Getting started with Payments in your App
Accepting payments in your app can improve conversion of orders from mobile devices. In this guide we will show you a basic example of integrating Mollie Payments in your iOS or Android App.
The code examples provided here are for illustrative purposes only and Mollie does not yet offer support on them.
Keep the guidelines of the platform you are developing on in mind
Every platform has it's own guidelines for accepting of rejecting apps in the App Store or Marketplace. See :ref:`app-store-r-r` for an in depth review.
Step 1: Create a Payment-creation script on your server
Storing API keys in your app is insecure. Hence, you need to create a script on your server what you app can call to create the payment for the app. The task of this script is to ensure that the Mollie APIs are called the way you want.
In particular, do not pass the amount from the app to your script but use your own business rules in the script to prevent users of your app from messing with your payments. Remember that the app is installed on a device outside of your control and thus untrusted.
Ensure that this file can only be called by genuine installations of your own app.
Step 2: Configure your app to accept the Redirect URL
We will be using a custom URL scheme to ensure your customer is redirected back to the app after the payment. Configure iOS or Android to link your URL scheme with your app.
Go to your
Info.plist file. Right click any blank area and select
Add Row to create a new key.
You’ll be prompted to select a key from a drop-down menu. Scroll to the bottom and select
URL types. This creates
an array item. You can further click the disclosure icon to expand it and you need to select
Item 0. Expand that
row as well and you should see
URL identifier. Double-click the value field and fill in your identifier. Most of the
time will this be the same as your bundle ID, e.g.
com.mollie.MollieApp. Click on the plus-button next to
URL Schemes from the drop-down menu. Expand the
URL Schemes row and another
Item 0 will show up.
Type in the value-field the scheme you want to handle, in our case
mollie-app. Make sure to pick a unique scheme.
AndroidManifest.xml file. Decide for what activity you want to support the URL scheme and add the following
code inside your
<activity> object. Replace
android:scheme with your URL scheme and
android:host with the
commando, in our example
Step 3: Call your server and open the Checkout URL
To initiate a payment from your app you need to call the file you have created in step 1 and open the browser with the Checkout URL you will receive.
Never send an amount to your server for creating a payment to prevent price changes between the payment and the actual price the customer needs to pay.
We use the OkHttp library in this example. Therefor, add the following line to
Step 4: Handle the redirect
We return the customer back to your App after the payment is paid or canceled. You should tell the App what to do with this request.
AppDelegate.swift file and add the
application(_:open:options) method. Split out the host into an array
so you can access the data that we return. Your method should return
true to let the device know that you can handle
Open the class that you have specified in your
AndroidManifest.xml as handler for the URL scheme. And should add the
handling code in the
Step 5: Share the status of the payment with your App
Since the API-key is not included in your App, you can not request the status of the payment directly from Mollie. Therefor you should create a way to inform your App about the status update of the payment from your server. An option you have is to use a Silence Notification. Please see the guides for iOS and Android about how to integrate this in your App.