Skip to content

Commit

Permalink
Merge branch 'develop_1.1.2’
Browse files Browse the repository at this point in the history
в метод "Init" добавлен параметр NSDictionary *additionalPaymentData
Правила заполнения параметра: обязательным является наличие параметра Email. Прочие можно добавлять по желанию. Данные параметры будут переданы на страницу оплаты (в случае ее кастомизации). Максимальная длина для каждого передаваемого параметра: Ключ – 20 знаков, Значение – 100 знаков. Максимальное количество пар «ключ-значение» не может превышать 20.
пример @{@"Email":@"[email protected]", @"Phone":@"+71234567890"}
  • Loading branch information
Budnikov Vyacheslav committed Dec 20, 2016
2 parents aa0b827 + f480e2d commit b09d568
Show file tree
Hide file tree
Showing 21 changed files with 145 additions and 22 deletions.
2 changes: 1 addition & 1 deletion ASDKCore.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Pod::Spec.new do |s|

s.name = "ASDKCore"
s.version = "1.1.1"
s.version = "1.1.2"
s.summary = "Core library that allows you to use internet acquiring from Tinkoff Bank in your app"
s.description = "Core library that allows you to use internet acquiring from Tinkoff Bank in your app!"

Expand Down
4 changes: 3 additions & 1 deletion ASDKCore/API Objects/Request/Init/ASDKInitRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
@property (nonatomic, copy) NSString *requestDescription;
@property (nonatomic, copy) NSString *payForm;
@property (nonatomic) BOOL recurrent;
@property (nonatomic, strong) NSString *additionalPaymentData;

- (ASDKInitRequest *)initWithTerminalKey:(NSString *)terminalKey
amount:(NSNumber *)amount
Expand All @@ -38,6 +39,7 @@
payForm:(NSString *)payForm
payType:(NSString *)payType
customerKey:(NSString *)customerKey
recurrent:(BOOL)recurrent;
recurrent:(BOOL)recurrent
additionalPaymentData:(NSString *)data;

@end
4 changes: 3 additions & 1 deletion ASDKCore/API Objects/Request/Init/ASDKInitRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ - (ASDKInitRequest *)initWithTerminalKey:(NSString *)terminalKey
payType:(NSString *)payType
customerKey:(NSString *)customerKey
recurrent:(BOOL)recurrent
additionalPaymentData:(NSString *)data
{
ASDKInitRequest *request = [[ASDKInitRequest alloc] init];

Expand All @@ -46,8 +47,9 @@ - (ASDKInitRequest *)initWithTerminalKey:(NSString *)terminalKey
request.payType = payType;
request.customerKey = customerKey;
request.recurrent = recurrent;
request.additionalPaymentData = data;
}

return request;
}

Expand Down
7 changes: 6 additions & 1 deletion ASDKCore/ASDKAcquiringApi.m
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,12 @@ - (void)initWithRequest:(ASDKInitRequest *)request
{
[parameters setObject:@"Y" forKey:kASDKRecurrent];
}


if (request.additionalPaymentData)
{
[parameters setObject:request.additionalPaymentData forKey:kASDKDATA];
}

[self path:kASDKAPIPathInit
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 @@ -63,6 +63,7 @@
payForm:(NSString *)payForm
customerKey:(NSString *)customerKey
recurrent:(BOOL)recurrent
additionalPaymentData:(NSDictionary *)data
success:(void (^)(ASDKInitResponse *response))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 @@ -99,6 +99,7 @@ - (void)initWithAmount:(NSNumber *)amount
payForm:(NSString *)payForm
customerKey:(NSString *)customerKey
recurrent:(BOOL)recurrent
additionalPaymentData:(NSDictionary *)data
success:(void (^)(ASDKInitResponse *response))success
failure:(void (^)(ASDKAcquringSdkError *error))failure
{
Expand All @@ -112,7 +113,8 @@ - (void)initWithAmount:(NSNumber *)amount
customerKey:customerKey
recurrent:recurrent
terminalKey:self.terminalKey
password:self.password];
password:self.password
additionalPaymentData:data];

