Paypal 订阅智能按钮与SDK集成时捕获错误-沙盒和Live
案例:通过智能支付按钮设置订阅时出错 备注:在实时环境中,我确实从我的账户中收取了交易费用 错误:有一个捕获错误,在沙箱和实时案例中进行了3天的测试,没有找到一个解决方案 对于沙盒模式,我发现了一些关于完全相同错误的参考,但对于那些人来说,这是一个错误。似乎在一夜之间消失了。这些不是订阅模式,而是常规购买模式。 以下是脚本,它不应该像我所做的那么难,我们在几年前建立了一个类似的计费环境,并且几乎立即起作用,但这不是订阅 进一步详情: -我在composer文件中也设置了正确的环境设置。 -产品就在那里 -有计划吗 -我们使用基于座位的定价(0.01美分,然后乘以总金额,单位为美元*100) //通过控制台 邮政500 //通过网络 {ack:“错误”,消息:“未处理的api错误”,元:{calc:“4ac27dc9b8a70”,…},…}Paypal 订阅智能按钮与SDK集成时捕获错误-沙盒和Live,paypal,paypal-sandbox,Paypal,Paypal Sandbox,案例:通过智能支付按钮设置订阅时出错 备注:在实时环境中,我确实从我的账户中收取了交易费用 错误:有一个捕获错误,在沙箱和实时案例中进行了3天的测试,没有找到一个解决方案 对于沙盒模式,我发现了一些关于完全相同错误的参考,但对于那些人来说,这是一个错误。似乎在一夜之间消失了。这些不是订阅模式,而是常规购买模式。 以下是脚本,它不应该像我所做的那么难,我们在几年前建立了一个类似的计费环境,并且几乎立即起作用,但这不是订阅 进一步详情: -我在composer文件中也设置了正确的环境设置。 -产品就
////////////////////////////////////
// Smart Button Script
////////////////////////////////////
<script src="https://www.paypal.com/sdk/js?vault=true&client-id=<?= $paypal_sandbox_id ?>¤cy=<?php echo $currency ?? "USD"; ?>&debug=false"></script>
<script>
paypal.Buttons({
// Set up the subscription
createSubscription: function (data, actions) {
return actions.subscription.create({
'plan_id': 'P-6NH76920JR31236564LYU3X4Y',
'quantity': total_billed_vat * 100
});
},
// Finalize the transaction
onApprove: function (data, actions) {
console.log('onApprove', data);
// Authorize the transaction
return actions.order.capture().then(function (details) {
console.log('capture', details);
// Show a success message to the buyer
alert('Transaction completed by ' + details.payer.name.given_name + '!');
// Call your server to save the transaction
return fetch('../api/paypal/paypal-transaction-complete.php', {
method: 'post',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
orderID: data.orderID
})
});
}).then(function (response) {
// Show a success message to the buyer
alert('actions.order.capture done ' + details.payer.name.given_name + '!');
});
},
onCancel: function (data, actions) {
// Show a cancel page or return to cart
alert('Feel free to retry when you are ready');
}
}).render('#paypal-button-container');
</script>
使用的手动来源:
找到的问题资源之一:这是一种“500内部服务错误”API响应,最好联系PayPal的支持(MTS),而不是堆栈溢出,因为它实际上是在PayPal服务器端抛出的,没有详细信息,需要追溯。然而,我确实有一些知识,在这种情况下,我怀疑交易金额与购买单位金额不匹配。也许你可以用一个更简单的请求来纠正这一点,即从开始到结束用一个简单的静态数字(如$10)进行测试,看看问题是否没有发生。谢谢。我也问过。这就是说:我发现对于订阅模型,“actions.order.capture()”这一行不被接受或不被接受。新的智能按钮物流似乎已经解决了所有这些问题,并在购买后返回。到目前为止,一切测试都取得了积极的结果。未决的“真实”交易。再次感谢。嗨@Kim K。我正在使用新的智能按钮,但我得到了同样的错误。你解决过这个问题吗?@AndresSK,我在回复Preston对帖子的回复时发了这个帖子。Quote:我发现对于订阅模型,“actions.order.capture()”这一行不被接受或接受。新的智能按钮物流似乎已经解决了所有这些问题,并在购买后返回。到目前为止,一切测试都取得了积极的结果。未决的“真实”交易。
////////////////////////////////////
// Smart Button Script
////////////////////////////////////
<script src="https://www.paypal.com/sdk/js?vault=true&client-id=<?= $paypal_sandbox_id ?>¤cy=<?php echo $currency ?? "USD"; ?>&debug=false"></script>
<script>
paypal.Buttons({
// Set up the subscription
createSubscription: function (data, actions) {
return actions.subscription.create({
'plan_id': 'P-6NH76920JR31236564LYU3X4Y',
'quantity': total_billed_vat * 100
});
},
// Finalize the transaction
onApprove: function (data, actions) {
console.log('onApprove', data);
// Authorize the transaction
return actions.order.capture().then(function (details) {
console.log('capture', details);
// Show a success message to the buyer
alert('Transaction completed by ' + details.payer.name.given_name + '!');
// Call your server to save the transaction
return fetch('../api/paypal/paypal-transaction-complete.php', {
method: 'post',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
orderID: data.orderID
})
});
}).then(function (response) {
// Show a success message to the buyer
alert('actions.order.capture done ' + details.payer.name.given_name + '!');
});
},
onCancel: function (data, actions) {
// Show a cancel page or return to cart
alert('Feel free to retry when you are ready');
}
}).render('#paypal-button-container');
</script>
////////////////////////////////////
// ../api/paypal/paypal-transaction-complete.php
////////////////////////////////////
<?php
namespace Sample;
require __DIR__ . '/vendor/autoload.php';
//1. Import the PayPal SDK client that was created in `Set up Server-Side SDK`.
use Sample\PayPalClient;
use PayPalCheckoutSdk\Orders\OrdersGetRequest;
class GetOrder
{
// 2. Set up your server to receive a call from the client
/**
*You can use this function to retrieve an order by passing order ID as an argument.
*/
public static function getOrder($orderId)
{
// 3. Call PayPal to get the transaction details
$client = PayPalClient::client();
$response = $client->execute(new OrdersGetRequest($orderId));
/**
*Enable the following line to print complete response as JSON.
*/
//print json_encode($response->result);
print "Status Code: {$response->statusCode}\n";
print "Status: {$response->result->status}\n";
print "Order ID: {$response->result->id}\n";
print "Intent: {$response->result->intent}\n";
print "Links:\n";
foreach($response->result->links as $link)
{
print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n";
}
// 4. Save the transaction in your database. Implement logic to save transaction to your database for future reference.
print "Gross Amount: {$response->result->purchase_units[0]->amount->currency_code} {$response->result->purchase_units[0]->amount->value}\n";
// To print the whole response body, uncomment the following line
// echo json_encode($response->result, JSON_PRETTY_PRINT);
}
}
/**
*This driver function invokes the getOrder function to retrieve
*sample order details.
*
*To get the correct order ID, this sample uses createOrder to create a new order
*and then uses the newly-created order ID with GetOrder.
*/
if (!count(debug_backtrace()))
{
GetOrder::getOrder($data->orderID, true);
}
////////////////////////////////////
// SDK Installed in ../api/paypal/
////////////////////////////////////
{
"require": {
"paypal/paypal-checkout-sdk": "^1.0"
}
}