diff --git a/stripe/src/main/java/com/stripe/android/model/PaymentMethod.kt b/stripe/src/main/java/com/stripe/android/model/PaymentMethod.kt index e8c1654bcb0..d94cb07d7b6 100644 --- a/stripe/src/main/java/com/stripe/android/model/PaymentMethod.kt +++ b/stripe/src/main/java/com/stripe/android/model/PaymentMethod.kt @@ -127,7 +127,8 @@ data class PaymentMethod internal constructor( AuBecsDebit("au_becs_debit"), BacsDebit("bacs_debit"), Sofort("sofort", isReusable = false), - P24("p24", isReusable = false); + P24("p24", isReusable = false), + Bancontact("bancontact", isReusable = false); override fun toString(): String { return code diff --git a/stripe/src/main/java/com/stripe/android/model/PaymentMethodCreateParams.kt b/stripe/src/main/java/com/stripe/android/model/PaymentMethodCreateParams.kt index f99960bb326..e2e9b0a5265 100644 --- a/stripe/src/main/java/com/stripe/android/model/PaymentMethodCreateParams.kt +++ b/stripe/src/main/java/com/stripe/android/model/PaymentMethodCreateParams.kt @@ -149,6 +149,7 @@ data class PaymentMethodCreateParams internal constructor( Type.BacsDebit -> bacsDebit?.toParamMap() Type.Sofort -> sofort?.toParamMap() Type.P24 -> null + Type.Bancontact -> null }.takeUnless { it.isNullOrEmpty() }?.let { mapOf(type.code to it) }.orEmpty() @@ -162,7 +163,8 @@ data class PaymentMethodCreateParams internal constructor( AuBecsDebit("au_becs_debit", true), BacsDebit("bacs_debit", true), Sofort("sofort"), - P24("p24") + P24("p24"), + Bancontact("bancontact") } @Parcelize @@ -497,6 +499,19 @@ data class PaymentMethodCreateParams internal constructor( ) } + @JvmStatic + @JvmOverloads + internal fun createBancontact( + billingDetails: PaymentMethod.BillingDetails, + metadata: Map? = null + ): PaymentMethodCreateParams { + return PaymentMethodCreateParams( + type = Type.Bancontact, + billingDetails = billingDetails, + metadata = metadata + ) + } + /** * @param googlePayPaymentData a [JSONObject] derived from Google Pay's * [PaymentData#toJson()](https://developers.google.com/pay/api/android/reference/client#tojson) diff --git a/stripe/src/main/java/com/stripe/android/model/parsers/PaymentMethodJsonParser.kt b/stripe/src/main/java/com/stripe/android/model/parsers/PaymentMethodJsonParser.kt index 9bb6a811b8a..a20fdbf58d9 100644 --- a/stripe/src/main/java/com/stripe/android/model/parsers/PaymentMethodJsonParser.kt +++ b/stripe/src/main/java/com/stripe/android/model/parsers/PaymentMethodJsonParser.kt @@ -66,7 +66,7 @@ internal class PaymentMethodJsonParser : ModelJsonParser { SofortJsonParser().parse(it) } ) - PaymentMethod.Type.P24 -> { + PaymentMethod.Type.P24, PaymentMethod.Type.Bancontact -> { // no-op } } diff --git a/stripe/src/test/java/com/stripe/android/ApiKeyFixtures.kt b/stripe/src/test/java/com/stripe/android/ApiKeyFixtures.kt index 494e625fef8..e0ced081597 100644 --- a/stripe/src/test/java/com/stripe/android/ApiKeyFixtures.kt +++ b/stripe/src/test/java/com/stripe/android/ApiKeyFixtures.kt @@ -12,4 +12,5 @@ internal object ApiKeyFixtures { const val BACS_PUBLISHABLE_KEY = "pk_test_z6Ct4bpx0NUjHii0rsi4XZBf00jmM8qA28" const val SOFORT_PUBLISHABLE_KEY = "pk_test_vOo1umqsYxSrP5UXfOeL3ecm" const val P24_PUBLISHABLE_KEY = "pk_test_vOo1umqsYxSrP5UXfOeL3ecm" + const val BANCONTACT_PUBLISHABLE_KEY = "pk_test_vOo1umqsYxSrP5UXfOeL3ecm" } diff --git a/stripe/src/test/java/com/stripe/android/PaymentMethodEndToEndTest.kt b/stripe/src/test/java/com/stripe/android/PaymentMethodEndToEndTest.kt index c97dcb4776d..117bc8e2f3b 100644 --- a/stripe/src/test/java/com/stripe/android/PaymentMethodEndToEndTest.kt +++ b/stripe/src/test/java/com/stripe/android/PaymentMethodEndToEndTest.kt @@ -3,9 +3,12 @@ package com.stripe.android import android.content.Context import androidx.test.core.app.ApplicationProvider import com.google.common.truth.Truth.assertThat +import com.stripe.android.exception.InvalidRequestException import com.stripe.android.model.PaymentMethod +import com.stripe.android.model.PaymentMethodCreateParams import com.stripe.android.model.PaymentMethodCreateParamsFixtures import kotlin.test.Test +import kotlin.test.assertFailsWith import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner @@ -57,4 +60,27 @@ class PaymentMethodEndToEndTest { assertThat(paymentMethod?.type) .isEqualTo(PaymentMethod.Type.P24) } + + @Test + fun createPaymentMethod_withBancontact_shouldCreateObject() { + val params = PaymentMethodCreateParamsFixtures.BANCONTACT + val paymentMethod = + Stripe(context, ApiKeyFixtures.BANCONTACT_PUBLISHABLE_KEY) + .createPaymentMethodSynchronous(params) + assertThat(paymentMethod?.type) + .isEqualTo(PaymentMethod.Type.Bancontact) + } + + @Test + fun createPaymentMethod_withBancontact_missingName_shouldFail() { + val params = PaymentMethodCreateParams.createBancontact( + billingDetails = PaymentMethodCreateParamsFixtures.BILLING_DETAILS.copy(name = null) + ) + assertFailsWith( + "A name is required to create a Bancontact payment method" + ) { + Stripe(context, ApiKeyFixtures.BANCONTACT_PUBLISHABLE_KEY) + .createPaymentMethodSynchronous(params) + } + } } diff --git a/stripe/src/test/java/com/stripe/android/model/PaymentMethodCreateParamsFixtures.kt b/stripe/src/test/java/com/stripe/android/model/PaymentMethodCreateParamsFixtures.kt index c7138351a2c..cb0ebf72b64 100644 --- a/stripe/src/test/java/com/stripe/android/model/PaymentMethodCreateParamsFixtures.kt +++ b/stripe/src/test/java/com/stripe/android/model/PaymentMethodCreateParamsFixtures.kt @@ -73,6 +73,10 @@ internal object PaymentMethodCreateParamsFixtures { billingDetails = BILLING_DETAILS ) + internal val BANCONTACT = PaymentMethodCreateParams.createBancontact( + billingDetails = BILLING_DETAILS + ) + @JvmStatic fun createWith(metadata: Map): PaymentMethodCreateParams { return PaymentMethodCreateParams.create(