@siglume/direct-request-payment 0.4.2 → 0.4.4

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.
@@ -267,7 +267,15 @@ Returns the `sha256:`-prefixed hash for an existing challenge string.
267
267
  ## `directRequestPaymentRequestHash(input)` / `direct_request_payment_request_hash(...)`
268
268
 
269
269
  Returns the SDK-side request hash material for merchant, amount, currency, and
270
- challenge. This is mostly useful for tests and internal assertions.
270
+ challenge. This is the legacy v1 hash retained for wire compatibility and
271
+ existing idempotency assertions.
272
+
273
+ ## `directRequestPaymentRequestHashV2(input)` / `direct_request_payment_request_hash_v2(...)`
274
+
275
+ Returns the v2 request hash for the same fields using canonical JSON before
276
+ hashing. New tests and server-side assertions should prefer this value when the
277
+ API response includes `request_hash_v2`; keep accepting `request_hash` for older
278
+ requirements and historical webhook payloads.
271
279
 
272
280
  ## `DirectRequestPaymentMerchantClient`
273
281
 
@@ -308,8 +316,10 @@ Input:
308
316
  Hosted Checkout (open-redirect defense). A Hosted Checkout `success_url` /
309
317
  `cancel_url` must be on a registered origin; the origin of
310
318
  `webhook_callback_url` is auto-allowed in addition. Each entry must be an
311
- absolute origin such as `https://shop.example.com`; entries are normalized to
312
- bare, lowercased origins and deduped.
319
+ absolute origin such as `https://shop.example.com`; production origins must
320
+ use `https`. Development `http` origins are accepted only for `localhost`,
321
+ `127.0.0.1`, or `[::1]`. Userinfo is rejected. Entries are normalized to bare,
322
+ lowercased origins and deduped.
313
323
 
314
324
  In addition to the `setupMerchant` inputs above, `setupCheckout` accepts these
315
325
  orchestration toggles:
@@ -371,7 +381,7 @@ POST /v1/sdrp/direct-payments/checkout-sessions
371
381
  ```ts
372
382
  const session = await merchant.createCheckoutSession({
373
383
  merchant: "example_merchant",
374
- amount_minor: 500,
384
+ amount_minor: 1200,
375
385
  currency: "JPY",
376
386
  nonce: order.id,
377
387
  success_url: "https://www.your-shop.com/thanks",
@@ -383,7 +393,7 @@ const session = await merchant.createCheckoutSession({
383
393
  ```py
