Skip to content

Commit a55a6c9

Browse files
authored
Clear cache on error (#147)
1 parent 7d9abc9 commit a55a6c9

File tree

6 files changed

+29
-3
lines changed

6 files changed

+29
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 3.2.1 October 29 2024
4+
5+
- Fix: Ensure we clear the preload cache on error responses.
6+
37
## 3.2.0 October 18 2024
48

59
- Prevent entering recovery mode for single-use multipass URLs.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ your project:
2323
#### Gradle
2424

2525
```groovy
26-
implementation "com.shopify:checkout-sheet-kit:3.2.0"
26+
implementation "com.shopify:checkout-sheet-kit:3.2.1"
2727
```
2828

2929
#### Maven
@@ -33,7 +33,7 @@ implementation "com.shopify:checkout-sheet-kit:3.2.0"
3333
<dependency>
3434
<groupId>com.shopify</groupId>
3535
<artifactId>checkout-sheet-kit</artifactId>
36-
<version>3.2.0</version>
36+
<version>3.2.1</version>
3737
</dependency>
3838
```
3939

lib/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def resolveEnvVarValue(name, defaultValue) {
1414
return rawValue ? rawValue : defaultValue
1515
}
1616

17-
def versionName = resolveEnvVarValue("CHECKOUT_SHEET_KIT_VERSION", "3.2.0")
17+
def versionName = resolveEnvVarValue("CHECKOUT_SHEET_KIT_VERSION", "3.2.1")
1818

1919
ext {
2020
app_compat_version = '1.6.1'

lib/src/main/java/com/shopify/checkoutsheetkit/CheckoutDialog.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ internal class CheckoutDialog(
150150
}
151151

152152
internal fun closeCheckoutDialogWithError(exception: CheckoutException) {
153+
CheckoutWebView.markCacheEntryStale()
153154
checkoutEventProcessor.onCheckoutFailed(exception)
154155
if (!this.checkoutUrl.isOneTimeUse() &&
155156
ShopifyCheckoutSheetKit.configuration.errorRecovery.shouldRecoverFromError(exception)) {

lib/src/test/java/com/shopify/checkoutsheetkit/CheckoutDialogTest.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,26 @@ class CheckoutDialogTest {
155155
verify(mockEventProcessor, never()).onCheckoutFailed(any())
156156
}
157157

158+
@Test
159+
fun `closeCheckoutDialogWithError marks cache entry stale`() {
160+
withPreloadingEnabled {
161+
val mockEventProcessor = mock<DefaultCheckoutEventProcessor>()
162+
ShopifyCheckoutSheetKit.preload("https://shopify.com", activity)
163+
ShopifyCheckoutSheetKit.present("https://shopify.com", activity, mockEventProcessor)
164+
165+
assertThat(CheckoutWebView.cacheEntry).isNotNull()
166+
167+
val dialog = ShadowDialog.getLatestDialog()
168+
val checkoutDialog = dialog as CheckoutDialog
169+
val error = checkoutException(isRecoverable = false)
170+
171+
checkoutDialog.closeCheckoutDialogWithError(error)
172+
shadowOf(Looper.getMainLooper()).runToEndOfTasks()
173+
174+
assertThat(CheckoutWebView.cacheEntry).isNull()
175+
}
176+
}
177+
158178
@Test
159179
fun `calls onCheckoutFailed if closeCheckoutDialogWithError for non-recoverable error`() {
160180
val mockEventProcessor = mock<DefaultCheckoutEventProcessor>()

samples/MobileBuyIntegration/app/src/main/java/com/shopify/checkout_sdk_mobile_buy_integration_sample/common/MobileBuyEventProcessor.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class MobileBuyEventProcessor(
6767
logger.log("Checkout failed", error)
6868

6969
if (!error.isRecoverable) {
70+
cartViewModel.clearCart()
7071
GlobalScope.launch(Dispatchers.Main) {
7172
Toast.makeText(
7273
context,

0 commit comments

Comments
 (0)