@siglume/direct-request-payment 0.4.7 → 0.4.8

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/dist/index.d.ts CHANGED
@@ -6,7 +6,11 @@ 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.7";
9
+ declare const DIRECT_REQUEST_PAYMENT_SDK_VERSION = "0.4.8";
10
+ declare const DIRECT_REQUEST_PAYMENT_STANDARD_SETTLED_STATUS = "settled";
11
+ declare const DIRECT_REQUEST_PAYMENT_METERED_ACCEPTED_STATUS = "pending_settlement";
12
+ declare const DIRECT_REQUEST_PAYMENT_STANDARD_FINALITY = "per_payment_onchain";
13
+ declare const DIRECT_REQUEST_PAYMENT_METERED_FINALITY = "aggregated_onchain_settlement";
10
14
  type DirectRequestPaymentCurrency = "JPY" | "USD";
11
15
  type DirectRequestPaymentToken = "JPYC" | "USDC";
12
16
  type DirectRequestPaymentMeteredPlanType = "micro" | "nano";
@@ -411,6 +415,47 @@ interface DirectRequestPaymentWebhookEvent {
411
415
  };
412
416
  [key: string]: unknown;
413
417
  }
418
+ type DirectPaymentConfirmationKind = "standard_settled" | "metered_usage_accepted" | "metered_batch_settled" | "unknown";
419
+ type DirectPaymentConfirmationUnknownReason = "not_direct_payment_confirmed" | "invalid_metered_settlement_confirmation" | "missing_standard_settlement_fields" | "missing_metered_usage_fields" | "unknown_confirmation_shape";
420
+ interface DirectPaymentStandardSettledClassification {
421
+ kind: "standard_settled";
422
+ event: DirectRequestPaymentWebhookEvent;
423
+ data: DirectRequestPaymentWebhookEvent["data"];
424
+ requirement_id: string;
425
+ challenge_hash: string;
426
+ chain_receipt_id: string;
427
+ request_hash_v2?: string | null;
428
+ }
429
+ interface DirectPaymentMeteredUsageAcceptedClassification {
430
+ kind: "metered_usage_accepted";
431
+ event: DirectRequestPaymentWebhookEvent;
432
+ data: DirectRequestPaymentWebhookEvent["data"];
433
+ pricing_band: DirectRequestPaymentMeteredPlanType;
434
+ requirement_id: string;
435
+ challenge_hash: string;
436
+ request_hash_v2?: string | null;
437
+ }
438
+ interface DirectPaymentMeteredBatchSettledClassification {
439
+ kind: "metered_batch_settled";
440
+ event: DirectRequestPaymentWebhookEvent;
441
+ data: DirectRequestPaymentWebhookEvent["data"];
442
+ settlement_batch_id: string;
443
+ chain_receipt_id: string;
444
+ usage_event_digest: string;
445
+ settled_at?: string | null;
446
+ }
447
+ interface DirectPaymentUnknownClassification {
448
+ kind: "unknown";
449
+ event: DirectRequestPaymentWebhookEvent;
450
+ data: DirectRequestPaymentWebhookEvent["data"];
451
+ reason: DirectPaymentConfirmationUnknownReason;
452
+ requirement_id?: string | null;
453
+ settlement_batch_id?: string | null;
454
+ pricing_band?: string | null;
455
+ settlement_status?: string | null;
456
+ finality?: string | null;
457
+ }
458
+ type DirectPaymentConfirmationClassification = DirectPaymentStandardSettledClassification | DirectPaymentMeteredUsageAcceptedClassification | DirectPaymentMeteredBatchSettledClassification | DirectPaymentUnknownClassification;
414
459
  declare class SiglumeDirectRequestPaymentError extends Error {
415
460
  constructor(message: string);
416
461
  }
@@ -562,6 +607,7 @@ declare function verifyWebhookSignature(signing_secret: string, body: Uint8Array
562
607
  now?: number;
563
608
  }): Promise<WebhookSignatureVerification>;
564
609
  declare function parseDirectRequestPaymentWebhookEvent(payload: unknown): DirectRequestPaymentWebhookEvent;
610
+ declare function classifyDirectPaymentConfirmation(event: DirectRequestPaymentWebhookEvent): DirectPaymentConfirmationClassification;
565
611
  declare function verifyDirectRequestPaymentWebhook(signing_secret: string, body: Uint8Array | ArrayBuffer | string | Record<string, unknown>, signature_header: string, options?: {
566
612
  tolerance_seconds?: number;
567
613
  now?: number;
@@ -574,4 +620,4 @@ declare const verifyExternal402Challenge: typeof verifyDirectRequestPaymentChall
574
620
  declare const createExternal402RecurringChallenge: typeof createDirectRequestPaymentRecurringChallenge;
575
621
  declare const verifyExternal402RecurringChallenge: typeof verifyDirectRequestPaymentRecurringChallenge;
576
622
 
577
- 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 };
623
+ export { DEFAULT_SIGLUME_API_BASE, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, DIRECT_REQUEST_PAYMENT_ALLOWANCE_RECEIPT_KIND, DIRECT_REQUEST_PAYMENT_CHALLENGE_SCHEME, DIRECT_REQUEST_PAYMENT_METERED_ACCEPTED_STATUS, DIRECT_REQUEST_PAYMENT_METERED_FINALITY, 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, DIRECT_REQUEST_PAYMENT_STANDARD_FINALITY, DIRECT_REQUEST_PAYMENT_STANDARD_SETTLED_STATUS, type DirectPaymentConfirmationClassification, type DirectPaymentConfirmationKind, type DirectPaymentConfirmationUnknownReason, type DirectPaymentMeteredBatchSettledClassification, type DirectPaymentMeteredUsageAcceptedClassification, type DirectPaymentRequirement, type DirectPaymentRequirementCreateInput, type DirectPaymentStandardSettledClassification, type DirectPaymentUnknownClassification, 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, classifyDirectPaymentConfirmation, computeWebhookSignature, createDirectRequestPaymentChallenge, createDirectRequestPaymentChallengeSignature, createDirectRequestPaymentRecurringChallenge, createDirectRequestPaymentRecurringChallengeSignature, createExternal402Challenge, createExternal402RecurringChallenge, directRequestPaymentChallengeHash, directRequestPaymentRequestHash, directRequestPaymentRequestHashV2, parseDirectRequestPaymentChallenge, parseDirectRequestPaymentWebhookEvent, verifyDirectRequestPaymentChallenge, verifyDirectRequestPaymentRecurringChallenge, verifyDirectRequestPaymentWebhook, verifyExternal402Challenge, verifyExternal402RecurringChallenge, verifyWebhookSignature };
package/dist/index.js CHANGED
@@ -7,7 +7,11 @@ 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.7";
10
+ var DIRECT_REQUEST_PAYMENT_SDK_VERSION = "0.4.8";
11
+ var DIRECT_REQUEST_PAYMENT_STANDARD_SETTLED_STATUS = "settled";
12
+ var DIRECT_REQUEST_PAYMENT_METERED_ACCEPTED_STATUS = "pending_settlement";
13
+ var DIRECT_REQUEST_PAYMENT_STANDARD_FINALITY = "per_payment_onchain";
14
+ var DIRECT_REQUEST_PAYMENT_METERED_FINALITY = "aggregated_onchain_settlement";
11
15
  var DIRECT_REQUEST_PAYMENT_CONFIRMED_WEBHOOK_MODES = /* @__PURE__ */ new Set([DIRECT_REQUEST_PAYMENT_MODE, "metered_settlement_batch"]);
12
16
  var SiglumeDirectRequestPaymentError = class extends Error {
13
17
  constructor(message) {
@@ -600,6 +604,112 @@ function parseDirectRequestPaymentWebhookEvent(payload) {
600
604
  }
601
605
  return parsed;
602
606
  }
607
+ function classifyDirectPaymentConfirmation(event) {
608
+ const data = event.data;
609
+ const requirementId = stringOrNull(data.requirement_id) ?? stringOrNull(data.direct_payment_requirement_id);
610
+ const challengeHash = stringOrNull(data.challenge_hash);
611
+ const pricingBand = stringOrNull(data.pricing_band);
612
+ const finality = stringOrNull(data.finality);
613
+ const settlementStatus = stringOrNull(data.settlement_status);
614
+ if (event.type !== "direct_payment.confirmed") {
615
+ return {
616
+ kind: "unknown",
617
+ event,
618
+ data,
619
+ reason: "not_direct_payment_confirmed",
620
+ requirement_id: requirementId,
621
+ settlement_batch_id: stringOrNull(data.settlement_batch_id),
622
+ pricing_band: pricingBand,
623
+ settlement_status: settlementStatus,
624
+ finality
625
+ };
626
+ }
627
+ if (data.mode === "metered_settlement_batch") {
628
+ const settlementBatchId = stringOrNull(data.settlement_batch_id);
629
+ const chainReceiptId = stringOrNull(data.chain_receipt_id);
630
+ const usageEventDigest = stringOrNull(data.usage_event_digest);
631
+ if (settlementStatus === DIRECT_REQUEST_PAYMENT_STANDARD_SETTLED_STATUS && settlementBatchId && chainReceiptId && usageEventDigest) {
632
+ return {
633
+ kind: "metered_batch_settled",
634
+ event,
635
+ data,
636
+ settlement_batch_id: settlementBatchId,
637
+ chain_receipt_id: chainReceiptId,
638
+ usage_event_digest: usageEventDigest,
639
+ settled_at: stringOrNull(data.settled_at)
640
+ };
641
+ }
642
+ return {
643
+ kind: "unknown",
644
+ event,
645
+ data,
646
+ reason: "invalid_metered_settlement_confirmation",
647
+ requirement_id: requirementId,
648
+ settlement_batch_id: settlementBatchId,
649
+ pricing_band: pricingBand,
650
+ settlement_status: settlementStatus,
651
+ finality
652
+ };
653
+ }
654
+ if (pricingBand === "standard") {
655
+ const chainReceiptId = stringOrNull(data.chain_receipt_id);
656
+ if (finality === DIRECT_REQUEST_PAYMENT_STANDARD_FINALITY && settlementStatus === DIRECT_REQUEST_PAYMENT_STANDARD_SETTLED_STATUS && requirementId && challengeHash && chainReceiptId) {
657
+ return {
658
+ kind: "standard_settled",
659
+ event,
660
+ data,
661
+ requirement_id: requirementId,
662
+ challenge_hash: challengeHash,
663
+ chain_receipt_id: chainReceiptId,
664
+ request_hash_v2: stringOrNull(data.request_hash_v2)
665
+ };
666
+ }
667
+ return {
668
+ kind: "unknown",
669
+ event,
670
+ data,
671
+ reason: "missing_standard_settlement_fields",
672
+ requirement_id: requirementId,
673
+ pricing_band: pricingBand,
674
+ settlement_status: settlementStatus,
675
+ finality
676
+ };
677
+ }
678
+ if (pricingBand === "micro" || pricingBand === "nano") {
679
+ if (finality === DIRECT_REQUEST_PAYMENT_METERED_FINALITY && settlementStatus === DIRECT_REQUEST_PAYMENT_METERED_ACCEPTED_STATUS && requirementId && challengeHash) {
680
+ return {
681
+ kind: "metered_usage_accepted",
682
+ event,
683
+ data,
684
+ pricing_band: pricingBand,
685
+ requirement_id: requirementId,
686
+ challenge_hash: challengeHash,
687
+ request_hash_v2: stringOrNull(data.request_hash_v2)
688
+ };
689
+ }
690
+ return {
691
+ kind: "unknown",
692
+ event,
693
+ data,
694
+ reason: "missing_metered_usage_fields",
695
+ requirement_id: requirementId,
696
+ pricing_band: pricingBand,
697
+ settlement_status: settlementStatus,
698
+ finality
699
+ };
700
+ }
701
+ return {
702
+ kind: "unknown",
703
+ event,
704
+ data,
705
+ reason: "unknown_confirmation_shape",
706
+ requirement_id: requirementId,
707
+ settlement_batch_id: stringOrNull(data.settlement_batch_id),
708
+ pricing_band: pricingBand,
709
+ settlement_status: settlementStatus,
710
+ finality
711
+ };
712
+ }
603
713
  async function verifyDirectRequestPaymentWebhook(signing_secret, body, signature_header, options = {}) {
604
714
  const verification = await verifyWebhookSignature(signing_secret, body, signature_header, options);
605
715
  const text = new TextDecoder().decode(bodyBytes(body));
@@ -948,11 +1058,15 @@ export {
948
1058
  DEFAULT_WEBHOOK_TOLERANCE_SECONDS,
949
1059
  DIRECT_REQUEST_PAYMENT_ALLOWANCE_RECEIPT_KIND,
950
1060
  DIRECT_REQUEST_PAYMENT_CHALLENGE_SCHEME,
1061
+ DIRECT_REQUEST_PAYMENT_METERED_ACCEPTED_STATUS,
1062
+ DIRECT_REQUEST_PAYMENT_METERED_FINALITY,
951
1063
  DIRECT_REQUEST_PAYMENT_MODE,
952
1064
  DIRECT_REQUEST_PAYMENT_RECEIPT_KIND,
953
1065
  DIRECT_REQUEST_PAYMENT_RECURRING_CHALLENGE_SCHEME,
954
1066
  DIRECT_REQUEST_PAYMENT_REFERENCE_TYPE,
955
1067
  DIRECT_REQUEST_PAYMENT_SDK_VERSION,
1068
+ DIRECT_REQUEST_PAYMENT_STANDARD_FINALITY,
1069
+ DIRECT_REQUEST_PAYMENT_STANDARD_SETTLED_STATUS,
956
1070
  DirectRequestPaymentClient,
957
1071
  DirectRequestPaymentMerchantClient,
958
1072
  HostedCheckoutNotAvailableError,
@@ -964,6 +1078,7 @@ export {
964
1078
  buildPaymentExecutionPayload,
965
1079
  buildPreparedTransactionExecutionPayload,
966
1080
  buildWebhookSignatureHeader,
1081
+ classifyDirectPaymentConfirmation,
967
1082
  computeWebhookSignature,
968
1083
  createDirectRequestPaymentChallenge,
969
1084
  createDirectRequestPaymentChallengeSignature,