384
394
  session = merchant.create_checkout_session(
385
395
  merchant="example_merchant",
386
- amount_minor=500,
396
+ amount_minor=1200,
387
397
  currency="JPY",
388
398
  nonce=order["id"],
389
399
  success_url="https://www.your-shop.com/thanks",
@@ -500,11 +510,15 @@ Use it with the authenticated buyer's Siglume bearer token. Developer Portal
500
510
 
501
511
  This client creates SDRP Standard Payment requirements for external merchant
502
512
  checkout flows. Micro Payment and Nano Payment are applied automatically by
503
- amount and settled on a weekly / monthly cadence; they are not created explicitly
504
- through this client.
513
+ amount and settled on account-assigned weekly / monthly slots; they are not
514
+ created explicitly through this client. Use the statement APIs below to see
515
+ open-period usage, the close time, the final-notice schedule, and settled /
516
+ unsettled / past-due revenue.
505
517
 
506
- Payment requirements include `fee_bps` from the Siglume platform. The SDK does
507
- not calculate merchant plan fees locally; see [Pricing](./pricing.md).
518
+ Standard Payment requirements include `fee_bps` from the Siglume platform. The
519
+ SDK does not calculate merchant plan fees locally. For Micro / Nano, use the
520
+ statement API amount fields (`protocol_fee_minor`, `gross_buyer_debit_minor`,
521
+ `buyer_debit_minor`, and `rounding_delta_minor`); see [Pricing](./pricing.md).
508
522
 
509
523
  ```ts
510
524
  const siglume = new DirectRequestPaymentClient({
@@ -542,6 +556,22 @@ Input:
542
556
  - `allowance_amount_minor`: optional positive integer
543
557
  - `metadata`: optional JSON object
544
558
 
559
+ The returned requirement includes both compatibility and machine-readable
560
+ settlement fields:
561
+
562
+ - `request_hash`: legacy v1 request hash, retained for existing requirements
563
+ and integrations.
564
+ - `request_hash_v2`: canonical-JSON v2 request hash when the server can compute
565
+ one for the challenge-backed request.
566
+ - `pricing_band`: `standard`, `micro`, or `nano`.
567
+ - `settlement_cadence`: `per_payment`, `weekly`, or `monthly`.
568
+ - `finality`: machine-readable finality class such as
569
+ `per_payment_onchain` or `aggregated_onchain_settlement`.
570
+ - `protocol_fee_minor`: Micro / Nano protocol fee when applicable; `null` for
571
+ Standard Payment.
572
+ - `settlement_status`: `pending_payment`, `provisional`, `settled`,
573
+ `pending_settlement`, or another explicit operational state.
574
+
545
575
  ### `getPaymentRequirement(requirement_id)` / `get_payment_requirement(requirement_id)`
546
576
 
547
577
  Calls:
@@ -629,6 +659,191 @@ Input may include:
629
659
  - `await_timeout_seconds`
630
660
  - `await_poll_seconds`
631
661
 
662
+ ### `request<T>(method, path, json_body?)` (TypeScript only)
663
+
664
+ Calls an authenticated Siglume JSON endpoint using the same bearer token and
665
+ base URL configured on `DirectRequestPaymentClient`.
666
+
667
+ `path` is the API path after `/v1`, for example
668
+ `/sdrp/metered/my-summary`. The helper expects a JSON response. Use raw
669
+ `fetch`, `curl`, or your HTTP client for CSV exports.
670
+
671
+ Python does not expose a public generic request helper. Use the named Python
672
+ methods documented below for Micro / Nano statements, and ordinary HTTPS
673
+ requests for endpoints that do not yet have a named Python SDK method.
674
+
675
+ ## Metered Statement APIs
676
+
677
+ Micro Payment and Nano Payment require operational reconciliation after usage is
678
+ accepted. The immediate requirement response does not tell a merchant how much
679
+ is settled, when the batch can first debit, or why a buyer is past due.
680
+
681
+ See the full operating guide:
682
+ [Micro / Nano Statements and Notices](./metered-statements.md).
683
+
684
+ ### Buyer summary
685
+
686
+ ```text
687
+ GET /v1/sdrp/metered/my-summary
688
+ ```
689
+
690
+ Common query parameters:
691
+
692
+ - `plan_type`: `micro` or `nano`
693
+ - `token_symbol`: `JPYC` or `USDC`
694
+
695
+ TypeScript:
696
+
697
+ ```ts
698
+ const summary = await siglume.getBuyerMeteredSummary({
699
+ plan_type: "micro",
700
+ token_symbol: "JPYC",
701
+ });
702
+ ```
703
+
704
+ Python:
705
+
706
+ ```py
707
+ summary = siglume.get_buyer_metered_summary(plan_type="micro", token_symbol="JPYC")
708
+ ```
709
+
710
+ Use `open_periods` for current-period estimated debit,
711
+ `settlement_batches` for closed / scheduled / settled periods, and
712
+ `past_due_blocks` to explain `METERED_SETTLEMENT_PAST_DUE`.
713
+
714
+ ### Buyer usage and settlement lists
715
+
716
+ ```text
717
+ GET /v1/sdrp/metered/my-usage-events
718
+ GET /v1/sdrp/metered/my-settlement-batches
719
+ ```
720
+
721
+ SDK methods:
722
+
723
+ - TypeScript: `listBuyerUsageEvents(...)`, `listBuyerSettlementBatches(...)`
724
+ - Python: `list_buyer_usage_events(...)`, `list_buyer_settlement_batches(...)`
725
+
726
+ Each accepts `plan_type`, `token_symbol`, `status`, and `limit`, and returns
727
+ `{items, next_cursor}`.
728
+
729
+ Buyer-facing amount names are centered on the debit:
730
+
731
+ - `estimated_buyer_debit_minor`
732
+ - `provider_usage_amount_minor`
733
+ - `gross_buyer_debit_minor`
734
+ - `buyer_debit_minor`
735
+ - `protocol_fee_minor`
736
+
737
+ ### Provider summary
738
+
739
+ ```text
740
+ GET /v1/sdrp/metered/provider/summary
741
+ ```
742
+
743
+ Common query parameters:
744
+
745
+ - `plan_type`: `micro` or `nano`
746
+ - `token_symbol`: `JPYC` or `USDC`
747
+ - `listing_id`
748
+ - `capability_key`
749
+
750
+ TypeScript:
751
+
752
+ ```ts
753
+ const providerSummary = await siglume.getProviderMeteredSummary({
754
+ plan_type: "micro",
755
+ token_symbol: "JPYC",
756
+ });
757
+ ```
758
+
759
+ Python:
760
+
761
+ ```py
762
+ provider_summary = siglume.get_provider_metered_summary(plan_type="micro", token_symbol="JPYC")
763
+ ```
764
+
765
+ Use `open_periods` for current-period expected revenue, `periods` for closed
766
+ and historical batches, and `totals` to separate settled, unsettled, and
767
+ past-due provider amounts. Do not recognize Micro / Nano revenue until the batch
768
+ is `settled` and has an on-chain receipt.
769
+
770
+ ### Provider usage and settlement detail
771
+
772
+ ```text
773
+ GET /v1/sdrp/metered/provider/usage-events
774
+ GET /v1/sdrp/metered/provider/settlement-batches
775
+ GET /v1/sdrp/metered/provider/settlement-batches/{settlement_batch_id}
776
+ ```
777
+
778
+ SDK methods:
779
+
780
+ - TypeScript: `listProviderUsageEvents(...)`,
781
+ `listProviderSettlementBatches(...)`, `getProviderSettlementBatch(...)`
782
+ - Python: `list_provider_usage_events(...)`,
783
+ `list_provider_settlement_batches(...)`, `get_provider_settlement_batch(...)`
784
+
785
+ Provider list methods accept `plan_type`, `token_symbol`, `status`,
786
+ `listing_id`, `capability_key`, and `limit`. Detail accepts
787
+ `settlement_batch_id`, plus optional `listing_id` and `capability_key`. List
788
+ methods return `{items, next_cursor}`.
789
+
790
+ Provider-facing amount names:
791
+
792
+ - `provider_receivable_minor`
793
+ - `gross_buyer_debit_minor`
794
+ - `buyer_debit_minor`
795
+ - `protocol_fee_minor`
796
+ - `settled_provider_receivable_minor`
797
+ - `unsettled_provider_receivable_minor`
798
+ - `past_due_provider_receivable_minor`
799
+
800
+ Schedule and execution fields:
801
+
802
+ - `period_start`, `period_end`, `close_at`
803
+ - `expected_scheduled_debit_at`
804
+ - `scheduled_debit_at`
805
+ - `not_before_attempt_at`
806
+ - `execution_status`
807
+ - `latest_execution_attempt_status`
808
+ - `chain_receipt_id`
809
+ - `usage_event_digest`
810
+ - `attempt_count`
811
+ - `next_attempt_at`
812
+
813
+ Failure fields are sanitized for public display:
814
+
815
+ - `failure_reason_code`
816
+ - `failure_reason_label`
817
+ - `failure_reason_help`
818
+ - `support_reference`
819
+
820
+ Provider APIs do not expose raw `buyer_user_id`, buyer email, buyer wallet
821
+ address, relayer id, nonce, gas data, raw RPC errors, or raw
822
+ `failure_message`. Use `buyer_period_ref` for provider-side reconciliation
823
+ within a period.
824
+
825
+ ### Provider CSV export
826
+
827
+ ```text
828
+ GET /v1/sdrp/metered/provider/settlement-batches/{settlement_batch_id}/usage-events.csv
829
+ ```
830
+
831
+ The CSV is not JSON. Fetch it with raw `fetch`, `curl`, or your HTTP client:
832
+
833
+ ```bash
834
+ curl https://siglume.com/v1/sdrp/metered/provider/settlement-batches/<batch-id>/usage-events.csv \
835
+ -H "Authorization: Bearer <provider-siglume-bearer-token>" \
836
+ -o sdrp-metered.csv
837
+ ```
838
+
839
+ Columns:
840
+
841
+ ```text
842
+ metered_usage_id,created_at,plan_type,settlement_cadence,period_start,period_end,listing_id,capability_key,operation_key,currency,token_symbol,provider_receivable_minor,protocol_fee_minor,gross_buyer_debit_minor,rounding_delta_minor,buyer_debit_minor,status,settlement_batch_id,buyer_period_ref
843
+ ```
844
+
845
+ The CSV uses `buyer_period_ref`, not raw buyer account identifiers.
846
+
632
847
  ## Payload Builders
633
848
 
634
849
  These pure functions build the `execute-prepared` payload from a payment
@@ -698,8 +913,17 @@ Returns `{ timestamp, signature }`.
698
913
  Validates and normalizes a parsed webhook event object (requires `id`, `type`,
699
914
  `api_version`, `occurred_at`, and an object `data`). Throws
700
915
  `SiglumeWebhookPayloadError` on a malformed event, or when a
701
- `direct_payment.confirmed` event does not carry `data.mode = "external_402"`. The
702
- `payload` argument is positional in both languages.
916
+ `direct_payment.confirmed` event does not carry a supported Direct Request
917
+ Payment mode (`external_402` or `metered_settlement_batch`). The `payload`
918
+ argument is positional in both languages.
919
+
920
+ For `direct_payment.confirmed`, inspect `event.data.pricing_band`,
921
+ `event.data.settlement_cadence`, `event.data.finality`,
922
+ `event.data.protocol_fee_minor`, and `event.data.settlement_status` instead of
923
+ inferring whether the event means per-payment on-chain confirmation or an
924
+ aggregated Micro / Nano settlement confirmation. `event.data.request_hash_v2`
925
+ is present on new challenge-backed requirements; keep accepting
926
+ `event.data.request_hash` for historical payloads.
703
927
 
704
928
  ### `verifyDirectRequestPaymentWebhook(secret, body, signature_header, options)` / `verify_direct_request_payment_webhook(secret, body, signature_header, *, tolerance_seconds=300, now=None)`
705
929
 
@@ -746,6 +970,7 @@ Both packages export these importable constants:
746
970
  | `DIRECT_REQUEST_PAYMENT_ALLOWANCE_RECEIPT_KIND` | `sdrp_direct_payment_allowance` |
747
971
  | `DIRECT_REQUEST_PAYMENT_REFERENCE_TYPE` | `sdrp_direct_payment_requirement` |
748
972
  | `DEFAULT_WEBHOOK_TOLERANCE_SECONDS` | `300` |
973
+ | `DIRECT_REQUEST_PAYMENT_SDK_VERSION` | package version string |
749
974
 
750
975
  The `external_402` / `siglume-external-402-*` values are legacy wire-compat
751
976
  identifiers, not public product names (see the README "Compatibility Notes").
@@ -14,11 +14,13 @@ external merchant.
14
14
  The merchant server must not create charges with a customer wallet. It signs the
15
15
  order challenge; the buyer-facing Siglume payment flow pays it.
16
16
 
17
- This quickstart is for SDRP Standard Payment in an external merchant product.
18
- Micro Payment and Nano Payment are applied automatically by amount and settled on
19
- a weekly / monthly cadence (see [Pricing](./pricing.md#settlement-schedule)); they
20
- are not browser checkout requirements you create with this SDK. Their provider
21
- revenue remains unsettled until the later on-chain settlement succeeds.
17
+ This quickstart uses Standard-band example amounts. Micro Payment and Nano
18
+ Payment are applied automatically by amount through the same Hosted Checkout or
19
+ agent/API flow; you do not create a separate Micro/Nano object or pass a
20
+ "force Standard" flag. Micro/Nano are settled on account-assigned weekly /
21
+ monthly slots after the final notice and close-plus-3-day window (see
22
+ [Pricing](./pricing.md#settlement-schedule)), and provider revenue remains
23
+ unsettled until the later on-chain settlement succeeds.
22
24
 
23
25
  ## Two Buyer Systems
24
26
 
@@ -73,7 +75,7 @@ await merchant.setupCheckout({
73
75
  // Per order: create a session and redirect the shopper to checkout_url.
74
76
  const session = await merchant.createCheckoutSession({
75
77
  merchant: "example_merchant",
76
- amount_minor: 500, // server-fixed; the browser cannot change it
78
+ amount_minor: 1200, // server-fixed; the browser cannot change it
77
79
  currency: "JPY",
78
80
  nonce: order.id, // unique per order
79
81
  success_url: "https://www.example.com/thanks",
@@ -113,7 +115,7 @@ merchant.setup_checkout(
113
115
  # Per order: create a session and redirect the shopper to checkout_url.
114
116
  session = merchant.create_checkout_session(
115
117
  merchant="example_merchant",
116
- amount_minor=500, # server-fixed; the browser cannot change it
118
+ amount_minor=1200, # server-fixed; the browser cannot change it
117
119
  currency="JPY",
118
120
  nonce=order["id"], # unique per order
119
121
  success_url="https://www.example.com/thanks",
@@ -430,6 +432,59 @@ if verified["event"]["type"] == "direct_payment.confirmed":
430
432
  )
431
433
  ```
432
434
 
435
+ ## Reconcile Micro / Nano Statements
436
+
437
+ Standard Payment can be fulfilled from the verified
438
+ `direct_payment.confirmed` webhook. Micro Payment and Nano Payment are different:
439
+ they are automatic amount bands and are settled later in aggregated on-chain
440
+ batches. Use the statement APIs to answer:
441
+
442
+ - how much Micro / Nano usage is open this week or month,
443
+ - when the buyer's assigned period closes,
444
+ - when Siglume may first attempt the debit (`not_before_attempt_at`),
445
+ - how much provider revenue is settled, unsettled, retrying, or past due.
446
+
447
+ Provider summary:
448
+
449
+ ```ts
450
+ import { DirectRequestPaymentClient } from "@siglume/direct-request-payment";
451
+
452
+ const siglume = new DirectRequestPaymentClient({
453
+ auth_token: providerSiglumeBearerToken,
454
+ });
455
+
456
+ const summary = await siglume.getProviderMeteredSummary({
457
+ plan_type: "micro",
458
+ token_symbol: "JPYC",
459
+ });
460
+
461
+ console.log(summary.totals.settled_provider_receivable_minor);
462
+ console.log(summary.totals.unsettled_provider_receivable_minor);
463
+ console.log(summary.totals.past_due_provider_receivable_minor);
464
+ ```
465
+
466
+ Line-level CSV export:
467
+
468
+ ```bash
469
+ curl https://siglume.com/v1/sdrp/metered/provider/settlement-batches/<batch-id>/usage-events.csv \
470
+ -H "Authorization: Bearer <provider-siglume-bearer-token>" \
471
+ -o sdrp-metered.csv
472
+ ```
473
+
474
+ Python exposes the same named helper:
475
+
476
+ ```py
477
+ from siglume_direct_request_payment import DirectRequestPaymentClient
478
+
479
+ siglume = DirectRequestPaymentClient(auth_token=provider_siglume_bearer_token)
480
+ summary = siglume.get_provider_metered_summary(plan_type="micro", token_symbol="JPYC")
481
+ ```
482
+
483
+ Do not book Micro / Nano provider revenue as settled revenue until the batch is
484
+ `settled` and `chain_receipt_id` is present. See
485
+ [Micro / Nano Statements and Notices](./metered-statements.md) for the full
486
+ manual, including buyer past-due blocks and public failure fields.
487
+
433
488
  ## Failure Handling
434
489
 
435
490
  - `EXTERNAL_402_CHALLENGE_REQUIRED`: the merchant server did not provide a
@@ -465,3 +520,6 @@ if verified["event"]["type"] == "direct_payment.confirmed":
465
520
  - Nonces cannot be reused for separate order attempts.
466
521
  - The order is fulfilled only after a verified webhook maps back to the stored
467
522
  `challenge_hash`.
523
+ - Micro / Nano accounting reads statement APIs or CSV and keeps settled,
524
+ unsettled, and past-due revenue separate.
525
+ - Micro / Nano provider revenue is not recognized before on-chain settlement.