From 998f861ff46778c02ba83662b03061be424611ad Mon Sep 17 00:00:00 2001 From: Budnikov Vyacheslav Date: Fri, 20 Mar 2020 17:04:17 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=D0=B0=D1=87?= =?UTF-8?q?=D0=B0=20=D0=BE=D0=B1=D1=8F=D0=B7=D0=B0=D1=82=D0=B5=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BC=D0=B5?= =?UTF-8?q?=D1=82=D1=80=D0=B0=20ip=20=D0=B4=D0=BB=D1=8F=203DSv2=20=D0=B4?= =?UTF-8?q?=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA=D0=B0=20FallbackOnTd?= =?UTF-8?q?sV1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ASDKFinishAuthorizeRequest.h | 4 +- .../ASDKFinishAuthorizeRequest.m | 2 + ASDKCore/ASDKAcquiringApi.m | 1 + ASDKCore/ASDKAcquiringSdk.h | 1 + ASDKCore/ASDKAcquiringSdk.m | 4 +- ASDKCore/RequestBuilder/ASDKRequestBuilder.m | 9 +-- .../ASDKFinishAuthorizeRequestBuilder.h | 3 +- .../ASDKFinishAuthorizeRequestBuilder.m | 11 ++- ASDKUI/Helpers/ASDKUtils.h | 3 + ASDKUI/Helpers/ASDKUtils.m | 79 +++++++++++++++++++ .../ASDKPaymentFormStarter.m | 2 + .../ASDKPaymentFormViewController.m | 11 +-- 12 files changed, 113 insertions(+), 17 deletions(-) diff --git a/ASDKCore/API Objects/Request/FinishAuthorize/ASDKFinishAuthorizeRequest.h b/ASDKCore/API Objects/Request/FinishAuthorize/ASDKFinishAuthorizeRequest.h index 587a26b..f7d6a74 100644 --- a/ASDKCore/API Objects/Request/FinishAuthorize/ASDKFinishAuthorizeRequest.h +++ b/ASDKCore/API Objects/Request/FinishAuthorize/ASDKFinishAuthorizeRequest.h @@ -28,6 +28,7 @@ @property (nonatomic, copy) NSString *infoEmail; @property (nonatomic, copy) NSString *encryptedPaymentData; @property (nonatomic, strong) NSDictionary *data; +@property (nonatomic, copy) NSString *ipAddress; - (ASDKFinishAuthorizeRequest *)initWithTerminalKey:(NSString *)terminalKey paymentId:(NSString *)paymentId @@ -36,6 +37,7 @@ infoEmail:(NSString *)infoEmail token:(NSString *)token encryptedPaymentData:(NSString *)encryptedPaymentData - data:(NSDictionary *)data; + data:(NSDictionary *)data + ip:(NSString * )ipAddress; @end diff --git a/ASDKCore/API Objects/Request/FinishAuthorize/ASDKFinishAuthorizeRequest.m b/ASDKCore/API Objects/Request/FinishAuthorize/ASDKFinishAuthorizeRequest.m index a313349..6ece394 100644 --- a/ASDKCore/API Objects/Request/FinishAuthorize/ASDKFinishAuthorizeRequest.m +++ b/ASDKCore/API Objects/Request/FinishAuthorize/ASDKFinishAuthorizeRequest.m @@ -30,6 +30,7 @@ - (ASDKFinishAuthorizeRequest *)initWithTerminalKey:(NSString *)terminalKey token:(NSString *)token encryptedPaymentData:(NSString *)encryptedPaymentData data:(NSDictionary *)data + ip:(NSString * )ipAddress { ASDKFinishAuthorizeRequest *request = [[ASDKFinishAuthorizeRequest alloc] init]; @@ -43,6 +44,7 @@ - (ASDKFinishAuthorizeRequest *)initWithTerminalKey:(NSString *)terminalKey request.token = token; request.encryptedPaymentData = encryptedPaymentData; request.data = data; + request.ipAddress = ipAddress; } return request; diff --git a/ASDKCore/ASDKAcquiringApi.m b/ASDKCore/ASDKAcquiringApi.m index e65322d..64e8a96 100644 --- a/ASDKCore/ASDKAcquiringApi.m +++ b/ASDKCore/ASDKAcquiringApi.m @@ -321,6 +321,7 @@ - (void)finishAuthorizeWithRequest:(ASDKFinishAuthorizeRequest *)request } if (request.data) { [parameters setObject:request.data forKey:kASDKDATA]; } + if (request.ipAddress) { [parameters setObject:request.ipAddress forKey:@"IP"]; } [self apiVersion:APIVersion_v2 path:kASDKAPIPathFinishAuthorize parameters:parameters success:^(NSDictionary *responseDictionary, NSURLResponse *response) diff --git a/ASDKCore/ASDKAcquiringSdk.h b/ASDKCore/ASDKAcquiringSdk.h index 1a8206d..13a7f6c 100644 --- a/ASDKCore/ASDKAcquiringSdk.h +++ b/ASDKCore/ASDKAcquiringSdk.h @@ -92,6 +92,7 @@ cardData:(NSString *)cardData infoEmail:(NSString *)infoEmail data:(NSDictionary *)data + ip:(NSString * )ipAddress success:(void (^)(ASDKThreeDsData *data, ASDKPaymentInfo *paymentInfo, ASDKPaymentStatus status))success failure:(void (^)(ASDKAcquringSdkError *error))failure; diff --git a/ASDKCore/ASDKAcquiringSdk.m b/ASDKCore/ASDKAcquiringSdk.m index de77ed0..54a6953 100644 --- a/ASDKCore/ASDKAcquiringSdk.m +++ b/ASDKCore/ASDKAcquiringSdk.m @@ -191,6 +191,7 @@ - (void)finishAuthorizeWithPaymentId:(NSString *)paymentId cardData:(NSString *)cardData infoEmail:(NSString *)infoEmail data:(NSDictionary *)data + ip:(NSString * )ipAddress success:(void (^)(ASDKThreeDsData *data, ASDKPaymentInfo *paymentInfo, ASDKPaymentStatus status))success failure:(void (^)(ASDKAcquringSdkError *error))failure { @@ -202,7 +203,8 @@ - (void)finishAuthorizeWithPaymentId:(NSString *)paymentId terminalKey:self.terminalKey password:self.password encryptedPaymentData:encryptedPaymentData - data:data]; + data:data + ip:ipAddress]; ASDKFinishAuthorizeRequest *request = (ASDKFinishAuthorizeRequest *)[builder buildError:&buildError]; diff --git a/ASDKCore/RequestBuilder/ASDKRequestBuilder.m b/ASDKCore/RequestBuilder/ASDKRequestBuilder.m index 1157cbc..999e26f 100644 --- a/ASDKCore/RequestBuilder/ASDKRequestBuilder.m +++ b/ASDKCore/RequestBuilder/ASDKRequestBuilder.m @@ -35,7 +35,6 @@ - (instancetype)initWithTerminalKey:(NSString *)terminalKey - (ASDKAcquiringRequest *)buildError:(ASDKAcquringSdkError **)error { - //implement in subclasses return nil; } @@ -50,7 +49,7 @@ - (NSString *)makeToken - (NSString *)makeTokenWithParameters:(NSDictionary *)parameters { - NSArray *keys = [[parameters allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]; + NSArray *keys = [[parameters allKeys] sortedArrayUsingSelector:@selector(compare:)]; NSMutableString *tokenString = [NSMutableString string]; for (NSString *key in keys) { @@ -61,8 +60,6 @@ - (NSString *)makeTokenWithParameters:(NSDictionary *)parameters if ([parameterValue isKindOfClass:[NSDictionary class]] || [parameterValue isKindOfClass:[NSArray class]]) { parameterValue = @""; - //NSData *data = [NSKeyedArchiver archivedDataWithRootObject:parameterValue]; - //parameterValue = [NSString stringWithFormat:@"%@", data]; } else { @@ -72,9 +69,7 @@ - (NSString *)makeTokenWithParameters:(NSDictionary *)parameters [tokenString appendString:parameterValue]; } - -// NSLog(@"%@",tokenString); - + NSString *encodedTokenString = [ASDKCryptoUtils sha256:tokenString]; return encodedTokenString; diff --git a/ASDKCore/RequestBuilder/FinishAuthorize/ASDKFinishAuthorizeRequestBuilder.h b/ASDKCore/RequestBuilder/FinishAuthorize/ASDKFinishAuthorizeRequestBuilder.h index ea2639b..368783a 100644 --- a/ASDKCore/RequestBuilder/FinishAuthorize/ASDKFinishAuthorizeRequestBuilder.h +++ b/ASDKCore/RequestBuilder/FinishAuthorize/ASDKFinishAuthorizeRequestBuilder.h @@ -28,6 +28,7 @@ terminalKey:(NSString *)terminalKey password:(NSString *)password encryptedPaymentData:(NSString *)encryptedPaymentData - data:(NSDictionary *)data; + data:(NSDictionary *)data + ip:(NSString * )ipAddress; @end diff --git a/ASDKCore/RequestBuilder/FinishAuthorize/ASDKFinishAuthorizeRequestBuilder.m b/ASDKCore/RequestBuilder/FinishAuthorize/ASDKFinishAuthorizeRequestBuilder.m index c67c77f..115f2c0 100644 --- a/ASDKCore/RequestBuilder/FinishAuthorize/ASDKFinishAuthorizeRequestBuilder.m +++ b/ASDKCore/RequestBuilder/FinishAuthorize/ASDKFinishAuthorizeRequestBuilder.m @@ -26,6 +26,7 @@ @interface ASDKFinishAuthorizeRequestBuilder () @property (nonatomic, copy) NSString *infoEmail; @property (nonatomic, copy) NSString *encryptedPaymentData; @property (nonatomic, strong) NSDictionary *data; +@property (nonatomic, copy) NSString *ipAddress; @end @@ -38,6 +39,7 @@ + (ASDKFinishAuthorizeRequestBuilder *)builderWithPaymentId:(NSString *)paymentI password:(NSString *)password encryptedPaymentData:(NSString *)encryptedPaymentData data:(NSDictionary *)data + ip:(NSString * )ipAddress { ASDKFinishAuthorizeRequestBuilder *builder = [[ASDKFinishAuthorizeRequestBuilder alloc] init]; @@ -51,6 +53,7 @@ + (ASDKFinishAuthorizeRequestBuilder *)builderWithPaymentId:(NSString *)paymentI builder.password = password; builder.encryptedPaymentData = encryptedPaymentData; builder.data = data; + builder.ipAddress = ipAddress; } return builder; @@ -83,7 +86,8 @@ - (ASDKFinishAuthorizeRequest *)buildError:(ASDKAcquringSdkError **)error infoEmail:self.infoEmail token:token encryptedPaymentData:self.encryptedPaymentData - data:self.data]; + data:self.data + ip:self.ipAddress]; return request; } @@ -131,7 +135,6 @@ - (NSDictionary *)parametersForToken { [parameters setObject:self.paymentId forKey:kASDKPaymentId]; } - if (self.cardData.length > 0) { [parameters setObject:self.cardData forKey:kASDKCardData]; @@ -144,6 +147,10 @@ - (NSDictionary *)parametersForToken { [parameters setObject:self.encryptedPaymentData forKey:@"EncryptedPaymentData"]; } + if (self.ipAddress.length > 0) + { + [parameters setObject:self.ipAddress forKey:@"IP"]; + } return parameters; } diff --git a/ASDKUI/Helpers/ASDKUtils.h b/ASDKUI/Helpers/ASDKUtils.h index 0f4f1a2..33709a0 100644 --- a/ASDKUI/Helpers/ASDKUtils.h +++ b/ASDKUI/Helpers/ASDKUtils.h @@ -26,4 +26,7 @@ + (UIColor *)colorWithInteger:(NSInteger)rgbValue alpha:(CGFloat)alpha; + (UIColor *)colorWithInteger:(NSInteger)rgbValue; + (UIColor *)colorWithIntegerShadeOfGrey:(NSInteger)greyHex; + ++ (NSString *)getIPAddress; + @end diff --git a/ASDKUI/Helpers/ASDKUtils.m b/ASDKUI/Helpers/ASDKUtils.m index 92a91a1..32334e8 100644 --- a/ASDKUI/Helpers/ASDKUtils.m +++ b/ASDKUI/Helpers/ASDKUtils.m @@ -18,6 +18,15 @@ #import "ASDKUtils.h" +#include +#include +#include + +#define IOS_CELLULAR @"pdp_ip0" +#define IOS_WIFI @"en0" +#define IP_ADDR_IPv4 @"ipv4" +#define IP_ADDR_IPv6 @"ipv6" + @implementation ASDKUtils + (UIImage *)imageFromColor:(UIColor *)color @@ -48,4 +57,74 @@ + (UIColor *)colorWithIntegerShadeOfGrey:(NSInteger)greyHex { return [UIColor colorWithWhite:greyHex/255.f alpha:1.f]; } ++ (NSString *)getIPAddress +{ + NSDictionary *dict = [self getIPAddresses]; + + if ([dict objectForKey:@"en0/ipv4"]) + { + return [dict objectForKey:@"en0/ipv4"]; + } + else if ([dict objectForKey:@"en1/ipv4"]) + { + return [dict objectForKey:@"en1/ipv4"]; + } + else + { + return dict.allValues.firstObject; + } + + return nil; +} + ++ (NSDictionary *)getIPAddresses +{ + NSMutableDictionary *addresses = [NSMutableDictionary dictionaryWithCapacity:8]; + struct ifaddrs *interfaces; + if (!getifaddrs(&interfaces)) + { + struct ifaddrs *interface; + for (interface=interfaces; interface; interface=interface->ifa_next) + { + if (!(interface->ifa_flags & IFF_UP)) + { + continue; + } + + const struct sockaddr_in *addr = (const struct sockaddr_in*)interface->ifa_addr; + char addrBuf[ MAX(INET_ADDRSTRLEN, INET6_ADDRSTRLEN) ]; + if (addr && (addr->sin_family==AF_INET || addr->sin_family==AF_INET6)) + { + NSString *name = [NSString stringWithUTF8String:interface->ifa_name]; + NSString *type; + if (addr->sin_family == AF_INET) + { + if (inet_ntop(AF_INET, &addr->sin_addr, addrBuf, INET_ADDRSTRLEN)) + { + type = IP_ADDR_IPv4; + } + } + else + { + const struct sockaddr_in6 *addr6 = (const struct sockaddr_in6*)interface->ifa_addr; + if (inet_ntop(AF_INET6, &addr6->sin6_addr, addrBuf, INET6_ADDRSTRLEN)) + { + type = IP_ADDR_IPv6; + } + } + + if (type) + { + NSString *key = [NSString stringWithFormat:@"%@/%@", name, type]; + addresses[key] = [NSString stringWithUTF8String:addrBuf]; + } + } + } + + freeifaddrs(interfaces); + } + + return [addresses count] ? addresses : nil; +} + @end diff --git a/ASDKUI/Payment/PaymentFormStarter/ASDKPaymentFormStarter.m b/ASDKUI/Payment/PaymentFormStarter/ASDKPaymentFormStarter.m index 78f5915..ba814c5 100644 --- a/ASDKUI/Payment/PaymentFormStarter/ASDKPaymentFormStarter.m +++ b/ASDKUI/Payment/PaymentFormStarter/ASDKPaymentFormStarter.m @@ -609,6 +609,7 @@ - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController cardData:nil infoEmail:payment.billingContact.emailAddress data:nil + ip:nil success:^(ASDKThreeDsData *data, ASDKPaymentInfo *paymentInfo, ASDKPaymentStatus status) { self.onCompleteSuccessPaymentInfo = paymentInfo; self.onCompleteStatus = status; @@ -637,6 +638,7 @@ - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController cardData:nil infoEmail:payment.billingContact.emailAddress data:nil + ip:nil success:^(ASDKThreeDsData *data, ASDKPaymentInfo *paymentInfo, ASDKPaymentStatus status) { self.onCompleteSuccessPaymentInfo = paymentInfo; self.onCompleteStatus = status; diff --git a/ASDKUI/Payment/PaymentViewController/ASDKPaymentFormViewController.m b/ASDKUI/Payment/PaymentViewController/ASDKPaymentFormViewController.m index fadeb82..8d0840d 100644 --- a/ASDKUI/Payment/PaymentViewController/ASDKPaymentFormViewController.m +++ b/ASDKUI/Payment/PaymentViewController/ASDKPaymentFormViewController.m @@ -1119,11 +1119,11 @@ - (NSDictionary *)threeDSMethodCheckURL:(NSString *)threeDSMethodURL tdsServerTr return nil; } -- (void)performFinishAuthorize:(NSDictionary *)additionalData emailString:(NSString *)emailString encryptedCardString:(NSString *)encryptedCardString payment:(ASDKInitResponse *)payment threeDSVersion:(NSString *)threeDSVersion +- (void)performFinishAuthorize:(NSDictionary *)additionalData ip:(NSString *)ipAddress emailString:(NSString *)emailString encryptedCardString:(NSString *)encryptedCardString payment:(ASDKInitResponse *)payment threeDSVersion:(NSString *)threeDSVersion { __weak typeof(self) weakSelf = self; - [self.acquiringSdk finishAuthorizeWithPaymentId:payment.paymentId encryptedPaymentData:nil cardData:encryptedCardString infoEmail:emailString data:additionalData success:^(ASDKThreeDsData *data, ASDKPaymentInfo *paymentInfo, ASDKPaymentStatus status) { + [self.acquiringSdk finishAuthorizeWithPaymentId:payment.paymentId encryptedPaymentData:nil cardData:encryptedCardString infoEmail:emailString data:additionalData ip:ipAddress success:^(ASDKThreeDsData *data, ASDKPaymentInfo *paymentInfo, ASDKPaymentStatus status) { __strong typeof(weakSelf) strongSelf = weakSelf; [[NSNotificationCenter defaultCenter] postNotificationName:ASDKNotificationHideLoader object:nil]; @@ -1194,7 +1194,8 @@ - (void)performFinishAuthorizeRequestWithPaymentId:(ASDKInitResponse *)payment [self.acquiringSdk check3dsVersionWithPaymentId:payment.paymentId cardData:encryptedCardString success:^(ASDKResponseCheck3dsVersion *response) { __strong typeof(weakSelf) strongSelf = weakSelf; NSDictionary *additionalData = [strongSelf threeDSMethodCheckURL:[response threeDSMethodURL] tdsServerTransID:[response tdsServerTransID]]; - [strongSelf performFinishAuthorize:additionalData emailString:emailString encryptedCardString:encryptedCardString payment:payment threeDSVersion:[response threeDSVersion]]; + NSString *ipAddress = ASDKUtils.getIPAddress; + [strongSelf performFinishAuthorize:additionalData ip:ipAddress emailString:emailString encryptedCardString:encryptedCardString payment:payment threeDSVersion:[response threeDSVersion]]; } failure: ^(ASDKAcquringSdkError *error) { [[NSNotificationCenter defaultCenter] postNotificationName:ASDKNotificationHideLoader object:nil]; __strong typeof(weakSelf) strongSelf = weakSelf; @@ -1206,7 +1207,7 @@ - (void)performFinishAuthorizeRequestWithPaymentId:(ASDKInitResponse *)payment } else { - [self performFinishAuthorize:nil emailString:emailString encryptedCardString:encryptedCardString payment:payment threeDSVersion:nil]; + [self performFinishAuthorize:nil ip:nil emailString:emailString encryptedCardString:encryptedCardString payment:payment threeDSVersion:nil]; } } } @@ -1245,7 +1246,7 @@ - (void)manageSuccessWithPaymentInfo:(ASDKPaymentInfo *)paymentInfo if (!self.selectedCard) { [[ASDKCardsListDataController instance] updateCardsListWithSuccessBlock:^{ paymentSuccessBlock(); } - errorBlock:^(ASDKAcquringSdkError *error) { paymentSuccessBlock(); } ]; + errorBlock:^(ASDKAcquringSdkError *error) { paymentSuccessBlock(); } ]; } else {