Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Payment status other than "paid" refreshes the Mollie page #4

Closed
chocolata opened this issue Apr 29, 2021 · 5 comments · Fixed by #5
Closed

Payment status other than "paid" refreshes the Mollie page #4

chocolata opened this issue Apr 29, 2021 · 5 comments · Fixed by #5
Assignees
Labels
enhancement New feature or request

Comments

@chocolata
Copy link

Hi,

I just stumbled upon your plugin... Thanks for your work. It's great to see that we're getting very close to getting the complete Mollie experience within the Mall plugin.

Do you know how we can deal with the issue of the Mollie page refreshing whenever the payment has any other status than "Paid"?
As you can see here, we were working on a similar integration, and it seems that the missing link would be a webhook. Would you have a clue how we could implement that?

Otherwise payment methods like banktransfer would not work in the plugin.

Thanks in advance for looking into it.

@chocolata chocolata changed the title Payment status "open" refreshes the Mollie page Payment status other than "paid" refreshes the Mollie page Apr 29, 2021
@chocolata
Copy link
Author

Hi, I just got word from Tobias from the Mall plugin. He says the following:

Regarding the incoming webhooks, this is actually a rather trivial problem to solve with Laravel/October. Simply register a callback URL via a routes.php file. I once did that for a plugin for snipcart.com, which might be an inspiration (I would say a much simpler single method setup will work in your case):
Route registration: https://github.com/OFFLINE-GmbH/oc-snipcartshop-plugin/blob/develop/routes.php#L10
Actual processing: https://github.com/OFFLINE-GmbH/oc-snipcartshop-plugin/blob/develop/classes/OrderCompleted.php#L81

Looking at the official Mollie PHP package, I would suggest to dump the incomplete Omnipay package and use this instead:
https://github.com/mollie/mollie-api-php

It should just need a few changes to the existing code to replace Omnipay with this package. They also have a nice webhook processor example that you can use. Just update the payment state of the Order model according to the incoming data. October's event system should take care of the rest (like sending notification mails):
https://github.com/mollie/mollie-api-php/blob/master/examples/payments/webhook.php

Would you feel like teaming up to get this up and running?

@guus-frenken guus-frenken self-assigned this May 4, 2021
@guus-frenken guus-frenken added the enhancement New feature or request label May 4, 2021
@guus-frenken
Copy link
Contributor

guus-frenken commented May 6, 2021

Hi Maarten,

I've created a separate branch and spent some time converting the plugin to use Mollie's own API client for PHP instead of Omnipay so we can utilize webhooks, feel free to test it for your purposes.

When a Mollie payment is created in the process() method, it passes a webhook URL for which I have created a route. When Mollie sends a POST request to this route, it calls a method that can change status of the order depending on status of the Mollie payment.

There are still some issues I will have to look into:

  • Mollie expects the amount to be formatted like "10.00", but the Mall plugin's $this->order->total_in_currency variable will output a rounded numer like "10" which Mollie will reject.

  • When you have enabled multiple payment methods in your Mollie account and you do not specify a payment method when creating a payment in the process() method, Mollie will not send a webhook when a payment is failed or canceled, it will just return you to the Mollie start screen where you can select another payment method. If you abandon the payment page, Mollie will send a webhook when the payment expires. The expiry time depends on the last payment method you attempted. The result of this is that Mollie will never send a webhook for 'canceled' or 'failed' statuses to your shop if you have enabled multiple payment methods within Mollie, only 'paid' and 'expired' will be used.

  • What to do when the user returns to the website after paying (or not paying): I have enabled a callback in the
    process() method. This callback requires you to implement a complete() method in your class which is called when the user returns to the website. I've made a complete() method that simply redirects you to the orders page regardless of the outcome of the payment. I am not sure if there is a better way to handle this.

  • Changing the sratus of the Mall order / payment: The method that gets called when the webhook is used will either return PaymentResult->fail() or PaymentResult->success() depending on the status of the Mollie payment. I have experimented with using Mall's built in OrderState model, but this model only contains order states for canceled, complete and new, so I am not sure how to handle expired payments.

@chocolata
Copy link
Author

Hi Guus,

Thank you so much for your work!! I've been doing some testing and came up with the following:

Regarding your first remark: could we do something like this? We do have to be mindful of other thousand and decimal separators one might set up in the currency configuration of the Mall Plugin:

number_format((float)$this->order->total_in_currency,2)

As far as your second comment is concerned: if the admin has multiple payment methods defined in their Mollie account, could we set up a separate payment gateway in the Mall plugin for each of those? We might define a payment gateway for each payment method in the Mollie account, and we could supply fields for the apikey, besides a dropdown with a list of all available payment methods? Would this be practical, you think? Or can we get it up and running in the current setup?

Regarding your third comment: could you have a look at the payment method "invoice" that is by default included in the Mall plugin? When we choose that payment method, the user is redirected to /checkout/done with a message: your order is completed. There's a button below that links to the overview of the orders. There the order is marked "payment pending". Would that be of any use for our usecase?

Regarding your fourth comment, I think we might ask the advice of Tobias here. I'll try to reach him regarding expired payments...

I hope these comments might be helpful. Let me know if there's anything else I could do.

@guus-frenken
Copy link
Contributor

Hi Maarten,

I have made some more progress:

  • The plugin now has the ability to specify a Mollie payment method when creating a payment. When creating a payment method in the "Mall: Payments" section of the settings, make sure that the "Code" field matches a Mollie payment method. When checking out an order, the plugin will check if the selected payment method is active in the Mollie account using the API. if the payment method is not active or otherwise invalid, the user will be redirected to the Mollie Checkout page that shows all possible payment methods.

  • Fixed formatting for the amount > value field using number_format() I believe this is safe because the $this->order->total_in_currency variable is always a float.

@chocolata
Copy link
Author

Thank you so much for your work. I'll be testing it out ASAP and let you know my findings!

@guus-frenken guus-frenken linked a pull request May 11, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants