diff --git a/ASDKUI/Payment/PaymentFormStarter/ASDKDesignConfiguration.h b/ASDKUI/Payment/PaymentFormStarter/ASDKDesignConfiguration.h index 713a57b..1351b02 100644 --- a/ASDKUI/Payment/PaymentFormStarter/ASDKDesignConfiguration.h +++ b/ASDKUI/Payment/PaymentFormStarter/ASDKDesignConfiguration.h @@ -142,4 +142,10 @@ typedef NS_ENUM(NSUInteger, TableViewCellType) - (void)setPayViewTitle:(NSString *)title; - (NSString *)payViewTitle; + +- (void)setPresentationCompletion:(void (^)(void))presentationCompletion; +- (void (^)(void))getPresentationCompletion; +- (void)setPresentAnimated:(BOOL)animated; +- (BOOL)shouldAnimate; + @end diff --git a/ASDKUI/Payment/PaymentFormStarter/ASDKDesignConfiguration.m b/ASDKUI/Payment/PaymentFormStarter/ASDKDesignConfiguration.m index 1e499c1..21a54eb 100644 --- a/ASDKUI/Payment/PaymentFormStarter/ASDKDesignConfiguration.m +++ b/ASDKUI/Payment/PaymentFormStarter/ASDKDesignConfiguration.m @@ -45,6 +45,9 @@ @interface ASDKDesignConfiguration () @property (nonatomic, strong) NSString *payViewControllerTitle; +@property (nonatomic, strong) void (^presentationCompletion)(void); +@property (nonatomic) BOOL _presentAnimated; + @end @implementation ASDKDesignConfiguration @@ -62,6 +65,7 @@ - (id)init __navigationBarItemsTextColor = UIColor.blackColor; } __presentStyleModal = UIModalPresentationFullScreen; + __presentAnimated = YES; } return self; @@ -298,4 +302,22 @@ - (NSString *)payViewTitle return self.payViewControllerTitle; } +- (void)setPresentationCompletion:(void (^)(void))presentationCompletion +{ + _presentationCompletion = presentationCompletion; +} +- (void (^)(void))getPresentationCompletion +{ + return _presentationCompletion; +} + +-(void)setPresentAnimated:(BOOL)animated +{ + __presentAnimated = animated; +} +-(BOOL)shouldAnimate +{ + return __presentAnimated; +} + @end diff --git a/ASDKUI/Payment/PaymentFormStarter/ASDKPaymentFormStarter.m b/ASDKUI/Payment/PaymentFormStarter/ASDKPaymentFormStarter.m index ba814c5..7693df9 100644 --- a/ASDKUI/Payment/PaymentFormStarter/ASDKPaymentFormStarter.m +++ b/ASDKUI/Payment/PaymentFormStarter/ASDKPaymentFormStarter.m @@ -170,37 +170,41 @@ - (void)presentPaymentFormFromViewController:(UIViewController *)presentingViewC { [self prepareDesign]; - ASDKPaymentFormViewController *vc = [[ASDKPaymentFormViewController alloc] initWithAmount:amount - orderId:orderId - title:title - description:description - cardId:cardId - email:email - customerKey:customerKey - recurrent:recurrent - makeCharge:makeCharge - additionalPaymentData:data - receiptData:receiptData - shopsData:shopsData - shopsReceiptsData:shopsReceiptsData - success:^(ASDKPaymentInfo *paymentInfo) - { - [ASDKPaymentFormStarter resetSharedInstance]; - - onSuccess(paymentInfo); - } - cancelled:^ - { - [ASDKPaymentFormStarter resetSharedInstance]; - - onCancelled(); - } - error:^(ASDKAcquringSdkError *error) - { - [ASDKPaymentFormStarter resetSharedInstance]; - - onError(error); - }]; + ASDKPaymentFormViewController *vc = [ + [ASDKPaymentFormViewController alloc] + initWithAmount:amount + orderId:orderId + title:title + description:description + cardId:cardId + email:email + customerKey:customerKey + recurrent:recurrent + makeCharge:makeCharge + additionalPaymentData:data + receiptData:receiptData + shopsData:shopsData + shopsReceiptsData:shopsReceiptsData + success:^(ASDKPaymentInfo *paymentInfo) { + [ASDKPaymentFormStarter resetSharedInstance]; + if (onSuccess != nil) + { + onSuccess(paymentInfo); + } + } + cancelled:^{ + [ASDKPaymentFormStarter resetSharedInstance]; + if (onCancelled != nil){ + onCancelled(); + } + } + error:^(ASDKAcquringSdkError *error){ + [ASDKPaymentFormStarter resetSharedInstance]; + if (onError != nil) + { + onError(error); + } + }]; vc.acquiringSdk = self.acquiringSdk; @@ -209,7 +213,10 @@ - (void)presentPaymentFormFromViewController:(UIViewController *)presentingViewC [ASDKCardsListDataController cardsListDataControllerWithAcquiringSdk:self.acquiringSdk customerKey:customerKey]; - [presentingViewController presentViewController:nc animated:YES completion:nil]; + [presentingViewController presentViewController:nc + animated:self.designConfiguration.shouldAnimate + completion:self.designConfiguration.getPresentationCompletion + ]; } #pragma mark - Loader @@ -362,7 +369,10 @@ - (void)payWithApplePayFromViewController:(UIViewController *)presentingViewCont if (viewController) { self.presentingViewControllerApplePay = presentingViewController; - [self.presentingViewControllerApplePay presentViewController:viewController animated:YES completion:^{}]; + [self.presentingViewControllerApplePay presentViewController:viewController + animated:self.designConfiguration.shouldAnimate + completion:self.designConfiguration.getPresentationCompletion + ]; } else { @@ -446,7 +456,10 @@ - (void)payUsingApplePayFromViewController:(UIViewController *)presentingViewCon if (viewController) { self.presentingViewControllerApplePay = presentingViewController; - [self.presentingViewControllerApplePay presentViewController: viewController animated: YES completion:^{}]; + [self.presentingViewControllerApplePay presentViewController: viewController + animated:self.designConfiguration.shouldAnimate + completion:self.designConfiguration.getPresentationCompletion + ]; } else { @@ -466,11 +479,17 @@ - (void)checkStatusTransaction:(NSString *)paymentId success:(void (^)(ASDKPaymentStatus status))onSuccess error:(void (^)(ASDKAcquringSdkError *error))onError { - [self.acquiringSdk getStateWithPaymentId:paymentId success:^(ASDKPaymentInfo *paymentInfo, ASDKPaymentStatus status) { - onSuccess(status); - } failure:^(ASDKAcquringSdkError *error) { - onError(error); - }]; + [self.acquiringSdk getStateWithPaymentId:paymentId success:^(ASDKPaymentInfo *paymentInfo, ASDKPaymentStatus status) { + if (onSuccess != nil) + { + onSuccess(status); + } + } failure:^(ASDKAcquringSdkError *error) { + if (onError != nil) + { + onError(error); + } + }]; } - (void)refundTransaction:(NSString *)paymentId @@ -478,9 +497,15 @@ - (void)refundTransaction:(NSString *)paymentId error:(void (^)(ASDKAcquringSdkError *error))onError { [self.acquiringSdk rejectTrancastionWithPaymentId:paymentId success:^(ASDKCancelResponse *response) { - onSuccess(); + if (onSuccess != nil) + { + onSuccess(); + } } failure:^(ASDKAcquringSdkError *error) { - onError(error); + if (onError != nil) + { + onError(error); + } }]; } @@ -505,93 +530,114 @@ - (void)chargeWithRebillId:(NSNumber *)rebillId [paymentData setObject:@(YES) forKey:@"chargeFlag"]; - [self.acquiringSdk initWithAmount:[NSNumber numberWithDouble:100 * amount.doubleValue] - orderId:orderId - description:description - payForm:nil - customerKey:customerKey - recurrent:NO - additionalPaymentData:paymentData - receiptData:receiptData - shopsData:shopsData - shopsReceiptsData:shopsReceiptsData - location:ASDKLocalized.sharedInstance.localeIdentifier - success:^(ASDKInitResponse *response) { - [self.acquiringSdk chargeWithPaymentId:response.paymentId rebillId:rebillId success:^(ASDKPaymentInfo *paymentInfo, ASDKPaymentStatus status) { - [ASDKPaymentFormStarter resetSharedInstance]; - onSuccess(paymentInfo); - } failure:^(ASDKAcquringSdkError *error) { - ASDKAcquiringResponse *errorResponse = [error.userInfo objectForKey:@"acquringResponse"]; - //пользователю необходимо подтвердить платеж через ввод cvc ASDK-432 - //ErrorCode == 104 - if ([[errorResponse.dictionary objectForKey:@"ErrorCode"] integerValue] == 104) - { - [[ASDKCardsListDataController cardsListDataControllerWithAcquiringSdk:self.acquiringSdk customerKey:customerKey] updateCardsListWithSuccessBlock:^{ - ASDKCard *selectedCard = [[ASDKCardsListDataController instance] cardByRebillId:rebillId]; - if (selectedCard != nil) - { - [self prepareDesign]; - - ASDKPaymentFormViewController *vc = [[ASDKPaymentFormViewController alloc] initWithAmount:amount - orderId:orderId - title:nil - description:description - cardId:selectedCard.cardId - email:nil - customerKey:customerKey - recurrent:NO - makeCharge:YES - additionalPaymentData:paymentData - receiptData:receiptData - shopsData:shopsData - shopsReceiptsData:shopsReceiptsData - success:^(ASDKPaymentInfo *paymentInfo) - { - [ASDKPaymentFormStarter resetSharedInstance]; - - onSuccess(paymentInfo); - } - cancelled:^ - { - [ASDKPaymentFormStarter resetSharedInstance]; - - onError(nil); - } - error:^(ASDKAcquringSdkError *error) - { - [ASDKPaymentFormStarter resetSharedInstance]; - - onError(error); - }]; - - vc.acquiringSdk = self.acquiringSdk; - [ASDKCardsListDataController cardsListDataControllerWithAcquiringSdk:self.acquiringSdk customerKey:customerKey]; - [vc setChargeError:YES]; - [vc setChargeErrorPaymentId:[errorResponse.dictionary objectForKey:@"PaymentId"]]; - [vc needSetupCardRequisitesCellForCVC]; - - ASDKNavigationController *nc = [[ASDKNavigationController alloc] initWithRootViewController:vc]; - [nc setModalPresentationStyle:self.designConfiguration.modalPresentationStyle]; - - if (paymentConfirm) - { - paymentConfirm(nc); - } - } - } errorBlock:^(ASDKAcquringSdkError *error) { - [ASDKPaymentFormStarter resetSharedInstance]; - onError(error); - }]; - } - else - { - [ASDKPaymentFormStarter resetSharedInstance]; - onError(error); - } - }]; - } failure:^(ASDKAcquringSdkError *error) { - onError(error); - }]; + [self.acquiringSdk initWithAmount:[NSNumber numberWithDouble:100 * amount.doubleValue] + orderId:orderId + description:description + payForm:nil + customerKey:customerKey + recurrent:NO + additionalPaymentData:paymentData + receiptData:receiptData + shopsData:shopsData + shopsReceiptsData:shopsReceiptsData + location:ASDKLocalized.sharedInstance.localeIdentifier + success:^(ASDKInitResponse *response) { + [self.acquiringSdk chargeWithPaymentId:response.paymentId rebillId:rebillId success:^(ASDKPaymentInfo *paymentInfo, ASDKPaymentStatus status) { + [ASDKPaymentFormStarter resetSharedInstance]; + if (onSuccess != nil) + { + onSuccess(paymentInfo); + } + } failure:^(ASDKAcquringSdkError *error) { + ASDKAcquiringResponse *errorResponse = [error.userInfo objectForKey:@"acquringResponse"]; + //пользователю необходимо подтвердить платеж через ввод cvc ASDK-432 + //ErrorCode == 104 + if ([[errorResponse.dictionary objectForKey:@"ErrorCode"] integerValue] == 104) + { + [[ASDKCardsListDataController cardsListDataControllerWithAcquiringSdk:self.acquiringSdk customerKey:customerKey] updateCardsListWithSuccessBlock:^{ + ASDKCard *selectedCard = [[ASDKCardsListDataController instance] cardByRebillId:rebillId]; + if (selectedCard != nil) + { + [self prepareDesign]; + + ASDKPaymentFormViewController *vc = [ + [ASDKPaymentFormViewController alloc] + initWithAmount:amount + orderId:orderId + title:nil + description:description + cardId:selectedCard.cardId + email:nil + customerKey:customerKey + recurrent:NO + makeCharge:YES + additionalPaymentData:paymentData + receiptData:receiptData + shopsData:shopsData + shopsReceiptsData:shopsReceiptsData + success:^(ASDKPaymentInfo *paymentInfo) + { + [ASDKPaymentFormStarter resetSharedInstance]; + if (onSuccess != nil) + { + onSuccess(paymentInfo); + } + } + cancelled:^ + { + [ASDKPaymentFormStarter resetSharedInstance]; + if (onError != nil) + { + onError(nil); + } + } + error:^(ASDKAcquringSdkError *error) + { + [ASDKPaymentFormStarter resetSharedInstance]; + if (onError != nil) + { + onError(error); + } + }]; + + vc.acquiringSdk = self.acquiringSdk; + [ASDKCardsListDataController cardsListDataControllerWithAcquiringSdk:self.acquiringSdk customerKey:customerKey]; + [vc setChargeError:YES]; + [vc setChargeErrorPaymentId:[errorResponse.dictionary objectForKey:@"PaymentId"]]; + [vc needSetupCardRequisitesCellForCVC]; + + ASDKNavigationController *nc = [[ASDKNavigationController alloc] initWithRootViewController:vc]; + [nc setModalPresentationStyle:self.designConfiguration.modalPresentationStyle]; + + if (paymentConfirm) + { + paymentConfirm(nc); + } + } + } errorBlock:^(ASDKAcquringSdkError *error) { + [ASDKPaymentFormStarter resetSharedInstance]; + if (onError != nil) + { + onError(error); + } + }]; + } + else + { + [ASDKPaymentFormStarter resetSharedInstance]; + if (onError != nil) + { + onError(error); + } + } + }]; + } failure:^(ASDKAcquringSdkError *error) { + if (onError != nil) + { + onError(error); + } + } + ]; } #pragma mark - PKPaymentAuthorizationViewControllerDelegate @@ -698,23 +744,35 @@ - (void)presentAttachFormFromViewController:(UIViewController *)presentingViewCo // ASDKLoopViewController *viewController = [[ASDKLoopViewController alloc] initWithAddCardRequestKey:@"1" acquiringSdk:self.acquiringSdk]; - ASDKAttachCardViewController *viewController = [[ASDKAttachCardViewController alloc] initWithCardCheckType:cardCheckType - formTitle:(NSString *)title - formHeader:(NSString *)header - description:(NSString *)description - email:(NSString *)email - customerKey:(NSString *)customerKey - additionalData:(NSDictionary *)data - success:^(ASDKResponseAttachCard *result) { - [ASDKPaymentFormStarter resetSharedInstance]; - onSuccess(result); - } cancelled:^{ - [ASDKPaymentFormStarter resetSharedInstance]; - onCancelled(); - } error:^(ASDKAcquringSdkError *error) { - [ASDKPaymentFormStarter resetSharedInstance]; - onError(error); - }]; + ASDKAttachCardViewController *viewController = [ + [ASDKAttachCardViewController alloc] + initWithCardCheckType:cardCheckType + formTitle:(NSString *)title + formHeader:(NSString *)header + description:(NSString *)description + email:(NSString *)email + customerKey:(NSString *)customerKey + additionalData:(NSDictionary *)data + success:^(ASDKResponseAttachCard *result) { + [ASDKPaymentFormStarter resetSharedInstance]; + if (onSuccess != nil) + { + onSuccess(result); + } + } cancelled:^{ + [ASDKPaymentFormStarter resetSharedInstance]; + if (onCancelled != nil) + { + onCancelled(); + } + } error:^(ASDKAcquringSdkError *error) { + [ASDKPaymentFormStarter resetSharedInstance]; + if (onError != nil) + { + onError(error); + } + } + ]; viewController.isDissmissAfterCompletion = isDissmissAfterCompletion; viewController.acquiringSdk = self.acquiringSdk; @@ -722,7 +780,10 @@ - (void)presentAttachFormFromViewController:(UIViewController *)presentingViewCo ASDKNavigationController *nc = [[ASDKNavigationController alloc] initWithRootViewController:viewController]; [nc setModalPresentationStyle:self.designConfiguration.modalPresentationStyle]; [ASDKCardsListDataController cardsListDataControllerWithAcquiringSdk:self.acquiringSdk customerKey:customerKey]; - [presentingViewController presentViewController:nc animated:YES completion:nil]; + [presentingViewController presentViewController:nc + animated:self.designConfiguration.shouldAnimate + completion:self.designConfiguration.getPresentationCompletion + ]; } - (void)presentAttachFormFromViewController:(UIViewController *)presentingViewController