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 Web客户端付款不起作用。is_payment_enabled: true
OUTPUT
我收到以下错误:"An unexpected error has occured.24002"
。在facebook's error reference中,24002表示“由于缺少隐私URL,无法处理付款请求”。
题
这是否意味着即使我在测试环境中使用管理员的聊天机器人帐户,我也必须提供隐私政策URL来测试付款?
UPDATE
根据建议,我实现了更新的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"]
根据这个"payments"
,它应该没有reference
是的,但是因为您只是测试它可以是任何URL。一旦您提交机器人进行审批,就需要指出真正的隐私政策。
您还使用了已弃用的付款版本。对于webview付款,你应该使用PaymentRequest
,这里解释:
https://developers.facebook.com/docs/messenger-platform/payments/webview-payments