捕获订阅智能按钮与 SDK 集成时的错误 - 沙盒和实时



案例:通过智能支付按钮设置订阅时出错

备注:在实时环境中,我的帐户中确实被收取了交易费用

错误:存在捕获错误,在沙盒和实时案例中进行了 3 天的测试,未找到一个解决方案

对于沙盒模式,我找到了一些完全相同错误的参考资料,但对于那些人来说,它似乎在一夜之间消失了,2.这些不是订阅模式,而是常规购买模式。 以下是脚本,它应该不像我制作的那样难,几年前我们建立了一个类似的计费环境,几乎立即起作用,但这不是订阅。

更多详情: - 我也在作曲家文件中设置了正确的环境设置。 - 产品在那里 - 计划在那里 - 我们使用基于席位的定价(0.01美分,然后乘以美元*100的总金额(

////////////////////////////////////
// Error 500
////////////////////////////////////

通过控制台 邮编 https://www.paypal.com/smart/api/order/9VU587...34202/capture 500

通过网络

{ack: "error", message: ">

unhandle api error", meta: {calc: "4ac27dc9b8a70",...},...}

////////////////////////////////////
// Smart Button Script
////////////////////////////////////
<script src="https://www.paypal.com/sdk/js?vault=true&client-id=<?= $paypal_sandbox_id ?>&currency=<?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>

PHP 服务器端脚本:

////////////////////////////////////
// ../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 SamplePayPalClient;
use PayPalCheckoutSdkOrdersOrdersGetRequest;
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);
}

用于PayPal集成的 v2 的 SDK。

////////////////////////////////////
// SDK Installed in ../api/paypal/
////////////////////////////////////
{
"require": {
"paypal/paypal-checkout-sdk": "^1.0"
}
}

二手手册 来源:https://developer.paypal.com/docs/subscriptions/integrate/发现的问题资源之一:https://www.paypal-community.com/t5/REST-APIs/BASIC-Smart-Payment-buttons-integration-help/td-p/1844051

这是"500 内部服务错误"API 响应的类型,您最好联系PayPal对 (MTS( 的支持,而不是堆栈溢出,因为它实际上是在没有详细信息的情况下抛出PayPal服务器端的,需要追溯。但是,我碰巧有一些知识,在这种情况下,我的怀疑是交易金额与购买单位金额不匹配。也许您可以通过更简单的请求来纠正这一点,即从头到尾使用简单的静态数字(如 10 美元(进行测试,看看问题是否没有发生。

相关内容

最新更新