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 3ceab1be51c..d67e81f128e 100644 --- a/stripe/src/main/java/com/stripe/android/model/PaymentMethod.kt +++ b/stripe/src/main/java/com/stripe/android/model/PaymentMethod.kt @@ -129,7 +129,8 @@ data class PaymentMethod internal constructor( Sofort("sofort", isReusable = false), P24("p24", isReusable = false), Bancontact("bancontact", isReusable = false), - Giropay("giropay", isReusable = false); + Giropay("giropay", isReusable = false), + Eps("eps", 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 20cc56e7994..008aa4d4467 100644 --- a/stripe/src/main/java/com/stripe/android/model/PaymentMethodCreateParams.kt +++ b/stripe/src/main/java/com/stripe/android/model/PaymentMethodCreateParams.kt @@ -148,7 +148,7 @@ data class PaymentMethodCreateParams internal constructor( Type.AuBecsDebit -> auBecsDebit?.toParamMap() Type.BacsDebit -> bacsDebit?.toParamMap() Type.Sofort -> sofort?.toParamMap() - Type.P24, Type.Bancontact, Type.Giropay -> null + Type.P24, Type.Bancontact, Type.Giropay, Type.Eps -> null }.takeUnless { it.isNullOrEmpty() }?.let { mapOf(type.code to it) }.orEmpty() @@ -164,7 +164,8 @@ data class PaymentMethodCreateParams internal constructor( Sofort("sofort"), P24("p24"), Bancontact("bancontact"), - Giropay("giropay") + Giropay("giropay"), + Eps("eps") } @Parcelize @@ -525,6 +526,19 @@ data class PaymentMethodCreateParams internal constructor( ) } + @JvmStatic + @JvmOverloads + internal fun createEps( + billingDetails: PaymentMethod.BillingDetails, + metadata: Map? = null + ): PaymentMethodCreateParams { + return PaymentMethodCreateParams( + type = Type.Eps, + 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 13ef8159063..86b27cca9c8 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,10 @@ internal class PaymentMethodJsonParser : ModelJsonParser { SofortJsonParser().parse(it) } ) - PaymentMethod.Type.P24, PaymentMethod.Type.Bancontact, PaymentMethod.Type.Giropay -> { + PaymentMethod.Type.P24, + PaymentMethod.Type.Bancontact, + PaymentMethod.Type.Giropay, + PaymentMethod.Type.Eps -> { // 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 c9d08c6638b..d2e69eef23e 100644 --- a/stripe/src/test/java/com/stripe/android/ApiKeyFixtures.kt +++ b/stripe/src/test/java/com/stripe/android/ApiKeyFixtures.kt @@ -14,4 +14,5 @@ internal object ApiKeyFixtures { const val P24_PUBLISHABLE_KEY = "pk_test_vOo1umqsYxSrP5UXfOeL3ecm" const val BANCONTACT_PUBLISHABLE_KEY = "pk_test_vOo1umqsYxSrP5UXfOeL3ecm" const val GIROPAY_PUBLISHABLE_KEY = "pk_test_vOo1umqsYxSrP5UXfOeL3ecm" + const val EPS_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 21605443fa0..8d828e820e3 100644 --- a/stripe/src/test/java/com/stripe/android/PaymentMethodEndToEndTest.kt +++ b/stripe/src/test/java/com/stripe/android/PaymentMethodEndToEndTest.kt @@ -106,4 +106,27 @@ class PaymentMethodEndToEndTest { .createPaymentMethodSynchronous(params) } } + + @Test + fun createPaymentMethod_withEps_shouldCreateObject() { + val params = PaymentMethodCreateParamsFixtures.EPS + val paymentMethod = + Stripe(context, ApiKeyFixtures.EPS_PUBLISHABLE_KEY) + .createPaymentMethodSynchronous(params) + assertThat(paymentMethod?.type) + .isEqualTo(PaymentMethod.Type.Eps) + } + + @Test + fun createPaymentMethod_withEps_missingName_shouldFail() { + val params = PaymentMethodCreateParams.createEps( + billingDetails = PaymentMethodCreateParamsFixtures.BILLING_DETAILS.copy(name = null) + ) + assertFailsWith( + "A name is required to create a EPS payment method" + ) { + Stripe(context, ApiKeyFixtures.EPS_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 70e6f1e2632..1fb515a4d6c 100644 --- a/stripe/src/test/java/com/stripe/android/model/PaymentMethodCreateParamsFixtures.kt +++ b/stripe/src/test/java/com/stripe/android/model/PaymentMethodCreateParamsFixtures.kt @@ -81,6 +81,10 @@ internal object PaymentMethodCreateParamsFixtures { billingDetails = BILLING_DETAILS ) + internal val EPS = PaymentMethodCreateParams.createEps( + billingDetails = BILLING_DETAILS + ) + @JvmStatic fun createWith(metadata: Map): PaymentMethodCreateParams { return PaymentMethodCreateParams.create(