Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Bancontact PaymentMethod #2389

Merged
merged 2 commits into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

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