-
Notifications
You must be signed in to change notification settings - Fork 662
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pass billing details in
ElementsSessionContext
(#9446)
* Pass billing address in `ElementsSessionContext` * Address code review feedback 1. Rename `BillingAddress` to `BillingDetails` and add email 2. Move extension to separate file and add comments 3. Remove duplicate `billing_phone` param * Put changes behind feature flag
- Loading branch information
1 parent
b664fe3
commit 0f3d653
Showing
17 changed files
with
416 additions
and
16 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
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
55 changes: 55 additions & 0 deletions
55
...s/src/main/java/com/stripe/android/financialconnections/utils/BillingDetailsExtensions.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,55 @@ | ||
package com.stripe.android.financialconnections.utils | ||
|
||
import com.stripe.android.financialconnections.FinancialConnectionsSheet.ElementsSessionContext.BillingDetails | ||
|
||
/** | ||
* Creates API params for use with the Stripe core API. | ||
* | ||
* These params include the phone number and a nested address object. | ||
*/ | ||
internal fun BillingDetails.toApiParams(): Map<String, Any> { | ||
val addressParams = address?.let { address -> | ||
buildMap { | ||
address.line1?.let { put("line1", it) } | ||
address.line2?.let { put("line2", it) } | ||
address.postalCode?.let { put("postal_code", it) } | ||
address.city?.let { put("city", it) } | ||
address.state?.let { put("state", it) } | ||
address.country?.let { put("country", it) } | ||
}.filterValues { | ||
it.isNotBlank() | ||
} | ||
} | ||
return mapOf( | ||
"name" to name, | ||
"email" to email, | ||
"phone" to phone, | ||
"address" to addressParams, | ||
).filterNotNullValues() | ||
} | ||
|
||
/** | ||
* Creates API params for use with the consumer API. | ||
* | ||
* These params don't include the phone number and flatten the address. | ||
*/ | ||
internal fun BillingDetails.toConsumerBillingAddressParams(): Map<String, Any> { | ||
val contactParams = buildMap { | ||
name?.let { put("name", it) } | ||
}.filter { entry -> | ||
entry.value.isNotBlank() | ||
} | ||
|
||
val addressParams = buildMap { | ||
address?.line1?.let { put("line_1", it) } | ||
address?.line2?.let { put("line_2", it) } | ||
address?.postalCode?.let { put("postal_code", it) } | ||
address?.city?.let { put("locality", it) } | ||
address?.state?.let { put("administrative_area", it) } | ||
address?.country?.let { put("country_code", it) } | ||
}.filterValues { | ||
it.isNotBlank() | ||
} | ||
|
||
return contactParams + addressParams | ||
} |
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
Oops, something went wrong.