Performing a payment

AS
Last updated 4 months ago

Let's get started with some code examples to learn the basics of integrating with Yoco.

You can also download our Example App (please insert your API key and Secret in the AppDelegate.m file)

Please make sure that you have successfully authenticated the Yoco SDK before you attempt to perform a transaction.

Step 1: Listen for events

Extend from the YocoClientDelegate to listen for events from the Yoco SDK.

/* Setup a YocoClientDelegate that will receive response events from the Yoco application */
#import <YocoClientDelegate.h>
@interface ExampleClientHandler : NSObject<YocoClientDelegate>
@end

Implement your handler

#import <YocoSDK/YocoSDKClient.h>
@implementation ExampleClientHandler
/** handle successful transaction */
-(void) handleTransactionSuccess:(YocoPaymentSuccessResponse*) response {
NSLog(@"payment success")
}
/** handle failure of transaction */
-(void) handleTransactionFailure:(YocoPaymentFailureResponse*) response {
NSLog(response.message)
}
/** handle successful refund */
-(void) handleRefundSuccess:(YocoRefundSuccessResponse *)response {
NSLog(@"refund success")
}
/** handle failure of refund */
-(void) handleRefundFailure:(YocoRefundFailureResponse *)response {
NSLog(response.message)
}
@end

After you have initialised your YocoClient you should attach your delegate

//Setup your delegate and register it with the YocoClient
ExampleClientHandler* yocoClientHandler = [[ExampleClientHandler alloc] init];
[YocoClient setDelegate:yocoClientHandler];

Step 2: Starting a payment

When you start a payment you must pass in a YocoStaff object which identifies which staff member (within your application) is performing this payment. This allows the merchant to track payments to their staff members while only having a single Yoco login or API token.

-(void)examplePayment {
// The details of the staff member performing the transaction
YocoStaff* staff = [[YocoStaff alloc] initWithStaffNumber:@"some-internal-staff-number"
andName:@"Joe Bloggs"];
// Perform a simple payment with the YocoClient
// 2500 is R25.00 (amounts are always in cents)
[YocoClient payCents:2500 withCurrency:@"ZAR" andStaff:staff];
}