**
**
Version <= 1.4.x
- iOS 9.0 or Later
- Xcode 9
Version >= 1.5.x
- iOS 9.0 or Later
- Xcode 10
Framework Dependencies:
Accelerate AudioToolbox AVFoundation CoreGraphics CoreMedia CoreVideo Foundation MobileCoreServices OpenGLES QuartzCore Security UIKit CommonCrypto (Just for version 1.4)
Project Configuration
- ObjC in other linker flags in target
- lc++ in target other linker flags
- Disable Bitcode
Carthage
If you haven't already, install the latest version of Carthage
Add this to the Cartfile:
git "https://github.com/paymentez/paymentez-ios.git"
For Beta Versions:
git "https://github.com/paymentez/paymentez-ios.git" "master"
ObjC configuration
Set ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES
In Build Phases -> Embed Frameworks Uncheck "Copy Only When Installing"
PaymentezSDK is a dynamic framework (More Info) so you have to build each version for the desire target (simulator and device). To make the integration easy, you can follow these instructions in order to have just one Universal .framework file.
- Build the SDK and create .framework files
- If you want build yourself the SDK or you are using a new/beta version of Xcode . Download the project from github and run the following script inside the root folder
sh package.sh
This will create a /build folder where there are all the necesary .framework (simulator, iphoneos and universal)
- Or if you prefer you can download pre-compilled .framework files from Releases
- Drag the PaymentezSDK.framework (preferably Universal version) To your project and check "Copy Files if needed".
In Target->General : Add PaymentezSDK.framework to Embeeded Libraries and Linked Frameworks and Libraries
- Update the Build Settings with
Set ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES
In Build Phases -> Embed Frameworks Uncheck "Copy Only When Installing"
- If you use the Universal version and you want to upload to the appstore. Add Run Script Phase: Target->Build Phases -> + ->New Run Script Phase. And paste the following. Make sure that this build phase is added after Embed Frameworks phase.
bash "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/PaymentezSDK.framework/install_dynamic.sh"
Usage
Importing Swift
import PaymentezSDK
Setting up your app inside AppDelegate->didFinishLaunchingWithOptions. You should use the Paymentez Client Credentials (Just ADD enabled)
PaymentezSDKClient.setEnvironment("AbiColApp", secretKey: "2PmoFfjZJzjKTnuSYCFySMfHlOIBz7", testMode: true)
There are 3 ways to present the Add Card Form:
- As a Widget in a Custom View
- As a Viewcontroller Pushed to your UINavigationController
- As a ViewController presented in Modal
The AddCard Form includes: Card io scan, and card validation.
In order to create a widget you should create a PaymentezAddNativeController from the PaymentezSDKClient. Then add it to the UIView that will be the container of the Paymentez Form. The min height should be 300 px, and whole screen as width (270px without paymentez logo)
Note: When you are using the Paymentez Form as Widget. The Client custom ViewController will be responsible for the layout and synchronization (aka Spinner or loading)
The widget can scan with your phones camera the credit card data using card.io.
let paymentezAddVC = self.addPaymentezWidget(toView: self.addView, delegate: nil, uid:UserModel.uid, email:UserModel.email)
Objc
[self addPaymentezWidgetToView:self. addView delegate:self uid:@"myuid" email:@"myemail"];
Retrive the valid credit card from the PaymentezAddNativeController (Widget):
if let validCard = paymentezAddVC.getValidCard() // CHECK IF THE CARD IS VALID, IF THERE IS A VALIDATION ERROR NIL VALUE WILL BE RETURNED
{
sender?.isEnabled = false
PaymentezSDKClient.createToken(validCard, uid: UserModel.uid, email: UserModel.email, callback: { (error, cardAdded) in
if cardAdded != nil // handle the card status
{
}
else if error != nil //handle the error
{
}
})
}
Objc
PaymentezCard *validCard = [self.paymentezAddVC getValidCard];
if (validCard != nil) // Check if it is avalid card
{
[PaymentezSDKClient add:validCard uid:USERMODEL_UID email:USERMODEL_EMAIL callback:^(PaymentezSDKError *error, PaymentezCard *cardAdded) {
[sender setEnabled:YES];
if(cardAdded != nil) // handle the card status
{
}
else //handle the error
{
}
}];
}
self.navigationController?.pushPaymentezViewController(delegate: self, uid: UserModel.uid, email: UserModel.email)
Objc
[self.navigationController pushPaymentezViewControllerWithDelegate:self uid:@"myuid" email:@"[email protected]"]`;
self.presentPaymentezViewController(delegate: self, uid: "myuid", email: "[email protected]")
Objc
[self presentPaymentezViewControllerWithDelegate:self uid:@"myuid" email:@"[email protected]"];
If you present the Form as a viewcontroller (push and modal) you must implement the PaymetnezCardAddedDelegate Protocol in order to handle the states or actions inside the Viewcontroller. If you are using Widget implementation you can handle the actions as described above.
protocol PaymentezCardAddedDelegate
{
func cardAdded(_ error:PaymentezSDKError?, _ cardAdded:PaymentezCard?)
func viewClosed()
}
func cardAdded(_ error:PaymentezSDKError?, _ cardAdded:PaymentezCard?)
is called whenever there is an error or a card is added.
func viewClosed()
Whenever the modal is closed
If you want to do the scan yourself, using card.io
PaymentezSDKClient.scanCard(self) { (closed, number, expiry, cvv, card) in
if !closed // user did not closed the scan card dialog
{
if card != nil // paymentezcard object to handle the data
{
}
})
-ObjC
[PaymentezSDKClient scanCard:self callback:^(BOOL userClosed, NSString *cardNumber, NSString *expiryDate, NSString *cvv, PaymentezCard *card) {
if (!userClosed) //user did not close the scan card dialog
{
if (card != nil) // Handle card
{
}
}
}];
For custom form integrations Fields required
- cardNumber: card number as a string without any separators, e.g. 4111111111111111.
- cardHolder: cardholder name.
- expuryMonth: integer representing the card's expiration month, 01-12.
- expiryYear: integer representing the card's expiration year, e.g. 2020.
- cvc: card security code as a string, e.g. '123'.
let card = PaymentezCard.createCard(cardHolder:"Gustavo Sotelo", cardNumber:"4111111111111111", expiryMonth:10, expiryYear:2020, cvc:"123")
if card != nil // A valid card was created
{
PaymentezSDKClient.add(card, uid: "69123", email: "[email protected]", callback: { (error, cardAdded) in
if cardAdded != nil
{
//the request was succesfully sent, you should check the cardAdded status
}
})
}
else
{
//handle invalid card
}
ObjC
PaymentezCard *validCard = [PaymentezCard createCardWithCardHolder:@"Gustavo Sotelo" cardNumber:@"4111111111111111" expiryMonth:10 expiryYear:2020 cvc:@"123"];
if (validCard != nil) // Check if it is avalid card
{
[PaymentezSDKClient add:validCard uid:USERMODEL_UID email:USERMODEL_EMAIL callback:^(PaymentezSDKError *error, PaymentezCard *cardAdded) {
[sender setEnabled:YES];
if(cardAdded != nil) // handle the card status
{
}
else //handle the error
{
}
}];
}
Debit actions should be implemented in your own backend. For security reasons we provide a secure session id generation, for kount fraud systems. This will collect the device information in background
let sessionId = PaymentezSDKClient.getSecureSessionId()
Objc
NSString *sessionId = [PaymentezSDKClient getSecureSessionId];
Get Card Assets
let card = PaymentezCard.createCard(cardHolder:"Gustavo Sotelo", cardNumber:"4111111111111111", expiryMonth:10, expiryYear:2020, cvc:"123")
if card != nil // A valid card was created
{
let image = card.getCardTypeAsset()
}
Get Card Type (Just Amex, Mastercard, Visa, Diners)
let card = PaymentezCard.createCard(cardHolder:"Gustavo Sotelo", cardNumber:"4111111111111111", expiryMonth:10, expiryYear:2020, cvc:"123")
if card != nil // A valid card was created
{
switch(card.cardType)
{
case .amex:
case .masterCard:
case .visa:
case .diners:
default:
//not supported action
}
}
You can customize widget colors sample
paymentezAddVC.baseFontColor = .white
paymentezAddVC.baseColor = .green
paymentezAddVC.backgroundColor = .white
paymentezAddVC.showLogo = false
paymentezAddVC.baseFont = UIFont(name: "Your Font", size: 12) ?? UIFont.systemFont(ofSize: 12)
The customizable elements of the form are the following:
baseFontColor
: The color of the font of the fieldsbaseColor
: Color of the lines and titles of the fieldsbackgroundColor
: Background color of the widgetshowLogo
: Enable or disable Paymentez LogobaseFont
: Font of the entire formnameTitle
: String for the custom placeholder for the Name FieldcardTitle
: String for the custom placeholder for the Card FieldinvalidCardTitle
String for the error message when a card number is invalid
Before you can run the PaymentezStore application, you need to provide it with your APP_CODE, APP_SECRET_KEY and a sample backend.
- If you haven't already and APP_CODE and APP_SECRET_KEY, please ask your contact on Paymentez Team for it.
- Replace the
PAYMENTEZ_APP_CODE
andPAYMENTEZ_APP_SECRET_KEY
in your AppDelegate as shown in Usage section - Head to https://github.com/paymentez/example-java-backend and click "Deploy to Heroku" (you may have to sign up for a Heroku account as part of this process). Provide your Paymentez Server Credentials APP_CODE and APP_SECRET_KEY fields under 'Env'. Click "Deploy for Free".
- Replace the
BACKEND_URL
variable in the MyBackendLib.swift (inside the variable myBackendUrl) with the app URL Heroku provides you with (e.g. "https://my-example-app.herokuapp.com") - Replace the variables (uid and email) in UserModel.swift with your own user id reference