简体   繁体   中英

PayPal Plus - Payment state for confirmation

I'm currently implementing PayPal Plus inside a custom TYPO3 extension. Everything works fine, but I'm wondering which payment states PayPal could possibly return.

As of now, when a payment went though, I get the state "approved" and handle my code accordingly, as I figure the payment went just fine. The PayPal docs are such a mystery and they are all over the place and I don't really know where to look at and every time I work with their API it feels like the first time.

This is the part where I'm currently not sure about:

$pay = $this->payPalService->executePayment(paymentId, $payerId, $json->access_token);

if ($pay->state == 'approved') {
    $this->orderService->update($paymentId);
    $this->redirect('paymentSuccessful', 'Order');
}

The essential part I'm talking about is $pay->state == 'approved' . Can I assume that approved means I can safely handle the order and treat it as successfully paid? The official PayPal Plus docs don't mention that.

If you click "Reference" in the bottom left of the doc you mention, there is a link to the v1/payments API reference, which documents this execute API call and possible responses: https://developer.paypal.com/docs/api/payments/v1/#payment-execute-response

State ... Possible values: created,approved,failed.

That seems fairly straightforward as far as the values the field can take. So this, "approved" means the execution was successful.

However, to mark something as "successfully paid" per your question, you should be looking for a sale object in transactions[0]->related_resources[0]->sale . Its id is the PayPal transaction ID you should store for accounting purposes. And it will have its own "state", documented here :

State ... Possible values: completed,partially_refunded,pending,refunded,denied

You should treat 'completed' as success, and 'pending' as something requiring manual attention in the PayPal.com account

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM