Workflow

Overview

Workflow Examples

In Scope

Swift - SwiftUI

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

CardknoxSDK.setPrincipalKey("Your xKey value");
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.

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()

Specify the required parameters:

prms.xCommand = "<xCommand>";
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

prms.xCardNum = "4444333322221111";
prms.xExpDate = "1225"; // MMYY

If selected Transaction type is cc:capture

prms.xRefNum = "123456789";

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:

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

CardknoxSDK.setPrincipalKey("Your xKey value");
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.

override func viewDidAppear(_ animated: Bool) 
{
  super.viewDidAppear(animated)
  let cardknoxSDKDirect = CardknoxSDKDirect.create() as? CardknoxSDKDirect
}

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();

Specify the required parameters:

prms.xCommand = "<xCommand>";
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

prms.xCardNum = "4444333322221111";
prms.xExpDate = "1225"; // MMYY

If selected Transaction type is cc:capture

prms.xRefNum = "123456789";

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:

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

[CardknoxSDK setPrincipalKey:@"Your xKey"];
[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.

- (void)viewDidAppear:(BOOL)animated
{
  [super viewDidAppear:animated];
  CardknoxSDKDirect* cardknoxSDKDirect = [CardknoxSDKDirect create];
}

Destroy the Cardknox SDK object to free resources when SDK will no longer be used:

[cardknoxSDKDirect destroy];

Next, create a transaction parameters object:

TransactionParameters *prms =[[TransactionParameters alloc] init];

Specify the required parameters:

prms.xCommand = @"<xCommand>";
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

prms.xCardNum = @"4444333322221111";
prms.xExpDate = @"1225"; // MMYY

If selected Transaction type is cc:capture

prms.xRefNum = @"123456789";

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:

PaymentTransactionRequestDirect *request = [cardknoxSDKDirect createRequestWithParameters:prms];

if([request IsValid])
{
  PaymentTransactionResponse * response = [request process];
 
  if(response.isSuccess)
  {
    NSString* refNum = response.xRefNum;
    NSString* status = response.xStatus;
    NSString* avs = response.xAvsResult; 
  }
  else
  {
    NSString* refNum = response.xRefNum;
    NSString* error = response.xError;
    NSString* errorCode = response.xErrorCode;
  } 
}
else
{
  // Request could not be processed due to these errors
  NSArray* errors = request.ValidationErrors;
}

Out of Scope

Swift - SwiftUI 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

CardknoxSDK.setPrincipalKey("Your xKey value");
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.

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:

func transactionResultSubscription(aNotification: Notification)
{
    let response = PaymentTransactionResponse.unwrap(aNotification) as! PaymentTransactionResponse
    
    var message = ""
    if(response.isSuccess())
    {
        let refNum = response.xRefNum()!
        message = "Transaction success response! Ref num: " + refNum
    }
    else
    {
        let error = response.errorMessage()!
        message = "Transaction error response - " + error
    }
}

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:))
  }
}

Next, create a transaction parameters object:

let prms = TransactionParameters();

Specify the required parameters:

prms.xCommand = "<xCommand>";
prms.xAmount = 1.23;

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

CardknoxSDK.setPrincipalKey("Your xKey value");
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.

override func viewDidAppear(_ animated: Bool) 
{
  super.viewDidAppear(animated)
  let cardknoxSDKUI = CardknoxSDKUI.create() as? CardknoxSDKUI
}

Destroy the Cardknox SDK object to free resources when SDK will no longer be used:

cardknoxSDKDirect.destroy();

Define a method to run when the SDK processes a transaction and sends the processing results back:

@objc func transactionResultSubscription(aNotification: Notification)
{
    let response = PaymentTransactionResponse.unwrap(aNotification) as! PaymentTransactionResponse
    
    var message = ""
    if(response.isSuccess())
    {
        let refNum = response.xRefNum()!
        message = "Transaction success response! Ref num: " + refNum
    }
    else
    {
        let error = response.errorMessage()!
        message = "Transaction error response - " + error
    }
}

Afterwards, subscribe the method to receive results back from the SDK:

