Skip to main content

Build on Mobile

This page details how MobilePay app payments should be implemented in your Android/iOS app.

Prerequisites and Assumptions

This guide assumes:

  • You already have backend services integrated with MobilePay APIs.
  • Your app uses minSdkVersion API 23 (Marshmallow, 6.0) or later.
  • You are generally familiar with developing applications on Android.
Make sure you are compliant with mobile application distribution service rules!

Using app payments for digital sales might not be allowed by some mobile application distribution services (Google Play, App Store, etc.) and might result in your application being removed. Please review the terms of service for the respective mobile application distribution services you use to ensure that you are compliant with their guidelines.

Create Payment

First, you'll need to create payment. To do this you should call your backend service that is implemented as described here. This service call should return a response that contains a deep link needed to launch the MobilePay app.

Starting MobilePay

MobilePay supports navigation via native Activity Result APIs and deep linking.

Activity Result or startActivityForResult APIs use standard Android functions and will launch MobilePay in your app process. This is the preferred way when integrating into a native Android app.

Let's open MobilePay with the deep link received from your backend.

Kotlin using Activity Result APIs (requires AndroidX Activity 1.2.0 (or above) or Fragment 1.3.0 (or above))
private val mobilePayContract = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
when (it.resultCode) {
SUCCESS_RESULT_CODE -> {}
REJECT_RESULT_CODE -> {}
FAILED_RESULT_CODE -> {}
UNKNOWN_RESULT_CODE -> {}
}
}

// Use the link received from your backend to launch MobilePay.
fun openMobilePay(deepLink: String) {
try {
val intent = Intent(Intent.ACTION_VIEW).apply {
data = Uri.parse(deepLink)
}
mobilePayContract.launch(intent)
} catch (exception: ActivityNotFoundException) {
// Inform the user that MobilePay is not installed or use these links to redirect the user to Play Store:
// DK: https://play.google.com/store/apps/details?id=dk.danskebank.mobilepay
// FI: https://play.google.com/store/apps/details?id=fi.danskebank.mobilepay
}
}

companion object {
private const val SUCCESS_RESULT_CODE = Activity.RESULT_OK
private const val REJECT_RESULT_CODE = Activity.RESULT_CANCELED
private const val FAILED_RESULT_CODE = 1
private const val UNKNOWN_RESULT_CODE = 2
}

Handling the Result

MobilePay can return these result codes:

  • SUCCESS_RESULT_CODE (Activity.RESULT_OK) - payment was successful and it is in reserved state.
  • REJECT_RESULT_CODE (Activity.RESULT_CANCELED) - user rejected the payment.
  • FAILED_RESULT_CODE (1) - user could not complete the payment due to invalid state of payment or the user's MobilePay account.
  • UNKNOWN_RESULT_CODE (2) - user attempted to do a payment, but because of network issues we could not determine if it was successful. (E.g., the user tries to do a payment, but it does not succeed due to network issues. Then the user decides to reject the payment and again receives a network error. At this point we cannot leave the user blocked in the MobilePay app, so we finish with this result code.) You should try to capture or at least check the state of these payments as they can be successful.

All done

Now everything should be ready for testing! Sandbox testing guide is here.

Make sure you are using the correct MobilePay app!

MobilePay supports multiple countries, but cross-country payments are not enabled.

Having troubles with this guide? Be sure to contact us .