Cordova plugin for MobilePay AppSwitch
Last updated 2 years ago by emilbayes .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install cordova-mobilepay-appswitch 
SYNC missed versions from official npm registry.


Cordova plugin for MobilePay AppSwitch



function onisinstalled (err, isinstalled) {
  if (err) throw err // fatal error
  if (!isinstalled) return // Could open appstore to mobilepay installation

  window.mobilepay.setupWithMerchantId('APPDK0000000000', 'umwdev', onsetup)

function onsetup (err) {
  if (err) throw err // Fatal error

  var orderid = 'Order ID should be between 4 and 50 bytes (not same as string.length)'
  var price = 100.123 // Be careful with decimals. Doubles are not great for money
  window.mobilepay.beginMobilePaymentWithPayment(orderid, price, onpayment)

function onpayment (err, payment) {
  if (err) throw err // fatal error




Property indicating whether a payment is in progress. Any MobilePay method while this is happening will most likely cause an error.

window.mobilepay.isMobilePayInstalled(cb(err, isInstalled))

Check if the MobilePay (Denmark) app is installed.

window.mobilepay.setupWithMerchantId(merchantId, merchantUrlScheme, [options], cb(err))

Initialize MobilePay with your merchantId and merchantUrlScheme. Merchant id is provided by MobilePay A/S, the url scheme is iOS only, but must be unique. For testing a merchantId of APPDK0000000000 can be used.

options include:

  • returnSeconds: How long is the MobilePay receipt shown. Default 5 seconds. Allowed range is 0 - 9, both inclusive.
  • timeoutSeconds: How long is the user given before the payment errors. Default 0 seconds (infinite). Allowed range is 0 - 1200, both inclusive.

window.mobilepay.beginMobilePaymentWithPayment(orderId, productPrice, cb(err, payment))

orderId must be globally unique as it is a mechanism from MobilePay to prevent double payments in case of failure. Two identical orderIds created more than 24 hours apart will get different transaction id's, but still be considered the same order. Notice that err is not a Javascript Error object, but the below object with success === false, cancelled === false and the errorCode and errorMessage properties set.

Payment will be an object of:

  // These properties are always present
  orderId: String,
  success: Boolean,
  cancelled: Boolean,

  // These properties are only present if
  // success === true && cancelled === false
  // (cancelled is always the negation of success)
  transactionId: String,
  signature: String,
  productPrice: Number,
  amountWithdrawnFromCard: Number

  // These properties are only present when called on err
  errorCode: Number,
  errorMessage: String

Errors are documented here:


cordova plugins add cordova-mobilepay-appswitch \
  --variable WIDGET_ID=io.cordova.hellocordova \ # Replace this with your id
  --variable URL_SCHEME=hellocordova # Replace this with your unique identifier (iOS only)

Known Issues

MobilePay AppSwitch SDK does not list any known issues, however during the development of this plugin, several issues have been found and reported to MobilePay, but are deemed "not a priority" by MobilePay:

  • On iOS MobilePay SDK represents prices as float and not double, which means that prices such as 1.26 become 1.259999…
  • The MobilePay list of error codes is not exhaustive. For example on iOS you may sometimes get errorCode 1001 due to technical errors.
  • Sometimes the AppSwitch may fail if any Javascript errors happen after beginMobilePaymentWithPayment but before the AppSwitch happened. This will still open the MobilePay app, but not show any AppSwitch, while the SDK in the origin app is in the isAppSwitchInProgress === true state. There is no API to force clear this state, except restart the origin app.
  • The previous error has also been observed when switching back and fourth between the origin app and MobilePay.
  • The Android JAR file is included in this repository as it is not available on any public package manager. The iOS SDK is downloaded from CocoaPods



Current Tags

  • 1.2.1                                ...           latest (2 years ago)

5 Versions

  • 1.2.1                                ...           2 years ago
  • 1.2.0                                ...           2 years ago
  • 1.1.1                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 1
Last Month 1
Dependencies (1)
Dev Dependencies (2)
Dependents (0)

Copyright 2014 - 2016 © |