NotificationCenter.default.addObserver(self,
                                       selector: #selector(transactionResultSubscription(aNotification:)),
                                       name: Notification.Name( CardknoxSDK.transactionResultSubscription_NSNotificationCenterName()),
                                       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:

@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:

NotificationCenter.default.addObserver(self,
                                       selector: #selector(cardreaderEventSubscription(aNotification:)),
                                       name: Notification.Name( CardknoxSDK.cardreaderEventSubscription_NSNotificationCenterName()),
                                       object: nil)

Next, create a transaction parameters object:

let prms = TransactionParameters();

Specify the required parameters:

prms.xCommand = "<xCommand>";
prms.xAmount = 1.23;

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

[CardknoxSDK setPrincipalKey:@"Your xKey"];
[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.

- (void)viewDidAppear:(BOOL)animated
{
  [super viewDidAppear:animated];
  CardknoxSDKUI* cardknoxSDKUI = [CardknoxSDKUI create];
}

Destroy the Cardknox SDK object to free resources when SDK will no longer be used:

[cardknoxSDKUI destroy];

Define a method to run when the SDK processes a transaction and sends the processing results back:

-(void)transactionResultSubscription:(NSNotification*)aNotification
{
    PaymentTransactionResponse * response = [PaymentTransactionResponse unwrap:aNotification];
    
    NSString *message;
    if(response.isSuccess)
    {
        NSString * refNum = response.xRefNum;
        message = [NSString stringWithFormat:@"Transaction success response! Ref num: %@", refNum];
    }
    else
    {
        NSString * error = response.errorMessage;
        message = [NSString stringWithFormat:@"Transaction error response - %@", error];
    }
}

Afterwards, subscribe the method to receive results back from the SDK:

[[NSNotificationCenter defaultCenter] addObserver:self
                       selector:@selector(transactionResultSubscription:)
                           name:[CardknoxSDK transactionResultSubscription_NSNotificationCenterName]
                         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:

-(void)cardreaderEventSubscription:(NSNotification*)callbackNotification
{
    CardknoxCardReaderCallback* callback = [CardknoxCardReaderCallback unwrap:callbackNotification];
    
    int code = callback.code;
    NSString* name = callback.name;
    
    NSString* errorMessage;
    if(code == CardknoxCardReaderCallbackType.error){
        errorMessage = callback.message;
    }
}

Afterwards, subscribe the method to be notified about card reader events:

NotificationCenter.default.addObserver(self,
                                       selector: #selector(cardreaderEventSubscription(aNotification:)),
                                       name: Notification.Name( CardknoxSDK.cardreaderEventSubscription_NSNotificationCenterName()),
                                       object: nil)

Next, create a transaction parameters object:

TransactionParameters *prms =[[TransactionParameters alloc] init];

Specify the required parameters:

prms.xCommand = @"<xCommand>";
prms.xAmount = 1.23;

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

SelectionsExample 1Example 2

Integration

In Scope

In Scope

Language

Swift

Objective C

UI Toolkit

Storyboard

Storyboard

Transaction Type

cc:sale

cc:refund

In Scope Example 1

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 code

prms.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

CardknoxSDK.setPrincipalKey("Your xKey value");
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.

override func viewDidAppear(_ animated: Bool) 
{
  super.viewDidAppear(animated)
  let cardknoxSDKDirect = CardknoxSDKDirect.create() as? CardknoxSDKDirect
}

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();

Specify the required parameters:

prms.xCommand = "cc:sale";
prms.xAmount = 1.23;

[VARIES] REQUIRED FOR IN SCOPE CC:SALE

Specify the additional parameters for the “cc:sale” transaction type:

prms.xCardNum = "4444333322221111";
prms.xExpDate = "1225"; // MMYY

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:

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

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:

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

[CardknoxSDK setPrincipalKey:@"Your xKey"];
[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.

- (void)viewDidAppear:(BOOL)animated
{
  [super viewDidAppear:animated];
  CardknoxSDKDirect* cardknoxSDKDirect = [CardknoxSDKDirect create];
}

Destroy the Cardknox SDK object to free resources when SDK will no longer be used:

[cardknoxSDKDirect destroy];

Next, create a transaction parameters object:

TransactionParameters *prms =[[TransactionParameters alloc] init];

Specify the required parameters:

prms.xCommand = @"cc:refund";
prms.xAmount = 1.23;

[VARIES] REQUIRED FOR IN SCOPE CC:REFUND

Specify the additional parameters for the “cc:refund” transaction type:

prms.xRefNum = @"123456789";

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:

PaymentTransactionRequestDirect *request = [cardknoxSDKDirect createRequestWithParameters:prms];

if([request IsValid])
{
  PaymentTransactionResponse * response = [request process];
 
  if(response.isSuccess)
  {
    NSString* refNum = response.xRefNum;
    NSString* status = response.xStatus;
    NSString* avs = response.xAvsResult; 
  }
  else
  {
    NSString* refNum = response.xRefNum;
    NSString* error = response.xError;
    NSString* errorCode = response.xErrorCode;
  } 
}
else
{
  // Request could not be processed due to these errors
  NSArray* errors = request.ValidationErrors;
}

Out of Scope Example Processes

SelectionsExample 1Example 2

Integration

Out of Scope

Out of Scope

Language

Swift

Objective C

UI Toolkit

Storyboard

Storyboard

Transaction Type

cc:sale

cc:sale

Out of Scope Example 1

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

CardknoxSDK.setPrincipalKey("Your xKey value");
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.

override func viewDidAppear(_ animated: Bool) 
{
  super.viewDidAppear(animated)
  let cardknoxSDKUI = CardknoxSDKUI.create() as? CardknoxSDKUI
}

Destroy the Cardknox SDK object to free resources when SDK will no longer be used:

cardknoxSDKDirect.destroy();

Define a method to run when the SDK processes a transaction and sends the processing results back:

@objc func transactionResultSubscription(aNotification: Notification)
{
    let response = PaymentTransactionResponse.unwrap(aNotification) as? PaymentTransactionResponse
    
    var message = ""
    if((response?.isSuccess()) != nil)
    {
        let refNum = (response?.xRefNum())! as String
        message = "Transaction success response! Ref num: " + refNum
    }
    else
    {
        let error = (response?.errorMessage())! as String
        message = "Transaction error response - " + error            
    }
}

Afterwards, subscribe the method to receive results back from the SDK:

NotificationCenter.default.addObserver(self,
                                       selector: #selector(transactionResultSubscription(aNotification:)),
                                       name: Notification.Name( CardknoxSDK.transactionResultSubscription_NSNotificationCenterName()),
                                       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:

@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:

NotificationCenter.default.addObserver(self,
                                       selector: #selector(cardreaderEventSubscription(aNotification:)),
                                       name: Notification.Name( CardknoxSDK.cardreaderEventSubscription_NSNotificationCenterName()),
                                       object: nil)

Next, create a transaction parameters object:

let prms = TransactionParameters();

Specify the required parameters:

prms?.xCommand = "cc:sale";
2prms?.xAmount = 1.23;

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!
}

Out of Scope Example 2

Integration

Out of Scope

Language

Objective C

UI Toolkit

Storyboard

Transaction Type

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

[CardknoxSDK setPrincipalKey:@"Your xKey"];
[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.

- (void)viewDidAppear:(BOOL)animated
{
  [super viewDidAppear:animated];
  CardknoxSDKUI* cardknoxSDKUI = [CardknoxSDKUI create];
}

Destroy the Cardknox SDK object to free resources when SDK will no longer be used:

[cardknoxSDKUI destroy];

Define a method to run when the SDK processes a transaction and sends the processing results back:

-(void)transactionResultSubscription:(NSNotification*)aNotification
{
    PaymentTransactionResponse * response = [PaymentTransactionResponse unwrap:aNotification];
    
    NSString *message;
    if(response.isSuccess)
    {
        NSString * refNum = response.xRefNum;
        message = [NSString stringWithFormat:@"Transaction success response! Ref num: %@", refNum];
    }
    else
    {
        NSString * error = response.errorMessage;
        message = [NSString stringWithFormat:@"Transaction error response - %@", error];
    }
}

Afterwards, subscribe the method to receive results back from the SDK:

[[NSNotificationCenter defaultCenter] addObserver:self
                       selector:@selector(transactionResultSubscription:)
                           name:[CardknoxSDK transactionResultSubscription_NSNotificationCenterName]
                         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:

-(void)cardreaderEventSubscription:(NSNotification*)callbackNotification
{
    CardknoxCardReaderCallback* callback = [CardknoxCardReaderCallback unwrap:callbackNotification];
    
    int code = callback.code;
    NSString* name = callback.name;
    
    NSString* errorMessage;
    if(code == CardknoxCardReaderCallbackType.error){
        errorMessage = callback.message;
    }
}

Afterwards, subscribe the method to be notified about card reader events:

NotificationCenter.default.addObserver(self,
                                       selector: #selector(cardreaderEventSubscription(aNotification:)),
                                       name: Notification.Name( CardknoxSDK.cardreaderEventSubscription_NSNotificationCenterName()),
                                       object: nil)

Next, create a transaction parameters object:

TransactionParameters *prms = [[TransactionParameters alloc] init];

Specify the required parameters:

prms.xCommand = @"cc:sale";
prms.xAmount = 1.23;

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;
}

Last updated