Skip to content

Commit

Permalink
Improvements payWithApplePay
Browse files Browse the repository at this point in the history
  • Loading branch information
Budnikov Vyacheslav committed Mar 29, 2017
1 parent afbc7c0 commit 2425ac7
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 22 deletions.
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.7</string>
<string>1.1.8</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
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.7</string>
<string>1.1.8</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
55 changes: 46 additions & 9 deletions ASDKUI/Payment/PaymentFormStarter/ASDKPaymentFormStarter.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,54 @@
+ (BOOL)isPayWithAppleAvailable NS_AVAILABLE_IOS(9_0);
+ (NSArray<PKPaymentNetwork> *)payWithAppleSupportedNetworks NS_AVAILABLE_IOS(9_0);

/**
* @bref оплата с помощью ApplePay, онлайн документация https://oplata.tinkoff.ru/documentation/?section=Init
*
* @param amount - Сумма
* @param orderId - Номер заказа в системе Продавца
* @param description - Краткое описание товара
*
* @param customerKey - Идентификатор покупателя в системе Продавца. Если передается, то для данного покупателя будет осуществлена
* привязка карты к данному идентификатору клиента CustomerKey. В нотификации на AUTHORIZED будет передан параметр CardId,
* подробнее см. метод GetGardList https://oplata.tinkoff.ru/documentation/?section=GetCardList
*
* @param appleMerchantId - берётся из Target->Capabilities->ApplePay Merchant IDs.
* Создается в https://developer.apple.com/account/ios/identifier/merchant
* Настраивается в сертификате https://developer.apple.com/account/ios/identifier/bundle iOS App IDs-> Edit -> Apple Pay
*
* @param shippingMethods - доставка и стоимость доставки,
* например "доставка курьером стоимость 300руб." @[[PKShippingMethod summaryItemWithLabel:@"Доставка курьером" amount:[NSDecimalNumber decimalNumberWithString:@"300"]]]
*
* @param shippingContact - кому доставить и адрес доставки
*
* @param shippingEditableFields - какие поля можно показывать и редактировть на форме оплаты Apple Pay, например
* PKAddressFieldNone - ни одного (и не показывать)
* PKAddressFieldPostalAddress|PKAddressFieldName|PKAddressFieldEmail|PKAddressFieldPhone - Адрес ФИО Email и Телефон
*
* @param additionalPaymentData - Ключ=значение дополнительных параметров через “|”, например [email protected]|Phone=+71234567890,
* если ключи или значения содержат в себе спец символы, то получившееся значение должно быть закодировано функцией urlencode.
* При этом, обязательным является наличие дополнительного параметра Email. Прочие можно добавлять по желанию.
* Данные параметры будут переданы на страницу оплаты (в случае ее кастомизации). Максимальная длина для каждого передаваемого параметра:
* Ключ – 20 знаков, Значение – 100 знаков. Максимальное количество пар «ключ-значение» не может превышать 20.
* Пример передачи данных в параметре DATA: DATA=Phone=+71234567890|[email protected]
*
* @param onSuccess блок в случае успеха
* @param onCancelled блок в случае сканирования с ошибкой
* @param onError блок при отмене сканирования
*/

