代码相同的情况下 在个别手机会出现 {"errMsg":"request:fail abort statusCode:-1 connection closed"} 的报错,其他手机正常调起。已经排除 手机型号、VPN、谷歌账号、谷歌三件套版本、移动网WIFI差异、
plus.payment.getChannels((providers) => {
let provider = providers.find(function(e) {
return e.id === "google-pay";
});
let paymentMethodType = "CARD";
let cardPaymentMethodConfig = {
environment: 3, // 必填 1 是product 3是test
paymentMethodType: paymentMethodType, //必填 CARD、PAYPAL
existingPaymentMethodRequired: false, //可选 如果设置为true同时已经准备好了支付allowedPaymentMethods中的付款方式,isReadyToPay就会返回true。
currencyCode: "USD", //必填
countryCode: "US", //在欧洲经济区必填
transactionId: "", //当你想要接收googlepay回调的时候必填
totalPriceStatus: "FINAL", //必填 NOT_CURRENTLY_KNOWN、ESTIMATED、FINAL
totalPrice: "111.00", //必填 满足正则格式^[0-9]+(\.[0-9][0-9])?$
totalPriceLabel: "100heelo", //可选
checkoutOption: "DEFAULT", //可选 DEFAULT、COMPLETE_IMMEDIATE_PURCHASE
merchantName: "Example Merchant", //可选
emailRequired: true, //可选
shippingAddressRequired: true, //可选
shippingPhoneNumberRequired: false, //可选
//allowedCountryCodes: ["US", "GB"], //可选
allowedAuthMethods: ["PAN_ONLY", "CRYPTOGRAM_3DS"], //必填
allowedCardNetworks: ["AMEX", "DISCOVER", "JCB", "MASTERCARD", "VISA"], //必填
allowPrepaidCards: false, //可选
// allowCreditCards:false,//可选
assuranceDetailsRequired: false, //可选
billingAddressRequired: true, //可选
billingAddressParametersFormat: "FULL", //可选 MIN
phoneNumberRequired: false, //可选
tokenizationSpecificationType: "DIRECT", //必填 PAYMENT_GATEWAY、DIRECT
gateway: "example", //PAYMENT_GATEWAY时必填
gatewayMerchantId: "xxxx-xxxx-xxx", //PAYMENT_GATEWAY时必填
protocolVersion: "", //DIRECT时必填
publicKey: "", //DIRECT时必填
buildTokenizationSpecification: { //可选,此字段是为了方便开发者自定义构造tokenizationSpecification参数,设置此字段时,会覆盖掉`tokenizationSpecificationType`、`gateway`、`gatewayMerchantId`、`protocolVersion`、`publicKey`字段。(HBuilderX 3.5.1+支持)
"type": "PAYMENT_GATEWAY",
"parameters": {
"gateway": "custom-gateway",
"gatewayMerchantId": "xxxx-xxxx-xxx"
}
}
};
let paypalPaymentMethodConfig = {
environment: 3, // 必填 1 是product 3是test
paymentMethodType: paymentMethodType, //必填 CARD、PAYPAL
existingPaymentMethodRequired: false, //可选 如果设置为true同时已经准备好了支付allowedPaymentMethods中的付款方式,isReadyToPay就会返回true。
currencyCode: "USD", //必填
countryCode: "US", //在欧洲经济区必填
transactionId: "", //当你想要接收googlepay回调的时候必填
totalPriceStatus: "FINAL", //必填 NOT_CURRENTLY_KNOWN、ESTIMATED、FINAL
totalPrice: "111.00", //必填 满足正则格式^[0-9]+(\.[0-9][0-9])?$
totalPriceLabel: "100heelo", //可选
checkoutOption: "DEFAULT", //可选 DEFAULT、COMPLETE_IMMEDIATE_PURCHASE
merchantName: "Example Merchant", //可选
emailRequired: true, //可选
shippingAddressRequired: true, //可选
shippingPhoneNumberRequired: false, //可选
allowedCountryCodes: ["US", "GB"], //可选
merchantId: "xxxx-xxxx-xxx", //必填
};
let statement;
if (paymentMethodType === "CARD") {
statement = {
...cardPaymentMethodConfig
};
} else {
statement = {
...paypalPaymentMethodConfig
};
}
console.log(provider);
plus.payment.request(provider, statement, (result) => {
console.log("支付成功 :" + JSON.stringify(result));
}, (e) => {
console.log("支付失败: " + JSON.stringify(e));
})
});
1***@qq.com (作者)
谷歌登录获取到的参数与其他的不一样,只能拿到openId。把拿到的openId给到后端他那边是有办法解决的
2024-01-24 11:27