Skip to content

Commit

Permalink
Merge pull request #109 in MI/yandex-checkout-payments-swift from rel…
Browse files Browse the repository at this point in the history
…ease/3.1.0 to master

* commit 'cebdc6c6a26e31626a4539a1c9cc37a7d85a1b29':
  [NO-TASK] Delete default implementation for `TokenizationModuleOutput` protocol
  [NO-TASK] Bump .podspec version
  [NO-TASK] Update CHANGELOG.md
  [BIOS-1347] Fix tokens request in Apple Pay module on fail tokenize data
  [BIOS-1347] Fix tokens request in Apple Pay module
  • Loading branch information
AutoMergeBot authored and AutoMergeBot committed Dec 23, 2019
2 parents 7babd90 + cebdc6c commit 7312241
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 28 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Changelog

### 3.1.0

1. Улучшили процесс токенизации для способа оплаты Apple Pay.

### 3.0.0

Добавили возможность создавать платежный токен для рекуррентных платежей.
Expand Down
4 changes: 2 additions & 2 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ PODS:
- Reveal-SDK (24)
- SwiftLint (0.34.0)
- When (4.0.0)
- YandexCheckoutPayments (3.0.0):
- YandexCheckoutPayments (3.1.0):
- FunctionalSwift (~> 1.1.0)
- When (~> 4.0.0)
- YandexCheckoutPaymentsApi (~> 1.8.0)
Expand Down Expand Up @@ -63,7 +63,7 @@ SPEC CHECKSUMS:
Reveal-SDK: 5d7e56b8f018c0a88b3a2c10bf68d598bbd3b071
SwiftLint: 79d48a17c6565dc286c37efb8322c7b450f95c67
When: 4ffc88d535a094ad4bd5eaf2fd187de747e716d1
YandexCheckoutPayments: 7f8053c09c0ee7f6b2ab8152d29902067cdc2598
YandexCheckoutPayments: db2430de572c7c68a3bce6e22cbe1e82e6d4bf8b
YandexCheckoutPaymentsApi: fbe102bbfbab08a83da1a428a37f3d4b4bc1c28e
YandexCheckoutShowcaseApi: 44382163176b3a53692fa1c3b85c0c8d0a82b7e6
YandexCheckoutWalletApi: 5d2774cd1216ee0ce47d6412184008b37caeaeac
Expand Down
2 changes: 1 addition & 1 deletion YandexCheckoutPayments.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'YandexCheckoutPayments'
s.version = '3.0.0'
s.version = '3.1.0'
s.homepage = 'https://github.com/yandex-money/yandex-checkout-payments-swift'
s.license = {
:type => "MIT",
Expand Down
3 changes: 3 additions & 0 deletions YandexCheckoutPayments.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -4219,6 +4219,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = ./YandexCheckoutPayments/Public/Resources/Entitlements/YandexCheckoutPaymentsExamplePods.entitlements;
CURRENT_PROJECT_VERSION = 12;
DEVELOPMENT_TEAM = 2752592HU5;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -4291,6 +4292,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = ./YandexCheckoutPayments/Public/Resources/Entitlements/YandexCheckoutPaymentsExamplePods.debug.entitlements;
CURRENT_PROJECT_VERSION = 12;
DEVELOPMENT_TEAM = 2752592HU5;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -4320,6 +4322,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = ./YandexCheckoutPayments/Public/Resources/Entitlements/YandexCheckoutPaymentsExamplePods.inhouse.entitlements;
CURRENT_PROJECT_VERSION = 12;
DEVELOPMENT_TEAM = 2752592HU5;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class TokenizationPresenter: NSObject { // NSObject needs for PKPaymentAuthoriza
private var strategy: TokenizationStrategyInput?
private var tokenizeData: TokenizeData?
private var isReusableToken: Bool?
private var shouldInvalidateTokenizeData = false

private var paymentOption: PaymentOption? {
didSet {
Expand Down Expand Up @@ -386,8 +385,10 @@ extension TokenizationPresenter: TokenizationInteractorOutput {
interactor.trackEvent(event)
interactor.stopAnalyticsService()

if shouldInvalidateTokenizeData {
shouldInvalidateTokenizeData = false
strategy?.didTokenizeData()

if strategy?.shouldInvalidateTokenizeData == true {
strategy?.shouldInvalidateTokenizeData = false
} else {
moduleOutput?.tokenizationModule(
self,
Expand Down Expand Up @@ -579,7 +580,7 @@ extension TokenizationPresenter: BankCardDataInputModuleOutput {

func didPressCloseBarButtonItem(on module: BankCardDataInputModuleInput) {
if paymentOptionsCount > Constants.minimalRecommendedPaymentsOptions {
shouldInvalidateTokenizeData = true
strategy?.shouldInvalidateTokenizeData = true
presentPaymentMethodsModule()
} else {
close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import YandexCheckoutPaymentsApi
final class ApplePayStrategy: NSObject {

private enum PaymentResult {
case idle
case success
case failed
case cancel
}

// MARK: - Outputs
Expand Down Expand Up @@ -43,11 +44,13 @@ final class ApplePayStrategy: NSObject {
// MARK: - Stored data

private weak var paymentMethodsModuleInput: PaymentMethodsModuleInput?
private var paymentResult: PaymentResult = .failed
private var applePayCompletion: ((PKPaymentAuthorizationStatus) -> Void)?
private var paymentResult: PaymentResult = .idle

// MARK: - TokenizationStrategyInput

var savePaymentMethod: Bool
var shouldInvalidateTokenizeData = false
}

// MARK: - TokenizationStrategyInput
Expand All @@ -68,22 +71,38 @@ extension ApplePayStrategy: TokenizationStrategyInput {
}
}

func didTokenizeData() {
guard paymentResult != .cancel else {
shouldInvalidateTokenizeData = true
return
}
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }
self.applePayCompletion?(.success)
}
}

func paymentAuthorizationViewController(
_ controller: PKPaymentAuthorizationViewController,
didAuthorizePayment payment: PKPayment,
completion: @escaping (PKPaymentAuthorizationStatus) -> Void
) {
guard paymentResult != .cancel else { return }
paymentResult = .success
let tokenizeData: TokenizeData = .applePay(
paymentData: payment.token.paymentData.base64EncodedString(),
savePaymentMethod: savePaymentMethod
)
applePayCompletion = completion
output?.tokenize(tokenizeData, paymentOption: paymentOption)
completion(.success)
}

func paymentAuthorizationViewControllerDidFinish(_ controller: PKPaymentAuthorizationViewController) {
if case .failed = paymentResult {
func paymentAuthorizationViewControllerDidFinish(
_ controller: PKPaymentAuthorizationViewController
) {
if paymentResult == .idle
|| paymentResult == .success {
paymentResult = .cancel
output?.didFinish(on: self)
}
}
Expand All @@ -98,11 +117,16 @@ extension ApplePayStrategy: TokenizationStrategyInput {
}

func didFailPresentApplePayModule() {
guard paymentResult != .cancel else { return }
trackScreenErrorAnalytics()
paymentMethodsModuleInput?.showPlaceholder(message: §Localized.applePayUnavailableTitle)
}

func failTokenizeData(_ error: Error) {
guard paymentResult != .cancel else {
shouldInvalidateTokenizeData = true
return
}
trackScreenErrorAnalytics()
output?.presentErrorWithMessage(§Localized.Error.failTokenizeData)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ final class BankCardStrategy {

private weak var bankCardDataInputModule: BankCardDataInputModuleInput?

var shouldInvalidateTokenizeData = false
var savePaymentMethod: Bool

private let paymentOption: PaymentOption
Expand Down Expand Up @@ -76,6 +77,7 @@ extension BankCardStrategy: TokenizationStrategyInput {
func didPressSubmitButton(on module: ApplePayContractModuleInput) {}
func didLoginInYandexMoney(_ response: YamoneyLoginResponse) {}
func failLoginInYandexMoney(_ error: Error) {}
func didTokenizeData() {}
}

private func makeBankCard(_ cardData: CardData) -> BankCard? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ final class LinkedBankCardStrategy {
private weak var bankCardDataInputModule: BankCardDataInputModuleInput?

var savePaymentMethod: Bool
var shouldInvalidateTokenizeData = false

private let authorizationService: AuthorizationProcessing
private let paymentOption: PaymentInstrumentYandexMoneyLinkedBankCard
Expand Down Expand Up @@ -106,6 +107,7 @@ extension LinkedBankCardStrategy: TokenizationStrategyInput {
func didPresentApplePayModule() {}
func didPressSubmitButton(on module: ApplePayContractModuleInput) {}
func bankCardDataInputModule(_ module: BankCardDataInputModuleInput, didPressConfirmButton bankCardData: CardData) {}
func didTokenizeData() {}
}

private func makeConfirmation(returnUrl: String) -> Confirmation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ final class SberbankStrategy {
weak var contractStateHandler: ContractStateHandler?

var savePaymentMethod: Bool
var shouldInvalidateTokenizeData = false

init(
paymentOption: PaymentOption,
Expand Down Expand Up @@ -62,4 +63,5 @@ extension SberbankStrategy: TokenizationStrategyInput {
func didPressSubmitButton(on module: ContractModuleInput) {}
func didLoginInYandexMoney(_ response: YamoneyLoginResponse) {}
func yamoneyAuthParameters(_ module: YamoneyAuthParametersModuleInput, loginWithReusableToken isReusableToken: Bool) {}
func didTokenizeData() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ protocol TokenizationStrategyInput: class {
var output: TokenizationStrategyOutput? { get set }
var contractStateHandler: ContractStateHandler? { get set }
var savePaymentMethod: Bool { get set }
var shouldInvalidateTokenizeData: Bool { get set }

func beginProcess()
func didTokenizeData()

func didPressSubmitButton(
on module: ContractModuleInput
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ final class WalletStrategy {
weak var contractStateHandler: ContractStateHandler?

var savePaymentMethod: Bool
var shouldInvalidateTokenizeData = false

private let authorizationService: AuthorizationProcessing
private let paymentOption: PaymentInstrumentYandexMoneyWallet
Expand Down Expand Up @@ -108,6 +109,7 @@ extension WalletStrategy: TokenizationStrategyInput {
func didFailPresentApplePayModule() {}
func didPresentApplePayModule() {}
func didPressSubmitButton(on module: ApplePayContractModuleInput) {}
func didTokenizeData() {}
}

private func makeConfirmation(returnUrl: String) -> Confirmation {
Expand Down
22 changes: 7 additions & 15 deletions YandexCheckoutPayments/Public/TokenizationModuleIO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,20 @@ public protocol TokenizationModuleOutput: class {
/// In the process of running mSDK, allows you to run processes using the
/// `TokenizationModuleInput` protocol methods.
/// - error: `YandexCheckoutPaymentsError` error.
func didFinish(on module: TokenizationModuleInput,
with error: YandexCheckoutPaymentsError?)
func didFinish(
on module: TokenizationModuleInput,
with error: YandexCheckoutPaymentsError?
)

/// Will be called when the 3-D Secure process successfully passes.
///
/// - Parameters:
/// - module: Input for tokenization module.
/// In the process of running mSDK, allows you to run processes using the
/// `TokenizationModuleInput` protocol methods.
func didSuccessfullyPassedCardSec(on module: TokenizationModuleInput)
func didSuccessfullyPassedCardSec(
on module: TokenizationModuleInput
)

/// Will be called when the tokenization process successfully passes.
///
Expand All @@ -48,15 +52,3 @@ public protocol TokenizationModuleOutput: class {
paymentMethodType: PaymentMethodType
)
}

/// Default implementation for `TokenizationModuleOutput`
public extension TokenizationModuleOutput {
func didFinish(on module: TokenizationModuleInput,
with error: YandexCheckoutPaymentsError?) {}
func didSuccessfullyPassedCardSec(on module: TokenizationModuleInput) {}
func tokenizationModule(
_ module: TokenizationModuleInput,
didTokenize token: Tokens,
paymentMethodType: PaymentMethodType
) {}
}
2 changes: 1 addition & 1 deletion YandexCheckoutPaymentsExample/Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>7</string>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>yandexauth</string>
Expand Down

0 comments on commit 7312241

Please sign in to comment.