ASDKInitRequest *request = (ASDKInitRequest *)[builder buildError:&buildError];

Expand Down
2 changes: 1 addition & 1 deletion ASDKCore/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.1.1</string>
<string>1.1.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
15 changes: 12 additions & 3 deletions ASDKCore/RequestBuilder/ASDKRequestBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,18 @@ - (NSString *)makeTokenWithParameters:(NSDictionary *)parameters

if (![parameterValue isKindOfClass:[NSString class]])
{
parameterValue = [parameterValue stringValue];
}

if ([parameterValue isKindOfClass:[NSDictionary class]] || [parameterValue isKindOfClass:[NSArray class]])
{
parameterValue = @"";
//NSData *data = [NSKeyedArchiver archivedDataWithRootObject:parameterValue];
//parameterValue = [NSString stringWithFormat:@"%@", data];
}
else
{
parameterValue = [NSString stringWithFormat:@"%@", parameterValue];
}
}

[tokenString appendString:parameterValue];
}

Expand Down
3 changes: 2 additions & 1 deletion ASDKCore/RequestBuilder/Init/ASDKInitRequestBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
customerKey:(NSString *)customerKey
recurrent:(BOOL)recurrent
terminalKey:(NSString *)terminalKey
password:(NSString *)password;
password:(NSString *)password
additionalPaymentData:(NSDictionary *)data;

@end
90 changes: 86 additions & 4 deletions ASDKCore/RequestBuilder/Init/ASDKInitRequestBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ @interface ASDKInitRequestBuilder ()
@property (nonatomic, copy) NSString *payForm;
@property (nonatomic, copy) NSString *payType;
@property (nonatomic) BOOL recurrent;
@property (nonatomic, strong) NSString *additionalPaymentData;
@property (nonatomic, strong) NSDictionary *additionalPaymentData_;


@end

Expand All @@ -41,6 +44,7 @@ + (ASDKInitRequestBuilder *)builderWithAmount:(NSNumber *)amount
recurrent:(BOOL)recurrent
terminalKey:(NSString *)terminalKey
password:(NSString *)password
additionalPaymentData:(NSDictionary *)data
{
ASDKInitRequestBuilder *builder = [[ASDKInitRequestBuilder alloc] init];

Expand All @@ -55,8 +59,10 @@ + (ASDKInitRequestBuilder *)builderWithAmount:(NSNumber *)amount
builder.recurrent = recurrent;
builder.terminalKey = terminalKey;
builder.password = password;
builder.additionalPaymentData_ = data;
builder.additionalPaymentData = nil;
}

return builder;
}

Expand All @@ -83,8 +89,9 @@ - (ASDKAcquiringRequest *)buildError:(ASDKAcquringSdkError **)error
payForm:self.payForm
payType:self.payType
customerKey:self.customerKey
recurrent:self.recurrent];

recurrent:self.recurrent
additionalPaymentData:self.additionalPaymentData];

return request;
}

Expand Down Expand Up @@ -163,6 +170,41 @@ - (void)validateError:(ASDKAcquringSdkError **)error

return;
}

if ([self.additionalPaymentData_ count] > 0)
{
if ([self.additionalPaymentData_ objectForKey:@"Email"] == nil)
{
validationError = [ASDKAcquringSdkError errorWithMessage:kASDKDATA details:@"Обязательным является наличие дополнительного параметра Email" code:0];

[(ASDKAcquringSdkError *)validationError setIsSdkError:NO];

*error = validationError;

return;
}

BOOL invalidAdditionalPaymentData = NO;
if ([[self.additionalPaymentData_ allKeys] count] > 20)
{
invalidAdditionalPaymentData = YES;
}
else for (NSString *key in [self.additionalPaymentData_ allKeys])
{
if ([key length] > 20 || [[self.additionalPaymentData_ objectForKey:key] length] > 100)
{
invalidAdditionalPaymentData = YES;
break;
}
}

if (invalidAdditionalPaymentData == YES)
{
validationError = [ASDKAcquringSdkError errorWithMessage:kASDKDATA details:@"Ключ – 20 знаков, Значение – 100 знаков. Максимальное количество пар «ключ-значение» не может превышать 20." code:0];
[(ASDKAcquringSdkError *)validationError setIsSdkError:NO];
*error = validationError;
}
}
}

