Skip to content

auctifera-josed/cordova-plugin-cardflight

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

CardFlight Plugin

Cordova plugin for CardFlight

Security

Remember that all cordova code is exposed (client side) and you shouldn't store any private keys in code.

Use

This plugin defines global cardFlight object.

Although in the global scope, it is not available until after the deviceready event.

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    console.log(cardFlight);
}

Note: Plugin requires the following frameworks, although plugin adds them, recheck that are properly referenced in xcode project:

  • libstdc++.6.0.9.dylib
  • AVFoundation
  • AudioToolbox
  • MediaPlayer
  • MessageUI
  • ExternalAccessory
  • CoreGraphics //Sometimes this framework is not added. This can be manually added in xcode from Build Phases --> Link Binary With Libraries --> + --> CoreGraphics.framework --> Add

Install

Install using cordova plugin add https://github.com/auctifera-josed/cordova-plugin-cardflight

Example

cardFlight.setAccount('be*********************', 'acc_****************', function(err, res) {
    if (err) console.log(err);
    else console.log(res);
})
cardFlight.charge(100, 'USD', function(res) {
    console.log(res);
}, function(res) {
    console.log(res);
})

true = success | false = error (Activate logging to identify error)

Reference

  1. setAccount //Should be called first, calls readerInit
  2. getAccount
  3. charge
  4. refund
  5. getCurrentCard
  6. newSwipe
  7. setCurrency
  8. cancelTransaction
  9. addCardTypedView
  10. removeCardTypedView
  11. setLogging
  12. readerInit
  13. cardFlightEvent

API

The setAccount(apiKey, accountToken, callback) function sets the key, token and initializes the reader object.`

you need to set the account before using any other method

apiKey*

The CardFlight's Test/Production API key

accountToken*

The Merchant Account's token

callback

function(err,res){}

The charge(amount, success, error[, currency]) function creates a charge of the given amount to the last swiped/typed credit card. Charge event returns error if card is null

amount*

The amount to be charged

currency

Optional string to modify the currency, default is 'USD'

The refund(amount, chargeToken, success, error) function allows to refund the charge of the given token

amount*

The amount to be refunded

chargeToken*

The CardFlight's charge token (e.g ch_Wqi19gebijL-********)

The getCurrentCard(success, error) function returns a string containing the last 4 chars of the current credit card

The newSwipe(success, error) function sets the system to allow a new swipe

Note: - Convenient method to use if there is a Swipe Error event - Note that this method is called in the readerIsConnected event

The setCurrency(currency, success, error) function to set the default currency for all future charges

currency*

A ISO 4217 Currency Code (e.g USD, EUR)

The getAccount(success, error) function returns the current account token from the session manager

The cancelTransaction(success, error) function manually cancel the swipe process before the timeout duration has been reached or cancels an EMV transaction. Additionally it sets to null the reader, paymentView and card objects.

Note: This method should be call anytime the reader shouldn't be expecting a swipe to avoid weird behaviour.

The addCardTypedView(paymentView, success, error) function adds a CFTPaymentView to accept user input with card information. It takes a paymentView object to create the view.

This method overrides any previous view with the new one.

paymentView*

An object to create a paymentView, e.g:

{
  "x": 20,
  "y": 20,
  "width": 200,
  "height": 20,
  "keyboardAppearance": "dark",
  "border-color": {
    "red": 1.0,
    "green": 1.0,
    "blue": 1.0,
    "alpha": 1.0
  },
  "focus" : true
}
  • x*,y*: position on screen
  • width*, height*: size
  • keyboardApperance options:
    • dark
    • alert
    • default
    • light
  • focus*: indicates if view should be focus uppon creation

The removeCardTypedView(success, error) function removes from the super view the last created view with the method 'addCardTypedView'

The setLogging(logging, success, error) function switches the logging to on/off, convenient method for debugging.

logging*

True activates logging, false deactivates it

The readerInit(success, error) function initializes the reader object to start detecting CardFlight card reader.

This method is called from setAccount function

Listen to reader and card events as cases of the cardFlightEvent event, cases are:

  1. reader
  2. attached
  3. connected //Calls newSwipe method
  4. disconnected
  5. swipe
  6. card
  7. Swipe error
  8. XXXX //4 last card digits
  9. refund
  10. charge
  11. error

Charge and Refund events return a charge object:

{ 
  "amount": xxx,
  "amountRefunded": xxx,
  "createdDate": "YYYY-MM-DD HH:MM:SS Z",
  "isRefunded": bool,
  "token": "charge_secret_token"
 }
window.addEventListener('cardFlightEvent', function (e) {
  switch (e.dataType) {
    case 'reader':
      break;
    case 'card':
      break;
    case ...:
      ...
    default:
      console.log(e);
  }
});

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published