Created
May 31, 2020 16:42
-
-
Save alpbak/b4d81412263d2065cd673efb2ded1fe2 to your computer and use it in GitHub Desktop.
PayTabs integration - Objective C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)handleCreditCard{ | |
NSLog(@"CREDIT CARD"); | |
AddressModel *addressModel; | |
for (AddressModel *am in [[[User sharedInstance]sharedUser]all_addresses]) { | |
if ([[am address_id] isEqualToString:_addressId]) { | |
addressModel = am; | |
} | |
} | |
NSBundle *bundle = [NSBundle bundleWithURL:[[NSBundle mainBundle] URLForResource:@"Resources" withExtension:@"bundle"]]; | |
NSString *shippingAddress = @"Address not found"; | |
NSString *shippingCity = @"City not found"; | |
NSString *shippingCountry = @"Country not found"; | |
NSString *shippingState = @"State not found"; | |
NSString *shippingZIPCode = @"ZIP not found"; | |
if ([addressModel address_1]) { | |
if ([addressModel address_1].length > 1) { | |
shippingAddress = [addressModel address_1]; | |
} | |
} | |
if ([addressModel zone]) { | |
if ([addressModel zone].length > 1) { | |
shippingCity = [addressModel zone]; | |
} | |
} | |
if ([addressModel iso_code_3]) { | |
if ([addressModel iso_code_3].length > 1) { | |
shippingCountry = [addressModel iso_code_3]; | |
} | |
} | |
if ([addressModel zone_id]) { | |
if ([addressModel zone_id].length > 1) { | |
shippingState = [addressModel zone_id]; | |
} | |
} | |
if ([addressModel zone_code]) { | |
if ([addressModel zone_code].length > 1) { | |
shippingZIPCode = [addressModel zone_code]; | |
} | |
} | |
NSString *lang = @"en"; | |
if ([[[LocalizationSystem sharedInstance] language] isEqualToString:@"AR"] || [[[LocalizationSystem sharedInstance] language] isEqualToString:@"ar-US"] || [[[LocalizationSystem sharedInstance] language] isEqualToString:@"ar_AE"]) { | |
lang = @"ar"; | |
} | |
PTFWInitialSetupViewController *view = [[PTFWInitialSetupViewController alloc] | |
initWithBundle:bundle | |
andWithViewFrame:self.view.frame | |
andWithAmount:_totalOrderAmount | |
andWithCustomerTitle:@"Test iOS App" | |
andWithCurrencyCode:@"AED" | |
andWithTaxAmount:0 | |
andWithSDKLanguage:lang | |
andWithShippingAddress:shippingAddress | |
andWithShippingCity:shippingCity | |
andWithShippingCountry:shippingCountry | |
andWithShippingState:shippingState | |
andWithShippingZIPCode:shippingZIPCode | |
andWithBillingAddress:shippingAddress | |
andWithBillingCity:shippingCity | |
andWithBillingCountry:shippingCountry | |
andWithBillingState:shippingState | |
andWithBillingZIPCode:shippingZIPCode | |
andWithOrderID:@"192837645" | |
andWithPhoneNumber:[[[User sharedInstance]sharedUser]telephone] | |
andWithCustomerEmail:@"test@testiosapp.com" | |
andIsTokenization:NO | |
andIsPreAuth:NO | |
andWithMerchantEmail:@"admin@testiosapp.com" | |
andWithMerchantSecretKey:@"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | |
andWithAssigneeCode:@"SDK" | |
andWithThemeColor:[UIColor colorWithHexString:@"#05A6D4"] | |
andIsThemeColorLight:YES]; | |
view.didReceiveBackButtonCallback = ^{ | |
NSLog(@"cc-didReceiveBackButtonCallback"); | |
UIViewController *rootViewController = [[[[UIApplication sharedApplication]delegate] window] rootViewController]; | |
[rootViewController dismissViewControllerAnimated:YES completion:nil]; | |
}; | |
view.didStartPreparePaymentPage = ^{ | |
// Start Prepare Payment Page | |
// Show loading indicator | |
NSLog(@"cc-didStartPreparePaymentPage"); | |
}; | |
view.didFinishPreparePaymentPage = ^{ | |
// Finish Prepare Payment Page | |
// Stop loading indicator | |
NSLog(@"cc-didFinishPreparePaymentPage"); | |
}; | |
view.didReceiveFinishTransactionCallback = ^(int responseCode, NSString * _Nonnull result, int transactionID, NSString * _Nonnull tokenizedCustomerEmail, NSString * _Nonnull tokenizedCustomerPassword, NSString * _Nonnull token, BOOL transactionState) { | |
NSLog(@"Response Code: %i", responseCode); | |
NSLog(@"Response Result: %@", result); | |
// In Case you are using tokenization | |
NSLog(@"Tokenization Cutomer Email: %@", tokenizedCustomerEmail); | |
NSLog(@"Tokenization Customer Password: %@", tokenizedCustomerPassword); | |
NSLog(@"TOkenization Token: %@", token); | |
UIViewController *rootViewController = [[[[UIApplication sharedApplication]delegate] window] rootViewController]; | |
[rootViewController dismissViewControllerAnimated:YES completion:nil]; | |
if (responseCode == 100) { | |
[self handleCardPaymentWithTransactionId:[NSString stringWithFormat:@"%d",transactionID] responseCode:[NSString stringWithFormat:@"%d",responseCode]]; | |
} | |
}; | |
//view.modalPresentationStyle = UIModalPresentationFullScreen; | |
[self presentViewController:view animated:true completion:nil]; | |
} | |
- (void)handleCardPaymentWithTransactionId:(NSString *)transactionId responseCode:(NSString *)responseCode{ | |
[self showWaitView]; | |
NSString *notes = @""; | |
NSString *couponCode = @""; | |
if (_orderNotes) { | |
notes = _orderNotes; | |
} | |
if (_eneterdCouponCode) { | |
couponCode = _eneterdCouponCode; | |
} | |
NSDictionary *params = @{ | |
@"addressId": _addressId, | |
@"comment": notes, | |
@"coupon": couponCode, | |
@"TRANSACTION_ID": transactionId, | |
@"RESPONSE_CODE": responseCode | |
}; | |
[[APIService shared]payCardDictionary:params completion:^(BOOL succeed, id _Nullable responseObject) { | |
if (succeed) { | |
//DO WHATEVER FOR SUCCESS | |
} | |
else{ | |
//DO WHATEVER FOR ERROR | |
} | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment