【发布时间】:2020-10-14 10:24:46
【问题描述】:
我试图弄清楚如何获取使用 PayPal SDK 进行的付款的交易 ID。这是我的 JS 中的内容:
paypal.Buttons({
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: parseFloat( window.my_config.amount ),
currency: 'USD',
},
description: window.my_config.description
}],
commit: true
});
},
onApprove: function(data, actions) {
console.dir({ data: data, actions:actions });
return actions.order.capture().then(function(details) {
console.log({ details: details });
// This function shows a transaction success message to your buyer.
alert('Transaction completed by ' + details.payer.name.given_name);
});
$('#AJAXloadingWrapper').show();
}
}).render('#paypalWrapper');
这是我的调试返回的结果:
我在任何地方都看不到交易 ID。应该是 7CA44490MT363621L(通过我的 PayPal 帐户中的 transid)
如何获得它?在我以前使用的旧系统中:
curl https://api.paypal.com/v1/payments/payment/L8EM97CXSYBJ2 -H "Content-Type: application/json" -H "Authorization: Bearer tokenstring"
但这不起作用。我尝试将其更改为 v2:
curl https://api.paypal.com/v2/payments/payment/L8EM97CXSYBJ2 -H "Content-Type: application/json" -H "Authorization: Bearer xxxx"
...但我得到的回应是什么都没有(没有错误,但没有输出)
我尝试过一些基于:
sub get_proper_trans_id {
my $token = encode_base64(qq|$config->{$config->{mode}}->{system_client_id}:$config->{$config->{mode}}->system_secret}|);
$token =~ s/\n//g;
my $trans_id = '50D311011N3466050';
print qq|curl https://$config->{$config->{mode}}->{transaction_endpoint}/v2/payments/payment/$trans_id -H "Content-Type: application/json" -H "Authorization: Bearer $token"\n|;
my $results = `curl https://$config->{$config->{mode}}->{transaction_endpoint}/v2/payments/payment/$trans_id -H "Content-Type: application/json" -H "Authorization: Bearer $token"`;
my $json_vals = decode_json($results);
use Data::Dumper;
print Dumper($json_vals);
}
什么都不输出(也没有错误)
更新: 正如建议的那样,我正在尝试使用输出结果中的purchase_units -> payments -> captures -> id。问题是这似乎是错误的/与我所期望的不同。当我登录我的 PayPal 时,我得到:
0NP90326GE709501L
然而返回数据中的值是:
891170207E054363D
为什么这些不同? FWIW 我正在我的个人 PayPal 帐户(而不是它发送到的企业)中查看这个。不过,商家和客户的 trans ID 应该是相同的吧?
更新 2: 毕竟,我发现一个帖子说 PayPal 故意为买家和卖家提供不同的交易 ID。什么皮塔饼。所以另一种方法是传入一个自定义的 invoice_id,我们可以与之交叉引用。一切都好——除了我似乎也做不到!
我试过了:
return actions.order.create({
purchase_units: [{
amount: {
value: parseFloat( window.my_config.amount ),
currency: 'USD',
},
description: window.my_config.description,
}],
invoice_id: invoice_id,
commit: true
});
},
还有:
return actions.order.create({
purchase_units: [{
amount: {
value: parseFloat( window.my_config.amount ),
currency: 'USD',
},
description: window.my_config.description,
invoice_id: invoice_id
}],
commit: true
});
},
但是当他们完成付款的过程时,它会返回:
Error: Order could not be captured
..当尝试运行return actions.order.capture().then(function(details) {
更新 3:
我仍然无法让它工作。这是您传递 custom_id 的方式吗?
return actions.order.create({
purchase_units: [{
amount: {
value: parseFloat( window.my_config.amount ),
currency: 'USD',
custom_id: invoice_id
},
description: window.my_config.description
}],
commit: true
});
我在那里试过了,也如下 commit: true,但还是不行:((确认付款后“订单无法被捕获”)
【问题讨论】: