GoPay's iOS SDK for Payments REST API
Switch branches/tags
Nothing to show
Clone or download
Latest commit b24f2aa Jan 28, 2016
Failed to load latest commit information.
gopay-api-example podspec update Dec 17, 2015
gopay-api Updated includes from <angled> to "quotes" Dec 17, 2015
gopay-ui Initial commit Dec 17, 2015
LICENSE Update LICENSE Jan 28, 2016 Updated readme Dec 18, 2015
gopay-ios-api.podspec podspec update Dec 17, 2015



The simplest way to install SDK is to use CocoaPods:

Add this line to your podfile:

pod 'gopay-ios-api', :git => '', :tag => '1.0.0'


1. Initialize the GoPay iOS SDK

Add the GoPay iOS SDK header file to your app delegate. Import this header in any of your implementation files to use the SDK.

#import <GPAPI.h>

Add the following code to initialize the SDK in your app delegate's application:didFinishLaunchingWithOptions: method.

[[GPAPI sharedAPI] setClientID:@"<<Your client ID>>" clientSecret:@"<<Your client secret>>" productionMode:NO];

You dont't need specify token scope because SDK automatically get it depending on the operation that performs.

2. Initialize Payment object

We need to initialize Payment to store info about payment in it

GPPaymentRequest *payment = [[GPPaymentRequest alloc] init];
payment.amount = 20;
payment.currency = @"CZK";
payment.order_number = @"001";
payment.order_description = @"test";
GPPayer *payer = [[GPPayer alloc] init];
payer.allowed_payment_instruments = @[];
payer.default_payment_instrument = @"PAYMENT_CARD"; = @"Zbynek"; = @"Zak"; = @""; = @"+420777456123"; = @"C.Budejovice"; = @"Plana 67"; = @"370 03"; = @"CZE";
payment.payer = payer;
GPTarget *target = [[GPTarget alloc] init];
target.type = PAY_TARGET_ACCOUNT;
target.goid = @"8035442195"; // Usually your go id = target;

3. Create payment

[GPAPI sharedAPI] createPayment:payment withHandleSuccess:^(GPPayment *payment) {

} failure:^(NSError *error) {


4. Open payment gateway in GPAPIWebView

In handle success block we get payment url a then we load it in GPAPIWebView which is UIViewController with UIWebView and some special functionality.

#import <GPAPIWebView.h>

GPAPIWebView *webView = [[GPAPIWebView alloc] init];
webView.openInSafariUrls = [[GPAPI sharedAPI] bankURLs];
webView.url = payment.gw_url; // z vytvorene platby ziskame url brany, kterou otevreme v GPAPIWebView
webView.webViewDidDone = ^(long long paymentID) {
    [self dismissViewControllerAnimated:YES completion:nil];
webView.webViewCanceled = ^{
    [self dismissViewControllerAnimated:YES completion:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:webView];
navController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:navController animated:YES completion:nil]; 

5. Check payment status

[[GPAPI sharedAPI] getPaymentWithID:paymentID withHandleSuccess:^(GPPayment *payment) {
    NSLog(@"payment state: %@", [payment userReadableState]);
} failure:^(NSError *error) {
    NSLog(@"error: %@", error);

6. Refund payment

To refund payment we need payment id and amount to be refunded.

[[GPAPI sharedAPI] refundPaymentWithID:3000006620 amount:10000 withHandleSuccess:^(GPAPIResult result) {
} failure:^(NSError *error) {


7. Create recurrence

To create recurrence we need to create GPCreateNextPayment object and set amount, currency, order_number, order_description and items then we call createRecurrence with this object and payment id.

GPCreateNextPayment *createNextPayment = [[GPCreateNextPayment alloc] init];
createNextPayment.amount = 500;
createNextPayment.currency = @"CZK";
createNextPayment.order_number = @"002";
createNextPayment.order_description = @"pojisteni02";
createNextPayment.items = @[[[GPItem alloc] initWithName:@"item01" amount:500]];

[[GPAPI sharedAPI] createRecurrence:createNextPayment forPaymentWithID:3000006542 withHandleSuccess:^(GPPayment *payment) {
} failure:^(NSError *error) {


8. Void reccurence

To void reccurence we need payment id.

[[GPAPI sharedAPI] voidRecurrenceForPaymentWithID:3000139597 withHandleSuccess:^(GPAPIResult result) {

} failure:^(NSError *error) {

9. Void authorization

To void authorization we need payment id.

[[GPAPI sharedAPI] refundPaymentWithID:3000006620 amount:10000 withHandleSuccess:^(GPAPIResult result) {
} failure:^(NSError *error) {


10. Capture preauthorized payment

To capture preauthorized payment we need payment id.

[[GPAPI sharedAPI] capturePaymentWithID:3000141703 withHandleSuccess:^(GPAPIResult result) {

} failure:^(NSError *error) {

SDK responses

Every SDK call has success and failure block. In failure block we get NSError object, where in userInfo are errors from API.

NSLog(@"errors: %@", error.userInfo[@"errors"]);

In success block we get GPPayment object from createPayment, getPaymentWithID and createRecurrence methods. GPPayment is defined in GPPayment.h. From refundPaymentWithID, voidRecurrence, voidAuthorization and capturePayment we get GPAPIResult enum which is defined in GPAPIConstants.h.


All enums are defined in GPAPIConstants.h.