Skip to content

Commit

Permalink
Merge pull request yoomoney#50 in MI/yandex-checkout-payments-swift f…
Browse files Browse the repository at this point in the history
…rom ~TVERDOKHLEB/yandex-checkout-payments-swift:task/b2b/BIOS-1145 to feature/pay-by-linked-to-the-store-card

* commit '63a03480d9a942056be6f6709ac818bd97cacfc8':
  [BIOS-1145] Add recurring metrics
  • Loading branch information
AutoMergeBot authored and AutoMergeBot committed Aug 20, 2019
2 parents d927565 + 63a0348 commit 0fa682b
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ struct MaskedBankCardDataInputModuleInputData {
let testModeSettings: TestModeSettings?
let isLoggingEnabled: Bool
let analyticsEvent: AnalyticsEvent?
let tokenizeScheme: AnalyticsEvent.TokenizeScheme?
}

protocol MaskedBankCardDataInputModuleOutput: class {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ extension MaskedBankCardDataInputPresenter: BankCardDataInputModuleInput {
DispatchQueue.global().async { [weak self] in
guard let interactor = self?.interactor else { return }
let (authType, _) = interactor.makeTypeAnalyticsParameters()
interactor.trackEvent(.screenError(authType: authType, scheme: .linkedCard))
let scheme = self?.inputData.tokenizeScheme
interactor.trackEvent(.screenError(authType: authType, scheme: scheme))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import YandexCheckoutPaymentsApi

protocol BankCardRepeatInteractorInput: class {
protocol BankCardRepeatInteractorInput: AnalyticsTrackable {
func fetchPaymentMethod(paymentMethodId: String)
func tokenize(amount: MonetaryAmount,
confirmation: Confirmation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ final class BankCardRepeatInteractor {

private let clientApplicationKey: String
private let paymentService: PaymentProcessing
private let analyticsService: AnalyticsProcessing

init(clientApplicationKey: String,
paymentService: PaymentProcessing) {
paymentService: PaymentProcessing,
analyticsService: AnalyticsProcessing) {
ThreatMetrixService.configure()

self.clientApplicationKey = clientApplicationKey
self.paymentService = paymentService
self.analyticsService = analyticsService
}
}

Expand Down Expand Up @@ -66,6 +69,10 @@ extension BankCardRepeatInteractor: BankCardRepeatInteractorInput {
let tmxSessionIdWithError = tmxSessionId.recover(on: .global(), mapError)
tmxSessionIdWithError.fail(output.didFailTokenize)
}

func trackEvent(_ event: AnalyticsEvent) {
analyticsService.trackEvent(event)
}
}

// MARK: - Private global helpers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extension BankCardRepeatPresenter: TokenizationViewOutput {
private func presentContract() {

let viewModel = PaymentMethodViewModelFactory.makePaymentMethodViewModel(.bankCard)
let tokenizeScheme = TokenizeSchemeFactory.makeTokenizeScheme(.bankCard)
let tokenizeScheme = AnalyticsEvent.TokenizeScheme.recurringCard

let moduleInputData = ContractModuleInputData(
shopName: inputData.shopName,
Expand Down Expand Up @@ -78,7 +78,8 @@ extension BankCardRepeatPresenter: BankCardRepeatInteractorOutput {
cardMask: cardMask,
testModeSettings: inputData.testModeSettings,
isLoggingEnabled: inputData.isLoggingEnabled,
analyticsEvent: nil
analyticsEvent: .screenRecurringCardForm,
tokenizeScheme: .recurringCard
)

DispatchQueue.main.async { [weak self] in
Expand Down Expand Up @@ -119,6 +120,11 @@ extension BankCardRepeatPresenter: BankCardRepeatInteractorOutput {
}

private func showError(_ error: Error) {
let authType = AnalyticsEvent.AuthType.withoutAuth
let scheme = AnalyticsEvent.TokenizeScheme.recurringCard
let event = AnalyticsEvent.screenError(authType: authType, scheme: scheme)
interactor.trackEvent(event)

let message = makeMessage(error)
contractModuleInput?.hideActivity()
contractModuleInput?.showPlaceholder(message: message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ extension TokenizationPresenter: TokenizationStrategyOutput {
cardMask: paymentOption.cardMask,
testModeSettings: inputData.testModeSettings,
isLoggingEnabled: inputData.isLoggingEnabled,
analyticsEvent: .screenLinkedCardForm
analyticsEvent: .screenLinkedCardForm,
tokenizeScheme: .linkedCard
)
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ enum AnalyticsEvent {
/// The opening pages 3DS.
case screen3ds

/// Open Bank Card screen with screen recurring
case screenRecurringCardForm

// MARK: - Actions

/// Create a payment token with the payment method selected.
Expand Down Expand Up @@ -66,6 +69,7 @@ enum AnalyticsEvent {
case bankCard = "bank-card"
case smsSbol = "sms-sbol"
case applePay = "apple-pay"
case recurringCard = "recurring-card"

var key: String {
return Key.tokenizeScheme.rawValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ final class AnalyticsService: AnalyticsProcessing {
eventName = EventKey.screenError.rawValue
case .screen3ds:
eventName = EventKey.screen3ds.rawValue
case .screenRecurringCardForm:
eventName = EventKey.screenRecurringCardForm.rawValue
case .actionTokenize:
eventName = EventKey.actionTokenize.rawValue
case .actionYaLoginAuthorization:
Expand Down Expand Up @@ -107,6 +109,9 @@ final class AnalyticsService: AnalyticsProcessing {
case .screen3ds:
parameters = nil

case .screenRecurringCardForm:
parameters = nil

case .actionTokenize(let scheme, let authType, let tokenType):
parameters = [
scheme.key: scheme.rawValue,
Expand Down Expand Up @@ -147,6 +152,7 @@ final class AnalyticsService: AnalyticsProcessing {
case screenBankCardForm
case screenError
case screen3ds
case screenRecurringCardForm
case actionTokenize
case actionYaLoginAuthorization
case actionPaymentAuthorization
Expand Down
6 changes: 5 additions & 1 deletion YandexCheckoutPayments/Public/TokenizationAssembly.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ public enum TokenizationAssembly {
testModeSettings: inputData.testModeSettings,
isLoggingEnabled: inputData.isLoggingEnabled)

let analyticsService = AnalyticsProcessingAssembly
.makeAnalyticsService(isLoggingEnabled: inputData.isLoggingEnabled)

let interactor = BankCardRepeatInteractor(
clientApplicationKey: inputData.clientApplicationKey,
paymentService: paymentService
paymentService: paymentService,
analyticsService: analyticsService
)
let router = TokenizationRouter()

Expand Down

0 comments on commit 0fa682b

Please sign in to comment.