CONTEXT
我在WebView中使用标记化付款编写自定义结帐流程,因为我需要在美国境外使用付款。 我使用此代码(基于此Facebook guide)来询问用户的信用卡信息。
const saveThis = this
MessengerExtensions.requestPaymentCredentials(
function success(name, email, cardType, cardLastFourDigits, shippingAddress) {
console.log('success getting user payment info', cardLastFourDigits)
saveThis.printAsyncData(cardType)
},
function error(err, errorMessage) {
console.log('error trying to get user payment info', errorMessage)
saveThis.printAsyncData(errorMessage)
},
['CONTACT_NAME', 'CONTACT_EMAIL', 'CONTACT_PHONE', 'SHIPPING_ADDRESS']
);
注意事项
saveThis.printAsyncData()
函数是一种解决方法来记录
在移动设备中输出所以我可以调试代码,因为付款
不使用Messenger网络客户端。is_payment_enabled: true
输出
我收到以下错误:"An unexpected error has occured.24002"
。在facebook's error reference中,24002表示"由于缺少隐私网址而无法处理付款请求" 。
问题
这是否意味着即使我在测试环境中使用管理员的聊天机器人帐户,我也必须提供隐私政策网址来测试付款?
更新
根据建议,我按如下方式实施了更新的WebView支付代码:
const methodData = [{
supportedMethods: ['fb'], //only 'fb' is supported
data: {
merchantTitle: 'Merchant name', // optional, defaults to the Facebook Page name
merchantImageUrl: 'imageURL', //optional, defaults to the app icon
confirmationText: 'Thank you!', // optional, defaults to "Thank you for your payment"
merchantFBPageId: '28636603843****', // page id with onboarded payment method. Need to be the same with the page id in thread or messenger extension
termsUrl: 'https://www.facebook.com/' // Merchant payment privacy terms and conditions.
}
}]
const paymentDetails = {
displayItems: [ //array of items being charged for
{
label: 'T-shirt',
amount: {
currency: 'USD',
value : '15.00'
}
}
],
total: {
label: 'Total', // defaults to "Total"
amount: {
currency: 'USD',
value : '16.23'
}
},
shippingOptions: [ // Optional. Array of options for user to select
{
id: 'free-shipping', // custom ID
label: 'Free shipping in US', //human-readable name
amount: {currency: 'USD', value: '0.00'},
selected: true
}
]
}
const additionalOptions = {
requestShipping: false, // If shipping is required. If true, handle shippingoptionchange and shippingaddresschange events.
requestPayerName: true, // Name of the payer sent with the final response
requestPayerEmail: true, // Email address, same as above
requestPayerPhone: false // Phone number, same as above
}
let request = new this.messengerExtensions.PaymentRequest(
methodData, // array of payment methods and their setup
paymentDetails, // array of items, total, shipping options
additionalOptions, // request shipping information, payee email address, etc
);
request.canMakePayment()
.then(response => {
this.printAsyncData(response + ' from canMakePayment')
if (response === true) {
// proceed
} else {
// something went wrong, e.g. invalid `displayItems` configuration
// or the device does not run a
// recent enough version of the Facebook app
}
})
.catch(error => {
this.printAsyncData(error+' error from canMakePayment')
// an error such as `InvalidStateError`
// if a payment is already in process
});
此建议的实现将变量response
作为false
返回。从此link复制每个配置变量。我使用在Chatbot的fb页面>上找到的PageID更改了MerchantPageID。信息,所以我不认为这可能是问题所在。我检查了我的Android设备的Messenger版本,是最新版本,是147.0.0.25.86版本。
我甚至尝试按如下方式实施付款对话框,以了解其行为。
request.show().then(response => {
// Process the payment if using tokenized payments.
// Process the confirmation if using Stripe/PayPal
this.printAsyncData(response)
// paymentResponse.complete('success').then(() => {
// // cleanup UI, log, etc
// });
}).catch(error => this.printAsyncData(error+'from show()'));
付款对话框很好地弹出。它显示用户的姓名和电子邮件,但在METHOD PAYMENT标题下,它会无限期地显示加载微调器。此外,.show()
从不触发回调,因此不允许在paymentResponse.complete('success')
之前在该行上打印其响应。
更新2
我已通过以下代码获得支持的功能,以尝试了解我所缺少的内容
const saveThis = this
MessengerExtensions.getSupportedFeatures(function success(result) {
var features = result.supported_features;
saveThis.printAsyncData(features)
}, function error(err, errorMessage) {
saveThis.printAsyncData(errorMessage)
});
这是我的android messenger客户端上的输出:
["sharing_broadcast","sharing_direct", "sharing_open_graph", "permissions", "thread_context", "context", "sharing_media_template"]
根据此reference
,没有"payments"
答案 0 :(得分:0)
是的,但由于您只是在测试,因此可以是任何网址。一旦您提交机器人进行审批,就需要指出真正的隐私政策。
您还在使用已弃用的付款版本。对于webview付款,您应该使用PaymentRequest
,此处说明:
https://developers.facebook.com/docs/messenger-platform/payments/webview-payments