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.
SDK Documentation includes tips for the order in which to create charges, and other information useful to implementing this plugin.
Please review the LICENSE file before proceeding. Copyright 2016 – 2017.
- 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.
- 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)
cordova plugin add https://github.com/loganthompson/cordova-cardflight.git
Access the cardflight
globally, available after the document's deviceReady
event.
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.
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,
});
Initialize the card reader. This method accepts a readerType argument, and is highly recommended for speed.
cardflight.initReader(successCallback, errorCallback, {
readerType: TYPE_ENUM // optional
});
Prepare the reader for a credit card swipe
cardflight.beginSwipe(successCallback, errorCallback);
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
});
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
});
Removes the keyed-entry payment view and hides keyboard
cardflight.endKeyed(successCallback, errorCallback);
Cancel the current transaction
cardflight.cancelTransaction(successCallback, errorCallback);
Run CardFlight's destroy method
cardflight.destroy(successCallback, errorCallback);
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
});
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
});
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.
Set listener on card swipe event (not the same as card or transaction responses; includes no data).
cardflight.registerOnCardSwiped(successCallback, errorCallback);
Set listener to detect when an EMV card is physically dipped.
cardflight.registerOnEMVCardDipped(successCallback, errorCallback);
Set listener to detect when an EMV card is physically removed.
cardflight.registerOnEMVCardRemoved(successCallback, errorCallback);
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);
Set listener for the event fired when a card reader is physically attached via the headphone jack.
cardflight.registerOnReaderAttached(successCallback, errorCallback);
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);
Set a listener for the physical reader's connecting
state (physically attached but not yet connected).
cardflight.registerOnReaderConnecting(successCallback, errorCallback);
Set a listener for the physical reader's connected
state (physically attached and connected).
cardflight.registerOnReaderConnected(successCallback, errorCallback);
Set a listener for the physical reader's disconnected
state (fired when unplugged).
cardflight.registerOnReaderDisconnected(successCallback, errorCallback);
Set a listener for when a connection attempt has been made but no reader was detected.
cardflight.registerOnReaderNotDetected(successCallback, errorCallback);
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);
Set listener for reader's low battery event.
cardflight.registerOnLowBattery(successCallback, errorCallback);
-
To begin an EMV charge you'll have to set the charge
amount
anddescription
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).
- iOS
- Android