@@ -91,6 +91,8 @@ @interface PSTCKAPIClient ()
9191@property (nonatomic , retain ) PSTCKTransactionParams *transaction;
9292@property (nonatomic , copy ) PSTCKErrorCompletionBlock errorCompletion;
9393@property (nonatomic , copy ) PSTCKTransactionCompletionBlock beforeValidateCompletion;
94+ @property (nonatomic , copy ) PSTCKNotifyCompletionBlock showingDialogCompletion;
95+ @property (nonatomic , copy ) PSTCKNotifyCompletionBlock dialogDismissedCompletion;
9496@property (nonatomic , copy ) PSTCKTransactionCompletionBlock successCompletion;
9597@property int INVALID_DATA_SENT_RETRIES;
9698@end
@@ -245,14 +247,13 @@ - (void)chargeCard:(nonnull PSTCKCardParams *)card
245247 forTransaction : (nonnull PSTCKTransactionParams *)transaction
246248 onViewController : (nonnull UIViewController *)viewController
247249 didEndWithError : (nonnull PSTCKErrorCompletionBlock)errorCompletion
248- didRequestValidation : (nullable PSTCKTransactionCompletionBlock)beforeValidateCompletion
249250didTransactionSuccess : (nonnull PSTCKTransactionCompletionBlock)successCompletion {
250251 NSCAssert (card != nil , @" 'card' is required for a charge" );
251252 NSCAssert (errorCompletion != nil , @" 'errorCompletion' is required to handle any errors encountered while charging" );
252253 NSCAssert (viewController != nil , @" 'viewController' is required to show any alerts that may be needed" );
253254 NSCAssert (transaction != nil , @" 'transaction' is required so we may know who to charge" );
254255 NSCAssert (successCompletion != nil , @" 'successCompletion' is required so you can continue the process after charge succeeds. Remember to verify on server before giving value." );
255- [self startWithCard: card forTransaction: transaction onViewController: viewController didEndWithError: errorCompletion didRequestValidation: beforeValidateCompletion didTransactionSuccess: successCompletion];
256+ [self startWithCard: card forTransaction: transaction onViewController: viewController didEndWithError: errorCompletion didTransactionSuccess: successCompletion];
256257
257258 if (PROCESSING){
258259 [self didEndWithProcessingError ];
@@ -268,17 +269,54 @@ - (void)chargeCard:(nonnull PSTCKCardParams *)card
268269 [self makeChargeRequest: data atStage: PSTCKChargeStageNoHandle];
269270}
270271
272+ - (void )chargeCard : (nonnull PSTCKCardParams *)card
273+ forTransaction : (nonnull PSTCKTransactionParams *)transaction
274+ onViewController : (nonnull UIViewController *)viewController
275+ didEndWithError : (nonnull PSTCKErrorCompletionBlock)errorCompletion
276+ didRequestValidation : (nonnull PSTCKTransactionCompletionBlock)beforeValidateCompletion
277+ willPresentDialog : (nonnull PSTCKNotifyCompletionBlock)showingDialogCompletion
278+ dismissedDialog : (nonnull PSTCKNotifyCompletionBlock)dialogDismissedCompletion
279+ didTransactionSuccess : (nonnull PSTCKTransactionCompletionBlock)successCompletion {
280+ self.beforeValidateCompletion = beforeValidateCompletion;
281+ self.showingDialogCompletion = showingDialogCompletion;
282+ self.dialogDismissedCompletion = dialogDismissedCompletion;
283+ [self chargeCard: card forTransaction: transaction onViewController: viewController didEndWithError: errorCompletion didTransactionSuccess: successCompletion];
284+
285+ }
286+
287+ - (void )chargeCard : (nonnull PSTCKCardParams *)card
288+ forTransaction : (nonnull PSTCKTransactionParams *)transaction
289+ onViewController : (nonnull UIViewController *)viewController
290+ didEndWithError : (nonnull PSTCKErrorCompletionBlock)errorCompletion
291+ willPresentDialog : (nonnull PSTCKNotifyCompletionBlock)showingDialogCompletion
292+ dismissedDialog : (nonnull PSTCKNotifyCompletionBlock)dialogDismissedCompletion
293+ didTransactionSuccess : (nonnull PSTCKTransactionCompletionBlock)successCompletion {
294+ self.showingDialogCompletion = showingDialogCompletion;
295+ self.dialogDismissedCompletion = dialogDismissedCompletion;
296+ [self chargeCard: card forTransaction: transaction onViewController: viewController didEndWithError: errorCompletion didTransactionSuccess: successCompletion];
297+
298+ }
299+
300+ - (void )chargeCard : (nonnull PSTCKCardParams *)card
301+ forTransaction : (nonnull PSTCKTransactionParams *)transaction
302+ onViewController : (nonnull UIViewController *)viewController
303+ didEndWithError : (nonnull PSTCKErrorCompletionBlock)errorCompletion
304+ didRequestValidation : (nonnull PSTCKTransactionCompletionBlock)beforeValidateCompletion
305+ didTransactionSuccess : (nonnull PSTCKTransactionCompletionBlock)successCompletion {
306+ self.beforeValidateCompletion = beforeValidateCompletion;
307+ [self chargeCard: card forTransaction: transaction onViewController: viewController didEndWithError: errorCompletion didTransactionSuccess: successCompletion];
308+
309+ }
310+
271311- (void )startWithCard : (nonnull PSTCKCardParams *)card
272312 forTransaction : (nonnull PSTCKTransactionParams *)transaction
273313 onViewController : (nonnull UIViewController *)viewController
274314 didEndWithError : (nonnull PSTCKErrorCompletionBlock)errorCompletion
275- didRequestValidation : (nullable PSTCKTransactionCompletionBlock)beforeValidateCompletion
276315didTransactionSuccess : (nonnull PSTCKTransactionCompletionBlock)successCompletion {
277316 self.card = card;
278317 self.transaction = transaction;
279318 self.viewController = viewController;
280319 self.errorCompletion = errorCompletion;
281- self.beforeValidateCompletion = beforeValidateCompletion;
282320 self.successCompletion = successCompletion;
283321 self.serverTransaction = [PSTCKServerTransaction new ];
284322
@@ -346,9 +384,7 @@ - (void) makeChargeRequest:(NSData *)data
346384}
347385
348386- (void ) requestPin {
349- [self .operationQueue addOperationWithBlock: ^{
350- self.beforeValidateCompletion (self.serverTransaction .reference );
351- }];
387+ [self notifyShowingDialog ];
352388 UIAlertController* alert = [UIAlertController alertControllerWithTitle: @" Enter CARD PIN"
353389 message: @" To confirm that you are the owner of this card please enter your card PIN"
354390 preferredStyle: UIAlertControllerStyleAlert];
@@ -357,6 +393,7 @@ - (void) requestPin{
357393 actionWithTitle: @" Continue" style: UIAlertActionStyleDefault
358394 handler: ^(UIAlertAction * action) {
359395 [action isEnabled ]; // Just to avoid Unused error
396+ [self notifyDialogDismissed ];
360397 NSString *provided = ((UITextField *)[alert.textFields objectAtIndex: 0 ]).text ;
361398 NSString *handle = [PSTCKCardValidator sanitizedNumericStringForString: provided];
362399 if (handle == nil ||
@@ -386,13 +423,13 @@ - (void) requestPin{
386423}
387424
388425- (void ) requestAuth : (NSString * _Nonnull) url {
389- [self .operationQueue addOperationWithBlock: ^{
390- self.beforeValidateCompletion (self.serverTransaction .reference );
391- }];
426+ [self notifyShowingDialog ];
427+ [self notifyBeforeValidate ];
392428 PSTCKAuthViewController* authorizer = [[[PSTCKAuthViewController alloc ] init ]
393429 initWithURL: [NSURL URLWithString: url]
394430 handler: ^{
395431 [self .viewController dismissViewControllerAnimated: YES completion: nil ];
432+ [self notifyDialogDismissed ];
396433 [self makeChargeRequest: nil
397434 atStage: PSTCKChargeStageRequery];
398435 }];
@@ -405,9 +442,8 @@ - (void) requestAuth:(NSString * _Nonnull) url{
405442}
406443
407444- (void ) requestOtp : (NSString * _Nonnull) otpmessage {
408- [self .operationQueue addOperationWithBlock: ^{
409- self.beforeValidateCompletion (self.serverTransaction .reference );
410- }];
445+ [self notifyShowingDialog ];
446+ [self notifyBeforeValidate ];
411447 UIAlertController* tkalert = [UIAlertController alertControllerWithTitle: @" Enter OTP"
412448 message: otpmessage
413449 preferredStyle: UIAlertControllerStyleAlert];
@@ -416,6 +452,7 @@ - (void) requestOtp:(NSString * _Nonnull) otpmessage{
416452 actionWithTitle: @" Continue" style: UIAlertActionStyleDefault
417453 handler: ^(UIAlertAction * action) {
418454 [action isEnabled ]; // Just to avoid Unused error
455+ [self notifyDialogDismissed ];
419456 NSString *provided = ((UITextField *)[tkalert.textFields objectAtIndex: 0 ]).text ;
420457 PSTCKValidationParams *validateParams = [PSTCKValidationParams alloc ];
421458 validateParams.trans = self.serverTransaction .id ;
@@ -499,6 +536,32 @@ - (void)didEndSuccessfully{
499536 }];
500537}
501538
539+ - (void )notifyShowingDialog {
540+ if (self.showingDialogCompletion == NULL ){
541+ return ;
542+ }
543+ [self .operationQueue addOperationWithBlock: ^{
544+ self.showingDialogCompletion ();
545+ }];
546+ }
547+ - (void )notifyDialogDismissed {
548+ if (self.dialogDismissedCompletion == NULL ){
549+ return ;
550+ }
551+ [self .operationQueue addOperationWithBlock: ^{
552+ self.dialogDismissedCompletion ();
553+ }];
554+ }
555+ - (void )notifyBeforeValidate {
556+ if (self.beforeValidateCompletion == NULL ){
557+ return ;
558+ }
559+ [self .operationQueue addOperationWithBlock: ^{
560+ self.beforeValidateCompletion (self.serverTransaction .reference );
561+ }];
562+ }
563+
564+
502565- (void )didEndWithErrorMessage : (NSString *)errorString {
503566 NSDictionary *userInfo = @{
504567 NSLocalizedDescriptionKey : PSTCKCardErrorProcessingErrorUserMessage,
0 commit comments