【发布时间】:2017-09-26 05:38:27
【问题描述】:
在paypal API reference page 中,它说创建付款后会返回响应。我想在支付完成后使用交易信息,但是不知道如何从基础集成场景here获取这个响应json。浏览完文档后,我看不到在哪里可以获得此响应。我在这里错过了一个选项吗?提前致谢。
以下是我的代码
paypal.Button.render({
// Set your environment
env: 'sandbox', // sandbox | production
// Pass the client ids to use to create your transaction on sandbox and production environments
client: {
sandbox: 'removed for security', // from https://developer.paypal.com/developer/applications/
production: 'removed for security' // from https://developer.paypal.com/developer/applications/
},
// Pass the payment details for your transaction
// See https://developer.paypal.com/docs/api/payments/#payment_create for the expected json parameters
payment: function() {
return paypal.rest.payment.create(this.props.env, this.props.client, {
transactions: [
{
amount: {
total: total,
currency: 'USD'
},
custom: purchaseOrderNumber
}
]
});
},
// Display a "Pay Now" button rather than a "Continue" button
commit: true,
// Pass a function to be called when the customer completes the payment
onAuthorize: function(data, actions) {
console.log("data", data);
console.log("actions", actions);
return actions.payment.execute().then(function() {
console.log('The payment was completed!');
//use transaction information from json response here
});
},
// Pass a function to be called when the customer cancels the payment
onCancel: function(data) {
console.log('The payment was cancelled!');
}
}, '#paypal-button');
编辑:
数据的控制台结果
{
"paymentToken":"EC-8T213183GM917341N",
"payerID":"784ARKSZGWBPG",
"paymentID":"PAY-00M809553A479072XLEBN4RI",
"intent":"sale",
"returnUrl":"https://www.sandbox.paypal.com/?paymentId=PAY-00M809553A479072XLEBN4RI&token=EC-8T213183GM917341N&PayerID=784ARKSZGWBPG"
}
操作结果的控制台
{
"payment":{}
}
//see below for console screenshot
EDIT2:
对paypal框架的请求和响应
看起来最后一张图片是我真正需要的响应。有没有办法从基本的 paypal 按钮获取这些数据?
【问题讨论】:
-
您是否已将您的贝宝开发帐户设置为使用沙盒?为了清楚起见......你按下贝宝结帐按钮,然后你登陆贝宝,你在那里做所有的事情,最后当它把你重定向回你的页面时它不起作用。或者你没有进入贝宝沙盒?
-
是的,我已将我的帐户设置为使用沙盒,一切正常。我不需要重定向到另一个页面。我只是想使用响应中的信息来做一些其他的事情,仅此而已。如果某处有一个包含响应 json 的变量,那就太好了。
-
你在
data和actions看到了什么? -
@Edwin 并澄清一下,单击贝宝结帐按钮会打开一个弹出窗口,显示在同一页面中。我认为这是因为我正在使用基本集成,如 here
-
您能否也将您的请求发布到 paypal 框架?
标签: javascript json paypal paypal-sandbox