@plyaz/types 1.16.4 → 1.16.5

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 +1,2 @@
1
1
  export type * from './types';
2
+ export * from './plans';
@@ -0,0 +1,5 @@
1
+ export declare enum PROVIDER_PRODUCT_STATUS {
2
+ Active = "active",
3
+ Inactive = "inactive",
4
+ Archived = "archived"
5
+ }
@@ -0,0 +1,2 @@
1
+ export * from './enums';
2
+ export type * from './types';
@@ -0,0 +1,180 @@
1
+ import type { CurrencyCode } from '../../../../locale/types';
2
+ import type { PAYMENT_PROVIDER_TYPE } from '../../../provider';
3
+ import type { PROVIDER_PRODUCT_STATUS } from './enums';
4
+ /**
5
+ * Billing cycle for subscription or recurring payments
6
+ */
7
+ export type BillingCycle = 'monthly' | 'weekly' | 'yearly' | 'daily' | 'one time' | 'period' | string;
8
+ /**
9
+ * Parameters to create a new product in the payment provider
10
+ */
11
+ export interface CreateProductParams<T extends object = object> {
12
+ /** ID of the internal plan this product is linked to */
13
+ planId: string;
14
+ /** Optional array of feature IDs associated with the plan */
15
+ featureIds?: string[];
16
+ /** Display name of the product */
17
+ name: string;
18
+ /** Optional detailed description of the product */
19
+ description?: string;
20
+ /** Payment provider (Stripe, PayPal, etc.) */
21
+ provider: PAYMENT_PROVIDER_TYPE;
22
+ /** Optional metadata for additional product info */
23
+ metadata?: T;
24
+ }
25
+ /**
26
+ * Result returned after successfully creating a product in the provider
27
+ */
28
+ export interface CreateProductResult<T extends object = object> {
29
+ /** Provider-specific product ID */
30
+ providerProductId: string;
31
+ /** Provider-specific price ID, if applicable */
32
+ providerPriceId?: string;
33
+ /** Current status of the product in the provider system */
34
+ status: PROVIDER_PRODUCT_STATUS;
35
+ /** Optional metadata returned from provider */
36
+ metadata?: T;
37
+ }
38
+ /**
39
+ * Parameters to update an existing product in the payment provider
40
+ */
41
+ export interface UpdateProductParams<T extends object = object> {
42
+ /** Payment provider (Stripe, PayPal, etc.) */
43
+ provider: PAYMENT_PROVIDER_TYPE;
44
+ /** Provider-specific product ID to update */
45
+ providerProductId: string;
46
+ /** Optional new display name */
47
+ name?: string;
48
+ /** Optional updated description */
49
+ description?: string;
50
+ /** Optional metadata updates */
51
+ metadata?: T;
52
+ }
53
+ /**
54
+ * Result returned after updating a product in the provider
55
+ */
56
+ export interface UpdateProductResult<T extends object = object> {
57
+ /** Provider-specific product ID */
58
+ providerProductId: string;
59
+ /** Current status of the product in the provider system */
60
+ status: PROVIDER_PRODUCT_STATUS;
61
+ /** Optional metadata returned from provider */
62
+ metadata?: T;
63
+ }
64
+ /**
65
+ * Parameters to fetch details of a product from the provider
66
+ */
67
+ export interface FetchProductParams {
68
+ /** Payment provider (Stripe, PayPal, etc.) */
69
+ provider: PAYMENT_PROVIDER_TYPE;
70
+ /** Provider-specific product ID to fetch */
71
+ providerProductId: string;
72
+ }
73
+ /**
74
+ * Result returned when fetching a product from the provider
75
+ */
76
+ export interface FetchProductResult<T extends object = object> {
77
+ /** Provider-specific product ID */
78
+ providerProductId: string;
79
+ /** Display name of the product */
80
+ name: string;
81
+ /** Optional description */
82
+ description?: string;
83
+ /** Optional price in smallest currency unit */
84
+ price?: number;
85
+ /** Optional currency code */
86
+ currency?: CurrencyCode;
87
+ /** Current status of the product in the provider system */
88
+ status: PROVIDER_PRODUCT_STATUS;
89
+ /** Optional metadata returned from provider */
90
+ metadata?: T;
91
+ }
92
+ /**
93
+ * Parameters to deactivate or archive a product in the provider
94
+ */
95
+ export interface DeactivateProductParams {
96
+ /** Payment provider (Stripe, PayPal, etc.) */
97
+ provider: PAYMENT_PROVIDER_TYPE;
98
+ /** Provider-specific product ID to deactivate */
99
+ providerProductId: string;
100
+ /** Optional reason for deactivation */
101
+ reason?: string;
102
+ }
103
+ /**
104
+ * Parameters to create pricing for a product in the provider
105
+ */
106
+ export interface CreatePricingParams<T extends object = object> {
107
+ /** Payment provider (Stripe, PayPal, etc.) */
108
+ provider: PAYMENT_PROVIDER_TYPE;
109
+ /** Provider-specific product ID */
110
+ providerProductId: string;
111
+ /** Amount in the smallest currency unit (e.g., cents) */
112
+ amount: number;
113
+ /** Currency code (ISO) */
114
+ currency: CurrencyCode;
115
+ /** Billing cycle for the product */
116
+ billingCycle: BillingCycle;
117
+ /** Optional number of trial days */
118
+ trialDays?: number;
119
+ /** Optional metadata for pricing */
120
+ metadata?: T;
121
+ }
122
+ /**
123
+ * Result returned after creating pricing in the provider
124
+ */
125
+ export interface CreatePricingResult<T extends object = object> {
126
+ /** Provider-specific product ID */
127
+ providerProductId: string;
128
+ /** Provider-specific price ID */
129
+ providerPriceId: string;
130
+ /** Amount in the smallest currency unit */
131
+ amount: number;
132
+ /** Currency code */
133
+ currency: CurrencyCode;
134
+ /** Billing cycle for the product */
135
+ billingCycle: BillingCycle;
136
+ /** Optional trial days */
137
+ trialDays?: number;
138
+ /** Status of the price in the provider system */
139
+ status: PROVIDER_PRODUCT_STATUS;
140
+ /** Optional metadata returned from provider */
141
+ metadata?: T;
142
+ }
143
+ /**
144
+ * Parameters to update existing pricing info in the provider
145
+ */
146
+ export interface UpdatePricingParams<T extends object = object> {
147
+ /** Payment provider (Stripe, PayPal, etc.) */
148
+ provider: PAYMENT_PROVIDER_TYPE;
149
+ /** Provider-specific price ID to update */
150
+ providerPriceId: string;
151
+ /** Optional updated amount in smallest currency unit */
152
+ amount?: number;
153
+ /** Optional updated currency */
154
+ currency?: CurrencyCode;
155
+ /** Optional updated billing cycle */
156
+ billingCycle?: BillingCycle;
157
+ /** Optional updated trial days */
158
+ trialDays?: number;
159
+ /** Optional metadata updates */
160
+ metadata?: T;
161
+ }
162
+ /**
163
+ * Result returned after updating pricing in the provider
164
+ */
165
+ export interface UpdatePricingResult<T extends object = object> {
166
+ /** Provider-specific price ID */
167
+ providerPriceId: string;
168
+ /** Updated amount in smallest currency unit */
169
+ amount: number;
170
+ /** Updated currency code */
171
+ currency: CurrencyCode;
172
+ /** Updated billing cycle */
173
+ billingCycle: BillingCycle;
174
+ /** Updated trial days, if any */
175
+ trialDays?: number;
176
+ /** Status of the price in the provider system */
177
+ status: PROVIDER_PRODUCT_STATUS;
178
+ /** Optional metadata returned from provider */
179
+ metadata?: T;
180
+ }
@@ -1,9 +1,9 @@
1
1
  import type { CurrencyCode } from '../../../locale/types';
2
2
  import type { ProviderHealthStatus } from '../../../features';
3
- import type { BaseProviderConfig } from '../../gateways';
3
+ import type { BaseProviderConfig, CreatePricingParams, CreatePricingResult, CreateProductParams, CreateProductResult, DeactivateProductParams, FetchProductParams, FetchProductResult, UpdatePricingParams, UpdatePricingResult, UpdateProductParams, UpdateProductResult } from '../../gateways';
4
4
  import type { PaymentResult, ProcessPaymentRequest } from '../../request';
5
5
  import type { FeeBreakdown, Money } from '../../transaction';
6
- import type { AdapterConfiguration, CreateCustomerParams, CreateSubscriptionParams, CustomerResult, FeeCalculationOptions, FeeStructure, PaymentStatusResult, PayoutParams, PayoutResult, RefundParams, RefundResult, SavedPaymentMethod, SavedPaymentMethodResult, SavePaymentMethodParams, SubscriptionResult, TransactionDetails, TransactionHistory, TransactionHistoryParams, WebhookPayload, WebhookResult } from '../core';
6
+ import type { AdapterConfiguration, CreateCustomerParams, CreateSubscriptionParams, CustomerResult, FeeCalculationOptions, FeeStructure, PaymentStatusResult, PayoutParams, PayoutResult, RefundParams, RefundResult, SavedPaymentMethod, SavedPaymentMethodResult, SavePaymentMethodParams, SubscriptionResult, TransactionDetails, TransactionHistory, TransactionHistoryParams, WebhookPayload, WebhookResult, WithdrawalParams, WithdrawalResult } from '../core';
7
7
  import type { ProviderCapabilities, ProviderConfiguration } from '../payment-provider';
8
8
  import type { PAYMENT_METHOD, PAYMENT_PROVIDER_TYPE } from '../provider-capability';
9
9
  /**
@@ -201,9 +201,27 @@ export interface PaymentAdapter {
201
201
  * Process payout to recipient (optional)
202
202
  */
203
203
  processPayout?(params: PayoutParams): Promise<PayoutResult>;
204
+ /**
205
+ * Process withdrawal from a user's balance (optional)
206
+ * This method represents a user-initiated request to move funds from their platform account
207
+ * to an external destination, which the provider then processes as a payout.
208
+ * * @param params - Withdrawal request parameters
209
+ * @returns Withdrawal result with status
210
+ */
211
+ processWithdrawal?(params: WithdrawalParams): Promise<WithdrawalResult>;
204
212
  /**
205
213
  * Get transaction history from provider (optional).
206
214
  * Only implement if provider supports historical transaction queries.
207
215
  */
208
216
  getTransactionHistory?(params: TransactionHistoryParams): Promise<TransactionHistory>;
217
+ /** Create product + pricing in provider */
218
+ createProduct?(params: CreateProductParams): Promise<CreateProductResult>;
219
+ /** Update product or price info in provider */
220
+ updateProduct?(params: UpdateProductParams): Promise<UpdateProductResult>;
221
+ /** Fetch provider product details */
222
+ fetchProduct?(params: FetchProductParams): Promise<FetchProductResult>;
223
+ /** Deactivate or archive provider product */
224
+ deactivateProduct?(params: DeactivateProductParams): Promise<boolean>;
225
+ createPricing?(params: CreatePricingParams): Promise<CreatePricingResult>;
226
+ updatePricing?(params: UpdatePricingParams): Promise<UpdatePricingResult>;
209
227
  }
@@ -0,0 +1,8 @@
1
+ export declare enum WITHDRAWAL_STATUS {
2
+ Requested = "requested",
3
+ Approved = "approved",
4
+ InTransit = "in_transit",
5
+ Completed = "completed",
6
+ Failed = "failed",
7
+ Cancelled = "cancelled"
8
+ }
@@ -1 +1,2 @@
1
1
  export type * from './types';
2
+ export * from './enums';
@@ -1,6 +1,7 @@
1
1
  import type { CurrencyCode } from '../../../locale/types';
2
2
  import type { FeeBreakdown, Money } from '../../transaction';
3
3
  import type { PAYMENT_METHOD, PAYMENT_PROVIDER_TYPE, PAYMENT_STATUS } from '../provider-capability';
4
+ import type { WITHDRAWAL_STATUS } from './enums';
4
5
  /**
5
6
  * Parameters required to initiate a refund.
6
7
  * Refunds can be full or partial.
@@ -350,31 +351,29 @@ export interface SavedPaymentMethod<TMetadata extends object = object> {
350
351
  metadata?: TMetadata;
351
352
  }
352
353
  export interface CreateSubscriptionParams<TMetadata extends object = object> {
353
- /** Plyaz user ID */
354
+ /** Plyaz user ID (Stripe customer ID or your internal user ID mapped to Stripe) */
354
355
  userId: string;
355
- /** Amount per billing cycle */
356
- amount: Money;
357
- /** Billing cycle (in ISO 8601 duration or custom format) */
358
- billingCycle: string;
359
- /** Payment method to charge */
356
+ /** Plan to subscribe the user to: 'standard' | 'pro' | 'enterprise' */
357
+ plan: 'standard' | 'pro' | 'enterprise';
358
+ /** Payment method to charge (Stripe payment method ID) */
360
359
  paymentMethodId: string;
361
360
  /** Optional trial period in days */
362
361
  trialDays?: number;
363
- /** Subscription metadata */
362
+ /** Optional metadata for additional info */
364
363
  metadata?: TMetadata;
365
364
  }
366
365
  export interface SubscriptionResult<TMetadata extends object = object> {
367
- /** Internal Plyaz subscription ID */
366
+ /** Internal subscription ID */
368
367
  subscriptionId: string;
369
368
  /** Provider subscription ID */
370
369
  providerSubscriptionId?: string;
371
- /** Current subscription status */
370
+ /** Status: active, trialing, paused, canceled, expired */
372
371
  status: 'active' | 'trialing' | 'paused' | 'canceled' | 'expired';
373
372
  /** Next billing date */
374
373
  nextBillingDate?: Date;
375
- /** Start date of subscription */
374
+ /** Subscription start date */
376
375
  startedAt: Date;
377
- /** Metadata and provider payload */
376
+ /** Provider-specific metadata */
378
377
  metadata?: TMetadata;
379
378
  }
380
379
  export interface PayoutParams<TMetadata extends object = object> {
@@ -425,3 +424,50 @@ export interface ReceiptData<TMetadata extends object = object> {
425
424
  total: Money;
426
425
  providerMetadata?: TMetadata;
427
426
  }
427
+ /**
428
+ * Parameters required for a user-initiated withdrawal request.
429
+ * Represents a user requesting to move funds from their platform balance to an external account.
430
+ */
431
+ export interface WithdrawalParams<TMetadata extends object = object> {
432
+ /** Unique ID of the user requesting the withdrawal */
433
+ userId: string;
434
+ /** Amount to withdraw */
435
+ amount: Money;
436
+ /** CurrencyCode of the withdrawal */
437
+ CurrencyCode: CurrencyCode;
438
+ /**
439
+ * Optional ID of the saved external account (bank, card) to send funds to.
440
+ * This is analogous to `destinationId` in Payouts, but tied to a user's saved method.
441
+ */
442
+ destinationAccountId?: string;
443
+ /** Reason or description for the withdrawal (e.g., 'Cashing out earnings') */
444
+ reason?: string;
445
+ /** Optional idempotency key to prevent duplicate requests */
446
+ idempotencyKey?: string;
447
+ /** Additional metadata */
448
+ metadata?: TMetadata;
449
+ }
450
+ /**
451
+ * Result returned after processing a withdrawal request.
452
+ * The status tracks the disbursement process back to the user's account.
453
+ */
454
+ export interface WithdrawalResult<TMetadata extends object = object> {
455
+ /** Internal Plyaz withdrawal ID */
456
+ withdrawalId: string;
457
+ /** Provider-specific transaction ID (often the underlying Payout ID) */
458
+ providerTransactionId?: string;
459
+ /** Current status of the withdrawal */
460
+ status: WITHDRAWAL_STATUS;
461
+ /** Final amount successfully transferred */
462
+ amount: Money;
463
+ /** Any fees deducted from the withdrawal amount */
464
+ fees?: FeeBreakdown;
465
+ /** Timestamp when the withdrawal request was submitted */
466
+ requestedAt: Date;
467
+ /** Estimated or actual completion time */
468
+ completedAt?: Date;
469
+ /** Failure reason message, if status is 'failed' */
470
+ failureReason?: string;
471
+ /** Metadata and provider response */
472
+ metadata?: TMetadata;
473
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plyaz/types",
3
- "version": "1.16.4",
3
+ "version": "1.16.5",
4
4
  "author": "Redeemer Pace",
5
5
  "license": "ISC",
6
6
  "description": "Provides shared TypeScript types and schema utilities for validation and parsing in the @playz ecosystem.",