-
Notifications
You must be signed in to change notification settings - Fork 728
Extract FlagImageResolver for adaptive-pricing flag images #13401
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
Merged
jaynewstrom-stripe
merged 1 commit into
master
from
jaynewstrom/checkout-flag-image-resolver
Jul 10, 2026
Merged
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions
6
paymentsheet/src/main/java/com/stripe/android/checkout/FlagImageRepository.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
58 changes: 58 additions & 0 deletions
58
paymentsheet/src/main/java/com/stripe/android/checkout/FlagImageResolver.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,58 @@ | ||
| package com.stripe.android.checkout | ||
|
|
||
| import android.graphics.Bitmap | ||
| import com.stripe.android.core.networking.AnalyticsRequestExecutor | ||
| import com.stripe.android.networking.PaymentAnalyticsRequestFactory | ||
| import com.stripe.android.paymentsheet.analytics.PaymentSheetEvent | ||
| import com.stripe.android.paymentsheet.repositories.CheckoutSessionResponse | ||
| import javax.inject.Inject | ||
|
|
||
| /** | ||
| * Resolves the adaptive-pricing flag images for a [CheckoutSessionResponse]. | ||
| * | ||
| * Flags are keyed by uppercase currency code, so when the response's integration and local | ||
| * currencies are both already present in the [cached] map (i.e. the currencies haven't changed | ||
| * across a mutation such as applying a promotion code), the cached images are reused instead of | ||
| * being re-downloaded. A failed fetch reports [PaymentSheetEvent.AdaptivePricingFlagImageLoadFailed] | ||
| * for each missing flag and leaves the images null so a later mutation can retry. | ||
| */ | ||
| internal class FlagImageResolver @Inject constructor( | ||
| private val flagImageRepository: FlagImageRepository, | ||
| private val analyticsRequestExecutor: AnalyticsRequestExecutor, | ||
| private val paymentAnalyticsRequestFactory: PaymentAnalyticsRequestFactory, | ||
| ) { | ||
| suspend fun resolve( | ||
| response: CheckoutSessionResponse, | ||
| cached: Map<String, Bitmap>?, | ||
| ): Map<String, Bitmap>? { | ||
| val adaptivePricingInfo = response.adaptivePricingInfo ?: return null | ||
| val localOption = adaptivePricingInfo.localCurrencyOptions.firstOrNull() ?: return null | ||
| val integrationCurrency = adaptivePricingInfo.integrationCurrency | ||
| val localCurrency = localOption.currency | ||
|
|
||
| if (cached != null && | ||
| cached.containsKey(integrationCurrency.uppercase()) && | ||
| cached.containsKey(localCurrency.uppercase()) | ||
| ) { | ||
| return cached | ||
| } | ||
|
|
||
| val result = flagImageRepository.fetch( | ||
| integrationCurrencyCode = integrationCurrency, | ||
| localCurrencyCode = localCurrency, | ||
| ) | ||
| for (failure in result.failures) { | ||
| val event = PaymentSheetEvent.AdaptivePricingFlagImageLoadFailed( | ||
| countryCode = failure.countryCode, | ||
| url = failure.url, | ||
| ) | ||
| analyticsRequestExecutor.executeAsync( | ||
| paymentAnalyticsRequestFactory.createRequest( | ||
| event = event, | ||
| additionalParams = event.params, | ||
| ) | ||
| ) | ||
| } | ||
| return result.images | ||
| } | ||
| } |
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
6 changes: 6 additions & 0 deletions
6
paymentsheet/src/main/java/com/stripe/android/common/di/DisplayDensity.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,6 @@ | ||
| package com.stripe.android.common.di | ||
|
|
||
| import javax.inject.Qualifier | ||
|
|
||
| @Qualifier | ||
| internal annotation class DisplayDensity |
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.
This is technically new behavior. It should never really be triggered. But I want this in the new checkout controller. And it was easier to introduce it here than in one massive PR for checkout controller.