- (NSDictionary *)parametersForToken
Expand Down Expand Up @@ -201,8 +243,48 @@ - (NSDictionary *)parametersForToken
{
[parameters setObject:@"Y" forKey:kASDKRecurrent];
}


if ([self.additionalPaymentData_ count] > 0)
{

NSUInteger i = 0;
NSUInteger count = [[self.additionalPaymentData_ allKeys] count] - 1;
NSMutableString *strPostBody = [[NSMutableString alloc] init];
for (NSString *key in [self.additionalPaymentData_ allKeys])
{
NSString *data = [NSString stringWithFormat:@"%@=%@%@", [self encodeURL:key], [self encodeURL:[[self.additionalPaymentData_ objectForKey:key] description]], (i < count ? @"|" : @"")];
[strPostBody appendString:data];
i++;
}

self.additionalPaymentData = strPostBody;

[parameters setObject:strPostBody forKey:kASDKDATA];
}

return parameters;
}

- (NSString *)encodeURL:(NSString *)string
{
// NSMutableCharacterSet * characterSet = [NSMutableCharacterSet URLQueryAllowedCharacterSet];
// NSString *newString = [string stringByAddingPercentEncodingWithAllowedCharacters:characterSet];

NSMutableCharacterSet * characterSet = [NSMutableCharacterSet characterSetWithCharactersInString:@":/?#[]@!$ &'()*+,;=\"<>%{}|\\^~`"];
[characterSet invert];
NSString *newString = [string stringByAddingPercentEncodingWithAllowedCharacters:characterSet];

// NSString *newString = (__bridge_transfer NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
// (__bridge CFStringRef)string,
// NULL,
// (CFStringRef)@":/?#[]@!$ &'()*+,;=\"<>%{}|\\^~`",
// CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding));
if (newString)
{
return newString;
}

return @"";
}

