Fetching contributors…
Cannot retrieve contributors at this time
242 lines (161 sloc) 7.11 KB


Please read this section first before walking through the implementation guide


Cococapods version 1.0.0


Navigate to your project's root directory and run pod init to create a Podfile.

pod init

Open up the Podfile and add MidtransKit to your project's target.


def shared_pods
    pod 'MidtransKit'

target 'MyBeautifulApp' do

Save the file and run the following to install MidtransKit.

pod install --verbose

Cocoapods will download and install MidtransKit and also create a .xcworkspace project.


Once you have completed installation of MidtransKit, configure it with your clientKey and environment in your AppDelegate.h

import MidtransKit

MidtransConfig.shared().setClientKey("client key", environment: .sandbox, merchantServerURL: "merchant server url")

Credit Card Payment Feature

Custom Acquiring Bank

MidtransCreditCardConfig.shared().acquiringBank = acquiringBank
these are banks that we've supported

Enable 3D Secure

MidtransCreditCardConfig.shared().secure3DEnabled = true

Token Storage

MidtransCreditCardConfig.shared().tokenStorageEnabled = true


MidtransCreditCardConfig.shared().paymentType = .oneclick
MidtransCreditCardConfig.shared().saveCardEnabled = true

//1-click need 3D secure enabled
MidtransCreditCardConfig.shared().tokenStorageEnabled = true

//1-click need 3ds enabled
MidtransCreditCardConfig.shared().secure3DEnabled = true


MidtransCreditCardConfig.shared().paymentType = .twoclick
MidtransCreditCardConfig.shared().saveCardEnabled = true

You cannot use tokenStorage feature for 2-Click, so disable it and make sure that you're already setup your merchant server to support save card. You can see the documentation here.


Generate TransactionTokenResponse object

To create this object, you need to prepare required objects like MidtransItemDetail as an item representation etc.

let itemDetail = MidtransItemDetail.init(itemID: item_id, name: item_name, price: item_price, quantity: item_qty)

let customerDetail = MidtransCustomerDetails.init(firstName: first_name, lastName: last_name, email: email_addr, phone: phone_number, shippingAddress: ship_addr, billingAddress: bill_addr)

let transactionDetail = MidtransTransactionDetails.init(orderID: order_ir, andGrossAmount: gross_amount)

MidtransMerchantClient.shared().requestTransactionToken(with: transactionDetail!, itemDetails: [itemDetail!], customerDetails: customerDetail) { (response, error) in
	if (response != nil) {
		//handle response                
    else {        
    	//handle error
Present the MidtransUIPaymentViewController

We provide you a MidtransUIPaymentViewController to handle all the payment, it's basically a UINavigtionViewController so you need to use presentViewController:_ animated:_ completion:_ to present it.

let vc = MidtransUIPaymentViewController.init(token: response)
self.present(vc!, animated: true, completion: nil)

Get Notified

Set your view controller to conform with MidtransUIPaymentViewControllerDelegate


import MidtransKit

class ViewController: UIViewController, MidtransUIPaymentViewControllerDelegate

//other code

Set the delegate of MidtransUIPaymentViewController


let vc = MidtransUIPaymentViewController.init(token: response)

//set the delegate
vc?.paymentDelegate = self

self.present(vc!, animated: true, completion: nil)

Add two methods to your view controller, these methods are from MidtransUIPaymentViewControllerDelegate protocol


#pragma mark - MidtransUIPaymentViewControllerDelegate

func paymentViewController(_ viewController: MidtransUIPaymentViewController!, paymentFailed error: Error!) {
func paymentViewController(_ viewController: MidtransUIPaymentViewController!, paymentPending result: MidtransTransactionResult!) {
func paymentViewController(_ viewController: MidtransUIPaymentViewController!, paymentSuccess result: MidtransTransactionResult!) {

func paymentViewController_paymentCanceled(_ viewController: MidtransUIPaymentViewController!) {

Want to Implement Your Own Status Page

MidtransUIConfiguration.shared().hideStatusPage = true

Hide Did You Know Label

If you don't want to show this view

Did You Know Screenshot

then set hideDidYouKnowView to false

MidtransUIConfiguration.shared().hideDidYouKnowView = true/false;

Customise Theme Color & Font

We've created MidtransUIThemeManager to configure the theme color and font of the veritrans payment UI.

let fontSource = MidtransUIFontSource.init(fontNameBold: font_name, fontNameRegular: font_name, fontNameLight: font_name)

MidtransUIThemeManager.applyCustomThemeColor(theme_color, themeFont: fontSource)

Put this code before you present the MidtransUIPaymentViewController

Want Support CardIO ?

Update the Podfile to this

def shared_pods
	pod 'MidtransKit'
	pod 'MidtransKit/CardIO'

target 'MyBeautifulApp' do

Then because CardIO not support dynamic framework, your project need to implement Bridging Header, here is how you can implement it

  1. Add a new file to Xcode (File > New > File), then select “Source” and click “Header File“.
  2. Name your file “YourProjectName-Bridging-Header.h”. Example: In my app Station, the file is named “Station-Bridging-Header”.
  3. Create the file.
  4. Navigate to your project build settings and find the “Swift Compiler – Code Generation” section. You may find it faster to type in “Swift Compiler” into the search box to narrow down the results. Note: If you don’t have a “Swift Compiler – Code Generation” section, this means you probably don’t have any Swift classes added to your project yet. Add a Swift file, then try again.
  5. Next to “Objective-C Bridging Header” you will need to add the name/path of your header file. If your file resides in your project’s root folder simply put the name of the header file there. Examples: “ProjectName/ProjectName-Bridging-Header.h” or simply “ProjectName-Bridging-Header.h”.
  6. Open up your newly created bridging header and import your Objective-C classes using #import statements. Any class listed in this file will be able to be accessed from your swift classes.

Then insert this

#import <MidtransKit/MidtransKit.h>
#import <MidtransCoreKit/MidtransCoreKit.h>

to the bridging header file, now you can the SDK anywhere inside your project without importing MidtransKit inside your class