Commit 87657f9
authored
[WEB-4448] Track correct package after purchase (#968)
## Motivation / Description
See thread here
https://revenuecat.slack.com/archives/C08H0L0RV09/p1782487589364049
**Problem**
When a Web Paywall user switches away from the default package and then
purchases via the express checkout button (Apple Pay / Google Pay), the
returned PaywallPurchaseResult reports the default package instead of
the one actually purchased. The charge and entitlements are correct —
only the returned metadata is wrong — which corrupts downstream
ad/analytics attribution for customers.
**Root cause**
Two stale closures captured the package selected at render time rather
than purchase time:
getWalletButtonRender (src/main.ts) — the wallet button is rendered once
with the initially selected package. When the user switches packages,
the Svelte action's update() forwards the new package to the button via
buttonUpdater.updatePurchase(), so the charge is correct — but the
success handler still spread the pkg captured at first render into
selectedPackage.
presentExpressPurchaseButton's onFinished — built
storeTransaction.productIdentifier from the rcPackage argument (also the
initial package), ignoring operationResult.productIdentifier, which the
backend already returns with the actual purchased product.
**Fix**
getWalletButtonRender now tracks the currently selected package in the
render closure (updated alongside updatePurchase()) and reports it as
selectedPackage on success.
onFinished now uses operationResult.productIdentifier (backend-reported,
reflects what was actually charged) for
storeTransaction.productIdentifier instead of the captured package.
https://www.loom.com/share/d9341d0479c54f52873484ba1e56e153
## Changes introduced
## Linear ticket (if any)
## Additional comments
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Touches purchase success payloads used for analytics/attribution;
billing behavior is unchanged but incorrect metadata previously affected
downstream tracking.
>
> **Overview**
> Fixes **wrong `PaywallPurchaseResult` metadata** when a paywall user
changes the selected package and completes purchase via Apple Pay /
Google Pay. Charges and entitlements were already correct; only the
returned package and product id were stale.
>
> **`presentExpressPurchaseButton`**:
`storeTransaction.productIdentifier` now comes from
**`operationResult.productIdentifier`** (backend) instead of the
initially passed `rcPackage`.
>
> **`getWalletButtonRender`**: maintains **`currentPkg`** in the render
closure, updated whenever `update()` calls
`buttonUpdater.updatePurchase()`, and returns that as
**`selectedPackage`** on success instead of the package captured at
first render.
>
> Adds **`wallet-button-render.test.ts`** covering package switch vs no
switch.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
1d4f261. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent eefd1a7 commit 87657f9
2 files changed
Lines changed: 106 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1407 | 1407 | | |
1408 | 1408 | | |
1409 | 1409 | | |
1410 | | - | |
| 1410 | + | |
1411 | 1411 | | |
1412 | 1412 | | |
1413 | 1413 | | |
| |||
1475 | 1475 | | |
1476 | 1476 | | |
1477 | 1477 | | |
| 1478 | + | |
| 1479 | + | |
1478 | 1480 | | |
1479 | 1481 | | |
1480 | 1482 | | |
| |||
1488 | 1490 | | |
1489 | 1491 | | |
1490 | 1492 | | |
1491 | | - | |
| 1493 | + | |
1492 | 1494 | | |
1493 | 1495 | | |
1494 | 1496 | | |
| |||
1504 | 1506 | | |
1505 | 1507 | | |
1506 | 1508 | | |
| 1509 | + | |
1507 | 1510 | | |
1508 | 1511 | | |
1509 | 1512 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
0 commit comments