Skip to content

Commit

Permalink
fix warning
Browse files Browse the repository at this point in the history
Add sum NumberFormatter for amount fraction digits
  • Loading branch information
Budnikov Vyacheslav committed Nov 27, 2017
1 parent dfcd065 commit 57139f0
Show file tree
Hide file tree
Showing 17 changed files with 124 additions and 29 deletions.
8 changes: 8 additions & 0 deletions ASDKCore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
2C6E6BAA1F94CB0300B345B9 /* ASDKRequestSubmitRandomAmount.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C6E6BA81F94CB0300B345B9 /* ASDKRequestSubmitRandomAmount.m */; };
2C6E6BAD1F94CC2700B345B9 /* ASDKRequestBuilderSubmitRandomAmount.h in Headers */ = {isa = PBXBuildFile; fileRef = 2C6E6BAB1F94CC2700B345B9 /* ASDKRequestBuilderSubmitRandomAmount.h */; };
2C6E6BAE1F94CC2700B345B9 /* ASDKRequestBuilderSubmitRandomAmount.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C6E6BAC1F94CC2700B345B9 /* ASDKRequestBuilderSubmitRandomAmount.m */; };
2CFBF58E1FCBFD180060C87F /* ASDKUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 2CFBF58C1FCBFD180060C87F /* ASDKUtils.h */; };
2CFBF58F1FCBFD180060C87F /* ASDKUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 2CFBF58D1FCBFD180060C87F /* ASDKUtils.m */; };
83166ED71C63984E00533D85 /* ASDKCore.h in Headers */ = {isa = PBXBuildFile; fileRef = 83166ED61C63984E00533D85 /* ASDKCore.h */; settings = {ATTRIBUTES = (Public, ); }; };
83166F2F1C63988F00533D85 /* ASDKBaseObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 83166EE11C63988F00533D85 /* ASDKBaseObject.h */; settings = {ATTRIBUTES = (Public, ); }; };
83166F301C63988F00533D85 /* ASDKBaseObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 83166EE21C63988F00533D85 /* ASDKBaseObject.m */; };
Expand Down Expand Up @@ -150,6 +152,8 @@
2C6E6BA81F94CB0300B345B9 /* ASDKRequestSubmitRandomAmount.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ASDKRequestSubmitRandomAmount.m; sourceTree = "<group>"; };
2C6E6BAB1F94CC2700B345B9 /* ASDKRequestBuilderSubmitRandomAmount.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ASDKRequestBuilderSubmitRandomAmount.h; sourceTree = "<group>"; };
2C6E6BAC1F94CC2700B345B9 /* ASDKRequestBuilderSubmitRandomAmount.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ASDKRequestBuilderSubmitRandomAmount.m; sourceTree = "<group>"; };
2CFBF58C1FCBFD180060C87F /* ASDKUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ASDKUtils.h; sourceTree = "<group>"; };
2CFBF58D1FCBFD180060C87F /* ASDKUtils.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ASDKUtils.m; sourceTree = "<group>"; };
83166ED31C63984E00533D85 /* ASDKCore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ASDKCore.framework; sourceTree = BUILT_PRODUCTS_DIR; };
83166ED61C63984E00533D85 /* ASDKCore.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ASDKCore.h; sourceTree = "<group>"; };
83166ED81C63984E00533D85 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -264,6 +268,8 @@
946C39A21C64921A0036D1AF /* ASDKApiKeys.h */,
83166F151C63988F00533D85 /* CryptoUtils */,
83166F181C63988F00533D85 /* RequestBuilder */,
2CFBF58C1FCBFD180060C87F /* ASDKUtils.h */,
2CFBF58D1FCBFD180060C87F /* ASDKUtils.m */,
);
path = ASDKCore;
sourceTree = "<group>";
Expand Down Expand Up @@ -608,6 +614,7 @@
83166F411C63988F00533D85 /* ASDKAcquiringResponse.h in Headers */,
946C399E1C648F940036D1AF /* ASDKCardData.h in Headers */,
2C352DAB1E4B1707008215A5 /* ASDKCancelRequestBuilder.h in Headers */,
2CFBF58E1FCBFD180060C87F /* ASDKUtils.h in Headers */,
2C1C13451F8F6184002B636F /* ASDKRequestAttachCard.h in Headers */,
943FC86D1C6881650044C707 /* ASDKPaymentInfo.h in Headers */,
83166F4F1C63988F00533D85 /* ASDKAcquiringApi.h in Headers */,
Expand Down Expand Up @@ -761,6 +768,7 @@
83871B801C6CC5EF00D69603 /* ASDKStringKeyCreator.m in Sources */,
83166F501C63988F00533D85 /* ASDKAcquiringApi.m in Sources */,
83166F4A1C63988F00533D85 /* ASDKGetStateResponse.m in Sources */,
2CFBF58F1FCBFD180060C87F /* ASDKUtils.m in Sources */,
2C6E6BA01F949F9700B345B9 /* ASDKResponseGetAddCardState.m in Sources */,
2C1C134A1F8F8112002B636F /* ASDKResponseAddCardInit.m in Sources */,
83166F5D1C63988F00533D85 /* ASDKGetCardListRequestBuilder.m in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@interface ASDKRequestSubmitRandomAmount : ASDKAcquiringRequest

@property (nonatomic, copy) NSString *requestKey;
@property (nonatomic, strong) NSNumber *amount;
@property (nonatomic, strong) NSString *amount;

- (instancetype)initWithTerminalKey:(NSString *)terminalKey
token:(NSString *)token
Expand Down
3 changes: 2 additions & 1 deletion ASDKCore/API Objects/Request/ASDKRequestSubmitRandomAmount.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
//

#import "ASDKRequestSubmitRandomAmount.h"
#import "ASDKUtils.h"

@implementation ASDKRequestSubmitRandomAmount

Expand All @@ -30,7 +31,7 @@ - (instancetype)initWithTerminalKey:(NSString *)terminalKey
if (self = [super initWithTerminalKey:terminalKey token:token])
{
_requestKey = requestKey;
_amount = amount;
_amount = [ASDKUtils amountWholeDigits:amount.doubleValue];
}

return self;
Expand Down
4 changes: 2 additions & 2 deletions ASDKCore/API Objects/Request/Init/ASDKInitRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@interface ASDKInitRequest : ASDKAcquiringRequest

@property (nonatomic, copy) NSString *payType;
@property (nonatomic, strong) NSNumber *amount;
@property (nonatomic, strong) NSString *amount;
@property (nonatomic, copy) NSString *orderId;
@property (nonatomic, copy) NSString *customerKey;
@property (nonatomic, copy) NSString *requestDescription;
Expand All @@ -33,7 +33,7 @@
@property (nonatomic, strong) NSDictionary *receiptData;

- (ASDKInitRequest *)initWithTerminalKey:(NSString *)terminalKey
amount:(NSNumber *)amount
amount:(NSString *)amount
orderId:(NSString *)orderId
description:(NSString *)description
token:(NSString *)token
Expand Down
2 changes: 1 addition & 1 deletion ASDKCore/API Objects/Request/Init/ASDKInitRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@implementation ASDKInitRequest

- (ASDKInitRequest *)initWithTerminalKey:(NSString *)terminalKey
amount:(NSNumber *)amount
amount:(NSString *)amount
orderId:(NSString *)orderId
description:(NSString *)description
token:(NSString *)token
Expand Down
29 changes: 29 additions & 0 deletions ASDKCore/ASDKUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// ASDKUtils.h
// ASDKCore
//
// Created by v.budnikov on 27.11.2017.
// Copyright © 2017 Tinkoff Bank. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import <Foundation/Foundation.h>

extern NSString *const kSumDecimalSeparator;

@interface ASDKUtils : NSObject

+ (NSString *)amountWholeDigits:(double)amount;

@end
56 changes: 56 additions & 0 deletions ASDKCore/ASDKUtils.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// ASDKUtils.m
// ASDKCore
//
// Copyright © 2017 Tinkoff Bank. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import "ASDKUtils.h"

NSString *const kSumDecimalSeparator = @",";

@implementation ASDKUtils

+ (NSNumberFormatter *)sumNumberFormatter
{
static NSNumberFormatter *sumNumberFormatter = nil;

if (sumNumberFormatter == nil)
{
sumNumberFormatter = [[NSNumberFormatter alloc] init];
[sumNumberFormatter setGroupingSize:0];
[sumNumberFormatter setDecimalSeparator:kSumDecimalSeparator];
[sumNumberFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
[sumNumberFormatter setMaximumFractionDigits:2];
[sumNumberFormatter setMinimumFractionDigits:2];
}

return sumNumberFormatter;
}

+ (NSString *)amountWholeDigits:(double)amount
{
NSString *string = [[self sumNumberFormatter] stringFromNumber:[NSNumber numberWithDouble:amount]];
NSArray *array = [string componentsSeparatedByString:kSumDecimalSeparator];

if ([array count] == 2)
{
return [array objectAtIndex:0];
}

return string;
}

@end
7 changes: 4 additions & 3 deletions ASDKCore/RequestBuilder/Init/ASDKInitRequestBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
// limitations under the License.

#import "ASDKInitRequestBuilder.h"
#import "ASDKUtils.h"

@interface ASDKInitRequestBuilder ()

@property (nonatomic, strong) NSNumber *amount;
@property (nonatomic, strong) NSString *amount;
@property (nonatomic, copy) NSString *orderId;
@property (nonatomic, copy) NSString *customerKey;
@property (nonatomic, copy) NSString *requestDescription;
Expand Down Expand Up @@ -50,7 +51,7 @@ + (ASDKInitRequestBuilder *)builderWithAmount:(NSNumber *)amount

if (builder)
{
builder.amount = [NSNumber numberWithInteger:[NSString stringWithFormat:@"%.0f", amount.doubleValue].integerValue];
builder.amount = [ASDKUtils amountWholeDigits:amount.doubleValue];
builder.orderId = orderId;
builder.requestDescription = description;
builder.payType = payType;
Expand Down Expand Up @@ -215,7 +216,7 @@ - (NSDictionary *)parametersForToken
kASDKPassword : [self password]}];
if (self.amount)
{
[parameters setObject:self.amount.stringValue forKey:kASDKAmount];
[parameters setObject:self.amount forKey:kASDKAmount];
}

if (self.orderId.length > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
- (ASDKCard *)cardWithRebillId;
- (ASDKCard *)cardWithIdentifier:(NSString *)indentifier;

- (void)updateCardsListWithSuccessBlock:(void (^)())onSuccess
- (void)updateCardsListWithSuccessBlock:(void (^)(void))onSuccess
errorBlock:(void (^)(ASDKAcquringSdkError *error))onError;

- (void)removeCardWithCardId:(NSNumber *)cardId
successBlock:(void (^)())onSuccess
successBlock:(void (^)(void))onSuccess
errorBlock:(void (^)(ASDKAcquringSdkError *error))onError;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ - (ASDKCard *)cardWithIdentifier:(NSString *)indentifier
}


- (void)updateCardsListWithSuccessBlock:(void (^)())onSuccess
- (void)updateCardsListWithSuccessBlock:(void (^)(void))onSuccess
errorBlock:(void (^)(ASDKAcquringSdkError *error))onError
{
if (self.acquiringSdk && self.customerKey)
Expand Down Expand Up @@ -161,7 +161,7 @@ - (void)updateCardsListWithSuccessBlock:(void (^)())onSuccess
}

- (void)removeCardWithCardId:(NSNumber *)cardId
successBlock:(void (^)())onSuccess
successBlock:(void (^)(void))onSuccess
errorBlock:(void (^)(ASDKAcquringSdkError *error))onError
{
if (self.acquiringSdk && self.customerKey)
Expand Down
8 changes: 4 additions & 4 deletions ASDKUI/Payment/PaymentFormStarter/ASDKPaymentFormStarter.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
- (void)scanCardSuccess:(void (^)(NSString *cardNumber))success
failure:(void (^)(ASDKAcquringSdkError *error))failure
cancel:(void (^)())cancel;
cancel:(void (^)(void))cancel;

@end

Expand Down Expand Up @@ -71,7 +71,7 @@
additionalPaymentData:(NSDictionary *)data
receiptData:(NSDictionary *)receiptData
success:(void (^)(ASDKPaymentInfo *paymentInfo))onSuccess
cancelled:(void (^)())onCancelled
cancelled:(void (^)(void))onCancelled
error:(void (^)(ASDKAcquringSdkError *error))onError;

- (void)chargeWithRebillId:(NSNumber *)rebillId
Expand Down Expand Up @@ -140,15 +140,15 @@
additionalPaymentData:(NSDictionary *)additionalPaymentData //JSON объект содержащий дополнительные параметры, например @{@"Email" : @"[email protected]"}
receiptData:(NSDictionary *)receiptData // JSON объект с данными чека, обязательно должен быть объект Items в который вложены позиции чека Email и Taxation - Система налогообложения, значения: osn, usn_income, usn_income_outcome, envd, esn, или patent
success:(void (^)(ASDKPaymentInfo *paymentInfo))onSuccess
cancelled:(void (^)())onCancelled
cancelled:(void (^)(void))onCancelled
error:(void (^)(ASDKAcquringSdkError *error))onError NS_AVAILABLE_IOS(9_0);

- (void)checkStatusTransaction:(NSString *)paymentId
success:(void (^)(ASDKPaymentStatus status))onSuccess
error:(void (^)(ASDKAcquringSdkError *error))onError;

- (void)refundTransaction:(NSString *)paymentId
success:(void (^)())onSuccess
success:(void (^)(void))onSuccess
error:(void (^)(ASDKAcquringSdkError *error))onError;

/*!
Expand Down
6 changes: 3 additions & 3 deletions ASDKUI/Payment/PaymentFormStarter/ASDKPaymentFormStarter.m
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ - (void)presentPaymentFormFromViewController:(UIViewController *)presentingViewC
additionalPaymentData:(NSDictionary *)data
receiptData:(NSDictionary *)receiptData
success:(void (^)(ASDKPaymentInfo *paymentInfo))onSuccess
cancelled:(void (^)())onCancelled
cancelled:(void (^)(void))onCancelled
error:(void(^)(ASDKAcquringSdkError *error))onError
{
[self prepareDesign];
Expand Down Expand Up @@ -289,7 +289,7 @@ - (void)payWithApplePayFromViewController:(UIViewController *)presentingViewCont
additionalPaymentData:(NSDictionary *)additionalPaymentData
receiptData:(NSDictionary *)receiptData
success:(void (^)(ASDKPaymentInfo *paymentInfo))onSuccess
cancelled:(void (^)())onCancelled
cancelled:(void (^)(void))onCancelled
error:(void (^)(ASDKAcquringSdkError *error))onError
{
///////////////
Expand Down Expand Up @@ -366,7 +366,7 @@ - (void)checkStatusTransaction:(NSString *)paymentId
}

- (void)refundTransaction:(NSString *)paymentId
success:(void (^)())onSuccess
success:(void (^)(void))onSuccess
error:(void (^)(ASDKAcquringSdkError *error))onError
{
[self.acquiringSdk rejectTrancastionWithPaymentId:paymentId success:^(ASDKCancelResponse *response) {
Expand Down
2 changes: 1 addition & 1 deletion SampleProject/ASDKSampleApp/Resources/books.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"cover": "cover3",
"title": "Чайка по имени Джонатан Ливингстон",
"author" : "Ричард Бах",
"cost" : 720800.0312,
"cost" : 720800.0301,
"description" : "Короткое описание"
}
]
Expand Down
4 changes: 2 additions & 2 deletions SampleProject/ASDKSampleApp/Source/ASDKCardIOScanner.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@interface ASDKCardIOScanner () <CardIOPaymentViewControllerDelegate>

@property (nonatomic, strong) void (^successBlock)(NSString *cardNumber);
@property (nonatomic, strong) void (^cancelBlock)();
@property (nonatomic, strong) void (^cancelBlock)(void);

@end

Expand Down Expand Up @@ -96,7 +96,7 @@ - (void)userDidCancelPaymentViewController:(CardIOPaymentViewController *)paymen

- (void)scanCardSuccess:(void (^)(NSString *cardNumnber))success
failure:(void (^)(ASDKAcquringSdkError *error))failure
cancel:(void (^)())cancel
cancel:(void (^)(void))cancel
{
self.successBlock = success;
self.cancelBlock = cancel;
Expand Down
6 changes: 3 additions & 3 deletions SampleProject/ASDKSampleApp/Source/PayController.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
receiptData:(NSDictionary *)receiptData
fromViewController:(UIViewController *)viewController
success:(void (^)(ASDKPaymentInfo *paymentInfo))onSuccess
cancelled:(void (^)())onCancelled
cancelled:(void (^)(void))onCancelled
error:(void(^)(ASDKAcquringSdkError *error))onError;

+ (void)chargeWithRebillId:(NSNumber *)rebillId
Expand All @@ -47,7 +47,7 @@
receiptData:(NSDictionary *)receiptData
fromViewController:(UIViewController *)viewController
success:(void (^)(ASDKPaymentInfo *paymentIfo))onSuccess
cancelled:(void (^)())onCancelled
cancelled:(void (^)(void))onCancelled
error:(void(^)(ASDKAcquringSdkError *error))onError;

+ (void)checkStatusTransaction:(NSString *)paymentId
Expand All @@ -57,7 +57,7 @@

+ (void)refundTransaction:(NSString *)paymentId
fromViewController:(UIViewController *)viewController
success:(void (^)())onSuccess
success:(void (^)(void))onSuccess
error:(void (^)(ASDKAcquringSdkError *error))onError;

+ (void)attachCard:(NSString *)cardCheckType additionalData:(NSDictionary *)data fromViewController:(UIViewController *)viewController
Expand Down
6 changes: 3 additions & 3 deletions SampleProject/ASDKSampleApp/Source/PayController.m
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ + (void)buyItemWithName:(NSString *)name
receiptData:(NSDictionary *)receiptData
fromViewController:(UIViewController *)viewController
success:(void (^)(ASDKPaymentInfo *paymentInfo))onSuccess
cancelled:(void (^)())onCancelled
cancelled:(void (^)(void))onCancelled
error:(void(^)(ASDKAcquringSdkError *error))onError
{
ASDKPaymentFormStarter *paymentFormStarter = [PayController paymentFormStarter];
Expand Down Expand Up @@ -250,7 +250,7 @@ + (void)buyWithApplePayAmount:(NSNumber *)amount
receiptData:(NSDictionary *)receiptData
fromViewController:(UIViewController *)viewController
success:(void (^)(ASDKPaymentInfo *paymentIfo))onSuccess
cancelled:(void (^)())onCancelled
cancelled:(void (^)(void))onCancelled
error:(void(^)(ASDKAcquringSdkError *error))onError
{
ASDKPaymentFormStarter *paymentFormStarter = [PayController paymentFormStarter];
Expand Down Expand Up @@ -309,7 +309,7 @@ + (void)checkStatusTransaction:(NSString *)paymentId

+ (void)refundTransaction:(NSString *)paymentId
fromViewController:(UIViewController *)viewController
success:(void (^)())onSuccess
success:(void (^)(void))onSuccess
error:(void (^)(ASDKAcquringSdkError *error))onError
{
ASDKPaymentFormStarter *paymentFormStarter = [PayController paymentFormStarter];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath

if ([self cellTypeForIndexPath:indexPath] == CellTypeAddNewCard)
{
[PayController attachCard:self.addNewCardCheckType additionalData:nil fromViewController:self success:^(ASDKResponseAddCardInit *response) {
[PayController attachCard:@"AUTO"/*self.addNewCardCheckType*/ additionalData:nil fromViewController:self success:^(ASDKResponseAddCardInit *response) {
//
} cancelled:^{
//
Expand Down

0 comments on commit 57139f0

Please sign in to comment.