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 3 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 @@ -128,7 +128,9 @@ data class PaymentMethod internal constructor(
BacsDebit("bacs_debit"),
Sofort("sofort", isReusable = false),
P24("p24", isReusable = false),
Bancontact("bancontact", isReusable = false);
Bancontact("bancontact", 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,8 +148,7 @@ data class PaymentMethodCreateParams internal constructor(
Type.AuBecsDebit -> auBecsDebit?.toParamMap()
Type.BacsDebit -> bacsDebit?.toParamMap()
Type.Sofort -> sofort?.toParamMap()
Type.P24 -> null
Type.Bancontact -> null
Type.P24, Type.Bancontact, Type.Giropay, Type.EPS -> null
}.takeUnless { it.isNullOrEmpty() }?.let {
mapOf(type.code to it)
}.orEmpty()
Expand All @@ -164,7 +163,9 @@ data class PaymentMethodCreateParams internal constructor(
BacsDebit("bacs_debit", true),
Sofort("sofort"),
P24("p24"),
Bancontact("bancontact")
Bancontact("bancontact"),
Giropay("giropay"),
EPS("eps")
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's make this Eps to be consistent with the other types (e.g. FPX is Fpx)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

}

@Parcelize
Expand Down Expand Up @@ -512,6 +513,32 @@ data class PaymentMethodCreateParams internal constructor(
)
}

@JvmStatic
@JvmOverloads
internal fun createGiropay(
billingDetails: PaymentMethod.BillingDetails,
metadata: Map<String, String>? = null
): PaymentMethodCreateParams {
return PaymentMethodCreateParams(
type = Type.Giropay,
billingDetails = billingDetails,
metadata = metadata
)
}

@JvmStatic
@JvmOverloads
internal fun createEPS(
Copy link
Collaborator

Choose a reason for hiding this comment

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

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.P24,
PaymentMethod.Type.Bancontact,
PaymentMethod.Type.Giropay,
PaymentMethod.Type.EPS -> {
// no-op
}
}
Expand Down
2 changes: 2 additions & 0 deletions stripe/src/test/java/com/stripe/android/ApiKeyFixtures.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ internal object ApiKeyFixtures {
const val SOFORT_PUBLISHABLE_KEY = "pk_test_vOo1umqsYxSrP5UXfOeL3ecm"
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 @@ -83,4 +83,50 @@ class PaymentMethodEndToEndTest {
.createPaymentMethodSynchronous(params)
}
}

@Test
fun createPaymentMethod_withGiropay_shouldCreateObject() {
val params = PaymentMethodCreateParamsFixtures.GIROPAY
val paymentMethod =
Stripe(context, ApiKeyFixtures.GIROPAY_PUBLISHABLE_KEY)
.createPaymentMethodSynchronous(params)
assertThat(paymentMethod?.type)
.isEqualTo(PaymentMethod.Type.Giropay)
}

@Test
fun createPaymentMethod_withGiropay_missingName_shouldFail() {
val params = PaymentMethodCreateParams.createGiropay(
billingDetails = PaymentMethodCreateParamsFixtures.BILLING_DETAILS.copy(name = null)
)
assertFailsWith<InvalidRequestException>(
"A name is required to create a Giropay payment method"
) {
Stripe(context, ApiKeyFixtures.GIROPAY_PUBLISHABLE_KEY)
.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 @@ -77,6 +77,14 @@ internal object PaymentMethodCreateParamsFixtures {
billingDetails = BILLING_DETAILS
)

internal val GIROPAY = PaymentMethodCreateParams.createGiropay(
billingDetails = BILLING_DETAILS
)

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

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