Skip to content

Commit ef53271

Browse files
committed
[hotfix] notify caller of intention to show dialog
1 parent b901e0e commit ef53271

File tree

8 files changed

+119
-28
lines changed

8 files changed

+119
-28
lines changed

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
=== 3.0.3 2017-05-24
2+
3+
* Hotfix Ensure we notify caller when showing or dismissing our dialogs
4+
15
=== 2.1.1 2016-12-08
26

37
* Hotfix Add TransactionParams to PaystackIOSStatic's headers

Example/Paystack iOS Example/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
<key>CFBundlePackageType</key>
1616
<string>APPL</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>3.0.2</string>
18+
<string>3.0.3</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>
22-
<string>4</string>
22+
<string>5</string>
2323
<key>LSRequiresIPhoneOS</key>
2424
<true/>
2525
<key>UILaunchStoryboardName</key>

Example/Paystack iOS Example/ViewController.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class ViewController: UIViewController, PSTCKPaymentCardTextFieldDelegate {
106106
let transactionParams = PSTCKTransactionParams.init();
107107
transactionParams.access_code = newCode as String;
108108
// use library to create charge and get its reference
109-
PSTCKAPIClient.shared().chargeCard(self.cardDetailsForm.cardParams, forTransaction: transactionParams, on: self, didEndWithError: { (error, reference) -> Void in
109+
PSTCKAPIClient.shared().chargeCard(self.cardDetailsForm.cardParams, forTransaction: transactionParams, on: self, didEndWithError: { (error, reference) in
110110
self.outputOnLabel(str: "Charge errored")
111111
// what should I do if an error occured?
112112
print(error)
@@ -131,13 +131,20 @@ class ViewController: UIViewController, PSTCKPaymentCardTextFieldDelegate {
131131
}
132132
}
133133
self.chargeCardButton.isEnabled = true;
134-
}, didRequestValidation: { (reference) -> Void in
134+
}, didRequestValidation: { (reference) in
135135
self.outputOnLabel(str: "requested validation: " + reference)
136-
}, didTransactionSuccess: { (reference) -> Void in
136+
}, willPresentDialog: {
137+
// make sure dialog can show
138+
// if using a "processing" dialog, please hide it
139+
self.outputOnLabel(str: "will show a dialog")
140+
}, dismissedDialog: {
141+
// if using a processing dialog, please make it visible again
142+
self.outputOnLabel(str: "dismissed dialog")
143+
}) { (reference) in
137144
self.outputOnLabel(str: "succeeded: " + reference)
138145
self.chargeCardButton.isEnabled = true;
139146
self.verifyTransaction(reference: reference)
140-
})
147+
}
141148
return
142149
}
143150

Paystack.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'Paystack'
3-
s.version = '3.0.2'
3+
s.version = '3.0.3'
44
s.summary = 'Paystack is a web-based API helping African Businesses accept payments online.'
55
s.description = <<-DESC
66
Paystack makes it easy for African Businesses to accept Mastercard, Visa and Verve cards from anyone, anywhere in the world.

Paystack/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>3.0.2</string>
18+
<string>3.0.3</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>
22-
<string>4</string>
22+
<string>5</string>
2323
<key>NSPrincipalClass</key>
2424
<string></string>
2525
</dict>

Paystack/PSTCKAPIClient.m

Lines changed: 76 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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
249250
didTransactionSuccess:(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
276315
didTransactionSuccess:(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,

Paystack/PublicHeaders/PSTCKAPIClient.h

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
#import <UIKit/UIViewController.h>
99
#endif
1010

11-
static NSString *const __nonnull PSTCKSDKVersion = @"3.0.2";
12-
static NSString *const __nonnull PSTCKSDKBuild = @"11";
11+
static NSString *const __nonnull PSTCKSDKVersion = @"3.0.3";
12+
static NSString *const __nonnull PSTCKSDKBuild = @"12";
1313

1414
@class PSTCKCard, PSTCKCardParams, PSTCKTransactionParams, PSTCKToken;
1515

@@ -21,6 +21,7 @@ static NSString *const __nonnull PSTCKSDKBuild = @"11";
2121
*/
2222
typedef void (^PSTCKErrorCompletionBlock)(NSError * __nonnull error, NSString * __nullable reference);
2323
typedef void (^PSTCKTransactionCompletionBlock)(NSString * __nonnull reference);
24+
typedef void (^PSTCKNotifyCompletionBlock)();
2425

2526
/**
2627
A top-level class that imports the rest of the Paystack SDK. This class used to contain several methods to create Paystack tokens, but those are now deprecated in
@@ -67,16 +68,32 @@ typedef void (^PSTCKTransactionCompletionBlock)(NSString * __nonnull reference);
6768
@interface PSTCKAPIClient (CreditCards)
6869

6970
/**
70-
* Converts an PSTCKCardParams object into a Paystack token using the Paystack API.
71+
* Charges a PSTCKCardParams object using the Paystack API.
7172
*
7273
* @param card The user's card details. Cannot be nil. @see https://paystack.com/docs/api#create_card_token
73-
* @param completion The callback to run with the returned Paystack token (and any errors that may have occurred).
7474
*/
7575
- (void) chargeCard:(nonnull PSTCKCardParams *)card
7676
forTransaction:(nonnull PSTCKTransactionParams *)transaction
7777
onViewController:(nonnull UIViewController *)viewController
7878
didEndWithError:(nonnull PSTCKErrorCompletionBlock)errorCompletion
79-
didRequestValidation:(nullable PSTCKTransactionCompletionBlock)beforeValidateCompletion
79+
didRequestValidation:(nonnull PSTCKTransactionCompletionBlock)beforeValidateCompletion
80+
didTransactionSuccess:(nonnull PSTCKTransactionCompletionBlock)successCompletion;
81+
82+
- (void) chargeCard:(nonnull PSTCKCardParams *)card
83+
forTransaction:(nonnull PSTCKTransactionParams *)transaction
84+
onViewController:(nonnull UIViewController *)viewController
85+
didEndWithError:(nonnull PSTCKErrorCompletionBlock)errorCompletion
86+
didRequestValidation:(nonnull PSTCKTransactionCompletionBlock)beforeValidateCompletion
87+
willPresentDialog:(nonnull PSTCKNotifyCompletionBlock)showingDialogCompletion
88+
dismissedDialog:(nonnull PSTCKNotifyCompletionBlock)dialogDismissedCompletion
89+
didTransactionSuccess:(nonnull PSTCKTransactionCompletionBlock)successCompletion;
90+
91+
- (void) chargeCard:(nonnull PSTCKCardParams *)card
92+
forTransaction:(nonnull PSTCKTransactionParams *)transaction
93+
onViewController:(nonnull UIViewController *)viewController
94+
didEndWithError:(nonnull PSTCKErrorCompletionBlock)errorCompletion
95+
willPresentDialog:(nonnull PSTCKNotifyCompletionBlock)showingDialogCompletion
96+
dismissedDialog:(nonnull PSTCKNotifyCompletionBlock)dialogDismissedCompletion
8097
didTransactionSuccess:(nonnull PSTCKTransactionCompletionBlock)successCompletion;
8198

8299
@end

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.2
1+
3.0.3

0 commit comments

Comments
 (0)