- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am using the orders API to create orders... But, I'm stuck with the onApprove function... How do you retrieve the order details on the server side?
CLIENT SIDE:
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
alert('Transaction completed by ' + details.payer.name.given_name);
return fetch('/paypal-transaction-complete', {
method: 'post',
headers: {'content-type': 'application/json'},
body: JSON.stringify({orderID: data.orderID})});
});
}
ON THE SERVER SIDE(using php)
GetOrder::getOrder('REPLACE-WITH-ORDER-ID', true);
What should I pass in place of 'REPLACE-WITH-ORDER-ID' ?
Basically how do i obtain the order ID from the JSON
Solved! Go to Solution.
- Labels:
-
Payments REST APIs
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Verifying is pretty much just doing a GET on the orderID, and looking over the response to see if the user has "CONFIRMED" (approved) the amount to be paid. Or if the order has already been captured, you check to see if its status is "COMPLETED".
Capturing is actually telling the PayPal API to take those funds from the user (the payer) and dump it into your merchant account (the payee) after they have confirmed (onApprove). Once you do this, its a good time to store all of this information in a database (if you have not already)... so fulfilling the purchase can be handled and tracked.
Most of the examples I see skip the step of looking at the order first, and instead goes straight into capturing, and then looking at the order. Like their example for the js sdk "onApprove" does a capture immediately instead of verifying the order first. Its a flow choice, but at some point you would want to do a GET on that orderID to check that everything checks out and to store details from it into a database.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can get your data by reading the file: php://input, for example using file_get_contents('php://input') and then decode that input with json_decode().
$json = file_get_contents('php://input');
$data = json_decode($json);
$orderid = $data->orderID;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Could you tell me the difference between capturing an order and verifying an order ?
How to capture an order and verify it at the same time ?
I'm really confused...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Verifying is pretty much just doing a GET on the orderID, and looking over the response to see if the user has "CONFIRMED" (approved) the amount to be paid. Or if the order has already been captured, you check to see if its status is "COMPLETED".
Capturing is actually telling the PayPal API to take those funds from the user (the payer) and dump it into your merchant account (the payee) after they have confirmed (onApprove). Once you do this, its a good time to store all of this information in a database (if you have not already)... so fulfilling the purchase can be handled and tracked.
Most of the examples I see skip the step of looking at the order first, and instead goes straight into capturing, and then looking at the order. Like their example for the js sdk "onApprove" does a capture immediately instead of verifying the order first. Its a flow choice, but at some point you would want to do a GET on that orderID to check that everything checks out and to store details from it into a database.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for that🙏 , it really helped clarify my doubts😊... I feel like their documentation isn't adequately explanatory enough ...
My server integration isn't working for some reason😢....
Could you help identify what i'm doing wrong?
Client side
onApprove: function(data) {
return fetch('/server-side-file-name', {
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
orderID: data.orderID
})
}).then(function(res) {
return res.json();
}).then(function(details) {
alert('Transaction funds captured from ' + details.payer_given_name);
})
}
ON the SERVER SIDE
if (!count(debug_backtrace()))
{
$json = file_get_contents('php://input');
$data = json_decode($json);
$orderid = $data->orderID;
CaptureOrder::captureOrder($orderid, true);
}

Haven't Found your Answer?
It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.
- failed to pay with sandbox account in Sandbox Environment
- Paypal 3DS intigration error in NVP/SOAP APIs
- PERMISSION_DENIED error for checkout/orders/{order_id} endpoint in REST APIs
- PERMISSION_DENIED trying to refund capture in live mode in REST APIs
- Inserting province/autonomous region by address when creating an order does not take effect in Braintree Server-side Integration (PHP, Java, .NET, Ruby, Python, NodeJS SDKs)