Skip to content

Commit

Permalink
Introduce 'State' field in Billing Address UI (#164)
Browse files Browse the repository at this point in the history
* Introduce 'State' field in Billing Address UI

* Minor improvements

Co-authored-by: Stefan Popa <[email protected]>
  • Loading branch information
zfoltin and stefan-tudor authored Oct 11, 2022
1 parent abd34bb commit 27c2dd3
Show file tree
Hide file tree
Showing 39 changed files with 546 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
@interface MainViewController (TableViewDelegates) <UITableViewDataSource, UITableViewDelegate>

/**
* A method that opens pbba payment screen from deeplink
*
* @param url - deeplink url
*/
* A method that opens pbba payment screen from deeplink
*
* @param url - deeplink url
*/
- (void)openPBBAScreen:(NSURL *)url;
@end
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#import "MaterialSnackbar.h"
#import <CoreLocation/CoreLocation.h>
#import <InAppSettingsKit/IASKAppSettingsViewController.h>
#import <InAppSettingsKit/IASKSettingsReader.h>
#import "MaterialSnackbar.h"
@import JudoKit_iOS;

#import "ApplePayViewController.h"
#import "DemoFeature.h"
#import "ExampleAppStorage.h"
#import "IASKAppSettingsViewController+Additions.h"
#import "MainViewController.h"
#import "NoUICardPayViewController.h"
#import "PBBAViewController.h"
#import "PayWithCardTokenViewController.h"
#import "NoUICardPayViewController.h"
#import "Settings.h"
#import "UIViewController+Additions.h"

Expand Down Expand Up @@ -265,7 +265,6 @@ - (void)serverToServerMethodOperation {
}

- (void)presentTextFieldAlertControllerWithCompletion:()completion {

}

- (void)transactionDetailsMethodOperation {
Expand All @@ -276,15 +275,15 @@ - (void)transactionDetailsMethodOperation {
negativeButtonTitle:@"Cancel"
textFieldPlaceholder:@"Receipt ID"
andCompletion:^(NSString *text) {
if (!text || text.length == 0) {
return;
}
[weakSelf.judoKit fetchTransactionWithReceiptId:text
completion:^(JPResponse *response, JPError *error) {
[weakSelf handleResponse:response error:error];
}];
}];
if (!text || text.length == 0) {
return;
}

[weakSelf.judoKit fetchTransactionWithReceiptId:text
completion:^(JPResponse *response, JPError *error) {
[weakSelf handleResponse:response error:error];
}];
}];
}

// MARK: Helper methods
Expand Down Expand Up @@ -331,20 +330,20 @@ - (JPConfiguration *)configuration {
configuration.isInitialRecurringPayment = Settings.defaultSettings.isInitialRecurringPaymentEnabled;
configuration.cardAddress = Settings.defaultSettings.address;
configuration.primaryAccountDetails = Settings.defaultSettings.primaryAccountDetails;

configuration.emailAddress = Settings.defaultSettings.emailAddress;
configuration.phoneCountryCode = Settings.defaultSettings.phoneCountryCode;
configuration.mobileNumber = Settings.defaultSettings.mobileNumber;
configuration.scaExemption = Settings.defaultSettings.scaExemption;
configuration.challengeRequestIndicator = Settings.defaultSettings.challengeRequestIndicator;
configuration.threeDSTwoMaxTimeout = Settings.defaultSettings.threeDsTwoMaxTimeout;

NSString *messageVersion = Settings.defaultSettings.threeDSTwoMessageVersion;

if (messageVersion.length > 0) {
configuration.threeDSTwoMessageVersion = messageVersion;
}

return configuration;
}

Expand All @@ -364,7 +363,7 @@ - (JPApplePayConfiguration *)applePayConfiguration {
currency:Settings.defaultSettings.amount.currency
countryCode:@"GB"
paymentSummaryItems:items];

