@nehorai/payments 0.1.0 → 0.2.0

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,5 +1,5 @@
1
- import { k as PaymentProvider } from '../payment-types-68W-PlGg.cjs';
2
- export { A as AuthorizationResult, a as AuthorizePaymentParams, C as CapturePaymentParams, b as CaptureResult, c as CardBrand, d as CreatePaymentIntentParams, e as CurrencyConversion, P as PaymentAmount, f as PaymentError, g as PaymentErrorCode, h as PaymentIntentResult, i as PaymentMetadata, j as PaymentMethodType, l as ProviderHealthStatus, m as ProviderMetadata, R as RefundParams, n as RefundResult, T as TaxInvoiceStatus, o as TransactionType, V as VoidPaymentParams, p as VoidResult } from '../payment-types-68W-PlGg.cjs';
1
+ import { n as PaymentProvider } from '../payment-types-DUs8IALw.cjs';
2
+ export { A as AuthorizationResult, a as AuthorizePaymentParams, C as CancelSubscriptionParams, b as CancelSubscriptionResult, c as CapturePaymentParams, d as CaptureResult, e as CardBrand, f as CreatePaymentIntentParams, g as CreateSubscriptionParams, h as CurrencyConversion, P as PaymentAmount, i as PaymentError, j as PaymentErrorCode, k as PaymentIntentResult, l as PaymentMetadata, m as PaymentMethodType, o as ProviderHealthStatus, p as ProviderMetadata, R as RefundParams, q as RefundResult, S as SubscriptionInterval, r as SubscriptionResult, s as SubscriptionStatus, T as TaxInvoiceStatus, t as TransactionType, V as VoidPaymentParams, u as VoidResult } from '../payment-types-DUs8IALw.cjs';
3
3
  import { c as TransactionStatus } from '../state-machine-Cu6_qKnv.cjs';
4
4
  export { D as DEFAULT_AUTH_HOLD_DAYS, H as HOLD_STATES, S as SUCCESS_STATES, a as StateTransitionResult, T as TERMINAL_STATES, b as TransactionEvent, V as VALID_TRANSITIONS, d as attemptTransition, e as calculateCaptureDeadline, f as canCapture, g as canRefund, h as canTransition, i as canVoid, j as getNextStatus, k as isAuthorizationExpired, l as isHoldState, m as isSuccessState, n as isTerminalState } from '../state-machine-Cu6_qKnv.cjs';
5
5
 
@@ -1,5 +1,5 @@
1
- import { k as PaymentProvider } from '../payment-types-68W-PlGg.js';
2
- export { A as AuthorizationResult, a as AuthorizePaymentParams, C as CapturePaymentParams, b as CaptureResult, c as CardBrand, d as CreatePaymentIntentParams, e as CurrencyConversion, P as PaymentAmount, f as PaymentError, g as PaymentErrorCode, h as PaymentIntentResult, i as PaymentMetadata, j as PaymentMethodType, l as ProviderHealthStatus, m as ProviderMetadata, R as RefundParams, n as RefundResult, T as TaxInvoiceStatus, o as TransactionType, V as VoidPaymentParams, p as VoidResult } from '../payment-types-68W-PlGg.js';
1
+ import { n as PaymentProvider } from '../payment-types-DUs8IALw.js';
2
+ export { A as AuthorizationResult, a as AuthorizePaymentParams, C as CancelSubscriptionParams, b as CancelSubscriptionResult, c as CapturePaymentParams, d as CaptureResult, e as CardBrand, f as CreatePaymentIntentParams, g as CreateSubscriptionParams, h as CurrencyConversion, P as PaymentAmount, i as PaymentError, j as PaymentErrorCode, k as PaymentIntentResult, l as PaymentMetadata, m as PaymentMethodType, o as ProviderHealthStatus, p as ProviderMetadata, R as RefundParams, q as RefundResult, S as SubscriptionInterval, r as SubscriptionResult, s as SubscriptionStatus, T as TaxInvoiceStatus, t as TransactionType, V as VoidPaymentParams, u as VoidResult } from '../payment-types-DUs8IALw.js';
3
3
  import { c as TransactionStatus } from '../state-machine-Cu6_qKnv.js';
4
4
  export { D as DEFAULT_AUTH_HOLD_DAYS, H as HOLD_STATES, S as SUCCESS_STATES, a as StateTransitionResult, T as TERMINAL_STATES, b as TransactionEvent, V as VALID_TRANSITIONS, d as attemptTransition, e as calculateCaptureDeadline, f as canCapture, g as canRefund, h as canTransition, i as canVoid, j as getNextStatus, k as isAuthorizationExpired, l as isHoldState, m as isSuccessState, n as isTerminalState } from '../state-machine-Cu6_qKnv.js';
5
5
 
@@ -1,4 +1,4 @@
1
- import { k as PaymentProvider } from '../payment-types-68W-PlGg.cjs';
1
+ import { n as PaymentProvider } from '../payment-types-DUs8IALw.cjs';
2
2
 
3
3
  /**
4
4
  * @nehorai/payments - Idempotency Utilities
@@ -1,4 +1,4 @@
1
- import { k as PaymentProvider } from '../payment-types-68W-PlGg.js';
1
+ import { n as PaymentProvider } from '../payment-types-DUs8IALw.js';
2
2
 
3
3
  /**
4
4
  * @nehorai/payments - Idempotency Utilities
@@ -0,0 +1,79 @@
1
+ import { n as PaymentProvider } from './payment-types-DUs8IALw.js';
2
+ import { c as TransactionStatus } from './state-machine-Cu6_qKnv.js';
3
+ import { WebhookProcessingResult, ReconciliationResult } from './types/index.js';
4
+
5
+ /**
6
+ * @nehorai/payments - Webhook Handler Interface
7
+ *
8
+ * Defines the contract for processing incoming webhooks from payment providers.
9
+ * Handles idempotency, reconciliation, and event-to-action mapping.
10
+ */
11
+
12
+ /**
13
+ * Parsed webhook event with standardized fields
14
+ */
15
+ interface ParsedWebhookEvent {
16
+ /** Provider that sent the webhook */
17
+ provider: PaymentProvider;
18
+ /** Provider's unique event ID */
19
+ eventId: string;
20
+ /** Standardized event type */
21
+ eventType: string;
22
+ /** Associated payment intent/transaction ID */
23
+ providerTransactionId?: string;
24
+ /** Amount in minor units (if applicable) */
25
+ amountMinor?: number;
26
+ /** Currency (if applicable) */
27
+ currency?: string;
28
+ /** New status (if status change event) */
29
+ newStatus?: TransactionStatus;
30
+ /** Error details (if failure event) */
31
+ error?: {
32
+ code: string;
33
+ message: string;
34
+ };
35
+ /** Original timestamp from provider */
36
+ timestamp: Date;
37
+ /** Full raw payload */
38
+ rawPayload: Record<string, unknown>;
39
+ }
40
+ /**
41
+ * Result of parsing a webhook event
42
+ */
43
+ interface ParseWebhookResult {
44
+ success: boolean;
45
+ event?: ParsedWebhookEvent;
46
+ error?: string;
47
+ }
48
+ /**
49
+ * Handler function for a specific event type
50
+ */
51
+ type EventHandler = (event: ParsedWebhookEvent) => Promise<WebhookProcessingResult>;
52
+ /**
53
+ * Map of event types to handler functions
54
+ */
55
+ type EventHandlerMap = Map<string, EventHandler>;
56
+ /**
57
+ * Webhook Handler Interface
58
+ *
59
+ * Provider-specific webhook handlers implement this interface.
60
+ * Enables consistent webhook processing across all providers.
61
+ */
62
+ interface IWebhookHandler {
63
+ /**
64
+ * Provider this handler is for
65
+ */
66
+ readonly provider: PaymentProvider;
67
+ /**
68
+ * Event types this handler can process
69
+ */
70
+ readonly supportedEventTypes: readonly string[];
71
+ parseEvent(rawPayload: Record<string, unknown>): ParseWebhookResult;
72
+ processEvent(event: ParsedWebhookEvent): Promise<WebhookProcessingResult>;
73
+ canHandle(eventType: string): boolean;
74
+ reconcile(transactionId: string, providerTransactionId: string): Promise<ReconciliationResult>;
75
+ mapEventType(providerEventType: string): string;
76
+ mapStatus(providerStatus: string): TransactionStatus | null;
77
+ }
78
+
79
+ export type { EventHandler as E, IWebhookHandler as I, ParseWebhookResult as P, EventHandlerMap as a, ParsedWebhookEvent as b };
@@ -0,0 +1,79 @@
1
+ import { n as PaymentProvider } from './payment-types-DUs8IALw.cjs';
2
+ import { c as TransactionStatus } from './state-machine-Cu6_qKnv.cjs';
3
+ import { WebhookProcessingResult, ReconciliationResult } from './types/index.cjs';
4
+
5
+ /**
6
+ * @nehorai/payments - Webhook Handler Interface
7
+ *
8
+ * Defines the contract for processing incoming webhooks from payment providers.
9
+ * Handles idempotency, reconciliation, and event-to-action mapping.
10
+ */
11
+
12
+ /**
13
+ * Parsed webhook event with standardized fields
14
+ */
15
+ interface ParsedWebhookEvent {
16
+ /** Provider that sent the webhook */
17
+ provider: PaymentProvider;
18
+ /** Provider's unique event ID */
19
+ eventId: string;
20
+ /** Standardized event type */
21
+ eventType: string;
22
+ /** Associated payment intent/transaction ID */
23
+ providerTransactionId?: string;
24
+ /** Amount in minor units (if applicable) */
25
+ amountMinor?: number;
26
+ /** Currency (if applicable) */
27
+ currency?: string;
28
+ /** New status (if status change event) */
29
+ newStatus?: TransactionStatus;
30
+ /** Error details (if failure event) */
31
+ error?: {
32
+ code: string;
33
+ message: string;
34
+ };
35
+ /** Original timestamp from provider */
36
+ timestamp: Date;
37
+ /** Full raw payload */
38
+ rawPayload: Record<string, unknown>;
39
+ }
40
+ /**
41
+ * Result of parsing a webhook event
42
+ */
43
+ interface ParseWebhookResult {
44
+ success: boolean;
45
+ event?: ParsedWebhookEvent;
46
+ error?: string;
47
+ }
48
+ /**
49
+ * Handler function for a specific event type
50
+ */
51
+ type EventHandler = (event: ParsedWebhookEvent) => Promise<WebhookProcessingResult>;
52
+ /**
53
+ * Map of event types to handler functions
54
+ */
55
+ type EventHandlerMap = Map<string, EventHandler>;
56
+ /**
57
+ * Webhook Handler Interface
58
+ *
59
+ * Provider-specific webhook handlers implement this interface.
60
+ * Enables consistent webhook processing across all providers.
61
+ */
62
+ interface IWebhookHandler {
63
+ /**
64
+ * Provider this handler is for
65
+ */
66
+ readonly provider: PaymentProvider;
67
+ /**
68
+ * Event types this handler can process
69
+ */
70
+ readonly supportedEventTypes: readonly string[];
71
+ parseEvent(rawPayload: Record<string, unknown>): ParseWebhookResult;
72
+ processEvent(event: ParsedWebhookEvent): Promise<WebhookProcessingResult>;
73
+ canHandle(eventType: string): boolean;
74
+ reconcile(transactionId: string, providerTransactionId: string): Promise<ReconciliationResult>;
75
+ mapEventType(providerEventType: string): string;
76
+ mapStatus(providerStatus: string): TransactionStatus | null;
77
+ }
78
+
79
+ export type { EventHandler as E, IWebhookHandler as I, ParseWebhookResult as P, EventHandlerMap as a, ParsedWebhookEvent as b };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nehorai/payments",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Generic payment orchestration library with circuit breaker and multi-provider routing",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",