@proxy-checkout/stripe-server-js 0.0.0 → 0.0.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/README.md +8 -9
- package/dist/cjs/errors.d.cts +38 -0
- package/dist/cjs/errors.d.ts +38 -0
- package/dist/cjs/errors.js +38 -0
- package/dist/cjs/index.d.cts +7 -0
- package/dist/cjs/index.d.ts +7 -0
- package/dist/cjs/index.js +22 -0
- package/dist/cjs/metadata.d.cts +46 -0
- package/dist/{metadata.d.ts → cjs/metadata.d.ts} +7 -1
- package/dist/cjs/metadata.js +92 -0
- package/dist/cjs/open-checkout.d.cts +60 -0
- package/dist/cjs/open-checkout.d.ts +60 -0
- package/dist/cjs/open-checkout.js +210 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/psp.d.cts +12 -0
- package/dist/cjs/psp.d.ts +12 -0
- package/dist/cjs/psp.js +25 -0
- package/dist/cjs/sync-checkout-cart.d.cts +47 -0
- package/dist/{sync-checkout-cart.d.ts → cjs/sync-checkout-cart.d.ts} +3 -1
- package/dist/cjs/sync-checkout-cart.js +97 -0
- package/dist/cjs/types.d.cts +52 -0
- package/dist/{types.d.ts → cjs/types.d.ts} +20 -3
- package/dist/cjs/types.js +10 -0
- package/dist/cjs/version.d.cts +2 -0
- package/dist/{version.d.ts → cjs/version.d.ts} +1 -1
- package/dist/cjs/version.js +5 -0
- package/dist/esm/errors.d.ts +38 -0
- package/dist/esm/errors.js +33 -0
- package/dist/esm/index.d.ts +7 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/metadata.d.ts +46 -0
- package/dist/{metadata.js → esm/metadata.js} +44 -0
- package/dist/esm/open-checkout.d.ts +60 -0
- package/dist/esm/open-checkout.js +207 -0
- package/dist/esm/psp.d.ts +12 -0
- package/dist/esm/psp.js +22 -0
- package/dist/esm/sync-checkout-cart.d.ts +47 -0
- package/dist/{sync-checkout-cart.js → esm/sync-checkout-cart.js} +37 -17
- package/dist/esm/types.d.ts +52 -0
- package/dist/esm/version.d.ts +2 -0
- package/dist/{version.js → esm/version.js} +1 -1
- package/package.json +16 -8
- package/dist/errors.d.ts +0 -20
- package/dist/errors.js +0 -15
- package/dist/index.d.ts +0 -6
- package/dist/index.js +0 -5
- package/dist/open-checkout.d.ts +0 -48
- package/dist/open-checkout.js +0 -48
- /package/dist/{types.js → esm/types.js} +0 -0
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Server-side Stripe adapter for Proxy Checkout. It owns the Stripe-specific integ
|
|
|
4
4
|
|
|
5
5
|
- **`requiredMetadata(proxySession)`** — the `proxy_session_id` metadata Proxy needs on the Checkout Session, Subscription, and PaymentIntent.
|
|
6
6
|
- **`assertCheckoutSessionBelongsToProxy` / `assertSubscriptionBelongsToProxy` / `assertPaymentIntentBelongsToProxy`** — provider-object ownership checks.
|
|
7
|
-
- **`openCheckout(...)`** — records payer-opened, validates the typed cart,
|
|
7
|
+
- **`openCheckout(...)`** — records payer-opened, validates/reconciles the typed cart with rollback, injects required metadata, creates the Stripe Checkout Session with deterministic idempotency, records the Proxy provider binding, and returns the client secret. The merchant only supplies app-specific Stripe params.
|
|
8
8
|
- **`syncCheckoutCart(...)`** — validates the stored Proxy provider binding, then updates the Proxy cart and the Stripe Checkout `line_items` in the safest order with deterministic rollback/reconciliation (`ProxyStripeCartSyncError`).
|
|
9
9
|
|
|
10
10
|
PSP-agnostic primitives (sessions, subscriptions, webhooks, lifecycle) live in [`@proxy-checkout/server-js`](https://www.npmjs.com/package/@proxy-checkout/server-js). This package is an additive adapter on top and is dependency-free: you inject your own `Stripe` instance and your `@proxy-checkout/server-js` client.
|
|
@@ -32,13 +32,11 @@ const checkout = await openCheckout({
|
|
|
32
32
|
proxySessionId,
|
|
33
33
|
cartSchema, // a zod-style schema, or any (value) => Cart validator
|
|
34
34
|
validateCart: ({ cart }) => buildMerchantOffer(cart),
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
subscription_data: { metadata: metadata.subscriptionData.metadata },
|
|
41
|
-
}),
|
|
35
|
+
buildCheckoutSessionParams: ({ cart, offer }) => ({
|
|
36
|
+
...buildMerchantStripeParams(cart, offer),
|
|
37
|
+
mode: "subscription",
|
|
38
|
+
ui_mode: "custom",
|
|
39
|
+
}),
|
|
42
40
|
});
|
|
43
41
|
// checkout.clientSecret -> render Stripe Elements
|
|
44
42
|
|
|
@@ -55,4 +53,5 @@ await syncCheckoutCart({
|
|
|
55
53
|
});
|
|
56
54
|
```
|
|
57
55
|
|
|
58
|
-
|
|
56
|
+
Use the delegated-checkout guide from your Proxy onboarding materials for the
|
|
57
|
+
full four-route integration recipe.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapter-specific error raised when a Stripe/Proxy cart synchronization cannot
|
|
3
|
+
* complete cleanly. The `reconciled` flag is true only when the SDK verified the
|
|
4
|
+
* Proxy and Stripe carts are back in a consistent state.
|
|
5
|
+
*/
|
|
6
|
+
export type ProxyStripeCartSyncCode = "reconciliation_failed" | "stripe_update_failed";
|
|
7
|
+
export type ProxyStripeOpenCheckoutCode = "provider_binding_failed";
|
|
8
|
+
/**
|
|
9
|
+
* Raised after Stripe Checkout creation succeeds but the Proxy binding cannot
|
|
10
|
+
* be recorded or reconciled. The provider id is exposed so operators can find
|
|
11
|
+
* and expire/refund the orphaned provider object deterministically.
|
|
12
|
+
*/
|
|
13
|
+
export declare class ProxyStripeOpenCheckoutError extends Error {
|
|
14
|
+
readonly name = "ProxyStripeOpenCheckoutError";
|
|
15
|
+
readonly code: ProxyStripeOpenCheckoutCode;
|
|
16
|
+
readonly cause: unknown;
|
|
17
|
+
readonly providerCheckoutSessionId: string;
|
|
18
|
+
readonly reconciled = false;
|
|
19
|
+
constructor(message: string, details: {
|
|
20
|
+
cause: unknown;
|
|
21
|
+
code: ProxyStripeOpenCheckoutCode;
|
|
22
|
+
providerCheckoutSessionId: string;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
export declare class ProxyStripeCartSyncError extends Error {
|
|
26
|
+
readonly name = "ProxyStripeCartSyncError";
|
|
27
|
+
readonly code: ProxyStripeCartSyncCode;
|
|
28
|
+
/** True only when the SDK verified Proxy and Stripe are in a consistent state. */
|
|
29
|
+
readonly reconciled: boolean;
|
|
30
|
+
readonly cause: unknown;
|
|
31
|
+
readonly rollbackCause: unknown;
|
|
32
|
+
constructor(message: string, details: {
|
|
33
|
+
code: ProxyStripeCartSyncCode;
|
|
34
|
+
reconciled: boolean;
|
|
35
|
+
cause: unknown;
|
|
36
|
+
rollbackCause?: unknown;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapter-specific error raised when a Stripe/Proxy cart synchronization cannot
|
|
3
|
+
* complete cleanly. The `reconciled` flag is true only when the SDK verified the
|
|
4
|
+
* Proxy and Stripe carts are back in a consistent state.
|
|
5
|
+
*/
|
|
6
|
+
export type ProxyStripeCartSyncCode = "reconciliation_failed" | "stripe_update_failed";
|
|
7
|
+
export type ProxyStripeOpenCheckoutCode = "provider_binding_failed";
|
|
8
|
+
/**
|
|
9
|
+
* Raised after Stripe Checkout creation succeeds but the Proxy binding cannot
|
|
10
|
+
* be recorded or reconciled. The provider id is exposed so operators can find
|
|
11
|
+
* and expire/refund the orphaned provider object deterministically.
|
|
12
|
+
*/
|
|
13
|
+
export declare class ProxyStripeOpenCheckoutError extends Error {
|
|
14
|
+
readonly name = "ProxyStripeOpenCheckoutError";
|
|
15
|
+
readonly code: ProxyStripeOpenCheckoutCode;
|
|
16
|
+
readonly cause: unknown;
|
|
17
|
+
readonly providerCheckoutSessionId: string;
|
|
18
|
+
readonly reconciled = false;
|
|
19
|
+
constructor(message: string, details: {
|
|
20
|
+
cause: unknown;
|
|
21
|
+
code: ProxyStripeOpenCheckoutCode;
|
|
22
|
+
providerCheckoutSessionId: string;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
export declare class ProxyStripeCartSyncError extends Error {
|
|
26
|
+
readonly name = "ProxyStripeCartSyncError";
|
|
27
|
+
readonly code: ProxyStripeCartSyncCode;
|
|
28
|
+
/** True only when the SDK verified Proxy and Stripe are in a consistent state. */
|
|
29
|
+
readonly reconciled: boolean;
|
|
30
|
+
readonly cause: unknown;
|
|
31
|
+
readonly rollbackCause: unknown;
|
|
32
|
+
constructor(message: string, details: {
|
|
33
|
+
code: ProxyStripeCartSyncCode;
|
|
34
|
+
reconciled: boolean;
|
|
35
|
+
cause: unknown;
|
|
36
|
+
rollbackCause?: unknown;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProxyStripeCartSyncError = exports.ProxyStripeOpenCheckoutError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Raised after Stripe Checkout creation succeeds but the Proxy binding cannot
|
|
6
|
+
* be recorded or reconciled. The provider id is exposed so operators can find
|
|
7
|
+
* and expire/refund the orphaned provider object deterministically.
|
|
8
|
+
*/
|
|
9
|
+
class ProxyStripeOpenCheckoutError extends Error {
|
|
10
|
+
name = "ProxyStripeOpenCheckoutError";
|
|
11
|
+
code;
|
|
12
|
+
cause;
|
|
13
|
+
providerCheckoutSessionId;
|
|
14
|
+
reconciled = false;
|
|
15
|
+
constructor(message, details) {
|
|
16
|
+
super(message);
|
|
17
|
+
this.cause = details.cause;
|
|
18
|
+
this.code = details.code;
|
|
19
|
+
this.providerCheckoutSessionId = details.providerCheckoutSessionId;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.ProxyStripeOpenCheckoutError = ProxyStripeOpenCheckoutError;
|
|
23
|
+
class ProxyStripeCartSyncError extends Error {
|
|
24
|
+
name = "ProxyStripeCartSyncError";
|
|
25
|
+
code;
|
|
26
|
+
/** True only when the SDK verified Proxy and Stripe are in a consistent state. */
|
|
27
|
+
reconciled;
|
|
28
|
+
cause;
|
|
29
|
+
rollbackCause;
|
|
30
|
+
constructor(message, details) {
|
|
31
|
+
super(message);
|
|
32
|
+
this.code = details.code;
|
|
33
|
+
this.reconciled = details.reconciled;
|
|
34
|
+
this.cause = details.cause;
|
|
35
|
+
this.rollbackCause = details.rollbackCause;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.ProxyStripeCartSyncError = ProxyStripeCartSyncError;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { type ProxyStripeCartSyncCode, ProxyStripeCartSyncError, type ProxyStripeOpenCheckoutCode, ProxyStripeOpenCheckoutError, } from "./errors.js";
|
|
2
|
+
export { assertCheckoutSessionBelongsToProxy, assertPaymentIntentBelongsToProxy, assertSubscriptionBelongsToProxy, injectRequiredCheckoutSessionMetadata, PROXY_SESSION_METADATA_KEY, type ProxySessionMetadata, type ProxyStripeRequiredMetadata, requiredMetadata, } from "./metadata.js";
|
|
3
|
+
export { type OpenCheckoutOptions, type OpenCheckoutReconciledCart, type OpenCheckoutResult, openCheckout, } from "./open-checkout.js";
|
|
4
|
+
export { normalizePsp } from "./psp.js";
|
|
5
|
+
export { type SyncCheckoutCartOptions, type SyncCheckoutCartResult, type SyncedCart, syncCheckoutCart, } from "./sync-checkout-cart.js";
|
|
6
|
+
export type { StripeCheckoutSessionCreateParams, StripeCheckoutSessionLike, StripeCheckoutSessionsApiLike, StripeCheckoutSessionUpdateParams, StripeClientLike, StripeMetadata, StripePaymentIntentLike, StripeRequestOptionsLike, StripeSubscriptionLike, } from "./types.js";
|
|
7
|
+
export { proxyCheckoutStripeServerSdkName, proxyCheckoutStripeServerSdkVersion, } from "./version.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { type ProxyStripeCartSyncCode, ProxyStripeCartSyncError, type ProxyStripeOpenCheckoutCode, ProxyStripeOpenCheckoutError, } from "./errors.js";
|
|
2
|
+
export { assertCheckoutSessionBelongsToProxy, assertPaymentIntentBelongsToProxy, assertSubscriptionBelongsToProxy, injectRequiredCheckoutSessionMetadata, PROXY_SESSION_METADATA_KEY, type ProxySessionMetadata, type ProxyStripeRequiredMetadata, requiredMetadata, } from "./metadata.js";
|
|
3
|
+
export { type OpenCheckoutOptions, type OpenCheckoutReconciledCart, type OpenCheckoutResult, openCheckout, } from "./open-checkout.js";
|
|
4
|
+
export { normalizePsp } from "./psp.js";
|
|
5
|
+
export { type SyncCheckoutCartOptions, type SyncCheckoutCartResult, type SyncedCart, syncCheckoutCart, } from "./sync-checkout-cart.js";
|
|
6
|
+
export type { StripeCheckoutSessionCreateParams, StripeCheckoutSessionLike, StripeCheckoutSessionsApiLike, StripeCheckoutSessionUpdateParams, StripeClientLike, StripeMetadata, StripePaymentIntentLike, StripeRequestOptionsLike, StripeSubscriptionLike, } from "./types.js";
|
|
7
|
+
export { proxyCheckoutStripeServerSdkName, proxyCheckoutStripeServerSdkVersion, } from "./version.js";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.proxyCheckoutStripeServerSdkVersion = exports.proxyCheckoutStripeServerSdkName = exports.syncCheckoutCart = exports.normalizePsp = exports.openCheckout = exports.requiredMetadata = exports.PROXY_SESSION_METADATA_KEY = exports.injectRequiredCheckoutSessionMetadata = exports.assertSubscriptionBelongsToProxy = exports.assertPaymentIntentBelongsToProxy = exports.assertCheckoutSessionBelongsToProxy = exports.ProxyStripeOpenCheckoutError = exports.ProxyStripeCartSyncError = void 0;
|
|
4
|
+
var errors_js_1 = require("./errors.js");
|
|
5
|
+
Object.defineProperty(exports, "ProxyStripeCartSyncError", { enumerable: true, get: function () { return errors_js_1.ProxyStripeCartSyncError; } });
|
|
6
|
+
Object.defineProperty(exports, "ProxyStripeOpenCheckoutError", { enumerable: true, get: function () { return errors_js_1.ProxyStripeOpenCheckoutError; } });
|
|
7
|
+
var metadata_js_1 = require("./metadata.js");
|
|
8
|
+
Object.defineProperty(exports, "assertCheckoutSessionBelongsToProxy", { enumerable: true, get: function () { return metadata_js_1.assertCheckoutSessionBelongsToProxy; } });
|
|
9
|
+
Object.defineProperty(exports, "assertPaymentIntentBelongsToProxy", { enumerable: true, get: function () { return metadata_js_1.assertPaymentIntentBelongsToProxy; } });
|
|
10
|
+
Object.defineProperty(exports, "assertSubscriptionBelongsToProxy", { enumerable: true, get: function () { return metadata_js_1.assertSubscriptionBelongsToProxy; } });
|
|
11
|
+
Object.defineProperty(exports, "injectRequiredCheckoutSessionMetadata", { enumerable: true, get: function () { return metadata_js_1.injectRequiredCheckoutSessionMetadata; } });
|
|
12
|
+
Object.defineProperty(exports, "PROXY_SESSION_METADATA_KEY", { enumerable: true, get: function () { return metadata_js_1.PROXY_SESSION_METADATA_KEY; } });
|
|
13
|
+
Object.defineProperty(exports, "requiredMetadata", { enumerable: true, get: function () { return metadata_js_1.requiredMetadata; } });
|
|
14
|
+
var open_checkout_js_1 = require("./open-checkout.js");
|
|
15
|
+
Object.defineProperty(exports, "openCheckout", { enumerable: true, get: function () { return open_checkout_js_1.openCheckout; } });
|
|
16
|
+
var psp_js_1 = require("./psp.js");
|
|
17
|
+
Object.defineProperty(exports, "normalizePsp", { enumerable: true, get: function () { return psp_js_1.normalizePsp; } });
|
|
18
|
+
var sync_checkout_cart_js_1 = require("./sync-checkout-cart.js");
|
|
19
|
+
Object.defineProperty(exports, "syncCheckoutCart", { enumerable: true, get: function () { return sync_checkout_cart_js_1.syncCheckoutCart; } });
|
|
20
|
+
var version_js_1 = require("./version.js");
|
|
21
|
+
Object.defineProperty(exports, "proxyCheckoutStripeServerSdkName", { enumerable: true, get: function () { return version_js_1.proxyCheckoutStripeServerSdkName; } });
|
|
22
|
+
Object.defineProperty(exports, "proxyCheckoutStripeServerSdkVersion", { enumerable: true, get: function () { return version_js_1.proxyCheckoutStripeServerSdkVersion; } });
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Required Stripe metadata placement + provider-object ownership assertions.
|
|
3
|
+
*
|
|
4
|
+
* Proxy correlates Stripe objects to a session solely through
|
|
5
|
+
* `metadata.proxy_session_id`. This module centralizes that placement so
|
|
6
|
+
* customers never have to remember which Stripe objects need the key, and
|
|
7
|
+
* provides assertions that a Stripe object actually belongs to a Proxy session.
|
|
8
|
+
*/
|
|
9
|
+
import type { StripeCheckoutSessionCreateParams, StripeCheckoutSessionLike, StripePaymentIntentLike, StripeSubscriptionLike } from "./types.js";
|
|
10
|
+
/** The single metadata key Proxy reads to correlate a Stripe object to a session. */
|
|
11
|
+
export declare const PROXY_SESSION_METADATA_KEY = "proxy_session_id";
|
|
12
|
+
export type ProxySessionMetadata = Readonly<Record<"proxy_session_id", string>>;
|
|
13
|
+
/**
|
|
14
|
+
* The metadata each Stripe object must carry, ready to spread into Stripe params.
|
|
15
|
+
*
|
|
16
|
+
* - `checkoutSession` → `metadata` on `checkout.sessions.create`
|
|
17
|
+
* - `subscriptionData` → `subscription_data` for subscription-mode Checkout
|
|
18
|
+
* - `paymentIntentData` → `payment_intent_data` for payment-mode Checkout / PaymentIntents
|
|
19
|
+
*/
|
|
20
|
+
export interface ProxyStripeRequiredMetadata {
|
|
21
|
+
readonly checkoutSession: ProxySessionMetadata;
|
|
22
|
+
readonly paymentIntent: ProxySessionMetadata;
|
|
23
|
+
readonly paymentIntentData: {
|
|
24
|
+
readonly metadata: ProxySessionMetadata;
|
|
25
|
+
};
|
|
26
|
+
readonly subscription: ProxySessionMetadata;
|
|
27
|
+
readonly subscriptionData: {
|
|
28
|
+
readonly metadata: ProxySessionMetadata;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** Build the required Stripe metadata placements for a Proxy session. */
|
|
32
|
+
export declare function requiredMetadata(proxySession: {
|
|
33
|
+
id: string;
|
|
34
|
+
}): ProxyStripeRequiredMetadata;
|
|
35
|
+
/**
|
|
36
|
+
* Return Stripe Checkout Session create params with required Proxy metadata in
|
|
37
|
+
* every object Proxy may later need to correlate. Conflicting merchant-provided
|
|
38
|
+
* proxy metadata fails before any Stripe side effect.
|
|
39
|
+
*/
|
|
40
|
+
export declare function injectRequiredCheckoutSessionMetadata(params: StripeCheckoutSessionCreateParams, proxySessionId: string): StripeCheckoutSessionCreateParams;
|
|
41
|
+
/** Assert a Stripe Checkout Session carries the expected `proxy_session_id` metadata. */
|
|
42
|
+
export declare function assertCheckoutSessionBelongsToProxy(checkoutSession: Pick<StripeCheckoutSessionLike, "metadata">, proxySessionId: string): void;
|
|
43
|
+
/** Assert a Stripe Subscription carries the expected `proxy_session_id` metadata. */
|
|
44
|
+
export declare function assertSubscriptionBelongsToProxy(subscription: Pick<StripeSubscriptionLike, "metadata">, proxySessionId: string): void;
|
|
45
|
+
/** Assert a Stripe PaymentIntent carries the expected `proxy_session_id` metadata. */
|
|
46
|
+
export declare function assertPaymentIntentBelongsToProxy(paymentIntent: Pick<StripePaymentIntentLike, "metadata">, proxySessionId: string): void;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* customers never have to remember which Stripe objects need the key, and
|
|
7
7
|
* provides assertions that a Stripe object actually belongs to a Proxy session.
|
|
8
8
|
*/
|
|
9
|
-
import type { StripeCheckoutSessionLike, StripePaymentIntentLike, StripeSubscriptionLike } from "./types.js";
|
|
9
|
+
import type { StripeCheckoutSessionCreateParams, StripeCheckoutSessionLike, StripePaymentIntentLike, StripeSubscriptionLike } from "./types.js";
|
|
10
10
|
/** The single metadata key Proxy reads to correlate a Stripe object to a session. */
|
|
11
11
|
export declare const PROXY_SESSION_METADATA_KEY = "proxy_session_id";
|
|
12
12
|
export type ProxySessionMetadata = Readonly<Record<"proxy_session_id", string>>;
|
|
@@ -32,6 +32,12 @@ export interface ProxyStripeRequiredMetadata {
|
|
|
32
32
|
export declare function requiredMetadata(proxySession: {
|
|
33
33
|
id: string;
|
|
34
34
|
}): ProxyStripeRequiredMetadata;
|
|
35
|
+
/**
|
|
36
|
+
* Return Stripe Checkout Session create params with required Proxy metadata in
|
|
37
|
+
* every object Proxy may later need to correlate. Conflicting merchant-provided
|
|
38
|
+
* proxy metadata fails before any Stripe side effect.
|
|
39
|
+
*/
|
|
40
|
+
export declare function injectRequiredCheckoutSessionMetadata(params: StripeCheckoutSessionCreateParams, proxySessionId: string): StripeCheckoutSessionCreateParams;
|
|
35
41
|
/** Assert a Stripe Checkout Session carries the expected `proxy_session_id` metadata. */
|
|
36
42
|
export declare function assertCheckoutSessionBelongsToProxy(checkoutSession: Pick<StripeCheckoutSessionLike, "metadata">, proxySessionId: string): void;
|
|
37
43
|
/** Assert a Stripe Subscription carries the expected `proxy_session_id` metadata. */
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Required Stripe metadata placement + provider-object ownership assertions.
|
|
4
|
+
*
|
|
5
|
+
* Proxy correlates Stripe objects to a session solely through
|
|
6
|
+
* `metadata.proxy_session_id`. This module centralizes that placement so
|
|
7
|
+
* customers never have to remember which Stripe objects need the key, and
|
|
8
|
+
* provides assertions that a Stripe object actually belongs to a Proxy session.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.PROXY_SESSION_METADATA_KEY = void 0;
|
|
12
|
+
exports.requiredMetadata = requiredMetadata;
|
|
13
|
+
exports.injectRequiredCheckoutSessionMetadata = injectRequiredCheckoutSessionMetadata;
|
|
14
|
+
exports.assertCheckoutSessionBelongsToProxy = assertCheckoutSessionBelongsToProxy;
|
|
15
|
+
exports.assertSubscriptionBelongsToProxy = assertSubscriptionBelongsToProxy;
|
|
16
|
+
exports.assertPaymentIntentBelongsToProxy = assertPaymentIntentBelongsToProxy;
|
|
17
|
+
const server_js_1 = require("@proxy-checkout/server-js");
|
|
18
|
+
/** The single metadata key Proxy reads to correlate a Stripe object to a session. */
|
|
19
|
+
exports.PROXY_SESSION_METADATA_KEY = "proxy_session_id";
|
|
20
|
+
/** Build the required Stripe metadata placements for a Proxy session. */
|
|
21
|
+
function requiredMetadata(proxySession) {
|
|
22
|
+
const metadata = { proxy_session_id: proxySession.id };
|
|
23
|
+
return {
|
|
24
|
+
checkoutSession: metadata,
|
|
25
|
+
paymentIntent: metadata,
|
|
26
|
+
paymentIntentData: { metadata },
|
|
27
|
+
subscription: metadata,
|
|
28
|
+
subscriptionData: { metadata },
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Return Stripe Checkout Session create params with required Proxy metadata in
|
|
33
|
+
* every object Proxy may later need to correlate. Conflicting merchant-provided
|
|
34
|
+
* proxy metadata fails before any Stripe side effect.
|
|
35
|
+
*/
|
|
36
|
+
function injectRequiredCheckoutSessionMetadata(params, proxySessionId) {
|
|
37
|
+
const metadata = { proxy_session_id: proxySessionId };
|
|
38
|
+
return {
|
|
39
|
+
...params,
|
|
40
|
+
metadata: mergeProxyMetadata(params.metadata, metadata, "metadata.proxy_session_id"),
|
|
41
|
+
...(params.mode === "subscription" || params.subscription_data !== undefined
|
|
42
|
+
? {
|
|
43
|
+
subscription_data: {
|
|
44
|
+
...objectRecord(params.subscription_data),
|
|
45
|
+
metadata: mergeProxyMetadata(metadataFromNestedParams(params.subscription_data), metadata, "subscription_data.metadata.proxy_session_id"),
|
|
46
|
+
},
|
|
47
|
+
}
|
|
48
|
+
: {}),
|
|
49
|
+
...(params.mode === "payment" || params.payment_intent_data !== undefined
|
|
50
|
+
? {
|
|
51
|
+
payment_intent_data: {
|
|
52
|
+
...objectRecord(params.payment_intent_data),
|
|
53
|
+
metadata: mergeProxyMetadata(metadataFromNestedParams(params.payment_intent_data), metadata, "payment_intent_data.metadata.proxy_session_id"),
|
|
54
|
+
},
|
|
55
|
+
}
|
|
56
|
+
: {}),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/** Assert a Stripe Checkout Session carries the expected `proxy_session_id` metadata. */
|
|
60
|
+
function assertCheckoutSessionBelongsToProxy(checkoutSession, proxySessionId) {
|
|
61
|
+
assertProxyMetadata(checkoutSession.metadata, proxySessionId, "Stripe checkout session");
|
|
62
|
+
}
|
|
63
|
+
/** Assert a Stripe Subscription carries the expected `proxy_session_id` metadata. */
|
|
64
|
+
function assertSubscriptionBelongsToProxy(subscription, proxySessionId) {
|
|
65
|
+
assertProxyMetadata(subscription.metadata, proxySessionId, "Stripe subscription");
|
|
66
|
+
}
|
|
67
|
+
/** Assert a Stripe PaymentIntent carries the expected `proxy_session_id` metadata. */
|
|
68
|
+
function assertPaymentIntentBelongsToProxy(paymentIntent, proxySessionId) {
|
|
69
|
+
assertProxyMetadata(paymentIntent.metadata, proxySessionId, "Stripe payment intent");
|
|
70
|
+
}
|
|
71
|
+
function assertProxyMetadata(metadata, proxySessionId, objectLabel) {
|
|
72
|
+
const value = metadata?.[exports.PROXY_SESSION_METADATA_KEY];
|
|
73
|
+
if (value !== proxySessionId) {
|
|
74
|
+
throw new server_js_1.ProxyCheckoutValidationError(`${objectLabel} metadata.${exports.PROXY_SESSION_METADATA_KEY} (${value ?? "missing"}) does not match Proxy session ${proxySessionId}.`, { code: "provider_binding_mismatch", field: `metadata.${exports.PROXY_SESSION_METADATA_KEY}` });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function mergeProxyMetadata(existing, required, field) {
|
|
78
|
+
const existingValue = existing?.[exports.PROXY_SESSION_METADATA_KEY];
|
|
79
|
+
if (existingValue !== undefined && existingValue !== required.proxy_session_id) {
|
|
80
|
+
throw new server_js_1.ProxyCheckoutValidationError(`Stripe metadata.${exports.PROXY_SESSION_METADATA_KEY} (${existingValue}) conflicts with Proxy session ${required.proxy_session_id}.`, { code: "provider_binding_mismatch", field });
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
...existing,
|
|
84
|
+
...required,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function objectRecord(value) {
|
|
88
|
+
return typeof value === "object" && value !== null ? value : {};
|
|
89
|
+
}
|
|
90
|
+
function metadataFromNestedParams(value) {
|
|
91
|
+
return objectRecord(value).metadata;
|
|
92
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `openCheckout` — the payer-opened + provider-object creation workflow.
|
|
3
|
+
*
|
|
4
|
+
* It performs the Proxy protocol steps (record payer-opened, validate the cart,
|
|
5
|
+
* inject required metadata, create the Stripe Checkout Session, record the
|
|
6
|
+
* provider binding). Merchants provide only Stripe params, so the adapter owns
|
|
7
|
+
* metadata placement, idempotency, and binding reconciliation.
|
|
8
|
+
*/
|
|
9
|
+
import type { JsonObject, PayerOpenedResult, ProxyCartValidator, ProxyCheckoutServerClient, ProxySessionProviderBinding } from "@proxy-checkout/server-js";
|
|
10
|
+
import type { StripeCheckoutSessionCreateParams, StripeCheckoutSessionLike, StripeClientLike, StripeRequestOptionsWithoutIdempotencyLike } from "./types.js";
|
|
11
|
+
export interface OpenCheckoutOptions<TStripe extends StripeClientLike, TCart, TOffer> {
|
|
12
|
+
/** Builds app-specific Stripe Checkout Session params. Proxy metadata is injected by the SDK. */
|
|
13
|
+
readonly buildCheckoutSessionParams: (input: {
|
|
14
|
+
cart: TCart;
|
|
15
|
+
offer: TOffer;
|
|
16
|
+
proxySession: PayerOpenedResult;
|
|
17
|
+
stripe: TStripe;
|
|
18
|
+
}) => Promise<StripeCheckoutSessionCreateParams> | StripeCheckoutSessionCreateParams;
|
|
19
|
+
/** Optional schema validating the session cart snapshot into a typed cart. */
|
|
20
|
+
readonly cartSchema?: ProxyCartValidator<TCart>;
|
|
21
|
+
/** Optional extractor used to assert the cart buyer reference matches the session. */
|
|
22
|
+
readonly getCartBuyerReference?: (cart: TCart) => string | null | undefined;
|
|
23
|
+
/** A Proxy server SDK client. */
|
|
24
|
+
readonly proxy: ProxyCheckoutServerClient;
|
|
25
|
+
readonly proxySessionId: string;
|
|
26
|
+
/** Provider identifier recorded with the binding. Defaults to "stripe". */
|
|
27
|
+
readonly psp?: string;
|
|
28
|
+
/** Optional cart reconciliation before Stripe creation. The SDK performs the versioned Proxy cart write. */
|
|
29
|
+
readonly reconcileCart?: (input: {
|
|
30
|
+
cart: TCart;
|
|
31
|
+
offer: TOffer;
|
|
32
|
+
session: PayerOpenedResult;
|
|
33
|
+
}) => OpenCheckoutReconciledCart<TCart> | Promise<OpenCheckoutReconciledCart<TCart>> | null | undefined;
|
|
34
|
+
readonly requestId?: string;
|
|
35
|
+
/** The merchant's Stripe instance. */
|
|
36
|
+
readonly stripe: TStripe;
|
|
37
|
+
/** Optional Stripe request options. The SDK owns the deterministic idempotency key. */
|
|
38
|
+
readonly stripeRequestOptions?: StripeRequestOptionsWithoutIdempotencyLike;
|
|
39
|
+
/** Optional merchant cart validation that derives an app-specific offer. */
|
|
40
|
+
readonly validateCart?: (input: {
|
|
41
|
+
cart: TCart;
|
|
42
|
+
session: PayerOpenedResult;
|
|
43
|
+
}) => Promise<TOffer> | TOffer;
|
|
44
|
+
}
|
|
45
|
+
export interface OpenCheckoutReconciledCart<TCart> {
|
|
46
|
+
readonly amountMinor: number;
|
|
47
|
+
readonly cart: TCart;
|
|
48
|
+
readonly cartSnapshot: JsonObject;
|
|
49
|
+
readonly currency: string;
|
|
50
|
+
}
|
|
51
|
+
export interface OpenCheckoutResult<TCart, TOffer, TSession> {
|
|
52
|
+
readonly binding: ProxySessionProviderBinding;
|
|
53
|
+
readonly cart: TCart;
|
|
54
|
+
readonly checkoutSession: TSession;
|
|
55
|
+
readonly clientSecret: string | null;
|
|
56
|
+
readonly offer: TOffer;
|
|
57
|
+
readonly proxySession: PayerOpenedResult;
|
|
58
|
+
readonly proxySessionId: string;
|
|
59
|
+
}
|
|
60
|
+
export declare function openCheckout<TStripe extends StripeClientLike, TCart = unknown, TOffer = undefined, TSession extends StripeCheckoutSessionLike = StripeCheckoutSessionLike>(options: OpenCheckoutOptions<TStripe, TCart, TOffer>): Promise<OpenCheckoutResult<TCart, TOffer, TSession>>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `openCheckout` — the payer-opened + provider-object creation workflow.
|
|
3
|
+
*
|
|
4
|
+
* It performs the Proxy protocol steps (record payer-opened, validate the cart,
|
|
5
|
+
* inject required metadata, create the Stripe Checkout Session, record the
|
|
6
|
+
* provider binding). Merchants provide only Stripe params, so the adapter owns
|
|
7
|
+
* metadata placement, idempotency, and binding reconciliation.
|
|
8
|
+
*/
|
|
9
|
+
import type { JsonObject, PayerOpenedResult, ProxyCartValidator, ProxyCheckoutServerClient, ProxySessionProviderBinding } from "@proxy-checkout/server-js";
|
|
10
|
+
import type { StripeCheckoutSessionCreateParams, StripeCheckoutSessionLike, StripeClientLike, StripeRequestOptionsWithoutIdempotencyLike } from "./types.js";
|
|
11
|
+
export interface OpenCheckoutOptions<TStripe extends StripeClientLike, TCart, TOffer> {
|
|
12
|
+
/** Builds app-specific Stripe Checkout Session params. Proxy metadata is injected by the SDK. */
|
|
13
|
+
readonly buildCheckoutSessionParams: (input: {
|
|
14
|
+
cart: TCart;
|
|
15
|
+
offer: TOffer;
|
|
16
|
+
proxySession: PayerOpenedResult;
|
|
17
|
+
stripe: TStripe;
|
|
18
|
+
}) => Promise<StripeCheckoutSessionCreateParams> | StripeCheckoutSessionCreateParams;
|
|
19
|
+
/** Optional schema validating the session cart snapshot into a typed cart. */
|
|
20
|
+
readonly cartSchema?: ProxyCartValidator<TCart>;
|
|
21
|
+
/** Optional extractor used to assert the cart buyer reference matches the session. */
|
|
22
|
+
readonly getCartBuyerReference?: (cart: TCart) => string | null | undefined;
|
|
23
|
+
/** A Proxy server SDK client. */
|
|
24
|
+
readonly proxy: ProxyCheckoutServerClient;
|
|
25
|
+
readonly proxySessionId: string;
|
|
26
|
+
/** Provider identifier recorded with the binding. Defaults to "stripe". */
|
|
27
|
+
readonly psp?: string;
|
|
28
|
+
/** Optional cart reconciliation before Stripe creation. The SDK performs the versioned Proxy cart write. */
|
|
29
|
+
readonly reconcileCart?: (input: {
|
|
30
|
+
cart: TCart;
|
|
31
|
+
offer: TOffer;
|
|
32
|
+
session: PayerOpenedResult;
|
|
33
|
+
}) => OpenCheckoutReconciledCart<TCart> | Promise<OpenCheckoutReconciledCart<TCart>> | null | undefined;
|
|
34
|
+
readonly requestId?: string;
|
|
35
|
+
/** The merchant's Stripe instance. */
|
|
36
|
+
readonly stripe: TStripe;
|
|
37
|
+
/** Optional Stripe request options. The SDK owns the deterministic idempotency key. */
|
|
38
|
+
readonly stripeRequestOptions?: StripeRequestOptionsWithoutIdempotencyLike;
|
|
39
|
+
/** Optional merchant cart validation that derives an app-specific offer. */
|
|
40
|
+
readonly validateCart?: (input: {
|
|
41
|
+
cart: TCart;
|
|
42
|
+
session: PayerOpenedResult;
|
|
43
|
+
}) => Promise<TOffer> | TOffer;
|
|
44
|
+
}
|
|
45
|
+
export interface OpenCheckoutReconciledCart<TCart> {
|
|
46
|
+
readonly amountMinor: number;
|
|
47
|
+
readonly cart: TCart;
|
|
48
|
+
readonly cartSnapshot: JsonObject;
|
|
49
|
+
readonly currency: string;
|
|
50
|
+
}
|
|
51
|
+
export interface OpenCheckoutResult<TCart, TOffer, TSession> {
|
|
52
|
+
readonly binding: ProxySessionProviderBinding;
|
|
53
|
+
readonly cart: TCart;
|
|
54
|
+
readonly checkoutSession: TSession;
|
|
55
|
+
readonly clientSecret: string | null;
|
|
56
|
+
readonly offer: TOffer;
|
|
57
|
+
readonly proxySession: PayerOpenedResult;
|
|
58
|
+
readonly proxySessionId: string;
|
|
59
|
+
}
|
|
60
|
+
export declare function openCheckout<TStripe extends StripeClientLike, TCart = unknown, TOffer = undefined, TSession extends StripeCheckoutSessionLike = StripeCheckoutSessionLike>(options: OpenCheckoutOptions<TStripe, TCart, TOffer>): Promise<OpenCheckoutResult<TCart, TOffer, TSession>>;
|