php - Paypal API v2 响应指定的资源不存在

标签 php paypal paypal-sandbox

我试图在服务器端/capture资金,但我收到错误消息“指定的资源不存在”。

我已经放置了为沙盒和欧元货币配置的 Paypal 脚本:

<script src='https://www.paypal.com/sdk/js?client-id=sb&currency=EUR&commit=true&disable-funding=card,credit' ></script>

然后,按如下所述配置按钮

paypal.Buttons( {
       createOrder : function( data, actions ) {
                     return actions.order.create( {
                            "intent"         : "CAPTURE",
                            "purchase_units" : [ { amount : { "value" : cart-total-amount,
                                                              "currency_code" : "EUR",
                                                              } } ] } );
                            },
       onApprove: function( data, actions ) {
                   /*
                   MY SERVER API
                   */
                   _this.api( "my-server-api-url/cart/submit/",
                               { "items" : _this.cart.items,
                                 "invoice" : _this.cart.invoice,
                                 "paymentmethod" : "paypal",
                                 "orderid"  : data.orderID,
                                 "payerid" : data.payerID,
                                  }, function( data ) {
                                 alert( data.message );
                                 } );
                     },
       style: { "layout" : "horizontal",
                           "color" : "blue",
                           "shape" : "rect",
                           "label" : "paypal",
                           "tagline" : false,
                            "height" : 40,
                           },
                  } ).render( "#paypal-button-id" );

只是解释一下代码:

_this = 对我的类(class)/图书馆的引用

_this.cart.items = 发票上的项目

_this.cart.invoice = 发票详情

$orderid = data.orderID(来自上面的js)

然后,在服务器端,我从 Paypal(变量 $accesstoken)正确获取了 token ,但是当我尝试获取资金时出现错误。

  $curl = curl_init( "https://api.sandbox.paypal.com/v2/checkout/orders/" . $orderid . "/capture" );
  curl_setopt( $curl, CURLOPT_POST, true );
  curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, false );
  curl_setopt( $curl, CURLOPT_HEADER, false );
  curl_setopt( $curl, CURLINFO_HEADER_OUT, true );
  curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
  curl_setopt( $curl, CURLOPT_HTTPHEADER, [ "Content-Type: application/json",
                                            "Authorization: Bearer " . $accesstoken,
                                            "Accept: application/json",
                                             ] );
  $result = curl_exec( $curl );
  curl_close( $ch );
  curl_close( $curl );

错误(json_decoded 然后是 print_r):

stdClass Object
(
[name] => RESOURCE_NOT_FOUND
[details] => Array
    (
        [0] => stdClass Object
            (
                [location] => path
                [issue] => INVALID_RESOURCE_ID
                [description] => Specified resource ID does not exist. Please check the resource ID and try again.
            )

    )

[message] => The specified resource does not exist.
[debug_id] => cb446322c3a2c
[links] => Array
    (
        [0] => stdClass Object
            (
                [href] => https://developer.paypal.com/docs/api/orders/v2/#error-INVALID_RESOURCE_ID
                [rel] => information_link
                [method] => GET
            )
    )
)

基本上我在客户端创建一个订单(通过 Js 使用 Paypal API),然后我在服务器端捕获它。

我在这个过程中缺少什么?

最佳答案

包含 js 文件时缺少 client-id:

<script src='https://www.paypal.com/sdk/js?client-id=[CLIENT-ID-HERE]&currency=EUR&commit=true&disable-funding=card,credit' ></script>

关于php - Paypal API v2 响应指定的资源不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55316799/

相关文章:

php - htmlspecialchars() - 如何以及何时使用和避免多次使用

php - Google 日历 API - (403) 访问未配置'

php - 以这种方式处理方程式是否安全?

Paypal API v2-API 响应缺少 Seller_receivable_breakdown

Paypal live issue 非美国

paypal - 如何创建 PayPal 网站支付专业沙箱帐户?

c# - 从 paypal 沙箱中获取响应

php - 使用 MySql Update 和 PHP 制作表情符号

Paypal IPN 处理程序

paypal - 如何创建沙盒用户?