服务第三方支付

pifa
wangdong 6 months ago
parent 8d8b462eb9
commit 9982f9a824
  1. 90
      pages/news/recycling/pay.vue

@ -9,16 +9,16 @@
<view class="item" v-for="(a,i) in list2" @click="tabItem(i)">
<image v-if="tabIndex == i" src="@/static/invoice/select-on.png"></image>
<image v-else src="@/static/invoice/select.png"></image>
{{a.method == 'wechat'?'微信支付':'余额支付'}}<text v-if="a.method == 'balance'">余额{{userInfo.balance}}</text>
{{a.method == 'huifu' ? '银联支付' : (a.method == 'wechat'?'微信支付':'余额支付')}}<text v-if="a.method == 'balance'">余额{{userInfo.balance}}</text>
</view>
</view>
<view class="pay-btn" @click="clickPay()">确认支付</view>
<addShuiyin />
</view>
</template>
<script>
import { Wechat } from '@/core/payment'
import * as CashierApi from '@/api/cashier';
import * as newFunApi from '@/api/newFun'
export default {
data() {
@ -37,8 +37,19 @@
this.order_id = o.order_id;
this.type = o.type;
this.toServerOrder();
uni.$on('appShow', this.solveShowMsg);
},
onUnload() {
uni.$off('appShow', this.solveShowMsg);
},
methods: {
solveShowMsg(info) {
console.log(info);
if (this.miniPayRequest && Object.keys(this.miniPayRequest).length > 0 && info.appId === this.miniPayRequest.miniuser) {
this.onTradeQuery(this.miniPayRequest.out_trade_no, this.list2[this.tabIndex].method);
}
},
clickPay(){
if(this.isClick == false){
return;
@ -56,6 +67,21 @@
}
}else if(this.list2[this.tabIndex].method == "wechat"){
this.toPay1()
} else if(this.list2[this.tabIndex].method == "huifu") {
this.isClick = true;
if (!this.miniPayRequest || Object.keys(this.miniPayRequest).length === 0) {
this.$toast(`暂无银联支付信息`);
return
}
let appPayRequest = '';
appPayRequest = encodeURIComponent(JSON.stringify({
sign: this.miniPayRequest.sign,
prepayid: this.miniPayRequest.prepayid,
}));
uni.openEmbeddedMiniProgram({
appId: this.miniPayRequest.miniuser,
path: `${this.miniPayRequest.minipath}?appPayRequest=${appPayRequest}`
});
}
},
//
@ -68,6 +94,7 @@
this.userInfo = data.personal
this.orderInfo = data.order
this.list2 = data.paymentMethods;
this.setDefaultPayType();
console.log(data)
console.log(this.orderInfo)
console.log(this.list2)
@ -79,6 +106,20 @@
})
}
},
async huifuPay() {
const app = this;
const {status, data } = await newFunApi.serverOrderPay({
order_id: this.order_id,
method: 'huifu',
client: "MP-WEIXIN",
})
if(status == 200) {
const { miniPayRequest, out_trade_no } = data.payment;
app.miniPayRequest = miniPayRequest;
app.miniPayRequest.out_trade_no = out_trade_no;
}
},
async toPay1() {
const that = this;
const {status, data } = await newFunApi.serverOrderPay({
@ -161,9 +202,50 @@
})
}
},
//
setDefaultPayType() {
const app = this
const defaultIndex = app.list2.findIndex(item => item.is_default == true)
defaultIndex > -1 && app.tabItem(defaultIndex);
},
tabItem(i){
this.tabIndex = i
}
if (this.list2[this.tabIndex].method == "huifu") {
this.huifuPay();
}
},
// :
onTradeQuery(outTradeNo, method) {
const app = this
//
//
CashierApi.tradeQuery({
outTradeNo,
method,
client: app.platform
})
.then(result => {
if (result.data.isPay) {
uni.showToast({
title: result.message || "支付成功",
icon: 'success'
})
setTimeout(() => {
uni.redirectTo({
url: "/pages/news/caigou/notice1"
})
}, 1000)
} else {
uni.showToast({
title: result.message || "支付失败",
icon: 'none'
})
}
})
.finally(() => app.showConfirmModal = false)
},
}
}
</script>
@ -232,4 +314,4 @@
border-radius: 20rpx;
}
}
</style>
</style>
Loading…
Cancel
Save