Skip to content

Commit

Permalink
Feature/refine gopay (#388)
Browse files Browse the repository at this point in the history
* impl callback gopay

* fix gopay flow

* refine result handler

* refine handleGopayStatus
  • Loading branch information
jukiginanjar authored Nov 5, 2018
1 parent c24aa4e commit 0b93e12
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 44 deletions.
14 changes: 14 additions & 0 deletions MidtransCoreKit/MidtransCoreKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
0CB8B7C8206B55C10067A0B8 /* MidtransPromoPromos.h in Headers */ = {isa = PBXBuildFile; fileRef = 0CB8B7BB206B558D0067A0B8 /* MidtransPromoPromos.h */; settings = {ATTRIBUTES = (Public, ); }; };
0CB8B7C9206B55C10067A0B8 /* MidtransPromoResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = 0CB8B7BD206B558D0067A0B8 /* MidtransPromoResponse.h */; settings = {ATTRIBUTES = (Public, ); }; };
3D85847D2111C52500899462 /* MidtransCoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E5CDEC8A1E9340CA0032DC3B /* MidtransCoreKit.framework */; };
DD1F2A50218AD29100D73039 /* MIDUrlHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = DD1F2A4E218AD29100D73039 /* MIDUrlHandler.h */; settings = {ATTRIBUTES = (Public, ); }; };
DD1F2A51218AD29100D73039 /* MIDUrlHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = DD1F2A4E218AD29100D73039 /* MIDUrlHandler.h */; settings = {ATTRIBUTES = (Public, ); }; };
DD1F2A52218AD29100D73039 /* MIDUrlHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = DD1F2A4F218AD29100D73039 /* MIDUrlHandler.m */; };
DD1F2A53218AD29100D73039 /* MIDUrlHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = DD1F2A4F218AD29100D73039 /* MIDUrlHandler.m */; };
DD1F2A54218AD29100D73039 /* MIDUrlHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = DD1F2A4F218AD29100D73039 /* MIDUrlHandler.m */; };
E546D1F9217EFF4C006D4650 /* MidtransPaymentAkulaku.h in Headers */ = {isa = PBXBuildFile; fileRef = E546D1F7217EFF4B006D4650 /* MidtransPaymentAkulaku.h */; settings = {ATTRIBUTES = (Public, ); }; };
E546D1FA217EFF4C006D4650 /* MidtransPaymentAkulaku.h in Headers */ = {isa = PBXBuildFile; fileRef = E546D1F7217EFF4B006D4650 /* MidtransPaymentAkulaku.h */; settings = {ATTRIBUTES = (Public, ); }; };
E546D1FB217EFF4C006D4650 /* MidtransPaymentAkulaku.m in Sources */ = {isa = PBXBuildFile; fileRef = E546D1F8217EFF4B006D4650 /* MidtransPaymentAkulaku.m */; };
Expand Down Expand Up @@ -437,6 +442,8 @@
30D9ABFA1C76FD1D00F858AE /* MidtransNetworkOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MidtransNetworkOperation.h; sourceTree = "<group>"; };
30D9ABFB1C76FD1D00F858AE /* MidtransNetworkOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MidtransNetworkOperation.m; sourceTree = "<group>"; };
3D8584782111C52500899462 /* MidtransCoreKitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MidtransCoreKitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
DD1F2A4E218AD29100D73039 /* MIDUrlHandler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MIDUrlHandler.h; sourceTree = "<group>"; };
DD1F2A4F218AD29100D73039 /* MIDUrlHandler.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MIDUrlHandler.m; sourceTree = "<group>"; };
E50D85D21D0EC64E00F26D2E /* MidtransPaymentMandiriECash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MidtransPaymentMandiriECash.h; sourceTree = "<group>"; };
E50D85D31D0EC64E00F26D2E /* MidtransPaymentMandiriECash.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MidtransPaymentMandiriECash.m; sourceTree = "<group>"; };
E50D85E31D0ECB7000F26D2E /* MidtransPaymentBCAKlikpay.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MidtransPaymentBCAKlikpay.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -859,6 +866,8 @@
E5FBC7F01E39E3FF006B574D /* MidtransNetworkLogger.m */,
00B827761DDAC76800E5AC17 /* MidtransDeviceHelper.h */,
00B827771DDAC76800E5AC17 /* MidtransDeviceHelper.m */,
DD1F2A4E218AD29100D73039 /* MIDUrlHandler.h */,
DD1F2A4F218AD29100D73039 /* MIDUrlHandler.m */,
);
name = Utils;
sourceTree = "<group>";
Expand Down Expand Up @@ -953,6 +962,7 @@
E57120581E937A790064F515 /* SNPPointDataModels.h in Headers */,
E57120591E937A790064F515 /* SNPPointResponse.h in Headers */,
E571205A1E937A790064F515 /* MidtransBinDataModels.h in Headers */,
DD1F2A51218AD29100D73039 /* MIDUrlHandler.h in Headers */,
E571205B1E937A790064F515 /* MidtransBinResponse.h in Headers */,
E571205C1E937A790064F515 /* MidtransTransactionExpire.h in Headers */,
E571205D1E937A790064F515 /* MidtransPromo.h in Headers */,
Expand Down Expand Up @@ -1047,6 +1057,7 @@
E55F635B1E934C4700C012C8 /* MidtransCreditCardConfig.h in Headers */,
E55F635C1E934C4700C012C8 /* MidtransHelper.h in Headers */,
E55F635D1E934C4700C012C8 /* MidtransNetworking.h in Headers */,
DD1F2A50218AD29100D73039 /* MIDUrlHandler.h in Headers */,
E55F635E1E934C4700C012C8 /* MidtransNetworkOperation.h in Headers */,
E55F635F1E934C4700C012C8 /* MidtransNetworkLogger.h in Headers */,
E55F63601E934C4700C012C8 /* MidtransDeviceHelper.h in Headers */,
Expand Down Expand Up @@ -1239,6 +1250,7 @@
buildActionMask = 2147483647;
files = (
E546D1FD217EFF4C006D4650 /* MidtransPaymentAkulaku.m in Sources */,
DD1F2A54218AD29100D73039 /* MIDUrlHandler.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1305,6 +1317,7 @@
E57120341E937A2C0064F515 /* MidtransPaymentBankTransfer.m in Sources */,
E57120351E937A2C0064F515 /* MidtransPaymentCIMBClicks.m in Sources */,
E57120361E937A2C0064F515 /* MidtransTransaction.m in Sources */,
DD1F2A53218AD29100D73039 /* MIDUrlHandler.m in Sources */,
0C1B35DC1ED6B3A7003F6806 /* SNPFreeTextPayment.m in Sources */,
E57120371E937A2C0064F515 /* MidtransTransactionDetails.m in Sources */,
E57120381E937A2C0064F515 /* MidtransTokenizeRequest.m in Sources */,
Expand Down Expand Up @@ -1394,6 +1407,7 @@
E55F63D51E934C6400C012C8 /* MidtransPaymentXLTunai.m in Sources */,
E55F63D61E934C6400C012C8 /* MidtransPaymentIndosatDompetku.m in Sources */,
E55F63D71E934C6400C012C8 /* MidtransPaymentKiosOn.m in Sources */,
DD1F2A52218AD29100D73039 /* MIDUrlHandler.m in Sources */,
E55F63D81E934C6400C012C8 /* MIdtransPaymentGCI.m in Sources */,
0C313E1E1FCD2C5A0074366F /* MidtransPaymentGOPAY.m in Sources */,
E5711FF41E9379950064F515 /* SNPPointResponse.m in Sources */,
Expand Down
19 changes: 19 additions & 0 deletions MidtransCoreKit/MidtransCoreKit/MIDUrlHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// MIDUrlHandler.h
// MidtransCoreKit
//
// Created by Muhammad.Masykur on 01/11/18.
// Copyright © 2018 Midtrans. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface MIDUrlHandler : NSObject

+ (void)handleUrl:(NSURL *)url;

@end

NS_ASSUME_NONNULL_END
24 changes: 24 additions & 0 deletions MidtransCoreKit/MidtransCoreKit/MIDUrlHandler.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// MIDUrlHandler.m
// MidtransCoreKit
//
// Created by Muhammad.Masykur on 01/11/18.
// Copyright © 2018 Midtrans. All rights reserved.
//

#import "MIDUrlHandler.h"
#import "MidtransConstant.h"

@implementation MIDUrlHandler

+ (void)handleUrl:(NSURL *)url {
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
for (NSString *param in [url.query componentsSeparatedByString:@"&"]) {
NSArray *elts = [param componentsSeparatedByString:@"="];
if([elts count] < 2) continue;
[params setObject:[elts lastObject] forKey:[elts firstObject]];
}

[[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_GOPAY_STATUS object:params];
}
@end
1 change: 1 addition & 0 deletions MidtransCoreKit/MidtransCoreKit/MidtransConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
@property (nonatomic) NSString *customBCASubcompanyCode;
@property (nonatomic) NSString *customPermataVARecipientName;
@property (nonatomic) NSString *customBNIVANumber;
@property (nonatomic) NSString *callbackSchemeURL;

@property (nonatomic) NSArray *customPaymentChannels;
@property (nonatomic) NSDictionary *customFreeText;
Expand Down
1 change: 1 addition & 0 deletions MidtransCoreKit/MidtransCoreKit/MidtransCoreKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,4 @@ FOUNDATION_EXPORT const unsigned char MidtransCoreKitVersionString[];
#import "MidtransPaymentGOPAY.h"
#import "MidtransPaymentDanamonOnline.h"
#import "MidtransPromoDataModels.h"
#import "MIDUrlHandler.h"
6 changes: 6 additions & 0 deletions MidtransCoreKit/MidtransCoreKit/MidtransMerchantClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,12 @@ - (void)requestTransactionTokenWithTransactionDetails:(nonnull MidtransTransacti
dictionaryParameters[@"enabled_payments"] = CONFIG.customPaymentChannels;
}

if ([CONFIG callbackSchemeURL].length > 0) {
NSDictionary *gopay = @{@"enable_callback": @YES,
@"callback_url": [CONFIG callbackSchemeURL]};
dictionaryParameters[@"gopay"] = gopay;
}

NSError *error;
if (![customerDetails isValidCustomerData:&error]) {
if (completion) completion (nil, error);
Expand Down
6 changes: 3 additions & 3 deletions MidtransCoreKit/MidtransCoreKit/MidtransTransactionResult.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ @interface MidtransTransactionResult()
@property (nonatomic, readwrite) NSString *indomaretPaymentCode;
@property (nonatomic, readwrite) NSString *kiosonExpireTime;
@property (nonatomic, readwrite) NSString *mandiriBillpayCode;
@property (nonatomic,readwrite) NSString *qrcodeUrl;
@property (nonatomic,readwrite) NSString *deeplinkUrl;
@property (nonatomic, readwrite) NSString *qrcodeUrl;
@property (nonatomic, readwrite) NSString *deeplinkUrl;
@property (nonatomic, readwrite) NSString *mandiriBillpayCompanyCode;
@property (nonatomic, readwrite) NSString *virtualAccountNumber;

@property (nonatomic, readwrite) NSURL *redirectURL;

@end

@implementation MidtransTransactionResult
Expand Down
8 changes: 7 additions & 1 deletion MidtransDemo/MidtransDemo/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ - (void)applicationDidEnterBackground:(UIApplication *)application {


- (void)applicationWillEnterForeground:(UIApplication *)application {
[[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_GOPAY_STATUS object:self];


}

Expand All @@ -113,5 +113,11 @@ - (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
NSLog(@"URL: %@", url);
[MIDUrlHandler handleUrl:url];

return YES;
}

@end
13 changes: 13 additions & 0 deletions MidtransDemo/MidtransDemo/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.11.1</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>None</string>
<key>CFBundleURLName</key>
<string>com.midtrans.demo</string>
<key>CFBundleURLSchemes</key>
<array>
<string>demo.midtrans</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>73</string>
<key>Fabric</key>
Expand Down
1 change: 1 addition & 0 deletions MidtransDemo/MidtransDemo/MDAddCardViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#import <ACFloatingTextfield_Objc/ACFloatingTextField.h>
#import <CHRTextFieldFormatter/CHRTextFieldFormatter.h>
#import <CHRTextFieldFormatter/CHRCardNumberMask.h>

@interface MDAddCardViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet ACFloatingTextField *cardNumberTextFIeld;
@property (nonatomic, strong) CHRTextFieldFormatter *cardNumberFormatter;
Expand Down
45 changes: 26 additions & 19 deletions MidtransDemo/MidtransDemo/MDOrderViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ - (void)viewWillAppear:(BOOL)animated {
- (void)viewDidLoad {
[super viewDidLoad];

self.totalAmount = @(10000.55);
self.totalAmount = @(1);
NSString *formattedPrice = [self formattedISOCurrencyNumber:self.totalAmount];
self.totalAmountLabel.text = self.pricePerItemLabel.text = formattedPrice;
[self.payButton setTitle:[NSString stringWithFormat:@"Pay %@", formattedPrice] forState:UIControlStateNormal];
Expand All @@ -60,24 +60,29 @@ - (void)viewDidLoad {
self.progressHUD = [JGProgressHUD progressHUDWithStyle:JGProgressHUDStyleDark];
self.progressHUD.textLabel.text = @"Loading...";

NSString *clientkey;
NSString *merchantServer;
CC_CONFIG.paymentType = [[MDOptionManager shared].ccTypeOption.value integerValue];
switch (CC_CONFIG.paymentType) {
case MTCreditCardPaymentTypeOneclick:
clientkey = @"VT-client-E4f1bsi1LpL1p5cF";
merchantServer = @"https://rakawm-snap.herokuapp.com";
CC_CONFIG.tokenStorageEnabled = NO;
break;
default:
clientkey = @"SB-Mid-client-txZHOj6jPP0_G8En";
merchantServer = @"https://dev-mobile-store.herokuapp.com/";
CC_CONFIG.tokenStorageEnabled = YES;
break;
}
[CONFIG setClientKey:clientkey
environment:MidtransServerEnvironmentSandbox
merchantServerURL:merchantServer];
// NSString *clientkey;
// NSString *merchantServer;
// CC_CONFIG.paymentType = [[MDOptionManager shared].ccTypeOption.value integerValue];
// switch (CC_CONFIG.paymentType) {
// case MTCreditCardPaymentTypeOneclick:
// clientkey = @"VT-client-E4f1bsi1LpL1p5cF";
// merchantServer = @"https://rakawm-snap.herokuapp.com";
// CC_CONFIG.tokenStorageEnabled = NO;
// break;
// default:
// clientkey = @"SB-Mid-client-txZHOj6jPP0_G8En";
// merchantServer = @"https://dev-mobile-store.herokuapp.com/";
// CC_CONFIG.tokenStorageEnabled = YES;
// break;
// }
// [CONFIG setClientKey:clientkey
// environment:MidtransServerEnvironmentSandbox
// merchantServerURL:merchantServer];

[CONFIG setClientKey:@"VT-client-yrHf-c8Sxr-ck8tx"
environment:MidtransServerEnvironmentProduction
merchantServerURL:@"https://midtrans-mobile-snap.herokuapp.com"];


//forced to use token storage
UICONFIG.hideStatusPage = NO;
Expand All @@ -104,6 +109,8 @@ - (void)viewDidLoad {
CONFIG.customPermataVANumber = [MDOptionManager shared].permataVAOption.value;
[[MidtransNetworkLogger shared] startLogging];

CONFIG.callbackSchemeURL = @"demo.midtrans://";

self.amountView.backgroundColor = [UIColor mdThemeColor];
__weak MDOrderViewController *wself = self;
defaults_observe_object(@"md_color", ^(NSNotification *note) {
Expand Down
2 changes: 1 addition & 1 deletion MidtransDemo/MidtransDemo/MDProductViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ - (void)viewDidLoad {

CONFIG.currency = [MidtransHelper currencyFromString:[MDOptionManager shared].currencyOption.value];
self.title = @"Product Detail";
NSNumber *price = @(10000.55);
NSNumber *price = @(1);
self.priceLabel.text = [self formattedISOCurrencyNumber:price];
self.navigationItem.backBarButtonItem =
[[UIBarButtonItem alloc] initWithTitle:@""
Expand Down
53 changes: 33 additions & 20 deletions MidtransKit/MidtransKit/classes/MidGopayViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ @interface MidGopayViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic) MidtransDirectHeader *headerView;
@end

@implementation MidGopayViewController
@implementation MidGopayViewController {
MidtransTransactionResult *payResult;
}

@dynamic view;
- (instancetype)initWithToken:(MidtransTransactionTokenResponse *)token
paymentMethodName:(MidtransPaymentListModel *)paymentMethod
Expand All @@ -42,7 +45,7 @@ - (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
NSLog(@"view did appear");
}
- (void)handleGopayStatus{
- (void)handleGopayStatus:(id)sender {
[[MidtransMerchantClient shared] performCheckStatusTransactionWcompletion:^(MidtransTransactionResult * _Nullable result, NSError * _Nullable error) {
if (!error) {
if (result.statusCode == 200) {
Expand All @@ -56,8 +59,9 @@ - (void)handleGopayStatus{
}
- (void)viewDidLoad {
[super viewDidLoad];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleGopayStatus)
selector:@selector(handleGopayStatus:)
name:NOTIFICATION_GOPAY_STATUS
object:nil];

Expand All @@ -81,15 +85,15 @@ - (void)viewDidLoad {
self.view.topWrapperView.hidden = YES;
self.view.topNoticeLabel.text = [VTClassHelper getTranslationFromAppBundleForString:@"Please complete your ‘GO-PAY‘ payment via ‘GO-JEK‘ app"];
} else {
NSURL *gojekUrl = [NSURL URLWithString:MIDTRANS_GOPAY_PREFIX];
if ([[UIApplication sharedApplication] canOpenURL:gojekUrl]) {
self.view.finishPaymentHeightConstraints.constant = 0.0f;
self.view.topWrapperView.hidden = NO;
self.view.transactionBottomDetailConstraints.constant = 0.0f;

} else {
self.view.topWrapperView.hidden = YES;
self.view.gopayTopViewHeightConstraints.constant = 0.0f;
NSURL *gojekUrl = [NSURL URLWithString:MIDTRANS_GOPAY_PREFIX];
if ([[UIApplication sharedApplication] canOpenURL:gojekUrl]) {
self.view.gopayTopViewHeightConstraints.constant = 0.0f;
self.view.topWrapperView.hidden = YES;
} else {
self.view.topWrapperView.hidden = NO;
self.view.transactionBottomDetailConstraints.constant = 0.0f;
self.view.finishPaymentHeightConstraints.constant = 0.0f;
}
}

Expand Down Expand Up @@ -190,7 +194,19 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa
- (IBAction)installGOJEKappButtonDidTapped:(id)sender {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:GOJEK_APP_ITUNES_LINK]];
}
- (void)openGojekAppWithResult:(MidtransTransactionResult *)result {
NSURL *gojekConstructURL = [NSURL URLWithString:[result.additionalData objectForKey:@"deeplink_url"]];
if ([[UIApplication sharedApplication] canOpenURL:gojekConstructURL]) {
[[UIApplication sharedApplication] openURL:gojekConstructURL];
}
}

- (IBAction)finishPaymentButtonDidTapped:(id)sender {
if (payResult) {
[self openGojekAppWithResult:payResult];
return;
}

[self showLoadingWithText:[VTClassHelper getTranslationFromAppBundleForString:@"Processing your transaction"]];
id<MidtransPaymentDetails>paymentDetails;
paymentDetails = [[MidtransPaymentGOPAY alloc] init];
Expand All @@ -210,17 +226,14 @@ - (IBAction)finishPaymentButtonDidTapped:(id)sender {
} else {
NSDictionary *userInfo = @{TRANSACTION_RESULT_KEY:result};
[[NSNotificationCenter defaultCenter] postNotificationName:TRANSACTION_PENDING object:nil userInfo:userInfo];
NSURL *gojekConstructURL = [NSURL URLWithString:[result.additionalData objectForKey:@"deeplink_url"]];
if ([[UIApplication sharedApplication] canOpenURL:gojekConstructURL]) {
[[UIApplication sharedApplication] openURL:gojekConstructURL];
}

payResult = result;

[self openGojekAppWithResult:result];

if (UICONFIG.hideStatusPage) {
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
} else {
[self handleGopayStatus];
}

}

}
Expand Down

0 comments on commit 0b93e12

Please sign in to comment.