Workflow
In Scope
Out of Scope
Custom UI
In Scope Examples
Out of Scope Examples
To submit a <xCommand> request, first configure the SDK with:
- an xKey value obtained from Cardknox
- a software name value; a short name for your application
- a software version value; the current version of your software
- a version value; the current Cardknox Gateway version 4.5.9
1
CardknoxSDK.setPrincipalKey("Your xKey value");
2
CardknoxSDK.setxSoftwareName("Your app name", xSoftwareVersion: "1.0.0", xVersion: "4.5.9");
Create a Cardknox SDK object. A good place is the “view appear” method. This object will be used to create “request” objects.
1
func viewDidAppear()
2
{
3
// Example of a "view appear" method in a SwiftUI View
4
// Store the object instance as a @State in the View for later use
5
let cardknoxSDKDirect = CardknoxSDKDirect.create() as? CardknoxSDKDirect;
6
}
Register the “view appear” method with the “body” parameter
struct InScopeView : View
{
var body: some View
{
// Using NavigationView as a View example
NavigationView{}
.onAppear(perform: viewDidAppear)
}
}
Destroy the Cardknox SDK object to free resources when SDK will no longer be used:
1
cardknoxSDKDirect.destroy();
Next, create a transaction parameters object:
1
let prms : TransactionParameters = TransactionParameters.init()
Specify the required parameters:
1
prms.xCommand = "<xCommand>";
2
prms.xAmount = 1.23;
CHANGE <xCommand>
Specify the additional parameters for the <xCommand> transaction type:
If selected Transaction type is cc:sale, cc:credit, cc:authonly
1
prms.xCardNum = "4444333322221111";
2
prms.xExpDate = "1225"; // MMYY
If selected Transaction type is cc:capture
1
prms.xRefNum = "123456789";
Specify optional parameters, if any:
1
prms.xInvoice = "123456";
2
prms.xBillFirstName = "Billing first name";
3
// ... etc.
Create a request object, check if the request object is valid, initiate a transaction & process the response:
1
let request = cardknoxSDKDirect.createRequest(withParameters: prms) as! PaymentTransactionRequestDirect;
2
3
if(request.isValid)
4
{
5
let respone = request.process() as! PaymentTransactionResponse
6
7
if(response.isSuccess())
8
{
9
let refNum = respone.xRefNum();
10
let status = respone.xStatus();
11
let avs = respone.xAvsResult();
12
}
13
else
14
{
15
let refNum = response.xRefNum();
16
let error = response.xError()!
17
let errorCode = response.xErrorCode()!;
18
}
19
}
20
else
21
{
22
// Request could not be processed due to these errors
23
let errors = request.validationErrors!
24
}
To submit a <xCommand> request, first configure the SDK with:
- an xKey value obtained from Cardknox
- a software name value; a short name for your application
- a software version value; the current version of your software
- a version value; the current Cardknox Gateway version 4.5.9
1
CardknoxSDK.setPrincipalKey("Your xKey value");
2
CardknoxSDK.setxSoftwareName("Your app name", xSoftwareVersion: "1.0.0", xVersion: "4.5.9");
Create a Cardknox SDK object. A good place is the “view appear” method. This object will be used to create “request” objects.
1
override func viewDidAppear(_ animated: Bool)
2
{
3
super.viewDidAppear(animated)
4
let cardknoxSDKDirect = CardknoxSDKDirect.create() as? CardknoxSDKDirect
5
}
Destroy the Cardknox SDK object to free resources when SDK will no longer be used:
1
cardknoxSDKDirect.destroy();
Next, create a transaction parameters object:
1
let prms = TransactionParameters();
Specify the required parameters:
1
prms.xCommand = "<xCommand>";
2
prms.xAmount = 1.23;
CHANGE <xCommand>
Specify the additional parameters for the <xCommand> transaction type:
If selected Transaction type is cc:sale, cc:credit, cc:authonly
1
prms.xCardNum = "4444333322221111";
2
prms.xExpDate = "1225"; // MMYY
If selected Transaction type is cc:capture
1
prms.xRefNum = "123456789";
Specify optional parameters, if any:
1
prms.xInvoice = "123456";
2
prms.xBillFirstName = "Billing first name";
3
// ... etc.
Create a request object, check if the request object is valid, initiate a transaction & process the response:
1
let request = cardknoxSDKDirect.createRequest(withParameters: prms) as! PaymentTransactionRequestDirect;
2
3
if(request.isValid)
4
{
5
let respone = request.process() as! PaymentTransactionResponse
6
7
if(response.isSuccess())
8
{
9
let refNum = respone.xRefNum();
10
let status = respone.xStatus();
11
let avs = respone.xAvsResult();
12
}
13
else
14
{
15
let refNum = response.xRefNum();
16
let error = response.xError()!
17
let errorCode = response.xErrorCode()!;
18
}
19
}
20
else
21
{
22
// Request could not be processed due to these errors
23
let errors = request.validationErrors!
24
}
To submit a <xCommand> request, first configure the SDK with:
- an xKey value obtained from Cardknox
- a software name value; a short name for your application
- a software version value; the current version of your software
- a version value; the current Cardknox Gateway version 4.5.9
1
[CardknoxSDK setPrincipalKey:@"Your xKey"];
2
[CardknoxSDK setxSoftwareName:@"Your app name" xSoftwareVersion:@"1.0.0" xVersion:@"4.5.9"];
Create a Cardknox SDK object. A good place is the “view appear” method. This object will be used to create “request” objects.
1
- (void)viewDidAppear:(BOOL)animated
2
{
3
[super viewDidAppear:animated];
4
CardknoxSDKDirect* cardknoxSDKDirect = [CardknoxSDKDirect create];
5
}
Destroy the Cardknox SDK object to free resources when SDK will no longer be used:
1
[cardknoxSDKDirect destroy];
Next, create a transaction parameters object:
1
TransactionParameters *prms =[[TransactionParameters alloc] init];
Specify the required parameters:
1
prms.xCommand = @"<xCommand>";
2
prms.xAmount = 1.23;
CHANGE <xCommand>
Specify the additional parameters for the <xCommand> transaction type:
If selected Transaction type is cc:sale, cc:credit, cc:authonly
1
prms.xCardNum = @"4444333322221111";
2
prms.xExpDate = @"1225"; // MMYY
If selected Transaction type is cc:capture
1
prms.xRefNum = @"123456789";
Specify optional parameters, if any:
1
prms.xInvoice = @"123456";
2
prms.xBillFirstName = @"Billing first name";
3
// ... etc.
Create a request object, check if the request object is valid, initiate a transaction & process the response:
1
PaymentTransactionRequestDirect *request = [cardknoxSDKDirect createRequestWithParameters:prms];
2
3
if([request IsValid])
4
{
5
PaymentTransactionResponse * response = [request process];
6
7
if(response.isSuccess)
8
{
9
NSString* refNum = response.xRefNum;
10
NSString* status = response.xStatus;
11
NSString* avs = response.xAvsResult;
12
}
13
else
14
{
15
NSString* refNum = response.xRefNum;
16
NSString* error = response.xError;
17
NSString* errorCode = response.xErrorCode;
18
}
19
}
20
else
21
{
22
// Request could not be processed due to these errors
23
NSArray* errors = request.ValidationErrors;
24
}
To submit a <xCommand> request, first configure the SDK with:
- an xKey value obtained from Cardknox
- a software name value; a short name for your application
- a software version value; the current version of your software
- a version value; the current Cardknox Gateway version 4.5.9
1
CardknoxSDK.setPrincipalKey("Your xKey value");
2
CardknoxSDK.setxSoftwareName("Your app name", xSoftwareVersion: "1.0.0", xVersion: "4.5.9");
Create a Cardknox SDK object. A good place is the “view appear” method. This object will be used to create “request” objects.
1
func viewDidAppear()
2
{
3
// Example of a "view appear" method in a SwiftUI View
4
// Store the object instance as a @State in the View for later use
5
let cardknoxSDKUI = CardknoxSDKUI.create() as? CardknoxSDKUI
6
}
Register the “view appear” method with the “body” parameterde
1
struct OutOfScopeView : View
2
{
3
var body: some View
4
{
5
// Using NavigationView as a View example
6
NavigationView{}
7
.onAppear(perform: viewDidAppear)
8
}
9
}
Destroy the Cardknox SDK object to free resources when SDK will no longer be used:
1
cardknoxSDKDirect.destroy();
Define a Publisher object that will deliver processed Transaction results in a Notification:
1
let transactionResultSubscription =
2
NotificationCenter.default.publisher(for: NSNotification.Name(CardknoxSDK.transactionResultSubscription_NSNotificationCenterName()))
Define a Publisher object that will deliver Notifications about various card reader event taking place in the SDK:
1
let cardreaderEventSubscription =
2
NotificationCenter.default.publisher(for: NSNotification.Name(CardknoxSDK.cardreaderEventSubscription_NSNotificationCenterName()))
Define a method to run when the SDK processes a transaction and sends the processing results back:
1
func transactionResultSubscription(aNotification: Notification)
2
{
3
let response = PaymentTransactionResponse.unwrap(aNotification) as! PaymentTransactionResponse
4
5
var message = ""
6
if(response.isSuccess())
7
{
8
let refNum = response.xRefNum()!
9
message = "Transaction success response! Ref num: " + refNum
10
}
11
else
12
{
13
let error = response.errorMessage()!
14
message = "Transaction error response - " + error
15
}
16
}
Afterwards, subscribe the method to receive results back from the SDK:
1
struct OutOfScopeView : View
2
{
3
var body: some View
4
{
5
// Using NavigationView as a View example
6
NavigationView{}
7
.onReceive(transactionResultSubscriptionPublisher, perform: transactionResultSubscription(aNotification:))
8
}
9
}
SDK works with a card reader to accept a card. Various card reader events can happen during processing. Define a method to run whenever a new card reader event happens:
1
func cardreaderEventSubscription(aNotification: Notification)
2
{
3
let callback = CardknoxCardReaderCallback.unwrap(aNotification) as? CardknoxCardReaderCallback
4
5
let code = callback?.code()
6
let name = callback?.name()
7
8
var errorMessage : String?;
9
if(code == CardknoxCardReaderCallbackType.error()){
10
errorMessage = callback?.message();
11
}
12
}
Afterwards, subscribe the method to be notified about card reader events:
1
struct OutOfScopeView : View
2
{
3
var body: some View
4
{
5
// Using NavigationView as a View example
6
NavigationView{}
7
.onReceive(cardreaderEventSubscriptionPublisher, perform: cardreaderEventSubscription(aNotification:))
8
}
9
}
Next, create a transaction parameters object:
1
let prms = TransactionParameters();
Specify the required parameters:
1
prms.xCommand = "<xCommand>";
2
prms.xAmount = 1.23;
CHANGE <xCommand> to value from Transaction Type dropdown
Specify optional parameters, if any:
1
prms.xInvoice = "123456";
2
prms.xBillFirstName = "Billing first name";
3
// ... etc.
Create a request object, check if the request object is valid, initiate a transaction & process the response:
1
// Define if a 'keyed' screen is available
2
CardknoxSDKUI.setEnableKeyedEntry(true);
3
// Define if a 'swipe' screen is available
4
CardknoxSDKUI.setEnableDeviceInsertSwipeTap(true);
5
// Define if the UI should auto close
6
CardknoxSDKUI.setCloseOnProcessedTransaction(true);
7
8
let request = cardknoxSDKUI.createRequest(withParameters: prms) as! PaymentTransactionRequestUI
9
if(request.isValid)
10
{
11
// Show the Cardknox UI
12
request.process()
13
}
14
else
15
{
16
// Request could not be processed due to these errors
17
let errors = request.validationErrors!
18
}
To submit a <xCommand> request, first configure the SDK with:
- an xKey value obtained from Cardknox
- a software name value; a short name for your application
- a software version value; the current version of your software
- a version value; the current Cardknox Gateway version 4.5.9
1
CardknoxSDK.setPrincipalKey("Your xKey value");
2
CardknoxSDK.setxSoftwareName("Your app name", xSoftwareVersion: "1.0.0", xVersion: "4.5.9");
Create a Cardknox SDK object. A good place is the “view appear” method. This object will be used to create “request” objects.
1
override func viewDidAppear(_ animated: Bool)
2
{
3
super.viewDidAppear(animated)
4
let cardknoxSDKUI = CardknoxSDKUI.create() as? CardknoxSDKUI
5
}
Destroy the Cardknox SDK object to free resources when SDK will no longer be used:
1
cardknoxSDKDirect.destroy();
Define a method to run when the SDK processes a transaction and sends the processing results back:
1
@objc func transactionResultSubscription(aNotification: Notification)
2
{
3
let response = PaymentTransactionResponse.unwrap(aNotification) as! PaymentTransactionResponse
4
5
var message = ""
6
if(response.isSuccess())
7
{
8
let refNum = response.xRefNum()!
9
message = "Transaction success response! Ref num: " + refNum
10
}
11
else
12
{
13
let error = response.errorMessage()!
14
message = "Transaction error response - " + error
15
}
16
}
Afterwards, subscribe the method to receive results back from the SDK:
1
NotificationCenter.default.addObserver(self,
2
selector: #selector(transactionResultSubscription(aNotification:)),
3
name: Notification.Name( CardknoxSDK.transactionResultSubscription_NSNotificationCenterName()),
4
object: nil)
SDK works with a card reader to accept a card. Various card reader events can happen during processing. Define a method to run whenever a new card reader event happens:
1
@objc func cardreaderEventSubscription(aNotification: Notification)
2
{
3
let callback = CardknoxCardReaderCallback.unwrap(aNotification) as? CardknoxCardReaderCallback
4
5
let code = callback?.code()
6
let name = callback?.name()
7
8
var errorMessage : String?;
9
if(code == CardknoxCardReaderCallbackType.error()){
10
errorMessage = callback?.message();
11
}
12
}
Afterwards, subscribe the method to be notified about card reader events:
1
NotificationCenter.default.addObserver(self,
2
selector: #selector(cardreaderEventSubscription(aNotification:)),
3
name: Notification.Name( CardknoxSDK.cardreaderEventSubscription_NSNotificationCenterName()),
4
object: nil)
Next, create a transaction parameters object:
1
let prms = TransactionParameters();
Specify the required parameters:
1
prms.xCommand = "<xCommand>";
2
prms.xAmount = 1.23;
CHANGE <xCommand> to value from Transaction Type dropdown
Specify optional parameters, if any:
1
prms.xInvoice = "123456";
2
prms.xBillFirstName = "Billing first name";
3
// ... etc.
Create a request object, check if the request object is valid, initiate a transaction & process the response:
1
// Define if a 'keyed' screen is available
2
CardknoxSDKUI.setEnableKeyedEntry(true);
3
// Define if a 'swipe' screen is available
4
CardknoxSDKUI.setEnableDeviceInsertSwipeTap(true);
5
// Define if the UI should auto close
6
CardknoxSDKUI.setCloseOnProcessedTransaction(true);
7
8
let request = cardknoxSDKUI.createRequest(withParameters: prms) as! PaymentTransactionRequestUI
9
if(request.isValid)
10
{
11
// Show the Cardknox UI
12
request.process()
13
}
14
else
15
{
16
// Request could not be processed due to these errors
17
let errors = request.validationErrors!
18
}
To submit a <xCommand> request, first configure the SDK with:
- an xKey value obtained from Cardknox
- a software name value; a short name for your application
- a software version value; the current version of your software
- a version value; the current Cardknox Gateway version 4.5.9
1
[CardknoxSDK setPrincipalKey:@"Your xKey"];
2
[CardknoxSDK setxSoftwareName:@"Your app name" xSoftwareVersion:@"1.0.0" xVersion:@"4.5.9"];
Create a Cardknox SDK object. A good place is the “view appear” method. This object will be used to create “request” objects.
1
- (void)viewDidAppear:(BOOL)animated
2
{
3
[super viewDidAppear:animated];
4
CardknoxSDKUI* cardknoxSDKUI = [CardknoxSDKUI create];
5
}
Destroy the Cardknox SDK object to free resources when SDK will no longer be used:
1
[cardknoxSDKUI destroy];
Define a method to run when the SDK processes a transaction and sends the processing results back:
1
-(void)transactionResultSubscription:(NSNotification*)aNotification
2
{
3
PaymentTransactionResponse * response = [PaymentTransactionResponse unwrap:aNotification];
4
5
NSString *message;
6
if(response.isSuccess)
7
{
8
NSString * refNum = response.xRefNum;
9
message = [NSString stringWithFormat:@"Transaction success response! Ref num: %@", refNum];
10
}
11
else
12
{
13
NSString * error = response.errorMessage;
14
message = [NSString stringWithFormat:@"Transaction error response - %@", error];
15
}
16
}
Afterwards, subscribe the method to receive results back from the SDK:
1
[[NSNotificationCenter defaultCenter] addObserver:self
2
selector:@selector(transactionResultSubscription:)
3
name:[CardknoxSDK transactionResultSubscription_NSNotificationCenterName]
4
object:nil];
SDK works with a card reader to accept a card. Various card reader events can happen during processing. Define a method to run whenever a new card reader event happens:
1
-(void)cardreaderEventSubscription:(NSNotification*)callbackNotification
2
{
3
CardknoxCardReaderCallback* callback = [CardknoxCardReaderCallback unwrap:callbackNotification];
4
5
int code = callback.code;
6
NSString* name = callback.name;
7
8
NSString* errorMessage;
9
if(code == CardknoxCardReaderCallbackType.error){
10
errorMessage = callback.message;
11
}
12
}
Afterwards, subscribe the method to be notified about card reader events:
1
NotificationCenter.default.addObserver(self,
2
selector: #selector(cardreaderEventSubscription(aNotification:)),
3
name: Notification.Name( CardknoxSDK.cardreaderEventSubscription_NSNotificationCenterName()),
4
object: nil)
Next, create a transaction parameters object:
1
TransactionParameters *prms =[[TransactionParameters alloc] init];
Specify the required parameters:
1
prms.xCommand = @"<xCommand>";
2
prms.xAmount = 1.23;
CHANGE <xCommand> to value from Transaction Type dropdown
Specify optional parameters, if any:
1
prms.xInvoice = @"123456";
2
prms.xBillFirstName = @"Billing first name";
3
// ... etc.
Create a request object, check if the request object is valid, initiate a transaction & process the response:
1
// Define if a 'keyed' screen is available
2
CardknoxSDKUI.EnableKeyedEntry = true;
3
// Define if a 'swipe' screen is available
4
CardknoxSDKUI.EnableDeviceInsertSwipeTap = true;
5
// Define if the UI should auto close
6
CardknoxSDKUI.CloseSDKUIOnProcessedTransaction = true;
7
8
PaymentTransactionRequestUI *request = [cardknoxSDKUI createRequestWithParameters:prms];
9
if(request.IsValid)
10
{
11
// Show the Cardknox UI
12
[request process];
13
}
14
else
15
{
16
// Request could not be processed due to these errors
17
NSArray* errors = request.ValidationErrors;
18
}
Selections | Example 1 | Example 2 |
---|---|---|
Integration | In Scope | In Scope |
Language | Swift | Objective C |
UI Toolkit | Storyboard | Storyboard |
Transaction Type | cc:sale | cc:refund |
|
Integration | In Scope |
Language | Swift |
UI Toolkit | Storyboard |
Transaction | cc:sale |
Example 1 sets
xCardNum
& xExpDate
into the parameters object as those 2 are required by the cc:sale
command. Therefor example 1 has the Specify the additional parameters for the "cc:sale" transaction type:
sample codeprms.xCardNum = "4444333322221111";
2prms.xExpDate = "1225"; // MMYY
To submit a cc:sale request, first configure the SDK with:
- an xKey value obtained from Cardknox
- a software name value; a short name for your application
- a software version value; the current version of your software, if any
- a version value; the current Cardknox Gateway version 4.5.9
1
CardknoxSDK.setPrincipalKey("Your xKey value");
2
CardknoxSDK.setxSoftwareName("Your app name", xSoftwareVersion: "1.0.0", xVersion: "4.5.9")
Create a Cardknox SDK object. A good place is the “view appear” method. This object will be used to create “request” objects.
1
override func viewDidAppear(_ animated: Bool)
2
{
3
super.viewDidAppear(animated)
4
let cardknoxSDKDirect = CardknoxSDKDirect.create() as? CardknoxSDKDirect
5
}
Destroy the Cardknox SDK object to free resources when SDK will no longer be used:
1
cardknoxSDKDirect.destroy();
Next, create a transaction parameters object:
1
let prms = TransactionParameters();
Specify the required parameters:
1
prms.xCommand = "cc:sale";
2
prms.xAmount = 1.23;
[VARIES] REQUIRED FOR IN SCOPE CC:SALE
Specify the additional parameters for the “cc:sale” transaction type:
1
prms.xCardNum = "4444333322221111";
2
prms.xExpDate = "1225"; // MMYY
Specify optional parameters, if any:
1
prms.xInvoice = "123456";
2
prms.xBillFirstName = "Billing first name";
3
// ... etc.
Create a request object, check if the request object is valid, initiate a transaction & process the response:
1
let request = cardknoxSDKDirect.createRequest(withParameters: prms) as! PaymentTransactionRequestDirect;
2
if(request.isValid)
3
{
4
let respone = request.process() as! PaymentTransactionResponse
5
6
if(response.isSuccess())
7
{
8
let refNum = respone.xRefNum();
9
let status = respone.xStatus();
10
let avs = respone.xAvsResult();
11
}
12
else
13
{
14
let refNum = response.xRefNum();
15
let error = response.xError()!
16
let errorCode = response.xErrorCode()!;
17
}
18
}
19
else
20
{
21
// Request could not be processed due to these errors
22
let errors = request.validationErrors!
23
}
Integration | In Scope |
Language | Objective C |
UI Toolkit | Storyboard |
Transaction Type | cc:refund |
Example 2 sets the xRefNum value required by the
cc:refund
command. Therefor example 2 has Specify the additional parameters for the "cc:refund" transaction type:
1
prms.xRefNum = @"123456789";
To submit a cc:sale request, first configure the SDK with:
- an xKey value obtained from Cardknox
- a software name value; a short name for your application
- a software version value; the current version of your software, if any
- a version value; the current Cardknox Gateway version 4.5.9
1
[CardknoxSDK setPrincipalKey:@"Your xKey"];
2
[CardknoxSDK setxSoftwareName:@"Your app name" xSoftwareVersion:@"1.0.0" xVersion:@"4.5.9"];
Create a Cardknox SDK object. A good place is the “view appear” method. This object will be used to create “request” objects.
1
- (void)viewDidAppear:(BOOL)animated
2
{
3
[super viewDidAppear:animated];
4
CardknoxSDKDirect* cardknoxSDKDirect = [CardknoxSDKDirect create];
5
}
Destroy the Cardknox SDK object to free resources when SDK will no longer be used:
1
[cardknoxSDKDirect destroy];
Next, create a transaction parameters object:
1
TransactionParameters *prms =[[TransactionParameters alloc] init];
Specify the required parameters:
1
prms.xCommand = @"cc:refund";
2
prms.xAmount = 1.23;
[VARIES] REQUIRED FOR IN SCOPE CC:REFUND
Specify the additional parameters for the “cc:refund” transaction type:
1
prms.xRefNum = @"123456789";
Specify optional parameters, if any:
1
prms.xInvoice = @"123456";
2
prms.xBillFirstName = @"Billing first name";
3
// ... etc.
Create a request object, check if the request object is valid, initiate a transaction & process the response:
1
PaymentTransactionRequestDirect *request = [cardknoxSDKDirect createRequestWithParameters:prms];
2
3
if([request IsValid])
4
{
5
PaymentTransactionResponse * response = [request process];
6
7
if(response.isSuccess)
8
{
9
NSString* refNum = response.xRefNum;
10
NSString* status = response.xStatus;
11
NSString* avs = response.xAvsResult;
12
}
13
else
14
{
15
NSString* refNum = response.xRefNum;
16
NSString* error = response.xError;
17
NSString* errorCode = response.xErrorCode;
18
}
19
}
20
else
21
{
22
// Request could not be processed due to these errors
23
NSArray* errors = request.ValidationErrors;
24
}
Selections | Example 1 | Example 2 |
---|---|---|
Integration | Out of Scope | Out of Scope |
Language | Swift | Objective C |
UI Toolkit | Storyboard | Storyboard |
Transaction Type | cc:sale | cc:sale |
|
Integration | Out of Scope |
Language | Swift |
UI Toolkit | Storyboard |
Transaction | cc:sale |
To submit a cc:sale request, first configure the SDK with:
- an xKey value obtained from Cardknox
- a software name value; a short name for your application
- a software version value; the current version of your software, if any
- a version value; the current Cardknox Gateway version 4.5.9
1
CardknoxSDK.setPrincipalKey("Your xKey value");
2
CardknoxSDK.setxSoftwareName("Your app name", xSoftwareVersion: "1.0.0", xVersion: "4.5.9")
Create a Cardknox SDK object. A good place is the “view appear” method. This object will be used to create “request” objects.
1
override func viewDidAppear(_ animated: Bool)
2
{
3
super.viewDidAppear(animated)
4
let cardknoxSDKUI = CardknoxSDKUI.create() as? CardknoxSDKUI
5
}
Destroy the Cardknox SDK object to free resources when SDK will no longer be used:
1
cardknoxSDKDirect.destroy();
Define a method to run when the SDK processes a transaction and sends the processing results back:
1
@objc func transactionResultSubscription(aNotification: Notification)
2
{
3
let response = PaymentTransactionResponse.unwrap(aNotification) as? PaymentTransactionResponse
4
5
var message = ""
6
if((response?.isSuccess()) != nil)
7
{
8
let refNum = (response?.xRefNum())! as String
9
message = "Transaction success response! Ref num: " + refNum
10
}
11
else
12
{
13
let error = (response?.errorMessage())! as String
14
message = "Transaction error response - " + error
15
}
16
}
Afterwards, subscribe the method to receive results back from the SDK:
1
NotificationCenter.default.addObserver(self,
2
selector: #selector(transactionResultSubscription(aNotification:)),
3
name: Notification.Name( CardknoxSDK.transactionResultSubscription_NSNotificationCenterName()),
4
object: nil)
SDK works with a card reader to accept a card. Various card reader events can happen during processing. Define a method to run whenever a new card reader event happens:
1
@objc func cardreaderEventSubscription(aNotification: Notification)
2
{
3
let callback = CardknoxCardReaderCallback.unwrap(aNotification) as? CardknoxCardReaderCallback
4
5
let code = callback?.code()
6
let name = callback?.name()
7
8
var errorMessage : String?;
9
if(code == CardknoxCardReaderCallbackType.error()){
10
errorMessage = callback?.message();
11
}
12
}
Afterwards, subscribe the method to be notified about card reader events:
1
NotificationCenter.default.addObserver(self,
2
selector: #selector(cardreaderEventSubscription(aNotification:)),
3
name: Notification.Name( CardknoxSDK.cardreaderEventSubscription_NSNotificationCenterName()),
4
object: nil)
Next, create a transaction parameters object:
1
let prms = TransactionParameters();
Specify the required parameters:
1
prms?.xCommand = "cc:sale";
2
2prms?.xAmount = 1.23;
Specify optional parameters, if any:
1
prms?.xInvoice = "123456";
2
prms?.xBillFirstName = "Billing first name";
3
// ... etc.
Create a request object, check if the request object is valid, initiate a transaction & process the response:
1
// Define if a 'keyed' screen is available
2
CardknoxSDKUI.setEnableKeyedEntry(true);
3
// Define if a 'swipe' screen is available
4
CardknoxSDKUI.setEnableDeviceInsertSwipeTap(true);
5
// Define if the UI should auto close
6
CardknoxSDKUI.setCloseOnProcessedTransaction(true);
7
8
let request = cardknoxSDKUI.createRequest(withParameters: prms) as! PaymentTransactionRequestUI
9
if(request.isValid)
10
{
11
// Show the Cardknox UI
12
request.process()
13
}
14
else
15
{
16
// Request could not be processed due to these errors
17
let errors = request.validationErrors!
18
}
Integration | Out of Scope |
Language | Objective C |
UI Toolkit | Storyboard |