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 EPS PaymentMethod #2395

Merged
merged 5 commits into from
Apr 17, 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 @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -164,7 +164,8 @@ data class PaymentMethodCreateParams internal constructor(
Sofort("sofort"),
P24("p24"),
Bancontact("bancontact"),
Giropay("giropay")
Giropay("giropay"),
Eps("eps")
}

@Parcelize
Expand Down Expand Up @@ -525,6 +526,19 @@ data class PaymentMethodCreateParams internal constructor(
)
}

@JvmStatic
@JvmOverloads
internal fun createEps(
billingDetails: PaymentMethod.BillingDetails,
metadata: Map<String, String>? = 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ internal class PaymentMethodJsonParser : ModelJsonParser<PaymentMethod> {
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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<InvalidRequestException>(
"A name is required to create a EPS payment method"
) {
Stripe(context, ApiKeyFixtures.EPS_PUBLISHABLE_KEY)
.createPaymentMethodSynchronous(params)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ internal object PaymentMethodCreateParamsFixtures {
billingDetails = BILLING_DETAILS
)

internal val EPS = PaymentMethodCreateParams.createEps(
billingDetails = BILLING_DETAILS
)

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