Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ internal class FinancialConnectionsLiteRepositoryImpl(
) : FinancialConnectionsLiteRepository {

fun FinancialConnectionsSheetConfiguration.apiRequestOptions() = ApiRequest.Options(
publishableKeyProvider = { publishableKey },
stripeAccountIdProvider = { stripeAccountId },
apiKey = publishableKey,
stripeAccount = stripeAccountId,
)

override suspend fun synchronize(
Expand Down
24 changes: 14 additions & 10 deletions payments-core/api/payments-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,14 @@ public final class com/stripe/android/PaymentConfiguration : android/os/Parcelab
public static final field Companion Lcom/stripe/android/PaymentConfiguration$Companion;
public final fun describeContents ()I
public fun equals (Ljava/lang/Object;)Z
public final fun getBetas ()Ljava/util/Set;
public static final fun getInstance (Landroid/content/Context;)Lcom/stripe/android/PaymentConfiguration;
public final fun getPublishableKey ()Ljava/lang/String;
public final fun getStripeAccountId ()Ljava/lang/String;
public fun hashCode ()I
public static final fun init (Landroid/content/Context;Ljava/lang/String;)V
public static final fun init (Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;)V
public static final fun init (Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;Ljava/util/Set;)V
public fun toString ()Ljava/lang/String;
public final fun writeToParcel (Landroid/os/Parcel;I)V
}
Expand All @@ -378,7 +380,8 @@ public final class com/stripe/android/PaymentConfiguration$Companion {
public final fun getInstance (Landroid/content/Context;)Lcom/stripe/android/PaymentConfiguration;
public final fun init (Landroid/content/Context;Ljava/lang/String;)V
public final fun init (Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;)V
public static synthetic fun init$default (Lcom/stripe/android/PaymentConfiguration$Companion;Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)V
public final fun init (Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;Ljava/util/Set;)V
public static synthetic fun init$default (Lcom/stripe/android/PaymentConfiguration$Companion;Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;Ljava/util/Set;ILjava/lang/Object;)V
}

public final class com/stripe/android/PaymentIntentResult : com/stripe/android/StripeIntentResult {
Expand Down Expand Up @@ -589,14 +592,6 @@ public final class com/stripe/android/Stripe$Companion {
public final fun setAppInfo (Lcom/stripe/android/core/AppInfo;)V
}

public final class com/stripe/android/StripeApiBeta : java/lang/Enum {
public static final field WeChatPayV1 Lcom/stripe/android/StripeApiBeta;
public final fun getCode ()Ljava/lang/String;
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public static fun valueOf (Ljava/lang/String;)Lcom/stripe/android/StripeApiBeta;
public static fun values ()[Lcom/stripe/android/StripeApiBeta;
}

public abstract class com/stripe/android/StripeIntentResult : com/stripe/android/core/model/StripeModel {
public static final field $stable I
public fun equals (Ljava/lang/Object;)Z
Expand Down Expand Up @@ -2138,6 +2133,7 @@ public final class com/stripe/android/model/PaymentMethod$Type : java/lang/Enum,
public static final field Konbini Lcom/stripe/android/model/PaymentMethod$Type;
public static final field Link Lcom/stripe/android/model/PaymentMethod$Type;
public static final field MobilePay Lcom/stripe/android/model/PaymentMethod$Type;
public static final field Vipps Lcom/stripe/android/model/PaymentMethod$Type;
public static final field Multibanco Lcom/stripe/android/model/PaymentMethod$Type;
public static final field Netbanking Lcom/stripe/android/model/PaymentMethod$Type;
public static final field Oxxo Lcom/stripe/android/model/PaymentMethod$Type;
Expand Down Expand Up @@ -2333,6 +2329,10 @@ public final class com/stripe/android/model/PaymentMethodCreateParams : android/
public static final fun createMobilePay (Lcom/stripe/android/model/PaymentMethod$BillingDetails;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createMobilePay (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createMobilePay (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;Lcom/stripe/android/model/PaymentMethod$AllowRedisplay;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createVipps ()Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createVipps (Lcom/stripe/android/model/PaymentMethod$BillingDetails;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createVipps (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createVipps (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;Lcom/stripe/android/model/PaymentMethod$AllowRedisplay;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createMultibanco ()Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createMultibanco (Lcom/stripe/android/model/PaymentMethod$BillingDetails;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createMultibanco (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
Expand Down Expand Up @@ -2587,6 +2587,11 @@ public final class com/stripe/android/model/PaymentMethodCreateParams$Companion
public final fun createMobilePay (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createMobilePay (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;Lcom/stripe/android/model/PaymentMethod$AllowRedisplay;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static synthetic fun createMobilePay$default (Lcom/stripe/android/model/PaymentMethodCreateParams$Companion;Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;Lcom/stripe/android/model/PaymentMethod$AllowRedisplay;ILjava/lang/Object;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createVipps ()Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createVipps (Lcom/stripe/android/model/PaymentMethod$BillingDetails;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createVipps (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createVipps (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;Lcom/stripe/android/model/PaymentMethod$AllowRedisplay;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static synthetic fun createVipps$default (Lcom/stripe/android/model/PaymentMethodCreateParams$Companion;Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;Lcom/stripe/android/model/PaymentMethod$AllowRedisplay;ILjava/lang/Object;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createMultibanco ()Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createMultibanco (Lcom/stripe/android/model/PaymentMethod$BillingDetails;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createMultibanco (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
Expand Down Expand Up @@ -4323,4 +4328,3 @@ public final class com/stripe/android/view/i18n/TranslatorManager {
public final fun getErrorMessageTranslator ()Lcom/stripe/android/view/i18n/ErrorMessageTranslator;
public final fun setErrorMessageTranslator (Lcom/stripe/android/view/i18n/ErrorMessageTranslator;)V
}

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class PaymentConfiguration
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
constructor(
val publishableKey: String,
val stripeAccountId: String? = null
val stripeAccountId: String? = null,
val betas: Set<StripeApiBeta> = emptySet(),
) : Parcelable {

init {
Expand All @@ -36,11 +37,13 @@ constructor(
@JvmSynthetic
fun save(
publishableKey: String,
stripeAccountId: String?
stripeAccountId: String?,
betas: Set<StripeApiBeta>,
) {
prefs.edit()
.putString(KEY_PUBLISHABLE_KEY, publishableKey)
.putString(KEY_ACCOUNT_ID, stripeAccountId)
.putStringSet(KEY_BETAS, betas.mapTo(linkedSetOf()) { it.code })
.apply()
}

Expand All @@ -49,7 +52,10 @@ constructor(
return prefs.getString(KEY_PUBLISHABLE_KEY, null)?.let { publishableKey ->
PaymentConfiguration(
publishableKey = publishableKey,
stripeAccountId = prefs.getString(KEY_ACCOUNT_ID, null)
stripeAccountId = prefs.getString(KEY_ACCOUNT_ID, null),
betas = prefs.getStringSet(KEY_BETAS, linkedSetOf<String>()).orEmpty().mapNotNullTo(linkedSetOf()) { betaCode ->
StripeApiBeta.entries.firstOrNull { it.code == betaCode }
}
)
}
}
Expand All @@ -59,6 +65,7 @@ constructor(

private const val KEY_PUBLISHABLE_KEY = "key_publishable_key"
private const val KEY_ACCOUNT_ID = "key_account_id"
private const val KEY_BETAS = "key_betas"
}
}

Expand Down Expand Up @@ -95,16 +102,19 @@ constructor(
fun init(
context: Context,
publishableKey: String,
stripeAccountId: String? = null
stripeAccountId: String? = null,
betas: Set<StripeApiBeta> = emptySet(),
) {
instance = PaymentConfiguration(
publishableKey = publishableKey,
stripeAccountId = stripeAccountId
stripeAccountId = stripeAccountId,
betas = betas,
)
Store(context)
.save(
publishableKey = publishableKey,
stripeAccountId = stripeAccountId
stripeAccountId = stripeAccountId,
betas = betas,
)

DefaultFraudDetectionDataRepository(context).refresh()
Expand Down
9 changes: 6 additions & 3 deletions payments-core/src/main/java/com/stripe/android/Stripe.kt
Original file line number Diff line number Diff line change
Expand Up @@ -112,22 +112,25 @@ class Stripe internal constructor(
),
ApiKeyValidator.get().requireValid(publishableKey),
stripeAccountId,
enableLogging
enableLogging,
betas,
)

private constructor(
context: Context,
stripeRepository: StripeRepository,
publishableKey: String,
stripeAccountId: String?,
enableLogging: Boolean
enableLogging: Boolean,
betas: Set<StripeApiBeta> = emptySet(),
) : this(
stripeRepository,
StripePaymentController(
context.applicationContext,
{ publishableKey },
stripeRepository,
enableLogging
enableLogging,
betasProvider = { betas },
),
publishableKey,
stripeAccountId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,23 @@ constructor(
private val paymentAnalyticsRequestFactory: PaymentAnalyticsRequestFactory =
PaymentAnalyticsRequestFactory(context.applicationContext, publishableKeyProvider),
private val alipayRepository: AlipayRepository = DefaultAlipayRepository(stripeRepository),
private val uiContext: CoroutineContext = Dispatchers.Main
private val uiContext: CoroutineContext = Dispatchers.Main,
private val betasProvider: () -> Set<StripeApiBeta> = { emptySet() },
) : PaymentController {

private val failureMessageFactory = PaymentFlowFailureMessageFactory(context)
private val paymentIntentFlowResultProcessor = PaymentIntentFlowResultProcessor(
context,
publishableKeyProvider,
betasProvider(),
stripeRepository,
Logger.getInstance(enableLogging),
workContext
)
private val setupIntentFlowResultProcessor = SetupIntentFlowResultProcessor(
context,
publishableKeyProvider,
betasProvider(),
stripeRepository,
Logger.getInstance(enableLogging),
workContext
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.stripe.android.googlepaylauncher.injection

import com.stripe.android.StripeApiBeta
import com.stripe.android.core.injection.STRIPE_API_BETAS
import com.stripe.android.core.networking.AnalyticsRequestFactory
import com.stripe.android.googlepaylauncher.DefaultGooglePayRepository
import com.stripe.android.googlepaylauncher.DefaultPaymentsClientFactory
Expand All @@ -12,7 +14,9 @@ import com.stripe.android.payments.core.analytics.RealErrorReporter
import dagger.Binds
import dagger.Module
import dagger.Provides
import javax.inject.Named
import javax.inject.Singleton
import kotlin.jvm.JvmSuppressWildcards

@Module(
subcomponents = [GooglePayPaymentMethodLauncherViewModelSubcomponent::class]
Expand Down Expand Up @@ -50,5 +54,9 @@ internal abstract class GooglePayPaymentMethodLauncherModule {
googlePayConfig: GooglePayPaymentMethodLauncher.Config,
paymentsClientFactory: PaymentsClientFactory
) = paymentsClientFactory.create(googlePayConfig.environment)

@Provides
@Named(STRIPE_API_BETAS)
fun provideStripeApiBetas(): Set<@JvmSuppressWildcards StripeApiBeta> = emptySet()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,14 @@ constructor(
requiresMandateForPaymentIntent = false,
hasDelayedSettlement = false,
),
Vipps(
"vipps",
isReusable = false,
isVoucher = false,
requiresMandate = false,
requiresMandateForPaymentIntent = false,
hasDelayedSettlement = false,
),
Multibanco(
"multibanco",
isReusable = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,21 @@ constructor(
)
}

@JvmStatic
@JvmOverloads
fun createVipps(
billingDetails: PaymentMethod.BillingDetails? = null,
metadata: Map<String, String>? = null,
allowRedisplay: PaymentMethod.AllowRedisplay? = null,
): PaymentMethodCreateParams {
return PaymentMethodCreateParams(
type = PaymentMethod.Type.Vipps,
billingDetails = billingDetails,
metadata = metadata,
allowRedisplay = allowRedisplay,
)
}

@JvmStatic
@JvmOverloads
fun createTwint(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package com.stripe.android.payments
import android.content.Context
import com.stripe.android.PaymentController
import com.stripe.android.PaymentIntentResult
import com.stripe.android.StripeApiBeta
import com.stripe.android.SetupIntentResult
import com.stripe.android.StripeIntentResult
import com.stripe.android.StripeIntentResult.Outcome.Companion.CANCELED
import com.stripe.android.StripeIntentResult.Outcome.Companion.SUCCEEDED
import com.stripe.android.core.Logger
import com.stripe.android.core.injection.IOContext
import com.stripe.android.core.injection.PUBLISHABLE_KEY
import com.stripe.android.core.injection.STRIPE_API_BETAS
import com.stripe.android.core.networking.ApiRequest
import com.stripe.android.model.PaymentIntent
import com.stripe.android.model.PaymentMethod
Expand All @@ -22,16 +24,17 @@ import kotlinx.coroutines.withContext
import kotlinx.coroutines.withTimeoutOrNull
import javax.inject.Inject
import javax.inject.Named
import javax.inject.Provider
import javax.inject.Singleton
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmSuppressWildcards

/**
* Class responsible for processing the result of a [PaymentController] confirm operation.
*/
internal sealed class PaymentFlowResultProcessor<T : StripeIntent, out S : StripeIntentResult<T>>(
context: Context,
private val publishableKeyProvider: Provider<String>,
private val publishableKeyProvider: () -> String,
private val betasProvider: () -> Set<@JvmSuppressWildcards StripeApiBeta>,
protected val stripeRepository: StripeRepository,
private val logger: Logger,
private val workContext: CoroutineContext,
Expand All @@ -46,8 +49,9 @@ internal sealed class PaymentFlowResultProcessor<T : StripeIntent, out S : Strip
}

val requestOptions = ApiRequest.Options(
apiKey = publishableKeyProvider.get(),
stripeAccount = result.stripeAccountId
apiKey = publishableKeyProvider(),
stripeAccount = result.stripeAccountId,
betas = betasProvider(),
)

val initialRetrieveIntentStartTime = System.currentTimeMillis()
Expand Down Expand Up @@ -310,12 +314,14 @@ internal sealed class PaymentFlowResultProcessor<T : StripeIntent, out S : Strip
internal class PaymentIntentFlowResultProcessor @Inject constructor(
context: Context,
@Named(PUBLISHABLE_KEY) publishableKeyProvider: () -> String,
@Named(STRIPE_API_BETAS) betas: Set<@JvmSuppressWildcards StripeApiBeta>,
stripeRepository: StripeRepository,
logger: Logger,
@IOContext workContext: CoroutineContext
) : PaymentFlowResultProcessor<PaymentIntent, PaymentIntentResult>(
context,
publishableKeyProvider,
{ betas },
stripeRepository,
logger,
workContext
Expand Down Expand Up @@ -374,12 +380,14 @@ internal class PaymentIntentFlowResultProcessor @Inject constructor(
internal class SetupIntentFlowResultProcessor @Inject constructor(
context: Context,
@Named(PUBLISHABLE_KEY) publishableKeyProvider: () -> String,
@Named(STRIPE_API_BETAS) betas: Set<@JvmSuppressWildcards StripeApiBeta>,
stripeRepository: StripeRepository,
logger: Logger,
@IOContext workContext: CoroutineContext
) : PaymentFlowResultProcessor<SetupIntent, SetupIntentResult>(
context,
publishableKeyProvider,
{ betas },
stripeRepository,
logger,
workContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ package com.stripe.android.payments.core.injection
import android.content.Context
import androidx.annotation.RestrictTo
import com.stripe.android.PaymentConfiguration
import com.stripe.android.StripeApiBeta
import com.stripe.android.core.injection.PUBLISHABLE_KEY
import com.stripe.android.core.injection.STRIPE_API_BETAS
import com.stripe.android.core.injection.STRIPE_ACCOUNT_ID
import dagger.Module
import dagger.Provides
import javax.inject.Named
import javax.inject.Provider
import kotlin.jvm.JvmSuppressWildcards

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
@Module
Expand All @@ -29,4 +32,10 @@ class PaymentConfigurationModule {
fun provideStripeAccountId(
paymentConfiguration: Provider<PaymentConfiguration>
): () -> String? = { paymentConfiguration.get().stripeAccountId }

@Provides
@Named(STRIPE_API_BETAS)
fun provideStripeApiBetas(
paymentConfiguration: Provider<PaymentConfiguration>
): Set<@JvmSuppressWildcards StripeApiBeta> = paymentConfiguration.get().betas
}
Loading