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.
platform :ios, '7.0'
def shared_pods
pod 'MidtransCoreKit'
pod 'MidtransKit'
end
target 'MyBeautifulApp' do
shared_pods
end
If you want to support CardIO, update the Podfile
to this
platform :ios, '7.0'
def shared_pods
pod 'MidtransKit'
pod 'MidtransKit/CardIO'
end
target 'MyBeautifulApp' do
shared_pods
end
Save the file and run the following to install MidtransKit
.
pod install
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>
[CONFIG setClientKey:@"client_key"
environment:MidtransServerEnvironment
merchantServerURL:@"merchant server URL"];
CC_CONFIG.acquiringBank = acquiringBank;
/*
these are banks that we've supported
MTAcquiringBankBCA
MTAcquiringBankBRI
MTAcquiringBankCIMB
MTAcquiringBankMandiri
MTAcquiringBankBNI
*/
CC_CONFIG.authenticationType = MTAuthenticationType3DS;
To enable 1-click you need to:
- enable 3ds
- enable saved card
CC_CONFIG.paymentType = MTCreditCardPaymentTypeOneclick;
CC_CONFIG.saveCardEnabled = YES;
//1-click need 3ds enabled
CC_CONFIG.authenticationType = MTAuthenticationType3DS;
To enable 2-clicks you only need to:
- enable saved card
CC_CONFIG.paymentType = MTCreditCardPaymentTypeTwoclick;
CC_CONFIG.saveCardEnabled = YES;
To create this object, you need to prepare required objects like MidtransItemDetail
as an item representation etc.
//ViewController.m
MidtransItemDetail *itemDetail = [[MidtransItemDetail alloc] initWithItemID:@"item_id"
name:@"item_name"
price:item_price
quantity:item_quantiry];
MidtransCustomerDetails *customerDetails = [[MidtransCustomerDetails alloc] initWithFirstName:@"user_firstname"
lastName:@"user_lastname"
email:@"user_email"
phone:@"user_phone"
shippingAddress:ship_address
billingAddress:bill_address];
MidtransTransactionDetails *transactionDetails = [[MidtransTransactionDetails alloc] initWithOrderID:@"order_id"
andGrossAmount:items_gross_amount];
[[MidtransMerchantClient shared] requestTransactionTokenWithTransactionDetails:transactionDetails
itemDetails:self.itemDetails
customerDetails:customerDetails
completion:^(MidtransTransactionTokenResponse * _Nullable token, NSError * _Nullable error)
{
if (token) {
}
else {
}
}];
we provide method to handle transaction limitation time, to set it you just need following this code
- (void)requestTransactionTokenWithTransactionDetails:(nonnull MidtransTransactionDetails *)transactionDetails
itemDetails:(nullable NSArray<MidtransItemDetail*> *)itemDetails
customerDetails:(nullable MidtransCustomerDetails *)customerDetails
customField:(nullable NSDictionary *)customField
transactionExpireTime:(nullable MidtransTransactionExpire *)expireTime
completion:(void (^_Nullable)(MidtransTransactionTokenResponse *_Nullable token, NSError *_Nullable error))completion;
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.
MidtransUIPaymentViewController *vc = [[MidtransUIPaymentViewController alloc] initWithToken:token];
[self presentViewController:vc animated:YES completion:nil];
Set your view controller to conform with MidtransUIPaymentViewControllerDelegate
//ViewController.m
#import <MidtransKit/MidtransKit.h>
@interface ViewController () <MidtransUIPaymentViewControllerDelegate>
//other code
Set the delegate of MidtransUIPaymentViewController
//ViewController.m
MidtransUIPaymentViewController *vc = [[MidtransUIPaymentViewController alloc] initWithToken:token];
//set the delegate
vc.paymentDelegate = self;
Add two methods to your view controller, these methods are from MidtransUIPaymentViewControllerDelegate protocol
//ViewController.m
#pragma mark - MidtransUIPaymentViewControllerDelegate
- (void)paymentViewController:(MidtransUIPaymentViewController *)viewController paymentSuccess:(MidtransTransactionResult *)result {
NSLog(@"success: %@", result);
}
- (void)paymentViewController:(MidtransUIPaymentViewController *)viewController paymentFailed:(NSError *)error {
[self showAlertError:error];
}
- (void)paymentViewController:(MidtransUIPaymentViewController *)viewController paymentPending:(MidtransTransactionResult *)result {
NSLog(@"pending: %@", result);
}
- (void)paymentViewController_paymentCanceled:(MidtransUIPaymentViewController *)viewController {
NSLog(@"canceled");
}
//This delegate methods is added on ios sdk v1.16.4 to handle the new3ds flow
- (void)paymentViewController:(MidtransUIPaymentViewController *)viewController paymentDeny:(MidtransTransactionResult *)result;
UICONFIG.hideStatusPage = YES;
If you don't want to show this view
then set hideDidYouKnowView
to NO
UICONFIG.hideDidYouKnowView = YES;
We've created MidtransUIThemeManager
to configure the theme color and font of the veritrans payment UI.
MidtransUIFontSource fontSource = [[MidtransUIFontSource alloc] initWithFontNameBold:font_name
fontNameRegular:font_name
fontNameLight:font_name];
[MidtransUIThemeManager applyCustomThemeColor:themeColor themeFont:fontSource];
Put this code before you present the MidtransUIPaymentViewController