|
let sdk:WDePOS = WDePOS.sharedInstance() |
|
|
|
// Create the instance of the Sale Request |
|
// Here the minimum data is depicted |
|
let saleRequest:WDSaleRequest! = WDSaleRequest.init(uniqueId: "yourSaleUniqueID", // provide your unique ID to identify the Sale |
|
location: nil, // provide the GPS location for this payment e.g. the mobile device location |
|
inclusiveTaxes: true, // Tax inclusive/exclusive flag |
|
currency: "EUR", // Currency to use for this Sale |
|
note: "Test Sale", // Top level note for this sale |
|
gratuityTaxRate: nil // Gratuity tax rate - nil if no gratuity to be set later in the payment flow |
|
)! |
|
|
|
// Create one item named "Item 1" costing 10.00 EUR at 20% Tax |
|
saleRequest.addSaleItem(NSDecimalNumber.init(value: 10), // Item Unit price |
|
quantity: NSDecimalNumber.init(value: 1), // Item Quantity |
|
taxRate: NSDecimalNumber.init(value: 20), // Item Tax rate |
|
itemDescription: "Item 1", // Item description |
|
productId: nil, |
|
externalProductId:nil |
|
) |
|
|
|
// Discover active terminals and use it - in this case we use the first one |
|
// Alternatively use the one discovered previously and stored in an instance variable (or user preferences) |
|
sdk.terminalManager.discoverDevices(WDExtensionTypeUUID.WDPosMateExtensionUUID) { (terminals:[WDTerminal]?, error:Error?) in |
|
if let terminalsArr = terminals{ |
|
//Here we assume that at least one terminal is present |
|
let terminal:WDTerminal! = terminalsArr.first |
|
// Set this Sale in total amount 10 EUR and use Card PreAuthorization to process this Sale |
|
saleRequest.addCardPreAuthorization(NSDecimalNumber.init(value: 10), terminal: terminal!) |
|
|
|
// Create Payment Configuration to be used in the Pay API later |
|
// Set the Sale of this payment configuration to be your new Sale Request |
|
let paymentConfiguration:WDSaleRequestConfiguration! = WDSaleRequestConfiguration.init(saleRequest: saleRequest) |
|
//Perform the Sale |
|
sdk.saleManager.pay(paymentConfiguration, with: type(of:self).paymentHandler) |
|
} |
|
else{ |
|
NSLog("No active terminal found") |
|
} |
|
} |
|
|
|
//************ CAPTURE ************// |
|
//Capture - can be done for previous successful PreAuthorization |
|
let saleResponse = WDSaleResponse() //You could obtain the previously performed Sale with PreAuthorization |
|
|
|
let referencedSale = saleResponse.referenceSaleRequest()//and use the helper to create the Referenced Sale Request |
|
|
|
//as there was only one card authorization it is safe to refer to it as first object in the processedCardPayment array |
|
let cardPreAuthorization = saleResponse.processedCardPayments().first |
|
|
|
//Now add the Card capture to the |
|
referencedSale.addCardCapture(NSDecimalNumber.init(integerLiteral: 10), originalPaymentId: cardPreAuthorization!.internalId) |
|
|
|
//Use the referencedSale request in the payment configuration |
|
let paymentConfiguration:WDSaleRequestConfiguration! = WDSaleRequestConfiguration.init(saleRequest: referencedSale) |
|
//Perform the Sale Request with Card Capture |
|
sdk.saleManager.pay(paymentConfiguration, with: type(of:self).paymentHandler) |