mollie / magento2

Mollie Payments for Magento 2
https://www.mollie.com
Other
101 stars 53 forks source link

Allow testing on a localhost environment #263

Closed evs-xsarus closed 4 years ago

evs-xsarus commented 4 years ago

Allow a configuration where it's not needed that the server is reachable by Mollie. Thus allowing testing op payments on:

Backend changes A new testmode or configuration can be added to indicate this Magento instance isn't reachable from the outside world.

When ommitting the webhook-URL, payment can properly be tested.

The following diff uses the existing configuration and only sets the webhook URL in live mode.

--- mollie/magento2/Service/Order/Transaction.php
+++ mollie/magento2/Service/Order/Transaction.php
@@ -59,6 +59,10 @@
      */
     public function getWebhookUrl()
     {
-        return $this->urlBuilder->getUrl('mollie/checkout/webhook/', ['_query' => 'isAjax=1']);
+        if ($this->config->getValue(\Mollie\Payment\Config::GENERAL_TYPE, ScopeInterface::SCOPE_STORE) == 'live') {
+            return $this->urlBuilder->getUrl('mollie/checkout/webhook/', ['_query' => 'isAjax=1']);
+        }
+
+        return '';
     }
 }

Additional context This would solve issue https://github.com/mollie/magento2/issues/230

The document states:

webhookUrl, string, OPTIONAL Set the webhook URL, where we will send payment status updates to. Note The webhookUrl is optional, but without a webhook you will miss out on important status changes to your payment. The webhookUrl must be reachable from Mollie’s point of view, so you cannot use localhost. If you want to use webhook during development on localhost, you must use a tool like ngrok to have the webhooks delivered to your local machine.

NB Other PSP's don't have this requirement where the environment must be reachable from the outside world.

Frank-Magmodules commented 4 years ago

Hi @evs-xsarus, thank you for the issue report and suggestion. Removing the webhook URL from test account payments indeed fixes this issue. However, the webhook is a vital part of the module where Mollie signals the store to fetch new status updates about payments.

Disabling this part opens up a bunch of new issues, where the module is not 100% working, so testings this without a webhook is not failsafe.

We will discuss this internally on how to get a more robust solution (besides working with NGROK that is 100% failsafe and a better way of testing this).

evs-xsarus commented 4 years ago

@Frank-Magmodules I understand. This might help your discussion: we develop on localhost and don't need the webhooks working on it yet. For our client, we have setup a testserver that's behind basic authentication. If it's possible to set those credentials in Mollie, than webhooks can work. When the site is deployed to production, we'll always perform tests on that server which is publicly available. Webhooks will work then.

Marvin-Magmodules commented 4 years ago

Hi @evs-xsarus, we have added this request to the roadmap and will implement a option for this in an upcoming release!

JeroenBoersma commented 4 years ago

A simple(r) check could be the use of $bootstrap->isDeveloperMode(). Which als makes it testable...

Another options would be the possibility to whitelist development domains in the backend of Mollie, but that would move the responsibility somewhere where not everyone should have access too.

Frank-Magmodules commented 4 years ago

Hi @evs-xsarus, we are happy to share that we've just released the new 1.16.0 version that has improvements for using the Mollie module on a localhost environment. It is now possible to disable or set a custom webhook URL. This setting has only effect when the test modus is enabled. This setting is ignored when live modus is active.

peterjaap commented 3 years ago

This is the way to set this undocumented feature;

magerun2 config:store:set payment/mollie_general/use_webhooks disabled

You can't use bin/magento config:set because the path isn't set in the adminhtml/system.xml file, so you also can't set it through the backend.

sprankhub commented 1 year ago

This is now part of system.xml, so that you can also set it via config:set and lock it if you want to.