- (void)payWithApplePayFromViewController:(UIViewController *)presentingViewController
amount:(NSNumber *)amount
orderId:(NSString *)orderId
description:(NSString *)description
customerKey:(NSString *)customerKey
sendEmail:(BOOL)sendEmail
amount:(NSNumber *)amount // цена товара
orderId:(NSString *)orderId // идентификатор товара
description:(NSString *)description // описание
customerKey:(NSString *)customerKey // идетинификатор пользователя (для сохранеиня платежей)
sendEmail:(BOOL)sendEmail // отправлять чек на почту
email:(NSString *)email
appleMerchantId:(NSString *)appleMerchantId
shippingMethods:(NSArray<PKShippingMethod *> *)shippingMethods
shippingContact:(PKContact *)shippingContact
additionalPaymentData:(NSDictionary *)data
appleMerchantId:(NSString *)appleMerchantId // берётся из Target->Capabilities->ApplePay Merchant IDs
shippingMethods:(NSArray<PKShippingMethod *> *)shippingMethods //доставка и стоимость доставки
shippingContact:(PKContact *)shippingContact //кому доставить и адрес доставки
shippingEditableFields:(PKAddressField)shippingEditableFields //какие поля можно показывать и редактировть на форме оплаты ApplePay
additionalPaymentData:(NSDictionary *)additionalPaymentData // Ключ=значение дополнительных параметров через “|”, например [email protected]|Phone=+71234567890
success:(void (^)(NSString *paymentId))onSuccess
cancelled:(void (^)())onCancelled
error:(void (^)(ASDKAcquringSdkError *error))onError NS_AVAILABLE_IOS(9_0);
Expand Down
17 changes: 9 additions & 8 deletions ASDKUI/Payment/PaymentFormStarter/ASDKPaymentFormStarter.m
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ - (void)payWithApplePayFromViewController:(UIViewController *)presentingViewCont
appleMerchantId:(NSString *)appleMerchantId
shippingMethods:(NSArray<PKShippingMethod *> *)shippingMethods
shippingContact:(PKContact *)shippingContact
additionalPaymentData:(NSDictionary *)data
shippingEditableFields:(PKAddressField)shippingEditableFields
additionalPaymentData:(NSDictionary *)additionalPaymentData
success:(void (^)(NSString *paymentId))onSuccess
cancelled:(void (^)())onCancelled
error:(void (^)(ASDKAcquringSdkError *error))onError
Expand All @@ -287,7 +288,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 additionalPaymentData:data
[self.acquiringSdk initWithAmount:[NSNumber numberWithDouble:100 * amount.doubleValue] orderId:orderId description:nil payForm:nil customerKey:customerKey recurrent:NO additionalPaymentData:additionalPaymentData
success:^(ASDKInitResponse *response){
self.paymentIdForApplePay = response.paymentId;

Expand Down Expand Up @@ -315,13 +316,13 @@ - (void)payWithApplePayFromViewController:(UIViewController *)presentingViewCont
paymentRequest.requiredBillingAddressFields = addressFieldBilling;

//
PKAddressField addressFieldShipping = PKAddressFieldNone;
if (shippingContact.postalAddress) { addressFieldShipping |= PKAddressFieldPostalAddress; }
if (shippingContact.name) { addressFieldShipping |= PKAddressFieldName; }
if (shippingContact.emailAddress) { addressFieldShipping |= PKAddressFieldEmail; }
if (shippingContact.phoneNumber) { addressFieldShipping |= PKAddressFieldPhone; }
//PKAddressField shippingEditableFields = PKAddressFieldNone;
//if (shippingContact.postalAddress) { shippingEditableFields |= PKAddressFieldPostalAddress; }
//if (shippingContact.name) { shippingEditableFields |= PKAddressFieldName; }
//if (shippingContact.emailAddress) { shippingEditableFields |= PKAddressFieldEmail; }
//if (shippingContact.phoneNumber) { shippingEditableFields |= PKAddressFieldPhone; }
paymentRequest.requiredShippingAddressFields = shippingEditableFields;
paymentRequest.shippingContact = shippingContact;
paymentRequest.requiredShippingAddressFields = addressFieldShipping;

//paymentRequest.shippingMethods = shippingMethods;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,9 @@ - (IBAction)buttonActionApplePay:(UIButton *)sender
description:self.item.title
email:shippingContact.emailAddress
appleMerchantId:@"merchant.tcsbank.ApplePayTestMerchantId"
shippingMethods:nil//@[[PKShippingMethod summaryItemWithLabel:@"Доставка" amount:[NSDecimalNumber decimalNumberWithString:@"300"]]]
shippingMethods:nil //@[[PKShippingMethod summaryItemWithLabel:@"Доставка" amount:[NSDecimalNumber decimalNumberWithString:@"300"]]]
shippingContact:shippingContact
shippingEditableFields:PKAddressFieldPostalAddress|PKAddressFieldName|PKAddressFieldEmail|PKAddressFieldPhone //PKAddressFieldNone
additionalPaymentData:nil
fromViewController:self
success:^(NSString *paymentId) { NSLog(@"%@", paymentId); }
Expand Down
1 change: 1 addition & 0 deletions SampleProject/ASDKSampleApp/Source/PayController.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
appleMerchantId:(NSString *)appleMerchantId
shippingMethods:(NSArray<PKShippingMethod *> *)shippingMethods
shippingContact:(PKContact *)shippingContact
shippingEditableFields:(PKAddressField)shippingEditableFields
additionalPaymentData:(NSDictionary *)data
fromViewController:(UIViewController *)viewController
success:(void (^)(NSString *paymentId))onSuccess
Expand Down
2 changes: 2 additions & 0 deletions SampleProject/ASDKSampleApp/Source/PayController.m
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ + (void)buyWithApplePayAmount:(NSNumber *)amount
appleMerchantId:(NSString *)appleMerchantId
shippingMethods:(NSArray<PKShippingMethod *> *)shippingMethods
shippingContact:(PKContact *)shippingContact
shippingEditableFields:(PKAddressField)shippingEditableFields
additionalPaymentData:(NSDictionary *)data
fromViewController:(UIViewController *)viewController
success:(void (^)(NSString *paymentId))onSuccess
Expand All @@ -149,6 +150,7 @@ + (void)buyWithApplePayAmount:(NSNumber *)amount
appleMerchantId:appleMerchantId
shippingMethods:shippingMethods
shippingContact:shippingContact
shippingEditableFields:shippingEditableFields
additionalPaymentData:data
success:^(NSString *paymentId) {
PaymentSuccessViewController *vc = [[PaymentSuccessViewController alloc] init];
Expand Down
4 changes: 2 additions & 2 deletions SampleProject/ASDKSampleApp/Supporting files/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.1.7</string>
<string>1.1.8</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>35</string>
<string>36</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
Expand Down

0 comments on commit 2425ac7

Please sign in to comment.