Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error reporter prototype #8078

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ constructor(
isVoucher = false,
requiresMandate = false,
hasDelayedSettlement = false,
shouldRefreshIfIntentRequiresAction = true,
shouldRefreshIfIntentRequiresAction = false
// shouldRefreshIfIntentRequiresAction = true,
),
Alma(
"alma",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package com.stripe.android.payments.core.authentication

import com.stripe.android.core.networking.AnalyticsEvent
import com.stripe.android.core.networking.AnalyticsRequestExecutor
import com.stripe.android.core.networking.AnalyticsRequestFactory
import com.stripe.android.core.networking.ApiRequest
import com.stripe.android.core.networking.DefaultAnalyticsRequestExecutor
import com.stripe.android.core.networking.ErrorReporter
import com.stripe.android.model.StripeIntent
import com.stripe.android.model.StripeIntent.NextActionData
import com.stripe.android.view.AuthActivityStarterHost
Expand All @@ -15,20 +20,27 @@ import javax.inject.Singleton
@Singleton
internal class BoletoAuthenticator @Inject constructor(
private val webIntentAuthenticator: WebIntentAuthenticator,
private val noOpIntentAuthenticator: NoOpIntentAuthenticator
private val noOpIntentAuthenticator: NoOpIntentAuthenticator,
private val errorReporter: ErrorReporter
) : PaymentAuthenticator<StripeIntent>() {
override suspend fun performAuthentication(
host: AuthActivityStarterHost,
authenticatable: StripeIntent,
requestOptions: ApiRequest.Options
) {
(authenticatable.nextActionData as NextActionData.DisplayBoletoDetails).let { detailsData ->
if (detailsData.hostedVoucherUrl == null) {
noOpIntentAuthenticator.authenticate(
host,
authenticatable,
requestOptions
)
suspend fun handleAuthenticationFailed(reason : ErrorReporter.ErrorEvent) {
errorReporter.report(reason, errorCode = null)
noOpIntentAuthenticator.authenticate(
host,
authenticatable,
requestOptions
)
}
(authenticatable.nextActionData as? NextActionData.DisplayBoletoDetails).let { detailsData ->
if (detailsData == null) {
handleAuthenticationFailed(ErrorReporter.ErrorEvent.INCORRECT_NEXT_ACTION_TYPE)
} else if (detailsData.hostedVoucherUrl == null) {
handleAuthenticationFailed(ErrorReporter.ErrorEvent.MISSING_HOSTED_VOUCHER_URL)
} else {
webIntentAuthenticator.authenticate(
host,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package com.stripe.android.payments.core.injection

import android.app.Application
import android.content.Context
import com.stripe.android.PaymentBrowserAuthStarter
import com.stripe.android.PaymentConfiguration
import com.stripe.android.PaymentRelayStarter
import com.stripe.android.core.networking.AnalyticsRequestFactory
import com.stripe.android.core.networking.ErrorReporter
import com.stripe.android.core.networking.NetworkTypeDetector
import com.stripe.android.core.networking.QErrorReporter
import com.stripe.android.core.utils.ContextUtils.packageInfo
import com.stripe.android.model.StripeIntent
import com.stripe.android.model.StripeIntent.NextActionData
import com.stripe.android.payments.DefaultReturnUrl
Expand All @@ -20,6 +27,7 @@ import dagger.Lazy
import dagger.Module
import dagger.Provides
import dagger.multibindings.IntoMap
import javax.inject.Provider
import javax.inject.Singleton

/**
Expand Down Expand Up @@ -95,13 +103,31 @@ internal abstract class AuthenticationModule {
@Binds
abstract fun bindsRedirectResolver(impl: RealRedirectResolver): RedirectResolver

@Binds
abstract fun bindsErrorReporter(impl : QErrorReporter) : ErrorReporter


companion object {
@Provides
@Singleton
fun provideDefaultReturnUrl(
context: Context
) = DefaultReturnUrl.create(context)


// TODO: I feel like I shouldn't have to rewrite this
@Provides
internal fun provideAnalyticsRequestFactory(
context: Context,
): AnalyticsRequestFactory = AnalyticsRequestFactory(
packageManager = context.packageManager,
packageName = context.packageName.orEmpty(),
packageInfo = context.packageInfo,
publishableKeyProvider = { PaymentConfiguration.getInstance(context = context).publishableKey },
networkTypeProvider = NetworkTypeDetector(context = context)::invoke,
)


@Provides
@Singleton
fun providePaymentRelayStarterFactory(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.stripe.android.payments.core.authentication

import org.junit.Test

class BoletoAuthenticatorTest {

// not sure how to actually test the authenticator, requires a lot of real-ish stuff

@Test
fun `error logged when stripe intent is incorrect type`() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.stripe.android.core.networking

interface ErrorReporter {
fun report(error : ErrorEvent, errorCode : Int?)

// TODO: add other error params here and then set them as additional params on the analytics event
enum class ErrorEvent(override val eventName : String) : AnalyticsEvent {
INCORRECT_NEXT_ACTION_TYPE(eventName = "boleto_incorrect_next_action_type"),
MISSING_HOSTED_VOUCHER_URL(eventName = "boleto_missing_hosted_voucher_url"),;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.stripe.android.core.networking

class FakeErrorReporter : ErrorReporter {

private val loggedErrors : MutableList<String> = mutableListOf()
override fun report(error: ErrorReporter.ErrorEvent) {
loggedErrors.add(error.eventName)
}

fun getLoggedErrors() : List<String> {
return loggedErrors.toList()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.stripe.android.core.networking

import javax.inject.Inject

class QErrorReporter @Inject constructor(
private val analyticsRequestExecutor: AnalyticsRequestExecutor,
private val analyticsRequestFactory: AnalyticsRequestFactory
) : ErrorReporter {
override fun report(error: ErrorReporter.ErrorEvent, errorCode : Int?) {
val additionalParams = mapOf("errorCode" to errorCode.toString())
analyticsRequestExecutor.executeAsync(analyticsRequestFactory.createRequest(error, additionalParams))
}
}