-
Notifications
You must be signed in to change notification settings - Fork 659
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Bank Account as source on Customer object (#2641)
Fixes #2601
- Loading branch information
1 parent
045a4c4
commit a0c91b8
Showing
6 changed files
with
101 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 7 additions & 10 deletions
17
stripe/src/main/java/com/stripe/android/model/parsers/CustomerSourceJsonParser.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,22 @@ | ||
package com.stripe.android.model.parsers | ||
|
||
import com.stripe.android.model.Card | ||
import com.stripe.android.model.CustomerSource | ||
import com.stripe.android.model.Source | ||
import com.stripe.android.model.StripeJsonUtils | ||
import com.stripe.android.model.StripeJsonUtils.optString | ||
import com.stripe.android.model.StripePaymentSource | ||
import org.json.JSONObject | ||
|
||
internal class CustomerSourceJsonParser : ModelJsonParser<CustomerSource> { | ||
override fun parse(json: JSONObject): CustomerSource? { | ||
val sourceObject: StripePaymentSource? = | ||
when (StripeJsonUtils.optString(json, "object")) { | ||
Card.OBJECT_TYPE -> CardJsonParser().parse(json) | ||
Source.OBJECT_TYPE -> SourceJsonParser().parse(json) | ||
when (optString(json, "object")) { | ||
"card" -> CardJsonParser().parse(json) | ||
"source" -> SourceJsonParser().parse(json) | ||
"bank_account" -> BankAccountJsonParser().parse(json) | ||
else -> null | ||
} | ||
|
||
return if (sourceObject == null) { | ||
null | ||
} else { | ||
CustomerSource(sourceObject) | ||
return sourceObject?.let { | ||
CustomerSource(it) | ||
} | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
stripe/src/test/java/com/stripe/android/model/parsers/CustomerJsonParserTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.stripe.android.model.parsers | ||
|
||
import com.google.common.truth.Truth.assertThat | ||
import com.stripe.android.model.BankAccount | ||
import com.stripe.android.model.Customer | ||
import com.stripe.android.model.CustomerSource | ||
import kotlin.test.Test | ||
import org.json.JSONObject | ||
|
||
class CustomerJsonParserTest { | ||
|
||
@Test | ||
fun `should correctly parse Customer with BankAccount source`() { | ||
assertThat( | ||
CustomerJsonParser() | ||
.parse(CUSTOMER_JSON) | ||
).isEqualTo( | ||
Customer( | ||
id = "cus_HcLIwF3BCi", | ||
defaultSource = "ba_1H3NOMCRMbs6FrXfahj", | ||
shippingInformation = null, | ||
sources = listOf( | ||
CustomerSource( | ||
BankAccount( | ||
id = "ba_1H3NOMCRMbs6FrXfahj", | ||
accountHolderName = "Test Bank Account", | ||
accountHolderType = BankAccount.Type.Individual, | ||
bankName = "STRIPE TEST BANK", | ||
countryCode = "US", | ||
currency = "usd", | ||
fingerprint = "wxXSAD5idPUzgBEz", | ||
last4 = "6789", | ||
routingNumber = "110000000", | ||
status = BankAccount.Status.New | ||
) | ||
) | ||
), | ||
hasMore = false, | ||
totalCount = 1, | ||
url = "/v1/customers/cus_HcLIwF3BCi/sources" | ||
) | ||
) | ||
} | ||
|
||
private companion object { | ||
private val CUSTOMER_JSON = JSONObject( | ||
""" | ||
{ | ||
"id": "cus_HcLIwF3BCi", | ||
"object": "customer", | ||
"created": 1594327465, | ||
"default_source": "ba_1H3NOMCRMbs6FrXfahj", | ||
"description": "mobile SDK example customer", | ||
"email": null, | ||
"livemode": false, | ||
"shipping": null, | ||
"sources": { | ||
"object": "list", | ||
"data": [{ | ||
"id": "ba_1H3NOMCRMbs6FrXfahj", | ||
"object": "bank_account", | ||
"account_holder_name": "Test Bank Account", | ||
"account_holder_type": "individual", | ||
"bank_name": "STRIPE TEST BANK", | ||
"country": "US", | ||
"currency": "usd", | ||
"customer": "cus_HcLIwF3BCiRp0t", | ||
"fingerprint": "wxXSAD5idPUzgBEz", | ||
"last4": "6789", | ||
"metadata": {}, | ||
"routing_number": "110000000", | ||
"status": "new" | ||
}], | ||
"has_more": false, | ||
"total_count": 1, | ||
"url": "\/v1\/customers\/cus_HcLIwF3BCi\/sources" | ||
} | ||
} | ||
""".trimIndent() | ||
) | ||
} | ||
} |