diff --git a/example/src/main/java/com/stripe/example/Settings.kt b/example/src/main/java/com/stripe/example/Settings.kt index 8de95c09e11..39acb452ef4 100644 --- a/example/src/main/java/com/stripe/example/Settings.kt +++ b/example/src/main/java/com/stripe/example/Settings.kt @@ -36,7 +36,7 @@ class Settings(context: Context) { .takeIf { it?.isNotBlank() == true } } - private companion object { + internal companion object { /** * Note: only necessary if not configured via `gradle.properties`. * @@ -62,6 +62,13 @@ class Settings(context: Context) { */ private val STRIPE_ACCOUNT_ID: String? = null + // Example payment sheet backend with a "/checkout" endpoint + // Remix from https://glitch.com/edit/#!/stripe-mobile-payment-sheet-test-playground-v3 + internal const val PAYMENT_SHEET_BASE_URL = "" + + // Publishable key for example payment sheet backend + internal const val PAYMENT_SHEET_PUBLISHABLE_KEY = "" + private const val METADATA_KEY_BACKEND_URL_KEY = "com.stripe.example.metadata.backend_url" private const val METADATA_KEY_PUBLISHABLE_KEY = diff --git a/example/src/main/java/com/stripe/example/activity/LaunchPaymentSheetCustomActivity.kt b/example/src/main/java/com/stripe/example/activity/LaunchPaymentSheetCustomActivity.kt index 8c1b8a47f3d..17cfdbcf123 100644 --- a/example/src/main/java/com/stripe/example/activity/LaunchPaymentSheetCustomActivity.kt +++ b/example/src/main/java/com/stripe/example/activity/LaunchPaymentSheetCustomActivity.kt @@ -4,10 +4,12 @@ import android.os.Bundle import android.view.Menu import android.view.MenuItem import androidx.core.view.isInvisible +import com.stripe.android.PaymentConfiguration import com.stripe.android.paymentsheet.PaymentSheet import com.stripe.android.paymentsheet.PaymentSheetResult import com.stripe.android.paymentsheet.model.PaymentOption import com.stripe.example.R +import com.stripe.example.Settings import com.stripe.example.databinding.ActivityPaymentSheetCustomBinding internal class LaunchPaymentSheetCustomActivity : BasePaymentSheetActivity() { @@ -21,6 +23,9 @@ internal class LaunchPaymentSheetCustomActivity : BasePaymentSheetActivity() { super.onCreate(savedInstanceState) setContentView(viewBinding.root) + // TODO(brnunes-stripe): Remove this once FlowController initialization is refactored. + PaymentConfiguration.init(this, Settings.PAYMENT_SHEET_PUBLISHABLE_KEY) + flowController = PaymentSheet.FlowController.create( this, ::onPaymentOption, diff --git a/example/src/main/java/com/stripe/example/module/BackendApiFactory.kt b/example/src/main/java/com/stripe/example/module/BackendApiFactory.kt index 78a1a93b46e..55076ef94bd 100644 --- a/example/src/main/java/com/stripe/example/module/BackendApiFactory.kt +++ b/example/src/main/java/com/stripe/example/module/BackendApiFactory.kt @@ -49,6 +49,15 @@ internal class BackendApiFactory internal constructor(private val backendUrl: St @OptIn(ExperimentalSerializationApi::class) fun createCheckout(): CheckoutBackendApi { + if (Settings.PAYMENT_SHEET_BASE_URL.isNullOrEmpty() || + Settings.PAYMENT_SHEET_PUBLISHABLE_KEY.isNullOrEmpty() + ) { + error( + "Settings.PAYMENT_SHEET_BASE_URL and Settings.PAYMENT_SHEET_PUBLISHABLE_KEY " + + "must be set for PaymentSheet example" + ) + } + val logging = HttpLoggingInterceptor() .setLevel(HttpLoggingInterceptor.Level.BODY) @@ -60,7 +69,7 @@ internal class BackendApiFactory internal constructor(private val backendUrl: St return Retrofit.Builder() .addConverterFactory(Json.asConverterFactory("application/json".toMediaType())) - .baseUrl(backendUrl) + .baseUrl(Settings.PAYMENT_SHEET_BASE_URL) .client(httpClient) .build() .create(CheckoutBackendApi::class.java)