Skip to content

Cordova plugin to access the Card Flight SDK from JavaScript

License

Notifications You must be signed in to change notification settings

loganthompson/cordova-cardflight

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CardFlight Cordova Plugin v 2.0

This plugin allows direct interactions with the native CardFlight SDK through JavaScript functions in your Cordova app. This includes creating EMV, swipe and keyed credit card charges, among other features.

iOS CardFlight SDK Version 3.6

SDK Documentation includes tips for the order in which to create charges, and other information useful to implementing this plugin.

Optimized for Android CardFlight SDK Version 3.2.7

LICENSE:

Please review the LICENSE file before proceeding. Copyright 2016 – 2017.

New in 2.0

  • Dynamic metadata! Just pass a 'metadata' object with other charge params
  • setApiTokens no longer automatically starts the reader. This is extremely helpful if you don't want the SDK to ask for microphone permissions at startup (and just provides more control).
  • Adds Android support
    • Note: Android version does not yet include keyed entry view.

New in 1.1

  • May now pass 'currency' variable upon charge creation
  • Can get readerState through plugin (string value)
  • Can initalize reader separately from setApiKeys function if needed
  • Adds refund method
  • Adds more callbacks (Reader Connecting state)
  • Adds support for info callbacks (tokens, sdk version)

Install

cordova plugin add https://github.com/loganthompson/cordova-cardflight.git

Global Object

Access the cardflight globally, available after the document's deviceReady event.

Getting Started

The callbacks for readerAttached, readerConnected and readerDisconnected will set themselves immediately, when the plugin receives Cordova's onCordovaReady event. On the native side, the reader itself is not initialized by the SDK until you set the API tokens.

Example:

document.addEventListener('deviceready', function() {
  if (window.cordova) {
    // Initialize cardflight SDK
    cardflight.setApiTokens(successCallback, errorCallback, {
      apiKey: YOUR_CARDFLIGHT_API_KEY,
      accountToken: YOUR_CARDFLIGHT_ACCOUNT_TOKEN,
    });
  }
});

This will run the SDK's setApiTokens method using given credentials.

After success, the plugin returns the bool value 'emvReady' to your successCallback. The CardFlight SDK is now initialized and ready to continue.

Methods

cardflight.setApiTokens()

Set API tokens to initalize CardFlight with apiKey and accountToken values. Requires apiKey and accountToken arguments.

cardflight.setApiTokens(successCallback, errorCallback, {
    apiKey: YOUR_CARDFLIGHT_API_KEY
    accountToken: YOUR_CARDFLIGHT_ACCOUNT_TOKEN,
});

cardflight.initReader()

Initialize the card reader. This method accepts a readerType argument, and is highly recommended for speed.

cardflight.initReader(successCallback, errorCallback, {
    readerType: TYPE_ENUM // optional
});

cardflight.beginSwipe()

Prepare the reader for a credit card swipe

cardflight.beginSwipe(successCallback, errorCallback);

cardflight.beginEMV()

Begin an EMV transaction with setup information, including amount and optional description

cardflight.beginEMV(successCallback, errorCallback, {
    amount: CHARGE_AMOUNT, // String value with decimal e.g. '5.00' or '.50'
    description: CHARGE_DESCRIPTION // optional
});

cardflight.beginKeyed()

Trigger keyed entry and show input view. View will appear a little more than 1/4 down the screen, above cordova webview. Enable zip by passing optional {zip:true}. Default bool value = NO

cardflight.beginKeyed(successCallback, errorCallback, {
    zip: BOOL // optional
});

cardflight.endKeyed()

Removes the keyed-entry payment view and hides keyboard

cardflight.endKeyed(successCallback, errorCallback);

cardflight.cancelTransaction()

Cancel the current transaction

cardflight.cancelTransaction(successCallback, errorCallback);

cardflight.destroy()

Run CardFlight's destroy method

cardflight.destroy(successCallback, errorCallback);

cardflight.processCharge()

