While using PayPal SDK REST Api, How to confirm that payment has "completed" as in completed-completed?
Right now the API is returning multiple attributes which is a bit confusing on what attribute to depend upon to proceed with the checkout process.
There is this state
field in the root attributes of the response object.
state -> approved
Then there is this payer
field which has a status
of its own, and its showing ...
status -> VERIFIED
Then there is this sale
object inside the transactions
object and it also has a state
which is showing..
state-> completed
So as per the Docs
A sale is a completed payment.
Which implies that we need to check for the sale -> state
flag.
$transactions = $payment->getTransactions();
$related_resources = $transactions[0]->getRelatedResources();
$sale = $related_resources[0]->getSale();
$sale_state = $sale->getState(); // 'complete' Or 'pending' or etc..