Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WirecardMobileServices/22dcb74422f0b92ab97adb5b431ec198 to your computer and use it in GitHub Desktop.
Save WirecardMobileServices/22dcb74422f0b92ab97adb5b431ec198 to your computer and use it in GitHub Desktop.
Sale Request PreAuthorization Supplement
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: 8), 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")
}
}
//************ SUPPLEMENT ************//
//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 Pre-auth supplement. Note that originalTransactionId and authorizationCode belong to a complete pre-authorize payment that already exist
referencedSale.addCardPreAuthorizationSupplement(NSDecimalNumber.init(integerLiteral: 1), originalTransactionId: cardPreAuthorization!.internalId, authorizationCode:cardPreAuthorization!.authorizationCode)
//Use the referencedSale request in the payment configuration
let paymentConfiguration:WDSaleRequestConfiguration! = WDSaleRequestConfiguration.init(saleRequest: referencedSale)
//Perform the Sale Request with Card Pre-Auth Supplement
sdk.saleManager.pay(paymentConfiguration, with: type(of:self).paymentHandler)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment