@plyaz/types 1.11.4 → 1.12.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.
- package/dist/api/index.cjs +1 -1
- package/dist/api/index.cjs.map +1 -1
- package/dist/auth/enums.d.ts +4 -0
- package/dist/auth/index.cjs +6 -0
- package/dist/auth/index.cjs.map +1 -1
- package/dist/auth/index.d.ts +0 -1
- package/dist/auth/index.js +6 -1
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/types.d.ts +34 -0
- package/dist/index.cjs +352 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +333 -1
- package/dist/index.js.map +1 -1
- package/dist/payments/currency/index.d.ts +37 -0
- package/dist/payments/events/emitter/types.d.ts +333 -0
- package/dist/payments/events/enums.d.ts +110 -0
- package/dist/payments/events/index.d.ts +4 -0
- package/dist/payments/events/types.d.ts +151 -0
- package/dist/payments/events/unified-event/enums.d.ts +14 -0
- package/dist/payments/events/unified-event/index.d.ts +2 -0
- package/dist/payments/events/unified-event/types.d.ts +346 -0
- package/dist/payments/gateways/index.d.ts +2 -0
- package/dist/payments/gateways/provider/index.d.ts +1 -0
- package/dist/payments/gateways/provider/types.d.ts +435 -0
- package/dist/payments/gateways/routings/enums.d.ts +87 -0
- package/dist/payments/gateways/routings/index.d.ts +2 -0
- package/dist/payments/gateways/routings/types.d.ts +512 -0
- package/dist/payments/index.cjs +351 -0
- package/dist/payments/index.cjs.map +1 -0
- package/dist/payments/index.d.ts +7 -0
- package/dist/payments/index.js +332 -0
- package/dist/payments/index.js.map +1 -0
- package/dist/payments/provider/adapter/index.d.ts +1 -0
- package/dist/payments/provider/adapter/types.d.ts +208 -0
- package/dist/payments/provider/core/index.d.ts +1 -0
- package/dist/payments/provider/core/types.d.ts +508 -0
- package/dist/payments/provider/index.d.ts +4 -0
- package/dist/payments/provider/payment-provider/index.d.ts +1 -0
- package/dist/payments/provider/payment-provider/types.d.ts +269 -0
- package/dist/payments/provider/provider-capability/enums.d.ts +116 -0
- package/dist/payments/provider/provider-capability/index.d.ts +1 -0
- package/dist/payments/request/enums.d.ts +19 -0
- package/dist/payments/request/index.d.ts +2 -0
- package/dist/payments/request/types.d.ts +221 -0
- package/dist/payments/service/index.d.ts +1 -0
- package/dist/payments/service/types.d.ts +48 -0
- package/dist/payments/transaction/index.d.ts +1 -0
- package/dist/payments/transaction/types.d.ts +120 -0
- package/package.json +6 -1
- package/dist/auth/config/types.d.ts +0 -67
- /package/dist/{auth/config → payments/events/emitter}/index.d.ts +0 -0
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import type { ProviderHealthStatus } from '../../../features';
|
|
2
|
+
import type { CURRENCY } from '../../currency';
|
|
3
|
+
import type { PaymentResult, ProcessPaymentRequest } from '../../request';
|
|
4
|
+
import type { FeeBreakdown, Money } from '../../transaction';
|
|
5
|
+
import type { CreateCustomerParams, CustomerResult, FeeCalculationOptions, PaymentProviderConfig, PaymentStatusResult, RefundParams, RefundResult, SavedPaymentMethodResult, SavePaymentMethodParams, TransactionHistory, TransactionHistoryParams, WebhookPayload, WebhookResult } from '../core';
|
|
6
|
+
import type { PAYMENTMETHOD, PAYMENTPROVIDERTYPE } from '../provider-capability';
|
|
7
|
+
/**
|
|
8
|
+
* Core interface that all payment providers must implement.
|
|
9
|
+
* This interface ensures consistent behavior across all providers
|
|
10
|
+
* while allowing for provider-specific capabilities and optimizations.
|
|
11
|
+
*
|
|
12
|
+
* Implementation Requirements:
|
|
13
|
+
* - All methods must be implemented (use NotImplementedError for unsupported features)
|
|
14
|
+
* - All operations must be idempotent where possible
|
|
15
|
+
* - All sensitive data must be handled according to PCI compliance
|
|
16
|
+
* - All errors must be properly typed and include provider context
|
|
17
|
+
*/
|
|
18
|
+
export interface PaymentProvider {
|
|
19
|
+
/** Unique identifier for this payment provider */
|
|
20
|
+
readonly name: PAYMENTPROVIDERTYPE;
|
|
21
|
+
/** Payment methods supported by this provider */
|
|
22
|
+
readonly supportedMethods: PAYMENTMETHOD[];
|
|
23
|
+
/** Currencies supported by this provider */
|
|
24
|
+
readonly supportedCurrencies: CURRENCY[];
|
|
25
|
+
/** Detailed capabilities of this provider */
|
|
26
|
+
readonly capabilities: ProviderCapabilities;
|
|
27
|
+
/** Provider configuration and metadata */
|
|
28
|
+
readonly config: ProviderConfiguration;
|
|
29
|
+
/**
|
|
30
|
+
* Initialize the provider with configuration and validate connectivity.
|
|
31
|
+
* This method should:
|
|
32
|
+
* - Validate all required configuration parameters
|
|
33
|
+
* - Test connectivity to provider APIs
|
|
34
|
+
* - Set up webhook endpoints if required
|
|
35
|
+
* - Initialize any required provider SDKs
|
|
36
|
+
*
|
|
37
|
+
* @param config - Provider-specific configuration
|
|
38
|
+
* @throws ProviderConfigurationError if configuration is invalid
|
|
39
|
+
* @throws ProviderConnectionError if unable to connect to provider
|
|
40
|
+
*/
|
|
41
|
+
initialize(config: PaymentProviderConfig): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Shutdown the provider and clean up resources.
|
|
44
|
+
* This method should:
|
|
45
|
+
* - Close any open connections
|
|
46
|
+
* - Cancel any pending operations
|
|
47
|
+
* - Clean up temporary resources
|
|
48
|
+
*/
|
|
49
|
+
shutdown(): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Create a new payment transaction.
|
|
52
|
+
* This method should:
|
|
53
|
+
* - Validate payment parameters
|
|
54
|
+
* - Create transaction with provider
|
|
55
|
+
* - Return payment result with next steps
|
|
56
|
+
* - Handle provider-specific error cases
|
|
57
|
+
*
|
|
58
|
+
* @param params - Payment creation parameters
|
|
59
|
+
* @returns Payment result with status and next steps
|
|
60
|
+
* @throws PaymentValidationError for invalid parameters
|
|
61
|
+
* @throws PaymentProcessingError for provider errors
|
|
62
|
+
*/
|
|
63
|
+
createPayment(params: ProcessPaymentRequest): Promise<PaymentResult>;
|
|
64
|
+
/**
|
|
65
|
+
* Process a refund for an existing transaction.
|
|
66
|
+
* This method should:
|
|
67
|
+
* - Validate refund parameters and permissions
|
|
68
|
+
* - Check if refund is possible for this transaction
|
|
69
|
+
* - Process refund with provider
|
|
70
|
+
* - Return refund result with status
|
|
71
|
+
*
|
|
72
|
+
* @param params - Refund processing parameters
|
|
73
|
+
* @returns Refund result with status and details
|
|
74
|
+
* @throws RefundValidationError for invalid refund requests
|
|
75
|
+
* @throws RefundProcessingError for provider errors
|
|
76
|
+
*/
|
|
77
|
+
processRefund(params: RefundParams): Promise<RefundResult>;
|
|
78
|
+
/**
|
|
79
|
+
* Get current status of a payment transaction.
|
|
80
|
+
* This method should:
|
|
81
|
+
* - Query provider for current transaction status
|
|
82
|
+
* - Normalize provider status to our standard statuses
|
|
83
|
+
* - Include any relevant status details
|
|
84
|
+
*
|
|
85
|
+
* @param transactionId - Provider's transaction identifier
|
|
86
|
+
* @returns Current normalized payment status
|
|
87
|
+
* @throws TransactionNotFoundError if transaction doesn't exist
|
|
88
|
+
*/
|
|
89
|
+
getPaymentStatus(transactionId: string): Promise<PaymentStatusResult>;
|
|
90
|
+
/**
|
|
91
|
+
* Process incoming webhook from provider.
|
|
92
|
+
* This method should:
|
|
93
|
+
* - Verify webhook signature for security
|
|
94
|
+
* - Parse and validate webhook payload
|
|
95
|
+
* - Normalize webhook data to our event format
|
|
96
|
+
* - Return processing result
|
|
97
|
+
*
|
|
98
|
+
* @param payload - Raw webhook payload from provider
|
|
99
|
+
* @returns Webhook processing result
|
|
100
|
+
* @throws WebhookVerificationError for invalid signatures
|
|
101
|
+
* @throws WebhookProcessingError for processing failures
|
|
102
|
+
*/
|
|
103
|
+
processWebhook(payload: WebhookPayload): Promise<WebhookResult>;
|
|
104
|
+
/**
|
|
105
|
+
* Verify webhook signature for security.
|
|
106
|
+
* This method should:
|
|
107
|
+
* - Validate webhook signature using provider's method
|
|
108
|
+
* - Return true if signature is valid, false otherwise
|
|
109
|
+
* - Handle different signature algorithms
|
|
110
|
+
*
|
|
111
|
+
* @param payload - Raw webhook body
|
|
112
|
+
* @param signature - Webhook signature header
|
|
113
|
+
* @param secret - Webhook secret for verification
|
|
114
|
+
* @returns True if signature is valid
|
|
115
|
+
*/
|
|
116
|
+
verifyWebhookSignature(payload: string, signature: string, secret?: string): boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Calculate fees for a potential transaction.
|
|
119
|
+
* This method should:
|
|
120
|
+
* - Calculate all applicable fees for the transaction
|
|
121
|
+
* - Include provider fees, platform fees, and additional charges
|
|
122
|
+
* - Consider user location, currency, and payment method
|
|
123
|
+
*
|
|
124
|
+
* @param amount - Transaction amount
|
|
125
|
+
* @param method - Payment method to be used
|
|
126
|
+
* @param options - Additional calculation options
|
|
127
|
+
* @returns Detailed fee breakdown
|
|
128
|
+
*/
|
|
129
|
+
calculateFees(amount: Money, method: PAYMENTMETHOD, options?: FeeCalculationOptions): Promise<FeeBreakdown>;
|
|
130
|
+
/**
|
|
131
|
+
* Check provider health and availability.
|
|
132
|
+
* This method should:
|
|
133
|
+
* - Test connectivity to provider APIs
|
|
134
|
+
* - Check service status and response times
|
|
135
|
+
* - Return detailed health information
|
|
136
|
+
*
|
|
137
|
+
* @returns Provider health status and metrics
|
|
138
|
+
*/
|
|
139
|
+
healthCheck(): Promise<ProviderHealthStatus>;
|
|
140
|
+
/**
|
|
141
|
+
* Create a customer profile with the provider (optional).
|
|
142
|
+
* Only implement if provider supports customer management.
|
|
143
|
+
*/
|
|
144
|
+
createCustomer?(params: CreateCustomerParams): Promise<CustomerResult>;
|
|
145
|
+
/**
|
|
146
|
+
* Save a payment method for future use (optional).
|
|
147
|
+
* Only implement if provider supports saved payment methods.
|
|
148
|
+
*/
|
|
149
|
+
savePaymentMethod?(params: SavePaymentMethodParams): Promise<SavedPaymentMethodResult>;
|
|
150
|
+
/**
|
|
151
|
+
* Delete a saved payment method (optional).
|
|
152
|
+
* Only implement if provider supports payment method management.
|
|
153
|
+
*/
|
|
154
|
+
deletePaymentMethod?(paymentMethodId: string): Promise<void>;
|
|
155
|
+
/**
|
|
156
|
+
* Get transaction history from provider (optional).
|
|
157
|
+
* Only implement if provider supports historical transaction queries.
|
|
158
|
+
*/
|
|
159
|
+
getTransactionHistory?(params: TransactionHistoryParams): Promise<TransactionHistory>;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Detailed provider capabilities interface.
|
|
163
|
+
* This interface allows the system to understand what each provider
|
|
164
|
+
* can and cannot do, enabling intelligent routing and feature availability.
|
|
165
|
+
*/
|
|
166
|
+
export interface ProviderCapabilities {
|
|
167
|
+
/** Supports recurring/subscription payments */
|
|
168
|
+
supportsSubscriptions: boolean;
|
|
169
|
+
/** Supports full refunds */
|
|
170
|
+
supportsRefunds: boolean;
|
|
171
|
+
/** Supports partial refunds */
|
|
172
|
+
supportsPartialRefunds: boolean;
|
|
173
|
+
/** Supports payment preauthorization (capture later) */
|
|
174
|
+
supportsPreauthorization: boolean;
|
|
175
|
+
/** Supports payment cancellation before capture */
|
|
176
|
+
supportsCancellation: boolean;
|
|
177
|
+
/** Supports 3D Secure verification */
|
|
178
|
+
supports3DSecure: boolean;
|
|
179
|
+
/** Provides fraud detection and scoring */
|
|
180
|
+
supportsFraudDetection: boolean;
|
|
181
|
+
/** Supports multi-factor authentication */
|
|
182
|
+
supportsMultiFactorAuth: boolean;
|
|
183
|
+
/** Provides real-time webhook notifications */
|
|
184
|
+
supportsWebhooks: boolean;
|
|
185
|
+
/** Supports customer profile management */
|
|
186
|
+
supportsCustomerProfiles: boolean;
|
|
187
|
+
/** Supports saved payment methods */
|
|
188
|
+
supportsSavedPaymentMethods: boolean;
|
|
189
|
+
/** Supports transaction history queries */
|
|
190
|
+
supportsTransactionHistory: boolean;
|
|
191
|
+
/** Supports multiple currencies */
|
|
192
|
+
supportsMultiCurrency: boolean;
|
|
193
|
+
/** Supports automatic currency conversion */
|
|
194
|
+
supportsCurrencyConversion: boolean;
|
|
195
|
+
/** Supports cryptocurrency payments */
|
|
196
|
+
supportsCryptocurrency: boolean;
|
|
197
|
+
/** Supports cross-border transactions */
|
|
198
|
+
supportsCrossBorderPayments: boolean;
|
|
199
|
+
/** Supports instant payouts to recipients */
|
|
200
|
+
supportsInstantPayouts: boolean;
|
|
201
|
+
/** Supports scheduled payouts */
|
|
202
|
+
supportsScheduledPayouts: boolean;
|
|
203
|
+
/** Supports marketplace/split payments */
|
|
204
|
+
supportsMarketplacePayments: boolean;
|
|
205
|
+
/** Supports chargeback/dispute management */
|
|
206
|
+
supportsDisputeManagement: boolean;
|
|
207
|
+
/** Provides dispute evidence submission */
|
|
208
|
+
supportsDisputeEvidence: boolean;
|
|
209
|
+
/** Minimum transaction amount per payment method */
|
|
210
|
+
minimumAmounts: Record<PAYMENTMETHOD, Money>;
|
|
211
|
+
/** Maximum transaction amount per payment method */
|
|
212
|
+
maximumAmounts: Record<PAYMENTMETHOD, Money>;
|
|
213
|
+
/** Supported countries/regions */
|
|
214
|
+
supportedRegions: string[];
|
|
215
|
+
/** Processing time estimates per payment method */
|
|
216
|
+
processingTimes: Record<PAYMENTMETHOD, ProcessingTimeEstimate>;
|
|
217
|
+
/** Settlement time estimates per payment method */
|
|
218
|
+
settlementTimes: Record<PAYMENTMETHOD, SettlementTimeEstimate>;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Provider configuration interface for initialization.
|
|
222
|
+
*/
|
|
223
|
+
export interface ProviderConfiguration<TSettings extends object = object, TFeatures extends Record<string, boolean> = Record<string, boolean>, TCredentials extends Record<string, string> = Record<string, string>> {
|
|
224
|
+
/** Provider name for logging and identification */
|
|
225
|
+
name: string;
|
|
226
|
+
/** Environment (sandbox, staging, production) */
|
|
227
|
+
environment: 'sandbox' | 'staging' | 'production';
|
|
228
|
+
/** Provider-specific configuration parameters */
|
|
229
|
+
credentials: TCredentials;
|
|
230
|
+
/** Webhook configuration */
|
|
231
|
+
webhookConfig?: {
|
|
232
|
+
/** Webhook endpoint URL */
|
|
233
|
+
endpointUrl: string;
|
|
234
|
+
/** Webhook secret for signature verification */
|
|
235
|
+
secret: string;
|
|
236
|
+
/** Events to subscribe to */
|
|
237
|
+
subscribedEvents: string[];
|
|
238
|
+
};
|
|
239
|
+
/** Feature flags for this provider */
|
|
240
|
+
features: TFeatures;
|
|
241
|
+
/** Custom provider settings (strongly typed via generic) */
|
|
242
|
+
settings: TSettings;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Processing time estimate interface.
|
|
246
|
+
*/
|
|
247
|
+
export interface ProcessingTimeEstimate {
|
|
248
|
+
/** Minimum processing time in minutes */
|
|
249
|
+
minimumMinutes: number;
|
|
250
|
+
/** Maximum processing time in minutes */
|
|
251
|
+
maximumMinutes: number;
|
|
252
|
+
/** Typical processing time in minutes */
|
|
253
|
+
typicalMinutes: number;
|
|
254
|
+
/** Factors that affect processing time */
|
|
255
|
+
factors: string[];
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Settlement time estimate interface.
|
|
259
|
+
*/
|
|
260
|
+
export interface SettlementTimeEstimate {
|
|
261
|
+
/** Minimum settlement time in business days */
|
|
262
|
+
minimumDays: number;
|
|
263
|
+
/** Maximum settlement time in business days */
|
|
264
|
+
maximumDays: number;
|
|
265
|
+
/** Typical settlement time in business days */
|
|
266
|
+
typicalDays: number;
|
|
267
|
+
/** Whether weekends and holidays affect settlement */
|
|
268
|
+
affectedByHolidays: boolean;
|
|
269
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enumeration of all supported payment providers in the Plyaz ecosystem.
|
|
3
|
+
*/
|
|
4
|
+
export declare enum PAYMENTPROVIDERTYPE {
|
|
5
|
+
Stripe = "stripe",
|
|
6
|
+
Paypal = "paypal",
|
|
7
|
+
CheckoutCom = "checkout_com",
|
|
8
|
+
Adyen = "adyen",
|
|
9
|
+
Moonpay = "moonpay",
|
|
10
|
+
CoinbaseCommerce = "coinbase_commerce",
|
|
11
|
+
BlockchainBridge = "blockchain_bridge",
|
|
12
|
+
Pix = "pix",
|
|
13
|
+
Boleto = "boleto",
|
|
14
|
+
Sepa = "sepa",
|
|
15
|
+
Ideal = "ideal",
|
|
16
|
+
Sofort = "sofort",
|
|
17
|
+
Alipay = "alipay",
|
|
18
|
+
WechatPay = "wechat_pay",
|
|
19
|
+
MockProvider = "mock_provider"
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Enumeration of payment methods supported across all providers.
|
|
23
|
+
*/
|
|
24
|
+
export declare enum PAYMENTMETHOD {
|
|
25
|
+
CreditCard = "credit_card",
|
|
26
|
+
DebitCard = "debit_card",
|
|
27
|
+
BankTransfer = "bank_transfer",
|
|
28
|
+
PaypalAccount = "paypal_account",
|
|
29
|
+
CryptoBitcoin = "crypto_bitcoin",
|
|
30
|
+
CryptoEthereum = "crypto_ethereum",
|
|
31
|
+
CryptoPolygon = "crypto_polygon",
|
|
32
|
+
CryptoOptimism = "crypto_optimism",
|
|
33
|
+
CryptoUsdc = "crypto_usdc",
|
|
34
|
+
CryptoUsdt = "crypto_usdt",
|
|
35
|
+
CryptoNativeToken = "crypto_native_token",
|
|
36
|
+
PixInstant = "pix_instant",
|
|
37
|
+
BoletoBancario = "boleto_bancario",
|
|
38
|
+
SepaDirectDebit = "sepa_direct_debit",
|
|
39
|
+
IdealBank = "ideal_bank",
|
|
40
|
+
SofortBanking = "sofort_banking",
|
|
41
|
+
AlipayDigital = "alipay_digital",
|
|
42
|
+
WechatPayDigital = "wechat_pay_digital",
|
|
43
|
+
ApplePay = "apple_pay",
|
|
44
|
+
GooglePay = "google_pay",
|
|
45
|
+
SamsungPay = "samsung_pay"
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Comprehensive payment status enumeration.
|
|
49
|
+
*/
|
|
50
|
+
export declare enum PAYMENTSTATUS {
|
|
51
|
+
Initiated = "initiated",
|
|
52
|
+
Pending = "pending",
|
|
53
|
+
Processing = "processing",
|
|
54
|
+
RequiresAction = "requires_action",
|
|
55
|
+
RequiresConfirmation = "requires_confirmation",
|
|
56
|
+
RequiresPaymentMethod = "requires_payment_method",
|
|
57
|
+
Completed = "completed",
|
|
58
|
+
Settled = "settled",
|
|
59
|
+
Failed = "failed",
|
|
60
|
+
Declined = "declined",
|
|
61
|
+
Cancelled = "cancelled",
|
|
62
|
+
Expired = "expired",
|
|
63
|
+
Refunded = "refunded",
|
|
64
|
+
PartiallyRefunded = "partially_refunded",
|
|
65
|
+
Disputed = "disputed",
|
|
66
|
+
Chargeback = "chargeback",
|
|
67
|
+
ChargebackResolved = "chargeback_resolved",
|
|
68
|
+
Held = "held",
|
|
69
|
+
Authorized = "authorized",
|
|
70
|
+
Captured = "captured"
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Transaction type enumeration.
|
|
74
|
+
*/
|
|
75
|
+
export declare enum TRANSACTIONTYPE {
|
|
76
|
+
Payment = "payment",
|
|
77
|
+
Refund = "refund",
|
|
78
|
+
PartialRefund = "partial_refund",
|
|
79
|
+
Withdrawal = "withdrawal",
|
|
80
|
+
Donation = "donation",
|
|
81
|
+
Subscription = "subscription",
|
|
82
|
+
SubscriptionRenewal = "subscription_renewal",
|
|
83
|
+
Fee = "fee",
|
|
84
|
+
Chargeback = "chargeback",
|
|
85
|
+
Adjustment = "adjustment",
|
|
86
|
+
Reward = "reward",
|
|
87
|
+
Penalty = "penalty",
|
|
88
|
+
Transfer = "transfer"
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* User type enumeration.
|
|
92
|
+
*/
|
|
93
|
+
export declare enum USERTYPE {
|
|
94
|
+
Fan = "fan",
|
|
95
|
+
Athlete = "athlete",
|
|
96
|
+
Club = "club",
|
|
97
|
+
Agent = "agent",
|
|
98
|
+
Scout = "scout",
|
|
99
|
+
Admin = "admin",
|
|
100
|
+
System = "system"
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Product type enumeration.
|
|
104
|
+
*/
|
|
105
|
+
export declare enum PRODUCTTYPE {
|
|
106
|
+
Campaign = "campaign",
|
|
107
|
+
Subscription = "subscription",
|
|
108
|
+
Nft = "nft",
|
|
109
|
+
Merchandise = "merchandise",
|
|
110
|
+
EventTicket = "event_ticket",
|
|
111
|
+
PremiumContent = "premium_content",
|
|
112
|
+
TrainingSession = "training_session",
|
|
113
|
+
Consultation = "consultation",
|
|
114
|
+
DigitalProduct = "digital_product",
|
|
115
|
+
PhysicalProduct = "physical_product"
|
|
116
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './enums';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enumeration of action types that users might need to complete.
|
|
3
|
+
*/
|
|
4
|
+
export declare enum REQUIREDACTIONTYPE {
|
|
5
|
+
/** Redirect to external page (3D Secure, bank auth, etc.) */
|
|
6
|
+
Redirect = "redirect",
|
|
7
|
+
/** Enter SMS or email verification code */
|
|
8
|
+
OtpVerification = "otp_verification",
|
|
9
|
+
/** Upload identity or financial documents */
|
|
10
|
+
DocumentUpload = "document_upload",
|
|
11
|
+
/** Provide additional payment information */
|
|
12
|
+
AdditionalPaymentInfo = "additional_payment_info",
|
|
13
|
+
/** Confirm payment via mobile app or email */
|
|
14
|
+
PaymentConfirmation = "payment_confirmation",
|
|
15
|
+
/** Contact customer support for manual verification */
|
|
16
|
+
ManualVerification = "manual_verification",
|
|
17
|
+
/** Wait for bank transfer or other delayed method */
|
|
18
|
+
WaitForCompletion = "wait_for_completion"
|
|
19
|
+
}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import type { PAYMENTMETHOD, PAYMENTPROVIDERTYPE, PAYMENTSTATUS, PRODUCTTYPE, USERTYPE } from '../provider';
|
|
2
|
+
import type { ReceiptData, SavedPaymentMethodInfo } from '../provider/core';
|
|
3
|
+
import type { FeeBreakdown, Money } from '../transaction';
|
|
4
|
+
import type { REQUIREDACTIONTYPE } from './enums';
|
|
5
|
+
/**
|
|
6
|
+
* Comprehensive payment request interface that supports all payment types
|
|
7
|
+
* and providers while maintaining type safety and validation requirements.
|
|
8
|
+
*
|
|
9
|
+
* Design Goals:
|
|
10
|
+
* - Single interface for all payment types
|
|
11
|
+
* - Extensible for new payment methods
|
|
12
|
+
* - Strong validation support
|
|
13
|
+
* - Audit trail requirements built-in
|
|
14
|
+
*/
|
|
15
|
+
export interface ProcessPaymentRequest<TCustomMetadata extends Record<string, string | number | boolean> = Record<string, never>> {
|
|
16
|
+
/** Payment amount and currency information */
|
|
17
|
+
amount: Money;
|
|
18
|
+
/** Selected payment method from supported options */
|
|
19
|
+
paymentMethod: PAYMENTMETHOD;
|
|
20
|
+
/**
|
|
21
|
+
* Optional provider override for advanced use cases
|
|
22
|
+
* If not specified, optimal provider will be auto-selected
|
|
23
|
+
*/
|
|
24
|
+
provider?: PAYMENTPROVIDERTYPE;
|
|
25
|
+
/** User making the payment - must be authenticated */
|
|
26
|
+
userId: string;
|
|
27
|
+
/** Type of user making the payment for limit enforcement */
|
|
28
|
+
userType: USERTYPE;
|
|
29
|
+
/** Product or service being purchased */
|
|
30
|
+
productId: string;
|
|
31
|
+
/** Type of product for business rule application */
|
|
32
|
+
productType: PRODUCTTYPE;
|
|
33
|
+
/**
|
|
34
|
+
* Human-readable description for receipts and statements
|
|
35
|
+
* Should be descriptive but concise (max 255 characters)
|
|
36
|
+
*/
|
|
37
|
+
description?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Additional structured metadata for transaction tracking
|
|
40
|
+
* Useful for analytics, debugging, and business intelligence
|
|
41
|
+
*/
|
|
42
|
+
metadata?: {
|
|
43
|
+
/** Campaign-specific information */
|
|
44
|
+
campaignInfo?: {
|
|
45
|
+
campaignId: string;
|
|
46
|
+
campaignTitle: string;
|
|
47
|
+
athleteId: string;
|
|
48
|
+
fundingGoal?: Money;
|
|
49
|
+
};
|
|
50
|
+
/** Subscription-specific information */
|
|
51
|
+
subscriptionInfo?: {
|
|
52
|
+
planId: string;
|
|
53
|
+
billingCycle: 'monthly' | 'quarterly' | 'yearly';
|
|
54
|
+
trialPeriod?: number;
|
|
55
|
+
};
|
|
56
|
+
/** Geographic and device information */
|
|
57
|
+
geoInfo?: {
|
|
58
|
+
country: string;
|
|
59
|
+
region?: string;
|
|
60
|
+
city?: string;
|
|
61
|
+
timezone?: string;
|
|
62
|
+
};
|
|
63
|
+
/** Custom metadata fields */
|
|
64
|
+
custom?: TCustomMetadata;
|
|
65
|
+
};
|
|
66
|
+
/** URL to redirect user after successful payment completion */
|
|
67
|
+
returnUrl?: string;
|
|
68
|
+
/** URL to redirect user after payment cancellation */
|
|
69
|
+
cancelUrl?: string;
|
|
70
|
+
/**
|
|
71
|
+
* Idempotency key to prevent duplicate payment processing
|
|
72
|
+
* Should be unique per payment attempt, recommended: UUID v4
|
|
73
|
+
*/
|
|
74
|
+
idempotencyKey?: string;
|
|
75
|
+
/**
|
|
76
|
+
* Whether to save payment method for future use
|
|
77
|
+
* Requires user consent and provider support
|
|
78
|
+
*/
|
|
79
|
+
savePaymentMethod?: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Existing saved payment method ID to use
|
|
82
|
+
* Alternative to entering new payment details
|
|
83
|
+
*/
|
|
84
|
+
savedPaymentMethodId?: string;
|
|
85
|
+
/**
|
|
86
|
+
* Payment scheduling information for future payments
|
|
87
|
+
* Used for subscription setup and delayed charges
|
|
88
|
+
*/
|
|
89
|
+
scheduling?: {
|
|
90
|
+
/** Whether this payment should be processed immediately */
|
|
91
|
+
processImmediately: boolean;
|
|
92
|
+
/** Scheduled processing time for future payments */
|
|
93
|
+
scheduledFor?: Date;
|
|
94
|
+
/** Recurring payment configuration */
|
|
95
|
+
recurring?: {
|
|
96
|
+
frequency: 'daily' | 'weekly' | 'monthly' | 'quarterly' | 'yearly';
|
|
97
|
+
interval: number;
|
|
98
|
+
endDate?: Date;
|
|
99
|
+
maxOccurrences?: number;
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Risk assessment override information
|
|
104
|
+
* Used for manual risk assessment adjustments
|
|
105
|
+
*/
|
|
106
|
+
riskAssessment?: {
|
|
107
|
+
/** Manual risk level override */
|
|
108
|
+
riskLevel?: 'low' | 'medium' | 'high';
|
|
109
|
+
/** Risk assessment notes */
|
|
110
|
+
notes?: string;
|
|
111
|
+
/** Skip automated fraud checks (admin only) */
|
|
112
|
+
skipFraudChecks?: boolean;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Processing preferences for payment handling
|
|
116
|
+
* Allows customization of payment processing behavior
|
|
117
|
+
*/
|
|
118
|
+
processingPreferences?: {
|
|
119
|
+
/** Preferred processing speed */
|
|
120
|
+
speed: 'standard' | 'fast' | 'instant';
|
|
121
|
+
/** Whether to attempt 3D Secure verification */
|
|
122
|
+
attempt3DS?: boolean;
|
|
123
|
+
/** Maximum acceptable processing time (minutes) */
|
|
124
|
+
maxProcessingTime?: number;
|
|
125
|
+
/** Fallback behavior if primary method fails */
|
|
126
|
+
fallbackBehavior?: 'retry' | 'fail' | 'alternative_method';
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Comprehensive payment result interface providing complete information
|
|
131
|
+
* about payment processing outcomes and next steps.
|
|
132
|
+
*/
|
|
133
|
+
export interface PaymentResult<TProviderResponse extends object = {}> {
|
|
134
|
+
/** Unique transaction identifier in Plyaz system */
|
|
135
|
+
transactionId: string;
|
|
136
|
+
/** Provider's transaction identifier for reference */
|
|
137
|
+
providerTransactionId?: string;
|
|
138
|
+
/** Current payment status */
|
|
139
|
+
status: PAYMENTSTATUS;
|
|
140
|
+
/**
|
|
141
|
+
* URL for redirect-based payment flows (Stripe Checkout, PayPal, etc.)
|
|
142
|
+
* Client should redirect user to this URL to complete payment
|
|
143
|
+
*/
|
|
144
|
+
redirectUrl?: string;
|
|
145
|
+
/**
|
|
146
|
+
* Client secret for client-side payment confirmation
|
|
147
|
+
* Used with Stripe Payment Intents and similar flows
|
|
148
|
+
*/
|
|
149
|
+
clientSecret?: string;
|
|
150
|
+
/** Generated receipt data if payment completed */
|
|
151
|
+
receipt?: ReceiptData;
|
|
152
|
+
/** Detailed breakdown of all fees charged */
|
|
153
|
+
fees?: FeeBreakdown;
|
|
154
|
+
/** Estimated settlement date for funds availability */
|
|
155
|
+
estimatedSettlement?: Date;
|
|
156
|
+
/**
|
|
157
|
+
* Actions required from user to complete payment
|
|
158
|
+
* Common for 3D Secure, bank verification, etc.
|
|
159
|
+
*/
|
|
160
|
+
requiredActions?: RequiredAction[];
|
|
161
|
+
/**
|
|
162
|
+
* Payment method information if saved during transaction
|
|
163
|
+
* Only includes safe display information, no sensitive data
|
|
164
|
+
*/
|
|
165
|
+
savedPaymentMethod?: SavedPaymentMethodInfo;
|
|
166
|
+
/**
|
|
167
|
+
* Provider-specific metadata and additional information
|
|
168
|
+
* Useful for debugging and advanced integrations
|
|
169
|
+
*/
|
|
170
|
+
metadata?: {
|
|
171
|
+
/** Provider-specific response data */
|
|
172
|
+
providerResponse?: TProviderResponse;
|
|
173
|
+
/** Processing performance metrics */
|
|
174
|
+
performanceMetrics?: {
|
|
175
|
+
providerResponseTime: number;
|
|
176
|
+
totalProcessingTime: number;
|
|
177
|
+
dbWriteTime?: number;
|
|
178
|
+
};
|
|
179
|
+
/** Security validation results */
|
|
180
|
+
securityChecks?: {
|
|
181
|
+
fraudScore?: number;
|
|
182
|
+
riskLevel?: 'low' | 'medium' | 'high';
|
|
183
|
+
securityFlags?: string[];
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
/** Time taken to process payment in milliseconds */
|
|
187
|
+
processingTime?: number;
|
|
188
|
+
/**
|
|
189
|
+
* Next steps for user or system
|
|
190
|
+
* Provides guidance on what should happen next
|
|
191
|
+
*/
|
|
192
|
+
nextSteps?: {
|
|
193
|
+
/** What the user should do next */
|
|
194
|
+
userAction?: 'redirect' | 'wait' | 'retry' | 'contact_support';
|
|
195
|
+
/** System actions to be taken */
|
|
196
|
+
systemAction?: 'webhook_pending' | 'manual_review' | 'auto_retry';
|
|
197
|
+
/** Expected timeframe for next update */
|
|
198
|
+
expectedUpdateIn?: number;
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Interface for actions required from user to complete payment.
|
|
203
|
+
* Supports various verification and confirmation flows.
|
|
204
|
+
*/
|
|
205
|
+
export interface RequiredAction<TActionData extends Record<string, unknown> = Record<string, never>> {
|
|
206
|
+
/** Type of action required from user */
|
|
207
|
+
type: REQUIREDACTIONTYPE;
|
|
208
|
+
/** URL or endpoint for completing the action */
|
|
209
|
+
actionUrl?: string;
|
|
210
|
+
/**
|
|
211
|
+
* Additional data needed for the action
|
|
212
|
+
* Format depends on action type
|
|
213
|
+
*/
|
|
214
|
+
actionData?: TActionData;
|
|
215
|
+
/** When this action expires and payment will be cancelled */
|
|
216
|
+
expiresAt?: Date;
|
|
217
|
+
/** Human-readable instructions for the user */
|
|
218
|
+
instructions?: string;
|
|
219
|
+
/** Whether this action is optional or required */
|
|
220
|
+
required: boolean;
|
|
221
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type * from './types';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ValidationResult } from '../../common';
|
|
2
|
+
import type { PAYMENTPROVIDERTYPE, PAYMENTSTATUS } from '../provider';
|
|
3
|
+
import type { PaymentAdapter } from '../provider/adapter';
|
|
4
|
+
import type { PaymentResult, ProcessPaymentRequest } from '../request';
|
|
5
|
+
import type { Money } from '../transaction';
|
|
6
|
+
/**
|
|
7
|
+
* Core payment service interface that defines the main payment operations.
|
|
8
|
+
* This interface ensures all payment services implement consistent methods
|
|
9
|
+
* for processing payments, checking status, and handling refunds.
|
|
10
|
+
* Used as dependency injection to provide type-safe service contracts.
|
|
11
|
+
*/
|
|
12
|
+
export interface PaymentServiceInterface {
|
|
13
|
+
/** Process a new payment transaction with full business logic validation */
|
|
14
|
+
processPayment(request: ProcessPaymentRequest): Promise<PaymentResult>;
|
|
15
|
+
/** Get current status of any payment transaction */
|
|
16
|
+
getPaymentStatus(transactionId: string): Promise<PAYMENTSTATUS>;
|
|
17
|
+
/** Process refunds with authorization and business rule validation */
|
|
18
|
+
/** Validate payment limits before processing */
|
|
19
|
+
validatePaymentLimits(userId: string, amount: Money): Promise<boolean>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Factory service for creating provider-specific payment adapters.
|
|
23
|
+
* Implements the Factory pattern to dynamically create
|
|
24
|
+
* payment provider instances based on routing decisions and configuration.
|
|
25
|
+
*/
|
|
26
|
+
export interface PaymentAdapterFactory {
|
|
27
|
+
/** Create adapter instance for specific provider */
|
|
28
|
+
createAdapter(provider: PAYMENTPROVIDERTYPE): Promise<PaymentAdapter>;
|
|
29
|
+
/** Get list of currently available and healthy providers */
|
|
30
|
+
getAvailableProviders(): PAYMENTPROVIDERTYPE[];
|
|
31
|
+
/** Validate provider configuration before creating adapter */
|
|
32
|
+
validateProviderConfig(provider: PAYMENTPROVIDERTYPE): boolean;
|
|
33
|
+
/** Get adapter with automatic provider selection based on routing rules */
|
|
34
|
+
getOptimalAdapter(request: ProcessPaymentRequest): Promise<PaymentAdapter>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* High-level orchestration service that coordinates payment workflows.
|
|
38
|
+
* Handles business logic coordination between multiple services while
|
|
39
|
+
* maintaining transaction consistency and event emission.
|
|
40
|
+
*/
|
|
41
|
+
export interface PaymentOrchestrationService {
|
|
42
|
+
/** Main orchestration method that handles complete payment workflow */
|
|
43
|
+
orchestratePayment(request: ProcessPaymentRequest): Promise<PaymentResult>;
|
|
44
|
+
/** Handle post-payment workflows (notifications, analytics, etc.) */
|
|
45
|
+
handlePaymentWorkflow(transactionId: string): Promise<void>;
|
|
46
|
+
/** Execute business rules validation before payment processing */
|
|
47
|
+
executeBusinessRules(request: ProcessPaymentRequest): Promise<ValidationResult>;
|
|
48
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type * from './types';
|