Skip to content

Commit

Permalink
Development (#364)
Browse files Browse the repository at this point in the history
* update

* update

* update

* update fix object data on saved card

* update

* add 5 minute expiry for cc token (#357)

* update reduce gross amount

* update promo velocity error

* decreased gross amount price to 2k (#359)

* update

* Feature/mob 1632 add custom field (#361)

* one custom field

* add multiple input type option

* add new kind for mdalertviewcontroller

* link mdoptionmanager custom field value with the ones for demo merchant client request

* change total amount to 10k then display bank name and logo on saved card view (#360)

* fix nil value checking for custom field (#362)

* update order_id

* update order-id

* fix setting midtrans transaction expire time according to md option (#363)

* update

* update constant and bump version to 1.12.1
  • Loading branch information
vanbungkring authored Jul 3, 2018
1 parent fa87e4d commit c9a76dd
Show file tree
Hide file tree
Showing 52 changed files with 1,248 additions and 769 deletions.
2 changes: 1 addition & 1 deletion MidtransCoreKit/MidtransCoreKit/MidtransConstant.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* error domain
*/

static NSString * const MIDTRANS_SDK_CURRENT_VERSION = @"1.12.0";
static NSString * const MIDTRANS_SDK_CURRENT_VERSION = @"1.12.1";
static NSString * const MIDTRANS_CUSTOMFIELD_1 = @"custom_field1";
static NSString * const MIDTRANS_CUSTOMFIELD_2 = @"custom_field2";
static NSString * const MIDTRANS_CUSTOMFIELD_3 = @"custom_field3";
Expand Down
15 changes: 14 additions & 1 deletion MidtransCoreKit/MidtransCoreKit/MidtransMaskedCreditCard.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,18 @@ static NSString * _Nonnull const kMTMaskedCreditCardExpiresAt = @"expires_at";
- (instancetype _Nonnull)initWithDictionary:(NSDictionary *_Nonnull)dictionary;

- (instancetype _Nonnull)initWithData:(NSDictionary *_Nonnull)data;

- (instancetype _Nonnull)initWithSavedTokenId:(NSString * _Nonnull)savedTokenId
maskedNumber:(NSString * _Nonnull)maskedNumber
tokenType:(NSString * _Nullable)tokenType
expiresAt:(NSString *_Nullable)expiresAt;

/*
self.savedTokenId = dictionary[kMTMaskedCreditCardIdentifier];
self.maskedNumber = dictionary[kMTMaskedCreditCardCardhash];
self.type = dictionary[kMTMaskedCreditCardType]?dictionary[kMTMaskedCreditCardType]:@"";
self.tokenType = dictionary[kMTMaskedCreditCardTokenType]?dictionary[kMTMaskedCreditCardTokenType]:@"";
self.expiresAt = dictionary[kMTMaskedCreditCardExpiresAt]?dictionary[kMTMaskedCreditCardExpiresAt]:@"";
self.statusCode = @"";
self.transactionId = @"";
*/
@end
22 changes: 18 additions & 4 deletions MidtransCoreKit/MidtransCoreKit/MidtransMaskedCreditCard.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,29 @@ - (instancetype _Nonnull)initWithDictionary:(NSDictionary *_Nonnull)dictionary {
if (self = [super init]) {
self.savedTokenId = dictionary[kMTMaskedCreditCardIdentifier];
self.maskedNumber = dictionary[kMTMaskedCreditCardCardhash];
self.type = dictionary[kMTMaskedCreditCardType];
self.tokenType = dictionary[kMTMaskedCreditCardTokenType];
self.expiresAt = dictionary[kMTMaskedCreditCardExpiresAt];
self.type = dictionary[kMTMaskedCreditCardType]?dictionary[kMTMaskedCreditCardType]:@"";
self.tokenType = dictionary[kMTMaskedCreditCardTokenType]?dictionary[kMTMaskedCreditCardTokenType]:@"";
self.expiresAt = dictionary[kMTMaskedCreditCardExpiresAt]?dictionary[kMTMaskedCreditCardExpiresAt]:@"";
self.statusCode = @"";
self.transactionId = @"";
}
return self;
}

- (instancetype )initWithSavedTokenId:(NSString * _Nonnull)savedTokenId
maskedNumber:(NSString * _Nonnull)maskedNumber
tokenType:(NSString * _Nullable)tokenType
expiresAt:(NSString *_Nullable)expiresAt {

if (self = [super init]) {
self.maskedNumber = maskedNumber;
self.savedTokenId = savedTokenId;
self.expiresAt = expiresAt;
self.statusCode = @"";
self.transactionId = @"";
self.type = [MidtransCreditCardHelper nameFromString:self.maskedNumber];
}
return self;
}
- (NSDictionary *)dictionaryValue {
return @{kMTMaskedCreditCardIdentifier:self.savedTokenId,
kMTMaskedCreditCardCardhash:self.maskedNumber,
Expand Down
2 changes: 1 addition & 1 deletion MidtransCoreKit/MidtransCoreKit/MidtransMerchantClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
* updated method, snapping
*/
- (void)requestTransacationWithCurrentToken:(NSString *_Nonnull)token
completion:(void (^_Nullable)(MidtransTransactionTokenResponse *_Nullable token, NSError *_Nullable error))completion;
completion:(void (^_Nullable)(MidtransTransactionTokenResponse *_Nullable regenerateToken, NSError *_Nullable error))completion;

- (void)requestTransactionTokenWithTransactionDetails:(nonnull MidtransTransactionDetails *)transactionDetails
itemDetails:(nullable NSArray<MidtransItemDetail*> *)itemDetails
Expand Down
55 changes: 53 additions & 2 deletions MidtransCoreKit/MidtransCoreKit/MidtransMerchantClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ - (void)fetchMaskedCardsCustomer:(MidtransCustomerDetails *)customer completion:
if (!error) {
for (NSDictionary *dictionary in requestResponse) {
MidtransMaskedCreditCard *card = [[MidtransMaskedCreditCard alloc] initWithDictionary:dictionary];
NSLog(@"data--> %@",card);
[result addObject:card];
}
}
Expand Down Expand Up @@ -228,9 +229,59 @@ - (void)requestCustomerPointWithToken:(NSString * _Nonnull )token

}
- (void)requestTransacationWithCurrentToken:(NSString *_Nonnull)token
completion:(void (^_Nullable)(MidtransTransactionTokenResponse *_Nullable token, NSError *_Nullable error))completion {
completion:(void (^_Nullable)(MidtransTransactionTokenResponse *_Nullable regenerateToken, NSError *_Nullable error))completion {

//NSString *URL = [NSString stringWithFormat:@"%@/%@", [CONFIG merchantURL], MIDTRANS_CORE_SNAP_MERCHANT_SERVER_CHARGE];
NSString *URL = [NSString stringWithFormat:ENDPOINT_TRANSACTION_DETAIL, [PRIVATECONFIG snapURL], token];
[[MidtransNetworking shared] getFromURL:URL parameters:nil callback:^(id response, NSError *error) {
if (!error) {
MidtransPaymentRequestV2Response *paymentRequestV2 = [[MidtransPaymentRequestV2Response alloc] initWithDictionary:(NSDictionary *)response];

if (completion) {
NSLog(@"response-->%@",response);
MidtransTransactionTokenResponse *token2;

MidtransAddress *billAddressConstruct = [MidtransAddress addressWithFirstName:paymentRequestV2.customerDetails.billingAddress.firstName
lastName:paymentRequestV2.customerDetails.billingAddress.firstName
phone:paymentRequestV2.customerDetails.billingAddress.phone
address:paymentRequestV2.customerDetails.billingAddress.firstName
city:paymentRequestV2.customerDetails.billingAddress.city
postalCode:paymentRequestV2.customerDetails.billingAddress.postalCode
countryCode:paymentRequestV2.customerDetails.billingAddress.countryCode];


NSNumber *amount = [NSNumber numberWithInteger:[paymentRequestV2.transactionDetails.grossAmount integerValue]];
MidtransTransactionDetails *reConstructTransactionDetail = [[MidtransTransactionDetails alloc] initWithOrderID:paymentRequestV2.transactionDetails.orderId
andGrossAmount:amount];



MidtransCustomerDetails *customerDetailsMock = [[MidtransCustomerDetails alloc] initWithFirstName:paymentRequestV2.customerDetails.firstName
lastName:paymentRequestV2.customerDetails.firstName
email:paymentRequestV2.customerDetails.email
phone:paymentRequestV2.customerDetails.phone
shippingAddress:billAddressConstruct
billingAddress:billAddressConstruct];
NSMutableArray *itemDetails = [NSMutableArray new];

for (MidtransPaymentRequestV2ItemDetails *detail in paymentRequestV2.itemDetails) {
MidtransItemDetail *regenerate = [[MidtransItemDetail alloc]initWithItemID:detail.itemDetailsIdentifier name:detail.name price:[NSNumber numberWithDouble:detail.price] quantity:[NSNumber numberWithDouble:detail.quantity]];
[itemDetails addObject:regenerate];
}
token2 = [MidtransTransactionTokenResponse modelObjectWithDictionary:@{@"token":token}
transactionDetails:reConstructTransactionDetail
customerDetails:customerDetailsMock
itemDetails:itemDetails];

completion(token2,NULL);
}

}
else {
if (completion) {
completion(NULL,error);
}
}
}];
}
- (void)requestTransactionTokenWithTransactionDetails:(nonnull MidtransTransactionDetails *)transactionDetails
itemDetails:(nullable NSArray<MidtransItemDetail*> *)itemDetails
Expand Down
3 changes: 2 additions & 1 deletion MidtransCoreKit/MidtransCoreKit/MidtransTransactionResult.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ @implementation MidtransTransactionResult
- (instancetype)initWithTransactionResponse:(NSDictionary *)response {
self = [super init];
if (self) {

NSMutableDictionary *mResponse = [NSMutableDictionary dictionaryWithDictionary:response];
self.statusCode = [[mResponse objectThenDeleteForKey:@"status_code"] integerValue];
self.statusMessage = [mResponse objectThenDeleteForKey:@"status_message"];
self.transactionId = [mResponse objectThenDeleteForKey:@"transaction_id"];
self.transactionStatus = [mResponse objectThenDeleteForKey:@"transaction_status"];
self.orderId = [mResponse objectThenDeleteForKey:@"order_id"];
self.paymentType = [mResponse objectThenDeleteForKey:@"payment_type"];

NSLog(@"daata-->%@",mResponse);
id rawGrossAmount = [mResponse objectThenDeleteForKey:@"gross_amount"];
if (rawGrossAmount) {
self.grossAmount = @([rawGrossAmount doubleValue]);
Expand Down
14 changes: 12 additions & 2 deletions MidtransCoreKit/MidtransCoreKit/Promo/MidtransPromoPromos.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,25 @@ + (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
return [[self alloc] initWithDictionary:dict];
}

- (NSString *)removeAllWhitespace:(NSString *)string{
return [string stringByReplacingOccurrencesOfString:@"\\s" withString:@""
options:NSRegularExpressionSearch
range:NSMakeRange(0, [string length])]
;
}
- (instancetype)initWithDictionary:(NSDictionary *)dict
{
self = [super init];

// This check serves to make sure that a non-NSDictionary object
// passed into the model class doesn't break the parsing.
if(self && [dict isKindOfClass:[NSDictionary class]]) {
self.bins = [self objectOrNilForKey:kMidtransPromoPromosBins fromDictionary:dict];
NSMutableArray *array = [NSMutableArray new];
for (int i =0; i<[[self objectOrNilForKey:kMidtransPromoPromosBins fromDictionary:dict] count]; i++) {
NSString *currValue =[[[self objectOrNilForKey:kMidtransPromoPromosBins fromDictionary:dict] objectAtIndex:i] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
[array addObject:currValue];
}
self.bins = array;
self.discountType = [self objectOrNilForKey:kMidtransPromoPromosDiscountType fromDictionary:dict];
self.promosIdentifier = [[self objectOrNilForKey:kMidtransPromoPromosId fromDictionary:dict] doubleValue];
self.discountedGrossAmount = [[self objectOrNilForKey:kMidtransPromoPromosDiscountedGrossAmount fromDictionary:dict] doubleValue];
Expand Down
4 changes: 2 additions & 2 deletions MidtransDemo/MidtransDemo/MDAlertInputCell.xib
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12120" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14113" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand Down
9 changes: 8 additions & 1 deletion MidtransDemo/MidtransDemo/MDAlertViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
typedef NS_ENUM(NSUInteger, MDAlertOptionType) {
MDAlertOptionTypeInput = 1,
MDAlertOptionTypeRadio = 2,
MDAlertOptionTypeCheck = 3
MDAlertOptionTypeCheck = 3,
MDAlertOptionTypeMultipleInput = 4
};

@class MDAlertViewController;
Expand All @@ -22,6 +23,7 @@ typedef NS_ENUM(NSUInteger, MDAlertOptionType) {
- (void)alertViewController:(MDAlertViewController *)viewController didApplyInput:(NSString *)inputText;
- (void)alertViewController:(MDAlertViewController *)viewController didApplyRadio:(id)value;
- (void)alertViewController:(MDAlertViewController *)viewController didApplyCheck:(NSArray *)values;
- (void)alertViewController:(MDAlertViewController *)viewController didApplyMultipleInput:(NSArray *)multipleInputText;

@end

Expand All @@ -33,6 +35,7 @@ typedef NS_ENUM(NSUInteger, MDAlertOptionType) {
@property (nonatomic) NSString *inputPlaceholder;
@property (nonatomic) NSString *inputText;
@property (nonatomic) NSString *predefinedInputText;
@property (nonatomic) NSArray *multipleInputTexts;
@property (nonatomic) id predefinedRadio;
@property (nonatomic) NSArray *predefinedCheckLists;

Expand All @@ -41,6 +44,10 @@ typedef NS_ENUM(NSUInteger, MDAlertOptionType) {
+ (MDAlertViewController *)alertWithTitle:(NSString *)title
predefinedText:(NSString *)predefinedText
inputPlaceholder:(NSString *)placeholder;
+ (MDAlertViewController *)alertWithTitle:(NSString *)title
multipleTextfields:(NSArray <NSString*>*)multipleTextfields
inputPlaceholder:(NSString *)placeholder;

- (void)show;
- (void)dismiss;

Expand Down
58 changes: 53 additions & 5 deletions MidtransDemo/MidtransDemo/MDAlertViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#import "MDAlertCheckCell.h"
#import "MDUtils.h"

#define MDAlertInputCellHeight 50.f

@interface MDAlertViewController () <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic) IBOutlet NSLayoutConstraint *tableHeightConstraint;
Expand All @@ -24,6 +26,7 @@ @interface MDAlertViewController () <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic) NSString *alertTitle;
@property (nonatomic) NSArray <NSString*>*radioButtons;
@property (nonatomic) NSArray <NSString*>*checkLists;
@property (nonatomic) NSArray <NSString*>*textfields;

@property (nonatomic) MDAlertInputCell *inputCell;
@end
Expand Down Expand Up @@ -60,6 +63,18 @@ + (MDAlertViewController *)alertWithTitle:(NSString *)title
return vc;
}

+ (MDAlertViewController *)alertWithTitle:(NSString *)title
multipleTextfields:(NSArray <NSString*>*)multipleTextfields
inputPlaceholder:(NSString *)placeholder {
MDAlertViewController *vc = [[MDAlertViewController alloc] initWithNibName:@"MDAlertViewController"
bundle:nil];
vc.alertTitle = title;
vc.multipleInputTexts = multipleTextfields;
vc.inputPlaceholder = placeholder;
vc.type = MDAlertOptionTypeMultipleInput;
return vc;
}

- (void)viewDidLoad {
[super viewDidLoad];

Expand Down Expand Up @@ -94,6 +109,12 @@ - (void)viewDidLoad {
}
}
}
else if (self.type == MDAlertOptionTypeMultipleInput) {
if (self.multipleInputTexts == nil) {
self.multipleInputTexts = @[@"", @"", @""];
}
self.applyButton.enabled = NO;
}

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
Expand Down Expand Up @@ -137,13 +158,16 @@ - (void)updateTableViewHeight {

switch (self.type) {
case MDAlertOptionTypeInput:
height = 50;
height = MDAlertInputCellHeight;
break;
case MDAlertOptionTypeRadio:
for (int i=0; i < self.radioButtons.count; i++) {
height += 44;
}
break;
case MDAlertOptionTypeMultipleInput:
height += 3 * MDAlertInputCellHeight;
break;
default:
for (int i=0; i < self.checkLists.count; i++) {
height += 44;
Expand Down Expand Up @@ -213,6 +237,11 @@ - (IBAction)applyTap:(UIButton *)sender {
[self.delegate alertViewController:self didApplyInput:self.inputText];
}
}
else if (self.type == MDAlertOptionTypeMultipleInput) {
if ([self.delegate respondsToSelector:@selector(alertViewController:didApplyMultipleInput:)]) {
[self.delegate alertViewController:self didApplyMultipleInput:self.multipleInputTexts];
}
}
else {
if ([self.delegate respondsToSelector:@selector(alertViewController:didApplyCheck:)]) {
NSArray *indexPaths = self.tableView.indexPathsForSelectedRows;
Expand All @@ -234,6 +263,9 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
else if (self.type == MDAlertOptionTypeInput) {
return 1;
}
else if (self.type == MDAlertOptionTypeMultipleInput) {
return 3;
}
else {
return self.checkLists.count;
}
Expand All @@ -247,15 +279,23 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
else if (self.type == MDAlertOptionTypeInput) {
return self.inputCell;
}
else if (self.type == MDAlertOptionTypeMultipleInput) {
MDAlertInputCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"MDAlertInputCell"];
cell.textField.hint = self.inputPlaceholder;
cell.textField.text = self.multipleInputTexts[indexPath.row];
cell.textField.tag = indexPath.row;
[cell.textField addTarget:self action:@selector(inputTextChanged:) forControlEvents:UIControlEventEditingChanged];
return cell;
}
else {
MDAlertCheckCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MDAlertCheckCell"];
cell.titleLabel.text = self.checkLists[indexPath.row];
return cell;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.type == MDAlertOptionTypeInput) {
return 50;
if (self.type == MDAlertOptionTypeInput || self.type == MDAlertOptionTypeMultipleInput) {
return MDAlertInputCellHeight;
}
else {
return 44;
Expand All @@ -266,8 +306,16 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
}

- (void)inputTextChanged:(MDTextField *)textField {
self.inputText = textField.text;
self.applyButton.enabled = textField.text.length > 0;
if (self.type == MDAlertOptionTypeInput) {
self.inputText = textField.text;
self.applyButton.enabled = textField.text.length > 0;
}
else if (self.type == MDAlertOptionTypeMultipleInput) {
NSMutableArray *mutable = [NSMutableArray arrayWithArray:self.multipleInputTexts];
[mutable replaceObjectAtIndex:textField.tag withObject:textField.text];
self.multipleInputTexts = [NSArray arrayWithArray:mutable];
self.applyButton.enabled = [self.multipleInputTexts componentsJoinedByString:@""].length > 0;
}
}

@end
Loading

0 comments on commit c9a76dd

Please sign in to comment.