Skip to content

Commit

Permalink
Added 3DS to sample app token payments (#84)
Browse files Browse the repository at this point in the history
* Added fix for 3DS transactions crashing

* Added 3DS to sample app token payments
  • Loading branch information
mpetrenco authored Oct 19, 2020
1 parent 33c9a23 commit 87d1bf5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ @interface PayWithCardTokenViewController ()
@property (strong, nonatomic) IBOutlet JPLoadingButton *preAuthWithCardTokenButton;
@property (strong, nonatomic) IBOutlet UIButton *createCardTokenButton;

@property (strong, nonatomic) JP3DSService *threeDSecureService;
@property (strong, nonatomic) JPApiService *apiService;
@property (strong, nonatomic) UIActivityIndicatorView *activityIndicatorView;
@property (strong, nonatomic) NSString *cardToken;
Expand All @@ -60,14 +61,22 @@ - (IBAction)addCardAction:(UIButton *)sender {

- (void)createCardTokenOperation {
__weak typeof(self) weakSelf = self;
[self.judoKit invokeTransactionWithType:JPTransactionTypeRegisterCard
[self.judoKit invokeTransactionWithType:JPTransactionTypeSaveCard
configuration:self.configuration
completion:^(JPResponse *response, JPError *error) {
[weakSelf handleResponse:response error:error showReceipt:false];
}];
}

- (void)handleResponse:(JPResponse *)response error:(NSError *)error showReceipt:(BOOL)showReceipt {
- (void)handleResponse:(JPResponse *)response
error:(NSError *)error
showReceipt:(BOOL)showReceipt {

if (error.code == Judo3DSRequestError) {
[self handle3DSecureTransactionFromError:error];
return;
}

if (error || !response) {
[self displayAlertWithError:error];
return;
Expand Down Expand Up @@ -118,6 +127,21 @@ - (IBAction)preAuthWithCardToken:(UIButton *)sender {
}];
}

- (void)handle3DSecureTransactionFromError:(NSError *)error {
__weak typeof(self) weakSelf = self;
JP3DSConfiguration *configuration = [JP3DSConfiguration configurationWithError:error];
[self.threeDSecureService invoke3DSecureWithConfiguration:configuration
completion:^(JPResponse *response, JPError *transactionError) {

if (response) {
[weakSelf presentResultTableViewControllerWithResponse:response];
return;
}

[weakSelf displayAlertWithError:error];
}];
}

- (void)setupButtons {
[self.preAuthWithCardTokenButton setBackgroundImage:UIColor.darkGrayColor.asImage forState:UIControlStateDisabled];
[self.preAuthWithCardTokenButton setBackgroundImage:UIColor.blackColor.asImage forState:UIControlStateNormal];
Expand All @@ -131,4 +155,11 @@ - (void)shouldEnableButtons:(BOOL)shouldEnable {
self.preAuthWithCardTokenButton.enabled = shouldEnable;
}

- (JP3DSService *)threeDSecureService {
if (!_threeDSecureService) {
_threeDSecureService = [[JP3DSService alloc] initWithApiService:self.apiService];
}
return _threeDSecureService;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ - (void)handle3DSecureTransactionWithError:(NSError *)error {
__weak typeof(self) weakSelf = self;
[self.interactor handle3DSecureTransactionFromError:error
completion:^(JPResponse *response, NSError *transactionError) {
if (error) {
if (transactionError) {
[weakSelf handlePaymentError:transactionError];
return;
}
Expand Down

0 comments on commit 87d1bf5

Please sign in to comment.