0.0.5 • Published 7 months ago

cordova-plugin-payengine-softpos v0.0.5

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
7 months ago

cordova-plugin-payengine-softpos

Overview

cordova-plugin-payengine-softpos is a Cordova plugin that enables seamless integration of payment processing capabilities into mobile applications. This plugin provides a simple and efficient way to handle payments on both iOS and Android platforms.

Features

  • Cross-Platform Support: Compatible with both iOS and Android devices.
  • Easy Integration: Simple API for incorporating payment processing into your app.
  • Secure Transactions: Ensures secure handling of payment information.

Installation

To install the plugin, run the following command in your Cordova project directory:

cordova plugin add cordova-plugin-payengine-softpos

Usage

After installing the plugin, you can use it in your JavaScript code as follows:

This plugin includes type support. If you're using JavaScript, you can annotate it as follows:

/**
 * @type {import("cordova-plugin-payengine-softpos").PayEngineDevicePlugin}
 */
var PayEngineDevicePlugin = window.PayEngineDevicePlugin;

Initialize and Register Callbacks

/**
 * @param {import("cordova-plugin-payengine-softpos").EventData} params
 */
var callbackHandler = function (params) {
    console.log(JSON.stringify(params));
    if (typeof params === 'object') {
        var { method, error, transactionId, completed, activationCode: activeCode, terminalInfo } = params;
        switch (method) {
            case 'criticalError':
                alert(error);
                break;
            case 'onInitFailed':
            case 'onConnectionFailed':
                status.innerHTML = getErrorMessage(error);
                break;
            case 'onActivationRequired':
                isActivationRequired = true;
                activationCode = activeCode;
                status.innerHTML = "Please activate using this code: " + activationCode;
                break;
            case 'onActivationStarting':
                isActivationRequired = false;
                status.innerHTML = "Activating device...Merchant ID: " + terminalInfo.merchantId;
                break;
            case 'onActivationProgress':
                status.innerHTML = `Activating device... ${completed}%`;
                break;
            case 'onConnected':
                if (!isConnected) {
                    // Set ready
                    status.innerHTML = "Ready to process";
                    btnTransaction.classList.add('show');
                }
                break;
            case 'onTransactionCompleted':
                alert(`Transaction succeeded. Transaction ID: ${transactionId}`);
                break;
            case 'onTransactionFailed':
                alert(`Transaction failed. ${error}`);
                break;
        }
    }
}

var errorHandler = function (err) {
    alert(JSON.stringify(err))
}

document.addEventListener('deviceready', function() {
    // Initialize the payment engine
    PayEngineDevicePlugin.initialize({
      environment: 'sandbox', // Options: sandbox | production
      merchantId: '<YOUR-MERCHANT-ID>', // Optional; omit to allow manual registration in the merchant portal
      mode: PayEngineDevicePlugin.transactionModes.DEVICE // Optional; controls transaction initiation mode. DEVICE = app only, COMPANION = terminal (API) only, FULL = both terminal and app
    }, callbackHandler, errorHandler);
});

Maintain the Connection

To ensure reliable device connectivity, implement these event listeners in your app:

// Handle app resume
document.addEventListener('resume', function() {
    if (initialized) {
        PayEngineDevicePlugin.connect()
            .then(() => {
                console.log('Device connection restored');
            })
            .catch(error => {
                console.error('Failed to restore device connection:', error);
            });
    }
}, false);

For optimal connection management, you should:

  • Reconnect when the app resumes from background
  • Monitor connection state through the callback handler

Making a Payment

To make a payment, use the following method:

PayEngineDevicePlugin.startTransaction({
  amount: 1.00,
  currencyCode: 'USD',
  transactionData: {
    data: {
        sales_tax: 0.50,
        order_number: '7874646254'
    }
  }
}, function() {
    console.log("Payment request successful");
}, function(error) {
    console.error("Payment request failed: ", error);
});

The transactionData property accepts all parameters from Sale API

License

Copyright (C) 2024 PayEngine. (https://www.payengine.co)

0.0.5

7 months ago

0.0.4

7 months ago

0.0.3

9 months ago

0.0.2

9 months ago

0.0.1

9 months ago