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

时间:2019-03-23 18:02:27

标签: php paypal paypal-sandbox

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

我放置了配置为沙箱和欧元货币的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 =对我的班级/图书馆的引用

_this.cart.items =发票上的物品

_this.cart.invoice =发票详细信息

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

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

  $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,然后再打印rr):

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)创建订单,然后在服务器端捕获订单。

在此过程中我缺少什么?

1 个答案:

答案 0 :(得分:4)

包含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>