@end
2 changes: 1 addition & 1 deletion ASDKUI.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "ASDKUI"
s.version = "1.1.1"
s.version = "1.1.2"
s.summary = "UI components library for internet acquiring from Tinkoff Bank"
s.description = "UI components library for internet acquiring from Tinkoff Bank!"
s.homepage = "https://www.tinkoff.ru"
Expand Down
2 changes: 1 addition & 1 deletion ASDKUI/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.1.1</string>
<string>1.1.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
2 changes: 2 additions & 0 deletions ASDKUI/Payment/PaymentFormStarter/ASDKPaymentFormStarter.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
cardId:(NSString *)cardId
email:(NSString *)email
customerKey:(NSString *)customerKey
additionalPaymentData:(NSDictionary *)data
success:(void (^)(NSString *paymentId))onSuccess
cancelled:(void (^)())onCancelled
error:(void (^)(ASDKAcquringSdkError *error))onError;
Expand All @@ -83,6 +84,7 @@
appleMerchantId:(NSString *)appleMerchantId
shippingMethods:(NSArray<PKShippingMethod *> *)shippingMethods
shippingContact:(PKContact *)shippingContact
additionalPaymentData:(NSDictionary *)data
success:(void (^)(NSString *paymentId))onSuccess
cancelled:(void (^)())onCancelled
error:(void (^)(ASDKAcquringSdkError *error))onError;
Expand Down
5 changes: 4 additions & 1 deletion ASDKUI/Payment/PaymentFormStarter/ASDKPaymentFormStarter.m
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ - (void)presentPaymentFormFromViewController:(UIViewController *)presentingViewC
cardId:(NSString *)cardId
email:(NSString *)email
customerKey:(NSString *)customerKey
additionalPaymentData:(NSDictionary *)data
success:(void (^)(NSString *paymentId))onSuccess
cancelled:(void (^)())onCancelled
error:(void(^)(ASDKAcquringSdkError *error))onError
Expand All @@ -128,6 +129,7 @@ - (void)presentPaymentFormFromViewController:(UIViewController *)presentingViewC
cardId:cardId
email:email
customerKey:customerKey
additionalPaymentData:data
success:^(NSString *paymentId)
{
[ASDKPaymentFormStarter resetSharedInstance];
Expand Down Expand Up @@ -259,6 +261,7 @@ - (void)payWithApplePayFromViewController:(UIViewController *)presentingViewCont
appleMerchantId:(NSString *)appleMerchantId
shippingMethods:(NSArray<PKShippingMethod *> *)shippingMethods
shippingContact:(PKContact *)shippingContact
additionalPaymentData:(NSDictionary *)data
success:(void (^)(NSString *paymentId))onSuccess
cancelled:(void (^)())onCancelled
error:(void (^)(ASDKAcquringSdkError *error))onError
Expand All @@ -268,7 +271,7 @@ - (void)payWithApplePayFromViewController:(UIViewController *)presentingViewCont
self.onError = onError;
self.onCancelled = onCancelled;

[self.acquiringSdk initWithAmount:[NSNumber numberWithDouble:100 * amount.doubleValue] orderId:orderId description:nil payForm:nil customerKey:customerKey recurrent:NO
[self.acquiringSdk initWithAmount:[NSNumber numberWithDouble:100 * amount.doubleValue] orderId:orderId description:nil payForm:nil customerKey:customerKey recurrent:NO additionalPaymentData:data
success:^(ASDKInitResponse *response){
self.paymentIdForApplePay = response.paymentId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
cardId:(NSString *)cardId
email:(NSString *)email
customerKey:(NSString *)customerKey
additionalPaymentData:(NSDictionary *)data
success:(void (^)(NSString *paymentId))success
cancelled:(void (^)())cancelled
error:(void(^)(ASDKAcquringSdkError *error))error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ @interface ASDKPaymentFormViewController () <UITextFieldDelegate, ASDKCardsListD
@property (nonatomic, strong) void (^onError)(ASDKAcquringSdkError *error);

@property (nonatomic, strong) ASDKCard *selectedCard;
@property (nonatomic, strong) NSDictionary *additionalPaymentData;

@end

Expand All @@ -105,7 +106,8 @@ - (instancetype)initWithAmount:(NSNumber *)amount
description:(NSString *)description
cardId:(NSString *)cardId
email:(NSString *)email
customerKey:(NSString *)customerKey
customerKey:(NSString *)customerKey
additionalPaymentData:(NSDictionary *)data
success:(void (^)(NSString *paymentId))success
cancelled:(void (^)())cancelled
error:(void(^)(ASDKAcquringSdkError *error))error
Expand All @@ -124,6 +126,7 @@ - (instancetype)initWithAmount:(NSNumber *)amount
_onCancelled = cancelled;
_onError = error;
_customerKey = customerKey;
_additionalPaymentData = data;
}

return self;
Expand Down Expand Up @@ -622,7 +625,8 @@ - (void)performInitRequest
description:nil
payForm:nil
customerKey:_customerKey
recurrent:NO
recurrent:NO
additionalPaymentData:_additionalPaymentData
success:^(ASDKInitResponse *response)
{
__strong typeof(weakSelf) strongSelf = weakSelf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ - (void)buyItem
[PayController buyItemWithName:self.item.title
description:self.item.bookDescription
amount:self.item.cost
additionalPaymentData:@{@"Email":@"[email protected]", @"Phone":@"+71234567890"}
fromViewController:self
success:^(NSString *paymentId)
{
Expand Down Expand Up @@ -194,6 +195,7 @@ - (IBAction)buttonActionApplePay:(UIButton *)sender
appleMerchantId:@"merchant.tcsbank.ApplePayTestMerchantId"
shippingMethods:nil//@[[PKShippingMethod summaryItemWithLabel:@"Доставка" amount:[NSDecimalNumber decimalNumberWithString:@"300"]]]
shippingContact:shippingContact
additionalPaymentData:nil
fromViewController:self
success:^(NSString *paymentId) { NSLog(@"%@", paymentId); }
cancelled:^{ NSLog(@"Canceled"); }
Expand Down
Loading

0 comments on commit b09d568

Please sign in to comment.