flinfo/dc-App/pages/my/pay.vue

154 lines
4.2 KiB
Vue
Raw Normal View History

2025-03-01 10:26:49 +08:00
<template>
<view>
<!-- 支付按钮或其他交互元素 -->
<web-view :src="payUrl+'?token=' + Token " bindmessage="onWebviewMessage" ></web-view>
<!-- <web-view src="http://159.75.168.143:88/apk/payInfo.html" ></web-view> -->
</view>
</template>
<script>
import {getToken} from '@/utils/auth'
import config from '@/config'
import request from '../../utils/request'
export default {
data() {
return {
payUrl: config.payUrl,
paysUrl: config.paysUrl,
stripe: null,
Token:getToken()
};
},
created() {
},
onLoad() {
this.userinfo = uni.getStorageSync('user_info');
console.log(this.Token);
},
methods: {
async getmode() {
var orderInfo = {
// "customer": "Stripe的Customer", //Customer
// "ephemeralKey": "Stripe的Customer Ephemeral Key", //临时访问Customer的Key
// "isAllowDelay": true, //是否支持延迟支付 默认false
// "merchantName": "DCloud", //商户名
// "paymentIntent": "Stripe的PaymentIntent", //订单信息
// "publishKey": "Public Key", //公钥
// "billingDetails": { //账单信息(可选)
// "name": "",
// "email": "",
// "phone": "",
// "address": {
// "city": "",
// "country": "CN", //国家代码(ISO 3166-1 alpha-2)
// "line1": "",
// "line2": "",
// "postalCode": "",
// "state": ""
// }
// }
};
let a = ''
console.log("123");
// 从Stripe测试服务器获取订单数据
// request({
// url: 'paymentController/create-payment-intent',
// method: "POST",
// data: {
// userId: 102,
// amount: 1
// }
// }).then(res => {
// console.log('998', res);
// a = res.clientSecret
// })
// return
await uni.request({
url: 'http://localhost:8880/paymentController/create-payment-intent',
method: "POST",
success: (res) => {
console.log("123", res);
orderInfo = {
// "customer": res.data.customer,
// "ephemeralKey": res.data.ephemeralKey,
// "isAllowDelay": true,
"merchantName": "DCloud",
"paymentIntent": res.clientSecret,
"publishKey": 'pk_test_51QGKJrCrcRylwRdelJhR9vySUQbjkJdVVIKAlArKH9E8OiNLGPbdieMsbGDJDaAHMWJpPRpnfgHZrv1Hq6suzVJL00uV3547D5',
// "billingDetails": res.data.billingDetails
};
},
});
// 仅作为示例,非真实参数信息。
//发起支付
await uni.getProvider({
service: 'payment',
success: function(res) {
console.log('431', res);
console.log('431', ~res.provider.indexOf('stripe'));
if (~res.provider.indexOf('stripe')) {
console.log('4311111111111111111111111');
uni.requestPayment({
"provider": "stripe",
"orderInfo": orderInfo,
success(res) {
console.log("requestPayment Success: "+JSON.stringify(res));
},
fail(e) {
console.log("requestPayment failed: "+JSON.stringify(e));
}
});
}else {
console.log('4311111111111111111111112');
}
}
});
// uni.getProvider({
// service: 'payment',
// success: function(res) {
// console.log('431', res);
// uni.requestPayment({
// "provider": "stripe",
// "orderInfo": orderInfo,
// success(res) {
// console.log("requestPayment Success: " + JSON.stringify(res));
// },
// fail(e) {
// console.log("requestPayment failed: " + JSON.stringify(e));
// }
// });
// // if (~res.provider.indexOf('stripe')) {
// // }
// }
// });
},
createPaymentIntent(amount, currency) {
// 创建支付意图
return this.stripe.paymentIntents.create({
amount,
currency,
payment_method_types: ['card'], // 只接受信用卡
})
.then(paymentIntent => {
// 处理成功回调,如显示订单详情
console.log('Payment intent created:', paymentIntent);
})
.catch(error => {
// 处理错误
console.error('Error creating payment intent:', error);
});
},
},
};
</script>