iOS library to enable GoPay checkout flow via Midtrans API.
-
Open your application in Xcode and select your project’s Package Dependencies tab and click the
+
button: -
Copy the SDK repository URL
https://github.com/veritrans/GoPay-Checkout-SDK
into the search field, Under Dependency Rule, select Branch:master
(to always get the latest version), and then click Add Package. -
After the package download completes, select, and click Add Package.
-
It's done! Gopay Tokenization SDK should now be listed under Swift Package Dependencies in the Xcode Project navigator.
- Download this repo
- Drag the
GopayCheckoutKit.xcframework
to your poroject on xcode - On popup, choose
copy items if needed
andcreate groups
then clickfinish
- build and run
If you're using cocoapods, add this to your .podfile
target 'MyApp' do
pod 'GopayCheckoutKit'
end
then do pod install
For Swift, you need to import GopayCheckoutKit
in your AppDelegate.Swift File and every class where you plan to use the sdk method.
For Objective-C, you need to import GopayCheckoutKit.h
in your AppDelegate.h and every class where you plan to use the sdk method.
You also need to setup your app url scheme, this is used to let the SDK go back to close the webview automatically and navigate to previous screen. For example, your app url scheme should be something like myapp://
, all lowercased.
To setup your app url scheme , There're two ways to do this, You can choose either:
-
Go toÂ
Project Settings
 ->ÂInfo
, and add insideÂThe URL Types
 section a new URL scheme. Add something of the sort ofÂmyapp
 or any name you preferred, lowercased. -
