Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.90 KB | None | 0 0
  1. // The SDK is initialized as shared instance so can be accessed
  2. // from multiple View Controllers
  3. AcceptSDK *sdk = [AcceptSDK sharedInstance];
  4.  
  5. // Set the SDK target environment - in this case Public Test
  6. // and the username and password to authenticate to it
  7. [sdk setupWithEnvironment:AcceptEnvironmentPublicTest
  8. username:@"yourUsername"
  9. password:@"yourPassword"];
  10.  
  11. // Create the instance of the Sale Request
  12. // Here the minimum data is depicted
  13. WDAcceptSaleRequest *saleRequest = [[WDAcceptSaleRequest alloc] initWithUniqueId:@"yourSaleUniqueID" // provide your unique ID to identify the Sale
  14. location:nil // provide the GPS location
  15. inclusiveTaxes:YES // Tax inclusive/exclusive flag
  16. currency:@"EUR" // Currency to use for this Sale
  17. note:@"Test Posmate Sale" // Top level note for this sale
  18. gratuityTaxRate:nil // Gratuity tax rate - nil if no gratuity to be set later in the payment flow
  19. ];
  20.  
  21. // Create one item named "Item 1" costing 10.00 EUR at 20% Tax
  22. [saleRequest addSaleItem:[NSDecimalNumber decimalNumberWithString:@"10.00"] // Item Unit price
  23. quantity:1 // Item Quantity
  24. taxRate:[NSDecimalNumber decimalNumberWithString:@"20.00"] // Item Tax rate
  25. itemDescription:@"Item 1" // Item description
  26. productId:nil // External product ID - in the case you are using ERP - such as SAP and wish to refer to the product
  27. ];
  28.  
  29. // Define the Sale operation as Purchase
  30. saleRequest.operation = AcceptSaleOperationPurchase;
  31.  
  32.  
  33. // Discover active terminals and use it - in this case we use the first one
  34. // Alternatively use the one discovered previously and stored in an instance variable (or user preferences)
  35. [sdk.terminalManager discoverDevices:WDAMiuraExtensionUUID
  36. completion:^(NSArray<WDAcceptTerminal *> * _Nullable terminals, NSError * _Nullable devicesError)
  37. {
  38.  
  39. // Set this Sale in total amount 10 EUR to be settled half by Card transaction (5 EUR)
  40. [saleRequest addCardTransaction:[NSDecimalNumber decimalNumberWithString:@"5.00"]
  41. terminal:[terminals firstObject]];
  42.  
  43. // and half by Cash transaction (5 EUR)
  44. [saleRequest addCashTransaction:[NSDecimalNumber decimalNumberWithString:@"5.00"]];
  45.  
  46.  
  47. // Create Payment Configuration to be used in the Pay API later
  48. WDAcceptPaymentConfig *paymentConfiguration = [WDAcceptPaymentConfig new];
  49.  
  50. // Set the Sale of this payment configuration to be your new Sale Request
  51. paymentConfiguration.sale = saleRequest;
  52.  
  53.  
  54. // The end of the payment process
  55. SaleCompletion paymentCompletion = ^(WDAcceptSaleResponse* sale, NSError* error){
  56. //sale - Is the completed Sale - contains the sale status, details, results
  57. //error - If any error is encountered during the sale it would be reported
  58. //in the form of error and hierarchy of underlying errors to give you as much details as possible
  59. };
  60.  
  61. // Updates from the payment flow
  62. PaymentProgress progressUpdate = ^(AcceptStateUpdate statusUpdate){
  63. // statusUpdate - coded statuses are reported throughout the payment flow
  64. };
  65.  
  66. // In the case the Cardholder Signature is required by the Payment flow this block will be executed
  67. // Your task is to respond to it by collecting the signature image from the customer and
  68. // posting it back in the sendCollectedSignature method
  69. SignatureRequiredRequest signatureRequiredRequest = ^(WDAcceptSignatureRequest* signatureRequest){
  70. //signatureRequest - comes from the payment flow and once you collect the signature from the customer
  71. // send it back in the signatureRequest.sendCollectedSignature
  72. signatureRequest.sendCollectedSignature([TestUtils signatureImageFromText:@"Test"],nil);
  73. //The signature image is transferred to the backend and stored with the Sale
  74. };
  75.  
  76. // Note: Applicable to terminals without BUTTONS
  77. // In the case the Cardholder Signature was collected then the merchant is required to confirm it's validity
  78. // A. If the terminal has buttons that are used for Approving/Rejecting then this block is either never called from Payment flow
  79. // or it's signatureVerificationCallback comes nil
  80. // B. If the terminal does not have buttons then the Application must present a user interface to Approve/Reject the Cardholder Signature
  81. SignatureVerificationRequest verifySignature = ^(SignatureVerificationResult signatureVerificationResult, NSError* signatureVerificationError){
  82.  
  83. if (signatureVerificationResult) {
  84. // Here the simplified use of Approving the Cardholder Signature is demonstrated
  85. signatureVerificationResult(AcceptSignatureVerificationResultApproved);
  86. }
  87.  
  88. };
  89.  
  90. // Note: Applicable to terminals without BUTTONS
  91. // In the case the payment Card has more than one card application available then the client application
  92. // has to present user interface for the Cardholder to select preferred card application
  93. // The list of card applications is present in appSelectionRequest.appsArray as a list of Strings
  94. PaymentCardApplicationSelectionRequest cardAppSelection = ^(WDAcceptAppSelectionRequest * appSelectionRequest){
  95. // There is more than 1 card application available
  96. // Present the UI for the Cardholder to select preferred card application (Debit | Credit)
  97. if(appSelectionRequest.appsArray.count > 0){
  98. // Here we demonstrate the simplified use of selecting the first card application from the list of available card applications
  99. // and sending it to the Payment flow
  100. appSelectionRequest.sendSelectedCardApplication(0);
  101. }
  102. };
  103.  
  104. // Start the Payment flow
  105. [[sdk saleManager] pay:paymentConfiguration // the payment configuration containing the Sale Request
  106. progress:progressUpdate // Block to be executed at the time of Payment flow progress update
  107. collectSignature:signatureRequiredRequest // Block to be executed at the time of Requesting the capture of the Cardholder signature
  108. verifySignature:verifySignature // Block to be executed if terminal asks Application to confirm the validity of the Cardholder signature
  109. selectCardApplication:cardAppSelection // Block to be executed if terminal asks for the Card Application selection in the case Card supports more than one card application
  110. completion:paymentCompletion]; // Block to be executed at the end of the Payment process
  111.  
  112.  
  113.  
  114. }];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement