@proxy-checkout/server-js 0.0.8 → 0.1.0-prx-124.139.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 +13 -1
- package/dist/cjs/client.d.cts +2 -0
- package/dist/cjs/client.d.ts +2 -0
- package/dist/cjs/client.js +4 -1
- package/dist/cjs/errors.d.cts +1 -1
- package/dist/cjs/errors.d.ts +1 -1
- package/dist/cjs/events.d.cts +10 -2
- package/dist/cjs/events.d.ts +10 -2
- package/dist/cjs/events.js +28 -1
- package/dist/cjs/index.d.cts +4 -3
- package/dist/cjs/index.d.ts +4 -3
- package/dist/cjs/index.js +6 -1
- package/dist/cjs/provider-acquisitions.d.cts +106 -0
- package/dist/cjs/provider-acquisitions.d.ts +106 -0
- package/dist/cjs/provider-acquisitions.js +168 -0
- package/dist/cjs/sessions.d.cts +36 -4
- package/dist/cjs/sessions.d.ts +36 -4
- package/dist/cjs/sessions.js +132 -7
- package/dist/cjs/version.d.cts +2 -2
- package/dist/cjs/version.d.ts +2 -2
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/webhook-events.d.cts +21 -0
- package/dist/cjs/webhook-events.d.ts +21 -0
- package/dist/cjs/webhook-events.js +48 -0
- package/dist/cjs/webhook-handler.d.cts +1 -0
- package/dist/cjs/webhook-handler.d.ts +1 -0
- package/dist/cjs/webhook-handler.js +7 -0
- package/dist/esm/client.d.ts +2 -0
- package/dist/esm/client.js +4 -1
- package/dist/esm/errors.d.ts +1 -1
- package/dist/esm/events.d.ts +10 -2
- package/dist/esm/events.js +29 -2
- package/dist/esm/index.d.ts +4 -3
- package/dist/esm/index.js +2 -1
- package/dist/esm/provider-acquisitions.d.ts +106 -0
- package/dist/esm/provider-acquisitions.js +164 -0
- package/dist/esm/sessions.d.ts +36 -4
- package/dist/esm/sessions.js +132 -7
- package/dist/esm/version.d.ts +2 -2
- package/dist/esm/version.js +1 -1
- package/dist/esm/webhook-events.d.ts +21 -0
- package/dist/esm/webhook-events.js +46 -0
- package/dist/esm/webhook-handler.d.ts +1 -0
- package/dist/esm/webhook-handler.js +7 -0
- package/package.json +1 -1
|
@@ -7,18 +7,35 @@
|
|
|
7
7
|
*/
|
|
8
8
|
export declare const PROXY_WEBHOOK_EVENT_TYPES: {
|
|
9
9
|
readonly paymentAttemptCancelled: "payment_attempt.cancelled";
|
|
10
|
+
readonly paymentAttemptDisputed: "payment_attempt.disputed";
|
|
11
|
+
readonly paymentAttemptDisputeLost: "payment_attempt.dispute_lost";
|
|
12
|
+
readonly paymentAttemptDisputeWon: "payment_attempt.dispute_won";
|
|
10
13
|
readonly paymentAttemptFailed: "payment_attempt.failed";
|
|
14
|
+
readonly paymentAttemptPartiallyRefunded: "payment_attempt.partially_refunded";
|
|
15
|
+
readonly paymentAttemptReconciliationRequired: "payment_attempt.reconciliation_required";
|
|
16
|
+
readonly paymentAttemptRefunded: "payment_attempt.refunded";
|
|
11
17
|
readonly paymentAttemptSucceeded: "payment_attempt.succeeded";
|
|
18
|
+
readonly providerAcquisitionCancelled: "provider_acquisition.cancelled";
|
|
19
|
+
readonly providerAcquisitionExpired: "provider_acquisition.expired";
|
|
20
|
+
readonly providerAcquisitionFailed: "provider_acquisition.failed";
|
|
21
|
+
readonly providerAcquisitionReconciliationRequired: "provider_acquisition.reconciliation_required";
|
|
12
22
|
readonly sessionCancelled: "proxy_session.cancelled";
|
|
13
23
|
readonly sessionExpired: "proxy_session.expired";
|
|
14
24
|
readonly sessionFailed: "proxy_session.failed";
|
|
15
25
|
readonly sessionMerchantActionRequired: "proxy_session.merchant_action_required";
|
|
16
26
|
readonly sessionPaid: "proxy_session.paid";
|
|
17
27
|
readonly sessionProvisionable: "proxy_session.provisionable";
|
|
28
|
+
readonly shopifyFulfillmentObserved: "shopify.fulfillment_observed";
|
|
29
|
+
readonly shopifyRefundObserved: "shopify.refund_observed";
|
|
30
|
+
readonly shopifySubscriptionPaymentObserved: "shopify.subscription_payment_observed";
|
|
31
|
+
readonly shopifySubscriptionRefundObserved: "shopify.subscription_refund_observed";
|
|
18
32
|
readonly subscriptionCancelled: "subscription.cancelled";
|
|
19
33
|
readonly subscriptionCancelScheduled: "subscription.cancel_scheduled";
|
|
34
|
+
readonly subscriptionChanged: "subscription.changed";
|
|
35
|
+
readonly subscriptionConfigurationActionRequired: "subscription.configuration_action_required";
|
|
20
36
|
readonly subscriptionPaymentFailed: "subscription.payment_failed";
|
|
21
37
|
readonly subscriptionRenewed: "subscription.renewed";
|
|
38
|
+
readonly subscriptionTrialEnding: "subscription.trial_ending";
|
|
22
39
|
};
|
|
23
40
|
export type ProxyWebhookEventType = (typeof PROXY_WEBHOOK_EVENT_TYPES)[keyof typeof PROXY_WEBHOOK_EVENT_TYPES];
|
|
24
41
|
/** True for `proxy_session.*` events. */
|
|
@@ -27,3 +44,7 @@ export declare function isProxySessionEvent(eventType: string): boolean;
|
|
|
27
44
|
export declare function isProxySubscriptionEvent(eventType: string): boolean;
|
|
28
45
|
/** True for `payment_attempt.*` events. */
|
|
29
46
|
export declare function isProxyPaymentAttemptEvent(eventType: string): boolean;
|
|
47
|
+
/** True for non-granting `provider_acquisition.*` progress wakeups. */
|
|
48
|
+
export declare function isProxyProviderAcquisitionEvent(eventType: string): boolean;
|
|
49
|
+
/** True for observation-only `shopify.*` commerce events. */
|
|
50
|
+
export declare function isProxyShopifyEvent(eventType: string): boolean;
|
|
@@ -11,20 +11,39 @@ exports.PROXY_WEBHOOK_EVENT_TYPES = void 0;
|
|
|
11
11
|
exports.isProxySessionEvent = isProxySessionEvent;
|
|
12
12
|
exports.isProxySubscriptionEvent = isProxySubscriptionEvent;
|
|
13
13
|
exports.isProxyPaymentAttemptEvent = isProxyPaymentAttemptEvent;
|
|
14
|
+
exports.isProxyProviderAcquisitionEvent = isProxyProviderAcquisitionEvent;
|
|
15
|
+
exports.isProxyShopifyEvent = isProxyShopifyEvent;
|
|
14
16
|
exports.PROXY_WEBHOOK_EVENT_TYPES = {
|
|
15
17
|
paymentAttemptCancelled: "payment_attempt.cancelled",
|
|
18
|
+
paymentAttemptDisputed: "payment_attempt.disputed",
|
|
19
|
+
paymentAttemptDisputeLost: "payment_attempt.dispute_lost",
|
|
20
|
+
paymentAttemptDisputeWon: "payment_attempt.dispute_won",
|
|
16
21
|
paymentAttemptFailed: "payment_attempt.failed",
|
|
22
|
+
paymentAttemptPartiallyRefunded: "payment_attempt.partially_refunded",
|
|
23
|
+
paymentAttemptReconciliationRequired: "payment_attempt.reconciliation_required",
|
|
24
|
+
paymentAttemptRefunded: "payment_attempt.refunded",
|
|
17
25
|
paymentAttemptSucceeded: "payment_attempt.succeeded",
|
|
26
|
+
providerAcquisitionCancelled: "provider_acquisition.cancelled",
|
|
27
|
+
providerAcquisitionExpired: "provider_acquisition.expired",
|
|
28
|
+
providerAcquisitionFailed: "provider_acquisition.failed",
|
|
29
|
+
providerAcquisitionReconciliationRequired: "provider_acquisition.reconciliation_required",
|
|
18
30
|
sessionCancelled: "proxy_session.cancelled",
|
|
19
31
|
sessionExpired: "proxy_session.expired",
|
|
20
32
|
sessionFailed: "proxy_session.failed",
|
|
21
33
|
sessionMerchantActionRequired: "proxy_session.merchant_action_required",
|
|
22
34
|
sessionPaid: "proxy_session.paid",
|
|
23
35
|
sessionProvisionable: "proxy_session.provisionable",
|
|
36
|
+
shopifyFulfillmentObserved: "shopify.fulfillment_observed",
|
|
37
|
+
shopifyRefundObserved: "shopify.refund_observed",
|
|
38
|
+
shopifySubscriptionPaymentObserved: "shopify.subscription_payment_observed",
|
|
39
|
+
shopifySubscriptionRefundObserved: "shopify.subscription_refund_observed",
|
|
24
40
|
subscriptionCancelled: "subscription.cancelled",
|
|
25
41
|
subscriptionCancelScheduled: "subscription.cancel_scheduled",
|
|
42
|
+
subscriptionChanged: "subscription.changed",
|
|
43
|
+
subscriptionConfigurationActionRequired: "subscription.configuration_action_required",
|
|
26
44
|
subscriptionPaymentFailed: "subscription.payment_failed",
|
|
27
45
|
subscriptionRenewed: "subscription.renewed",
|
|
46
|
+
subscriptionTrialEnding: "subscription.trial_ending",
|
|
28
47
|
};
|
|
29
48
|
const SESSION_EVENT_TYPES = new Set([
|
|
30
49
|
exports.PROXY_WEBHOOK_EVENT_TYPES.sessionCancelled,
|
|
@@ -37,14 +56,35 @@ const SESSION_EVENT_TYPES = new Set([
|
|
|
37
56
|
const SUBSCRIPTION_EVENT_TYPES = new Set([
|
|
38
57
|
exports.PROXY_WEBHOOK_EVENT_TYPES.subscriptionCancelScheduled,
|
|
39
58
|
exports.PROXY_WEBHOOK_EVENT_TYPES.subscriptionCancelled,
|
|
59
|
+
exports.PROXY_WEBHOOK_EVENT_TYPES.subscriptionChanged,
|
|
60
|
+
exports.PROXY_WEBHOOK_EVENT_TYPES.subscriptionConfigurationActionRequired,
|
|
40
61
|
exports.PROXY_WEBHOOK_EVENT_TYPES.subscriptionPaymentFailed,
|
|
41
62
|
exports.PROXY_WEBHOOK_EVENT_TYPES.subscriptionRenewed,
|
|
63
|
+
exports.PROXY_WEBHOOK_EVENT_TYPES.subscriptionTrialEnding,
|
|
42
64
|
]);
|
|
43
65
|
const PAYMENT_ATTEMPT_EVENT_TYPES = new Set([
|
|
44
66
|
exports.PROXY_WEBHOOK_EVENT_TYPES.paymentAttemptCancelled,
|
|
67
|
+
exports.PROXY_WEBHOOK_EVENT_TYPES.paymentAttemptDisputeLost,
|
|
68
|
+
exports.PROXY_WEBHOOK_EVENT_TYPES.paymentAttemptDisputeWon,
|
|
69
|
+
exports.PROXY_WEBHOOK_EVENT_TYPES.paymentAttemptDisputed,
|
|
45
70
|
exports.PROXY_WEBHOOK_EVENT_TYPES.paymentAttemptFailed,
|
|
71
|
+
exports.PROXY_WEBHOOK_EVENT_TYPES.paymentAttemptPartiallyRefunded,
|
|
72
|
+
exports.PROXY_WEBHOOK_EVENT_TYPES.paymentAttemptReconciliationRequired,
|
|
73
|
+
exports.PROXY_WEBHOOK_EVENT_TYPES.paymentAttemptRefunded,
|
|
46
74
|
exports.PROXY_WEBHOOK_EVENT_TYPES.paymentAttemptSucceeded,
|
|
47
75
|
]);
|
|
76
|
+
const PROVIDER_ACQUISITION_EVENT_TYPES = new Set([
|
|
77
|
+
exports.PROXY_WEBHOOK_EVENT_TYPES.providerAcquisitionCancelled,
|
|
78
|
+
exports.PROXY_WEBHOOK_EVENT_TYPES.providerAcquisitionExpired,
|
|
79
|
+
exports.PROXY_WEBHOOK_EVENT_TYPES.providerAcquisitionFailed,
|
|
80
|
+
exports.PROXY_WEBHOOK_EVENT_TYPES.providerAcquisitionReconciliationRequired,
|
|
81
|
+
]);
|
|
82
|
+
const SHOPIFY_EVENT_TYPES = new Set([
|
|
83
|
+
exports.PROXY_WEBHOOK_EVENT_TYPES.shopifyFulfillmentObserved,
|
|
84
|
+
exports.PROXY_WEBHOOK_EVENT_TYPES.shopifyRefundObserved,
|
|
85
|
+
exports.PROXY_WEBHOOK_EVENT_TYPES.shopifySubscriptionPaymentObserved,
|
|
86
|
+
exports.PROXY_WEBHOOK_EVENT_TYPES.shopifySubscriptionRefundObserved,
|
|
87
|
+
]);
|
|
48
88
|
/** True for `proxy_session.*` events. */
|
|
49
89
|
function isProxySessionEvent(eventType) {
|
|
50
90
|
return SESSION_EVENT_TYPES.has(eventType);
|
|
@@ -57,3 +97,11 @@ function isProxySubscriptionEvent(eventType) {
|
|
|
57
97
|
function isProxyPaymentAttemptEvent(eventType) {
|
|
58
98
|
return PAYMENT_ATTEMPT_EVENT_TYPES.has(eventType);
|
|
59
99
|
}
|
|
100
|
+
/** True for non-granting `provider_acquisition.*` progress wakeups. */
|
|
101
|
+
function isProxyProviderAcquisitionEvent(eventType) {
|
|
102
|
+
return PROVIDER_ACQUISITION_EVENT_TYPES.has(eventType);
|
|
103
|
+
}
|
|
104
|
+
/** True for observation-only `shopify.*` commerce events. */
|
|
105
|
+
function isProxyShopifyEvent(eventType) {
|
|
106
|
+
return SHOPIFY_EVENT_TYPES.has(eventType);
|
|
107
|
+
}
|
|
@@ -17,6 +17,7 @@ export type ProxyWebhookClaimResult = "claimed" | "duplicate" | "processing";
|
|
|
17
17
|
export type ProxyWebhookOutcome = "duplicate" | "ignored" | "processed" | "processing";
|
|
18
18
|
/** Compact, lifecycle-free audit record handed to a {@link ProxyWebhookStore}. */
|
|
19
19
|
export interface ProxyWebhookProcessRecord {
|
|
20
|
+
readonly acquisitionAttemptId?: string | null;
|
|
20
21
|
readonly kind: ResolvedProxyEventKind;
|
|
21
22
|
readonly paymentAttemptId?: string | null;
|
|
22
23
|
readonly sessionId: string | null;
|
|
@@ -17,6 +17,7 @@ export type ProxyWebhookClaimResult = "claimed" | "duplicate" | "processing";
|
|
|
17
17
|
export type ProxyWebhookOutcome = "duplicate" | "ignored" | "processed" | "processing";
|
|
18
18
|
/** Compact, lifecycle-free audit record handed to a {@link ProxyWebhookStore}. */
|
|
19
19
|
export interface ProxyWebhookProcessRecord {
|
|
20
|
+
readonly acquisitionAttemptId?: string | null;
|
|
20
21
|
readonly kind: ResolvedProxyEventKind;
|
|
21
22
|
readonly paymentAttemptId?: string | null;
|
|
22
23
|
readonly sessionId: string | null;
|
|
@@ -198,6 +198,13 @@ function jsonResponse(status, body) {
|
|
|
198
198
|
}
|
|
199
199
|
function toProcessRecord(resolved) {
|
|
200
200
|
switch (resolved.kind) {
|
|
201
|
+
case "acquisition_progress":
|
|
202
|
+
return {
|
|
203
|
+
acquisitionAttemptId: resolved.acquisition.id,
|
|
204
|
+
kind: resolved.kind,
|
|
205
|
+
sessionId: resolved.session.id,
|
|
206
|
+
subscriptionId: null,
|
|
207
|
+
};
|
|
201
208
|
case "ignored":
|
|
202
209
|
return {
|
|
203
210
|
kind: resolved.kind,
|
package/dist/esm/client.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ProxyEventsResource } from "./events.js";
|
|
2
|
+
import { ProxyProviderAcquisitionsResource } from "./provider-acquisitions.js";
|
|
2
3
|
import { ProxySessionsResource } from "./sessions.js";
|
|
3
4
|
import { ProxySubscriptionsResource } from "./subscriptions.js";
|
|
4
5
|
import type { ProxyCheckoutServerClientOptions } from "./types.js";
|
|
@@ -7,6 +8,7 @@ import { ProxyWebhookEndpointsResource } from "./webhooks.js";
|
|
|
7
8
|
export declare class ProxyCheckoutServerClient {
|
|
8
9
|
readonly apiHost: string;
|
|
9
10
|
readonly sessions: ProxySessionsResource;
|
|
11
|
+
readonly providerAcquisitions: ProxyProviderAcquisitionsResource;
|
|
10
12
|
readonly subscriptions: ProxySubscriptionsResource;
|
|
11
13
|
/** Current-state lifecycle resolver for signed webhook events. */
|
|
12
14
|
readonly events: ProxyEventsResource;
|
package/dist/esm/client.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ProxyEventsResource } from "./events.js";
|
|
2
2
|
import { ProxyCheckoutHttpClient } from "./http-client.js";
|
|
3
|
+
import { ProxyProviderAcquisitionsResource } from "./provider-acquisitions.js";
|
|
3
4
|
import { ProxySessionsResource } from "./sessions.js";
|
|
4
5
|
import { ProxySubscriptionsResource } from "./subscriptions.js";
|
|
5
6
|
import { ProxyWebhooksResource } from "./webhook-handler.js";
|
|
@@ -7,6 +8,7 @@ import { ProxyWebhookEndpointsResource } from "./webhooks.js";
|
|
|
7
8
|
export class ProxyCheckoutServerClient {
|
|
8
9
|
apiHost;
|
|
9
10
|
sessions;
|
|
11
|
+
providerAcquisitions;
|
|
10
12
|
subscriptions;
|
|
11
13
|
/** Current-state lifecycle resolver for signed webhook events. */
|
|
12
14
|
events;
|
|
@@ -25,8 +27,9 @@ export class ProxyCheckoutServerClient {
|
|
|
25
27
|
payHost: options.payHost,
|
|
26
28
|
publishableKey: options.publishableKey,
|
|
27
29
|
});
|
|
30
|
+
this.providerAcquisitions = new ProxyProviderAcquisitionsResource(httpClient);
|
|
28
31
|
this.subscriptions = new ProxySubscriptionsResource(httpClient, this.sessions);
|
|
29
|
-
this.events = new ProxyEventsResource(this.sessions, this.subscriptions);
|
|
32
|
+
this.events = new ProxyEventsResource(this.sessions, this.subscriptions, this.providerAcquisitions);
|
|
30
33
|
this.webhooks = new ProxyWebhooksResource(this.events, this.sessions);
|
|
31
34
|
this.webhookEndpoints = new ProxyWebhookEndpointsResource(httpClient);
|
|
32
35
|
}
|
package/dist/esm/errors.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export interface ProxyCheckoutApiErrorDetails {
|
|
|
4
4
|
readonly responseBody: unknown;
|
|
5
5
|
readonly statusCode: number;
|
|
6
6
|
}
|
|
7
|
-
export type ProxyCheckoutValidationCode = "buyer_reference_mismatch" | "cart_invalid" | "invalid_date" | "provider_binding_mismatch" | "subscription_session_mismatch" | "webhook_sessions_resource_missing";
|
|
7
|
+
export type ProxyCheckoutValidationCode = "buyer_reference_mismatch" | "cart_invalid" | "cart_version_conflict" | "commercial_mode_required" | "invalid_date" | "invalid_session_presentation" | "provider_acquisition_in_progress" | "provider_binding_missing" | "provider_binding_mismatch" | "subscription_session_mismatch" | "unsupported_provider_option" | "webhook_sessions_resource_missing";
|
|
8
8
|
/**
|
|
9
9
|
* Raised when the SDK receives Proxy data it cannot safely normalize, for
|
|
10
10
|
* example an invalid date string, a cart snapshot that fails the merchant
|
package/dist/esm/events.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* lifecycle decision. It never grants from webhook payload fields, and it
|
|
7
7
|
* classifies subscription events from current state rather than event order.
|
|
8
8
|
*/
|
|
9
|
+
import type { ProviderAcquisition, ProxyProviderAcquisitionsResource } from "./provider-acquisitions.js";
|
|
9
10
|
import type { MerchantProxySession, ProxySessionsResource } from "./sessions.js";
|
|
10
11
|
import type { MerchantProxySubscription, ProxySubscriptionsResource } from "./subscriptions.js";
|
|
11
12
|
import type { ProxyCheckoutServerRequestOptions } from "./types.js";
|
|
@@ -66,23 +67,30 @@ export interface ResolvedPaymentAttempt extends ResolvedBase {
|
|
|
66
67
|
readonly sessionId: string | null;
|
|
67
68
|
readonly subscriptionId: string | null;
|
|
68
69
|
}
|
|
70
|
+
export interface ResolvedAcquisitionProgress extends ResolvedBase {
|
|
71
|
+
readonly acquisition: ProviderAcquisition;
|
|
72
|
+
readonly kind: "acquisition_progress";
|
|
73
|
+
readonly session: MerchantProxySession;
|
|
74
|
+
}
|
|
69
75
|
export interface ResolvedIgnored extends ResolvedBase {
|
|
70
76
|
readonly kind: "ignored";
|
|
71
77
|
readonly reason: string;
|
|
72
78
|
readonly sessionId: string | null;
|
|
73
79
|
readonly subscriptionId: string | null;
|
|
74
80
|
}
|
|
75
|
-
export type ResolvedProxyEvent = ResolvedInitialProvision | ResolvedSubscriptionRenewed | ResolvedSubscriptionCancelScheduled | ResolvedSubscriptionCancelled | ResolvedPaymentRisk | ResolvedTerminalSession | ResolvedPaymentAttempt | ResolvedIgnored;
|
|
81
|
+
export type ResolvedProxyEvent = ResolvedInitialProvision | ResolvedSubscriptionRenewed | ResolvedSubscriptionCancelScheduled | ResolvedSubscriptionCancelled | ResolvedPaymentRisk | ResolvedTerminalSession | ResolvedPaymentAttempt | ResolvedAcquisitionProgress | ResolvedIgnored;
|
|
76
82
|
export type ResolvedProxyEventKind = ResolvedProxyEvent["kind"];
|
|
77
83
|
export declare class ProxyEventsResource {
|
|
78
84
|
private readonly sessions;
|
|
79
85
|
private readonly subscriptions;
|
|
80
|
-
|
|
86
|
+
private readonly providerAcquisitions;
|
|
87
|
+
constructor(sessions: ProxySessionsResource, subscriptions: ProxySubscriptionsResource, providerAcquisitions: ProxyProviderAcquisitionsResource);
|
|
81
88
|
/**
|
|
82
89
|
* Resolve a signed webhook event into a current-state lifecycle decision by
|
|
83
90
|
* re-reading the authoritative session/subscription with the secret key.
|
|
84
91
|
*/
|
|
85
92
|
resolveCurrentState(event: ProxyWebhookEvent, options?: ResolveProxyEventOptions): Promise<ResolvedProxyEvent>;
|
|
93
|
+
private resolveProviderAcquisitionEvent;
|
|
86
94
|
private resolveSessionEvent;
|
|
87
95
|
private resolveSubscriptionEvent;
|
|
88
96
|
}
|
package/dist/esm/events.js
CHANGED
|
@@ -8,19 +8,24 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { assertSubscriptionMatchesSession } from "./consistency.js";
|
|
10
10
|
import { isSessionProvisionable, isSessionTerminal, isSubscriptionEnded, isSubscriptionPaymentAtRisk, subscriptionAccessEndsAt, subscriptionWillRenew, } from "./lifecycle.js";
|
|
11
|
-
import { isProxyPaymentAttemptEvent, isProxySessionEvent, isProxySubscriptionEvent, } from "./webhook-events.js";
|
|
11
|
+
import { isProxyPaymentAttemptEvent, isProxyProviderAcquisitionEvent, isProxySessionEvent, isProxySubscriptionEvent, } from "./webhook-events.js";
|
|
12
12
|
export class ProxyEventsResource {
|
|
13
13
|
sessions;
|
|
14
14
|
subscriptions;
|
|
15
|
-
|
|
15
|
+
providerAcquisitions;
|
|
16
|
+
constructor(sessions, subscriptions, providerAcquisitions) {
|
|
16
17
|
this.sessions = sessions;
|
|
17
18
|
this.subscriptions = subscriptions;
|
|
19
|
+
this.providerAcquisitions = providerAcquisitions;
|
|
18
20
|
}
|
|
19
21
|
/**
|
|
20
22
|
* Resolve a signed webhook event into a current-state lifecycle decision by
|
|
21
23
|
* re-reading the authoritative session/subscription with the secret key.
|
|
22
24
|
*/
|
|
23
25
|
async resolveCurrentState(event, options = {}) {
|
|
26
|
+
if (isProxyProviderAcquisitionEvent(event.type)) {
|
|
27
|
+
return this.resolveProviderAcquisitionEvent(event, options);
|
|
28
|
+
}
|
|
24
29
|
if (isProxySubscriptionEvent(event.type)) {
|
|
25
30
|
return this.resolveSubscriptionEvent(event, options);
|
|
26
31
|
}
|
|
@@ -41,6 +46,28 @@ export class ProxyEventsResource {
|
|
|
41
46
|
subscriptionId: readEventString(event.data.subscription_id),
|
|
42
47
|
});
|
|
43
48
|
}
|
|
49
|
+
async resolveProviderAcquisitionEvent(event, options) {
|
|
50
|
+
const sessionId = extractSessionId(event);
|
|
51
|
+
const acquisitionAttemptId = readEventString(event.data.provider_acquisition_attempt_id);
|
|
52
|
+
if (sessionId === null || acquisitionAttemptId === null) {
|
|
53
|
+
return ignored(event, "Provider acquisition event is missing current-state identifiers.", {
|
|
54
|
+
sessionId,
|
|
55
|
+
subscriptionId: null,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
const [session, acquisitions] = await Promise.all([
|
|
59
|
+
this.sessions.retrieve(sessionId, options),
|
|
60
|
+
this.providerAcquisitions.listProviderAcquisitions(sessionId, options),
|
|
61
|
+
]);
|
|
62
|
+
const acquisition = acquisitions.find((candidate) => candidate.id === acquisitionAttemptId);
|
|
63
|
+
if (!acquisition) {
|
|
64
|
+
return ignored(event, `Provider acquisition ${acquisitionAttemptId} is no longer visible for session ${sessionId}.`, { sessionId, subscriptionId: null });
|
|
65
|
+
}
|
|
66
|
+
if (acquisition.proxySessionId !== session.id) {
|
|
67
|
+
throw new Error("Proxy provider acquisition current state disagreed with its session");
|
|
68
|
+
}
|
|
69
|
+
return { acquisition, event, kind: "acquisition_progress", session };
|
|
70
|
+
}
|
|
44
71
|
async resolveSessionEvent(event, options) {
|
|
45
72
|
const sessionId = extractSessionId(event);
|
|
46
73
|
if (sessionId === null) {
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -2,12 +2,13 @@ export { type ProxyCartParseOptions, type ProxyCartValidator, parseProxyCart, }
|
|
|
2
2
|
export { createProxyCheckoutServerClient, ProxyCheckoutServerClient, } from "./client.js";
|
|
3
3
|
export { assertCartBuyerReference, assertSubscriptionMatchesSession, } from "./consistency.js";
|
|
4
4
|
export { isProxySessionNotFoundError, PROXY_SESSION_NOT_FOUND_ERROR_CODE, ProxyCheckoutApiError, type ProxyCheckoutApiErrorDetails, type ProxyCheckoutValidationCode, ProxyCheckoutValidationError, } from "./errors.js";
|
|
5
|
-
export { ProxyEventsResource, type ResolvedIgnored, type ResolvedInitialProvision, type ResolvedPaymentAttempt, type ResolvedPaymentRisk, type ResolvedProxyEvent, type ResolvedProxyEventKind, type ResolvedSubscriptionCancelled, type ResolvedSubscriptionCancelScheduled, type ResolvedSubscriptionRenewed, type ResolvedTerminalSession, type ResolveProxyEventOptions, } from "./events.js";
|
|
5
|
+
export { ProxyEventsResource, type ResolvedAcquisitionProgress, type ResolvedIgnored, type ResolvedInitialProvision, type ResolvedPaymentAttempt, type ResolvedPaymentRisk, type ResolvedProxyEvent, type ResolvedProxyEventKind, type ResolvedSubscriptionCancelled, type ResolvedSubscriptionCancelScheduled, type ResolvedSubscriptionRenewed, type ResolvedTerminalSession, type ResolveProxyEventOptions, } from "./events.js";
|
|
6
6
|
export { AT_RISK_SUBSCRIPTION_STATUSES, ENDED_SUBSCRIPTION_STATUSES, isSessionProvisionable, isSessionTerminal, isSubscriptionEnded, isSubscriptionPaymentAtRisk, PROVISIONABLE_SESSION_STATUSES, parseOptionalProxyDate, requireProxyDate, subscriptionAccessEndsAt, subscriptionWillRenew, TERMINAL_SESSION_STATUSES, } from "./lifecycle.js";
|
|
7
|
-
export { type
|
|
7
|
+
export { type AttachProviderAcquisitionObjectInput, type ProviderAcquisition, type ProviderAcquisitionCheckoutUiMode, type ProviderAcquisitionCommercialMode, type ProviderAcquisitionIntegrationPath, type ProviderAcquisitionObjectType, type ProviderAcquisitionObservedCheckoutUiMode, type ProviderAcquisitionPricingMode, type ProviderAcquisitionReservation, ProxyProviderAcquisitionsResource, proxyCheckoutProviderAcquisitionEndpoints, type ReserveProviderAcquisitionInput, type SupersedeProviderAcquisitionInput, } from "./provider-acquisitions.js";
|
|
8
|
+
export { type CreateProxySessionHandoffInput, type CreateProxySessionInput, type CreateProxySessionOptions, type MarkProxySessionProvisionedInput, type MarkProxySessionProvisioningFailedInput, type MerchantProxySession, type PayerHandoffResult, type PayerOpenedResult, type ProxySession, type ProxySessionAcquisitionSummary, type ProxySessionActionableNextStep, ProxySessionCartResource, type ProxySessionCartResult, type ProxySessionHandoff, type ProxySessionPresentationState, type ProxySessionProviderBinding, type ProxySessionProvisioningAcknowledgement, ProxySessionsResource, type ProxySessionViewStatus, proxyCheckoutServerEndpoints, type RecordProviderBindingInput, type SetProxySessionCartInput, type TypedMerchantProxySession, } from "./sessions.js";
|
|
8
9
|
export { type MerchantProxySubscription, ProxySubscriptionsResource, type ProxySubscriptionWithSession, type ProxySubscriptionWithUntypedSession, proxyCheckoutSubscriptionEndpoints, } from "./subscriptions.js";
|
|
9
10
|
export type { JsonObject, JsonPrimitive, JsonValue, ProxyCheckoutFetch, ProxyCheckoutServerClientOptions, ProxyCheckoutServerRequestOptions, } from "./types.js";
|
|
10
11
|
export { proxyCheckoutServerSdkName, proxyCheckoutServerSdkUserAgent, proxyCheckoutServerSdkVersion, } from "./version.js";
|
|
11
|
-
export { isProxyPaymentAttemptEvent, isProxySessionEvent, isProxySubscriptionEvent, PROXY_WEBHOOK_EVENT_TYPES, type ProxyWebhookEventType, } from "./webhook-events.js";
|
|
12
|
+
export { isProxyPaymentAttemptEvent, isProxyProviderAcquisitionEvent, isProxySessionEvent, isProxyShopifyEvent, isProxySubscriptionEvent, PROXY_WEBHOOK_EVENT_TYPES, type ProxyWebhookEventType, } from "./webhook-events.js";
|
|
12
13
|
export { PROXY_WEBHOOK_RETRY_AFTER_SECONDS, type ProxyWebhookClaimResult, type ProxyWebhookHandlerOptions, type ProxyWebhookOutcome, type ProxyWebhookPayloadInput, type ProxyWebhookProcessRecord, type ProxyWebhookProcessResult, type ProxyWebhookProvisioningFailure, type ProxyWebhookProvisioningSuccess, type ProxyWebhookProvisioningSuccessResult, type ProxyWebhookRequestInput, type ProxyWebhookStore, ProxyWebhooksResource, } from "./webhook-handler.js";
|
|
13
14
|
export { type ConstructProxyWebhookEventInput, type CreateWebhookEndpointInput, constructProxyWebhookEvent, PROXY_SIGNATURE_HEADER, ProxyWebhookEndpointsResource, type ProxyWebhookEvent, ProxyWebhookSignatureVerificationError, proxyCheckoutWebhookEndpointEndpoints, type RotateWebhookEndpointSecretInput, type UpdateWebhookEndpointInput, type VerifyProxyWebhookSignatureInput, verifyProxyWebhookSignature, type WebhookEndpoint, type WebhookEndpointSecretResult, } from "./webhooks.js";
|
package/dist/esm/index.js
CHANGED
|
@@ -4,9 +4,10 @@ export { assertCartBuyerReference, assertSubscriptionMatchesSession, } from "./c
|
|
|
4
4
|
export { isProxySessionNotFoundError, PROXY_SESSION_NOT_FOUND_ERROR_CODE, ProxyCheckoutApiError, ProxyCheckoutValidationError, } from "./errors.js";
|
|
5
5
|
export { ProxyEventsResource, } from "./events.js";
|
|
6
6
|
export { AT_RISK_SUBSCRIPTION_STATUSES, ENDED_SUBSCRIPTION_STATUSES, isSessionProvisionable, isSessionTerminal, isSubscriptionEnded, isSubscriptionPaymentAtRisk, PROVISIONABLE_SESSION_STATUSES, parseOptionalProxyDate, requireProxyDate, subscriptionAccessEndsAt, subscriptionWillRenew, TERMINAL_SESSION_STATUSES, } from "./lifecycle.js";
|
|
7
|
+
export { ProxyProviderAcquisitionsResource, proxyCheckoutProviderAcquisitionEndpoints, } from "./provider-acquisitions.js";
|
|
7
8
|
export { ProxySessionCartResource, ProxySessionsResource, proxyCheckoutServerEndpoints, } from "./sessions.js";
|
|
8
9
|
export { ProxySubscriptionsResource, proxyCheckoutSubscriptionEndpoints, } from "./subscriptions.js";
|
|
9
10
|
export { proxyCheckoutServerSdkName, proxyCheckoutServerSdkUserAgent, proxyCheckoutServerSdkVersion, } from "./version.js";
|
|
10
|
-
export { isProxyPaymentAttemptEvent, isProxySessionEvent, isProxySubscriptionEvent, PROXY_WEBHOOK_EVENT_TYPES, } from "./webhook-events.js";
|
|
11
|
+
export { isProxyPaymentAttemptEvent, isProxyProviderAcquisitionEvent, isProxySessionEvent, isProxyShopifyEvent, isProxySubscriptionEvent, PROXY_WEBHOOK_EVENT_TYPES, } from "./webhook-events.js";
|
|
11
12
|
export { PROXY_WEBHOOK_RETRY_AFTER_SECONDS, ProxyWebhooksResource, } from "./webhook-handler.js";
|
|
12
13
|
export { constructProxyWebhookEvent, PROXY_SIGNATURE_HEADER, ProxyWebhookEndpointsResource, ProxyWebhookSignatureVerificationError, proxyCheckoutWebhookEndpointEndpoints, verifyProxyWebhookSignature, } from "./webhooks.js";
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { ProxyCheckoutHttpClient } from "./http-client.js";
|
|
2
|
+
import type { ProxyCheckoutServerRequestOptions } from "./types.js";
|
|
3
|
+
declare const providerAcquisitionCheckoutUiModes: readonly ["custom", "embedded", "hosted"];
|
|
4
|
+
declare const providerAcquisitionObservedCheckoutUiModes: readonly ["custom", "embedded", "hosted", "unknown"];
|
|
5
|
+
declare const providerAcquisitionCommercialModes: readonly ["one_time", "subscription"];
|
|
6
|
+
declare const providerAcquisitionIntegrationPaths: readonly ["checkout_session", "direct_subscription", "payment_intent"];
|
|
7
|
+
declare const providerAcquisitionObjectTypes: readonly ["checkout_session", "payment_intent", "setup_intent", "subscription"];
|
|
8
|
+
declare const providerAcquisitionPricingModes: readonly ["fixed", "provider_finalized"];
|
|
9
|
+
export type ProviderAcquisitionCheckoutUiMode = (typeof providerAcquisitionCheckoutUiModes)[number];
|
|
10
|
+
export type ProviderAcquisitionObservedCheckoutUiMode = (typeof providerAcquisitionObservedCheckoutUiModes)[number];
|
|
11
|
+
export type ProviderAcquisitionCommercialMode = (typeof providerAcquisitionCommercialModes)[number];
|
|
12
|
+
export type ProviderAcquisitionIntegrationPath = (typeof providerAcquisitionIntegrationPaths)[number];
|
|
13
|
+
export type ProviderAcquisitionObjectType = (typeof providerAcquisitionObjectTypes)[number];
|
|
14
|
+
export type ProviderAcquisitionPricingMode = (typeof providerAcquisitionPricingModes)[number];
|
|
15
|
+
export interface ProviderAcquisition {
|
|
16
|
+
readonly attemptNumber: number;
|
|
17
|
+
readonly checkoutUiMode: ProviderAcquisitionObservedCheckoutUiMode | null;
|
|
18
|
+
readonly commercialMode: ProviderAcquisitionCommercialMode;
|
|
19
|
+
readonly completionRecordedAt: string | null;
|
|
20
|
+
readonly createdAt: string;
|
|
21
|
+
readonly directFeeBasisSource: string | null;
|
|
22
|
+
readonly directMerchandiseCurrency: string | null;
|
|
23
|
+
readonly directMerchandiseSubtotalMinor: number | null;
|
|
24
|
+
readonly id: string;
|
|
25
|
+
readonly integrationPath: ProviderAcquisitionIntegrationPath;
|
|
26
|
+
readonly merchantPspConfigId: string;
|
|
27
|
+
readonly pricingMode: ProviderAcquisitionPricingMode;
|
|
28
|
+
readonly providerCreatedAt: string | null;
|
|
29
|
+
/** Stripe Customer ID retained only as a merchant-authenticated diagnostic. */
|
|
30
|
+
readonly providerCustomerId: string | null;
|
|
31
|
+
readonly providerRetryNotAfter: string;
|
|
32
|
+
readonly providerRootObjectId: string | null;
|
|
33
|
+
readonly providerRootObjectType: ProviderAcquisitionObjectType | null;
|
|
34
|
+
readonly providerSetupIntentId: string | null;
|
|
35
|
+
readonly proxySessionId: string;
|
|
36
|
+
readonly psp: "stripe";
|
|
37
|
+
readonly status: string;
|
|
38
|
+
readonly statusReason: string | null;
|
|
39
|
+
readonly supersedesAttemptId: string | null;
|
|
40
|
+
readonly updatedAt: string;
|
|
41
|
+
readonly version: number;
|
|
42
|
+
}
|
|
43
|
+
export interface ProviderAcquisitionReservation {
|
|
44
|
+
readonly acquisitionAttempt: ProviderAcquisition;
|
|
45
|
+
readonly stripe: {
|
|
46
|
+
readonly idempotencyKeys: {
|
|
47
|
+
readonly root: string;
|
|
48
|
+
readonly setupIntent?: string;
|
|
49
|
+
};
|
|
50
|
+
readonly metadata: {
|
|
51
|
+
readonly proxyAcquisitionAttemptId: string;
|
|
52
|
+
readonly proxyContractVersion: "2";
|
|
53
|
+
readonly proxySessionId: string;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export interface ReserveProviderAcquisitionInput extends ProxyCheckoutServerRequestOptions {
|
|
58
|
+
readonly checkoutUiMode?: ProviderAcquisitionCheckoutUiMode;
|
|
59
|
+
readonly commercialMode: ProviderAcquisitionCommercialMode;
|
|
60
|
+
readonly integrationPath: ProviderAcquisitionIntegrationPath;
|
|
61
|
+
/** Optional server-only direct PaymentIntent percentage basis; omit to use verified provider gross. */
|
|
62
|
+
readonly merchandiseSubtotalMinor?: number;
|
|
63
|
+
readonly pricingMode: ProviderAcquisitionPricingMode;
|
|
64
|
+
readonly providerOptionsFingerprint: string;
|
|
65
|
+
}
|
|
66
|
+
export interface AttachProviderAcquisitionObjectInput extends ProxyCheckoutServerRequestOptions {
|
|
67
|
+
readonly expectedVersion: number;
|
|
68
|
+
readonly objectId: string;
|
|
69
|
+
readonly objectType: ProviderAcquisitionObjectType;
|
|
70
|
+
readonly role: "root" | "setup_intent";
|
|
71
|
+
}
|
|
72
|
+
export interface SupersedeProviderAcquisitionInput extends ProxyCheckoutServerRequestOptions {
|
|
73
|
+
readonly expectedVersion: number;
|
|
74
|
+
readonly reason: string;
|
|
75
|
+
readonly replacement: {
|
|
76
|
+
readonly checkoutUiMode?: ProviderAcquisitionCheckoutUiMode;
|
|
77
|
+
readonly integrationPath: ProviderAcquisitionIntegrationPath;
|
|
78
|
+
readonly providerOptionsFingerprint: string;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export declare const proxyCheckoutProviderAcquisitionEndpoints: readonly [{
|
|
82
|
+
readonly method: "POST";
|
|
83
|
+
readonly operation: "providerAcquisitions.reserveProviderAcquisition";
|
|
84
|
+
readonly path: "/proxy_sessions/:proxy_session_id/acquisition_attempts";
|
|
85
|
+
}, {
|
|
86
|
+
readonly method: "POST";
|
|
87
|
+
readonly operation: "providerAcquisitions.attachProviderAcquisitionObject";
|
|
88
|
+
readonly path: "/proxy_sessions/:proxy_session_id/acquisition_attempts/:acquisition_attempt_id/provider_objects";
|
|
89
|
+
}, {
|
|
90
|
+
readonly method: "POST";
|
|
91
|
+
readonly operation: "providerAcquisitions.supersedeProviderAcquisition";
|
|
92
|
+
readonly path: "/proxy_sessions/:proxy_session_id/acquisition_attempts/:acquisition_attempt_id/supersede";
|
|
93
|
+
}, {
|
|
94
|
+
readonly method: "GET";
|
|
95
|
+
readonly operation: "providerAcquisitions.listProviderAcquisitions";
|
|
96
|
+
readonly path: "/proxy_sessions/:proxy_session_id/acquisition_attempts";
|
|
97
|
+
}];
|
|
98
|
+
export declare class ProxyProviderAcquisitionsResource {
|
|
99
|
+
private readonly httpClient;
|
|
100
|
+
constructor(httpClient: ProxyCheckoutHttpClient);
|
|
101
|
+
reserveProviderAcquisition(proxySessionId: string, input: ReserveProviderAcquisitionInput): Promise<ProviderAcquisitionReservation>;
|
|
102
|
+
attachProviderAcquisitionObject(proxySessionId: string, acquisitionAttemptId: string, input: AttachProviderAcquisitionObjectInput): Promise<ProviderAcquisition>;
|
|
103
|
+
supersedeProviderAcquisition(proxySessionId: string, acquisitionAttemptId: string, input: SupersedeProviderAcquisitionInput): Promise<ProviderAcquisitionReservation>;
|
|
104
|
+
listProviderAcquisitions(proxySessionId: string, options?: ProxyCheckoutServerRequestOptions): Promise<ProviderAcquisition[]>;
|
|
105
|
+
}
|
|
106
|
+
export {};
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { requireInteger, requireJsonObject, requireNullableInteger, requireNullableString, requireString, } from "./response-validators.js";
|
|
2
|
+
const providerAcquisitionCheckoutUiModes = ["custom", "embedded", "hosted"];
|
|
3
|
+
const providerAcquisitionObservedCheckoutUiModes = [
|
|
4
|
+
...providerAcquisitionCheckoutUiModes,
|
|
5
|
+
"unknown",
|
|
6
|
+
];
|
|
7
|
+
const providerAcquisitionCommercialModes = ["one_time", "subscription"];
|
|
8
|
+
const providerAcquisitionIntegrationPaths = [
|
|
9
|
+
"checkout_session",
|
|
10
|
+
"direct_subscription",
|
|
11
|
+
"payment_intent",
|
|
12
|
+
];
|
|
13
|
+
const providerAcquisitionObjectTypes = [
|
|
14
|
+
"checkout_session",
|
|
15
|
+
"payment_intent",
|
|
16
|
+
"setup_intent",
|
|
17
|
+
"subscription",
|
|
18
|
+
];
|
|
19
|
+
const providerAcquisitionPricingModes = ["fixed", "provider_finalized"];
|
|
20
|
+
const providerAcquisitionPsps = ["stripe"];
|
|
21
|
+
export const proxyCheckoutProviderAcquisitionEndpoints = [
|
|
22
|
+
{
|
|
23
|
+
method: "POST",
|
|
24
|
+
operation: "providerAcquisitions.reserveProviderAcquisition",
|
|
25
|
+
path: "/proxy_sessions/:proxy_session_id/acquisition_attempts",
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
method: "POST",
|
|
29
|
+
operation: "providerAcquisitions.attachProviderAcquisitionObject",
|
|
30
|
+
path: "/proxy_sessions/:proxy_session_id/acquisition_attempts/:acquisition_attempt_id/provider_objects",
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
method: "POST",
|
|
34
|
+
operation: "providerAcquisitions.supersedeProviderAcquisition",
|
|
35
|
+
path: "/proxy_sessions/:proxy_session_id/acquisition_attempts/:acquisition_attempt_id/supersede",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
method: "GET",
|
|
39
|
+
operation: "providerAcquisitions.listProviderAcquisitions",
|
|
40
|
+
path: "/proxy_sessions/:proxy_session_id/acquisition_attempts",
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
export class ProxyProviderAcquisitionsResource {
|
|
44
|
+
httpClient;
|
|
45
|
+
constructor(httpClient) {
|
|
46
|
+
this.httpClient = httpClient;
|
|
47
|
+
}
|
|
48
|
+
async reserveProviderAcquisition(proxySessionId, input) {
|
|
49
|
+
const response = await this.httpClient.request("POST", `/proxy_sessions/${encodeURIComponent(proxySessionId)}/acquisition_attempts`, {
|
|
50
|
+
...(input.checkoutUiMode === undefined ? {} : { checkout_ui_mode: input.checkoutUiMode }),
|
|
51
|
+
commercial_mode: input.commercialMode,
|
|
52
|
+
integration_path: input.integrationPath,
|
|
53
|
+
...(input.merchandiseSubtotalMinor === undefined
|
|
54
|
+
? {}
|
|
55
|
+
: { merchandise_subtotal_minor: input.merchandiseSubtotalMinor }),
|
|
56
|
+
pricing_mode: input.pricingMode,
|
|
57
|
+
provider_options_fingerprint: input.providerOptionsFingerprint,
|
|
58
|
+
}, { requestId: input.requestId });
|
|
59
|
+
return parseReservation(response, "providerAcquisitions.reserveProviderAcquisition");
|
|
60
|
+
}
|
|
61
|
+
async attachProviderAcquisitionObject(proxySessionId, acquisitionAttemptId, input) {
|
|
62
|
+
const response = await this.httpClient.request("POST", `/proxy_sessions/${encodeURIComponent(proxySessionId)}/acquisition_attempts/${encodeURIComponent(acquisitionAttemptId)}/provider_objects`, {
|
|
63
|
+
expected_version: input.expectedVersion,
|
|
64
|
+
object_id: input.objectId,
|
|
65
|
+
object_type: input.objectType,
|
|
66
|
+
role: input.role,
|
|
67
|
+
}, { requestId: input.requestId });
|
|
68
|
+
return parseAcquisition(response, "providerAcquisitions.attachProviderAcquisitionObject");
|
|
69
|
+
}
|
|
70
|
+
async supersedeProviderAcquisition(proxySessionId, acquisitionAttemptId, input) {
|
|
71
|
+
const response = await this.httpClient.request("POST", `/proxy_sessions/${encodeURIComponent(proxySessionId)}/acquisition_attempts/${encodeURIComponent(acquisitionAttemptId)}/supersede`, {
|
|
72
|
+
expected_version: input.expectedVersion,
|
|
73
|
+
reason: input.reason,
|
|
74
|
+
replacement: {
|
|
75
|
+
...(input.replacement.checkoutUiMode === undefined
|
|
76
|
+
? {}
|
|
77
|
+
: { checkout_ui_mode: input.replacement.checkoutUiMode }),
|
|
78
|
+
integration_path: input.replacement.integrationPath,
|
|
79
|
+
provider_options_fingerprint: input.replacement.providerOptionsFingerprint,
|
|
80
|
+
},
|
|
81
|
+
}, { requestId: input.requestId });
|
|
82
|
+
return parseReservation(response, "providerAcquisitions.supersedeProviderAcquisition");
|
|
83
|
+
}
|
|
84
|
+
async listProviderAcquisitions(proxySessionId, options = {}) {
|
|
85
|
+
const response = await this.httpClient.request("GET", `/proxy_sessions/${encodeURIComponent(proxySessionId)}/acquisition_attempts`, undefined, options);
|
|
86
|
+
const body = requireJsonObject(response, "providerAcquisitions.listProviderAcquisitions");
|
|
87
|
+
if (!Array.isArray(body.data)) {
|
|
88
|
+
throw new Error("Proxy API response field providerAcquisitions.listProviderAcquisitions.data must be an array.");
|
|
89
|
+
}
|
|
90
|
+
return body.data.map((value, index) => parseAcquisition(value, `providerAcquisitions.listProviderAcquisitions.data[${index}]`));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function parseReservation(value, operation) {
|
|
94
|
+
const body = requireJsonObject(value, operation);
|
|
95
|
+
const stripe = requireJsonObject(body.stripe, `${operation}.stripe`);
|
|
96
|
+
const idempotencyKeys = requireJsonObject(stripe.idempotency_keys, `${operation}.stripe.idempotencyKeys`);
|
|
97
|
+
const metadata = requireJsonObject(stripe.metadata, `${operation}.stripe.metadata`);
|
|
98
|
+
const contractVersion = requireString(metadata.proxy_contract_version, `${operation}.stripe.metadata.proxyContractVersion`);
|
|
99
|
+
if (contractVersion !== "2") {
|
|
100
|
+
throw new Error(`Proxy API response field ${operation}.stripe.metadata.proxyContractVersion is unsupported.`);
|
|
101
|
+
}
|
|
102
|
+
const setupIntent = idempotencyKeys.setup_intent;
|
|
103
|
+
return {
|
|
104
|
+
acquisitionAttempt: parseAcquisition(body.acquisition_attempt, `${operation}.acquisitionAttempt`),
|
|
105
|
+
stripe: {
|
|
106
|
+
idempotencyKeys: {
|
|
107
|
+
root: requireString(idempotencyKeys.root, `${operation}.stripe.idempotencyKeys.root`),
|
|
108
|
+
...(setupIntent === undefined
|
|
109
|
+
? {}
|
|
110
|
+
: {
|
|
111
|
+
setupIntent: requireString(setupIntent, `${operation}.stripe.idempotencyKeys.setupIntent`),
|
|
112
|
+
}),
|
|
113
|
+
},
|
|
114
|
+
metadata: {
|
|
115
|
+
proxyAcquisitionAttemptId: requireString(metadata.proxy_acquisition_attempt_id, `${operation}.stripe.metadata.proxyAcquisitionAttemptId`),
|
|
116
|
+
proxyContractVersion: contractVersion,
|
|
117
|
+
proxySessionId: requireString(metadata.proxy_session_id, `${operation}.stripe.metadata.proxySessionId`),
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function parseAcquisition(value, operation) {
|
|
123
|
+
const body = requireJsonObject(value, operation);
|
|
124
|
+
return {
|
|
125
|
+
attemptNumber: requireInteger(body.attempt_number, `${operation}.attemptNumber`),
|
|
126
|
+
checkoutUiMode: requireNullableEnum(body.checkout_ui_mode, `${operation}.checkoutUiMode`, providerAcquisitionObservedCheckoutUiModes),
|
|
127
|
+
commercialMode: requireEnum(body.commercial_mode, `${operation}.commercialMode`, providerAcquisitionCommercialModes),
|
|
128
|
+
completionRecordedAt: requireNullableString(body.completion_recorded_at, `${operation}.completionRecordedAt`),
|
|
129
|
+
createdAt: requireString(body.created_at, `${operation}.createdAt`),
|
|
130
|
+
directFeeBasisSource: requireNullableString(body.direct_fee_basis_source, `${operation}.directFeeBasisSource`),
|
|
131
|
+
directMerchandiseCurrency: requireNullableString(body.direct_merchandise_currency, `${operation}.directMerchandiseCurrency`),
|
|
132
|
+
directMerchandiseSubtotalMinor: requireNullableInteger(body.direct_merchandise_subtotal_minor, `${operation}.directMerchandiseSubtotalMinor`),
|
|
133
|
+
id: requireString(body.id, `${operation}.id`),
|
|
134
|
+
integrationPath: requireEnum(body.integration_path, `${operation}.integrationPath`, providerAcquisitionIntegrationPaths),
|
|
135
|
+
merchantPspConfigId: requireString(body.merchant_psp_config_id, `${operation}.merchantPspConfigId`),
|
|
136
|
+
pricingMode: requireEnum(body.pricing_mode, `${operation}.pricingMode`, providerAcquisitionPricingModes),
|
|
137
|
+
providerCreatedAt: requireNullableString(body.provider_created_at, `${operation}.providerCreatedAt`),
|
|
138
|
+
providerCustomerId: requireNullableString(body.provider_customer_id, `${operation}.providerCustomerId`),
|
|
139
|
+
providerRetryNotAfter: requireString(body.provider_retry_not_after, `${operation}.providerRetryNotAfter`),
|
|
140
|
+
providerRootObjectId: requireNullableString(body.provider_root_object_id, `${operation}.providerRootObjectId`),
|
|
141
|
+
providerRootObjectType: requireNullableEnum(body.provider_root_object_type, `${operation}.providerRootObjectType`, providerAcquisitionObjectTypes),
|
|
142
|
+
providerSetupIntentId: requireNullableString(body.provider_setup_intent_id, `${operation}.providerSetupIntentId`),
|
|
143
|
+
proxySessionId: requireString(body.proxy_session_id, `${operation}.proxySessionId`),
|
|
144
|
+
psp: requireEnum(body.psp, `${operation}.psp`, providerAcquisitionPsps),
|
|
145
|
+
status: requireString(body.status, `${operation}.status`),
|
|
146
|
+
statusReason: requireNullableString(body.status_reason, `${operation}.statusReason`),
|
|
147
|
+
supersedesAttemptId: requireNullableString(body.supersedes_attempt_id, `${operation}.supersedesAttemptId`),
|
|
148
|
+
updatedAt: requireString(body.updated_at, `${operation}.updatedAt`),
|
|
149
|
+
version: requireInteger(body.version, `${operation}.version`),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
function requireEnum(value, field, values) {
|
|
153
|
+
const parsed = requireString(value, field);
|
|
154
|
+
if (!isEnumValue(parsed, values)) {
|
|
155
|
+
throw new Error(`Proxy API response field ${field} must be one of: ${values.join(", ")}.`);
|
|
156
|
+
}
|
|
157
|
+
return parsed;
|
|
158
|
+
}
|
|
159
|
+
function requireNullableEnum(value, field, values) {
|
|
160
|
+
return value === null ? null : requireEnum(value, field, values);
|
|
161
|
+
}
|
|
162
|
+
function isEnumValue(value, values) {
|
|
163
|
+
return values.some((candidate) => candidate === value);
|
|
164
|
+
}
|