@vaam-apps/vpay-stripe-js 0.21.0 → 0.21.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +6 -256
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -3,14 +3,6 @@
3
3
  A Stripe.js-shaped browser client for vpay's payer surface. Zero runtime
4
4
  dependencies, ESM, TypeScript strict.
5
5
 
6
- **On the registry since 2026-09-19.** `release.yml`'s `publish-stripe-js-sdk`
7
- job (added 2026-09-18) publishes it on every `v*` tag, and `npm view
8
- @vaam-apps/vpay-stripe-js versions` listed `0.2.1` (the first, 2026-09-19)
9
- through `0.4.1` on 2026-09-23. _(This read "Not yet on the registry … `E404`
10
- on 2026-09-05 and no workflow in this repository publishes anything" until
11
- 2026-09-23. The workflow half was wrong from 2026-09-18, and the registry half
12
- from 2026-09-19.)_
13
-
14
6
  ```bash
15
7
  pnpm add @vaam-apps/vpay-stripe-js
16
8
  ```
@@ -18,116 +10,6 @@ pnpm add @vaam-apps/vpay-stripe-js
18
10
  Inside this workspace it is a `workspace:*` dependency, built with
19
11
  `pnpm --filter @vaam-apps/vpay-stripe-js build`.
20
12
 
21
- ## Why this exists rather than `@stripe/stripe-js`
22
-
23
- `@stripe/stripe-js` cannot be pointed at another API. Its
24
- `StripeConstructorOptions` has exactly five members — `stripeAccount`,
25
- `apiVersion`, `locale`, `betas`, `developerTools` — and none of them is a host
26
- or base URL. The loader hardcodes `ORIGIN = 'https://js.stripe.com'`, and its
27
- `isStripeJSURL` accepts only `js.stripe.com/v3` or
28
- `js.stripe.com/{v3|[a-z]+}/stripe.js`. Elements iframes and the bundle's own
29
- XHRs are Stripe-origin by construction.
30
-
31
- So this is a drop-in-_shaped_ package of vpay's own, speaking vpay's
32
- `/v1/browser` routes. `@stripe/stripe-js` is a devDependency here and only a
33
- devDependency: it is used by `src/compat.test.ts` to pin, at compile time, in
34
- which direction the two packages' types are actually assignable. It is never
35
- loaded at runtime.
36
-
37
- ## The drop-in claim, scoped honestly
38
-
39
- **Compatible**: the payment-intent half of Stripe.js against a
40
- push (mobile-money) or redirect rail.
41
-
42
- | Stripe.js | `@vaam-apps/vpay-stripe-js` |
43
- | ------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------- |
44
- | `loadStripe(pk)` | `loadStripe(pk, { baseUrl, checkoutBaseUrl? })` — plus a required `baseUrl`; no `<script>` is downloaded |
45
- | `stripe.retrievePaymentIntent(clientSecret)` | same signature, same `PaymentIntentResult` shape |
46
- | `stripe.confirmPayment({ clientSecret, confirmParams, redirect })` | same, minus `elements` |
47
- | `stripe.handleNextAction({ clientSecret })` | same |
48
- | — | `stripe.confirmMobileMoneyPayment(clientSecret, { type, msisdn })` |
49
- | — | `stripe.waitForPaymentIntent(clientSecret, { timeoutMs, intervalMs })` |
50
- | `stripe.createEmbeddedCheckoutPage({ fetchClientSecret })` | `stripe.initEmbeddedCheckout({ fetchClientSecret, onComplete })` — **vpay's own page**, not Stripe's; see "Checkout" below |
51
- | — | `stripe.retrieveCheckoutSession(clientSecret)` |
52
- | — | `stripe.openCheckoutPopup({ fetchCheckoutUrl, onComplete, onCancel })` — vpay's hosted page in a window your page owns |
53
- | — | `notifyCheckoutOpener({ session, status })` — the popup half, called on your own `success_url` |
54
-
55
- **Not compatible, ever** — absent by construction, not stubbed, because each
56
- depends on card data or on an iframe served from `js.stripe.com`:
57
-
58
- - Elements
59
- - cards
60
- - 3DS
61
- - Payment Element
62
- - Link
63
- - Payment Request / Apple Pay / Google Pay
64
- - `confirmCardPayment`
65
- - `createPaymentMethod`
66
- - ConfirmationTokens
67
- - SetupIntents
68
-
69
- A method that is missing is a compile error on the merchant's page. A method
70
- that returned a plausible-looking failure would be a surprise at the till.
71
-
72
- **Checkout used to be on that list and is not any more.** Until Step 9 this
73
- README said "Checkout (hosted or embedded)" was not compatible, ever. That
74
- sentence was true when it was written and is retracted here, in the same PR
75
- that makes it false — but the replacement is narrower than it looks, and the
76
- distinction matters:
77
-
78
- - vpay now serves **its own** checkout page, hosted and embedded
79
- (`frontends/apps/checkout`, Step 9). `stripe.initEmbeddedCheckout` frames
80
- that page, and `stripe.retrieveCheckoutSession` reads vpay's own
81
- `checkout.session` object.
82
- - It is **not** `@stripe/stripe-js`'s Checkout. Stripe's own method is called
83
- `createEmbeddedCheckoutPage` in the version pinned here, its options are
84
- not ours, and its session object has `line_items`, `mode` and
85
- `amount_total`, none of which vpay's has (Step 9's D10). A merchant's
86
- Stripe Checkout integration does **not** port over by changing an import.
87
- - What _is_ portable is the handle: our `{ mount, unmount, destroy }` is
88
- assignable to Stripe's `StripeEmbeddedCheckout` in both directions, pinned
89
- in `src/compat.test.ts`. The mounting plumbing moves; the session model
90
- does not.
91
-
92
- ### Type compatibility, precisely
93
-
94
- Every claim below is a compile-time assertion in `src/compat.test.ts`; the
95
- package's `typecheck` fails if either side moves.
96
-
97
- - Stripe's `StripeError` **is** assignable to ours — ours is a widening, so
98
- existing error-rendering code keeps compiling.
99
- - Ours is **not** assignable to Stripe's: our `type` is an open `string` (so a
100
- `type` a later vpay version introduces is not a compile error at the
101
- merchant), and our optional members are written `?: T | undefined`, which
102
- `exactOptionalPropertyTypes` distinguishes from Stripe's `?: T`.
103
- - Our `PaymentIntent` is **not** assignable to Stripe's `PaymentIntent`.
104
- Stripe's requires a dozen fields that exist only because it settles cards
105
- (`capture_method`, `confirmation_method`, `canceled_at`, `payment_method`,
106
- …), and its `last_payment_error` is a card-decline shape.
107
- - Our embedded-checkout **handle** is assignable to Stripe's
108
- `StripeEmbeddedCheckout`, and Stripe's to ours: both are exactly
109
- `mount(string | HTMLElement)`, `unmount()`, `destroy()`.
110
- - Our embedded-checkout **options** are not assignable to Stripe's in either
111
- direction. Ours requires `fetchClientSecret` where Stripe's makes it
112
- optional (Stripe also accepts a bare `clientSecret`; vpay does not), and
113
- our `onComplete` receives the completing session where Stripe's takes no
114
- argument.
115
- - The two fields a checkout page actually branches on — `status` and
116
- `next_action` — **are** assignable to Stripe's, and `PaymentIntentResult`
117
- has the same two-member discriminated shape in both packages, so the
118
- narrowing idiom is portable:
119
-
120
- ```ts
121
- import type { PaymentIntentResult as StripeResult } from "@stripe/stripe-js";
122
- import type { PaymentIntentResult as VpayResult } from "@vaam-apps/vpay-stripe-js";
123
-
124
- // The same function body compiles against either alias.
125
- function render(result: VpayResult): string {
126
- if (result.error) return result.error.message ?? "Payment failed";
127
- return result.paymentIntent.status;
128
- }
129
- ```
130
-
131
13
  ## Using it
