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 fad39a71440..f8721434471 100644 --- a/stripe/src/main/java/com/stripe/android/model/PaymentMethodCreateParams.kt +++ b/stripe/src/main/java/com/stripe/android/model/PaymentMethodCreateParams.kt @@ -3,6 +3,7 @@ package com.stripe.android.model import android.os.Parcelable import com.stripe.android.ObjectBuilder import com.stripe.android.Stripe +import java.util.Locale import kotlinx.android.parcel.Parcelize import org.json.JSONException import org.json.JSONObject @@ -19,13 +20,17 @@ import org.json.JSONObject @Parcelize data class PaymentMethodCreateParams internal constructor( internal val type: Type, + private val card: Card? = null, private val ideal: Ideal? = null, private val fpx: Fpx? = null, private val sepaDebit: SepaDebit? = null, private val auBecsDebit: AuBecsDebit? = null, private val bacsDebit: BacsDebit? = null, + private val sofort: Sofort? = null, + private val billingDetails: PaymentMethod.BillingDetails? = null, + private val metadata: Map? = null, private val productUsage: Set = emptySet() ) : StripeParamsModel, Parcelable { @@ -108,6 +113,17 @@ data class PaymentMethodCreateParams internal constructor( metadata = metadata ) + private constructor( + sofort: Sofort, + billingDetails: PaymentMethod.BillingDetails?, + metadata: Map? + ) : this( + type = Type.Sofort, + sofort = sofort, + billingDetails = billingDetails, + metadata = metadata + ) + override fun toParamMap(): Map { return mapOf( PARAM_TYPE to type.code @@ -124,6 +140,7 @@ data class PaymentMethodCreateParams internal constructor( Type.SepaDebit -> sepaDebit?.toParamMap().orEmpty() Type.AuBecsDebit -> auBecsDebit?.toParamMap().orEmpty() Type.BacsDebit -> bacsDebit?.toParamMap().orEmpty() + Type.Sofort -> sofort?.toParamMap().orEmpty() } ) ).plus( @@ -139,7 +156,8 @@ data class PaymentMethodCreateParams internal constructor( Fpx("fpx"), SepaDebit("sepa_debit", true), AuBecsDebit("au_becs_debit", true), - BacsDebit("bacs_debit", true) + BacsDebit("bacs_debit", true), + Sofort("sofort") } @Parcelize @@ -347,6 +365,21 @@ data class PaymentMethodCreateParams internal constructor( } } + @Parcelize + data class Sofort( + internal var country: String + ) : StripeParamsModel, Parcelable { + override fun toParamMap(): Map { + return mapOf( + PARAM_COUNTRY to country.toUpperCase(Locale.ROOT) + ) + } + + private companion object { + private const val PARAM_COUNTRY = "country" + } + } + companion object { private const val PARAM_TYPE = "type" private const val PARAM_BILLING_DETAILS = "billing_details" @@ -418,7 +451,7 @@ data class PaymentMethodCreateParams internal constructor( } /** - * @return params for creating a `PaymentMethod.Type.BacsDebit` payment method + * @return params for creating a [PaymentMethod.Type.BacsDebit] payment method */ @JvmStatic @JvmOverloads @@ -430,6 +463,19 @@ data class PaymentMethodCreateParams internal constructor( return PaymentMethodCreateParams(bacsDebit, billingDetails, metadata) } + /** + * @return params for creating a `SOFORT` payment method + */ + @JvmStatic + @JvmOverloads + internal fun create( + sofort: Sofort, + billingDetails: PaymentMethod.BillingDetails? = null, + metadata: Map? = null + ): PaymentMethodCreateParams { + return PaymentMethodCreateParams(sofort, billingDetails, 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/test/java/com/stripe/android/ApiKeyFixtures.kt b/stripe/src/test/java/com/stripe/android/ApiKeyFixtures.kt index 319405806d0..e43797b7e9c 100644 --- a/stripe/src/test/java/com/stripe/android/ApiKeyFixtures.kt +++ b/stripe/src/test/java/com/stripe/android/ApiKeyFixtures.kt @@ -10,4 +10,5 @@ internal object ApiKeyFixtures { const val AU_BECS_DEBIT_PUBLISHABLE_KEY = "pk_test_Bfx5IwoTeK7kUbfS15dcgTrs00beFpWwto" const val KLARNA_PUBLISHABLE_KEY = "pk_test_8JUGw3jTOFqWQOt5nr2pjzF9" const val BACS_PUBLISHABLE_KEY = "pk_test_z6Ct4bpx0NUjHii0rsi4XZBf00jmM8qA28" + const val SOFORT_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 5e4a0fd451b..f4a27a6e507 100644 --- a/stripe/src/test/java/com/stripe/android/PaymentMethodEndToEndTest.kt +++ b/stripe/src/test/java/com/stripe/android/PaymentMethodEndToEndTest.kt @@ -31,4 +31,14 @@ class PaymentMethodEndToEndTest { ) ) } + + @Test + fun createPaymentMethod_withSofort_shouldCreateObject() { + val params = PaymentMethodCreateParamsFixtures.SOFORT + val paymentMethod = + Stripe(context, ApiKeyFixtures.SOFORT_PUBLISHABLE_KEY) + .createPaymentMethodSynchronous(params) + assertThat(paymentMethod) + .isNotNull() + } } 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 abc7deea1a0..1f8534aad60 100644 --- a/stripe/src/test/java/com/stripe/android/model/PaymentMethodCreateParamsFixtures.kt +++ b/stripe/src/test/java/com/stripe/android/model/PaymentMethodCreateParamsFixtures.kt @@ -62,6 +62,13 @@ internal object PaymentMethodCreateParamsFixtures { billingDetails = BILLING_DETAILS ) + internal val SOFORT = PaymentMethodCreateParams.create( + sofort = PaymentMethodCreateParams.Sofort( + country = "de" + ), + billingDetails = BILLING_DETAILS + ) + @JvmStatic fun createWith(metadata: Map): PaymentMethodCreateParams { return PaymentMethodCreateParams.create(