Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Sale Request - Authorization
//End of SDK Setup process
CurrentUserCompletion setupCompletion = ^( WDMerchantUser * _Nullable currentUser, WDMerchantCashier * _Nullable cashier, NSError * _Nullable error){
//Current User is returned upon successful login
//if the Cash Management is enabled and Cashier record exist for the current user then the Cashier is returned also
// The SDK is initialized as shared instance so can be accessed
// from multiple View Controllers
WDePOS *sdk = [WDePOS sharedInstance];
// Set the SDK target environment - in this case Public Test
// and the username and password to authenticate to it
[sdk setupWithEnvironment:WDEnvironmentPublicTest
// Create the instance of the Sale Request
// Here the minimum data is depicted
WDSaleRequest *saleRequest = [[WDSaleRequest alloc] initWithUniqueId:@"yourSaleUniqueID" // provide your unique ID to identify the Sale
location:nil // provide the GPS location
inclusiveTaxes:YES // Tax inclusive/exclusive flag
currency:@"EUR" // Currency to use for this Sale
note:@"Test Posmate 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 decimalNumberWithString:@"10.00"] // Item Unit price
quantity:NSDecimalNumber.init(value: 1) // Item Quantity
taxRate:[NSDecimalNumber decimalNumberWithString:@"20.00"] // Item Tax rate
itemDescription:@"Item 1" // Item description
productId:nil // External product ID - in the case you are using ERP - such as SAP and wish to refer to the product
// Define the Sale operation as Purchase
saleRequest.type = WDSaleTypePurchase;
// Create Payment Configuration to be used in the Pay API later
WDSaleRequestConfiguration *paymentConfiguration = [WDSaleRequestConfiguration new];
// 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:WDPosMateExtensionUUID
completion:^(NSArray<WDTerminal *> * _Nullable terminals, NSError * _Nullable devicesError)
// Set this Sale in total amount 10 EUR and use Card Authorization to process this Sale
[saleRequest addCardAuthorization:[NSDecimalNumber decimalNumberWithString:@"10.00"]
terminal:[terminals firstObject]];
// Set the Sale of this payment configuration to be your new Sale Request = saleRequest;
// Start the Payment flow
[[sdk saleManager] pay:paymentConfiguration withDelegate:self.paymentHandler];
//************ CAPTURE ************//
//Capture - can be done for previous successful Authorization
WDSaleResponse *saleResponse; //You could obtain the previously performed Sale with Authorization
WDReferenceSaleRequest *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
WDPaymentDetailCard *cardAuthorization = saleResponse.processedCardPayments.firstObject;
//Now add the Card capture to the
[referencedSale addCardCapture:[NSDecimalNumber decimalNumberWithString:@"10.00"] originalPaymentId:cardAuthorization.internalId];
//Use the referencedSale request in the payment configuration
WDSaleRequestConfiguration *paymentConfiguration = [[WDSaleRequestConfiguration alloc] initWithSaleRequest:referencedSale];
[[sdk saleManager] pay:paymentConfiguration withDelegate:self.paymentHandler];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.