@vaam-apps/vpay-stripe-js 0.2.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.
- package/LICENSE +21 -0
- package/README.md +477 -0
- package/dist/client.d.ts +50 -0
- package/dist/client.js +551 -0
- package/dist/embedded.d.ts +68 -0
- package/dist/embedded.js +196 -0
- package/dist/errors.d.ts +91 -0
- package/dist/errors.js +103 -0
- package/dist/form.d.ts +55 -0
- package/dist/form.js +135 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +14 -0
- package/dist/popup.d.ts +168 -0
- package/dist/popup.js +260 -0
- package/dist/types.d.ts +358 -0
- package/dist/types.js +1 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
|
16
|
+
|
|
17
|
+
Copyright 2026 Vymalo
|
|
18
|
+
|
|
19
|
+
The full text of the Apache License 2.0 is available at the URL above.
|
|
20
|
+
This file is an abridged pointer; replace it with the full text before
|
|
21
|
+
publishing the repository.
|
package/README.md
ADDED
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
# `@vaam-apps/vpay-stripe-js`
|
|
2
|
+
|
|
3
|
+
A Stripe.js-shaped browser client for vpay's payer surface. Zero runtime
|
|
4
|
+
dependencies, ESM, TypeScript strict.
|
|
5
|
+
|
|
6
|
+
**Not yet on the registry.** `npm view @vaam-apps/vpay-stripe-js` answered
|
|
7
|
+
`E404` on 2026-09-05 and no workflow in this repository publishes anything;
|
|
8
|
+
the manifest stopped saying `"private": true` on that date so that a release
|
|
9
|
+
can happen without editing it. Once published:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add @vaam-apps/vpay-stripe-js # not yet published — see above
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Inside this workspace it is a `workspace:*` dependency, built with
|
|
16
|
+
`pnpm --filter @vaam-apps/vpay-stripe-js build`.
|
|
17
|
+
|
|
18
|
+
## Why this exists rather than `@stripe/stripe-js`
|
|
19
|
+
|
|
20
|
+
`@stripe/stripe-js` cannot be pointed at another API. Its
|
|
21
|
+
`StripeConstructorOptions` has exactly five members — `stripeAccount`,
|
|
22
|
+
`apiVersion`, `locale`, `betas`, `developerTools` — and none of them is a host
|
|
23
|
+
or base URL. The loader hardcodes `ORIGIN = 'https://js.stripe.com'`, and its
|
|
24
|
+
`isStripeJSURL` accepts only `js.stripe.com/v3` or
|
|
25
|
+
`js.stripe.com/{v3|[a-z]+}/stripe.js`. Elements iframes and the bundle's own
|
|
26
|
+
XHRs are Stripe-origin by construction.
|
|
27
|
+
|
|
28
|
+
So this is a drop-in-_shaped_ package of vpay's own, speaking vpay's
|
|
29
|
+
`/v1/browser` routes. `@stripe/stripe-js` is a devDependency here and only a
|
|
30
|
+
devDependency: it is used by `src/compat.test.ts` to pin, at compile time, in
|
|
31
|
+
which direction the two packages' types are actually assignable. It is never
|
|
32
|
+
loaded at runtime.
|
|
33
|
+
|
|
34
|
+
## The drop-in claim, scoped honestly
|
|
35
|
+
|
|
36
|
+
**Compatible**: the payment-intent half of Stripe.js against a
|
|
37
|
+
push (mobile-money) or redirect rail.
|
|
38
|
+
|
|
39
|
+
| Stripe.js | `@vaam-apps/vpay-stripe-js` |
|
|
40
|
+
| ------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------- |
|
|
41
|
+
| `loadStripe(pk)` | `loadStripe(pk, { baseUrl, checkoutBaseUrl? })` — plus a required `baseUrl`; no `<script>` is downloaded |
|
|
42
|
+
| `stripe.retrievePaymentIntent(clientSecret)` | same signature, same `PaymentIntentResult` shape |
|
|
43
|
+
| `stripe.confirmPayment({ clientSecret, confirmParams, redirect })` | same, minus `elements` |
|
|
44
|
+
| `stripe.handleNextAction({ clientSecret })` | same |
|
|
45
|
+
| — | `stripe.confirmMobileMoneyPayment(clientSecret, { type, msisdn })` |
|
|
46
|
+
| — | `stripe.waitForPaymentIntent(clientSecret, { timeoutMs, intervalMs })` |
|
|
47
|
+
| `stripe.createEmbeddedCheckoutPage({ fetchClientSecret })` | `stripe.initEmbeddedCheckout({ fetchClientSecret, onComplete })` — **vpay's own page**, not Stripe's; see "Checkout" below |
|
|
48
|
+
| — | `stripe.retrieveCheckoutSession(clientSecret)` |
|
|
49
|
+
| — | `stripe.openCheckoutPopup({ fetchCheckoutUrl, onComplete, onCancel })` — vpay's hosted page in a window your page owns |
|
|
50
|
+
| — | `notifyCheckoutOpener({ session, status })` — the popup half, called on your own `success_url` |
|
|
51
|
+
|
|
52
|
+
**Not compatible, ever** — absent by construction, not stubbed, because each
|
|
53
|
+
depends on card data or on an iframe served from `js.stripe.com`:
|
|
54
|
+
|
|
55
|
+
- Elements
|
|
56
|
+
- cards
|
|
57
|
+
- 3DS
|
|
58
|
+
- Payment Element
|
|
59
|
+
- Link
|
|
60
|
+
- Payment Request / Apple Pay / Google Pay
|
|
61
|
+
- `confirmCardPayment`
|
|
62
|
+
- `createPaymentMethod`
|
|
63
|
+
- ConfirmationTokens
|
|
64
|
+
- SetupIntents
|
|
65
|
+
|
|
66
|
+
A method that is missing is a compile error on the merchant's page. A method
|
|
67
|
+
that returned a plausible-looking failure would be a surprise at the till.
|
|
68
|
+
|
|
69
|
+
**Checkout used to be on that list and is not any more.** Until Step 9 this
|
|
70
|
+
README said "Checkout (hosted or embedded)" was not compatible, ever. That
|
|
71
|
+
sentence was true when it was written and is retracted here, in the same PR
|
|
72
|
+
that makes it false — but the replacement is narrower than it looks, and the
|
|
73
|
+
distinction matters:
|
|
74
|
+
|
|
75
|
+
- vpay now serves **its own** checkout page, hosted and embedded
|
|
76
|
+
(`frontends/apps/checkout`, Step 9). `stripe.initEmbeddedCheckout` frames
|
|
77
|
+
that page, and `stripe.retrieveCheckoutSession` reads vpay's own
|
|
78
|
+
`checkout.session` object.
|
|
79
|
+
- It is **not** `@stripe/stripe-js`'s Checkout. Stripe's own method is called
|
|
80
|
+
`createEmbeddedCheckoutPage` in the version pinned here, its options are
|
|
81
|
+
not ours, and its session object has `line_items`, `mode` and
|
|
82
|
+
`amount_total`, none of which vpay's has (Step 9's D10). A merchant's
|
|
83
|
+
Stripe Checkout integration does **not** port over by changing an import.
|
|
84
|
+
- What _is_ portable is the handle: our `{ mount, unmount, destroy }` is
|
|
85
|
+
assignable to Stripe's `StripeEmbeddedCheckout` in both directions, pinned
|
|
86
|
+
in `src/compat.test.ts`. The mounting plumbing moves; the session model
|
|
87
|
+
does not.
|
|
88
|
+
|
|
89
|
+
### Type compatibility, precisely
|
|
90
|
+
|
|
91
|
+
Every claim below is a compile-time assertion in `src/compat.test.ts`; the
|
|
92
|
+
package's `typecheck` fails if either side moves.
|
|
93
|
+
|
|
94
|
+
- Stripe's `StripeError` **is** assignable to ours — ours is a widening, so
|
|
95
|
+
existing error-rendering code keeps compiling.
|
|
96
|
+
- Ours is **not** assignable to Stripe's: our `type` is an open `string` (so a
|
|
97
|
+
`type` a later vpay version introduces is not a compile error at the
|
|
98
|
+
merchant), and our optional members are written `?: T | undefined`, which
|
|
99
|
+
`exactOptionalPropertyTypes` distinguishes from Stripe's `?: T`.
|
|
100
|
+
- Our `PaymentIntent` is **not** assignable to Stripe's `PaymentIntent`.
|
|
101
|
+
Stripe's requires a dozen fields that exist only because it settles cards
|
|
102
|
+
(`capture_method`, `confirmation_method`, `canceled_at`, `payment_method`,
|
|
103
|
+
…), and its `last_payment_error` is a card-decline shape.
|
|
104
|
+
- Our embedded-checkout **handle** is assignable to Stripe's
|
|
105
|
+
`StripeEmbeddedCheckout`, and Stripe's to ours: both are exactly
|
|
106
|
+
`mount(string | HTMLElement)`, `unmount()`, `destroy()`.
|
|
107
|
+
- Our embedded-checkout **options** are not assignable to Stripe's in either
|
|
108
|
+
direction. Ours requires `fetchClientSecret` where Stripe's makes it
|
|
109
|
+
optional (Stripe also accepts a bare `clientSecret`; vpay does not), and
|
|
110
|
+
our `onComplete` receives the completing session where Stripe's takes no
|
|
111
|
+
argument.
|
|
112
|
+
- The two fields a checkout page actually branches on — `status` and
|
|
113
|
+
`next_action` — **are** assignable to Stripe's, and `PaymentIntentResult`
|
|
114
|
+
has the same two-member discriminated shape in both packages, so the
|
|
115
|
+
narrowing idiom is portable:
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
import type { PaymentIntentResult as StripeResult } from "@stripe/stripe-js";
|
|
119
|
+
import type { PaymentIntentResult as VpayResult } from "@vaam-apps/vpay-stripe-js";
|
|
120
|
+
|
|
121
|
+
// The same function body compiles against either alias.
|
|
122
|
+
function render(result: VpayResult): string {
|
|
123
|
+
if (result.error) return result.error.message ?? "Payment failed";
|
|
124
|
+
return result.paymentIntent.status;
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Using it
|
|
129
|
+
|
|
130
|
+
The integration is Stripe's own: the **server** creates the PaymentIntent with
|
|
131
|
+
the merchant SDK and renders the publishable key and the `client_secret` into
|
|
132
|
+
the page; the **browser** never holds a merchant API key.
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
// server (Node, @vaam-apps/vpay-sdk, OAuth2 private_key_jwt)
|
|
136
|
+
const intent = await vpay.paymentIntents.create({
|
|
137
|
+
amount: 5000,
|
|
138
|
+
currency: "xaf",
|
|
139
|
+
payment_method_types: ["mtn_momo"],
|
|
140
|
+
});
|
|
141
|
+
res.render("checkout", {
|
|
142
|
+
publishableKey: process.env.VPAY_PUBLISHABLE_KEY,
|
|
143
|
+
clientSecret: intent.client_secret,
|
|
144
|
+
});
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
// browser
|
|
149
|
+
import { loadStripe } from "@vaam-apps/vpay-stripe-js";
|
|
150
|
+
|
|
151
|
+
const stripe = await loadStripe(publishableKey, {
|
|
152
|
+
baseUrl: "https://api.vpay.example",
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
const confirmed = await stripe.confirmMobileMoneyPayment(clientSecret, {
|
|
156
|
+
type: "mtn_momo",
|
|
157
|
+
msisdn: "237690000000",
|
|
158
|
+
});
|
|
159
|
+
if (confirmed.error) {
|
|
160
|
+
show(confirmed.error.message);
|
|
161
|
+
} else {
|
|
162
|
+
// The payer now approves the push on their handset. Poll until the intent
|
|
163
|
+
// stops moving — three minutes by default, every two seconds, jittered.
|
|
164
|
+
const settled = await stripe.waitForPaymentIntent(clientSecret);
|
|
165
|
+
show(settled.error ? settled.error.message : settled.paymentIntent.status);
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Redirect rails
|
|
170
|
+
|
|
171
|
+
`confirmPayment` follows Stripe.js's rule. When the rail answers with
|
|
172
|
+
`next_action.redirect_to_url` and `redirect` is not `'if_required'`, the
|
|
173
|
+
browser is navigated with `window.location.assign(url)` and **the returned
|
|
174
|
+
promise never settles** — so a caller's `.then`/`.finally` cannot paint a
|
|
175
|
+
"payment failed" state during the unload. Pass `redirect: 'if_required'` to
|
|
176
|
+
get the intent back and render the hand-off yourself. With no `window` (Node,
|
|
177
|
+
SSR, a worker) the result is
|
|
178
|
+
`{ error: { type: 'api_error', code: 'redirect_unavailable' } }` rather than an
|
|
179
|
+
invented success.
|
|
180
|
+
|
|
181
|
+
**vpay appends nothing to your `return_url`** (decision D3). Stripe's
|
|
182
|
+
`payment_intent`, `payment_intent_client_secret` and `redirect_status` query
|
|
183
|
+
parameters are **absent**. A page handling the return trip must carry its own
|
|
184
|
+
state — put the `client_secret` in the `return_url` you supply, or key on your
|
|
185
|
+
own order id — and then call `retrievePaymentIntent` to learn the outcome.
|
|
186
|
+
|
|
187
|
+
**Step 5c ships push-only** (decision D4). `confirmPayment` returns the rail's
|
|
188
|
+
real `redirect_to_url` and will navigate to it, but the _return_ trip is not
|
|
189
|
+
wired: vpay has no `/provider/{code}/callback` route, so a redirect rail sends
|
|
190
|
+
the payer to a URL that does not exist yet. Do not ship a redirect-rail
|
|
191
|
+
checkout on this package until that route lands. `next_action.redirect_to_url.return_url`
|
|
192
|
+
is echoed back as a label; nothing redirects to it.
|
|
193
|
+
|
|
194
|
+
## Checkout (vpay's own)
|
|
195
|
+
|
|
196
|
+
A Checkout Session (`cs_…`, Step 9's D1) is created by the **merchant's
|
|
197
|
+
server** against an existing PaymentIntent, and carries where the payer goes
|
|
198
|
+
afterwards. It is a second credential of the same shape as the intent's:
|
|
199
|
+
`cs_…_secret_…` authorises reading one session, and nothing else — in
|
|
200
|
+
particular it is not the secret that authorises `confirm`.
|
|
201
|
+
|
|
202
|
+
```ts
|
|
203
|
+
// server (Node, @vaam-apps/vpay-sdk)
|
|
204
|
+
const session = await vpay.checkout.sessions.create({
|
|
205
|
+
payment_intent: intent.id,
|
|
206
|
+
ui_mode: "embedded",
|
|
207
|
+
return_url: "https://shop.example/order/42",
|
|
208
|
+
});
|
|
209
|
+
// hand session.client_secret to the browser through your own route
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
```ts
|
|
213
|
+
// browser
|
|
214
|
+
const stripe = await loadStripe(publishableKey, {
|
|
215
|
+
baseUrl: "https://api.vpay.example",
|
|
216
|
+
checkoutBaseUrl: "https://checkout.vpay.example", // required for embedded
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
const checkout = await stripe.initEmbeddedCheckout({
|
|
220
|
+
fetchClientSecret: async () =>
|
|
221
|
+
(
|
|
222
|
+
await fetch("/create-checkout-session", { method: "POST" }).then((r) =>
|
|
223
|
+
r.json(),
|
|
224
|
+
)
|
|
225
|
+
).client_secret,
|
|
226
|
+
onComplete: ({ session, status }) => {
|
|
227
|
+
// A message from an iframe, not proof of payment. Re-read the session
|
|
228
|
+
// from your own server before you ship anything.
|
|
229
|
+
checkout.unmount();
|
|
230
|
+
show(session, status);
|
|
231
|
+
},
|
|
232
|
+
});
|
|
233
|
+
checkout.mount("#checkout");
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
`checkoutBaseUrl` is your deployment's `checkout.public_base_url`. It is
|
|
237
|
+
**required** for `initEmbeddedCheckout`, which rejects without it, and it is
|
|
238
|
+
also the origin every incoming `message` is pinned against — a wrong value
|
|
239
|
+
does not fail loudly, it silently accepts nothing.
|
|
240
|
+
|
|
241
|
+
### The frame, and what crosses it
|
|
242
|
+
|
|
243
|
+
The iframe's `src` is
|
|
244
|
+
`{checkoutBaseUrl}/e/{cs_id}?key={pk}#{client_secret}`. The publishable key
|
|
245
|
+
is in the query string because vpay's page needs it server-side, before any
|
|
246
|
+
script runs, to derive the `frame-ancestors` for your origin; the session
|
|
247
|
+
secret is in the **fragment**, which no browser ever sends to a server
|
|
248
|
+
(decision D6).
|
|
249
|
+
|
|
250
|
+
Three messages come back from vpay's page, and each is acted on only when
|
|
251
|
+
`event.origin` equals `new URL(checkoutBaseUrl).origin` **and**
|
|
252
|
+
`event.source` is this frame:
|
|
253
|
+
|
|
254
|
+
| Message | Effect |
|
|
255
|
+
| -------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
|
|
256
|
+
| `{ type: 'vpay:resize', height }` | Sets the frame's height. The page owns its own height; until the first one arrives the frame is `0px` tall. |
|
|
257
|
+
| `{ type: 'vpay:complete', session, status }` | Calls your `onComplete`. Both members must be strings or the message is ignored. |
|
|
258
|
+
| `{ type: 'vpay:redirect', url }` | `window.top.location.assign(url)` — the redirect rail's hand-off. Refused unless `url` is an absolute `http(s)` URL. |
|
|
259
|
+
|
|
260
|
+
This package **posts nothing into the frame**, so there is no target origin
|
|
261
|
+
to get wrong (no `postMessage(…, '*')`, which is the mistake the protocol
|
|
262
|
+
was designed to preclude). The frame is sandboxed
|
|
263
|
+
`allow-scripts allow-same-origin allow-forms` — notably _without_
|
|
264
|
+
`allow-top-navigation`, which is why the redirect rail's hand-off is a
|
|
265
|
+
message your page acts on rather than something the frame does itself.
|
|
266
|
+
|
|
267
|
+
### The popup, and why its message comes from _your_ page
|
|
268
|
+
|
|
269
|
+
`openCheckoutPopup` is the third surface: vpay's **hosted** page in a
|
|
270
|
+
top-level window your page opened, rather than in an iframe or in the
|
|
271
|
+
payer's own tab.
|
|
272
|
+
|
|
273
|
+
```ts
|
|
274
|
+
// browser, inside a click handler
|
|
275
|
+
try {
|
|
276
|
+
const popup = await stripe.openCheckoutPopup({
|
|
277
|
+
// Your own server's `POST /v1/checkout/sessions` with ui_mode: 'hosted'.
|
|
278
|
+
fetchCheckoutUrl: async () =>
|
|
279
|
+
(await fetch("/checkout-url", { method: "POST" }).then((r) => r.json()))
|
|
280
|
+
.url,
|
|
281
|
+
onComplete: ({ session, status }) => {
|
|
282
|
+
// A message, not proof of payment: re-read the order from your own
|
|
283
|
+
// server, which your webhook is what writes.
|
|
284
|
+
refresh(session, status);
|
|
285
|
+
},
|
|
286
|
+
onCancel: () => show("The payment window was closed."),
|
|
287
|
+
});
|
|
288
|
+
} catch (err) {
|
|
289
|
+
if (err instanceof CheckoutPopupBlockedError) {
|
|
290
|
+
window.location.assign(await checkoutUrl()); // no browser blocks this
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
```ts
|
|
296
|
+
// browser, on the success_url page — which loads *inside* the popup
|
|
297
|
+
import { notifyCheckoutOpener } from "@vaam-apps/vpay-stripe-js";
|
|
298
|
+
|
|
299
|
+
notifyCheckoutOpener({ session: sessionIdFromTheUrl, status: "complete" });
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
Three things about this differ from the embedded surface, and each of them
|
|
303
|
+
is a consequence of a popup not being a frame:
|
|
304
|
+
|
|
305
|
+
1. **The completion message is sent by your return page, not by vpay's.**
|
|
306
|
+
Inside a popup `window.parent === window`, so vpay's checkout page has no
|
|
307
|
+
framer to post to and deliberately says nothing. What closes the loop is
|
|
308
|
+
`success_url` — your page, running in the popup, calling
|
|
309
|
+
`notifyCheckoutOpener`, which posts `{type:'vpay:complete', session,
|
|
310
|
+
status}` to `window.opener` and closes the window.
|
|
311
|
+
2. **`completionOrigin` therefore defaults to your own origin**, not to
|
|
312
|
+
`checkoutBaseUrl`. Pinning vpay's checkout origin here would accept
|
|
313
|
+
nothing at all. `checkoutBaseUrl` is not consulted by this method.
|
|
314
|
+
3. **`notifyCheckoutOpener` answers `false` and does nothing when there is
|
|
315
|
+
no opener**, which is exactly what happens when the same page is reached
|
|
316
|
+
by an ordinary redirect. One return page serves both integrations
|
|
317
|
+
without branching on a query parameter.
|
|
318
|
+
|
|
319
|
+
Two limits of that third property, stated because they are easy to meet and
|
|
320
|
+
neither is visible from the call site (review finding, 2026-09-06):
|
|
321
|
+
|
|
322
|
+
- **"Has an opener" is not the same as "is a vpay popup."** A tab your shop
|
|
323
|
+
was opened into by someone else's `window.open` also has one, and a payer
|
|
324
|
+
who then checks out by an ordinary **redirect** reaches the same return
|
|
325
|
+
page. The message itself is harmless there — it is pinned to
|
|
326
|
+
`targetOrigin`, so a third-party opener never receives it — but the default
|
|
327
|
+
`close: true` will close that payer's tab. Pass `close: false` on a return
|
|
328
|
+
page that also serves the redirect integration, or gate the call on
|
|
329
|
+
something only your popup path sets.
|
|
330
|
+
- **A `success_url` on a different origin from the page that opened the popup
|
|
331
|
+
is a silent no-op.** `targetOrigin` defaults to the return page's own
|
|
332
|
+
origin and `completionOrigin` to the opener's, so the browser drops the
|
|
333
|
+
message and `notifyCheckoutOpener` still answers `true` — it posted; nobody
|
|
334
|
+
could receive it. Name both explicitly when the two origins differ.
|
|
335
|
+
|
|
336
|
+
The window is opened **before** `fetchCheckoutUrl` is awaited, because
|
|
337
|
+
`window.open` succeeds only inside the user gesture that triggered it;
|
|
338
|
+
awaiting first is the usual way a popup integration gets blocked. A window
|
|
339
|
+
the browser refused is a `CheckoutPopupBlockedError` — the one failure here
|
|
340
|
+
that a correct integration can still hit, and the one you are expected to
|
|
341
|
+
fall back from. `location=yes` is in the window features on purpose: a
|
|
342
|
+
payment window that hides the address bar is a phishing lesson.
|
|
343
|
+
|
|
344
|
+
`windowName` defaults to `vpay-checkout`, and reusing the name reuses the
|
|
345
|
+
window — a second call navigates the window the first one opened rather than
|
|
346
|
+
opening a second checkout. That navigation is a `location.href` assignment
|
|
347
|
+
and not `location.assign()`, deliberately: the reused window is already on
|
|
348
|
+
vpay's origin, where the `href` setter and `replace()` are the only members
|
|
349
|
+
of `Location` an opener may touch.
|
|
350
|
+
|
|
351
|
+
`onCancel` is opt-in, and passing it is what starts a `closed` poll — a
|
|
352
|
+
closed window fires no event at its opener in any browser. It fires when the
|
|
353
|
+
payer dismissed the window without completing; it is **not** a cancellation
|
|
354
|
+
of the charge, which is untouched and may still settle.
|
|
355
|
+
|
|
356
|
+
`retrieveCheckoutSession(clientSecret)` reads
|
|
357
|
+
`GET /v1/browser/checkout/sessions/{id}` and, like everything else on the
|
|
358
|
+
`Stripe` object, never rejects.
|
|
359
|
+
|
|
360
|
+
On that route `payment_intent` is the **expanded intent**, not the `pi_…`
|
|
361
|
+
id, `client_secret` included — vpay's checkout page has to confirm and poll
|
|
362
|
+
it through the existing browser routes, and a second round trip to fetch it
|
|
363
|
+
would need a credential the page does not have yet. On the merchant SDKs
|
|
364
|
+
(`@vaam-apps/vpay-sdk`, `vpay_sdk`) the same field stays the id. So:
|
|
365
|
+
|
|
366
|
+
```ts
|
|
367
|
+
const { checkoutSession, error } = await stripe.retrieveCheckoutSession(cs);
|
|
368
|
+
checkoutSession?.status; // 'open' | 'complete' | 'expired'
|
|
369
|
+
checkoutSession?.payment_intent.status; // the whole intent, not an id
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
**This hands your page a live _confirm_ credential**
|
|
373
|
+
(`checkoutSession.payment_intent.client_secret`), which is a wider exposure
|
|
374
|
+
than the session's own secret. If all you want is whether the payer paid,
|
|
375
|
+
read `status` and `payment_status` and leave the intent alone. The route
|
|
376
|
+
also carries the merchant's display name for vpay's own page; this package
|
|
377
|
+
does not model it.
|
|
378
|
+
|
|
379
|
+
## Errors
|
|
380
|
+
|
|
381
|
+
Nothing on the `Stripe` object ever rejects. Every failure is
|
|
382
|
+
`{ error: { type, code?, message?, param? } }` — vpay's server envelope
|
|
383
|
+
passed through 1:1, or one of the three codes this package originates.
|
|
384
|
+
|
|
385
|
+
| `type` | `code` | Origin |
|
|
386
|
+
| ----------------------- | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
387
|
+
| `invalid_request_error` | `resource_missing` | The uniform 404. **Every** credential failure renders it byte-identically: unknown publishable key, wrong `client_secret`, another merchant's key, unknown intent. |
|
|
388
|
+
| `invalid_request_error` | `invalid_state` | The intent has already been confirmed. One charge per intent, forever — retry means a new PaymentIntent. |
|
|
389
|
+
| `invalid_request_error` | `checkout_session_expired` | The checkout session driving this intent is over — swept at its 24-hour horizon, expired by the merchant, or past that horizon and not yet swept. `confirmPayment` is refused before any charge is opened. Render the abandoned-checkout screen; a retry needs a **new** checkout session. |
|
|
390
|
+
| `invalid_request_error` | `checkout_session_complete` | The session already finished and its intent is `succeeded`. Not an error to retry: read the session and show the outcome. |
|
|
391
|
+
| `invalid_request_error` | `charge_declined` | The rail refused the payment. The charge is terminal and the intent keeps `requires_payment_method` with `last_payment_error` populated; a retry means a new PaymentIntent. |
|
|
392
|
+
| `invalid_request_error` | `invalid_request` | A parameter this package refused before sending: a malformed `clientSecret` (`param: 'clientSecret'`), an unencodable `payment_method_data`. |
|
|
393
|
+
| `api_error` | `provider_unavailable` | The rail. Retryable. |
|
|
394
|
+
| `api_error` | `polling_timeout` | **Client.** `waitForPaymentIntent` ran out of budget. |
|
|
395
|
+
| `api_error` | `redirect_unavailable` | **Client.** A redirect was required and there is no `window`. |
|
|
396
|
+
| `api_error` | `unexpected_response` | **Client.** Not vpay's envelope — a proxy's HTML 502, say. Carries the status, never the body. |
|
|
397
|
+
| `api_connection_error` | _(none)_ | **Client.** The request never landed. The absence of a code is the signal: vpay's server never sends this type. |
|
|
398
|
+
|
|
399
|
+
No message this package builds contains a `client_secret` or a publishable
|
|
400
|
+
key, and there is no `console` call in the shipping source — both are pinned
|
|
401
|
+
by tests, because the request URL carries both credentials in its query
|
|
402
|
+
string and a thrown `fetch` error's `cause` can carry the URL.
|
|
403
|
+
|
|
404
|
+
`loadStripe` and `initEmbeddedCheckout` are the two functions here that _do_
|
|
405
|
+
reject, and for the same reason: a blank publishable key, a `checkoutBaseUrl`
|
|
406
|
+
that is not an absolute `http(s)` URL, a missing one where an embedded
|
|
407
|
+
checkout needs it, or a `fetchClientSecret` that did not return a
|
|
408
|
+
`cs_…_secret_…` are integration mistakes visible on the merchant's first page
|
|
409
|
+
load rather than payer-facing failures. A rejection from your own
|
|
410
|
+
`fetchClientSecret` is passed through **unchanged** — it is your server call
|
|
411
|
+
failing, and a message this package invented on top of it would hide the
|
|
412
|
+
fault. Checking these once is what lets every other method keep the
|
|
413
|
+
never-rejects contract.
|
|
414
|
+
|
|
415
|
+
## Development
|
|
416
|
+
|
|
417
|
+
```bash
|
|
418
|
+
pnpm --filter @vaam-apps/vpay-stripe-js typecheck
|
|
419
|
+
pnpm --filter @vaam-apps/vpay-stripe-js test
|
|
420
|
+
pnpm --filter @vaam-apps/vpay-stripe-js build # tsc → dist/, gitignored
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
Unit tests run against a real `node:http` server standing in for
|
|
424
|
+
`/v1/browser` (`src/testing/browser-stub.ts`), not a patched `fetch`: the
|
|
425
|
+
contract under test is bytes on the wire. That stub is excluded from `dist`
|
|
426
|
+
and imported only from `*.test.ts`, so it is not a test double reachable from
|
|
427
|
+
a shipping process in ADR-0006's sense.
|
|
428
|
+
|
|
429
|
+
## Status
|
|
430
|
+
|
|
431
|
+
**Verified end to end on the compose stack, not yet in CI.**
|
|
432
|
+
|
|
433
|
+
- The payment-intent half: implemented, typechecked and unit-tested against
|
|
434
|
+
a `node:http` stub of the surface in
|
|
435
|
+
`docs/plans/2026-09-03-step5c-stripejs.md` §1. 119 tests pass, none
|
|
436
|
+
skipped or ignored.
|
|
437
|
+
- The server routes it speaks to — `GET /v1/browser/payment_intents/{id}` and
|
|
438
|
+
`POST /v1/browser/payment_intents/{id}/confirm`, publishable keys, the
|
|
439
|
+
`client_secret` column and the CORS layer — landed in the same step (block
|
|
440
|
+
A) and are proven by `backends/tests/integration/tests/browser_checkout.rs`
|
|
441
|
+
against real Postgres and WireMock.
|
|
442
|
+
- The end-to-end proof through this package is
|
|
443
|
+
`frontends/tests/e2e/cypress/e2e/checkout.cy.ts`, which drives
|
|
444
|
+
`examples/checkout-browser` to `succeeded` on the compose stack. It has
|
|
445
|
+
passed locally; it is wired into the CI `e2e` job but has not yet been
|
|
446
|
+
observed green in a GitHub Actions run.
|
|
447
|
+
- The redirect _return_ trip **was** a named gap (D4). It was **closed on
|
|
448
|
+
2026-09-04 (Step 9)**: the rail is now told a per-charge `return_url` and
|
|
449
|
+
vpay serves the page the payer comes back to — see
|
|
450
|
+
`docs/flows/hosted-checkout.md`. See `docs/status.md` for the
|
|
451
|
+
repository-wide picture.
|
|
452
|
+
- **Checkout is newer and less proven than the rest of this package.**
|
|
453
|
+
`initEmbeddedCheckout` is exercised against a real `iframe` in jsdom
|
|
454
|
+
(`src/embedded.test.ts`, 20 tests) and `retrieveCheckoutSession` against
|
|
455
|
+
the `node:http` stub (`src/checkout-session.test.ts`, 10 tests). Neither of
|
|
456
|
+
those two suites runs against a live vpay. The end-to-end proof that does is
|
|
457
|
+
`frontends/tests/e2e/cypress/e2e/shop-embedded.cy.ts` (Step 9, lane 6),
|
|
458
|
+
which frames vpay's own checkout page on `examples/shop` and completes a
|
|
459
|
+
payment inside it — **green from nothing in the `vpay-ci` VM on
|
|
460
|
+
2026-09-04**. What that spec cannot see is recorded on its own
|
|
461
|
+
`docs/status.md` row.
|
|
462
|
+
- **The popup surface (`openCheckoutPopup` / `notifyCheckoutOpener`) is
|
|
463
|
+
unit-tested and has not been driven by a real browser.** `src/popup.test.ts`
|
|
464
|
+
(26 tests) drives it against stub windows, because jsdom implements
|
|
465
|
+
neither `window.open` nor cross-window `postMessage` — so what is proven
|
|
466
|
+
is the origin check, the source check, the open-before-await ordering, the
|
|
467
|
+
blocked-window error, the cancel poll and the round trip between the two
|
|
468
|
+
halves. What is **not** proven anywhere yet is a real browser opening a
|
|
469
|
+
real window: no Cypress spec covers it, and the hand-run of
|
|
470
|
+
`examples/shop`'s popup mode on 2026-09-06 reached only the **fallback** —
|
|
471
|
+
the automation's synthetic click carries no user activation, so
|
|
472
|
+
`window.open` answered `null` and `CheckoutPopupBlockedError` did its job.
|
|
473
|
+
Recorded on `docs/status.md` and as a dated ⛔ in `docs/sdks/parity.md`.
|
|
474
|
+
- The `vpay:complete` payload is read strictly: `session` and `status` must
|
|
475
|
+
both be strings. If vpay's checkout page ever sends the session as an
|
|
476
|
+
object, `onComplete` stops firing rather than firing with fields it cannot
|
|
477
|
+
read — visible immediately, and by design.
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type CheckoutPopup, type OpenCheckoutPopupOptions } from "./popup.js";
|
|
2
|
+
import type { CheckoutSessionResult, ConfirmPaymentOptions, EmbeddedCheckout, InitEmbeddedCheckoutOptions, MobileMoneyData, PaymentIntentResult, Stripe, VpayStripeOptions, WaitForPaymentIntentOptions } from "./types.js";
|
|
3
|
+
declare const INSPECT_CUSTOM: unique symbol;
|
|
4
|
+
/**
|
|
5
|
+
* vpay's `Stripe` object. Constructed only by {@link loadStripe}.
|
|
6
|
+
*
|
|
7
|
+
* Holds a publishable key and a base URL and nothing else — in particular it
|
|
8
|
+
* never retains a `client_secret`, which is why the redacted representations
|
|
9
|
+
* below can be exhaustive rather than a filter.
|
|
10
|
+
*/
|
|
11
|
+
export declare class VpayStripe implements Stripe {
|
|
12
|
+
#private;
|
|
13
|
+
constructor(publishableKey: string, baseUrl: string, checkoutBaseUrl: string | undefined, fetchImpl: typeof fetch);
|
|
14
|
+
retrievePaymentIntent(clientSecret: string): Promise<PaymentIntentResult>;
|
|
15
|
+
confirmPayment(options: ConfirmPaymentOptions): Promise<PaymentIntentResult>;
|
|
16
|
+
handleNextAction(options: {
|
|
17
|
+
clientSecret: string;
|
|
18
|
+
}): Promise<PaymentIntentResult>;
|
|
19
|
+
confirmMobileMoneyPayment(clientSecret: string, data: MobileMoneyData): Promise<PaymentIntentResult>;
|
|
20
|
+
waitForPaymentIntent(clientSecret: string, options?: WaitForPaymentIntentOptions): Promise<PaymentIntentResult>;
|
|
21
|
+
retrieveCheckoutSession(clientSecret: string): Promise<CheckoutSessionResult>;
|
|
22
|
+
initEmbeddedCheckout(options: InitEmbeddedCheckoutOptions): Promise<EmbeddedCheckout>;
|
|
23
|
+
openCheckoutPopup(options: OpenCheckoutPopupOptions): Promise<CheckoutPopup>;
|
|
24
|
+
/** A safe, redacted representation. This object holds no secret to redact. */
|
|
25
|
+
[INSPECT_CUSTOM](): string;
|
|
26
|
+
/** A safe, redacted representation. This object holds no secret to redact. */
|
|
27
|
+
toJSON(): {
|
|
28
|
+
object: "vpay_stripe";
|
|
29
|
+
publishableKey: string;
|
|
30
|
+
baseUrl: string;
|
|
31
|
+
checkoutBaseUrl?: string;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Builds a {@link Stripe} bound to one vpay deployment and one publishable
|
|
36
|
+
* key.
|
|
37
|
+
*
|
|
38
|
+
* Asynchronous purely for source compatibility with `@stripe/stripe-js`'s
|
|
39
|
+
* `loadStripe`, whose promise covers a `<script>` download. This one has
|
|
40
|
+
* nothing to download — the whole point of the package is that
|
|
41
|
+
* `js.stripe.com` is not in the picture — so it resolves immediately.
|
|
42
|
+
*
|
|
43
|
+
* **This is the one function here that rejects.** A blank publishable key or
|
|
44
|
+
* base URL is an integration mistake visible on the merchant's first page
|
|
45
|
+
* load, not a payer-facing failure, and the `Stripe` object's methods keep
|
|
46
|
+
* their never-rejects contract precisely because the arguments were checked
|
|
47
|
+
* once, here.
|
|
48
|
+
*/
|
|
49
|
+
export declare function loadStripe(publishableKey: string, options: VpayStripeOptions): Promise<Stripe>;
|
|
50
|
+
export {};
|