Setting Up for Development

Before you can start working on the Scandi integration, you need to set up a local environment

Creating a New App

First, make sure you have a working Magento app with Scandi installed. The easiest way to get this setup is by using create-magento-app with create-scandipwa-app!

Next, since we want to create a reusable extension that can be installed on multiple projects, we can initialize it with a single command. After checking that you have the scandipwa CLI utility installed, navigate to your theme's root directory and enter this command:

(don't forget to replace your-payment-provider with the actual payment provider name!)

scandipwa extension create your-payment-provider-scandi

This will automatically create a new extension, including some boilerplate configuration to get you started. It will also install the extension into your app.

Setting up the Payment Extension

In most cases, you'll also want to install the Magento payment integration extension. While it might not provide out-of-the-box support for working with Scandi, it will already include most of the payment logic that you need for the integration.

Next, you'll need to configure the extension. The configuration will vary across providers, but you'll most likely have to log in to your account on the payment provider's website to copy some credentials into your Magento configuration – check the extension's documentation for more details!

In our example, Mollie needs us to enter a few authentication secrets to connect the extension to the Mollie account. We also need to enable the different payment methods supported by Mollie.

Be sure to also enable test mode in the extension. This will allow you to ensure your extension is working correctly without needing to make real payments.

It might be a good idea to get an idea of how the Magento extension works before starting work on your Scandi integration. You could simply switch the theme to Luma and complete a

Sigh... Webhooks

Many payment workflows involve webhooks. Webhooks allow a third-party server (in this case the payment provider) to notify your Magento app when something of interest has happened – for example, when a payment has been completed or canceled.

Crucially, since the payment providers' servers need to be able to notify your app, the URL needs to be accessible to them. This means that you can't simply keep your app on localhost, because then your computer is the only one that can access the website. And of course, the payment provider isn't running on your computer, so they can't access your app.

Fortunately, there is a workaround! You can tunnel traffic from a publicly accessible address to your locally-running app. ngrok is a tool that allows you to do it for free.

Using ngrok

First, create a ngrok account, and install the ngrok tool. Configure ngrok as specified in the instructions on their website. Then, you should be able to create a tunnel from a public .ngrok.io URL to your localhost. The easiest way is to create a HTTP tunnel:

./ngrok http 80 --region eu

Note: the --region parameter is optional, but your requests might be faster if you specify a region that is close to where you are.

Now, your local app will be available to anyone that knows the ngrok URL – which will be displayed after running the above command. And "anyone" includes the payment service provider, so webhooks will work!

Don't forget to update the Magento base_url to the new ngrok URL. Otherwise, you'll keep getting redirected to your localhost address.

Last updated