Skip to content

Commit

Permalink
Add support for Bancontact PaymentMethod (#2389)
Browse files Browse the repository at this point in the history
* Add support for Bancontact PaymentMethod

* Fix lint
  • Loading branch information
smaskell-stripe authored Apr 15, 2020
1 parent 38e4f68 commit 72263b3
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -497,6 +499,19 @@ data class PaymentMethodCreateParams internal constructor(
)
}

@JvmStatic
@JvmOverloads
internal fun createBancontact(
billingDetails: PaymentMethod.BillingDetails,
metadata: Map<String, String>? = 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ internal class PaymentMethodJsonParser : ModelJsonParser<PaymentMethod> {
SofortJsonParser().parse(it)
}
)
PaymentMethod.Type.P24 -> {
PaymentMethod.Type.P24, PaymentMethod.Type.Bancontact -> {
// no-op
}
}
Expand Down
1 change: 1 addition & 0 deletions stripe/src/test/java/com/stripe/android/ApiKeyFixtures.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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<InvalidRequestException>(
"A name is required to create a Bancontact payment method"
) {
Stripe(context, ApiKeyFixtures.BANCONTACT_PUBLISHABLE_KEY)
.createPaymentMethodSynchronous(params)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ internal object PaymentMethodCreateParamsFixtures {
billingDetails = BILLING_DETAILS
)

internal val BANCONTACT = PaymentMethodCreateParams.createBancontact(
billingDetails = BILLING_DETAILS
)

@JvmStatic
fun createWith(metadata: Map<String, String>): PaymentMethodCreateParams {
return PaymentMethodCreateParams.create(
Expand Down

0 comments on commit 72263b3

Please sign in to comment.