132
14
 
133
15
  The integration is Stripe's own: the **server** creates the PaymentIntent with
@@ -201,7 +83,7 @@ page, and a real browser has walked the whole Orange round trip
201
83
  (`shop-hosted.cy.ts`). Without a session, the payer lands on **your**
202
84
  `return_url` and you learn the outcome by calling `retrievePaymentIntent`,
203
85
  never from the fact that they came back.
204
- [`docs/flows/browser-checkout.md`](../../docs/flows/browser-checkout.md)
86
+ [`docs/flows/browser-checkout.md`](https://github.com/vaam-apps/vpay/blob/1deb2873dfda4398b2438dd5498b6264681b7d34/docs/flows/browser-checkout.md)
205
87
  § "The redirect gap (D4) — closed 2026-09-04" is the record.
206
88
 
207
89
  ## Checkout (vpay's own)
@@ -277,79 +159,7 @@ was designed to preclude). The frame is sandboxed
277
159
  `allow-top-navigation`, which is why the redirect rail's hand-off is a
278
160
  message your page acts on rather than something the frame does itself.
279
161
 
280
- ### The popup, and its two completion channels
281
-
282
- `openCheckoutPopup` is the third surface: vpay's **hosted** page in a
283
- top-level window your page opened, rather than in an iframe or in the
284
- payer's own tab.
285
-
286
- ```ts
287
- // browser — `checkoutBaseUrl` is what lets vpay's own page complete the popup
288
- const stripe = await loadStripe("pk_test_…", {
289
- baseUrl: "https://api.vpay.example",
290
- checkoutBaseUrl: "https://checkout.vpay.example",
291
- });
292
-
293
- // inside a click handler
294
- try {
295
- const popup = await stripe.openCheckoutPopup({
296
- // Your own server's `POST /v1/checkout/sessions` with ui_mode: 'hosted'.
297
- fetchCheckoutUrl: async () =>
298
- (await fetch("/checkout-url", { method: "POST" }).then((r) => r.json()))
299
- .url,
300
- onComplete: ({ session, status }) => {
301
- // Once per checkout session. A message, not proof of payment: re-read
302
- // the order from your own server, which your webhook is what writes.
303
- refresh(session, status);
304
- },
305
- onCancel: () => show("The payment window was closed."),
306
- });
307
- } catch (err) {
308
- if (err instanceof CheckoutPopupBlockedError) {
309
- window.location.assign(await checkoutUrl()); // no browser blocks this
310
- }
311
- }
312
- ```
313
-
314
- ```ts
315
- // browser, on the success_url page — which may load *inside* the popup
316
- import { notifyCheckoutOpener } from "@vaam-apps/vpay-stripe-js";
317
-
318
- notifyCheckoutOpener({ session: sessionIdFromTheUrl, status: "complete" });
319
- ```
320
-
321
- A popup is not a frame, so completion reaches your page by one of **two
322
- channels**, and `onComplete` fires **once per checkout session**, whichever
323
- arrives first (issue #65):
324
-
325
- 1. **Primary — vpay's own page.** Inside a popup `window.parent === window`,
326
- so vpay's checkout page posts to `window.opener` instead:
327
- `{type:'vpay:complete', session, status}`, with the checkout session's id
328
- and its own `status`, at most once, when the outcome appears. This side
329
- accepts it only from the origin of `loadStripe`'s **`checkoutBaseUrl`**
330
- and only from the window it opened. Without `checkoutBaseUrl` this
331
- channel is off. `status` is the session's — a payment that did not
332
- succeed arrives here too, with a status other than `complete`. After a
333
- redirect rail, the page the payer comes back to pins the opener by a
334
- different rule — only when you registered **exactly one** checkout
335
- origin — because its referrer is the rail's
336
- (`docs/flows/hosted-checkout/page-memory-and-protocols.md`).
337
- 2. **Fallback — your `success_url`.** When vpay's page could not open the
338
- primary channel it navigates the popup to your `success_url`, which calls
339
- `notifyCheckoutOpener` and posts the same shape to `window.opener`. This
340
- side accepts it from `completionOrigin` — **your** origin by default,
341
- since your page is the sender — and from the window it opened.
342
- 3. **Deduplicated per session id.** If both arrive, the second is dropped;
343
- so is a late one reaching a later `openCheckoutPopup` that reused the
344
- window by name. A message naming a _different_ session is not dropped.
345
- 4. **`notifyCheckoutOpener` answers `false` and does nothing when there is
346
- no opener**, which is exactly what happens when the same page is reached
347
- by an ordinary redirect. One return page serves both integrations
348
- without branching on a query parameter, and calling it unconditionally
349
- is correct: when vpay's page has already reported, the opener drops this
350
- one as a duplicate.
351
-
352
- #### Your page's `Referrer-Policy` must send vpay your origin
162
+ ### Your page's `Referrer-Policy` must send vpay your origin
353
163
 
354
164
  vpay's page learns which window it may post to by matching
355
165
  `document.referrer` against the origins you registered
@@ -463,68 +273,8 @@ failing, and a message this package invented on top of it would hide the
463
273
  fault. Checking these once is what lets every other method keep the
464
274
  never-rejects contract.
465
275
 
466
- ## Development
467
-
468
- ```bash
469
- pnpm --filter @vaam-apps/vpay-stripe-js typecheck
470
- pnpm --filter @vaam-apps/vpay-stripe-js test
471
- pnpm --filter @vaam-apps/vpay-stripe-js build # tsc → dist/, gitignored
472
- ```
276
+ ## More
473
277
 
474
- Unit tests run against a real `node:http` server standing in for
475
- `/v1/browser` (`src/testing/browser-stub.ts`), not a patched `fetch`: the
476
- contract under test is bytes on the wire. That stub is excluded from `dist`
477
- and imported only from `*.test.ts`, so it is not a test double reachable from
478
- a shipping process in ADR-0006's sense.
479
-
480
- ## Status
481
-
482
- **Verified end to end on the compose stack, not yet in CI.**
483
-
484
- - The payment-intent half: implemented, typechecked and unit-tested against
485
- a `node:http` stub of the surface in
486
- `docs/plans/2026-09-03-step5c-stripejs.md` §1. 119 tests pass, none
487
- skipped or ignored.
488
- - The server routes it speaks to — `GET /v1/browser/payment_intents/{id}` and
489
- `POST /v1/browser/payment_intents/{id}/confirm`, publishable keys, the
490
- `client_secret` column and the CORS layer — landed in the same step (block
491
- A) and are proven by `backends/tests/integration/tests/browser_checkout.rs`
492
- against real Postgres and WireMock.
493
- - The end-to-end proof through this package is
494
- `frontends/tests/e2e/cypress/e2e/checkout.cy.ts`, which drives
495
- `examples/checkout-browser` to `succeeded` on the compose stack. It has
496
- passed locally; it is wired into the CI `e2e` job but has not yet been
497
- observed green in a GitHub Actions run.
498
- - The redirect _return_ trip **was** a named gap (D4). It was **closed on
499
- 2026-09-04 (Step 9)**: the rail is now told a per-charge `return_url` and
500
- vpay serves the page the payer comes back to — see
501
- `docs/flows/hosted-checkout.md`. See `docs/status.md` for the
502
- repository-wide picture.
503
- - **Checkout is newer and less proven than the rest of this package.**
504
- `initEmbeddedCheckout` is exercised against a real `iframe` in jsdom
505
- (`src/embedded.test.ts`, 20 tests) and `retrieveCheckoutSession` against
506
- the `node:http` stub (`src/checkout-session.test.ts`, 10 tests). Neither of
507
- those two suites runs against a live vpay. The end-to-end proof that does is
508
- `frontends/tests/e2e/cypress/e2e/shop-embedded.cy.ts` (Step 9, lane 6),
509
- which frames vpay's own checkout page on `examples/shop` and completes a
510
- payment inside it — **green from nothing in the `vpay-ci` VM on
511
- 2026-09-04**. What that spec cannot see is recorded on its own
512
- `docs/status.md` row.
513
- - **The popup surface (`openCheckoutPopup` / `notifyCheckoutOpener`) is
514
- unit-tested and has not been driven by a real browser.** `src/popup.test.ts`
515
- (41 tests since issue #65) drives it against stub windows, because jsdom
516
- implements neither `window.open` nor cross-window `postMessage` — so what
517
- is proven is both channels' origin and source checks, the per-session
518
- deduplication in both orders of arrival, the open-before-await ordering,
519
- the blocked-window error, the cancel poll and the round trip between the
520
- two halves. vpay's page's own message is a literal of the checkout app's
521
- `CompleteMessage` shape in those tests, not the page itself. What is **not** proven anywhere yet is a real browser opening a
522
- real window: no Cypress spec covers it, and the hand-run of
523
- `examples/shop`'s popup mode on 2026-09-06 reached only the **fallback** —
524
- the automation's synthetic click carries no user activation, so
525
- `window.open` answered `null` and `CheckoutPopupBlockedError` did its job.
526
- Recorded on `docs/status.md` and as a dated ⛔ in `docs/sdks/parity.md`.
527
- - The `vpay:complete` payload is read strictly: `session` and `status` must
528
- both be strings. If vpay's checkout page ever sends the session as an
529
- object, `onComplete` stops firing rather than firing with fields it cannot
530
- read — visible immediately, and by design.
278
+ The guide for people is at
279
+ [vpay-oss.vaam.store](https://vpay-oss.vaam.store). What each SDK supports is
280
+ in [docs/sdks/parity.md](https://github.com/vaam-apps/vpay/blob/1deb2873dfda4398b2438dd5498b6264681b7d34/docs/sdks/parity.md).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaam-apps/vpay-stripe-js",
3
- "version": "0.21.0",
3
+ "version": "0.21.1",
4
4
  "description": "A Stripe.js-shaped browser client for vpay's payer surface: payment intents, embedded and hosted Checkout, zero runtime dependencies.",
5
5
  "license": "Apache-2.0",
6
6
  "publishConfig": {