Create a Cardknox SDK object. A good place is the “view appear” method. This object will be used to create “request” objects.
func viewDidAppear()
{
// Example of a "view appear" method in a SwiftUI View
// Store the object instance as a @State in the View for later use
let cardknoxSDKDirect = CardknoxSDKDirect.create() as? CardknoxSDKDirect;
}
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:
cardknoxSDKDirect.destroy();
Next, create a transaction parameters object:
let prms : TransactionParameters = TransactionParameters.init()
prms.xInvoice = "123456";
prms.xBillFirstName = "Billing first name";
// ... etc.
Create a request object, check if the request object is valid, initiate a transaction & process the response:
let request = cardknoxSDKDirect.createRequest(withParameters: prms) as! PaymentTransactionRequestDirect;
if(request.isValid)
{
let respone = request.process() as! PaymentTransactionResponse
if(response.isSuccess())
{
let refNum = respone.xRefNum();
let status = respone.xStatus();
let avs = respone.xAvsResult();
}
else
{
let refNum = response.xRefNum();
let error = response.xError()!
let errorCode = response.xErrorCode()!;
}
}
else
{
// Request could not be processed due to these errors
let errors = request.validationErrors!
}
Swift - Storyboard
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
prms.xInvoice = "123456";
prms.xBillFirstName = "Billing first name";
// ... etc.
Create a request object, check if the request object is valid, initiate a transaction & process the response:
let request = cardknoxSDKDirect.createRequest(withParameters: prms) as! PaymentTransactionRequestDirect;
if(request.isValid)
{
let respone = request.process() as! PaymentTransactionResponse
if(response.isSuccess())
{
let refNum = respone.xRefNum();
let status = respone.xStatus();
let avs = respone.xAvsResult();
}
else
{
let refNum = response.xRefNum();
let error = response.xError()!
let errorCode = response.xErrorCode()!;
}
}
else
{
// Request could not be processed due to these errors
let errors = request.validationErrors!
}
Objective C - Storyboard
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
Create a Cardknox SDK object. A good place is the “view appear” method. This object will be used to create “request” objects.
func viewDidAppear()
{
// Example of a "view appear" method in a SwiftUI View
// Store the object instance as a @State in the View for later use
let cardknoxSDKUI = CardknoxSDKUI.create() as? CardknoxSDKUI
}
Register the “view appear” method with the “body” parameterde
struct OutOfScopeView : 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:
cardknoxSDKDirect.destroy();
Define a Publisher object that will deliver processed Transaction results in a Notification:
let transactionResultSubscription =
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:
let cardreaderEventSubscription =
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:
Afterwards, subscribe the method to receive results back from the SDK:
struct OutOfScopeView : View
{
var body: some View
{
// Using NavigationView as a View example
NavigationView{}
.onReceive(transactionResultSubscriptionPublisher, perform: transactionResultSubscription(aNotification:))
}
}
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:
func cardreaderEventSubscription(aNotification: Notification)
{
let callback = CardknoxCardReaderCallback.unwrap(aNotification) as? CardknoxCardReaderCallback
let code = callback?.code()
let name = callback?.name()
var errorMessage : String?;
if(code == CardknoxCardReaderCallbackType.error()){
errorMessage = callback?.message();
}
}
Afterwards, subscribe the method to be notified about card reader events:
struct OutOfScopeView : View
{
var body: some View
{
// Using NavigationView as a View example
NavigationView{}
.onReceive(cardreaderEventSubscriptionPublisher, perform: cardreaderEventSubscription(aNotification:))
}
}
CHANGE <xCommand> to value from Transaction Type dropdown
Specify optional parameters, if any:
prms.xInvoice = "123456";
prms.xBillFirstName = "Billing first name";
// ... etc.
Create a request object, check if the request object is valid, initiate a transaction & process the response:
// Define if a 'keyed' screen is available
CardknoxSDKUI.setEnableKeyedEntry(true);
// Define if a 'swipe' screen is available
CardknoxSDKUI.setEnableDeviceInsertSwipeTap(true);
// Define if the UI should auto close
CardknoxSDKUI.setCloseOnProcessedTransaction(true);
let request = cardknoxSDKUI.createRequest(withParameters: prms) as! PaymentTransactionRequestUI
if(request.isValid)
{
// Show the Cardknox UI
request.process()
}
else
{
// Request could not be processed due to these errors
let errors = request.validationErrors!
}
Swift - Storyboard 2
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
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:
@objc func cardreaderEventSubscription(aNotification: Notification)
{
let callback = CardknoxCardReaderCallback.unwrap(aNotification) as? CardknoxCardReaderCallback
let code = callback?.code()
let name = callback?.name()
var errorMessage : String?;
if(code == CardknoxCardReaderCallbackType.error()){
errorMessage = callback?.message();
}
}
Afterwards, subscribe the method to be notified about card reader events:
CHANGE <xCommand> to value from Transaction Type dropdown
Specify optional parameters, if any:
prms.xInvoice = "123456";
prms.xBillFirstName = "Billing first name";
// ... etc.
Create a request object, check if the request object is valid, initiate a transaction & process the response:
// Define if a 'keyed' screen is available
CardknoxSDKUI.setEnableKeyedEntry(true);
// Define if a 'swipe' screen is available
CardknoxSDKUI.setEnableDeviceInsertSwipeTap(true);
// Define if the UI should auto close
CardknoxSDKUI.setCloseOnProcessedTransaction(true);
let request = cardknoxSDKUI.createRequest(withParameters: prms) as! PaymentTransactionRequestUI
if(request.isValid)
{
// Show the Cardknox UI
request.process()
}
else
{
// Request could not be processed due to these errors
let errors = request.validationErrors!
}
Objective C - Storyboard 2
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
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:
CHANGE <xCommand> to value from Transaction Type dropdown
Specify optional parameters, if any:
prms.xInvoice = @"123456";
prms.xBillFirstName = @"Billing first name";
// ... etc.
Create a request object, check if the request object is valid, initiate a transaction & process the response:
// Define if a 'keyed' screen is available
CardknoxSDKUI.EnableKeyedEntry = true;
// Define if a 'swipe' screen is available
CardknoxSDKUI.EnableDeviceInsertSwipeTap = true;
// Define if the UI should auto close
CardknoxSDKUI.CloseSDKUIOnProcessedTransaction = true;
PaymentTransactionRequestUI *request = [cardknoxSDKUI createRequestWithParameters:prms];
if(request.IsValid)
{
// Show the Cardknox UI
[request process];
}
else
{
// Request could not be processed due to these errors
NSArray* errors = request.ValidationErrors;
}
Examples
In Scope Example Processes
In Scope Example 1
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 code
prms.xInvoice = "123456";
prms.xBillFirstName = "Billing first name";
// ... etc.
Create a request object, check if the request object is valid, initiate a transaction & process the response:
let request = cardknoxSDKDirect.createRequest(withParameters: prms) as! PaymentTransactionRequestDirect;
if(request.isValid)
{
let respone = request.process() as! PaymentTransactionResponse
if(response.isSuccess())
{
let refNum = respone.xRefNum();
let status = respone.xStatus();
let avs = respone.xAvsResult();
}
else
{
let refNum = response.xRefNum();
let error = response.xError()!
let errorCode = response.xErrorCode()!;
}
}
else
{
// Request could not be processed due to these errors
let errors = request.validationErrors!
}
In Scope Example 2
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:
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
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:
@objc func cardreaderEventSubscription(aNotification: Notification)
{
let callback = CardknoxCardReaderCallback.unwrap(aNotification) as? CardknoxCardReaderCallback
let code = callback?.code()
let name = callback?.name()
var errorMessage : String?;
if(code == CardknoxCardReaderCallbackType.error()){
errorMessage = callback?.message();
}
}
Afterwards, subscribe the method to be notified about card reader events:
prms?.xInvoice = "123456";
prms?.xBillFirstName = "Billing first name";
// ... etc.
Create a request object, check if the request object is valid, initiate a transaction & process the response:
// Define if a 'keyed' screen is available
CardknoxSDKUI.setEnableKeyedEntry(true);
// Define if a 'swipe' screen is available
CardknoxSDKUI.setEnableDeviceInsertSwipeTap(true);
// Define if the UI should auto close
CardknoxSDKUI.setCloseOnProcessedTransaction(true);
let request = cardknoxSDKUI.createRequest(withParameters: prms) as! PaymentTransactionRequestUI
if(request.isValid)
{
// Show the Cardknox UI
request.process()
}
else
{
// Request could not be processed due to these errors
let errors = request.validationErrors!
}
Out of Scope Example 2
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
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:
prms.xInvoice = @"123456";
prms.xBillFirstName = @"Billing first name";
// ... etc.
Create a request object, check if the request object is valid, initiate a transaction & process the response:
// Define if a 'keyed' screen is available
CardknoxSDKUI.EnableKeyedEntry = true;
// Define if a 'swipe' screen is available
CardknoxSDKUI.EnableDeviceInsertSwipeTap = true;
// Define if the UI should auto close
CardknoxSDKUI.CloseSDKUIOnProcessedTransaction = true;
PaymentTransactionRequestUI *request = [cardknoxSDKUI createRequestWithParameters:prms];
if(request.IsValid)
{
// Show the Cardknox UI
[request process];
}
else
{
// Request could not be processed due to these errors
NSArray* errors = request.ValidationErrors;
}