Process a payment of any type. *Required arguments: amount, type ('emv', 'swipe' or 'keyed') Optional arguments: description, currency, metadata

*For emv charges, you can leave off amount and description, as they won't be used, but it is good practice to process charges with all available arguments.

In the case of an emv Transaction results of any type will be sent through registerOnTransactionResult callbacks.

cardflight.processCharge(successCallback, errorCallback, {
    type: CHARGE_TYPE,
    amount: CHARGE_AMOUNT, 
    description: CHARGE_DESCRIPTION, // optional
    currency: 'USD', // example, optional
    metadata: {} // optional
});

cardflight.uploadSignature()

Upload signature PNG data if/when required. Accepts a single argument data as base64 encoded string.

cardflight.uploadSignature(successCallback, errorCallback, {
    data: DATA // base64 encoded string of png signature image
});

Register Listener Callbacks

The above methods return a callback immediately, the id of which does not need to last. But for listeners that persist and need to be ready for an event to fire in the future, we have to register those callbacks. Use the following methods to register (or re-register) callbacks for a given event.


cardflight.registerOnCardSwiped()

Set listener on card swipe event (not the same as card or transaction responses; includes no data).

cardflight.registerOnCardSwiped(successCallback, errorCallback);

cardflight.registerOnEMVCardDipped()

Set listener to detect when an EMV card is physically dipped.

cardflight.registerOnEMVCardDipped(successCallback, errorCallback);

cardflight.registerOnEMVCardRemoved()

Set listener to detect when an EMV card is physically removed.

cardflight.registerOnEMVCardRemoved(successCallback, errorCallback);

cardflight.registerOnReaderResponse()

Set listener to receive updates for valid keyed card responses (will include card JSON with last4 and brand), invalidKeyedResponse (no card), readerCardResponse (card JSON with name & last4), readerSwipeDidCancel, and emvCardResponse (card JSON).

To handle transaction results of different types in different ways, call registerOnReaderResponse and pass a new successCallback whenever you change transactions (from keyed to swipe, for example).

cardflight.registerOnReaderResponse(successCallback(card), errorCallback);

cardflight.registerOnReaderAttached()

Set listener for the event fired when a card reader is physically attached via the headphone jack.

cardflight.registerOnReaderAttached(successCallback, errorCallback);

cardflight.registerOnEMVMessage()

Set a listener to receive all EMV instruction/status updates during transaction, which is useful for showing "processing" status, "Approved," "Remove Card" etc.

Returns string containing the message.

cardflight.registerOnEMVMessage(successCallback(message), errorCallback);

cardflight.registerOnReaderConnecting()

Set a listener for the physical reader's connecting state (physically attached but not yet connected).

cardflight.registerOnReaderConnecting(successCallback, errorCallback);

cardflight.registerOnReaderConnected()

Set a listener for the physical reader's connected state (physically attached and connected).

cardflight.registerOnReaderConnected(successCallback, errorCallback);

cardflight.registerOnReaderDisconnected()

Set a listener for the physical reader's disconnected state (fired when unplugged).

cardflight.registerOnReaderDisconnected(successCallback, errorCallback);

cardflight.registerOnReaderNotDetected()

Set a listener for when a connection attempt has been made but no reader was detected.

cardflight.registerOnReaderNotDetected(successCallback, errorCallback);

cardflight.registerOnTransactionResult()

Set a listener for transaction results of all types. If the charge was successful and was of type emv, the callback will receive a BOOL value for signatureRequired.

cardflight.registerOnTransactionResult(successCallback(signatureRequired), errorCallback);

cardflight.registerOnLowBattery()

Set listener for reader's low battery event.

cardflight.registerOnLowBattery(successCallback, errorCallback);

Tips

  • To begin an EMV charge you'll have to set the charge amount and description before the credit card is ever used. This differs from a swiped transaction, in which you'll get card information upfront and then send these arguments after the fact.

  • Watch the logs in Xcode while debugging (not just the browser).

Supported Platforms

  • iOS
  • Android

About

Cordova plugin to access the Card Flight SDK from JavaScript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published