cancel
Showing results for 
Search instead for 
Did you mean: 

Is our payment flow correct?

vovkin
Contributor

Is our payment flow correct?

We implemented payment via PayPal some time ago, it works fine, but sometimes it takes too long (2+ hours) to confirm payment (and so process the order). I want to make sure we are doing it right and there is no faster way to do this.

 

Here are the steps in our implementation:

- user choses to pay via PayPal
- we send request to PayPal API to create order, and if success - send user to PayPal checkout pages
- after payment is done, user returned by return URL to our website
- here we send request to PayPal API to capture the order (and set state on our side to `paid, not confirmed`)
- then we also have webhook listener that listens to:

  1.  `CHECKOUT.ORDER.APPROVED` when we receive this, we do same as in point above (unless it has been already done on return URL)
  2. `PAYMENT.CAPTURE.COMPLETED` only when we receive this, we set state on our side to `payment confirmed`.


The main questions is: are we doing it right, should we wait first for `CHECKOUT.ORDER.APPROVED` and then for `PAYMENT.CAPTURE.COMPLETED` to be sure that payment was completed, or we can confirm payment on our side right away when one of those are received?

 

Or maybe we can rely on some other notification instead of `PAYMENT.CAPTURE.COMPLETED`, that can be received faster, and guarantee that payment completed and money will be received?

@MTS-Aaron 

5 REPLIES 5
MTS-Aaron
PayPal Employee

Re: Is our payment flow correct?

Hi @vovkin 

 

Thanks for the question! In this case, you are using the correct webhook in `PAYMENT.CAPTURE.COMPLETED'. This is the one webhook that tells you whether or not the payment has been completely captured. 

 

While this is a reliable webhook, it may not be sent as quickly as the response you may get for the capture. If you are doing this capture, then you can check the status in the response. If it says "completed", no need to wait for the webhook as the payment capture completed right away. That can be one way to expedite instead of waiting for the webhook.

 

Hope that helps!

-Aaron

vovkin
Contributor

Re: Is our payment flow correct?

@MTS-Aaron , thanks for your response.

 

So when user returned by return URL from PayPal to our website, we can send capture request, and if response is COMPLETED, we can confirm payment right away?

 

But does it also mean that when we receive CHECKOUT.ORDER.APPROVED notification with status APPROVED , we also can make capture request, and if response status is COMPLETED  then we can confirm payment as well (not waiting forPAYMENT.CAPTURE.COMPLETED)? I'm specifying this, because sometimes users pay and don't return to our website, then we rely on notifications to proceed with payment confirmation.

MTS-Aaron
PayPal Employee

Re: Is our payment flow correct?

Hi @vovkin 

 

If I'm understanding your question correctly, you are right that when you see that COMPLETED webhook, the captured funds have completed movement from the buyer to the seller. 

 

Additionally, if you receive the Checkout.Order.Approved webhook with status Approved, you can definitely also make that capture request if the customer didn't get redirected back to your site automatically. 

 

I hope that helps!
-Aaron

vovkin
Contributor

Re: Is our payment flow correct?

Hi @MTS-Aaron ,


thanks for your answer again.


Sorry for more questions, but I want specify and summarise once again if I understand all this correctly:

 

1. If user returned to our website after payment by return URL, at this point we can make capture request, and if received response status is COMPLETED, we can confirm payment on our side, and no need to wait on any notifications.

2. If we receive PAYMENT.CAPTURE.COMPLETED notification with status COMPLETED, it means that we can for sure confirm payment on our side.

3. If we receive CHECKOUT.ORDER.APPROVED notification, with status APPROVED, we can do the same as in p. 1 - make checkout request and if response status is COMPLETED - confirm payment. And question - is it ok to make capture request on each CHECKOUT.ORDER.APPROVED notification with APPROVED status?

4. What if we receive CHECKOUT.ORDER.APPROVED notification (so same as in p.3), but with status COMPLETED? Does it also mean that we can confirm payment right away, w/o making capture request (that we do in p.3, when status is APPROVED)? Or we still should make capture request in this case?

 

And if you have some link to documentation that explains this, please share.

MTS-Aaron
PayPal Employee

Re: Is our payment flow correct?

Hi @vovkin 

Happy to help with this!

 

  1. That's right, there's no issues with attempting to capture before receiving the notification if you see that approval was completed.
  2. That's also right, capture completed means that you have received the funds.
  3. That would be correct too, if you have an Approval notification, you can attempt capture on it.
  4. You would still need to initiate capture on a "CHECKOUT.ORDER.APPROVED" notification if you haven't already captured it and it is showing as "Completed". My thought on that is that it'd only show as "Completed" if you had already captured it by the time the notification was sent. That would be like if you did p.1, capturing it right when the customer returned to your page with the Approval status.

Here are the docs I was able to find on this, but they don't outline your specific corner cases/inquiries.

 

I hope that helps!

-Aaron