@siglume/direct-request-payment 0.4.3 → 0.4.5
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 +36 -0
- package/README.md +33 -10
- package/dist/index.cjs +124 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +146 -1
- package/dist/index.d.ts +146 -1
- package/dist/index.js +124 -7
- package/dist/index.js.map +1 -1
- package/docs/announcement-ja.md +8 -8
- package/docs/api-reference.md +113 -34
- package/docs/merchant-quickstart.md +20 -18
- package/docs/metered-statements.md +117 -29
- package/docs/pricing.md +66 -20
- package/docs/security.md +26 -10
- package/examples/express-checkout.ts +12 -30
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -6,8 +6,128 @@ declare const DIRECT_REQUEST_PAYMENT_RECEIPT_KIND = "sdrp_direct_payment";
|
|
|
6
6
|
declare const DIRECT_REQUEST_PAYMENT_ALLOWANCE_RECEIPT_KIND = "sdrp_direct_payment_allowance";
|
|
7
7
|
declare const DIRECT_REQUEST_PAYMENT_REFERENCE_TYPE = "sdrp_direct_payment_requirement";
|
|
8
8
|
declare const DEFAULT_WEBHOOK_TOLERANCE_SECONDS = 300;
|
|
9
|
+
declare const DIRECT_REQUEST_PAYMENT_SDK_VERSION = "0.4.5";
|
|
9
10
|
type DirectRequestPaymentCurrency = "JPY" | "USD";
|
|
10
11
|
type DirectRequestPaymentToken = "JPYC" | "USDC";
|
|
12
|
+
type DirectRequestPaymentMeteredPlanType = "micro" | "nano";
|
|
13
|
+
type DirectRequestPaymentMinorAmount = string;
|
|
14
|
+
interface DirectRequestPaymentBuyerMeteredQuery {
|
|
15
|
+
plan_type?: DirectRequestPaymentMeteredPlanType | string;
|
|
16
|
+
token_symbol?: DirectRequestPaymentToken | string;
|
|
17
|
+
}
|
|
18
|
+
interface DirectRequestPaymentMeteredListQuery extends DirectRequestPaymentBuyerMeteredQuery {
|
|
19
|
+
status?: string;
|
|
20
|
+
cursor?: string;
|
|
21
|
+
limit?: number;
|
|
22
|
+
}
|
|
23
|
+
interface DirectRequestPaymentProviderMeteredQuery extends DirectRequestPaymentBuyerMeteredQuery {
|
|
24
|
+
listing_id?: string;
|
|
25
|
+
capability_key?: string;
|
|
26
|
+
}
|
|
27
|
+
interface DirectRequestPaymentProviderMeteredListQuery extends DirectRequestPaymentProviderMeteredQuery {
|
|
28
|
+
status?: string;
|
|
29
|
+
cursor?: string;
|
|
30
|
+
limit?: number;
|
|
31
|
+
}
|
|
32
|
+
interface DirectRequestPaymentListResponse<T> {
|
|
33
|
+
items: T[];
|
|
34
|
+
next_cursor?: string | null;
|
|
35
|
+
[key: string]: unknown;
|
|
36
|
+
}
|
|
37
|
+
interface DirectRequestPaymentBuyerUsageEvent {
|
|
38
|
+
metered_usage_id: string;
|
|
39
|
+
created_at?: string | null;
|
|
40
|
+
plan_type: string;
|
|
41
|
+
settlement_cadence: string;
|
|
42
|
+
product_listing_id?: string | null;
|
|
43
|
+
listing_id?: string | null;
|
|
44
|
+
capability_key?: string | null;
|
|
45
|
+
operation_key?: string | null;
|
|
46
|
+
currency: string;
|
|
47
|
+
token_symbol: string;
|
|
48
|
+
provider_usage_amount_minor: DirectRequestPaymentMinorAmount;
|
|
49
|
+
protocol_fee_minor: DirectRequestPaymentMinorAmount;
|
|
50
|
+
gross_buyer_debit_minor: DirectRequestPaymentMinorAmount;
|
|
51
|
+
status: string;
|
|
52
|
+
period_start?: string | null;
|
|
53
|
+
period_end?: string | null;
|
|
54
|
+
settlement_batch_id?: string | null;
|
|
55
|
+
expected_scheduled_debit_at?: string | null;
|
|
56
|
+
[key: string]: unknown;
|
|
57
|
+
}
|
|
58
|
+
interface DirectRequestPaymentProviderUsageEvent {
|
|
59
|
+
metered_usage_id: string;
|
|
60
|
+
created_at?: string | null;
|
|
61
|
+
plan_type: string;
|
|
62
|
+
settlement_cadence: string;
|
|
63
|
+
product_listing_id?: string | null;
|
|
64
|
+
listing_id?: string | null;
|
|
65
|
+
capability_key?: string | null;
|
|
66
|
+
operation_key?: string | null;
|
|
67
|
+
currency: string;
|
|
68
|
+
token_symbol: string;
|
|
69
|
+
provider_receivable_minor: DirectRequestPaymentMinorAmount;
|
|
70
|
+
protocol_fee_minor: DirectRequestPaymentMinorAmount;
|
|
71
|
+
gross_buyer_debit_minor: DirectRequestPaymentMinorAmount;
|
|
72
|
+
status: string;
|
|
73
|
+
period_start?: string | null;
|
|
74
|
+
period_end?: string | null;
|
|
75
|
+
expected_scheduled_debit_at?: string | null;
|
|
76
|
+
settlement_batch_id?: string | null;
|
|
77
|
+
buyer_period_ref?: string | null;
|
|
78
|
+
[key: string]: unknown;
|
|
79
|
+
}
|
|
80
|
+
interface DirectRequestPaymentSettlementBatch {
|
|
81
|
+
settlement_batch_id: string;
|
|
82
|
+
plan_type: string;
|
|
83
|
+
settlement_cadence: string;
|
|
84
|
+
status: string;
|
|
85
|
+
notice_status?: string | null;
|
|
86
|
+
period_start?: string | null;
|
|
87
|
+
period_end?: string | null;
|
|
88
|
+
close_at?: string | null;
|
|
89
|
+
expected_scheduled_debit_at?: string | null;
|
|
90
|
+
scheduled_debit_at?: string | null;
|
|
91
|
+
not_before_attempt_at?: string | null;
|
|
92
|
+
execution_status?: string | null;
|
|
93
|
+
latest_execution_attempt_status?: string | null;
|
|
94
|
+
attempt_count?: number | null;
|
|
95
|
+
next_attempt_at?: string | null;
|
|
96
|
+
chain_receipt_id?: string | null;
|
|
97
|
+
usage_event_digest?: string | null;
|
|
98
|
+
protocol_fee_minor?: DirectRequestPaymentMinorAmount;
|
|
99
|
+
gross_buyer_debit_minor?: DirectRequestPaymentMinorAmount;
|
|
100
|
+
rounding_delta_minor?: DirectRequestPaymentMinorAmount;
|
|
101
|
+
buyer_debit_minor?: DirectRequestPaymentMinorAmount;
|
|
102
|
+
provider_usage_amount_minor?: DirectRequestPaymentMinorAmount;
|
|
103
|
+
provider_receivable_minor?: DirectRequestPaymentMinorAmount;
|
|
104
|
+
settled_provider_receivable_minor?: DirectRequestPaymentMinorAmount;
|
|
105
|
+
unsettled_provider_receivable_minor?: DirectRequestPaymentMinorAmount;
|
|
106
|
+
past_due_provider_receivable_minor?: DirectRequestPaymentMinorAmount;
|
|
107
|
+
buyer_period_ref?: string | null;
|
|
108
|
+
failure_reason_code?: string | null;
|
|
109
|
+
failure_reason_label?: string | null;
|
|
110
|
+
failure_reason_help?: string | null;
|
|
111
|
+
support_reference?: string | null;
|
|
112
|
+
[key: string]: unknown;
|
|
113
|
+
}
|
|
114
|
+
interface DirectRequestPaymentBuyerMeteredSummary {
|
|
115
|
+
role: "buyer";
|
|
116
|
+
open_periods: Array<Record<string, unknown>>;
|
|
117
|
+
settlement_batches: DirectRequestPaymentSettlementBatch[];
|
|
118
|
+
past_due_blocks: Array<Record<string, unknown>>;
|
|
119
|
+
balance_sufficiency?: Record<string, unknown>;
|
|
120
|
+
[key: string]: unknown;
|
|
121
|
+
}
|
|
122
|
+
interface DirectRequestPaymentProviderMeteredSummary {
|
|
123
|
+
role: "provider";
|
|
124
|
+
timezone?: string | null;
|
|
125
|
+
filters?: Record<string, unknown>;
|
|
126
|
+
open_periods: Array<Record<string, unknown>>;
|
|
127
|
+
periods: DirectRequestPaymentSettlementBatch[];
|
|
128
|
+
totals: Record<string, DirectRequestPaymentMinorAmount>;
|
|
129
|
+
[key: string]: unknown;
|
|
130
|
+
}
|
|
11
131
|
interface DirectRequestPaymentChallengeInput {
|
|
12
132
|
merchant: string;
|
|
13
133
|
amount_minor: number;
|
|
@@ -78,11 +198,17 @@ interface DirectPaymentRequirement {
|
|
|
78
198
|
capability_key: string;
|
|
79
199
|
requirement_hash: string;
|
|
80
200
|
request_hash: string;
|
|
201
|
+
request_hash_v2?: string | null;
|
|
81
202
|
siglume_signature: string;
|
|
82
203
|
token_symbol: string;
|
|
83
204
|
currency: string;
|
|
84
205
|
amount_minor: number;
|
|
85
206
|
fee_bps: number;
|
|
207
|
+
pricing_band?: "standard" | DirectRequestPaymentMeteredPlanType | string | null;
|
|
208
|
+
settlement_cadence?: "per_payment" | "weekly" | "monthly" | string | null;
|
|
209
|
+
finality?: string | null;
|
|
210
|
+
protocol_fee_minor?: DirectRequestPaymentMinorAmount | null;
|
|
211
|
+
settlement_status?: string | null;
|
|
86
212
|
status: string;
|
|
87
213
|
expires_at?: string | null;
|
|
88
214
|
confirmed_at?: string | null;
|
|
@@ -265,6 +391,12 @@ interface DirectRequestPaymentWebhookEvent {
|
|
|
265
391
|
currency?: string;
|
|
266
392
|
token_symbol?: string;
|
|
267
393
|
status?: string;
|
|
394
|
+
request_hash_v2?: string | null;
|
|
395
|
+
pricing_band?: "standard" | DirectRequestPaymentMeteredPlanType | string | null;
|
|
396
|
+
settlement_cadence?: "per_payment" | "weekly" | "monthly" | string | null;
|
|
397
|
+
finality?: string | null;
|
|
398
|
+
protocol_fee_minor?: DirectRequestPaymentMinorAmount | null;
|
|
399
|
+
settlement_status?: string | null;
|
|
268
400
|
[key: string]: unknown;
|
|
269
401
|
};
|
|
270
402
|
[key: string]: unknown;
|
|
@@ -310,6 +442,13 @@ declare class DirectRequestPaymentClient {
|
|
|
310
442
|
await_finality?: boolean;
|
|
311
443
|
metadata?: Record<string, unknown>;
|
|
312
444
|
}): Promise<Web3PreparedTransactionExecuteResult>;
|
|
445
|
+
getBuyerMeteredSummary(input?: DirectRequestPaymentBuyerMeteredQuery): Promise<DirectRequestPaymentBuyerMeteredSummary>;
|
|
446
|
+
listBuyerUsageEvents(input?: DirectRequestPaymentMeteredListQuery): Promise<DirectRequestPaymentListResponse<DirectRequestPaymentBuyerUsageEvent>>;
|
|
447
|
+
listBuyerSettlementBatches(input?: DirectRequestPaymentMeteredListQuery): Promise<DirectRequestPaymentListResponse<DirectRequestPaymentSettlementBatch>>;
|
|
448
|
+
getProviderMeteredSummary(input?: DirectRequestPaymentProviderMeteredQuery): Promise<DirectRequestPaymentProviderMeteredSummary>;
|
|
449
|
+
listProviderUsageEvents(input?: DirectRequestPaymentProviderMeteredListQuery): Promise<DirectRequestPaymentListResponse<DirectRequestPaymentProviderUsageEvent>>;
|
|
450
|
+
listProviderSettlementBatches(input?: DirectRequestPaymentProviderMeteredListQuery): Promise<DirectRequestPaymentListResponse<DirectRequestPaymentSettlementBatch>>;
|
|
451
|
+
getProviderSettlementBatch(settlement_batch_id: string, input?: Pick<DirectRequestPaymentProviderMeteredQuery, "listing_id" | "capability_key">): Promise<DirectRequestPaymentSettlementBatch>;
|
|
313
452
|
request<T>(method: string, path: string, json_body?: unknown): Promise<T>;
|
|
314
453
|
}
|
|
315
454
|
declare class DirectRequestPaymentMerchantClient {
|
|
@@ -383,6 +522,12 @@ declare function directRequestPaymentRequestHash(input: {
|
|
|
383
522
|
currency: DirectRequestPaymentCurrency | string;
|
|
384
523
|
challenge: string;
|
|
385
524
|
}): Promise<string>;
|
|
525
|
+
declare function directRequestPaymentRequestHashV2(input: {
|
|
526
|
+
merchant: string;
|
|
527
|
+
amount_minor: number;
|
|
528
|
+
currency: DirectRequestPaymentCurrency | string;
|
|
529
|
+
challenge: string;
|
|
530
|
+
}): Promise<string>;
|
|
386
531
|
declare function buildPaymentExecutionPayload(requirement: DirectPaymentRequirement, options?: {
|
|
387
532
|
await_finality?: boolean;
|
|
388
533
|
metadata?: Record<string, unknown>;
|
|
@@ -419,4 +564,4 @@ declare const verifyExternal402Challenge: typeof verifyDirectRequestPaymentChall
|
|
|
419
564
|
declare const createExternal402RecurringChallenge: typeof createDirectRequestPaymentRecurringChallenge;
|
|
420
565
|
declare const verifyExternal402RecurringChallenge: typeof verifyDirectRequestPaymentRecurringChallenge;
|
|
421
566
|
|
|
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 };
|
|
567
|
+
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, DIRECT_REQUEST_PAYMENT_SDK_VERSION, type DirectPaymentRequirement, type DirectPaymentRequirementCreateInput, type DirectPaymentVerifyInput, type DirectRequestPaymentBillingPlan, type DirectRequestPaymentBuyerMeteredQuery, type DirectRequestPaymentBuyerMeteredSummary, type DirectRequestPaymentBuyerUsageEvent, type DirectRequestPaymentChallenge, type DirectRequestPaymentChallengeInput, type DirectRequestPaymentCheckoutSetupInput, type DirectRequestPaymentCheckoutSetupResult, DirectRequestPaymentClient, type DirectRequestPaymentClientOptions, type DirectRequestPaymentCurrency, type DirectRequestPaymentListResponse, type DirectRequestPaymentMerchantAccount, type DirectRequestPaymentMerchantBillingMandateInput, DirectRequestPaymentMerchantClient, type DirectRequestPaymentMerchantResponse, type DirectRequestPaymentMerchantSetupInput, type DirectRequestPaymentMeteredListQuery, type DirectRequestPaymentMeteredPlanType, type DirectRequestPaymentMinorAmount, type DirectRequestPaymentProviderMeteredListQuery, type DirectRequestPaymentProviderMeteredQuery, type DirectRequestPaymentProviderMeteredSummary, type DirectRequestPaymentProviderUsageEvent, type DirectRequestPaymentRecurringCadence, type DirectRequestPaymentRecurringChallenge, type DirectRequestPaymentRecurringChallengeInput, type DirectRequestPaymentSettlementBatch, 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, directRequestPaymentRequestHashV2, parseDirectRequestPaymentChallenge, parseDirectRequestPaymentWebhookEvent, verifyDirectRequestPaymentChallenge, verifyDirectRequestPaymentRecurringChallenge, verifyDirectRequestPaymentWebhook, verifyExternal402Challenge, verifyExternal402RecurringChallenge, verifyWebhookSignature };
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,8 @@ var DIRECT_REQUEST_PAYMENT_RECEIPT_KIND = "sdrp_direct_payment";
|
|
|
7
7
|
var DIRECT_REQUEST_PAYMENT_ALLOWANCE_RECEIPT_KIND = "sdrp_direct_payment_allowance";
|
|
8
8
|
var DIRECT_REQUEST_PAYMENT_REFERENCE_TYPE = "sdrp_direct_payment_requirement";
|
|
9
9
|
var DEFAULT_WEBHOOK_TOLERANCE_SECONDS = 300;
|
|
10
|
+
var DIRECT_REQUEST_PAYMENT_SDK_VERSION = "0.4.5";
|
|
11
|
+
var DIRECT_REQUEST_PAYMENT_CONFIRMED_WEBHOOK_MODES = /* @__PURE__ */ new Set([DIRECT_REQUEST_PAYMENT_MODE, "metered_settlement_batch"]);
|
|
10
12
|
var SiglumeDirectRequestPaymentError = class extends Error {
|
|
11
13
|
constructor(message) {
|
|
12
14
|
super(message);
|
|
@@ -53,7 +55,7 @@ var DirectRequestPaymentClient = class {
|
|
|
53
55
|
const authToken = options.auth_token ?? envValue("SIGLUME_AUTH_TOKEN");
|
|
54
56
|
if (!authToken) {
|
|
55
57
|
throw new SiglumeDirectRequestPaymentError(
|
|
56
|
-
"A buyer Siglume bearer token is required for Direct Request Payment API calls. Developer Portal API keys are not accepted."
|
|
58
|
+
"A buyer or provider Siglume user bearer token is required for Direct Request Payment API calls. Developer Portal API keys are not accepted."
|
|
57
59
|
);
|
|
58
60
|
}
|
|
59
61
|
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
@@ -63,7 +65,7 @@ var DirectRequestPaymentClient = class {
|
|
|
63
65
|
this.auth_token = authToken;
|
|
64
66
|
this.base_url = (options.base_url ?? envValue("SIGLUME_API_BASE") ?? DEFAULT_SIGLUME_API_BASE).replace(/\/+$/, "");
|
|
65
67
|
this.timeout_ms = Math.max(1, Math.trunc(options.timeout_ms ?? 15e3));
|
|
66
|
-
this.user_agent = options.user_agent ??
|
|
68
|
+
this.user_agent = options.user_agent ?? `@siglume/direct-request-payment/${DIRECT_REQUEST_PAYMENT_SDK_VERSION}`;
|
|
67
69
|
this.fetch_impl = fetchImpl;
|
|
68
70
|
}
|
|
69
71
|
async createPaymentRequirement(input) {
|
|
@@ -111,6 +113,53 @@ var DirectRequestPaymentClient = class {
|
|
|
111
113
|
async executeAllowanceTransaction(requirement, options = {}) {
|
|
112
114
|
return this.executePreparedTransaction(buildAllowanceExecutionPayload(requirement, options));
|
|
113
115
|
}
|
|
116
|
+
async getBuyerMeteredSummary(input = {}) {
|
|
117
|
+
return this.request(
|
|
118
|
+
"GET",
|
|
119
|
+
meteredQueryPath("/sdrp/metered/my-summary", input)
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
async listBuyerUsageEvents(input = {}) {
|
|
123
|
+
return this.request(
|
|
124
|
+
"GET",
|
|
125
|
+
meteredQueryPath("/sdrp/metered/my-usage-events", input)
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
async listBuyerSettlementBatches(input = {}) {
|
|
129
|
+
return this.request(
|
|
130
|
+
"GET",
|
|
131
|
+
meteredQueryPath("/sdrp/metered/my-settlement-batches", input)
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
async getProviderMeteredSummary(input = {}) {
|
|
135
|
+
return this.request(
|
|
136
|
+
"GET",
|
|
137
|
+
meteredQueryPath("/sdrp/metered/provider/summary", input)
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
async listProviderUsageEvents(input = {}) {
|
|
141
|
+
return this.request(
|
|
142
|
+
"GET",
|
|
143
|
+
meteredQueryPath("/sdrp/metered/provider/usage-events", input)
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
async listProviderSettlementBatches(input = {}) {
|
|
147
|
+
return this.request(
|
|
148
|
+
"GET",
|
|
149
|
+
meteredQueryPath("/sdrp/metered/provider/settlement-batches", input)
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
async getProviderSettlementBatch(settlement_batch_id, input = {}) {
|
|
153
|
+
return this.request(
|
|
154
|
+
"GET",
|
|
155
|
+
meteredQueryPath(
|
|
156
|
+
`/sdrp/metered/provider/settlement-batches/${encodeURIComponent(
|
|
157
|
+
requireNonEmpty(settlement_batch_id, "settlement_batch_id")
|
|
158
|
+
)}`,
|
|
159
|
+
input
|
|
160
|
+
)
|
|
161
|
+
);
|
|
162
|
+
}
|
|
114
163
|
async request(method, path, json_body) {
|
|
115
164
|
const controller = new AbortController();
|
|
116
165
|
const timeout = setTimeout(() => controller.abort(), this.timeout_ms);
|
|
@@ -168,7 +217,7 @@ var DirectRequestPaymentMerchantClient = class {
|
|
|
168
217
|
this.auth_token = authToken;
|
|
169
218
|
this.base_url = (options.base_url ?? envValue("SIGLUME_API_BASE") ?? DEFAULT_SIGLUME_API_BASE).replace(/\/+$/, "");
|
|
170
219
|
this.timeout_ms = Math.max(1, Math.trunc(options.timeout_ms ?? 15e3));
|
|
171
|
-
this.user_agent = options.user_agent ??
|
|
220
|
+
this.user_agent = options.user_agent ?? `@siglume/direct-request-payment/${DIRECT_REQUEST_PAYMENT_SDK_VERSION}`;
|
|
172
221
|
this.fetch_impl = fetchImpl;
|
|
173
222
|
}
|
|
174
223
|
async setupMerchant(input) {
|
|
@@ -461,6 +510,16 @@ async function directRequestPaymentRequestHash(input) {
|
|
|
461
510
|
const material = `${normalizeMerchant(input.merchant)}${positiveInteger(input.amount_minor, "amount_minor")}${normalizeCurrency(input.currency)}${requireNonEmpty(input.challenge, "challenge")}`;
|
|
462
511
|
return sha256Prefixed(material);
|
|
463
512
|
}
|
|
513
|
+
async function directRequestPaymentRequestHashV2(input) {
|
|
514
|
+
const material = JSON.stringify({
|
|
515
|
+
amount_minor: positiveInteger(input.amount_minor, "amount_minor"),
|
|
516
|
+
challenge: requireNonEmpty(input.challenge, "challenge"),
|
|
517
|
+
currency: normalizeCurrency(input.currency),
|
|
518
|
+
merchant: normalizeMerchant(input.merchant),
|
|
519
|
+
version: 2
|
|
520
|
+
});
|
|
521
|
+
return sha256Prefixed(material);
|
|
522
|
+
}
|
|
464
523
|
function buildPaymentExecutionPayload(requirement, options = {}) {
|
|
465
524
|
return buildPreparedTransactionExecutionPayload(requirement, requirement.transaction_request, {
|
|
466
525
|
receipt_kind: DIRECT_REQUEST_PAYMENT_RECEIPT_KIND,
|
|
@@ -534,8 +593,10 @@ function parseDirectRequestPaymentWebhookEvent(payload) {
|
|
|
534
593
|
occurred_at: requireNonEmpty(stringOrNull(event.occurred_at) ?? "", "webhook occurred_at"),
|
|
535
594
|
data: { ...data }
|
|
536
595
|
};
|
|
537
|
-
if (parsed.type === "direct_payment.confirmed" && parsed.data.mode
|
|
538
|
-
throw new SiglumeWebhookPayloadError(
|
|
596
|
+
if (parsed.type === "direct_payment.confirmed" && !DIRECT_REQUEST_PAYMENT_CONFIRMED_WEBHOOK_MODES.has(String(parsed.data.mode ?? ""))) {
|
|
597
|
+
throw new SiglumeWebhookPayloadError(
|
|
598
|
+
"direct_payment.confirmed webhook must carry a supported Direct Request Payment mode."
|
|
599
|
+
);
|
|
539
600
|
}
|
|
540
601
|
return parsed;
|
|
541
602
|
}
|
|
@@ -589,6 +650,13 @@ function normalizeToken(value) {
|
|
|
589
650
|
}
|
|
590
651
|
return token;
|
|
591
652
|
}
|
|
653
|
+
function normalizeMeteredPlanType(value) {
|
|
654
|
+
const planType = requireNonEmpty(value, "plan_type").toLowerCase();
|
|
655
|
+
if (planType === "micro" || planType === "nano") {
|
|
656
|
+
return planType;
|
|
657
|
+
}
|
|
658
|
+
throw new SiglumeDirectRequestPaymentError("plan_type must be micro or nano.");
|
|
659
|
+
}
|
|
592
660
|
function normalizeAllowedCurrencies(value) {
|
|
593
661
|
const normalized = {};
|
|
594
662
|
if (Array.isArray(value)) {
|
|
@@ -626,7 +694,15 @@ function normalizeOriginList(value) {
|
|
|
626
694
|
"each checkout_allowed_origins entry must be an absolute origin such as https://shop.example.com."
|
|
627
695
|
);
|
|
628
696
|
}
|
|
629
|
-
|
|
697
|
+
if (url.username || url.password) {
|
|
698
|
+
throw new SiglumeDirectRequestPaymentError("checkout_allowed_origins entries must not include userinfo.");
|
|
699
|
+
}
|
|
700
|
+
if (!isAllowedCheckoutOriginScheme(url)) {
|
|
701
|
+
throw new SiglumeDirectRequestPaymentError(
|
|
702
|
+
"checkout_allowed_origins entries must use https, except http is allowed for localhost, 127.0.0.1, or [::1]."
|
|
703
|
+
);
|
|
704
|
+
}
|
|
705
|
+
const origin = url.origin.toLowerCase();
|
|
630
706
|
if (!seen.has(origin)) {
|
|
631
707
|
seen.add(origin);
|
|
632
708
|
origins.push(origin);
|
|
@@ -634,8 +710,47 @@ function normalizeOriginList(value) {
|
|
|
634
710
|
}
|
|
635
711
|
return origins;
|
|
636
712
|
}
|
|
713
|
+
function isAllowedCheckoutOriginScheme(url) {
|
|
714
|
+
if (url.protocol === "https:") {
|
|
715
|
+
return Boolean(url.hostname);
|
|
716
|
+
}
|
|
717
|
+
if (url.protocol !== "http:") {
|
|
718
|
+
return false;
|
|
719
|
+
}
|
|
720
|
+
const hostname = url.hostname.toLowerCase();
|
|
721
|
+
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]" || hostname === "::1";
|
|
722
|
+
}
|
|
723
|
+
function meteredQueryPath(path, input) {
|
|
724
|
+
const params = new URLSearchParams();
|
|
725
|
+
if (input.plan_type !== void 0) {
|
|
726
|
+
params.set("plan_type", normalizeMeteredPlanType(input.plan_type));
|
|
727
|
+
}
|
|
728
|
+
if (input.token_symbol !== void 0) {
|
|
729
|
+
params.set("token_symbol", normalizeToken(input.token_symbol));
|
|
730
|
+
}
|
|
731
|
+
if ("status" in input && input.status !== void 0) {
|
|
732
|
+
params.set("status", requireNonEmpty(input.status, "status"));
|
|
733
|
+
}
|
|
734
|
+
if ("listing_id" in input && input.listing_id !== void 0) {
|
|
735
|
+
params.set("listing_id", requireNonEmpty(input.listing_id, "listing_id"));
|
|
736
|
+
}
|
|
737
|
+
if ("capability_key" in input && input.capability_key !== void 0) {
|
|
738
|
+
params.set("capability_key", requireNonEmpty(input.capability_key, "capability_key"));
|
|
739
|
+
}
|
|
740
|
+
if ("limit" in input && input.limit !== void 0) {
|
|
741
|
+
params.set("limit", String(positiveInteger(input.limit, "limit")));
|
|
742
|
+
}
|
|
743
|
+
if ("cursor" in input && input.cursor !== void 0) {
|
|
744
|
+
params.set("cursor", requireNonEmpty(input.cursor, "cursor"));
|
|
745
|
+
}
|
|
746
|
+
const query = params.toString();
|
|
747
|
+
return query ? `${path}?${query}` : path;
|
|
748
|
+
}
|
|
637
749
|
function positiveInteger(value, name) {
|
|
638
|
-
|
|
750
|
+
if (typeof value !== "number") {
|
|
751
|
+
throw new SiglumeDirectRequestPaymentError(`${name} must be a positive safe integer.`);
|
|
752
|
+
}
|
|
753
|
+
const parsed = value;
|
|
639
754
|
if (!Number.isSafeInteger(parsed) || parsed <= 0) {
|
|
640
755
|
throw new SiglumeDirectRequestPaymentError(`${name} must be a positive safe integer.`);
|
|
641
756
|
}
|
|
@@ -837,6 +952,7 @@ export {
|
|
|
837
952
|
DIRECT_REQUEST_PAYMENT_RECEIPT_KIND,
|
|
838
953
|
DIRECT_REQUEST_PAYMENT_RECURRING_CHALLENGE_SCHEME,
|
|
839
954
|
DIRECT_REQUEST_PAYMENT_REFERENCE_TYPE,
|
|
955
|
+
DIRECT_REQUEST_PAYMENT_SDK_VERSION,
|
|
840
956
|
DirectRequestPaymentClient,
|
|
841
957
|
DirectRequestPaymentMerchantClient,
|
|
842
958
|
HostedCheckoutNotAvailableError,
|
|
@@ -857,6 +973,7 @@ export {
|
|
|
857
973
|
createExternal402RecurringChallenge,
|
|
858
974
|
directRequestPaymentChallengeHash,
|
|
859
975
|
directRequestPaymentRequestHash,
|
|
976
|
+
directRequestPaymentRequestHashV2,
|
|
860
977
|
parseDirectRequestPaymentChallenge,
|
|
861
978
|
parseDirectRequestPaymentWebhookEvent,
|
|
862
979
|
verifyDirectRequestPaymentChallenge,
|