@siglume/direct-request-payment 0.1.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.
@@ -0,0 +1,69 @@
1
+ # Siglume Direct Request Payment SDK 公開ドラフト
2
+
3
+ Siglume Direct Request Payment 向けの外部事業者用SDKを公開しました。
4
+
5
+ - npm: https://www.npmjs.com/package/@siglume/direct-request-payment
6
+ - PyPI: https://pypi.org/project/siglume-direct-request-payment/
7
+ - GitHub: https://github.com/taihei-05/siglume-direct-request-payment
8
+
9
+ このSDKは、外部EC、予約サービス、会員制サービス、API販売、AtoAの都度課金などで、Siglumeウォレット決済を自社プロダクトに組み込むためのSDKです。
10
+
11
+ ## できること
12
+
13
+ - merchant JWT によるセルフサービスの導入設定
14
+ - merchant key の作成
15
+ - challenge secret の発行とローテーション
16
+ - billing mandate の準備
17
+ - webhook subscription の作成
18
+ - merchant server 側での署名付き challenge 生成
19
+ - buyer JWT による payment requirement 作成
20
+ - prepared transaction の実行補助
21
+ - `direct_payment.confirmed` webhook の署名検証
22
+ - subscription / scheduled autopay 向け recurring challenge 生成
23
+
24
+ Developer Portal の `cli_` API key を使うSDKではありません。導入設定は merchant の Siglume JWT、支払い作成は buyer の Siglume JWT で行います。
25
+
26
+ ## 最短導入
27
+
28
+ ```ts
29
+ import { DirectRequestPaymentMerchantClient } from "@siglume/direct-request-payment";
30
+
31
+ const merchant = new DirectRequestPaymentMerchantClient({
32
+ auth_token: process.env.SIGLUME_MERCHANT_AUTH_TOKEN!,
33
+ });
34
+
35
+ const setup = await merchant.setupCheckout({
36
+ merchant: "example_merchant",
37
+ display_name: "Example Merchant",
38
+ billing_plan: "launch",
39
+ billing_currency: "JPY",
40
+ webhook_callback_url: "https://merchant.example/siglume/webhook",
41
+ max_amount_minor: 100000,
42
+ });
43
+
44
+ console.log(setup.env);
45
+ ```
46
+
47
+ `setup.env` に、サーバー側で保存すべき `SIGLUME_DIRECT_PAYMENT_MERCHANT`、`SIGLUME_DIRECT_PAYMENT_CHALLENGE_SECRET`、`SIGLUME_WEBHOOK_SECRET` が返ります。
48
+
49
+ ## 料金
50
+
51
+ | Plan | Monthly fee (JPY / USD) | Payment fee |
52
+ | --- | ---: | ---: |
53
+ | Launch | JPY 0 / USD 0 | 1.8% |
54
+ | Starter | JPY 980 / USD 6.00 | 1.0% |
55
+ | Growth | JPY 2,980 / USD 18.00 | 0.7% |
56
+ | Pro | JPY 9,800 / USD 60.00 | 0.5% |
57
+
58
+ すべての決済にプラン料率の手数料が発生します。最低手数料は 1 決済あたり JPY 30(USD マーチャントは USD 0.20)です。手数料は決済時に差し引かれ、マーチャントは純額を受け取ります。月額料金は merchant billing mandate 経由で請求されます。
59
+
60
+ ## Scheduled Autopay
61
+
62
+ `cadence: "daily"` は scheduled autopay の承認タグであり、1日1回の実行制限ではありません。実際の実行は、購入者が承認した1回あたり、日次、月次の auto-pay budget によって制御されます。
63
+
64
+ ## 注意点
65
+
66
+ - challenge secret と webhook secret はサーバー側だけに保存してください。
67
+ - merchant JWT で購入者ウォレットを課金することはできません。
68
+ - buyer の支払い作成には buyer JWT が必要です。
69
+ - 本番受付前に billing mandate の承認状態を確認してください。
@@ -1,20 +1,34 @@
1
- # API Reference
2
-
1
+ # API Reference
2
+
3
3
  The TypeScript package is `@siglume/direct-request-payment`. The Python package
4
4
  is `siglume-direct-request-payment` and imports as
5
5
  `siglume_direct_request_payment`.