configuration.requiredShippingContactFields = Settings.defaultSettings.applePayShippingContactFields;
configuration.requiredBillingContactFields = Settings.defaultSettings.applePayBillingContactFields;
configuration.returnedContactInfo = Settings.defaultSettings.applePayReturnedContactInfo;
Expand Down Expand Up @@ -410,17 +409,15 @@ - (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView
- (void)tableView:(nonnull UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
DemoFeature *feature = self.features[indexPath.row];

BOOL isApplePayRelatedFeature = feature.type == DemoFeatureTypeApplePayPayment
|| feature.type == DemoFeatureTypeApplePayPreAuth
|| feature.type == DemoFeatureTypeApplePayStandalone;

BOOL isApplePayRelatedFeature = feature.type == DemoFeatureTypeApplePayPayment || feature.type == DemoFeatureTypeApplePayPreAuth || feature.type == DemoFeatureTypeApplePayStandalone;

JPConfiguration *configuration = self.configuration;
if (isApplePayRelatedFeature && ![JudoKit isApplePayAvailableWithConfiguration:configuration]) {
[self _jp_displayAlertWithTitle:@"Error" andMessage:@"ApplePay is not available for given configuration."];
return;
}

switch (feature.type) {
case DemoFeatureTypePayment:
[self paymentOperation];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
// SOFTWARE.

#import "NoUICardPayViewController.h"
#import "UIViewController+Additions.h"
#import "Settings.h"
#import "UIViewController+Additions.h"

@import JudoKit_iOS;

Expand All @@ -48,25 +48,25 @@ - (void)viewDidLoad {
- (IBAction)payWithCardToken:(UIButton *)sender {
self.configuration.reference = Settings.defaultSettings.reference;
[self.payWithCardButton startLoading];

__weak typeof(self) weakSelf = self;
[self.transactionService invokePaymentWithDetails:self.cardTransactionDetails
andCompletion:^(JPResponse *response, JPError *error) {
[weakSelf.payWithCardButton stopLoading];
[weakSelf handleResponse:response error:error showReceipt:true];
}];
[weakSelf.payWithCardButton stopLoading];
[weakSelf handleResponse:response error:error showReceipt:true];
}];
}

- (IBAction)preAuthWithCardToken:(UIButton *)sender {
self.configuration.reference = Settings.defaultSettings.reference;
[self.preAuthWithCardButton startLoading];

__weak typeof(self) weakSelf = self;
[self.transactionService invokePreAuthPaymentWithDetails:self.cardTransactionDetails
andCompletion:^(JPResponse *response, JPError *error) {
[weakSelf.preAuthWithCardButton stopLoading];
[weakSelf handleResponse:response error:error showReceipt:true];
}];
[weakSelf.preAuthWithCardButton stopLoading];
[weakSelf handleResponse:response error:error showReceipt:true];
}];
}

- (JPCardTransactionDetails *)cardTransactionDetails {
Expand All @@ -83,8 +83,9 @@ - (JPCardTransactionDetails *)cardTransactionDetails {
address3:nil
town:@"London"
postCode:@"se151qa"
countryCode:@826];

countryCode:@826
state:nil];

return details;
}

