Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@WirecardMobileServices
Last active April 15, 2019 07:05
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/20a92146643d91f84067772fcc9d331b to your computer and use it in GitHub Desktop.
Save WirecardMobileServices/20a92146643d91f84067772fcc9d331b to your computer and use it in GitHub Desktop.
Performing the Payment
// It is necessary to implement WDPaymentDelegate methods to receive events from the payment flow
@interface PaymentHandler : NSObject<WDPaymentDelegate>
@end
@implementation PaymentHandler
// The end of the payment process
- (void)completion:(WDSaleResponse * _Nullable)saleResponse saleResponseError:(NSError * _Nullable)saleResponseError {
//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
NSLog(@"sale response: %@, error: %@", saleResponse, saleResponseError);
}
// Updates from the payment flow
- (void)progress:(WDStateUpdate)paymentProgress {
// statusUpdate - coded statuses are reported throughout the payment flow
NSLog(@"progress: %zd", paymentProgress);
}
// 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
- (void)collectSignature:(WDSignatureRequest * _Nonnull)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
- (void)confirm:(WDPaymentConfirmationType)confirmationType paymentConfirmationResult:(PaymentConfirmationResult _Nullable)paymentConfirmationResult {
if (paymentConfirmationResult) {
// Here the simplified use of Approving the Cardholder Signature is demonstrated
paymentConfirmationResult(WDPaymentConfirmationResultApproved);
}
};
// 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
- (void)cardApplication:(WDAppSelectionRequest * _Nonnull)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.selectCardApplication(0);
}
}
@end
// Create the property for payment method handler somewhere in your controller
@property (nonatomic, strong) PaymentHandler *paymentHandler;
//
// The minimum body of the Payment method is shown here
//
-(void)pay{
//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
username:@"yourUsername"
password:@"yourPassword"
completion:setupCompletion];
// Create the instance of the Sale Request
// Here the minimum data is depicted
WDSaleRequestPurchase *saleRequest = [[WDSaleRequestPurchase 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 decimalNumberWithString:@"1"] // Item Quantity
taxRate:[NSDecimalNumber decimalNumberWithString:@"20.00"] // Item Tax rate
itemDescription:@"Item 1" // Item description
productId:nil
externalProductId:nil // External product ID - in the case you are using ERP - such as SAP and wish to refer to the product
];
// Create Payment Configuration to be used in the Pay API later with your Sale Request
WDSaleRequestConfiguration *paymentConfiguration = [[WDSaleRequestConfiguration alloc] initWithSaleRequest:saleRequest];
// 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 to be settled half by Card transaction (5 EUR)
[saleRequest addCardPayment:[NSDecimalNumber decimalNumberWithString:@"5.00"]
terminal:[terminals firstObject]];
// Start the Payment flow
[[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