umweltdk / cordova-mobilepay-appswitch

Cordova plugin for MobilePay AppSwitch
Other
1 stars 1 forks source link

cordova-mobilepay-appswitch

Cordova plugin for MobilePay AppSwitch

Usage

window.mobilepay.isMobilePayInstalled(onisinstalled)

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

  console.log(payment)
}

API

window.mobilepay.isAppSwitchInProgress

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:

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: https://github.com/MobilePayDev/MobilePay-AppSwitch-SDK/wiki/Error-handling

Install

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:

ISC