Alternatively, you can also go to your
info.plist
file and paste this code, you can rename themyapp
value with your preferred name.
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>myapp</string>
</array>
</dict>
</array>
SDK initialization can be done anywhere when you want to start to use the sdk's method. In this example, we'll use AppDelegate to setup the sdk within the application:didfinishlaunchingwithoptions:
.
Eversince ios 13, Apple introduces SceneDelegate
, so if your app target includes ios 13 and above, you'll also need to add the handleCallbackUrl
on the SceneDelegate
file within the openURLContexts:
method.
Important notes
For the callbackUrl
parameter, please use your app url scheme with this format myapp://home
, by adding home
to your app url scheme, as shown in the code below
AppDelegate file
- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
...
[GPYClient initWithMerchantServerURL:MERCHANT_SERVER_URL merchantId:MERCHANT_ID callbackUrl:@"myapp://home" isLoggingEnabled:NO];
...
}
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options{
[GPYClient handleCallbackUrl:url];
return YES;
}
SceneDelegate file
- (void)scene:(UIScene *)scene openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts{
NSURL *url = URLContexts.allObjects.firstObject.URL;
[GPYClient handleCallbackUrl:url];
}
AppDelegate File
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
GPYClient.initWithMerchantServerURL(MERCHANT_SERVER_URL, merchantId: MERCHANT_ID, callbackUrl: "myapp://home", isLoggingEnabled: false)
return true
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
GPYClient.handleCallbackUrl(url)
return true
}
SceneDelegate File
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
if let url = URLContexts.first?.url {
GPYClient.handleCallbackUrl(url)
}
}
GPYPartnerDetails *details = [[GPYPartnerDetails alloc]initWithPhoneNumber:@"8212345678" countryCode:@"62"];
[GPYClient linkAccountWithPaymentType:@"gopay" gopayPartnerDetails:details viewController:self completion:^(GPYLinkAccountResult * _Nullable result, NSError * _Nullable error) {
if (result) {
// do something
} else{
NSLog(@"error %@", error);
}
}];
let partnerDetails = GPYPartnerDetails(phoneNumber: "812345678", countryCode: "62")
GPYClient.linkAccount(withPaymentType: "gopay", gopayPartnerDetails: partnerDetails, viewController: self) { (result, error) in
if (result != nil){
// do something
} else {
// error
}
}
[GPYClient enquireAccountWithAccountID:ACCOUNT_ID completion:^(GPYAccountInfo * _Nullable result, NSError * _Nullable error) {
if (result) {
// do something
} else{
NSLog(@"error %@", error);
}
}];
GPYClient.enquireAccount(ACCOUNT_ID) { (result, error) in
if (result != nil) {
//do something
} else {
// error
}
}
[GPYClient disableAccountWithAccountID:ACCOUNT_ID completion:^(GPYDisableAccountResult * _Nullable result, NSError * _Nullable error) {
if (result) {
// do something
} else {
NSLog(@"error %@", error);
}
}];
GPYClient.disableAccount(withAccountID: ACCOUNT_ID) { (result, error) in
if (result != nil){
// do something
} else {
// error
}
}
GPYGopayDetails *gopayDetails = [[GPYGopayDetails alloc]initWithAccountID:ACCOUNT_ID paymentOptionToken:PAYMENT_OPTION_TOKEN];
GPYTransactionDetails *transDetails = [[GPYTransactionDetails alloc]initWithGrossAmount:@100 orderID:ORDER_ID currency:@"IDR"];
GPYCustomerDetails *customerDetails = [[GPYCustomerDetails alloc]initWithPhoneNumber:@"08123456789" firstName:@"fauzi" lastName:nil email:nil];
GPYItemDetails *itemDetails = [[GPYItemDetails alloc]initWithIthItemID:@"itemId1" name:@"one piece t-shirt" price:@100 quantity:@1 category:@"clothing"];
[GPYClient createTransactionWithPaymentType:@"gopay" viewController:self gopayDetails:gopayDetails transactionDetails:transDetails customerDetails:customerDetails itemDetails:@[itemDetails] completion:^(GPYTransactionResult * _Nullable result, NSError * _Nullable error) {
if (result) {
// do something
// Transaction status will be set to "Pending", To actually know the latest transaction status, you should hit get transaction API
} else {
NSLog(@"error transaksi %@", error);
}
}];
let gopayDetais = GPYGopayDetails(accountID: ACCOUNT_ID ?? "", paymentOptionToken: PAYMENT_OPTIONS_TOKEN ?? "")
let transDetails = GPYTransactionDetails(grossAmount: 200, orderID: "abc111", currency: "IDR")
let cusDetails = GPYCustomerDetails(phoneNumber: "088888888", firstName: "fauzi", lastName: "cihuy", email: "emailemail@gmail.com")
let itemDetails1 = GPYItemDetails(ithItemID: "aabb1", name: "one piece t-shirt", price: 100, quantity: 1, category: "shirts")
let itemDetails2 = GPYItemDetails(ithItemID: "aabb2", name: "one piece pants", price: 100, quantity: 1, category: "pants")
GPYClient.createTransaction(withPaymentType: "gopay", viewController: self, gopayDetails: gopayDetais, transactionDetails: transDetails, customerDetails: cusDetails, itemDetails: [itemDetails1, itemDetails2]) { (result, error) in
if (result != nil) {
// do something
} else {
// error
}
}
This response processor is used to help process and handle the webview if you hit the Partner API directly.
[GPYCheckoutProcessor processAccountLinkingWithResponse:linkingResponse viewController:viewController completion:^(GPYLinkAccountResult * _Nullable result, NSError * _Nullable error) {
if (result) {
//do something
} else{
// error
}
}];
GPYCheckoutProcessor.processAccountLinking(with: RESPONSE, viewController: self) { (result, error) in
if (result != nil){
// do something
} else {
// error
}
}
[GPYCheckoutProcessor processCreateTransactionWithResponse:transactionResponse viewController:viewController completion:^(GPYTransactionResult * _Nullable result, NSError * _Nullable error) {
if (result) {
// do something
} else {
// error
}
}];
GPYCheckoutProcessor.processCreateTransaction(with: TRANSACTION_RESPONSE, viewController: self) { (result, error) in
if (result != nil){
// do something
} else {
// error
}
}