@siglume/direct-request-payment 0.3.6 → 0.4.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/CHANGELOG.md +43 -0
- package/README.md +93 -0
- package/dist/index.cjs +91 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +55 -1
- package/dist/index.d.ts +55 -1
- package/dist/index.js +91 -2
- package/dist/index.js.map +1 -1
- package/docs/announcement-ja.md +24 -6
- package/docs/api-reference.md +133 -0
- package/docs/merchant-quickstart.md +134 -0
- package/docs/pricing.md +18 -14
- package/docs/security.md +17 -0
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -162,6 +162,42 @@ interface DirectRequestPaymentMerchantSetupInput {
|
|
|
162
162
|
webhook_callback_url?: string;
|
|
163
163
|
billing_mandate_cap_minor?: number;
|
|
164
164
|
max_amount_minor?: number;
|
|
165
|
+
checkout_allowed_origins?: string[];
|
|
166
|
+
}
|
|
167
|
+
interface HostedCheckoutSessionCreateInput {
|
|
168
|
+
merchant: string;
|
|
169
|
+
amount_minor: number;
|
|
170
|
+
currency: DirectRequestPaymentCurrency | string;
|
|
171
|
+
nonce: string;
|
|
172
|
+
success_url: string;
|
|
173
|
+
cancel_url: string;
|
|
174
|
+
metadata?: Record<string, unknown>;
|
|
175
|
+
}
|
|
176
|
+
interface HostedCheckoutSessionCreateResult {
|
|
177
|
+
checkout_url: string;
|
|
178
|
+
session_id: string;
|
|
179
|
+
challenge_hash: string;
|
|
180
|
+
status?: string;
|
|
181
|
+
expires_at?: string | null;
|
|
182
|
+
}
|
|
183
|
+
interface HostedCheckoutSession {
|
|
184
|
+
session_id: string;
|
|
185
|
+
merchant: string;
|
|
186
|
+
currency: string;
|
|
187
|
+
token_symbol: string;
|
|
188
|
+
amount_minor: number;
|
|
189
|
+
status: string;
|
|
190
|
+
challenge_hash: string;
|
|
191
|
+
requirement_id?: string | null;
|
|
192
|
+
success_url: string;
|
|
193
|
+
cancel_url: string;
|
|
194
|
+
expires_at?: string | null;
|
|
195
|
+
authenticated_at?: string | null;
|
|
196
|
+
paid_at?: string | null;
|
|
197
|
+
cancelled_at?: string | null;
|
|
198
|
+
created_at?: string | null;
|
|
199
|
+
metadata_jsonb?: Record<string, unknown>;
|
|
200
|
+
[key: string]: unknown;
|
|
165
201
|
}
|
|
166
202
|
interface DirectRequestPaymentMerchantBillingMandateInput {
|
|
167
203
|
currency?: DirectRequestPaymentCurrency | string;
|
|
@@ -246,6 +282,9 @@ declare class SiglumeApiError extends SiglumeDirectRequestPaymentError {
|
|
|
246
282
|
data?: unknown;
|
|
247
283
|
});
|
|
248
284
|
}
|
|
285
|
+
declare class HostedCheckoutNotAvailableError extends SiglumeApiError {
|
|
286
|
+
constructor(message?: string);
|
|
287
|
+
}
|
|
249
288
|
declare class SiglumeWebhookSignatureError extends SiglumeDirectRequestPaymentError {
|
|
250
289
|
constructor(message: string);
|
|
251
290
|
}
|
|
@@ -281,12 +320,27 @@ declare class DirectRequestPaymentMerchantClient {
|
|
|
281
320
|
private readonly fetch_impl;
|
|
282
321
|
constructor(options?: DirectRequestPaymentClientOptions);
|
|
283
322
|
setupMerchant(input: DirectRequestPaymentMerchantSetupInput): Promise<DirectRequestPaymentMerchantResponse>;
|
|
323
|
+
/**
|
|
324
|
+
* Create a Hosted Checkout session (Stripe-Checkout-equivalent for human web
|
|
325
|
+
* shoppers). Siglume authors the challenge server-side, persists a single-use
|
|
326
|
+
* expiring session, and returns a `checkout_url`. Redirect the shopper there;
|
|
327
|
+
* they log into Siglume, approve, and pay from their own wallet, then return
|
|
328
|
+
* to your `success_url`. Fulfill on the `direct_payment.confirmed` webhook
|
|
329
|
+
* (the source of truth), exactly as with the agent flow.
|
|
330
|
+
*
|
|
331
|
+
* `success_url`/`cancel_url` must be on an origin you registered via
|
|
332
|
+
* `checkout_allowed_origins` (or your `webhook_callback_url` origin).
|
|
333
|
+
*/
|
|
334
|
+
createCheckoutSession(input: HostedCheckoutSessionCreateInput): Promise<HostedCheckoutSessionCreateResult>;
|
|
335
|
+
/** Read a Hosted Checkout session's status (open / authenticated / paid / expired / cancelled / failed). */
|
|
336
|
+
getCheckoutSession(session_id: string): Promise<HostedCheckoutSession>;
|
|
284
337
|
getMerchant(merchant: string): Promise<DirectRequestPaymentMerchantResponse>;
|
|
285
338
|
rotateChallengeSecret(merchant: string): Promise<DirectRequestPaymentMerchantResponse>;
|
|
286
339
|
prepareBillingMandate(merchant: string, input?: DirectRequestPaymentMerchantBillingMandateInput): Promise<DirectRequestPaymentMerchantResponse>;
|
|
287
340
|
createWebhookSubscription(input: DirectRequestPaymentWebhookSubscriptionInput): Promise<DirectRequestPaymentWebhookSubscription>;
|
|
288
341
|
setupCheckout(input: DirectRequestPaymentCheckoutSetupInput): Promise<DirectRequestPaymentCheckoutSetupResult>;
|
|
289
342
|
request<T>(method: string, path: string, json_body?: unknown): Promise<T>;
|
|
343
|
+
private requestHostedCheckout;
|
|
290
344
|
}
|
|
291
345
|
declare function createDirectRequestPaymentChallenge(input: DirectRequestPaymentChallengeInput): Promise<DirectRequestPaymentChallenge>;
|
|
292
346
|
declare function createDirectRequestPaymentChallengeSignature(secret: string, input: {
|
|
@@ -365,4 +419,4 @@ declare const verifyExternal402Challenge: typeof verifyDirectRequestPaymentChall
|
|
|
365
419
|
declare const createExternal402RecurringChallenge: typeof createDirectRequestPaymentRecurringChallenge;
|
|
366
420
|
declare const verifyExternal402RecurringChallenge: typeof verifyDirectRequestPaymentRecurringChallenge;
|
|
367
421
|
|
|
368
|
-
export { DEFAULT_SIGLUME_API_BASE, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, DIRECT_REQUEST_PAYMENT_ALLOWANCE_RECEIPT_KIND, DIRECT_REQUEST_PAYMENT_CHALLENGE_SCHEME, DIRECT_REQUEST_PAYMENT_MODE, DIRECT_REQUEST_PAYMENT_RECEIPT_KIND, DIRECT_REQUEST_PAYMENT_RECURRING_CHALLENGE_SCHEME, DIRECT_REQUEST_PAYMENT_REFERENCE_TYPE, type DirectPaymentRequirement, type DirectPaymentRequirementCreateInput, type DirectPaymentVerifyInput, type DirectRequestPaymentBillingPlan, type DirectRequestPaymentChallenge, type DirectRequestPaymentChallengeInput, type DirectRequestPaymentCheckoutSetupInput, type DirectRequestPaymentCheckoutSetupResult, DirectRequestPaymentClient, type DirectRequestPaymentClientOptions, type DirectRequestPaymentCurrency, type DirectRequestPaymentMerchantAccount, type DirectRequestPaymentMerchantBillingMandateInput, DirectRequestPaymentMerchantClient, type DirectRequestPaymentMerchantResponse, type DirectRequestPaymentMerchantSetupInput, type DirectRequestPaymentRecurringCadence, type DirectRequestPaymentRecurringChallenge, type DirectRequestPaymentRecurringChallengeInput, type DirectRequestPaymentToken, type DirectRequestPaymentWebhookEvent, type DirectRequestPaymentWebhookSubscription, type DirectRequestPaymentWebhookSubscriptionInput, type ParsedDirectRequestPaymentChallenge, SiglumeApiError, SiglumeDirectRequestPaymentError, type SiglumeEnvelopeMeta, SiglumeWebhookPayloadError, SiglumeWebhookSignatureError, type Web3PreparedTransactionExecutePayload, type Web3PreparedTransactionExecuteResult, type Web3TransactionRequest, type WebhookSignatureVerification, buildAllowanceExecutionPayload, buildPaymentExecutionPayload, buildPreparedTransactionExecutionPayload, buildWebhookSignatureHeader, computeWebhookSignature, createDirectRequestPaymentChallenge, createDirectRequestPaymentChallengeSignature, createDirectRequestPaymentRecurringChallenge, createDirectRequestPaymentRecurringChallengeSignature, createExternal402Challenge, createExternal402RecurringChallenge, directRequestPaymentChallengeHash, directRequestPaymentRequestHash, parseDirectRequestPaymentChallenge, parseDirectRequestPaymentWebhookEvent, verifyDirectRequestPaymentChallenge, verifyDirectRequestPaymentRecurringChallenge, verifyDirectRequestPaymentWebhook, verifyExternal402Challenge, verifyExternal402RecurringChallenge, verifyWebhookSignature };
|
|
422
|
+
export { DEFAULT_SIGLUME_API_BASE, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, DIRECT_REQUEST_PAYMENT_ALLOWANCE_RECEIPT_KIND, DIRECT_REQUEST_PAYMENT_CHALLENGE_SCHEME, DIRECT_REQUEST_PAYMENT_MODE, DIRECT_REQUEST_PAYMENT_RECEIPT_KIND, DIRECT_REQUEST_PAYMENT_RECURRING_CHALLENGE_SCHEME, DIRECT_REQUEST_PAYMENT_REFERENCE_TYPE, type DirectPaymentRequirement, type DirectPaymentRequirementCreateInput, type DirectPaymentVerifyInput, type DirectRequestPaymentBillingPlan, type DirectRequestPaymentChallenge, type DirectRequestPaymentChallengeInput, type DirectRequestPaymentCheckoutSetupInput, type DirectRequestPaymentCheckoutSetupResult, DirectRequestPaymentClient, type DirectRequestPaymentClientOptions, type DirectRequestPaymentCurrency, type DirectRequestPaymentMerchantAccount, type DirectRequestPaymentMerchantBillingMandateInput, DirectRequestPaymentMerchantClient, type DirectRequestPaymentMerchantResponse, type DirectRequestPaymentMerchantSetupInput, type DirectRequestPaymentRecurringCadence, type DirectRequestPaymentRecurringChallenge, type DirectRequestPaymentRecurringChallengeInput, type DirectRequestPaymentToken, type DirectRequestPaymentWebhookEvent, type DirectRequestPaymentWebhookSubscription, type DirectRequestPaymentWebhookSubscriptionInput, HostedCheckoutNotAvailableError, type HostedCheckoutSession, type HostedCheckoutSessionCreateInput, type HostedCheckoutSessionCreateResult, type ParsedDirectRequestPaymentChallenge, SiglumeApiError, SiglumeDirectRequestPaymentError, type SiglumeEnvelopeMeta, SiglumeWebhookPayloadError, SiglumeWebhookSignatureError, type Web3PreparedTransactionExecutePayload, type Web3PreparedTransactionExecuteResult, type Web3TransactionRequest, type WebhookSignatureVerification, buildAllowanceExecutionPayload, buildPaymentExecutionPayload, buildPreparedTransactionExecutionPayload, buildWebhookSignatureHeader, computeWebhookSignature, createDirectRequestPaymentChallenge, createDirectRequestPaymentChallengeSignature, createDirectRequestPaymentRecurringChallenge, createDirectRequestPaymentRecurringChallengeSignature, createExternal402Challenge, createExternal402RecurringChallenge, directRequestPaymentChallengeHash, directRequestPaymentRequestHash, parseDirectRequestPaymentChallenge, parseDirectRequestPaymentWebhookEvent, verifyDirectRequestPaymentChallenge, verifyDirectRequestPaymentRecurringChallenge, verifyDirectRequestPaymentWebhook, verifyExternal402Challenge, verifyExternal402RecurringChallenge, verifyWebhookSignature };
|
package/dist/index.d.ts
CHANGED
|
@@ -162,6 +162,42 @@ interface DirectRequestPaymentMerchantSetupInput {
|
|
|
162
162
|
webhook_callback_url?: string;
|
|
163
163
|
billing_mandate_cap_minor?: number;
|
|
164
164
|
max_amount_minor?: number;
|
|
165
|
+
checkout_allowed_origins?: string[];
|
|
166
|
+
}
|
|
167
|
+
interface HostedCheckoutSessionCreateInput {
|
|
168
|
+
merchant: string;
|
|
169
|
+
amount_minor: number;
|
|
170
|
+
currency: DirectRequestPaymentCurrency | string;
|
|
171
|
+
nonce: string;
|
|
172
|
+
success_url: string;
|
|
173
|
+
cancel_url: string;
|
|
174
|
+
metadata?: Record<string, unknown>;
|
|
175
|
+
}
|
|
176
|
+
interface HostedCheckoutSessionCreateResult {
|
|
177
|
+
checkout_url: string;
|
|
178
|
+
session_id: string;
|
|
179
|
+
challenge_hash: string;
|
|
180
|
+
status?: string;
|
|
181
|
+
expires_at?: string | null;
|
|
182
|
+
}
|
|
183
|
+
interface HostedCheckoutSession {
|
|
184
|
+
session_id: string;
|
|
185
|
+
merchant: string;
|
|
186
|
+
currency: string;
|
|
187
|
+
token_symbol: string;
|
|
188
|
+
amount_minor: number;
|
|
189
|
+
status: string;
|
|
190
|
+
challenge_hash: string;
|
|
191
|
+
requirement_id?: string | null;
|
|
192
|
+
success_url: string;
|
|
193
|
+
cancel_url: string;
|
|
194
|
+
expires_at?: string | null;
|
|
195
|
+
authenticated_at?: string | null;
|
|
196
|
+
paid_at?: string | null;
|
|
197
|
+
cancelled_at?: string | null;
|
|
198
|
+
created_at?: string | null;
|
|
199
|
+
metadata_jsonb?: Record<string, unknown>;
|
|
200
|
+
[key: string]: unknown;
|
|
165
201
|
}
|
|
166
202
|
interface DirectRequestPaymentMerchantBillingMandateInput {
|
|
167
203
|
currency?: DirectRequestPaymentCurrency | string;
|
|
@@ -246,6 +282,9 @@ declare class SiglumeApiError extends SiglumeDirectRequestPaymentError {
|
|
|
246
282
|
data?: unknown;
|
|
247
283
|
});
|
|
248
284
|
}
|
|
285
|
+
declare class HostedCheckoutNotAvailableError extends SiglumeApiError {
|
|
286
|
+
constructor(message?: string);
|
|
287
|
+
}
|
|
249
288
|
declare class SiglumeWebhookSignatureError extends SiglumeDirectRequestPaymentError {
|
|
250
289
|
constructor(message: string);
|
|
251
290
|
}
|
|
@@ -281,12 +320,27 @@ declare class DirectRequestPaymentMerchantClient {
|
|
|
281
320
|
private readonly fetch_impl;
|
|
282
321
|
constructor(options?: DirectRequestPaymentClientOptions);
|
|
283
322
|
setupMerchant(input: DirectRequestPaymentMerchantSetupInput): Promise<DirectRequestPaymentMerchantResponse>;
|
|
323
|
+
/**
|
|
324
|
+
* Create a Hosted Checkout session (Stripe-Checkout-equivalent for human web
|
|
325
|
+
* shoppers). Siglume authors the challenge server-side, persists a single-use
|
|
326
|
+
* expiring session, and returns a `checkout_url`. Redirect the shopper there;
|
|
327
|
+
* they log into Siglume, approve, and pay from their own wallet, then return
|
|
328
|
+
* to your `success_url`. Fulfill on the `direct_payment.confirmed` webhook
|
|
329
|
+
* (the source of truth), exactly as with the agent flow.
|
|
330
|
+
*
|
|
331
|
+
* `success_url`/`cancel_url` must be on an origin you registered via
|
|
332
|
+
* `checkout_allowed_origins` (or your `webhook_callback_url` origin).
|
|
333
|
+
*/
|
|
334
|
+
createCheckoutSession(input: HostedCheckoutSessionCreateInput): Promise<HostedCheckoutSessionCreateResult>;
|
|
335
|
+
/** Read a Hosted Checkout session's status (open / authenticated / paid / expired / cancelled / failed). */
|
|
336
|
+
getCheckoutSession(session_id: string): Promise<HostedCheckoutSession>;
|
|
284
337
|
getMerchant(merchant: string): Promise<DirectRequestPaymentMerchantResponse>;
|
|
285
338
|
rotateChallengeSecret(merchant: string): Promise<DirectRequestPaymentMerchantResponse>;
|
|
286
339
|
prepareBillingMandate(merchant: string, input?: DirectRequestPaymentMerchantBillingMandateInput): Promise<DirectRequestPaymentMerchantResponse>;
|
|
287
340
|
createWebhookSubscription(input: DirectRequestPaymentWebhookSubscriptionInput): Promise<DirectRequestPaymentWebhookSubscription>;
|
|
288
341
|
setupCheckout(input: DirectRequestPaymentCheckoutSetupInput): Promise<DirectRequestPaymentCheckoutSetupResult>;
|
|
289
342
|
request<T>(method: string, path: string, json_body?: unknown): Promise<T>;
|
|
343
|
+
private requestHostedCheckout;
|
|
290
344
|
}
|
|
291
345
|
declare function createDirectRequestPaymentChallenge(input: DirectRequestPaymentChallengeInput): Promise<DirectRequestPaymentChallenge>;
|
|
292
346
|
declare function createDirectRequestPaymentChallengeSignature(secret: string, input: {
|
|
@@ -365,4 +419,4 @@ declare const verifyExternal402Challenge: typeof verifyDirectRequestPaymentChall
|
|
|
365
419
|
declare const createExternal402RecurringChallenge: typeof createDirectRequestPaymentRecurringChallenge;
|
|
366
420
|
declare const verifyExternal402RecurringChallenge: typeof verifyDirectRequestPaymentRecurringChallenge;
|
|
367
421
|
|
|
368
|
-
export { DEFAULT_SIGLUME_API_BASE, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, DIRECT_REQUEST_PAYMENT_ALLOWANCE_RECEIPT_KIND, DIRECT_REQUEST_PAYMENT_CHALLENGE_SCHEME, DIRECT_REQUEST_PAYMENT_MODE, DIRECT_REQUEST_PAYMENT_RECEIPT_KIND, DIRECT_REQUEST_PAYMENT_RECURRING_CHALLENGE_SCHEME, DIRECT_REQUEST_PAYMENT_REFERENCE_TYPE, type DirectPaymentRequirement, type DirectPaymentRequirementCreateInput, type DirectPaymentVerifyInput, type DirectRequestPaymentBillingPlan, type DirectRequestPaymentChallenge, type DirectRequestPaymentChallengeInput, type DirectRequestPaymentCheckoutSetupInput, type DirectRequestPaymentCheckoutSetupResult, DirectRequestPaymentClient, type DirectRequestPaymentClientOptions, type DirectRequestPaymentCurrency, type DirectRequestPaymentMerchantAccount, type DirectRequestPaymentMerchantBillingMandateInput, DirectRequestPaymentMerchantClient, type DirectRequestPaymentMerchantResponse, type DirectRequestPaymentMerchantSetupInput, type DirectRequestPaymentRecurringCadence, type DirectRequestPaymentRecurringChallenge, type DirectRequestPaymentRecurringChallengeInput, type DirectRequestPaymentToken, type DirectRequestPaymentWebhookEvent, type DirectRequestPaymentWebhookSubscription, type DirectRequestPaymentWebhookSubscriptionInput, type ParsedDirectRequestPaymentChallenge, SiglumeApiError, SiglumeDirectRequestPaymentError, type SiglumeEnvelopeMeta, SiglumeWebhookPayloadError, SiglumeWebhookSignatureError, type Web3PreparedTransactionExecutePayload, type Web3PreparedTransactionExecuteResult, type Web3TransactionRequest, type WebhookSignatureVerification, buildAllowanceExecutionPayload, buildPaymentExecutionPayload, buildPreparedTransactionExecutionPayload, buildWebhookSignatureHeader, computeWebhookSignature, createDirectRequestPaymentChallenge, createDirectRequestPaymentChallengeSignature, createDirectRequestPaymentRecurringChallenge, createDirectRequestPaymentRecurringChallengeSignature, createExternal402Challenge, createExternal402RecurringChallenge, directRequestPaymentChallengeHash, directRequestPaymentRequestHash, parseDirectRequestPaymentChallenge, parseDirectRequestPaymentWebhookEvent, verifyDirectRequestPaymentChallenge, verifyDirectRequestPaymentRecurringChallenge, verifyDirectRequestPaymentWebhook, verifyExternal402Challenge, verifyExternal402RecurringChallenge, verifyWebhookSignature };
|
|
422
|
+
export { DEFAULT_SIGLUME_API_BASE, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, DIRECT_REQUEST_PAYMENT_ALLOWANCE_RECEIPT_KIND, DIRECT_REQUEST_PAYMENT_CHALLENGE_SCHEME, DIRECT_REQUEST_PAYMENT_MODE, DIRECT_REQUEST_PAYMENT_RECEIPT_KIND, DIRECT_REQUEST_PAYMENT_RECURRING_CHALLENGE_SCHEME, DIRECT_REQUEST_PAYMENT_REFERENCE_TYPE, type DirectPaymentRequirement, type DirectPaymentRequirementCreateInput, type DirectPaymentVerifyInput, type DirectRequestPaymentBillingPlan, type DirectRequestPaymentChallenge, type DirectRequestPaymentChallengeInput, type DirectRequestPaymentCheckoutSetupInput, type DirectRequestPaymentCheckoutSetupResult, DirectRequestPaymentClient, type DirectRequestPaymentClientOptions, type DirectRequestPaymentCurrency, type DirectRequestPaymentMerchantAccount, type DirectRequestPaymentMerchantBillingMandateInput, DirectRequestPaymentMerchantClient, type DirectRequestPaymentMerchantResponse, type DirectRequestPaymentMerchantSetupInput, type DirectRequestPaymentRecurringCadence, type DirectRequestPaymentRecurringChallenge, type DirectRequestPaymentRecurringChallengeInput, type DirectRequestPaymentToken, type DirectRequestPaymentWebhookEvent, type DirectRequestPaymentWebhookSubscription, type DirectRequestPaymentWebhookSubscriptionInput, HostedCheckoutNotAvailableError, type HostedCheckoutSession, type HostedCheckoutSessionCreateInput, type HostedCheckoutSessionCreateResult, type ParsedDirectRequestPaymentChallenge, SiglumeApiError, SiglumeDirectRequestPaymentError, type SiglumeEnvelopeMeta, SiglumeWebhookPayloadError, SiglumeWebhookSignatureError, type Web3PreparedTransactionExecutePayload, type Web3PreparedTransactionExecuteResult, type Web3TransactionRequest, type WebhookSignatureVerification, buildAllowanceExecutionPayload, buildPaymentExecutionPayload, buildPreparedTransactionExecutionPayload, buildWebhookSignatureHeader, computeWebhookSignature, createDirectRequestPaymentChallenge, createDirectRequestPaymentChallengeSignature, createDirectRequestPaymentRecurringChallenge, createDirectRequestPaymentRecurringChallengeSignature, createExternal402Challenge, createExternal402RecurringChallenge, directRequestPaymentChallengeHash, directRequestPaymentRequestHash, parseDirectRequestPaymentChallenge, parseDirectRequestPaymentWebhookEvent, verifyDirectRequestPaymentChallenge, verifyDirectRequestPaymentRecurringChallenge, verifyDirectRequestPaymentWebhook, verifyExternal402Challenge, verifyExternal402RecurringChallenge, verifyWebhookSignature };
|
package/dist/index.js
CHANGED
|
@@ -25,6 +25,12 @@ var SiglumeApiError = class extends SiglumeDirectRequestPaymentError {
|
|
|
25
25
|
this.data = options.data;
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
|
+
var HostedCheckoutNotAvailableError = class extends SiglumeApiError {
|
|
29
|
+
constructor(message = "Hosted Checkout is not enabled for this account yet (server rollout in progress).") {
|
|
30
|
+
super(message, { status: 409, code: "HOSTED_CHECKOUT_NOT_ENABLED" });
|
|
31
|
+
this.name = "HostedCheckoutNotAvailableError";
|
|
32
|
+
}
|
|
33
|
+
};
|
|
28
34
|
var SiglumeWebhookSignatureError = class extends SiglumeDirectRequestPaymentError {
|
|
29
35
|
constructor(message) {
|
|
30
36
|
super(message);
|
|
@@ -57,7 +63,7 @@ var DirectRequestPaymentClient = class {
|
|
|
57
63
|
this.auth_token = authToken;
|
|
58
64
|
this.base_url = (options.base_url ?? envValue("SIGLUME_API_BASE") ?? DEFAULT_SIGLUME_API_BASE).replace(/\/+$/, "");
|
|
59
65
|
this.timeout_ms = Math.max(1, Math.trunc(options.timeout_ms ?? 15e3));
|
|
60
|
-
this.user_agent = options.user_agent ?? "@siglume/direct-request-payment/0.
|
|
66
|
+
this.user_agent = options.user_agent ?? "@siglume/direct-request-payment/0.4.1";
|
|
61
67
|
this.fetch_impl = fetchImpl;
|
|
62
68
|
}
|
|
63
69
|
async createPaymentRequirement(input) {
|
|
@@ -162,7 +168,7 @@ var DirectRequestPaymentMerchantClient = class {
|
|
|
162
168
|
this.auth_token = authToken;
|
|
163
169
|
this.base_url = (options.base_url ?? envValue("SIGLUME_API_BASE") ?? DEFAULT_SIGLUME_API_BASE).replace(/\/+$/, "");
|
|
164
170
|
this.timeout_ms = Math.max(1, Math.trunc(options.timeout_ms ?? 15e3));
|
|
165
|
-
this.user_agent = options.user_agent ?? "@siglume/direct-request-payment/0.
|
|
171
|
+
this.user_agent = options.user_agent ?? "@siglume/direct-request-payment/0.4.1";
|
|
166
172
|
this.fetch_impl = fetchImpl;
|
|
167
173
|
}
|
|
168
174
|
async setupMerchant(input) {
|
|
@@ -186,8 +192,47 @@ var DirectRequestPaymentMerchantClient = class {
|
|
|
186
192
|
if (input.max_amount_minor !== void 0) {
|
|
187
193
|
payload.max_amount_minor = positiveInteger(input.max_amount_minor, "max_amount_minor");
|
|
188
194
|
}
|
|
195
|
+
if (input.checkout_allowed_origins !== void 0) {
|
|
196
|
+
payload.checkout_allowed_origins = normalizeOriginList(input.checkout_allowed_origins);
|
|
197
|
+
}
|
|
189
198
|
return this.request("POST", "/sdrp/direct-payments/merchants", payload);
|
|
190
199
|
}
|
|
200
|
+
/**
|
|
201
|
+
* Create a Hosted Checkout session (Stripe-Checkout-equivalent for human web
|
|
202
|
+
* shoppers). Siglume authors the challenge server-side, persists a single-use
|
|
203
|
+
* expiring session, and returns a `checkout_url`. Redirect the shopper there;
|
|
204
|
+
* they log into Siglume, approve, and pay from their own wallet, then return
|
|
205
|
+
* to your `success_url`. Fulfill on the `direct_payment.confirmed` webhook
|
|
206
|
+
* (the source of truth), exactly as with the agent flow.
|
|
207
|
+
*
|
|
208
|
+
* `success_url`/`cancel_url` must be on an origin you registered via
|
|
209
|
+
* `checkout_allowed_origins` (or your `webhook_callback_url` origin).
|
|
210
|
+
*/
|
|
211
|
+
async createCheckoutSession(input) {
|
|
212
|
+
const payload = {
|
|
213
|
+
merchant: normalizeSelfServiceMerchant(input.merchant),
|
|
214
|
+
amount_minor: positiveInteger(input.amount_minor, "amount_minor"),
|
|
215
|
+
currency: normalizeCurrency(input.currency),
|
|
216
|
+
nonce: normalizeChallengeNonce(input.nonce),
|
|
217
|
+
success_url: requireNonEmpty(input.success_url, "success_url"),
|
|
218
|
+
cancel_url: requireNonEmpty(input.cancel_url, "cancel_url")
|
|
219
|
+
};
|
|
220
|
+
if (input.metadata !== void 0) {
|
|
221
|
+
payload.metadata = cloneJsonObject(input.metadata, "metadata");
|
|
222
|
+
}
|
|
223
|
+
return this.requestHostedCheckout(
|
|
224
|
+
"POST",
|
|
225
|
+
"/sdrp/direct-payments/checkout-sessions",
|
|
226
|
+
payload
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
/** Read a Hosted Checkout session's status (open / authenticated / paid / expired / cancelled / failed). */
|
|
230
|
+
async getCheckoutSession(session_id) {
|
|
231
|
+
return this.requestHostedCheckout(
|
|
232
|
+
"GET",
|
|
233
|
+
`/sdrp/direct-payments/checkout-sessions/${encodeURIComponent(requireNonEmpty(session_id, "session_id"))}`
|
|
234
|
+
);
|
|
235
|
+
}
|
|
191
236
|
async getMerchant(merchant) {
|
|
192
237
|
return this.request(
|
|
193
238
|
"GET",
|
|
@@ -292,6 +337,16 @@ var DirectRequestPaymentMerchantClient = class {
|
|
|
292
337
|
clearTimeout(timeout);
|
|
293
338
|
}
|
|
294
339
|
}
|
|
340
|
+
async requestHostedCheckout(method, path, json_body) {
|
|
341
|
+
try {
|
|
342
|
+
return await this.request(method, path, json_body);
|
|
343
|
+
} catch (error) {
|
|
344
|
+
if (isHostedCheckoutUnavailable(error)) {
|
|
345
|
+
throw new HostedCheckoutNotAvailableError();
|
|
346
|
+
}
|
|
347
|
+
throw error;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
295
350
|
};
|
|
296
351
|
async function createDirectRequestPaymentChallenge(input) {
|
|
297
352
|
const merchant = normalizeMerchant(input.merchant);
|
|
@@ -556,6 +611,29 @@ function normalizeAllowedCurrencies(value) {
|
|
|
556
611
|
function defaultTokenForCurrency(currency) {
|
|
557
612
|
return currency === "JPY" ? "JPYC" : "USDC";
|
|
558
613
|
}
|
|
614
|
+
function normalizeOriginList(value) {
|
|
615
|
+
if (!Array.isArray(value)) {
|
|
616
|
+
throw new SiglumeDirectRequestPaymentError("checkout_allowed_origins must be an array of origin URLs.");
|
|
617
|
+
}
|
|
618
|
+
const seen = /* @__PURE__ */ new Set();
|
|
619
|
+
const origins = [];
|
|
620
|
+
for (const item of value) {
|
|
621
|
+
let url;
|
|
622
|
+
try {
|
|
623
|
+
url = new URL(requireNonEmpty(String(item), "checkout_allowed_origins entry"));
|
|
624
|
+
} catch {
|
|
625
|
+
throw new SiglumeDirectRequestPaymentError(
|
|
626
|
+
"each checkout_allowed_origins entry must be an absolute origin such as https://shop.example.com."
|
|
627
|
+
);
|
|
628
|
+
}
|
|
629
|
+
const origin = `${url.protocol.toLowerCase()}//${url.host.toLowerCase()}`;
|
|
630
|
+
if (!seen.has(origin)) {
|
|
631
|
+
seen.add(origin);
|
|
632
|
+
origins.push(origin);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
return origins;
|
|
636
|
+
}
|
|
559
637
|
function positiveInteger(value, name) {
|
|
560
638
|
const parsed = Number(value);
|
|
561
639
|
if (!Number.isSafeInteger(parsed) || parsed <= 0) {
|
|
@@ -615,6 +693,16 @@ function stringOrNull(value) {
|
|
|
615
693
|
const text = value.trim();
|
|
616
694
|
return text ? text : null;
|
|
617
695
|
}
|
|
696
|
+
function isHostedCheckoutUnavailable(error) {
|
|
697
|
+
if (!(error instanceof SiglumeApiError)) {
|
|
698
|
+
return false;
|
|
699
|
+
}
|
|
700
|
+
const code = error.code.toUpperCase();
|
|
701
|
+
if (error.status === 409 && (code === "HOSTED_CHECKOUT_NOT_ENABLED" || code === "FEATURE_DISABLED")) {
|
|
702
|
+
return true;
|
|
703
|
+
}
|
|
704
|
+
return error.status === 404 && (code === "HTTP_404" || code === "NOT_FOUND" || code === "ROUTE_NOT_FOUND" || code === "FEATURE_DISABLED");
|
|
705
|
+
}
|
|
618
706
|
function isRecord(value) {
|
|
619
707
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
620
708
|
}
|
|
@@ -751,6 +839,7 @@ export {
|
|
|
751
839
|
DIRECT_REQUEST_PAYMENT_REFERENCE_TYPE,
|
|
752
840
|
DirectRequestPaymentClient,
|
|
753
841
|
DirectRequestPaymentMerchantClient,
|
|
842
|
+
HostedCheckoutNotAvailableError,
|
|
754
843
|
SiglumeApiError,
|
|
755
844
|
SiglumeDirectRequestPaymentError,
|
|
756
845
|
SiglumeWebhookPayloadError,
|