Skip to content

Commit

Permalink
передача обязательного параметра ip для 3DSv2
Browse files Browse the repository at this point in the history
доработка FallbackOnTdsV1
  • Loading branch information
Budnikov Vyacheslav committed Mar 20, 2020
1 parent 7e2746d commit 998f861
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,6 +37,7 @@
infoEmail:(NSString *)infoEmail
token:(NSString *)token
encryptedPaymentData:(NSString *)encryptedPaymentData
data:(NSDictionary *)data;
data:(NSDictionary *)data
ip:(NSString * )ipAddress;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand All @@ -43,6 +44,7 @@ - (ASDKFinishAuthorizeRequest *)initWithTerminalKey:(NSString *)terminalKey
request.token = token;
request.encryptedPaymentData = encryptedPaymentData;
request.data = data;
request.ipAddress = ipAddress;
}

return request;
Expand Down
1 change: 1 addition & 0 deletions ASDKCore/ASDKAcquiringApi.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions ASDKCore/ASDKAcquiringSdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 3 additions & 1 deletion ASDKCore/ASDKAcquiringSdk.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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];

Expand Down
9 changes: 2 additions & 7 deletions ASDKCore/RequestBuilder/ASDKRequestBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ - (instancetype)initWithTerminalKey:(NSString *)terminalKey

- (ASDKAcquiringRequest *)buildError:(ASDKAcquringSdkError **)error
{
//implement in subclasses
return nil;
}

Expand All @@ -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)
{
Expand All @@ -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
{
Expand All @@ -72,9 +69,7 @@ - (NSString *)makeTokenWithParameters:(NSDictionary *)parameters

[tokenString appendString:parameterValue];
}

// NSLog(@"%@",tokenString);


NSString *encodedTokenString = [ASDKCryptoUtils sha256:tokenString];

return encodedTokenString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
terminalKey:(NSString *)terminalKey
password:(NSString *)password
encryptedPaymentData:(NSString *)encryptedPaymentData
data:(NSDictionary *)data;
data:(NSDictionary *)data
ip:(NSString * )ipAddress;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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];

Expand All @@ -51,6 +53,7 @@ + (ASDKFinishAuthorizeRequestBuilder *)builderWithPaymentId:(NSString *)paymentI
builder.password = password;
builder.encryptedPaymentData = encryptedPaymentData;
builder.data = data;
builder.ipAddress = ipAddress;
}

return builder;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -131,7 +135,6 @@ - (NSDictionary *)parametersForToken
{
[parameters setObject:self.paymentId forKey:kASDKPaymentId];
}

if (self.cardData.length > 0)
{
[parameters setObject:self.cardData forKey:kASDKCardData];
Expand All @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions ASDKUI/Helpers/ASDKUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@
+ (UIColor *)colorWithInteger:(NSInteger)rgbValue alpha:(CGFloat)alpha;
+ (UIColor *)colorWithInteger:(NSInteger)rgbValue;
+ (UIColor *)colorWithIntegerShadeOfGrey:(NSInteger)greyHex;

+ (NSString *)getIPAddress;

@end
79 changes: 79 additions & 0 deletions ASDKUI/Helpers/ASDKUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@

#import "ASDKUtils.h"

#include <ifaddrs.h>
#include <arpa/inet.h>
#include <net/if.h>

#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
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions ASDKUI/Payment/PaymentFormStarter/ASDKPaymentFormStarter.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -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;
Expand All @@ -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];
}
}
}
Expand Down Expand Up @@ -1245,7 +1246,7 @@ - (void)manageSuccessWithPaymentInfo:(ASDKPaymentInfo *)paymentInfo
if (!self.selectedCard)
{
[[ASDKCardsListDataController instance] updateCardsListWithSuccessBlock:^{ paymentSuccessBlock(); }
errorBlock:^(ASDKAcquringSdkError *error) { paymentSuccessBlock(); } ];
errorBlock:^(ASDKAcquringSdkError *error) { paymentSuccessBlock(); } ];
}
else
{
Expand Down

0 comments on commit 998f861

Please sign in to comment.