iOS API

Import

import AffiniPaySDK

Card Entry (required)

The AFPCardEntryVC view controller allows the user to input credit/debit card information manually or using the AffiniPay card reader. A token that is returned from the AffiniPay Payment Gateway can then be used to make a charge.

Input

The input will be passed as an AFPTokenizationInitParams object with the following members:

ParameterTypeDescription
publicKeystringThe public key for your account obtained from OAuth login and used to create a one-time token.
amountstringThe requested charge amount in US cents, unformatted. For example, to charge $2.46, you should submit 246.
accountNamestringThe name of the account to receive payment, which will be shown on the Card Entry screen.
trustAccountbooleanWhether the requested account is a trust account.
requireCvvbooleanWhether CVV is required for a manual charge.
requireSwipeCvvbooleanWhether CVV is required for a charge using the card reader. An alert will be shown to get CVV from the end user.
disableCardReaderbooleanWhether all card reader actions and events (such as scan and detect) are disabled.

Output

The output will be returned as an AFPTokenizationResult object with the following members:

ParameterTypeDescription
amountstringThe requested charge amount given in US cents, unformatted. The AffiniPay Payment Gateway expects the charge in the same format. For example, USD $2.46 would be returned as “246”.
oneTimeTokenstringA temporary token given by the AffiniPay Payment Gateway that can be used to create a charge.
paymentDataSourcestringThe reason for payment failing to use EMV (Chip Scanning) and falling back to Magstripe (Swipe) instead.
posFieldsDictionaryAdditional parameters that describe the payment and verification method.
errorNSErrorAn error object returned from the server while generating a one-time payment token.
reasonstringAn error message returned from the server while generating a one-time payment token.

Interface

AffiniPaySDK

typedef void(^onReturnSwiperDataBlock_t)(NSDictionary* _Nullable data);
typedef void(^onReturnCardDataBlock_t)(NSDictionary* _Nullable data);
typedef void(^onReturnPaymentTokenBlock_t)(AFPTokenizationResult* _Nullable result);
typedef void(^onResetBlock_t)(void);
typedef void(^onDismissBlock_t)(void);
typedef void(^onCancelCvvAlertBlock_t)(void);

+ (AFPCardEntryVC* _Nullable)getCardEntryVC:(AFPTokenizationInitParams *_Nullable)params
onReturnSwiperData:(onReturnSwiperDataBlock_t _Nullable )onReturnSwiperData
onReturnCardData:(onReturnCardDataBlock_t _Nullable )onReturnCardData
onReturnPaymentToken:(onReturnPaymentTokenBlock_t _Nullable )onReturnPaymentToken
onReset:(onResetBlock_t _Nullable )onReset
onDismiss:(onDismissBlock_t _Nullable )onDismiss
onCancelCvvAlert:(onCancelCvvAlertBlock_t _Nullable )onCancelCvvAlert;

Example

// Input
let afpTokenInitParams = AFPTokenizationInitParams(publicKey: getPublicKey(),
                                amount: "100", // cents
                                accountName: accountName, // name of account to deposit
                                trustAccount: true,  // or false
                                requireCvv: true, // or false
                                requireSwipeCvv: true, // or false
                                disableCardReader: false, // or false
                                autoShowHideNavigationBar: true)

// Instantiate card entry view controller
self.afpCardEntryVC = AffiniPaySDK.getCardEntryVC(afpTokenInitParams, onReturnSwiperData: { (swiperData) in
            // swiperData
            print("swiperData: \(swiperData)")

        }, onReturnCardData: { (data) in
            // data
            print("data: \(data)")

            // show client details page            
            // ... the client details screen is going to be created by the partners

            self.clientVC = self.storyboard.instantiateViewController(withIdentifier: "ClientDetailsController") as? ClientDetailsController
            self.clientVC!.delegate = self // this is needed to get callback from the client details
            self.afpCardEntryVC?.navigationController?.pushViewController(self.clientVC!, animated: true)

        }, onReturnPaymentToken: { (result) in

            self.clientVC?.stopLoading() // stop loading at client details page
            if (result!.error) != nil {
                // error
            } else {
                print("Amount: \(amountString)")

                print("One time token: \(tokenId)"                
                // step: Create a charge on the backend using one token, account id, and amount                
                // ... The network layer code to create charge

                // step: Show Signature screen on successful charge                
                // ... the signature screen is going to be created by the partners                
                // ... the flow ends here

        }, onReset: {

            // callback on reset
            print("Block Called => onReset")

        }, onDismiss: {

            // callback on dismis
            print("Block Called => onDismiss")

        }, onCancelCvvAlert: {

            // callback on dismiss
            print("Block Called => onCancelCvvAlert")
            self.afpCardEntryVC!.dismiss()
        })
    }

// Push view controller
myNavigationController.pushViewController(cardEntryVC!, animated: true)

Screen highlights

  1. The amount to be charged.
  2. The account name, with a trust icon image if it is a trust account.
  3. The Card Number, Exp. Date, and CVV fields are for manual card entry.
  4. The button to scan and connect a bluetooth reader.
  5. The button to order a card reader from the website.
  6. The Back action in the navigation bar.
  7. The Cancel action in the navigation bar.
  8. For manual entry, the user taps this to go to the next step. The button is disabled if there are any input validation errors.