-
Notifications
You must be signed in to change notification settings - Fork 728
Prototype: in-sheet checkout session update for billing address tax #13233
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
Draft
cttsai-stripe
wants to merge
18
commits into
master
Choose a base branch
from
cttsai/checkout-session-in-sheet-tax-update
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
7ac3507
Prototype: in-sheet checkout session update for billing address tax
cttsai-stripe 903a171
Remove unnecessary billing_address_collection playground change
cttsai-stripe 8e716d4
Address review feedback: visibility, timeout, safety
cttsai-stripe f43ec01
Remove redundant withTimeout in withInternalStateLocked
cttsai-stripe 462ea1c
Align with iOS: use allowWhileSheetPresented flag on withInternalState
cttsai-stripe 826d606
Remove updateBillingAddressFromSheet, add flag to existing method
cttsai-stripe 4a1cf11
Remove CLAUDE.md change (moved to separate PR #13234)
cttsai-stripe 72944bc
Keep public updateBillingAddress API clean, add internal variant
cttsai-stripe eea50dc
Remove default values from internal function parameters
cttsai-stripe 7023d46
Rename allowWhileSheetPresented to isInSheetUpdate
cttsai-stripe e34ba68
Pass Checkout directly to InSheetCheckoutSessionUpdater
cttsai-stripe 3530eb5
Generalize InSheetCheckoutSessionUpdater to requiresUpdate/performUpdate
cttsai-stripe 5db6efe
Rename to performCheckoutSessionUpdateThenContinue, add spinner
cttsai-stripe dbf8c28
Add comment explaining tax field fallback chain
cttsai-stripe 2e127eb
Remove speculative "tax" field parsing, use only tax_meta/tax_context
cttsai-stripe a91dee8
Address review: default-to-billing, suppress isLoading, factory, sess…
cttsai-stripe 5aac64a
Remove isLoading suppression for in-sheet updates
cttsai-stripe 6e3e015
Remove shipping address case from InSheetCheckoutSessionUpdater
cttsai-stripe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
69 changes: 69 additions & 0 deletions
69
paymentsheet/src/main/java/com/stripe/android/checkout/InSheetCheckoutSessionUpdater.kt
This file contains hidden or 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,69 @@ | ||
| package com.stripe.android.checkout | ||
|
|
||
| import com.stripe.android.lpmfoundations.paymentmethod.IntegrationMetadata | ||
| import com.stripe.android.lpmfoundations.paymentmethod.PaymentMethodMetadata | ||
| import com.stripe.android.paymentelement.CheckoutSessionPreview | ||
| import com.stripe.android.paymentsheet.model.PaymentSelection | ||
| import com.stripe.android.paymentsheet.model.billingDetails | ||
| import com.stripe.android.paymentsheet.repositories.CheckoutSessionResponse | ||
|
|
||
| @OptIn(CheckoutSessionPreview::class) | ||
| internal class InSheetCheckoutSessionUpdater( | ||
| private val checkout: Checkout?, | ||
| ) { | ||
| companion object { | ||
| fun create(paymentMethodMetadata: PaymentMethodMetadata): InSheetCheckoutSessionUpdater { | ||
| val metadata = paymentMethodMetadata.integrationMetadata | ||
| as? IntegrationMetadata.CheckoutSession | ||
| val checkout = metadata?.let { CheckoutInstances[it.instancesKey].firstOrNull() } | ||
| return InSheetCheckoutSessionUpdater(checkout) | ||
| } | ||
| } | ||
|
|
||
| fun requiresUpdate(): Boolean { | ||
| val checkout = checkout ?: return false | ||
| return checkout.internalState.checkoutSessionResponse.taxStatus == | ||
| CheckoutSessionResponse.TaxStatus.REQUIRES_BILLING_ADDRESS | ||
| } | ||
|
|
||
| suspend fun performUpdate( | ||
| paymentSelection: PaymentSelection, | ||
| ): Result<Unit> { | ||
| val checkout = checkout | ||
| ?: return Result.failure(IllegalStateException("No Checkout instance")) | ||
| return updateWithBillingAddress(checkout, paymentSelection) | ||
| } | ||
|
|
||
| private suspend fun updateWithBillingAddress( | ||
| checkout: Checkout, | ||
| paymentSelection: PaymentSelection, | ||
| ): Result<Unit> { | ||
| val billingDetails = paymentSelection.billingDetails | ||
| ?: return Result.failure(IllegalStateException("Payment selection has no billing details")) | ||
|
|
||
| val billingAddress = billingDetails.address | ||
| ?: return Result.failure(IllegalStateException("Billing details have no address")) | ||
|
|
||
| if (billingAddress.country.isNullOrEmpty()) { | ||
| return Result.failure(IllegalStateException("Billing address has no country")) | ||
| } | ||
|
|
||
| return checkout.updateBillingAddressInternal( | ||
| name = billingDetails.name, | ||
| phoneNumber = billingDetails.phone, | ||
| address = billingAddress.toCheckoutAddress(), | ||
| isInSheetUpdate = true, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @OptIn(CheckoutSessionPreview::class) | ||
| private fun com.stripe.android.model.Address.toCheckoutAddress(): Address { | ||
| return Address() | ||
| .country(requireNotNull(country)) | ||
| .line1(line1) | ||
| .line2(line2) | ||
| .city(city) | ||
| .state(state) | ||
| .postalCode(postalCode) | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -102,7 +102,7 @@ internal class CheckoutSessionConfirmationInterceptor @AssistedInject constructo | |
| paymentMethodId = paymentMethod.id, | ||
| clientAttributionMetadata = clientAttributionMetadata, | ||
| returnUrl = returnUrl, | ||
| expectedAmount = intent.amount, | ||
| expectedAmount = currentExpectedAmount() ?: intent.amount, | ||
| savePaymentMethod = savePaymentMethod, | ||
| ) | ||
| else -> ConfirmCheckoutSessionParams( | ||
|
|
@@ -112,6 +112,12 @@ internal class CheckoutSessionConfirmationInterceptor @AssistedInject constructo | |
| ) | ||
| } | ||
|
|
||
| private fun currentExpectedAmount(): Long? { | ||
| val checkout = CheckoutInstances[integrationMetadata.instancesKey].firstOrNull() | ||
| ?: return null | ||
| return checkout.internalState.checkoutSessionResponse.amount | ||
| } | ||
|
|
||
|
Comment on lines
+115
to
+120
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should find a better way to pass along the updated expected amount. |
||
| private suspend fun confirmCheckoutSession( | ||
| params: ConfirmCheckoutSessionParams, | ||
| ): ConfirmationDefinition.Action<Args> { | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add tests and make it injected when ready for prod.