acdr-ui/dist/build/mp-weixin/modules/mall/sheep/platform/pay.js
2024-10-01 09:15:35 +08:00

2 lines
4.4 KiB
JavaScript

"use strict";var e=(e,t,a)=>new Promise(((i,s)=>{var n=e=>{try{c(a.next(e))}catch(t){s(t)}},l=e=>{try{c(a.throw(e))}catch(t){s(t)}},c=e=>e.done?i(e.value):Promise.resolve(e.value).then(n,l);c((a=a.apply(e,t)).next())}));const t=require("../../../../common/vendor.js"),a=require("../index.js");require("../helper/index.js");const i=require("../api/pay/order.js");exports.SheepPay=class{constructor(e,t,a){this.payment=e,this.id=a,this.orderType=t,this.payAction()}payAction(){return{WechatOfficialAccount:{wechat:()=>{this.wechatOfficialAccountPay()},alipay:()=>{this.redirectPay()},wallet:()=>{this.walletPay()},mock:()=>{this.mockPay()}},WechatMiniProgram:{wechat:()=>{this.wechatMiniProgramPay()},alipay:()=>{this.copyPayLink()},wallet:()=>{this.walletPay()},mock:()=>{this.mockPay()}},App:{wechat:()=>{this.wechatAppPay()},alipay:()=>{this.alipay()},wallet:()=>{this.walletPay()},mock:()=>{this.mockPay()}},H5:{wechat:()=>{this.wechatWapPay()},alipay:()=>{this.redirectPay()},wallet:()=>{this.walletPay()},mock:()=>{this.mockPay()}}}[a.sheep.$platform.name][this.payment]()}prepay(t){return new Promise(((s,n)=>e(this,null,(function*(){const e={id:this.id,channelCode:t,channelExtras:{}};if(["wx_pub","wx_lite"].includes(t)){const t=yield a.sheep.$platform.useProvider("wechat").getOpenid();if(!t)return void this.bindWeixin();e.channelExtras.openid=t}i.PayOrderApi.submitOrder(e).then((e=>{0===e.code&&s(e),0!==e.code&&e.msg.indexOf("无效的openid")>=0&&(e.msg.indexOf("无效的openid")>=0||e.msg.indexOf("下单账号与支付账号不一致")>=0)&&this.bindWeixin()}))}))))}wechatMiniProgramPay(){return e(this,null,(function*(){const{code:e,data:i}=yield this.prepay("wx_lite");if(0!==e)return;const s=JSON.parse(i.displayContent);t.index.requestPayment({provider:"wxpay",timeStamp:s.timeStamp,nonceStr:s.nonceStr,package:s.packageValue,signType:s.signType,paySign:s.paySign,success:e=>{this.payResult("success")},fail:e=>{"requestPayment:fail cancel"===e.errMsg?a.sheep.$helper.toast("支付已手动取消"):this.payResult("fail")}})}))}walletPay(){return e(this,null,(function*(){const{code:e}=yield this.prepay("wallet");0===e&&this.payResult("success")}))}mockPay(){return e(this,null,(function*(){const{code:e}=yield this.prepay("mock");0===e&&this.payResult("success")}))}copyPayLink(){return e(this,null,(function*(){const{error:e,data:i}=yield this.prepay();0===e&&t.index.showModal({title:"支付宝支付",content:"复制链接到外部浏览器",confirmText:"复制链接",success:e=>{e.confirm&&a.sheep.$helper.copyText(i.pay_data)}})}))}alipay(){return e(this,null,(function*(){const e=this,{error:i,data:s}=yield this.prepay("alipay_app");0===i&&t.index.requestPayment({provider:"alipay",orderInfo:s.pay_data,success:t=>{e.payResult("success")},fail:t=>{"requestPayment:fail [paymentAlipay:62001]user cancel"===t.errMsg?a.sheep.$helper.toast("支付已手动取消"):e.payResult("fail")}})}))}wechatAppPay(){return e(this,null,(function*(){const e=this,{error:a,data:i}=yield this.prepay("wx_app");0===a&&t.index.requestPayment({provider:"wxpay",orderInfo:i.pay_data,success:t=>{e.payResult("success")},fail:t=>{"requestPayment:fail cancel"!==t.errMsg&&e.payResult("fail")}})}))}payResult(e){a.sheep.$router.redirect("/modules/mall/pay/result",{id:this.id,orderType:this.orderType,payState:e})}bindWeixin(){t.index.showModal({title:"微信支付",content:"请先绑定微信再使用微信支付",success:function(e){e.confirm&&a.sheep.$platform.useProvider("wechat").bind()}})}},exports.getPayMethods=function(e){const t=[{icon:"/static/img/shop/pay/wechat.png",title:"微信支付",value:"wechat",disabled:!0},{icon:"/static/img/shop/pay/alipay.png",title:"支付宝支付",value:"alipay",disabled:!0},{icon:"/static/img/shop/pay/wallet.png",title:"余额支付",value:"wallet",disabled:!0},{icon:"/static/img/shop/pay/apple.png",title:"Apple Pay",value:"apple",disabled:!0},{icon:"/static/img/shop/pay/wallet.png",title:"模拟支付",value:"mock",disabled:!0}],i=a.sheep.$platform.name,s=t[0];("WechatOfficialAccount"===i&&e.includes("wx_pub")||"WechatMiniProgram"===i&&e.includes("wx_lite")||"App"===i&&e.includes("wx_app"))&&(s.disabled=!1),s.disabled=!1;const n=t[1];("WechatOfficialAccount"===i&&e.includes("alipay_wap")||"WechatMiniProgram"===i&&e.includes("alipay_wap")||"App"===i&&e.includes("alipay_app"))&&(n.disabled=!1);const l=t[2];e.includes("wallet")&&(l.disabled=!1);const c=t[4];return e.includes("mock")&&(c.disabled=!1),t};