iOS integration
This page explains the steps to integrate Client Side Encryption with your iOS application using CocoaPods, or manually.
Create your RSA key pair , and access your key
Note: View our iOS terms of use
Libraries
CocoaPods repository:
https://cocoapods.org/?q=worldpaycse Online generated API documentation:
http://cocoadocs.org/docsets/WorldpayCSE/ GitHub repository:
https://github.com/Worldpay/worldpay-cse-lib-iosREPO
Create your RSA key pair
CSE works using a 2048 bit RSA key pair which is made up of a public key and a private key. The public key must be supplied to the CSE library, and is used to encrypt the sensitive card details.
The private key exists within a secure environment at Worldpay. It is never transmitted and is not visible to any member of staff at Worldpay.
To create a key pair:
Log in to the Merchant Admin Interface (MAI) and click Client Side Encryption in the left panel.
Enter the description of the key, and then click Generate key.
The key pair has now been generated, and you'll be able to use the public key to encrypt card details.
Note: You can create more than one key. This is useful, for example, if you want to roll your keys to change them after a period of time. You can also disable a disused key. To learn more see
Access your key
To build the key into your payment page, you must view it:
Click View key on the key you wish to view. You'll be taken to a page which shows the key in two different formats:
Public key
This is the whole key in its entirety.
JavaScript formatted key
This is your formatted key. It has been formatted to allow you to simply copy it into your payment page.
Click the Client Side Encryption button at the bottom of the page to return to the main page.
Note: Although sensitive information is encrypted, there is no change in the way Worldpay processes a payment.
Installation
With CocoaPods
CocoaPods is a dependency manager for Objective-C and Swift, which automates the process of using 3rd-party libraries such as WorldpayCSE in your projects.
Podfile
platform :ios, '7.0'
pod 'WorldpayCSE'
Alternative: Manual installation
To use the manual method:
Download and import WorldpayCSE.framework and openssl.framework into your project. Use the
GitHub releases page for this.In Xcode add -ObjC to Other Linker Flags from Build Settings.
Usage
Three methods of usage are covered below:
Objective-C
Import the WorldpayCSE header file
#import <WorldpayCSE/WorldpayCSE.h
#import <WorldpayCSE/WorldpayCSE.h
Create the WorldpayCSE object
WorldpayCSE *wpCSE = [WorldpayCSE new];
Set the public (RSA) key
To set the public key (to identify you on our server):
NSError *error = nil;
[wpCSE setPublicKey:@"1#10001#00ccca2c4ef80be7f7a98d5e0eef7e5e6eafe700ef054"
"c07fa73cf86cd78d141f923cff2fb70afb40be36ec78c7a334ef2"
"3451c34cc8df03c2f496cd7f4fcccfd35aba72417c859d7e5e960"
"a5d1667010bb6d9d87b12d836405a5fb11ba28bb3a5e98e1c89d0"
"65fc47de9d11bfac053b3d6550207752724d9fa31ec2255d4952a"
"0dd0dc4f2be8a669b48eb247a1df5d94d921435af66588568999e"
"6a984152c53af211aab64edcd94a0ce1aceb66c50c0d3c074bac3"
"0d6f0ba81a367a03c3b94f17a6b896d34360dd7f459b715555dc0"
"8ece11fc451ffe26a089a93122a699958d2ab8a4da4d2586474fc"
"6e777a558d802381488c24a74cff4fcce3104e727ede3"
error:&error];
Set up the card data
WPCardData *cardData = [WPCardData new];
cardData.cardNumber = @"4444333322221111";
cardData.cvc = @"123";
cardData.expiryMonth = @"11";
cardData.expiryYear = @"2020";
cardData.cardHolderName = @"John Doe";
Validate and encrypt the card data
NSString encryptedData = [wpCSE encrypt:cardData error:&;error];
if (error) {
//handle error
//to get card data validation error call
//alternatively there is a convenient method [WorldpayCSE validate:(WPCardData)data]
//that can be used for similar purpose
if (error.code == WPErrorInvalidCardData) {
NSArray *cardValidationErrors = error.userInfo[kWPErrorDetailsKey];
//process card validation errors
}
}
Swift 2.0
Import the WorldpayCSE header file
import WorldpayCSE
Create the WorldpayCSE object
let wpCSE : WorldpayCSE = WorldpayCSE()
Set the public (RSA) key
To set the public key (to identify you on our server):
do {
try wpCSE.setPublicKey(
"1#10001#00ccca2c4ef80be7f7a98d5e0eef7e5e6eafe700ef054" +
"c07fa73cf86cd78d141f923cff2fb70afb40be36ec78c7a334ef2" +
"3451c34cc8df03c2f496cd7f4fcccfd35aba72417c859d7e5e960" +
"a5d1667010bb6d9d87b12d836405a5fb11ba28bb3a5e98e1c89d0" +
"65fc47de9d11bfac053b3d6550207752724d9fa31ec2255d4952a" +
"0dd0dc4f2be8a669b48eb247a1df5d94d921435af66588568999e" +
"6a984152c53af211aab64edcd94a0ce1aceb66c50c0d3c074bac3" +
"0d6f0ba81a367a03c3b94f17a6b896d34360dd7f459b715555dc0" +
"8ece11fc451ffe26a089a93122a699958d2ab8a4da4d2586474fc" +
"6e777a558d802381488c24a74cff4fcce3104e727ede3", error: ())
} catch error as NSError {;
// handle error
}
Set up the card data
let cardData : WPCardData = WPCardData()
cardData.cardNumber = "4444333322221111"
cardData.cvc = "123"
cardData.expiryMonth = "11"
cardData.expiryYear = "2020"
cardData.cardHolderName = "John Doe"
Validate and encrypt the card data
do {
let encryptedData = try wpCSE.encrypt(cardData)
} catch let error as NSError {
//to get card data validation error call
//alternatively there is a convenient method WorldpayCSE.validate(data: WPCardData!)
//that can be used for similar purpose
let errorCode = WPErrorCode(rawValue: (UInt)(error.code))
if errorCode == WPErrorCode.InvalidCardData {
let cardValidationErrors = error.userInfo[kWPErrorDetailsKey];
//handle card validation errors
}
}
Swift 1.2
Import the WorldpayCSE header file
import WorldpayCSE
Create the WorldpayCSE object
let wpCSE : WorldpayCSE = WorldpayCSE()
Set the public (RSA) key
To set the public key (to identify you on our server):
var error : NSError?
wpCSE.setPublicKey("1#10001#00ccca2c4ef80be7f7a98d5e0eef7e5e6eafe700ef054" +
"c07fa73cf86cd78d141f923cff2fb70afb40be36ec78c7a334ef2" +
"3451c34cc8df03c2f496cd7f4fcccfd35aba72417c859d7e5e960" +
"a5d1667010bb6d9d87b12d836405a5fb11ba28bb3a5e98e1c89d0" +
"65fc47de9d11bfac053b3d6550207752724d9fa31ec2255d4952a" +
"0dd0dc4f2be8a669b48eb247a1df5d94d921435af66588568999e" +
"6a984152c53af211aab64edcd94a0ce1aceb66c50c0d3c074bac3" +
"0d6f0ba81a367a03c3b94f17a6b896d34360dd7f459b715555dc0" +
"8ece11fc451ffe26a089a93122a699958d2ab8a4da4d2586474fc" +
"6e777a558d802381488c24a74cff4fcce3104e727ede3", error: &error)
if (error != nil) {
// handle error
}
Set up the card data
let cardData : WPCardData = WPCardData()
cardData.cardNumber = "4444333322221111"
cardData.cvc = "123"
cardData.expiryMonth = "11"
cardData.expiryYear = "2020"
cardData.cardHolderName = "John Doe"
Validate and encrypt the card data
let encryptedData = wpCSE.encrypt(cardData, error: &error)
if (error !=nil) {
// handle error
//to get card data validation error call
//alternatively there is a convenient method WorldpayCSE.validate(data: WPCardData!)
//that can be used for similar purpose
let errorCode = WPErrorCode(rawValue: (UInt)(error!.code))
if errorCode == WPErrorCode.InvalidCardData {
let cardValidationErrors: = AnyObject? = error!.userInfo?[kWPErrorDetailsKey];
// handle card validation errors
}
}
Terms of use
You can find the terms of use for iOS in