|
@@ -20,7 +20,7 @@ declare var wx: any;
|
|
|
})
|
|
|
export class PayCompComponent implements OnInit {
|
|
|
@Input('price') price!: number;
|
|
|
- @Input('credit') credit!: number|undefined;//钻石
|
|
|
+ @Input('credit') credit!: number | undefined; //钻石
|
|
|
@Input('gid') gid: string | undefined;
|
|
|
@Input('orderType') orderType!: string; //订单类型
|
|
|
@Input('tradeNo') tradeNo: string | undefined; //支付单号
|
|
@@ -59,26 +59,8 @@ export class PayCompComponent implements OnInit {
|
|
|
this.checkpay = val;
|
|
|
console.log(val);
|
|
|
}
|
|
|
- // async showCodeModal(type: string) {
|
|
|
- // if (!this.tradeNo) {
|
|
|
- // this.tradeNo = this.accServ.setTradeNo();
|
|
|
- // } else {
|
|
|
- // this.orderId = await this.getOrder();
|
|
|
- // if(this.orderType == 'service' && !this.orderId){
|
|
|
- // this.tradeNo = this.accServ.setTradeNo();
|
|
|
- // }
|
|
|
- // }
|
|
|
- // console.log(this.tradeNo);
|
|
|
- // switch (type) {
|
|
|
- // case 'wxpay':
|
|
|
- // this.openWxPay();
|
|
|
- // break;
|
|
|
- // default:
|
|
|
- // break;
|
|
|
- // }
|
|
|
- // }
|
|
|
- /* 校验支付方式 */
|
|
|
- async openWxPay() {
|
|
|
+ /* 用户确认支付 */
|
|
|
+ async userPayment() {
|
|
|
if (!this.tradeNo) {
|
|
|
this.tradeNo = this.accServ.setTradeNo();
|
|
|
} else {
|
|
@@ -93,6 +75,17 @@ export class PayCompComponent implements OnInit {
|
|
|
}
|
|
|
}
|
|
|
console.log(this.tradeNo);
|
|
|
+ switch (this.checkpay) {
|
|
|
+ case 'wxpay':
|
|
|
+ this.openWxPay();
|
|
|
+ break;
|
|
|
+ case 'alipay':
|
|
|
+ this.openAlipay();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /* 校验支付方式 */
|
|
|
+ async openWxPay() {
|
|
|
let ua = navigator.userAgent.toLowerCase();
|
|
|
let isWeixin = ua.indexOf('micromessenger') != -1;
|
|
|
if (isWeixin) {
|
|
@@ -143,8 +136,10 @@ export class PayCompComponent implements OnInit {
|
|
|
};
|
|
|
if (this.orderId) {
|
|
|
this.accServ.updateAccountLog(info, this.orderId);
|
|
|
- }else if(this.orderType == 'recharge'){
|
|
|
- this.accountLog = await this.accServ.updateRecharge(this.accountLog!)
|
|
|
+ } else if (this.orderType == 'recharge') {
|
|
|
+ this.accountLog = await this.accServ.updateRecharge(
|
|
|
+ this.accountLog!
|
|
|
+ );
|
|
|
}
|
|
|
_this.toast('支付成功', 'success');
|
|
|
_this.isOpen = false;
|
|
@@ -216,6 +211,91 @@ export class PayCompComponent implements OnInit {
|
|
|
this.toast(err.message, 'danger');
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /* 支付宝支付 */
|
|
|
+ async openAlipay(){
|
|
|
+ if (this.isDisabled) return;
|
|
|
+ try {
|
|
|
+ this.isDisabled = true;
|
|
|
+ await this.getOrderId();
|
|
|
+ let data:any = await this.getAliPayUrl();
|
|
|
+ console.log(data.pay_url);
|
|
|
+ window.open(data.pay_url, "newW");
|
|
|
+ this.timer = setInterval(async () => {
|
|
|
+ console.log("支付结果轮询");
|
|
|
+ let AccountLog = new Parse.Query("AccountLog");
|
|
|
+ AccountLog.equalTo("company", this.accServ.company);
|
|
|
+ AccountLog.equalTo("orderNumber", this.tradeNo);
|
|
|
+ AccountLog.equalTo("payType", "aliPay");
|
|
|
+ AccountLog.equalTo("isVerified", true);
|
|
|
+ let result = await AccountLog.first();
|
|
|
+ if (result && result.id) {
|
|
|
+ clearInterval(this.timer);
|
|
|
+ this.timer = null;
|
|
|
+ }
|
|
|
+ if (!this.timer) {
|
|
|
+ //支付成功返回状态
|
|
|
+ this.toast('支付成功', 'success');
|
|
|
+ this.isOpen = false;
|
|
|
+ this.payResult.emit({
|
|
|
+ code: 200,
|
|
|
+ tradeNo: this.tradeNo,
|
|
|
+ type: this.checkpay,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }, 1000);
|
|
|
+ }catch (err: any) {
|
|
|
+ this.isDisabled = false;
|
|
|
+ let alert = await this.alertCtrl.create({
|
|
|
+ header: '异常错误',
|
|
|
+ subHeader: '',
|
|
|
+ message: err.message,
|
|
|
+ buttons: [
|
|
|
+ {
|
|
|
+ role: 'ok',
|
|
|
+ text: '确认',
|
|
|
+ handler: () => {},
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ });
|
|
|
+ alert.present();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 获取支付宝支付
|
|
|
+ async getAliPayUrl() {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ let beforURL = window.location.href;
|
|
|
+ let params = {
|
|
|
+ company: this.accServ.company,
|
|
|
+ tradeNo: this.tradeNo,
|
|
|
+ price: this.price,
|
|
|
+ tradetype:'wap',
|
|
|
+ // price: 0.01,
|
|
|
+ orderTitle: this.title,
|
|
|
+ returnUrl: beforURL,
|
|
|
+ };
|
|
|
+ try {
|
|
|
+ this.http
|
|
|
+ .post("https://server.fmode.cn/api/alipay/neworder", params)
|
|
|
+ .subscribe((res: any) => {
|
|
|
+ if (res.code !== 200) {
|
|
|
+ this.toast('网络错误,请稍后重试', 'warning');
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (res.data && res.data.pay_url) {
|
|
|
+ resolve(res.data);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (err) {
|
|
|
+ if (err) {
|
|
|
+ this.toast('网络错误,请稍后重试', 'warning');
|
|
|
+ reject(err);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
/* 关闭支付弹窗 */
|
|
|
onClose() {
|
|
|
this.isOpen = false;
|
|
@@ -230,13 +310,13 @@ export class PayCompComponent implements OnInit {
|
|
|
async getOrderId() {
|
|
|
if (this.orderType == 'vip' && !this.orderId && this.gid) {
|
|
|
let resulte = await this.accServ.setOrder({
|
|
|
- type: 'service',//创建服务类订单
|
|
|
+ type: 'service', //创建服务类订单
|
|
|
gid: this.gid,
|
|
|
price: this.price,
|
|
|
total_fee: this.price,
|
|
|
tradeNo: this.tradeNo!,
|
|
|
out_trade_no: this.tradeNo!,
|
|
|
- payType: 'wxpay',
|
|
|
+ payType: this.checkpay,
|
|
|
});
|
|
|
console.log(resulte);
|
|
|
if (resulte?.objectId) {
|
|
@@ -245,9 +325,9 @@ export class PayCompComponent implements OnInit {
|
|
|
} else if (this.orderType == 'recharge') {
|
|
|
this.accountLog = await this.accServ.creatdRechargeLog({
|
|
|
tradeNo: this.tradeNo!,
|
|
|
- payType: 'wxpay',
|
|
|
+ payType: this.checkpay,
|
|
|
price: this.price,
|
|
|
- credit:this.credit!
|
|
|
+ credit: this.credit!,
|
|
|
});
|
|
|
}
|
|
|
}
|
|
@@ -268,8 +348,10 @@ export class PayCompComponent implements OnInit {
|
|
|
clearInterval(that.timer);
|
|
|
if (this.orderId) {
|
|
|
this.accServ.updateAccountLog(info, this.orderId);
|
|
|
- }else if(this.orderType == 'recharge'){
|
|
|
- this.accountLog = await this.accServ.updateRecharge(this.accountLog!)
|
|
|
+ } else if (this.orderType == 'recharge') {
|
|
|
+ this.accountLog = await this.accServ.updateRecharge(
|
|
|
+ this.accountLog!
|
|
|
+ );
|
|
|
}
|
|
|
that.toast('支付成功', 'success');
|
|
|
that.isOpen = false;
|