首页 > 解决方案 > 捕获订阅智能按钮与 SDK 集成的错误 - Sandbox 和 Live

问题描述

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

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

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

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

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

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

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

// 通过网络

{ack:“错误”,消息:“未处理的 api 错误”,元:{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 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);
}

用于 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 -按钮集成帮助/td-p/1844051

标签: paypalpaypal-sandbox

解决方案


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


推荐阅读