Payments with myPOS iOS SDK
This guide explains how to accept payments and process refunds in your iOS app using the myPOS SDK. Follow the steps below for a smooth payment experience.
Make a Payment
To initiate a payment, create an instance of PaymentViewController with:
- A list of
CartItemobjects - A unique Order ID
- A Delegate to handle the result
Swift
Swift
let controller = PaymentViewController(cartItems: selectedCartItems,
orderId: ICUtils.randomOrderId,
delegate: self)
self.present(controller, animated: true, completion: nil)Objective-C
Objective-C
PaymentViewController *controller = [[PaymentViewController alloc] initWithCartItems:_selectedCartItems
orderId:[ICUtils randomOrderId]
delegate:self];
[self presentViewController:controller animated:YES completion:nil]; Implement the PaymentDelegate
Make sure your class implements these methods:
Swift
Swift
func didMakePayment(transactionRef: String)
func paymentFailed(error: MobilePaymentSDKError)Objective-C
Objective-C
- (void)didMakePaymentWithTransactionRef:(NSString *)transactionRef;
- (void)paymentFailedWithError:(MobilePaymentSDKError *)error;Refund a Payment
Refunds require:
- The Transaction Reference
- The Order ID used for the payment
- The Amount you want to refund
Also, provide:
- A completed block (on success)
- A failed block (on error)
Swift
Swift
MobilePaymentSDK.refundTransaction(transaction.reference,
orderId: transaction.orderId,
amount: amount,
completed: { (transactionRef) in
showAlertWithText("Refund completed successfully")
},
failed: { (error) in
showAlertWithText("Refund failed. Error: \(error.message)")
})Objective-C
Objective-C
[MobilePaymentSDK refundTransaction:_transaction.reference
orderId:_transaction.orderId
amount:_amount
completed:^(NSString * _Nonnull transactionRef) {
[self showAlertWithText:@"Refund completed successfully"];
} failed:^(MobilePaymentSDKError * _Nonnull error) {
[self showAlertWithText:[@"Refund failed. Error: "
stringByAppendingString:error.message]];
}];Important:
Always make sure you are using the correct Transaction Reference ID for the refund