Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paypal API v2 response The specified resource does not exist

I'm trying to /capture the funds in server side but I got the error message "The specified resource does not exist".

I have placed Paypal script configured for sandbox nad EUR currency:

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

Then, configured the button as described below

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" );

Just to explain the code:

_this = reference to my class/library

_this.cart.items = ITEMS ON INVOCE

_this.cart.invoice = INVOICE DETAILS

$orderid = data.orderID (from js above)

Then, on server side I get correctly the token from Paypal (variable $accesstoken) but I got an error when I try to capture the funds.

  $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 );

Error (json_decoded and then 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
            )
    )
)

Basically I create an order on client side (using Paypal API via Js) and then I capture it on server side.

What I'm missing in this process?

like image 989
h2odev Avatar asked Mar 05 '23 07:03

h2odev


1 Answers

You were missing the client-id when you included the js file:

<script src='https://www.paypal.com/sdk/js?client-id=[CLIENT-ID-HERE]&currency=EUR&commit=true&disable-funding=card,credit' ></script>
like image 188
Manuel Otto Avatar answered Mar 16 '23 00:03

Manuel Otto