@siglume/direct-request-payment 0.3.0 → 0.3.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.
@@ -1,274 +1,331 @@
1
- # API Reference
2
-
3
- The TypeScript package is `@siglume/direct-request-payment`. The Python package
4
- is `siglume-direct-request-payment` and imports as
5
- `siglume_direct_request_payment`.
6
-
7
- ## Environment Variables
8
-
9
- | Name | Used by | Purpose |
10
- | --- | --- | --- |
11
- | `SIGLUME_DIRECT_PAYMENT_CHALLENGE_SECRET` | merchant server | HMAC secret for order challenges |
12
- | `SIGLUME_MERCHANT_AUTH_TOKEN` | merchant setup helper | merchant Siglume bearer token for self-service setup |
13
- | `SIGLUME_AUTH_TOKEN` | buyer payment helper | buyer Siglume bearer token for API calls |
14
- | `SIGLUME_API_BASE` | optional | API base URL override; defaults to `https://siglume.com/v1` |
15
- | `SIGLUME_WEBHOOK_SECRET` | merchant server | webhook signing secret returned as `whsec_...` |
16
-
17
- Do not use a Developer Portal `cli_` API key as either auth token. Merchant
18
- setup is merchant-JWT authenticated; payment requirement creation is
19
- buyer-JWT authenticated.
20
-
21
- ## `createDirectRequestPaymentChallenge(input)` / `create_direct_request_payment_challenge(...)`
22
-
23
- Creates the merchant-signed challenge required by Siglume.
24
-
25
- ```ts
26
- const challenge = await createDirectRequestPaymentChallenge({
27
- merchant: "example_merchant",
28
- amount_minor: 1200,
29
- currency: "JPY",
30
- secret: process.env.SIGLUME_DIRECT_PAYMENT_CHALLENGE_SECRET!,
31
- nonce: "order_123-attempt_1",
32
- });
33
- ```
34
-
35
- ```py
36
- import os
37
-
38
- challenge = create_direct_request_payment_challenge(
39
- merchant="example_merchant",
40
- amount_minor=1200,
41
- currency="JPY",
42
- secret=os.environ["SIGLUME_DIRECT_PAYMENT_CHALLENGE_SECRET"],
43
- nonce="order_123-attempt_1",
44
- )
45
- ```
46
-
47
- Returns:
48
-
49
- - `challenge`: value to pass to Siglume
50
- - `challenge_hash`: value to store on the order
51
- - `signature`: HMAC-SHA256 hex digest
52
- - `nonce`
53
-
54
- `nonce` must not contain `:` because the platform challenge string is delimited
55
- as `scheme:nonce:signature`.
56
-
57
- ## `verifyDirectRequestPaymentChallenge(secret, input)` / `verify_direct_request_payment_challenge(...)`
58
-
59
- Verifies a challenge against merchant, amount, currency, and secret. This is
60
- useful in tests and internal checkout assertions.
61
-
62
- ## `directRequestPaymentChallengeHash(challenge)` / `direct_request_payment_challenge_hash(...)`
63
-
64
- Returns the `sha256:`-prefixed hash for an existing challenge string.
65
-
66
- ## `directRequestPaymentRequestHash(input)` / `direct_request_payment_request_hash(...)`
67
-
68
- Returns the SDK-side request hash material for merchant, amount, currency, and
69
- challenge. This is mostly useful for tests and internal assertions.
70
-
71
- ## `DirectRequestPaymentMerchantClient`
72
-
73
- Use this client with the merchant's Siglume bearer token. It is the self-service
74
- setup surface for an external merchant integrating Direct Request Payment.
75
-
76
- ```ts
77
- const merchant = new DirectRequestPaymentMerchantClient({
78
- auth_token: merchantSiglumeBearerToken,
79
- base_url: "https://siglume.com/v1",
80
- });
81
- ```
82
-
83
- ```py
84
- merchant = DirectRequestPaymentMerchantClient(
85
- auth_token=merchant_siglume_bearer_token,
86
- base_url="https://siglume.com/v1",
87
- )
88
- ```
89
-
90
- ### `setupCheckout(input)` / `setup_checkout(...)`
91
-
92
- High-level setup for most integrations. It calls merchant setup, billing mandate
93
- preparation, and webhook subscription creation.
94
-
95
- Input:
96
-
97
- - `merchant`: self-service merchant key, 3-64 chars using lowercase letters,
98
- numbers, `_`, or `-`
99
- - `display_name`: optional public merchant name
100
- - `billing_plan`: `launch`, `starter`, `growth`, or `pro`
101
- - `billing_currency`: `JPY`; `USD` requires agreed USD/USDC billing terms
102
- - `webhook_callback_url`: HTTPS callback URL for signed payment events
103
- - `max_amount_minor`: optional billing mandate cap
104
-
105
- Returns:
106
-
107
- - `merchant`: merchant account setup response
108
- - `billing_mandate`: billing mandate preparation response, when requested
109
- - `webhook_subscription`: webhook subscription response, when created
110
- - `env`: server environment values to store, including returned secrets
111
-
112
- Secrets are returned only when created or rotated. Existing secrets are not
113
- replayed by `getMerchant` / `get_merchant`.
114
-
115
- ### `setupMerchant(input)` / `setup_merchant(...)`
116
-
117
- Calls:
118
-
119
- ```text
120
- POST /v1/market/api-store/direct-payments/merchants
121
- ```
122
-
123
- Creates or updates the merchant account for the authenticated merchant user.
124
-
125
- ### `getMerchant(merchant)` / `get_merchant(merchant)`
126
-
127
- Calls:
128
-
129
- ```text
130
- GET /v1/market/api-store/direct-payments/merchants/{merchant}
131
- ```
132
-
133
- Returns setup and billing status without returning the challenge secret.
134
-
135
- ### `rotateChallengeSecret(merchant)` / `rotate_challenge_secret(merchant)`
136
-
137
- Calls:
138
-
139
- ```text
140
- POST /v1/market/api-store/direct-payments/merchants/{merchant}/challenge-secret/rotate
141
- ```
142
-
143
- Returns the new challenge secret once.
144
-
145
- ### `prepareBillingMandate(merchant, input)` / `prepare_billing_mandate(...)`
146
-
147
- Calls:
148
-
149
- ```text
150
- POST /v1/market/api-store/direct-payments/merchants/{merchant}/billing-mandate
151
- ```
152
-
153
- Creates or reuses the merchant billing mandate. If the returned mandate requires
154
- wallet approval, complete that Siglume wallet step before accepting payments.
155
-
156
- ### `createWebhookSubscription(input)` / `create_webhook_subscription(...)`
157
-
158
- Calls:
159
-
160
- ```text
161
- POST /v1/market/webhooks/subscriptions
162
- ```
163
-
164
- Defaults event types to `direct_payment.confirmed` and
165
- `direct_payment.spent`. The returned `signing_secret` is shown only at creation
166
- or rotation.
167
-
168
- ## `DirectRequestPaymentClient`
169
-
170
- Thin wrapper around the current Siglume Direct Request Payment HTTP contract.
171
- Use it with the authenticated buyer's Siglume bearer token. Developer Portal
172
- `cli_` API keys are not accepted by these buyer-authenticated routes.
173
-
174
- Payment requirements include `fee_bps` from the Siglume platform. The SDK does
175
- not calculate merchant plan fees locally; see [Pricing](./pricing.md).
176
-
177
- ```ts
178
- const siglume = new DirectRequestPaymentClient({
179
- auth_token: buyerSiglumeBearerToken,
180
- base_url: "https://siglume.com/v1",
181
- });
182
- ```
183
-
184
- ```py
185
- siglume = DirectRequestPaymentClient(
186
- auth_token=buyer_siglume_bearer_token,
187
- base_url="https://siglume.com/v1",
188
- )
189
- ```
190
-
191
- ### `createPaymentRequirement(input)` / `create_payment_requirement(...)`
192
-
193
- Calls:
194
-
195
- ```text
196
- POST /v1/market/api-store/direct-payments/requirements
197
- ```
198
-
199
- The SDK sends `mode="external_402"` internally.
200
-
201
- Input:
202
-
203
- - `merchant`: Siglume merchant key
204
- - `amount_minor`: positive integer in minor currency units
205
- - `currency`: `JPY` or `USD` when enabled for the merchant account
206
- - `challenge`: merchant-signed challenge string
207
- - `token_symbol`: optional `JPYC` or `USDC` when enabled for the merchant account
208
- - `allowance_amount_minor`: optional positive integer
209
- - `metadata`: optional JSON object
210
-
211
- ### `executeAllowanceTransaction(requirement)` / `execute_allowance_transaction(...)`
212
-
213
- Executes `requirement.approve_transaction_request` through:
214
-
215
- ```text
216
- POST /v1/market/web3/transactions/execute-prepared
217
- ```
218
-
219
- Only call this when Siglume returned an approval transaction.
220
-
221
- ### `executePaymentTransaction(requirement)` / `execute_payment_transaction(...)`
222
-
223
- Executes `requirement.transaction_request` through the same prepared transaction
224
- route.
225
-
226
- ### `verifyPaymentRequirement(requirement_id, input)` / `verify_payment_requirement(...)`
227
-
228
- Calls:
229
-
230
- ```text
231
- POST /v1/market/api-store/direct-payments/requirements/{requirement_id}/verify
232
- ```
233
-
234
- Input may include:
235
-
236
- - `receipt_id`
237
- - `chain_receipt_id`
238
- - `await_finality`
239
- - `await_required_status`
240
- - `await_timeout_seconds`
241
- - `await_poll_seconds`
242
-
243
- ## Webhook Helpers
244
-
245
- - `buildWebhookSignatureHeader(secret, body)` for tests
246
- - `verifyWebhookSignature(secret, body, header)`
247
- - `verifyDirectRequestPaymentWebhook(secret, body, header)`
248
- - `parseDirectRequestPaymentWebhookEvent(payload)`
249
- - Python equivalents use snake_case:
250
- `build_webhook_signature_header`, `verify_webhook_signature`,
251
- `verify_direct_request_payment_webhook`, and
252
- `parse_direct_request_payment_webhook_event`.
253
-
254
- `verifyDirectRequestPaymentWebhook` verifies the signature and parses the event
255
- in one call.
256
-
257
- ## Errors
258
-
259
- TypeScript exports:
260
-
261
- - `SiglumeDirectRequestPaymentError`
262
- - `SiglumeApiError`
263
- - `SiglumeWebhookSignatureError`
264
- - `SiglumeWebhookPayloadError`
265
-
266
- Python exports:
267
-
268
- - `DirectRequestPaymentError`
269
- - `SiglumeApiError`
270
- - `SiglumeWebhookSignatureError`
271
- - `SiglumeWebhookPayloadError`
272
-
273
- `SiglumeApiError` includes the HTTP status, platform error code, and parsed
274
- response data where available.
1
+ # API Reference
2
+
3
+ The TypeScript package is `@siglume/direct-request-payment`. The Python package
4
+ is `siglume-direct-request-payment` and imports as
5
+ `siglume_direct_request_payment`.
6
+
7
+ ## Environment Variables
8
+
9
+ | Name | Used by | Purpose |
10
+ | --- | --- | --- |
11
+ | `SIGLUME_DIRECT_PAYMENT_CHALLENGE_SECRET` | merchant server | HMAC secret for order challenges |
12
+ | `SIGLUME_MERCHANT_AUTH_TOKEN` | merchant setup helper | merchant Siglume bearer token for self-service setup |
13
+ | `SIGLUME_AUTH_TOKEN` | buyer payment helper | buyer Siglume bearer token for API calls |
14
+ | `SIGLUME_API_BASE` | optional | API base URL override; defaults to `https://siglume.com/v1` |
15
+ | `SIGLUME_WEBHOOK_SECRET` | merchant server | webhook signing secret returned as `whsec_...` |
16
+
17
+ Do not use a Developer Portal `cli_` API key as either auth token. Merchant
18
+ setup is merchant-JWT authenticated; payment requirement creation is
19
+ buyer-JWT authenticated.
20
+
21
+ ## `createDirectRequestPaymentChallenge(input)` / `create_direct_request_payment_challenge(...)`
22
+
23
+ Creates the merchant-signed challenge required by Siglume.
24
+
25
+ ```ts
26
+ const challenge = await createDirectRequestPaymentChallenge({
27
+ merchant: "example_merchant",
28
+ amount_minor: 1200,
29
+ currency: "JPY",
30
+ secret: process.env.SIGLUME_DIRECT_PAYMENT_CHALLENGE_SECRET!,
31
+ nonce: "order_123-attempt_1",
32
+ });
33
+ ```
34
+
35
+ ```py
36
+ import os
37
+
38
+ challenge = create_direct_request_payment_challenge(
39
+ merchant="example_merchant",
40
+ amount_minor=1200,
41
+ currency="JPY",
42
+ secret=os.environ["SIGLUME_DIRECT_PAYMENT_CHALLENGE_SECRET"],
43
+ nonce="order_123-attempt_1",
44
+ )
45
+ ```
46
+
47
+ Returns:
48
+
49
+ - `challenge`: value to pass to Siglume
50
+ - `challenge_hash`: value to store on the order
51
+ - `signature`: HMAC-SHA256 hex digest
52
+ - `nonce`
53
+
54
+ `nonce` must not contain `:` because the platform challenge string is delimited
55
+ as `scheme:nonce:signature`.
56
+
57
+ ## `verifyDirectRequestPaymentChallenge(secret, input)` / `verify_direct_request_payment_challenge(...)`
58
+
59
+ Verifies a challenge against merchant, amount, currency, and secret. This is
60
+ useful in tests and internal checkout assertions.
61
+
62
+ ## `createDirectRequestPaymentRecurringChallenge(input)` / `create_direct_request_payment_recurring_challenge(...)`
63
+
64
+ Creates the merchant-signed, one-time approval challenge used when a buyer sets
65
+ up a subscription or scheduled autopay authorization.
66
+
67
+ ```ts
68
+ const recurring = await createDirectRequestPaymentRecurringChallenge({
69
+ merchant: "example_merchant",
70
+ amount_minor: 980,
71
+ currency: "JPY",
72
+ cadence: "daily",
73
+ secret: process.env.SIGLUME_DIRECT_PAYMENT_CHALLENGE_SECRET!,
74
+ nonce: "schedule_setup_4711",
75
+ });
76
+ ```
77
+
78
+ ```py
79
+ recurring = create_direct_request_payment_recurring_challenge(
80
+ merchant="example_merchant",
81
+ amount_minor=980,
82
+ currency="JPY",
83
+ cadence="daily",
84
+ secret=os.environ["SIGLUME_DIRECT_PAYMENT_CHALLENGE_SECRET"],
85
+ nonce="schedule_setup_4711",
86
+ )
87
+ ```
88
+
89
+ The recurring signature binds:
90
+
91
+ - merchant key
92
+ - amount in minor units
93
+ - currency
94
+ - cadence
95
+ - nonce
96
+
97
+ The HMAC material is:
98
+
99
+ ```text
100
+ merchant:amount_minor:currency:cadence:nonce
101
+ ```
102
+
103
+ `cadence` must be:
104
+
105
+ - `monthly` for subscriptions
106
+ - `daily` for scheduled autopay
107
+
108
+ For scheduled autopay, `daily` is an approval tag. It is not a one-run-per-day
109
+ limit. Occurrence execution is bounded by the buyer-approved per-run, daily, and
110
+ monthly auto-pay budget.
111
+
112
+ Returns the same fields as the one-time challenge helper, plus `cadence`.
113
+
114
+ ## `verifyDirectRequestPaymentRecurringChallenge(secret, input)` / `verify_direct_request_payment_recurring_challenge(...)`
115
+
116
+ Verifies a recurring approval challenge against merchant, amount, currency,
117
+ cadence, and secret.
118
+
119
+ ## `directRequestPaymentChallengeHash(challenge)` / `direct_request_payment_challenge_hash(...)`
120
+
121
+ Returns the `sha256:`-prefixed hash for an existing challenge string.
122
+
123
+ ## `directRequestPaymentRequestHash(input)` / `direct_request_payment_request_hash(...)`
124
+
125
+ Returns the SDK-side request hash material for merchant, amount, currency, and
126
+ challenge. This is mostly useful for tests and internal assertions.
127
+
128
+ ## `DirectRequestPaymentMerchantClient`
129
+
130
+ Use this client with the merchant's Siglume bearer token. It is the self-service
131
+ setup surface for an external merchant integrating Direct Request Payment.
132
+
133
+ ```ts
134
+ const merchant = new DirectRequestPaymentMerchantClient({
135
+ auth_token: merchantSiglumeBearerToken,
136
+ base_url: "https://siglume.com/v1",
137
+ });
138
+ ```
139
+
140
+ ```py
141
+ merchant = DirectRequestPaymentMerchantClient(
142
+ auth_token=merchant_siglume_bearer_token,
143
+ base_url="https://siglume.com/v1",
144
+ )
145
+ ```
146
+
147
+ ### `setupCheckout(input)` / `setup_checkout(...)`
148
+
149
+ High-level setup for most integrations. It calls merchant setup, billing mandate
150
+ preparation, and webhook subscription creation.
151
+
152
+ Input:
153
+
154
+ - `merchant`: self-service merchant key, 3-64 chars using lowercase letters,
155
+ numbers, `_`, or `-`
156
+ - `display_name`: optional public merchant name
157
+ - `billing_plan`: `launch`, `starter`, `growth`, or `pro`
158
+ - `billing_currency`: `JPY`; `USD` requires agreed USD/USDC billing terms
159
+ - `webhook_callback_url`: HTTPS callback URL for signed payment events
160
+ - `max_amount_minor`: optional billing mandate cap
161
+
162
+ Returns:
163
+
164
+ - `merchant`: merchant account setup response
165
+ - `billing_mandate`: billing mandate preparation response, when requested
166
+ - `webhook_subscription`: webhook subscription response, when created
167
+ - `env`: server environment values to store, including returned secrets
168
+
169
+ Secrets are returned only when created or rotated. Existing secrets are not
170
+ replayed by `getMerchant` / `get_merchant`.
171
+
172
+ ### `setupMerchant(input)` / `setup_merchant(...)`
173
+
174
+ Calls:
175
+
176
+ ```text
177
+ POST /v1/market/api-store/direct-payments/merchants
178
+ ```
179
+
180
+ Creates or updates the merchant account for the authenticated merchant user.
181
+
182
+ ### `getMerchant(merchant)` / `get_merchant(merchant)`
183
+
184
+ Calls:
185
+
186
+ ```text
187
+ GET /v1/market/api-store/direct-payments/merchants/{merchant}
188
+ ```
189
+
190
+ Returns setup and billing status without returning the challenge secret.
191
+
192
+ ### `rotateChallengeSecret(merchant)` / `rotate_challenge_secret(merchant)`
193
+
194
+ Calls:
195
+
196
+ ```text
197
+ POST /v1/market/api-store/direct-payments/merchants/{merchant}/challenge-secret/rotate
198
+ ```
199
+
200
+ Returns the new challenge secret once.
201
+
202
+ ### `prepareBillingMandate(merchant, input)` / `prepare_billing_mandate(...)`
203
+
204
+ Calls:
205
+
206
+ ```text
207
+ POST /v1/market/api-store/direct-payments/merchants/{merchant}/billing-mandate
208
+ ```
209
+
210
+ Creates or reuses the merchant billing mandate. If the returned mandate requires
211
+ wallet approval, complete that Siglume wallet step before accepting payments.
212
+
213
+ ### `createWebhookSubscription(input)` / `create_webhook_subscription(...)`
214
+
215
+ Calls:
216
+
217
+ ```text
218
+ POST /v1/market/webhooks/subscriptions
219
+ ```
220
+
221
+ Defaults event types to `direct_payment.confirmed` and
222
+ `direct_payment.spent`. The returned `signing_secret` is shown only at creation
223
+ or rotation.
224
+
225
+ ## `DirectRequestPaymentClient`
226
+
227
+ Thin wrapper around the current Siglume Direct Request Payment HTTP contract.
228
+ Use it with the authenticated buyer's Siglume bearer token. Developer Portal
229
+ `cli_` API keys are not accepted by these buyer-authenticated routes.
230
+
231
+ Payment requirements include `fee_bps` from the Siglume platform. The SDK does
232
+ not calculate merchant plan fees locally; see [Pricing](./pricing.md).
233
+
234
+ ```ts
235
+ const siglume = new DirectRequestPaymentClient({
236
+ auth_token: buyerSiglumeBearerToken,
237
+ base_url: "https://siglume.com/v1",
238
+ });
239
+ ```
240
+
241
+ ```py
242
+ siglume = DirectRequestPaymentClient(
243
+ auth_token=buyer_siglume_bearer_token,
244
+ base_url="https://siglume.com/v1",
245
+ )
246
+ ```
247
+
248
+ ### `createPaymentRequirement(input)` / `create_payment_requirement(...)`
249
+
250
+ Calls:
251
+
252
+ ```text
253
+ POST /v1/market/api-store/direct-payments/requirements
254
+ ```
255
+
256
+ The SDK sends `mode="external_402"` internally.
257
+
258
+ Input:
259
+
260
+ - `merchant`: Siglume merchant key
261
+ - `amount_minor`: positive integer in minor currency units
262
+ - `currency`: `JPY` or `USD` when enabled for the merchant account
263
+ - `challenge`: merchant-signed challenge string
264
+ - `token_symbol`: optional `JPYC` or `USDC` when enabled for the merchant account
265
+ - `allowance_amount_minor`: optional positive integer
266
+ - `metadata`: optional JSON object
267
+
268
+ ### `executeAllowanceTransaction(requirement)` / `execute_allowance_transaction(...)`
269
+
270
+ Executes `requirement.approve_transaction_request` through:
271
+
272
+ ```text
273
+ POST /v1/market/web3/transactions/execute-prepared
274
+ ```
275
+
276
+ Only call this when Siglume returned an approval transaction.
277
+
278
+ ### `executePaymentTransaction(requirement)` / `execute_payment_transaction(...)`
279
+
280
+ Executes `requirement.transaction_request` through the same prepared transaction
281
+ route.
282
+
283
+ ### `verifyPaymentRequirement(requirement_id, input)` / `verify_payment_requirement(...)`
284
+
285
+ Calls:
286
+
287
+ ```text
288
+ POST /v1/market/api-store/direct-payments/requirements/{requirement_id}/verify
289
+ ```
290
+
291
+ Input may include:
292
+
293
+ - `receipt_id`
294
+ - `chain_receipt_id`
295
+ - `await_finality`
296
+ - `await_required_status`
297
+ - `await_timeout_seconds`
298
+ - `await_poll_seconds`
299
+
300
+ ## Webhook Helpers
301
+
302
+ - `buildWebhookSignatureHeader(secret, body)` for tests
303
+ - `verifyWebhookSignature(secret, body, header)`
304
+ - `verifyDirectRequestPaymentWebhook(secret, body, header)`
305
+ - `parseDirectRequestPaymentWebhookEvent(payload)`
306
+ - Python equivalents use snake_case:
307
+ `build_webhook_signature_header`, `verify_webhook_signature`,
308
+ `verify_direct_request_payment_webhook`, and
309
+ `parse_direct_request_payment_webhook_event`.
310
+
311
+ `verifyDirectRequestPaymentWebhook` verifies the signature and parses the event
312
+ in one call.
313
+
314
+ ## Errors
315
+
316
+ TypeScript exports:
317
+
318
+ - `SiglumeDirectRequestPaymentError`
319
+ - `SiglumeApiError`
320
+ - `SiglumeWebhookSignatureError`
321
+ - `SiglumeWebhookPayloadError`
322
+
323
+ Python exports:
324
+
325
+ - `DirectRequestPaymentError`
326
+ - `SiglumeApiError`
327
+ - `SiglumeWebhookSignatureError`
328
+ - `SiglumeWebhookPayloadError`
329
+
330
+ `SiglumeApiError` includes the HTTP status, platform error code, and parsed
331
+ response data where available.