Skip to content

Latest commit

 

History

History
79 lines (60 loc) · 2.07 KB

README.md

File metadata and controls

79 lines (60 loc) · 2.07 KB

Description

Cordova integration with SumUp's Android and iOS implementations.

Installation

Add the plugin: cordova plugin add https://github.com/storepilot/cordova-plugin-sumup

Usage

Importing the plugin (note, the plugin does NOT use global variables):

import * as SumUp from 'cordova-plugin-sumup';

Authenticating

Login to SumUp

SumUp.login(apikey, accessToken?: string): Promise<void>

Supports an optional access token.

  • If no access token is given, a login screen will be shown.
  • If an error occurs, the promise is rejected with a SumUpError object.

After logging in, you need to keep the access token up to date using (expires every hour):

SumUp.auth(apikey, accessToken: string): Promise<void>

Log out using SumUp.logout()

Taking Payments

SumUp.pay(amount: number, currencycode: string, title: string): Promise<SumUpPayment>

Example usage:

async pay(payment: Payment) {
  try {
    const sumUpPayment = await SumUp.pay(payment.amount, payment.currency, 'My Business');
    const transactionCode = sumUpPayment.transaction_code;
    const cardName = sumUpPayment.card_type;
  } catch (e) {
    if (e.code === 5) {
      console.error('Token expired')
    }

    e.code = SumUpErrorCodes.PAYMENT_FAILED;
    throw e;
  }
}

Preparing the terminal

prepare(): Promise<void>

This will wake the terminal up. Beware, this can cause issues in the native plugin if used too liberally, see sumup/sumup-android-sdk#57

Note SumUpPayment is an interface of the type:

interface SumUpPayment {
    transaction_code: string;
    card_type: string;
    merchant_code: string;
    amount: number;
    tip_amount: number;
    vat_amount: number;
    currency: string;
    status: string;
    payment_type: string;
    entry_mode: string;
    installments: number;
  }

Misc

SumUp.settings(): Promise<void>

Opens the settings page.

FINAL NOTES

This is forked from https://github.com/nuvoPoint/cordova-plugin-sumup and edited to allow programmable apikey