Expand All @@ -105,7 +106,7 @@ - (JPCardTransactionService *)transactionService {
isSandboxed:Settings.defaultSettings.isSandboxed
andConfiguration:self.configuration];
}
return _transactionService;
return _transactionService;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ + (instancetype)resultFromObject:(id)objectToBuildFrom {
// Obtain the property name
objc_property_t property = propertyArray[i];
NSString *name = [[NSString alloc] initWithUTF8String:property_getName(property)];

if (!name || name.length == 0 || [name isEqualToString:@"observationInfo"]) {
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,19 @@ - (void)_jp_keyboardWillHide:(NSNotification *)notification {

- (IBAction)textFieldDidChange:(id)sender {
BOOL shouldEnableButtons =
self.cardNetworkTextField.text.length > 0
&& self.cardTokenTextField.text.length > 0
&& self.cardholderNameTextField.text.length > 0;

[self shouldEnableButtons: shouldEnableButtons];
self.cardNetworkTextField.text.length > 0 && self.cardTokenTextField.text.length > 0 && self.cardholderNameTextField.text.length > 0;

[self shouldEnableButtons:shouldEnableButtons];
}

- (IBAction)addCardAction:(UIButton *)sender {
__weak typeof(self) weakSelf = self;
[self.judoKit invokeTransactionWithType:JPTransactionTypeSaveCard
configuration:self.configuration
completion:^(JPResponse *response, JPError *error) {
[weakSelf handleResponse:response error:error showReceipt:false];
[weakSelf fillInFieldsFromResponse:response];
}];
[weakSelf handleResponse:response error:error showReceipt:false];
[weakSelf fillInFieldsFromResponse:response];
}];
}

- (void)handleResponse:(JPResponse *)response error:(NSError *)error showReceipt:(BOOL)showReceipt {
Expand All @@ -130,7 +128,7 @@ - (void)handleResponse:(JPResponse *)response error:(NSError *)error showReceipt

- (void)fillInFieldsFromResponse:(JPResponse *)response {
JPCardDetails *cardDetails = response.cardDetails;

if (cardDetails) {
self.cardNetworkTextField.text = [NSString stringWithFormat:@"%@", cardDetails.rawCardNetwork];
self.cardTokenTextField.text = cardDetails.cardToken;
Expand All @@ -140,44 +138,44 @@ - (void)fillInFieldsFromResponse:(JPResponse *)response {

- (IBAction)payWithCardToken:(UIButton *)sender {
[self.payWithCardTokenButton startLoading];

__weak typeof(self) weakSelf = self;

[self.transactionService invokeTokenPaymentWithDetails:self.cardTransactionDetails
andCompletion:^(JPResponse *response, JPError *error) {
[weakSelf handleResponse:response error:error showReceipt:true];
[weakSelf.payWithCardTokenButton stopLoading];
}];
[weakSelf handleResponse:response error:error showReceipt:true];
[weakSelf.payWithCardTokenButton stopLoading];
}];
}

- (IBAction)preAuthWithCardToken:(UIButton *)sender {
[self.preAuthWithCardTokenButton startLoading];

__weak typeof(self) weakSelf = self;

[self.transactionService invokePreAuthTokenPaymentWithDetails:self.cardTransactionDetails
andCompletion:^(JPResponse *response, JPError *error) {
[weakSelf handleResponse:response error:error showReceipt:true];
[weakSelf.preAuthWithCardTokenButton stopLoading];
}];
[weakSelf handleResponse:response error:error showReceipt:true];
[weakSelf.preAuthWithCardTokenButton stopLoading];
}];
}

- (JPCardTransactionDetails *)cardTransactionDetails {
self.configuration.reference = Settings.defaultSettings.reference;

JPCardTransactionDetails *details = [JPCardTransactionDetails detailsWithConfiguration:self.configuration];

NSString *secureCode = nil;

if (self.cardSecurityCodeTextField.text.length > 0) {
secureCode = self.cardSecurityCodeTextField.text;
}

details.cardToken = self.cardTokenTextField.text;
details.cardType = @(self.cardNetworkTextField.text.integerValue)._jp_toCardNetworkType;
details.secureCode = secureCode;
details.cardholderName = self.cardholderNameTextField.text;

return details;
}

Expand All @@ -192,7 +190,7 @@ - (JPCardTransactionService *)transactionService {
isSandboxed:Settings.defaultSettings.isSandboxed
andConfiguration:self.configuration];
}
return _transactionService;
return _transactionService;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ - (NSSet *)computeHiddenKeysWithPriority:(NSArray *)keys {
kAddressTownKey,
kAddressPostCodeKey,
kAddressCountryCodeKey,
kAddressStateKey,
kAddressPhoneCountryCodeKey,
kAddressMobileNumberKey,
kAddressEmailAddressKey,
Expand Down Expand Up @@ -72,6 +73,7 @@ - (NSSet *)computeHiddenKeysWithPriority:(NSArray *)keys {
kAddressTownKey,
kAddressPostCodeKey,
kAddressCountryCodeKey,
kAddressStateKey,
kAddressPhoneCountryCodeKey,
kAddressMobileNumberKey,
kAddressEmailAddressKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ - (void)presentTextFieldAlertControllerWithTitle:(NSString *)title
negativeButtonTitle:(NSString *)negativeButton
textFieldPlaceholder:(NSString *)placeholder
andCompletion:(void (^)(NSString *text))completion {

__block UITextField *textField = [UITextField new];
UIAlertController *controller = [UIAlertController alertControllerWithTitle:title
message:message
Expand All @@ -28,14 +28,14 @@ - (void)presentTextFieldAlertControllerWithTitle:(NSString *)title
UIAlertAction *buttonOk = [UIAlertAction actionWithTitle:positiveButton
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
completion(textField.text);
}];
completion(textField.text);
}];

UIAlertAction *buttonCancel = [UIAlertAction actionWithTitle:negativeButton
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action) {
completion(nil);
}];
completion(nil);
}];

[controller addTextFieldWithConfigurationHandler:^(UITextField *aTextField) {
textField = aTextField;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ static NSString *const kAddressLine3Key = @"address_line_3";
static NSString *const kAddressTownKey = @"address_town";
static NSString *const kAddressPostCodeKey = @"address_post_code";
static NSString *const kAddressCountryCodeKey = @"address_country_code";
static NSString *const kAddressStateKey = @"address_state";
static NSString *const kAddressPhoneCountryCodeKey = @"address_phone_country_code";
static NSString *const kAddressMobileNumberKey = @"address_mobile_number";
static NSString *const kAddressEmailAddressKey = @"address_email_address";
Expand Down
Loading

0 comments on commit 27c2dd3

Please sign in to comment.