Skip to content

Commit

Permalink
Add support for SOFORT PaymentMethod
Browse files Browse the repository at this point in the history
ANDROID-510
  • Loading branch information
mshafrir-stripe committed Apr 15, 2020
1 parent a3434a0 commit 81babf8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
22 changes: 18 additions & 4 deletions stripe/src/main/java/com/stripe/android/model/PaymentMethod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ data class PaymentMethod internal constructor(

@JvmField val auBecsDebit: AuBecsDebit? = null,

@JvmField val bacsDebit: BacsDebit? = null
@JvmField val bacsDebit: BacsDebit? = null,

@JvmField val sofort: Sofort? = null
) : StripeModel {

@Parcelize
Expand All @@ -119,11 +121,12 @@ data class PaymentMethod internal constructor(
) : Parcelable {
Card("card"),
CardPresent("card_present"),
Fpx("fpx", false),
Fpx("fpx", isReusable = false),
Ideal("ideal"),
SepaDebit("sepa_debit"),
AuBecsDebit("au_becs_debit"),
BacsDebit("bacs_debit");
BacsDebit("bacs_debit"),
Sofort("sofort", isReusable = false);

override fun toString(): String {
return code
Expand Down Expand Up @@ -152,6 +155,7 @@ data class PaymentMethod internal constructor(
private var sepaDebit: SepaDebit? = null
private var auBecsDebit: AuBecsDebit? = null
private var bacsDebit: BacsDebit? = null
private var sofort: Sofort? = null

fun setId(id: String?): Builder = apply {
this.id = id
Expand Down Expand Up @@ -209,6 +213,10 @@ data class PaymentMethod internal constructor(
this.bacsDebit = bacsDebit
}

fun setSofort(sofort: Sofort?): Builder = apply {
this.sofort = sofort
}

override fun build(): PaymentMethod {
return PaymentMethod(
id = id,
Expand All @@ -224,7 +232,8 @@ data class PaymentMethod internal constructor(
ideal = ideal,
sepaDebit = sepaDebit,
auBecsDebit = auBecsDebit,
bacsDebit = bacsDebit
bacsDebit = bacsDebit,
sofort = sofort
)
}
}
Expand Down Expand Up @@ -644,6 +653,11 @@ data class PaymentMethod internal constructor(
@JvmField val sortCode: String?
) : StripeModel

@Parcelize
data class Sofort internal constructor(
@JvmField val country: String?
) : StripeModel

companion object {
@JvmStatic
fun fromJson(paymentMethod: JSONObject?): PaymentMethod? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ internal class PaymentMethodJsonParser : ModelJsonParser<PaymentMethod> {
BacsDebitJsonParser().parse(it)
}
)
PaymentMethod.Type.Sofort ->
builder.setSofort(
json.optJSONObject(type.code)?.let {
SofortJsonParser().parse(it)
}
)
}

return builder.build()
Expand Down Expand Up @@ -256,6 +262,18 @@ internal class PaymentMethodJsonParser : ModelJsonParser<PaymentMethod> {
}
}

internal class SofortJsonParser : ModelJsonParser<PaymentMethod.Sofort> {
override fun parse(json: JSONObject): PaymentMethod.Sofort {
return PaymentMethod.Sofort(
country = StripeJsonUtils.optString(json, FIELD_COUNTRY)
)
}

private companion object {
private const val FIELD_COUNTRY = "country"
}
}

private companion object {
private const val FIELD_ID = "id"
private const val FIELD_BILLING_DETAILS = "billing_details"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ class PaymentMethodEndToEndTest {
val paymentMethod =
Stripe(context, ApiKeyFixtures.SOFORT_PUBLISHABLE_KEY)
.createPaymentMethodSynchronous(params)
assertThat(paymentMethod)
.isNotNull()
assertThat(paymentMethod?.type)
.isEqualTo(PaymentMethod.Type.Sofort)
assertThat(paymentMethod?.sofort)
.isEqualTo(
PaymentMethod.Sofort(
country = "DE"
)
)
}
}

0 comments on commit 81babf8

Please sign in to comment.