6
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
+
7
21
  ## `createDirectRequestPaymentChallenge(input)` / `create_direct_request_payment_challenge(...)`
8
-
9
- Creates the merchant-signed challenge required by Siglume.
10
-
22
+
23
+ Creates the merchant-signed challenge required by Siglume.
24
+
11
25
  ```ts
12
26
  const challenge = await createDirectRequestPaymentChallenge({
13
- merchant: "example_merchant",
14
- amount_minor: 1200,
15
- currency: "JPY",
16
- secret: process.env.SIGLUME_DIRECT_PAYMENT_CHALLENGE_SECRET!,
17
- nonce: "order_123-attempt_1",
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",
18
32
  });
19
33
  ```
20
34
 
@@ -31,29 +45,192 @@ challenge = create_direct_request_payment_challenge(
31
45
  ```
32
46
 
33
47
  Returns:
34
-
35
- - `challenge`: value to pass to Siglume
36
- - `challenge_hash`: value to store on the order
37
- - `signature`: HMAC-SHA256 hex digest
38
- - `nonce`
39
-
40
- `nonce` must not contain `:` because the platform challenge string is delimited
41
- as `scheme:nonce:signature`.
42
-
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
+
43
57
  ## `verifyDirectRequestPaymentChallenge(secret, input)` / `verify_direct_request_payment_challenge(...)`
44
-
45
- Verifies a challenge against merchant, amount, currency, and secret. This is
46
- useful in tests and internal checkout assertions.
47
-
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
+
48
225
  ## `DirectRequestPaymentClient`
49
-
50
- Thin wrapper around the current Siglume Direct Request Payment HTTP contract.
51
- Use it with the authenticated buyer's Siglume bearer token. Developer Portal
52
- `cli_` API keys are not accepted by these buyer-authenticated routes.
53
-
54
- Payment requirements include `fee_bps` from the Siglume platform. The SDK does
55
- not calculate merchant plan fees locally; see [Pricing](./pricing.md).
56
-
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
+
57
234
  ```ts
58
235
  const siglume = new DirectRequestPaymentClient({
59
236
  auth_token: buyerSiglumeBearerToken,
@@ -69,40 +246,59 @@ siglume = DirectRequestPaymentClient(
69
246
  ```
70
247
 
71
248
  ### `createPaymentRequirement(input)` / `create_payment_requirement(...)`
72
-
73
- Calls:
74
-
75
- ```text
76
- POST /v1/market/api-store/direct-payments/requirements
77
- ```
78
-
79
- The SDK sends `mode="external_402"` internally.
80
-
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
+
81
268
  ### `executeAllowanceTransaction(requirement)` / `execute_allowance_transaction(...)`
82
-
83
- Executes `requirement.approve_transaction_request` through:
84
-
85
- ```text
86
- POST /v1/market/web3/transactions/execute-prepared
87
- ```
88
-
89
- Only call this when Siglume returned an approval transaction.
90
-
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
+
91
278
  ### `executePaymentTransaction(requirement)` / `execute_payment_transaction(...)`
92
-
93
- Executes `requirement.transaction_request` through the same prepared transaction
94
- route.
95
-
279
+
280
+ Executes `requirement.transaction_request` through the same prepared transaction
281
+ route.
282
+
96
283
  ### `verifyPaymentRequirement(requirement_id, input)` / `verify_payment_requirement(...)`
97
-
98
- Calls:
99
-
100
- ```text
101
- POST /v1/market/api-store/direct-payments/requirements/{requirement_id}/verify
102
- ```
103
-
104
- ## Webhook Helpers
105
-
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
+
106
302
  - `buildWebhookSignatureHeader(secret, body)` for tests
107
303
  - `verifyWebhookSignature(secret, body, header)`
108
304
  - `verifyDirectRequestPaymentWebhook(secret, body, header)`
@@ -111,6 +307,25 @@ POST /v1/market/api-store/direct-payments/requirements/{requirement_id}/verify
111
307
  `build_webhook_signature_header`, `verify_webhook_signature`,
112
308
  `verify_direct_request_payment_webhook`, and
113
309
  `parse_direct_request_payment_webhook_event`.
114
-
115
- `verifyDirectRequestPaymentWebhook` verifies the signature and parses the event
116
- in one call.
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.