Paypal SDK - Return "Approved" when the toolbar says "Completed" after the payment

I use the following code to complete a payment that has been approved by Paypal.com:

// Get the order object $order_object = new Order($_GET["orderid"]); // Complete the payment $payment = Payment::get($order_object->paypal_payment_id, $apiContext); //Set the payer id $order_object->SetPayerId($_GET["PayerID"]); try { // PaymentExecution object includes information necessary // to execute a PayPal account payment. // The payer_id is added to the request query parameters // when the user is redirected from paypal back to your site $execution = new PaymentExecution(); $execution->setPayer_id($_GET["PayerID"]); //Execute the payment // (See bootstrap.php for more on `ApiContext`) $finished_payment = $payment->execute($execution, $apiContext); } catch(PayPal\Exception\PPConnectionException $e) { echo "<p>PPConnectionException - Already executed payment?</p>"; } echo "Payment state: " . $finished_payment->getState() . '<br/>'; echo "Payment ID:" . $finished_payment->getId() . '<br/>'; 

If I get an order state before it is executed, it returns created , which is ok, but then after executing with this code, it returns with an approved state.

This would be nice if approved meant that the transaction was completed, however, on the developer's toolbar, the transaction shows as completed , as I expected!

Why should the code return approved when it is truly completed ?

thanks

UPDATE: I just checked http://sandbox.paypal.com and logged in as my test seller account and client test account, I used and both also say the transaction is complete. I can prove it, because if I try to re-run the order, it will return a 500 error. This really confuses why it returns inconsistent data ...

Screenshots:

Returning from the code above ...

enter image description here

Type of order on the developer's website ... enter image description here

Does approved completed ?

+4
source share
2 answers

Yes, the approved average is completed, according to the documentation here: https://developer.paypal.com/webapps/developer/docs/api/#execute-an-approved-paypal-payment The answer must be "state": "approved" if everything will be fine.

+2
source

The limestone cannot distinguish between payment and sale.

"approved" is the final happy payment status. https://developer.paypal.com/docs/api/#look-up-a-payment-resource

After the payment is approved, a Sale is created. Then you can find it in the "transaction / related_resources" field of the payment JSON. "completed" - a happy state of Sale.

+2
source

Source: https://habr.com/ru/post/1497523/


All Articles