We provide an API-only implementation for all payment types. This allows users to bring your own UI to the mobile App. Please read this section first before walking through the implementation guide
- Create a merchant account in MAP
- Setup your merchant accounts settings, in particular Notification URL.
- Credit Card
- Telkomsel Cash
- XL Tunai
- Indosat Dompetku
- VA / Bank Transfer
- CIMB Clicks
- Indomaret
- BCA KlikPay
- Klikbca
- Mandiri E-Cash
- Mandiri Clickpay
- BRI E-Pay
- Kios ON
- GCI
- Akulaku
- Save Card Without Charge
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.
platform :ios, '7.0'
def shared_pods
pod 'MidtransCoreKit'
end
target 'MyBeautifulApp' do
shared_pods
end
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
//AppDelegate.m
#import <MidtransKit/MidtransKit.h>
[MidtransConfig setClientKey:@"your_client_key" andServerEnvironment:server_environment];
Before you can do the payment, you need to generate a transaction_token as representation of you credentials data.
//ViewController.m
MidtransTransactionDetails *transactionDetails =
[[MidtransTransactionDetails alloc] initWithOrderID:@"random_string"
andGrossAmount:gross_amount];
MidtransItemDetail *itemDetail =
[[MidtransItemDetail alloc] initWithItemID:@"your_item_id"
name:@"item_name"
price:item_price
quantity:item_qty];
NSArray *itemDetails = @[itemDetail];
MidtransCustomerDetails *customerDetails =
[[MidtransCustomerDetails alloc] initWithFirstName:@"first_name"
lastName:@"last_name"
email:@"email"
phone:@"phone_number"
shippingAddress:shipping_address
billingAddress:billing_address]
NSURL *merchantURL = [NSURL URLWithString:@"merchant-url"];
[[MidtransMerchantClient shared] requestTransactionTokenWithclientTokenURL:merchantURL
transactionDetails:transactionDetails
itemDetails:itemDetails
customerDetails:customerDetails
completion:^(TransactionTokenResponse *token, NSError * error)
{
if (token) {
//use this transaction token
} else {
//handle error
}
}];
In Credit Card transaction there are two main steps to make transaction
- Generate
card_tokenas representation of credit card - Charge transaction with generated and valid
card_token
Use following code as a template
MidtransCreditCard *card =
[[MidtransCreditCard alloc] initWithNumber:@"card_number"
expiryMonth:@"card_expiry_month"
expiryYear:@"card_expiry_year"
cvv:card_cvv];
//Set 3D secure enable or not by set the secure parameter
BOOL enable3DSecure = YES;
MidtransTokenizeRequest *tokenRequest =
[[MidtransTokenizeRequest alloc] initWithCreditCard:card
grossAmount:transactionDetails.grossAmount
secure:enable3DSecure];
[[MidtransClient shared] generateToken:tokenRequest completion:^(NSString *token, NSString *redirectURL, NSError *error) {
if (error) {
//handle error
} else {
//use the card token
}
}];
After you have a valid card_token, you can continue to the final step of payment and your credit card will be charged.
Use following code as a template.
MidtransPaymentCreditCard *paymentDetail = [[MidtransPaymentCreditCard alloc] initWithCreditCardToken:card_token customerDetails:transaction_token.customerDetails];
//set this if you want to save card
paymentDetail.saveToken = self.view.saveCardSwitch.on;
MidtransTransaction *transaction = [[MidtransTransaction alloc] initWithPaymentDetails:paymentDetail token:transaction_token];
You will have result if the transaction is success, and error if the transaction is failed.
MidtransPaymentTelkomselCash *paymentDetails = [[MidtransPaymentTelkomselCash alloc] initWithMSISDN:<phone number>];
MidtransTransaction *transaction = [[MidtransTransaction alloc] initWithPaymentDetails:paymentDetails token:transaction_token];
[[MidtransMerchantClient shared] performTransaction:transaction completion:^(MidtransTransactionResult *result, NSError *error) {
if (error) {
//handle error
} else {
//handle success result
}
}];
MidtransPaymentXLTunai *paymentDetails = [[MidtransPaymentXLTunai alloc] init];
MidtransTransaction *transaction = [[MidtransTransaction alloc] initWithPaymentDetails:paymentDetails token:transaction_token];
[[MidtransMerchantClient shared] performTransaction:transaction completion:^(MidtransTransactionResult *result, NSError *error) {
if (error) {
//handle error
} else {
if (result.redirectURL) {
//transaction need to continue via webcontainer
MidtransPaymentWebController *vc = [[MidtransPaymentWebController alloc] initWithTransactionResult:result paymentIdentifier:@"xl_tunai"];
vc.delegate = self;
//present the web container
[self.navigationController pushViewController:vc animated:YES];
}
}
}];
MidtransPaymentIndosatDompetku *paymentDetails = [[MidtransPaymentIndosatDompetku alloc] initWithMSISDN:<phone number>];
MidtransTransaction *transaction = [[MidtransTransaction alloc] initWithPaymentDetails:paymentDetails token:transaction_token];
[[MidtransMerchantClient shared] performTransaction:transaction completion:^(MidtransTransactionResult *result, NSError *error) {
if (error) {
//handle error
} else {
//handle success result
}
}];
You need to create paymentDetail as object of MidtransPaymentBankTransfer and set the bank transfer type with MidtransVAType values
- MidtransVATypeBCA
- MidtransVATypeMandiri
- MidtransVATypePermata
- MidtransVATypeOther
MidtransPaymentBankTransfer *paymentDetails = paymentDetails = [[MidtransPaymentBankTransfer alloc] initWithBankTransferType:<va type> email:<email>];
MidtransTransaction *transaction = [[MidtransTransaction alloc] initWithPaymentDetails:paymentDetails];
After charge transaction was successful, you'll get MidtransTransactionResult object, which have codes that needed to continue the transaction via ATM etc.
if (result) {
<for Mandiri VA>
NSString *billpayCode = transactionResult.mandiriBillpayCode;
NSString *companyCode = transactionResult.mandiriBillpayCompanyCode;
<for Others VA>
NSString *virtualAccountNumber = transactionResult.virtualAccountNumber;
} else {
//error
}
MidtransPaymentCIMBClicks *paymentDetails = [[MidtransPaymentCIMBClicks alloc] init];
MidtransTransaction *transaction = [[MidtransTransaction alloc] initWithPaymentDetails:paymentDetails token:transaction_token];
[[MidtransMerchantClient shared] performTransaction:transaction completion:^(MidtransTransactionResult *result, NSError *error) {
if (error) {
//handle error
} else {
if (result.redirectURL) {
//transaction need to continue via webcontainer
MidtransPaymentWebController *vc = [[MidtransPaymentWebController alloc] initWithTransactionResult:result paymentIdentifier:@"cimb_clicks"];
vc.delegate = self;
//present the web container
[self.navigationController pushViewController:vc animated:YES];
}
}
}];
MidtransPaymentCStore *paymentDetails = [[MidtransPaymentCStore alloc] init];
MidtransTransaction *transaction = [[MidtransTransaction alloc] initWithPaymentDetails:paymentDetails token:transaction_token];
[[MidtransMerchantClient shared] performTransaction:transaction completion:^(MidtransTransactionResult *result, NSError *error) {
if (error) {
//handle error
} else {
//transaction success
}
}];
MidtransPaymentBCAKlikpay *paymentDetails = [[MidtransPaymentBCAKlikpay alloc] init];
MidtransTransaction *transaction = [[MidtransTransaction alloc] initWithPaymentDetails:paymentDetails token:transaction_token];
[[MidtransMerchantClient shared] performTransaction:transaction completion:^(MidtransTransactionResult *result, NSError *error) {
if (error) {
//handle error
} else {
if (result.redirectURL) {
//transaction need to continue via webcontainer
MidtransPaymentWebController *vc = [[MidtransPaymentWebController alloc] initWithTransactionResult:result paymentIdentifier:@"bca_klikpay"];
vc.delegate = self;
//present the web container
[self.navigationController pushViewController:vc animated:YES];
}
}
}];
MidtransPaymentKlikBCA *paymentDetails = [[MidtransPaymentKlikBCA alloc] initWithKlikBCAUserId:<klikbca userid>];
MidtransTransaction *transaction = [[MidtransTransaction alloc] initWithPaymentDetails:paymentDetails token:transaction_token];
[[MidtransMerchantClient shared] performTransaction:transaction completion:^(MidtransTransactionResult *result, NSError *error) {
if (error) {
//handle error
} else {
//transaction success
}
}];
MidtransPaymentMandiriECash *paymentDetails = [[MidtransPaymentMandiriECash alloc] init];
MidtransTransaction *transaction = [[MidtransTransaction alloc] initWithPaymentDetails:paymentDetails token:transaction_token];
[[MidtransMerchantClient shared] performTransaction:transaction completion:^(MidtransTransactionResult *result, NSError *error) {
if (error) {
//handle error
} else {
if (result.redirectURL) {
//transaction need to continue via webcontainer
MidtransPaymentWebController *vc = [[MidtransPaymentWebController alloc] initWithTransactionResult:result paymentIdentifier:@"mandiri_ecash"];
vc.delegate = self;
//present the web container
[self.navigationController pushViewController:vc animated:YES];
}
}
}];
MidtransPaymentMandiriClickpay *paymentDetails = [[MidtransPaymentMandiriClickpay alloc] initWithCardNumber:<clickpay number> clickpayToken:<clickpay token>];
MidtransTransaction *transaction = [[MidtransTransaction alloc] initWithPaymentDetails:paymentDetails token:transaction_token];
[[MidtransMerchantClient shared] performTransaction:transaction completion:^(MidtransTransactionResult *result, NSError *error) {
if (error) {
//handle error
} else {
//transaction success
}
}];
MidtransPaymentEpayBRI *paymentDetails = [[MidtransPaymentEpayBRI alloc] init];
MidtransTransaction *transaction = [[MidtransTransaction alloc] initWithPaymentDetails:paymentDetails token:transaction_token];
[[MidtransMerchantClient shared] performTransaction:transaction completion:^(MidtransTransactionResult *result, NSError *error) {
if (error) {
//handle error
} else {
if (result.redirectURL) {
//transaction need to continue via webcontainer
MidtransPaymentWebController *vc = [[MidtransPaymentWebController alloc] initWithTransactionResult:result paymentIdentifier:@"bri_epay"];
vc.delegate = self;
//present the web container
[self.navigationController pushViewController:vc animated:YES];
}
}
}];
MidtransPaymentKiosOn *paymentDetails = [[MidtransPaymentKiosOn alloc] init];
MidtransTransaction *transaction = [[MidtransTransaction alloc] initWithPaymentDetails:paymentDetails token:transaction_token];
[[MidtransMerchantClient shared] performTransaction:transaction completion:^(MidtransTransactionResult *result, NSError *error) {
if (error) {
//handle error
} else {
//handle success result
}
}];
MIdtransPaymentGCI *paymentDetails = [[MIdtransPaymentGCI alloc] initWithCardNumber:cardNumber password:transaction_token]
MidtransTransaction *transaction = [[MidtransTransaction alloc] initWithPaymentDetails:paymentDetails token:transaction_token];
[[MidtransMerchantClient shared] performTransaction:transaction completion:^(MidtransTransactionResult *result, NSError *error) {
if (error) {
//handle error
} else {
//handle success result
}
}];
MidtransPaymentAkulaku *paymentDetails = [[MidtransPaymentAkulaku alloc] init];
MidtransTransaction *transaction = [[MidtransTransaction alloc] initWithPaymentDetails:paymentDetails token:transaction_token];
[[MidtransMerchantClient shared] performTransaction:transaction completion:^(MidtransTransactionResult *result, NSError *error) {
if (error) {
//handle error
} else {
if (result.redirectURL) {
//transaction need to continue via webcontainer
MidtransPaymentWebController *vc = [[MidtransPaymentWebController alloc] initWithTransactionResult:result paymentIdentifier:@"akulaku"];
vc.delegate = self;
//present the web container
[self.navigationController pushViewController:vc animated:YES];
}
}
}];
accepted Format
| Name | Type | Nullable | Format | |
|---|---|---|---|---|
| credit_card_number | NSString | N | 4111111111111111 | |
| expiry_month | NSString | N | MM | |
| expiry_year | NSString | N | YYYY |
###code usage
MidtransCreditCard *creditCard = [[MidtransCreditCard alloc] initWithNumber:@"4111111111111111" expiryMonth:@"11" expiryYear:@"2018" cvv:@"123"];
[[MidtransClient shared] registerCreditCard:creditCard completion:^(MidtransMaskedCreditCard * _Nullable maskedCreditCard, NSError * _Nullable error) {
}];
###Output
| JSON Attribute | Type | Description |
|---|---|---|
| transaction_id | String | Transaction ID given by Midtrans |
| cardhash | String | First 6-digit and last 4-digit of customer's |
| status_code | number | Status code |
| token_id | String | hashed card with 32 length string |
"cardhash" : "411111XXXXXX1111",
"token_id" : "411111CKtOalcBOxUiRTuGiIZsij1111",
"status_code" : "200",
"transaction_id" : "d177732e-9aa8-4d69-8e7c-9a2ea880d475"