Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // The SDK is initialized as shared instance so can be accessed
- // from multiple View Controllers
- AcceptSDK *sdk = [AcceptSDK sharedInstance];
- // Set the SDK target environment - in this case Public Test
- // and the username and password to authenticate to it
- [sdk setupWithEnvironment:AcceptEnvironmentPublicTest
- username:@"yourUsername"
- password:@"yourPassword"];
- // Create the instance of the Sale Request
- // Here the minimum data is depicted
- WDAcceptSaleRequest *saleRequest = [[WDAcceptSaleRequest 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: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.operation = AcceptSaleOperationPurchase;
- // 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:WDAMiuraExtensionUUID
- completion:^(NSArray<WDAcceptTerminal *> * _Nullable terminals, NSError * _Nullable devicesError)
- {
- // Set this Sale in total amount 10 EUR to be settled half by Card transaction (5 EUR)
- [saleRequest addCardTransaction:[NSDecimalNumber decimalNumberWithString:@"5.00"]
- terminal:[terminals firstObject]];
- // and half by Cash transaction (5 EUR)
- [saleRequest addCashTransaction:[NSDecimalNumber decimalNumberWithString:@"5.00"]];
- // Create Payment Configuration to be used in the Pay API later
- WDAcceptPaymentConfig *paymentConfiguration = [WDAcceptPaymentConfig new];
- // Set the Sale of this payment configuration to be your new Sale Request
- paymentConfiguration.sale = saleRequest;
- // The end of the payment process
- SaleCompletion paymentCompletion = ^(WDAcceptSaleResponse* sale, NSError* error){
- //sale - Is the completed Sale - contains the sale status, details, results
- //error - If any error is encountered during the sale it would be reported
- //in the form of error and hierarchy of underlying errors to give you as much details as possible
- };
- // Updates from the payment flow
- PaymentProgress progressUpdate = ^(AcceptStateUpdate statusUpdate){
- // statusUpdate - coded statuses are reported throughout the payment flow
- };
- // In the case the Cardholder Signature is required by the Payment flow this block will be executed
- // Your task is to respond to it by collecting the signature image from the customer and
- // posting it back in the sendCollectedSignature method
- SignatureRequiredRequest signatureRequiredRequest = ^(WDAcceptSignatureRequest* signatureRequest){
- //signatureRequest - comes from the payment flow and once you collect the signature from the customer
- // send it back in the signatureRequest.sendCollectedSignature
- signatureRequest.sendCollectedSignature([TestUtils signatureImageFromText:@"Test"],nil);
- //The signature image is transferred to the backend and stored with the Sale
- };
- // Note: Applicable to terminals without BUTTONS
- // In the case the Cardholder Signature was collected then the merchant is required to confirm it's validity
- // A. If the terminal has buttons that are used for Approving/Rejecting then this block is either never called from Payment flow
- // or it's signatureVerificationCallback comes nil
- // B. If the terminal does not have buttons then the Application must present a user interface to Approve/Reject the Cardholder Signature
- SignatureVerificationRequest verifySignature = ^(SignatureVerificationResult signatureVerificationResult, NSError* signatureVerificationError){
- if (signatureVerificationResult) {
- // Here the simplified use of Approving the Cardholder Signature is demonstrated
- signatureVerificationResult(AcceptSignatureVerificationResultApproved);
- }
- };
- // Note: Applicable to terminals without BUTTONS
- // In the case the payment Card has more than one card application available then the client application
- // has to present user interface for the Cardholder to select preferred card application
- // The list of card applications is present in appSelectionRequest.appsArray as a list of Strings
- PaymentCardApplicationSelectionRequest cardAppSelection = ^(WDAcceptAppSelectionRequest * appSelectionRequest){
- // There is more than 1 card application available
- // Present the UI for the Cardholder to select preferred card application (Debit | Credit)
- if(appSelectionRequest.appsArray.count > 0){
- // Here we demonstrate the simplified use of selecting the first card application from the list of available card applications
- // and sending it to the Payment flow
- appSelectionRequest.sendSelectedCardApplication(0);
- }
- };
- // Start the Payment flow
- [[sdk saleManager] pay:paymentConfiguration // the payment configuration containing the Sale Request
- progress:progressUpdate // Block to be executed at the time of Payment flow progress update
- collectSignature:signatureRequiredRequest // Block to be executed at the time of Requesting the capture of the Cardholder signature
- verifySignature:verifySignature // Block to be executed if terminal asks Application to confirm the validity of the Cardholder signature
- selectCardApplication:cardAppSelection // Block to be executed if terminal asks for the Card Application selection in the case Card supports more than one card application
- completion:paymentCompletion]; // Block to be executed at the end of the Payment process
- }];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement