@nehorai/payments 0.1.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.
- package/LICENSE +21 -0
- package/dist/config/index.cjs +116 -0
- package/dist/config/index.cjs.map +1 -0
- package/dist/config/index.d.cts +125 -0
- package/dist/config/index.d.ts +125 -0
- package/dist/config/index.js +83 -0
- package/dist/config/index.js.map +1 -0
- package/dist/factory.cjs +807 -0
- package/dist/factory.cjs.map +1 -0
- package/dist/factory.d.cts +96 -0
- package/dist/factory.d.ts +96 -0
- package/dist/factory.js +777 -0
- package/dist/factory.js.map +1 -0
- package/dist/index.cjs +1341 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +40 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.js +1260 -0
- package/dist/index.js.map +1 -0
- package/dist/payment-orchestrator-CPaLmDM5.d.ts +404 -0
- package/dist/payment-orchestrator-Co_X6T_V.d.cts +404 -0
- package/dist/payment-types-68W-PlGg.d.cts +211 -0
- package/dist/payment-types-68W-PlGg.d.ts +211 -0
- package/dist/providers/interfaces/index.cjs +19 -0
- package/dist/providers/interfaces/index.cjs.map +1 -0
- package/dist/providers/interfaces/index.d.cts +80 -0
- package/dist/providers/interfaces/index.d.ts +80 -0
- package/dist/providers/interfaces/index.js +1 -0
- package/dist/providers/interfaces/index.js.map +1 -0
- package/dist/repository/interfaces/index.cjs +19 -0
- package/dist/repository/interfaces/index.cjs.map +1 -0
- package/dist/repository/interfaces/index.d.cts +556 -0
- package/dist/repository/interfaces/index.d.ts +556 -0
- package/dist/repository/interfaces/index.js +1 -0
- package/dist/repository/interfaces/index.js.map +1 -0
- package/dist/routing-engine.interface-DJzGXor9.d.cts +194 -0
- package/dist/routing-engine.interface-h9_GmQ4b.d.ts +194 -0
- package/dist/services/index.cjs +806 -0
- package/dist/services/index.cjs.map +1 -0
- package/dist/services/index.d.cts +75 -0
- package/dist/services/index.d.ts +75 -0
- package/dist/services/index.js +763 -0
- package/dist/services/index.js.map +1 -0
- package/dist/state-machine-Cu6_qKnv.d.cts +109 -0
- package/dist/state-machine-Cu6_qKnv.d.ts +109 -0
- package/dist/types/index.cjs +173 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.d.cts +127 -0
- package/dist/types/index.d.ts +127 -0
- package/dist/types/index.js +130 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/index.cjs +167 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +102 -0
- package/dist/utils/index.d.ts +102 -0
- package/dist/utils/index.js +127 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { k as PaymentProvider, d as CreatePaymentIntentParams, h as PaymentIntentResult, a as AuthorizePaymentParams, A as AuthorizationResult, C as CapturePaymentParams, b as CaptureResult, V as VoidPaymentParams, p as VoidResult, R as RefundParams, n as RefundResult, l as ProviderHealthStatus, P as PaymentAmount } from './payment-types-68W-PlGg.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @nehorai/payments - Payment Provider Interface
|
|
5
|
+
*
|
|
6
|
+
* Defines the contract that all payment provider adapters must implement.
|
|
7
|
+
* Supports Two-Phase Commit (J5) pattern: Authorize -> Capture/Void
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Parameters for saving a payment method
|
|
12
|
+
*/
|
|
13
|
+
interface SavePaymentMethodParams {
|
|
14
|
+
userId: string;
|
|
15
|
+
/** Provider-specific setup data (e.g., SetupIntent confirmation) */
|
|
16
|
+
setupData: Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Result of saving a payment method
|
|
20
|
+
*/
|
|
21
|
+
interface SavePaymentMethodResult {
|
|
22
|
+
success: boolean;
|
|
23
|
+
paymentMethodId?: string;
|
|
24
|
+
cardBrand?: string;
|
|
25
|
+
cardLast4?: string;
|
|
26
|
+
cardExpMonth?: string;
|
|
27
|
+
cardExpYear?: string;
|
|
28
|
+
cardBin?: string;
|
|
29
|
+
error?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Result of deleting a payment method
|
|
33
|
+
*/
|
|
34
|
+
interface DeletePaymentMethodResult {
|
|
35
|
+
success: boolean;
|
|
36
|
+
error?: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Parameters for creating a setup intent
|
|
40
|
+
*/
|
|
41
|
+
interface CreateSetupIntentParams {
|
|
42
|
+
userId: string;
|
|
43
|
+
/** Customer ID in provider system */
|
|
44
|
+
customerId?: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Result of creating a setup intent
|
|
48
|
+
*/
|
|
49
|
+
interface SetupIntentResult {
|
|
50
|
+
success: boolean;
|
|
51
|
+
setupIntentId?: string;
|
|
52
|
+
clientSecret?: string;
|
|
53
|
+
error?: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Parameters for creating a customer
|
|
57
|
+
*/
|
|
58
|
+
interface CreateCustomerParams {
|
|
59
|
+
userId: string;
|
|
60
|
+
email: string;
|
|
61
|
+
name?: string;
|
|
62
|
+
metadata?: Record<string, string>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Result of creating a customer
|
|
66
|
+
*/
|
|
67
|
+
interface CreateCustomerResult {
|
|
68
|
+
success: boolean;
|
|
69
|
+
customerId?: string;
|
|
70
|
+
error?: string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Payment Provider Interface
|
|
74
|
+
*
|
|
75
|
+
* All payment provider adapters must implement this interface.
|
|
76
|
+
* Enables the adapter pattern for multi-provider support.
|
|
77
|
+
*/
|
|
78
|
+
interface IPaymentProvider {
|
|
79
|
+
/**
|
|
80
|
+
* Provider identifier
|
|
81
|
+
*/
|
|
82
|
+
readonly name: PaymentProvider;
|
|
83
|
+
/**
|
|
84
|
+
* Supported currencies (ISO 4217 codes)
|
|
85
|
+
*/
|
|
86
|
+
readonly supportedCurrencies: readonly string[];
|
|
87
|
+
/**
|
|
88
|
+
* Whether provider supports recurring billing
|
|
89
|
+
*/
|
|
90
|
+
readonly supportsRecurring: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Whether provider supports split payments (marketplace)
|
|
93
|
+
*/
|
|
94
|
+
readonly supportsSplitPayments: boolean;
|
|
95
|
+
createPaymentIntent(params: CreatePaymentIntentParams): Promise<PaymentIntentResult>;
|
|
96
|
+
authorize(params: AuthorizePaymentParams): Promise<AuthorizationResult>;
|
|
97
|
+
capture(params: CapturePaymentParams): Promise<CaptureResult>;
|
|
98
|
+
void(params: VoidPaymentParams): Promise<VoidResult>;
|
|
99
|
+
refund(params: RefundParams): Promise<RefundResult>;
|
|
100
|
+
createSetupIntent(params: CreateSetupIntentParams): Promise<SetupIntentResult>;
|
|
101
|
+
savePaymentMethod(params: SavePaymentMethodParams): Promise<SavePaymentMethodResult>;
|
|
102
|
+
deletePaymentMethod(paymentMethodId: string): Promise<DeletePaymentMethodResult>;
|
|
103
|
+
createCustomer(params: CreateCustomerParams): Promise<CreateCustomerResult>;
|
|
104
|
+
getOrCreateCustomer(userId: string, email: string): Promise<CreateCustomerResult>;
|
|
105
|
+
getHealth(): Promise<ProviderHealthStatus>;
|
|
106
|
+
validateWebhookSignature(payload: string, signature: string): boolean;
|
|
107
|
+
getPaymentIntentStatus(providerIntentId: string): Promise<{
|
|
108
|
+
status: string;
|
|
109
|
+
error?: string;
|
|
110
|
+
}>;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* @nehorai/payments - Routing Engine Interface
|
|
115
|
+
*
|
|
116
|
+
* Defines the contract for intelligent payment routing.
|
|
117
|
+
* Routes transactions to optimal providers based on:
|
|
118
|
+
* - Card BIN rules (configurable per deployment)
|
|
119
|
+
* - Provider health and availability
|
|
120
|
+
* - Transaction fees
|
|
121
|
+
* - Currency support
|
|
122
|
+
*/
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Context for making routing decisions
|
|
126
|
+
*/
|
|
127
|
+
interface RoutingContext {
|
|
128
|
+
/** User making the payment */
|
|
129
|
+
userId: string;
|
|
130
|
+
/** Payment amount and currency */
|
|
131
|
+
amount: PaymentAmount;
|
|
132
|
+
/** Card BIN (first 6-8 digits) for card type detection */
|
|
133
|
+
cardBin?: string;
|
|
134
|
+
/** User's country (ISO 2-letter code) */
|
|
135
|
+
userCountry?: string;
|
|
136
|
+
/** User's preferred provider (if any) */
|
|
137
|
+
preferredProvider?: PaymentProvider;
|
|
138
|
+
/** Whether this is a recurring payment */
|
|
139
|
+
isRecurring: boolean;
|
|
140
|
+
/** Saved payment method ID (if using saved method) */
|
|
141
|
+
savedPaymentMethodId?: string;
|
|
142
|
+
/** Provider of saved payment method */
|
|
143
|
+
savedPaymentMethodProvider?: PaymentProvider;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Result of routing decision
|
|
147
|
+
*/
|
|
148
|
+
interface RoutingDecision {
|
|
149
|
+
/** Selected provider */
|
|
150
|
+
provider: PaymentProvider;
|
|
151
|
+
/** Reason for selection */
|
|
152
|
+
reason: string;
|
|
153
|
+
/** Fallback providers in order of priority */
|
|
154
|
+
fallbackProviders: PaymentProvider[];
|
|
155
|
+
/** Estimated transaction fee percentage */
|
|
156
|
+
estimatedFeePercent: number;
|
|
157
|
+
/** Additional routing metadata */
|
|
158
|
+
metadata?: {
|
|
159
|
+
matchedBinRule?: boolean;
|
|
160
|
+
cardIssuer?: string;
|
|
161
|
+
cardCountry?: string;
|
|
162
|
+
primaryProviderUnavailable?: boolean;
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Routing Engine Interface
|
|
167
|
+
*
|
|
168
|
+
* Implementations of this interface handle intelligent routing
|
|
169
|
+
* of payments to optimal providers.
|
|
170
|
+
*/
|
|
171
|
+
interface IRoutingEngine {
|
|
172
|
+
/**
|
|
173
|
+
* Determine optimal provider for a transaction
|
|
174
|
+
*/
|
|
175
|
+
route(context: RoutingContext): Promise<RoutingDecision>;
|
|
176
|
+
/**
|
|
177
|
+
* Get next provider after a failure
|
|
178
|
+
*/
|
|
179
|
+
getFailoverProvider(failedProvider: PaymentProvider, context: RoutingContext): Promise<PaymentProvider | null>;
|
|
180
|
+
/**
|
|
181
|
+
* Check if a card BIN matches a configured rule
|
|
182
|
+
*/
|
|
183
|
+
matchCardBin(bin: string): boolean;
|
|
184
|
+
/**
|
|
185
|
+
* Get all available (healthy) providers
|
|
186
|
+
*/
|
|
187
|
+
getAvailableProviders(): Promise<PaymentProvider[]>;
|
|
188
|
+
/**
|
|
189
|
+
* Get provider recommendation without full context
|
|
190
|
+
*/
|
|
191
|
+
getQuickRecommendation(currency: string, isRecurring: boolean): Promise<PaymentProvider | null>;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export type { CreateCustomerParams as C, DeletePaymentMethodResult as D, IPaymentProvider as I, RoutingContext as R, SavePaymentMethodParams as S, CreateCustomerResult as a, CreateSetupIntentParams as b, IRoutingEngine as c, RoutingDecision as d, SavePaymentMethodResult as e, SetupIntentResult as f };
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { k as PaymentProvider, d as CreatePaymentIntentParams, h as PaymentIntentResult, a as AuthorizePaymentParams, A as AuthorizationResult, C as CapturePaymentParams, b as CaptureResult, V as VoidPaymentParams, p as VoidResult, R as RefundParams, n as RefundResult, l as ProviderHealthStatus, P as PaymentAmount } from './payment-types-68W-PlGg.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @nehorai/payments - Payment Provider Interface
|
|
5
|
+
*
|
|
6
|
+
* Defines the contract that all payment provider adapters must implement.
|
|
7
|
+
* Supports Two-Phase Commit (J5) pattern: Authorize -> Capture/Void
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Parameters for saving a payment method
|
|
12
|
+
*/
|
|
13
|
+
interface SavePaymentMethodParams {
|
|
14
|
+
userId: string;
|
|
15
|
+
/** Provider-specific setup data (e.g., SetupIntent confirmation) */
|
|
16
|
+
setupData: Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Result of saving a payment method
|
|
20
|
+
*/
|
|
21
|
+
interface SavePaymentMethodResult {
|
|
22
|
+
success: boolean;
|
|
23
|
+
paymentMethodId?: string;
|
|
24
|
+
cardBrand?: string;
|
|
25
|
+
cardLast4?: string;
|
|
26
|
+
cardExpMonth?: string;
|
|
27
|
+
cardExpYear?: string;
|
|
28
|
+
cardBin?: string;
|
|
29
|
+
error?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Result of deleting a payment method
|
|
33
|
+
*/
|
|
34
|
+
interface DeletePaymentMethodResult {
|
|
35
|
+
success: boolean;
|
|
36
|
+
error?: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Parameters for creating a setup intent
|
|
40
|
+
*/
|
|
41
|
+
interface CreateSetupIntentParams {
|
|
42
|
+
userId: string;
|
|
43
|
+
/** Customer ID in provider system */
|
|
44
|
+
customerId?: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Result of creating a setup intent
|
|
48
|
+
*/
|
|
49
|
+
interface SetupIntentResult {
|
|
50
|
+
success: boolean;
|
|
51
|
+
setupIntentId?: string;
|
|
52
|
+
clientSecret?: string;
|
|
53
|
+
error?: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Parameters for creating a customer
|
|
57
|
+
*/
|
|
58
|
+
interface CreateCustomerParams {
|
|
59
|
+
userId: string;
|
|
60
|
+
email: string;
|
|
61
|
+
name?: string;
|
|
62
|
+
metadata?: Record<string, string>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Result of creating a customer
|
|
66
|
+
*/
|
|
67
|
+
interface CreateCustomerResult {
|
|
68
|
+
success: boolean;
|
|
69
|
+
customerId?: string;
|
|
70
|
+
error?: string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Payment Provider Interface
|
|
74
|
+
*
|
|
75
|
+
* All payment provider adapters must implement this interface.
|
|
76
|
+
* Enables the adapter pattern for multi-provider support.
|
|
77
|
+
*/
|
|
78
|
+
interface IPaymentProvider {
|
|
79
|
+
/**
|
|
80
|
+
* Provider identifier
|
|
81
|
+
*/
|
|
82
|
+
readonly name: PaymentProvider;
|
|
83
|
+
/**
|
|
84
|
+
* Supported currencies (ISO 4217 codes)
|
|
85
|
+
*/
|
|
86
|
+
readonly supportedCurrencies: readonly string[];
|
|
87
|
+
/**
|
|
88
|
+
* Whether provider supports recurring billing
|
|
89
|
+
*/
|
|
90
|
+
readonly supportsRecurring: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Whether provider supports split payments (marketplace)
|
|
93
|
+
*/
|
|
94
|
+
readonly supportsSplitPayments: boolean;
|
|
95
|
+
createPaymentIntent(params: CreatePaymentIntentParams): Promise<PaymentIntentResult>;
|
|
96
|
+
authorize(params: AuthorizePaymentParams): Promise<AuthorizationResult>;
|
|
97
|
+
capture(params: CapturePaymentParams): Promise<CaptureResult>;
|
|
98
|
+
void(params: VoidPaymentParams): Promise<VoidResult>;
|
|
99
|
+
refund(params: RefundParams): Promise<RefundResult>;
|
|
100
|
+
createSetupIntent(params: CreateSetupIntentParams): Promise<SetupIntentResult>;
|
|
101
|
+
savePaymentMethod(params: SavePaymentMethodParams): Promise<SavePaymentMethodResult>;
|
|
102
|
+
deletePaymentMethod(paymentMethodId: string): Promise<DeletePaymentMethodResult>;
|
|
103
|
+
createCustomer(params: CreateCustomerParams): Promise<CreateCustomerResult>;
|
|
104
|
+
getOrCreateCustomer(userId: string, email: string): Promise<CreateCustomerResult>;
|
|
105
|
+
getHealth(): Promise<ProviderHealthStatus>;
|
|
106
|
+
validateWebhookSignature(payload: string, signature: string): boolean;
|
|
107
|
+
getPaymentIntentStatus(providerIntentId: string): Promise<{
|
|
108
|
+
status: string;
|
|
109
|
+
error?: string;
|
|
110
|
+
}>;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* @nehorai/payments - Routing Engine Interface
|
|
115
|
+
*
|
|
116
|
+
* Defines the contract for intelligent payment routing.
|
|
117
|
+
* Routes transactions to optimal providers based on:
|
|
118
|
+
* - Card BIN rules (configurable per deployment)
|
|
119
|
+
* - Provider health and availability
|
|
120
|
+
* - Transaction fees
|
|
121
|
+
* - Currency support
|
|
122
|
+
*/
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Context for making routing decisions
|
|
126
|
+
*/
|
|
127
|
+
interface RoutingContext {
|
|
128
|
+
/** User making the payment */
|
|
129
|
+
userId: string;
|
|
130
|
+
/** Payment amount and currency */
|
|
131
|
+
amount: PaymentAmount;
|
|
132
|
+
/** Card BIN (first 6-8 digits) for card type detection */
|
|
133
|
+
cardBin?: string;
|
|
134
|
+
/** User's country (ISO 2-letter code) */
|
|
135
|
+
userCountry?: string;
|
|
136
|
+
/** User's preferred provider (if any) */
|
|
137
|
+
preferredProvider?: PaymentProvider;
|
|
138
|
+
/** Whether this is a recurring payment */
|
|
139
|
+
isRecurring: boolean;
|
|
140
|
+
/** Saved payment method ID (if using saved method) */
|
|
141
|
+
savedPaymentMethodId?: string;
|
|
142
|
+
/** Provider of saved payment method */
|
|
143
|
+
savedPaymentMethodProvider?: PaymentProvider;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Result of routing decision
|
|
147
|
+
*/
|
|
148
|
+
interface RoutingDecision {
|
|
149
|
+
/** Selected provider */
|
|
150
|
+
provider: PaymentProvider;
|
|
151
|
+
/** Reason for selection */
|
|
152
|
+
reason: string;
|
|
153
|
+
/** Fallback providers in order of priority */
|
|
154
|
+
fallbackProviders: PaymentProvider[];
|
|
155
|
+
/** Estimated transaction fee percentage */
|
|
156
|
+
estimatedFeePercent: number;
|
|
157
|
+
/** Additional routing metadata */
|
|
158
|
+
metadata?: {
|
|
159
|
+
matchedBinRule?: boolean;
|
|
160
|
+
cardIssuer?: string;
|
|
161
|
+
cardCountry?: string;
|
|
162
|
+
primaryProviderUnavailable?: boolean;
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Routing Engine Interface
|
|
167
|
+
*
|
|
168
|
+
* Implementations of this interface handle intelligent routing
|
|
169
|
+
* of payments to optimal providers.
|
|
170
|
+
*/
|
|
171
|
+
interface IRoutingEngine {
|
|
172
|
+
/**
|
|
173
|
+
* Determine optimal provider for a transaction
|
|
174
|
+
*/
|
|
175
|
+
route(context: RoutingContext): Promise<RoutingDecision>;
|
|
176
|
+
/**
|
|
177
|
+
* Get next provider after a failure
|
|
178
|
+
*/
|
|
179
|
+
getFailoverProvider(failedProvider: PaymentProvider, context: RoutingContext): Promise<PaymentProvider | null>;
|
|
180
|
+
/**
|
|
181
|
+
* Check if a card BIN matches a configured rule
|
|
182
|
+
*/
|
|
183
|
+
matchCardBin(bin: string): boolean;
|
|
184
|
+
/**
|
|
185
|
+
* Get all available (healthy) providers
|
|
186
|
+
*/
|
|
187
|
+
getAvailableProviders(): Promise<PaymentProvider[]>;
|
|
188
|
+
/**
|
|
189
|
+
* Get provider recommendation without full context
|
|
190
|
+
*/
|
|
191
|
+
getQuickRecommendation(currency: string, isRecurring: boolean): Promise<PaymentProvider | null>;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export type { CreateCustomerParams as C, DeletePaymentMethodResult as D, IPaymentProvider as I, RoutingContext as R, SavePaymentMethodParams as S, CreateCustomerResult as a, CreateSetupIntentParams as b, IRoutingEngine as c, RoutingDecision as d, SavePaymentMethodResult as e, SetupIntentResult as f };
|