Skip to content

Commit 0b0a3c9

Browse files
committed
Merge branch 'development' of https://github.com/veritrans/Veritrans-ios-sdk into development
2 parents 0aa3dcb + ea9ed9c commit 0b0a3c9

33 files changed

+4716
-4517
lines changed

MidtransCoreKit/MidtransCoreKit/MidtransConfig.h

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#import <Foundation/Foundation.h>
1010
#import <UIKit/UIKit.h>
1111
#import "MidtransEnvironment.h"
12+
#import "MidtransHelper.h"
1213

1314
#define CONFIG ((MidtransConfig *)[MidtransConfig shared])
1415

@@ -41,6 +42,8 @@
4142
@property (nonatomic) NSArray *customPaymentChannels;
4243
@property (nonatomic) NSDictionary *customFreeText;
4344

45+
@property (nonatomic) MidtransCurrency currency;
46+
4447
/**
4548
Container for data that will be sent to the Merchant Server. The common use-case for this data is to identify client to the Merchant Server. If this variable is set to non-nil, then every request to the Merchant Server will contain this data in its HTTP request header.
4649

MidtransCoreKit/MidtransCoreKit/MidtransConstant.h

-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ static NSString *const MIDTRANS_UIKIT_TRACKING_SELECT_PAYMENT_TYPE = @"Payment
180180
//static NSString *const MIDTRANS_CORE_CREDIT_CARD_SCANNER_OUTPUT_EXPIRED_YEAR = @"credit_card_result_scan_expired_year";
181181
//static NSString *const MIDTRANS_CORE_CREDIT_CARD_SCANNER_OUTPUT_EXPIRED_MONTH = @"credit_card_result_scan_expired_month";
182182

183-
184183
static NSInteger const MIDTRANS_ERROR_CODE_3DSECURE = -30;
185184
static NSInteger const MIDTRANS_ERROR_CODE_CANCELED_WEBPAYMENT = -31;
186185

MidtransCoreKit/MidtransCoreKit/MidtransHelper.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,18 @@
99
#import <Foundation/Foundation.h>
1010
#import <UIKit/UIKit.h>
1111

12+
typedef NS_ENUM(NSInteger, MidtransCurrency) {
13+
MidtransCurrencyIDR,
14+
MidtransCurrencySGD
15+
};
16+
1217
extern NSString *const MidtransMaskedCardsUpdated;
1318

1419
@interface MidtransHelper : NSObject
1520
+ (id)nullifyIfNil:(id)object;
1621
+ (NSBundle*)coreBundle;
22+
+ (NSString *)stringFromCurrency:(MidtransCurrency)currency;
23+
+ (MidtransCurrency)currencyFromString:(NSString *)string;
1724
@end
1825

1926
@interface NSString (random)
@@ -28,11 +35,12 @@ extern NSString *const MidtransMaskedCardsUpdated;
2835
- (id)objectThenDeleteForKey:(NSString *)key;
2936
@end
3037

31-
3238
@interface NSObject (utilities)
3339
+ (NSNumberFormatter *)indonesianCurrencyFormatter;
3440
+ (NSDateFormatter *)dateFormatterWithIdentifier:(NSString *)identifier;
41+
+ (NSNumberFormatter *)multiCurrencyFormatter:(MidtransCurrency)currency;
3542
@end
43+
3644
//
3745
//@interface NSDictionary (SafeObject)
3846
//- (id)safeObjectForKey:(id)key;

MidtransCoreKit/MidtransCoreKit/MidtransHelper.m

+46-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
#import "MidtransHelper.h"
1010

1111
NSString *const MIdtransMaskedCardsUpdated = @"vt_masked_cards_updated";
12-
12+
NSString *const MIDTRANS_CORE_CURRENCY_IDR = @"IDR";
13+
NSString *const MIDTRANS_CORE_CURRENCY_SGD = @"SGD";
1314

1415
@implementation MidtransHelper
1516

@@ -36,6 +37,32 @@ + (NSBundle*)coreBundle {
3637
});
3738
return kitBundle;
3839
}
40+
+ (NSString *)stringFromCurrency:(MidtransCurrency)currency {
41+
switch (currency) {
42+
case MidtransCurrencyIDR:
43+
return MIDTRANS_CORE_CURRENCY_IDR;
44+
break;
45+
case MidtransCurrencySGD:
46+
return MIDTRANS_CORE_CURRENCY_SGD;
47+
break;
48+
49+
default:
50+
return MIDTRANS_CORE_CURRENCY_IDR;
51+
break;
52+
}
53+
}
54+
+ (MidtransCurrency)currencyFromString:(NSString *)string {
55+
NSString *uppercaseString = string.uppercaseString;
56+
if ([uppercaseString.uppercaseString isEqualToString:MIDTRANS_CORE_CURRENCY_SGD]) {
57+
return MidtransCurrencySGD;
58+
}
59+
else if ([uppercaseString isEqualToString:MIDTRANS_CORE_CURRENCY_IDR]) {
60+
return MidtransCurrencyIDR;
61+
}
62+
else {
63+
return MidtransCurrencyIDR;
64+
}
65+
}
3966

4067
@end
4168

@@ -115,9 +142,6 @@ + (NSNumberFormatter *)indonesianCurrencyFormatter {
115142

116143
if (currentFormatter == nil) {
117144
currentFormatter = [NSNumberFormatter new];
118-
currentFormatter.numberStyle = NSNumberFormatterDecimalStyle;
119-
currentFormatter.groupingSeparator = @",";
120-
currentFormatter.decimalSeparator = @".";
121145
[dictionary setObject:currentFormatter forKey:identifier];
122146
}
123147

@@ -133,5 +157,23 @@ + (NSDateFormatter *)dateFormatterWithIdentifier:(NSString *)identifier {
133157
}
134158
return currentFormatter;
135159
}
160+
161+
+ (NSNumberFormatter *)multiCurrencyFormatter:(MidtransCurrency)currency {
162+
NSNumberFormatter *currencyFormatter = [MidtransHelper indonesianCurrencyFormatter];
163+
currencyFormatter.numberStyle = NSNumberFormatterCurrencyISOCodeStyle;
164+
currencyFormatter.paddingPosition = NSNumberFormatterPadAfterPrefix;
165+
if (currency == MidtransCurrencySGD) {
166+
currencyFormatter.locale = [NSLocale localeWithLocaleIdentifier:@"en_SG"];
167+
currencyFormatter.minimumFractionDigits = 2;
168+
currencyFormatter.roundingMode = NSNumberFormatterRoundHalfEven;
169+
}
170+
else {
171+
// by default set to indonesian
172+
currencyFormatter.locale = [NSLocale localeWithLocaleIdentifier:@"id_ID"];
173+
currencyFormatter.minimumFractionDigits = 0;
174+
currencyFormatter.roundingMode = NSNumberFormatterRoundDown;
175+
}
176+
return currencyFormatter;
177+
}
136178
@end
137179

MidtransCoreKit/MidtransCoreKit/MidtransItemDetail.m

+13
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#import "MidtransItemDetail.h"
1010
#import "MidtransHelper.h"
11+
#import "MidtransConfig.h"
1112

1213
@implementation NSArray (VTITemDetail)
1314

@@ -44,6 +45,18 @@ - (instancetype)initWithItemID:(NSString *)itemID
4445
}
4546

4647
- (NSDictionary *)dictionaryValue {
48+
switch ([CONFIG currency]) {
49+
case MidtransCurrencyIDR:
50+
_price = [NSNumber numberWithInteger:_price.integerValue];
51+
break;
52+
case MidtransCurrencySGD:
53+
_price = [NSNumber numberWithDouble:_price.doubleValue];
54+
break;
55+
56+
default:
57+
_price = [NSNumber numberWithInteger:_price.integerValue];
58+
break;
59+
}
4760
return @{@"id":[MidtransHelper nullifyIfNil:_itemId],
4861
@"price":[MidtransHelper nullifyIfNil:_price],
4962
@"quantity":[MidtransHelper nullifyIfNil:_quantity],

MidtransCoreKit/MidtransCoreKit/MidtransMerchantClient.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ - (void)requestTransacationWithCurrentToken:(NSString *_Nonnull)token
249249
countryCode:paymentRequestV2.customerDetails.billingAddress.countryCode];
250250

251251

252-
NSNumber *amount = [NSNumber numberWithInteger:[paymentRequestV2.transactionDetails.grossAmount integerValue]];
252+
NSNumber *amount = [NSNumber numberWithDouble:[paymentRequestV2.transactionDetails.grossAmount doubleValue]];
253253
MidtransTransactionDetails *reConstructTransactionDetail = [[MidtransTransactionDetails alloc] initWithOrderID:paymentRequestV2.transactionDetails.orderId
254254
andGrossAmount:amount];
255255

MidtransCoreKit/MidtransCoreKit/MidtransPaymentRequestV2TransactionDetails.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
//
77

88
#import <Foundation/Foundation.h>
9-
10-
9+
#import "MidtransHelper.h"
1110

1211
@interface MidtransPaymentRequestV2TransactionDetails : NSObject <NSCoding, NSCopying>
1312

MidtransCoreKit/MidtransCoreKit/MidtransPaymentRequestV2TransactionDetails.m

+4-6
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77

88
#import "MidtransPaymentRequestV2TransactionDetails.h"
99

10-
1110
NSString *const kMidtransPaymentRequestV2TransactionDetailsOrderId = @"order_id";
1211
NSString *const kMidtransPaymentRequestV2TransactionDetailsGrossAmount = @"gross_amount";
1312

14-
1513
@interface MidtransPaymentRequestV2TransactionDetails ()
1614

1715
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
@@ -36,9 +34,9 @@ - (instancetype)initWithDictionary:(NSDictionary *)dict
3634
// This check serves to make sure that a non-NSDictionary object
3735
// passed into the model class doesn't break the parsing.
3836
if (self && [dict isKindOfClass:[NSDictionary class]]) {
39-
self.orderId = [self objectOrNilForKey:kMidtransPaymentRequestV2TransactionDetailsOrderId fromDictionary:dict];
40-
self.grossAmount = [self objectOrNilForKey:kMidtransPaymentRequestV2TransactionDetailsGrossAmount fromDictionary:dict];
41-
37+
self.orderId = [self objectOrNilForKey:kMidtransPaymentRequestV2TransactionDetailsOrderId fromDictionary:dict];
38+
self.grossAmount = [self objectOrNilForKey:kMidtransPaymentRequestV2TransactionDetailsGrossAmount fromDictionary:dict];
39+
4240
}
4341

4442
return self;
@@ -50,7 +48,7 @@ - (NSDictionary *)dictionaryRepresentation
5048
NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
5149
[mutableDict setValue:self.orderId forKey:kMidtransPaymentRequestV2TransactionDetailsOrderId];
5250
[mutableDict setValue:self.grossAmount forKey:kMidtransPaymentRequestV2TransactionDetailsGrossAmount];
53-
51+
5452
return [NSDictionary dictionaryWithDictionary:mutableDict];
5553
}
5654

MidtransCoreKit/MidtransCoreKit/MidtransTokenizeRequest.m

+16-1
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,23 @@ - (instancetype)initWithTwoClickToken:(NSString *)token
8181

8282
- (NSDictionary *)dictionaryValue {
8383
NSMutableDictionary *result = [NSMutableDictionary new];
84+
switch ([CONFIG currency]) {
85+
case MidtransCurrencyIDR:
86+
self.grossAmount = [NSNumber numberWithInteger:self.grossAmount.integerValue];
87+
break;
88+
case MidtransCurrencySGD:
89+
self.grossAmount = [NSNumber numberWithDouble:self.grossAmount.doubleValue];
90+
break;
91+
default:
92+
self.grossAmount = [NSNumber numberWithInteger:self.grossAmount.integerValue];
93+
break;
94+
}
8495
switch (self.featureType) {
8596
case MTCreditCardPaymentTypeTwoclick: {
8697
[result setDictionary:@{@"client_key":[CONFIG clientKey],
8798
@"secure":self.secure ? @"true":@"false",
8899
@"gross_amount":[MidtransHelper nullifyIfNil:self.grossAmount],
100+
@"currency":[MidtransHelper stringFromCurrency:[CONFIG currency]],
89101
@"two_click":@"true",
90102
@"token_id":[MidtransHelper nullifyIfNil:self.token]}];
91103
if (self.cvv) {
@@ -97,7 +109,9 @@ - (NSDictionary *)dictionaryValue {
97109
@"card_number":self.creditCard.number,
98110
@"card_type":[MidtransCreditCardHelper nameFromString: self.creditCard.number],
99111
@"secure":self.secure ? @"true":@"false",
100-
@"gross_amount":[MidtransHelper nullifyIfNil:self.grossAmount]}];
112+
@"gross_amount":[MidtransHelper nullifyIfNil:self.grossAmount],
113+
@"currency":[MidtransHelper stringFromCurrency:[CONFIG currency]]
114+
}];
101115
if (self.creditCard.expiryYear) {
102116
[result setObject:self.creditCard.expiryYear forKey:@"card_exp_year"];
103117
}
@@ -114,6 +128,7 @@ - (NSDictionary *)dictionaryValue {
114128
@"card_type":[MidtransCreditCardHelper nameFromString: self.creditCard.number],
115129
@"secure":self.secure ? @"true":@"false",
116130
@"gross_amount":[MidtransHelper nullifyIfNil:self.grossAmount],
131+
@"currency":[MidtransHelper stringFromCurrency:[CONFIG currency]],
117132
@"installment":self.installment? @"true":@"false",
118133
@"installment_term":[MidtransHelper nullifyIfNil:self.installmentTerm],
119134
@"two_click":self.twoClick? @"true":@"false"}];

MidtransCoreKit/MidtransCoreKit/MidtransTransactionDetails.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//
88

99
#import <Foundation/Foundation.h>
10-
10+
#import "MidtransHelper.h"
1111
/**
1212
An object that contains various details about a transaction.
1313
The content of this object is adapted from
@@ -17,7 +17,9 @@
1717

1818
@property (nonatomic, readonly) NSString *orderId;
1919
@property (nonatomic, readonly) NSNumber *grossAmount;
20+
@property (nonatomic, readonly) MidtransCurrency currency;
2021
- (instancetype)initWithOrderID:(NSString *)orderID andGrossAmount:(NSNumber *)grossAmount;
22+
- (instancetype)initWithOrderID:(NSString *)orderID andGrossAmount:(NSNumber *)grossAmount andCurrency:(MidtransCurrency)currency;
2123
- (NSDictionary *)dictionaryValue;
2224

2325
@end

MidtransCoreKit/MidtransCoreKit/MidtransTransactionDetails.m

+32-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88

99
#import "MidtransTransactionDetails.h"
1010
#import "MidtransHelper.h"
11+
#import "MidtransConfig.h"
1112

1213
@interface MidtransTransactionDetails()
1314

1415
@property (nonatomic, readwrite) NSString *orderId;
1516
@property (nonatomic, readwrite) NSNumber *grossAmount;
17+
@property (nonatomic, readwrite) MidtransCurrency currency;
1618

1719
@end
1820

@@ -26,12 +28,40 @@ - (instancetype)initWithOrderID:(NSString *)orderID andGrossAmount:(NSNumber *)g
2628
return self;
2729
}
2830

31+
-(instancetype)initWithOrderID:(NSString *)orderID andGrossAmount:(NSNumber *)grossAmount andCurrency:(MidtransCurrency)currency {
32+
if (self = [super init]) {
33+
self.orderId = orderID;
34+
self.grossAmount = grossAmount;
35+
self.currency = currency;
36+
}
37+
return self;
38+
}
39+
2940
- (NSDictionary *)dictionaryValue {
3041
// Format MUST BE compatible with
3142
// http://docs.veritrans.co.id/en/api/methods.html#transaction_details_attr
32-
NSInteger grossAmount = [self.grossAmount integerValue];
43+
NSNumber *amountNumber = nil;
44+
switch ([CONFIG currency]) {
45+
case MidtransCurrencyIDR:{
46+
NSInteger grossAmount = [self.grossAmount integerValue];
47+
amountNumber = [NSNumber numberWithInteger:grossAmount];
48+
}
49+
break;
50+
case MidtransCurrencySGD:{
51+
double grossAmount = [self.grossAmount doubleValue];
52+
amountNumber = [NSNumber numberWithDouble:grossAmount];
53+
}
54+
break;
55+
default:{
56+
NSInteger grossAmount = [self.grossAmount integerValue];
57+
amountNumber = [NSNumber numberWithInteger:grossAmount];
58+
}
59+
break;
60+
}
3361
return @{@"order_id": self.orderId,
34-
@"gross_amount": [NSNumber numberWithInteger:grossAmount]};
62+
@"gross_amount": amountNumber,
63+
@"currency": [MidtransHelper stringFromCurrency:self.currency]
64+
};
3565
}
3666

3767
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"filename" : "dc_field.png",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"filename" : "[email protected]",
11+
"scale" : "2x"
12+
},
13+
{
14+
"idiom" : "universal",
15+
"filename" : "[email protected]",
16+
"scale" : "3x"
17+
}
18+
],
19+
"info" : {
20+
"version" : 1,
21+
"author" : "xcode"
22+
}
23+
}
Loading
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"filename" : "dc_multicurrency.png",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"filename" : "[email protected]",
11+
"scale" : "2x"
12+
},
13+
{
14+
"idiom" : "universal",
15+
"filename" : "[email protected]",
16+
"scale" : "3x"
17+
}
18+
],
19+
"info" : {
20+
"version" : 1,
21+
"author" : "xcode"
22+
}
23+
}
Loading
Loading
Loading

MidtransDemo/MidtransDemo/MDOptionManager.h

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
@property (nonatomic) MDOption *secure3DOption;
1919
@property (nonatomic) MDOption *issuingBankOption;
2020
@property (nonatomic) MDOption *expireTimeOption;
21+
@property (nonatomic) MDOption *currencyOption;
2122
@property (nonatomic) MDOption *saveCardOption;
2223
@property (nonatomic) MDOption *promoOption;
2324
@property (nonatomic) MDOption *preauthOption;

0 commit comments

Comments
 (0)