9
9
#import " MidtransHelper.h"
10
10
11
11
NSString *const MIdtransMaskedCardsUpdated = @" vt_masked_cards_updated" ;
12
-
12
+ NSString *const MIDTRANS_CORE_CURRENCY_IDR = @" IDR" ;
13
+ NSString *const MIDTRANS_CORE_CURRENCY_SGD = @" SGD" ;
13
14
14
15
@implementation MidtransHelper
15
16
@@ -36,6 +37,32 @@ + (NSBundle*)coreBundle {
36
37
});
37
38
return kitBundle;
38
39
}
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
+ }
39
66
40
67
@end
41
68
@@ -115,9 +142,6 @@ + (NSNumberFormatter *)indonesianCurrencyFormatter {
115
142
116
143
if (currentFormatter == nil ) {
117
144
currentFormatter = [NSNumberFormatter new ];
118
- currentFormatter.numberStyle = NSNumberFormatterDecimalStyle;
119
- currentFormatter.groupingSeparator = @" ," ;
120
- currentFormatter.decimalSeparator = @" ." ;
121
145
[dictionary setObject: currentFormatter forKey: identifier];
122
146
}
123
147
@@ -133,5 +157,23 @@ + (NSDateFormatter *)dateFormatterWithIdentifier:(NSString *)identifier {
133
157
}
134
158
return currentFormatter;
135
159
}
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
+ }
136
178
@end
137
179
0 commit comments