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¤cy=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?
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]¤cy=EUR&commit=true&disable-funding=card,credit' ></script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With