Permalink
Fetching contributors…
Cannot retrieve contributors at this time
244 lines (177 sloc) 7.54 KB

Setup

Please read this section first before walking through the implementation guide

Requirement

Cococapods version 1.0.0

Installation

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 --verbose

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

Integration

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"];

Credit Card Payment Feature

Custom Acquiring Bank

CC_CONFIG.acquiringBank = acquiringBank;
/*
these are banks that we've supported
MTAcquiringBankBCA
MTAcquiringBankBRI
MTAcquiringBankCIMB
MTAcquiringBankMandiri
MTAcquiringBankBNI
*/

Enable 3D Secure

CC_CONFIG.secure3DEnabled = YES;

Token Storage

CC_CONFIG.tokenStorageEnabled = YES;

1-Click

CC_CONFIG.paymentType = MTCreditCardPaymentTypeOneclick;
CC_CONFIG.saveCardEnabled = YES;

//1-click need 3D secure enabled
CC_CONFIG.tokenStorageEnabled = YES;

//1-click need 3ds enabled
CC_CONFIG.secure3DEnabled = YES;

2-Clicks

CC_CONFIG.paymentType = MTCreditCardPaymentTypeTwoclick;
CC_CONFIG.saveCardEnabled = YES;

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.

Payment

Generate TransactionTokenResponse object

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 {
     
     }
 }];
Using Time Limit on transaction

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;
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.

MidtransUIPaymentViewController *vc = [[MidtransUIPaymentViewController alloc] initWithToken:token];
[self presentViewController:vc animated:YES completion:nil];

Get Notified

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");
}

Want to Implement Your Own Status Page

UICONFIG.hideStatusPage = YES;

Hide Did You Know Label

If you don't want to show this view

Did You Know Screenshot

then set hideDidYouKnowView to NO

UICONFIG.hideDidYouKnowView = YES;

Customise Theme Color & Font

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