mollie / mollie-api-php

Mollie API client for PHP
http://www.mollie.com
BSD 2-Clause "Simplified" License
552 stars 191 forks source link

How can I know if the payment passed or failed after the payment is done with redirect or webhook url? #618

Closed Julianlu1 closed 2 years ago

Julianlu1 commented 2 years ago

Hi,

I made it possible to send the user back to the app after a payment, but I am struggling to redirect the user to the correct app screen (success screen or payment failed screen). After the order is created, a payment url is sent to the client. He then pays or declines the payment. How can I redirect the user with a parameter that says success or failed, since there is only 1 redirectUrl.

 "redirectUrl" => "https://example.org/redirect",
 "webhookUrl" => "https://example.org/webhook",

I read that the webhookUrl is used to check for updates. This url will get called when the status of an order updates. The client then can listen for changes on that url.

Do I need to listen on the webhookUrl? Or can I pass a parameter to redirectUrl, however I do not know if the payment is success or failed.

Or do I need to call get payment directly after I redirected the user? https://docs.mollie.com/reference/v2/payments-api/get-payment

Thank you!

sandervanhooft commented 2 years ago

Hi @Julianlu1 ,

This is how I usually solve this:

  1. Redirect the user to something like a ReturnFromMollieController in your app.
  2. In that controller, retrieve the payment from Mollie and check the payment status.
  3. Depending on the payment status: display the correct message / redirect to the right page in your app.
Julianlu1 commented 2 years ago

Hey Sander,

Thanks for your answer. I am still trying to implement your method. I will let you know when it works or if I am running into problems.

sandervanhooft commented 2 years ago

Great!

Closing this for now, let me know if it should be reopened.

Julianlu1 commented 2 years ago

Yeah that's fine! Will let you know.