@explorins/pers-sdk 1.6.4 → 1.6.6
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/README.md +63 -37
- package/dist/analytics/index.d.ts +0 -16
- package/dist/analytics/index.d.ts.map +1 -1
- package/dist/analytics.cjs +5 -73
- package/dist/analytics.cjs.map +1 -1
- package/dist/analytics.js +1 -72
- package/dist/analytics.js.map +1 -1
- package/dist/business/index.d.ts +0 -24
- package/dist/business/index.d.ts.map +1 -1
- package/dist/business.cjs +5 -273
- package/dist/business.cjs.map +1 -1
- package/dist/business.js +1 -272
- package/dist/business.js.map +1 -1
- package/dist/campaign/api/campaign-api.d.ts +3 -3
- package/dist/campaign/api/campaign-api.d.ts.map +1 -1
- package/dist/campaign/index.d.ts +0 -34
- package/dist/campaign/index.d.ts.map +1 -1
- package/dist/campaign.cjs +5 -447
- package/dist/campaign.cjs.map +1 -1
- package/dist/campaign.js +1 -446
- package/dist/campaign.js.map +1 -1
- package/dist/chunks/analytics-service-CitlimKJ.cjs +49 -0
- package/dist/chunks/analytics-service-CitlimKJ.cjs.map +1 -0
- package/dist/chunks/analytics-service-CxyrOwel.js +46 -0
- package/dist/chunks/analytics-service-CxyrOwel.js.map +1 -0
- package/dist/chunks/{token-sdk-BW4kkJb3.js → base-token-service-BSXDwrcq.js} +138 -204
- package/dist/chunks/base-token-service-BSXDwrcq.js.map +1 -0
- package/dist/chunks/{token-sdk-CiAbOb6c.cjs → base-token-service-CYuqPPs0.cjs} +140 -207
- package/dist/chunks/base-token-service-CYuqPPs0.cjs.map +1 -0
- package/dist/chunks/business-service-Cq3-oksM.cjs +241 -0
- package/dist/chunks/business-service-Cq3-oksM.cjs.map +1 -0
- package/dist/chunks/business-service-DrC-TNGa.js +238 -0
- package/dist/chunks/business-service-DrC-TNGa.js.map +1 -0
- package/dist/chunks/campaign-service-CWK9I388.cjs +403 -0
- package/dist/chunks/campaign-service-CWK9I388.cjs.map +1 -0
- package/dist/chunks/campaign-service-Dd7gMjC9.js +400 -0
- package/dist/chunks/campaign-service-Dd7gMjC9.js.map +1 -0
- package/dist/chunks/donation-service-CyJS4DIZ.js +47 -0
- package/dist/chunks/donation-service-CyJS4DIZ.js.map +1 -0
- package/dist/chunks/donation-service-D-xFrONi.cjs +50 -0
- package/dist/chunks/donation-service-D-xFrONi.cjs.map +1 -0
- package/dist/chunks/{index-CJ9Jfa4A.js → explorer.utils-Ckll15ja.js} +108 -172
- package/dist/chunks/explorer.utils-Ckll15ja.js.map +1 -0
- package/dist/chunks/{index-CzEluQmf.cjs → explorer.utils-GpskbLl1.cjs} +106 -174
- package/dist/chunks/explorer.utils-GpskbLl1.cjs.map +1 -0
- package/dist/chunks/index-BtDNXaFq.js +13 -0
- package/dist/chunks/index-BtDNXaFq.js.map +1 -0
- package/dist/chunks/index-CMk3Aqkk.cjs +15 -0
- package/dist/chunks/index-CMk3Aqkk.cjs.map +1 -0
- package/dist/chunks/payment-service-B4qx0qiE.cjs +220 -0
- package/dist/chunks/payment-service-B4qx0qiE.cjs.map +1 -0
- package/dist/chunks/payment-service-DfCBFosx.js +217 -0
- package/dist/chunks/payment-service-DfCBFosx.js.map +1 -0
- package/dist/chunks/pers-sdk-CajYwGkL.cjs +5850 -0
- package/dist/chunks/pers-sdk-CajYwGkL.cjs.map +1 -0
- package/dist/chunks/pers-sdk-eO4XUi8w.js +5817 -0
- package/dist/chunks/pers-sdk-eO4XUi8w.js.map +1 -0
- package/dist/chunks/redemption-service-7qbeQxEM.cjs +330 -0
- package/dist/chunks/redemption-service-7qbeQxEM.cjs.map +1 -0
- package/dist/chunks/redemption-service-BT0J5Iy7.js +327 -0
- package/dist/chunks/redemption-service-BT0J5Iy7.js.map +1 -0
- package/dist/chunks/tenant-service-Ba7xrWED.cjs +171 -0
- package/dist/chunks/tenant-service-Ba7xrWED.cjs.map +1 -0
- package/dist/chunks/tenant-service-DELk412y.js +168 -0
- package/dist/chunks/tenant-service-DELk412y.js.map +1 -0
- package/dist/chunks/token-service-BWScn8Qa.cjs +208 -0
- package/dist/chunks/token-service-BWScn8Qa.cjs.map +1 -0
- package/dist/chunks/token-service-CpVwC5Eb.js +205 -0
- package/dist/chunks/token-service-CpVwC5Eb.js.map +1 -0
- package/dist/chunks/user-service-D1Rn4U8u.cjs +153 -0
- package/dist/chunks/user-service-D1Rn4U8u.cjs.map +1 -0
- package/dist/chunks/user-service-D6mTa_WZ.js +150 -0
- package/dist/chunks/user-service-D6mTa_WZ.js.map +1 -0
- package/dist/chunks/{index-BfOoX87y.cjs → web3-chain-service-BYkj61DN.cjs} +1 -33
- package/dist/chunks/web3-chain-service-BYkj61DN.cjs.map +1 -0
- package/dist/chunks/{index-CM21r58m.js → web3-chain-service-DN6tJmvK.js} +2 -31
- package/dist/chunks/web3-chain-service-DN6tJmvK.js.map +1 -0
- package/dist/core/auth/auth-provider.interface.d.ts +32 -69
- package/dist/core/auth/auth-provider.interface.d.ts.map +1 -1
- package/dist/core/auth/default-auth-provider.d.ts +15 -58
- package/dist/core/auth/default-auth-provider.d.ts.map +1 -1
- package/dist/core/auth/index.d.ts +10 -12
- package/dist/core/auth/index.d.ts.map +1 -1
- package/dist/core/auth/refresh-manager.d.ts +18 -0
- package/dist/core/auth/refresh-manager.d.ts.map +1 -0
- package/dist/core/auth/services/auth-service.d.ts +11 -6
- package/dist/core/auth/services/auth-service.d.ts.map +1 -1
- package/dist/core/auth/token-storage.d.ts +27 -47
- package/dist/core/auth/token-storage.d.ts.map +1 -1
- package/dist/core/errors/index.d.ts +1 -5
- package/dist/core/errors/index.d.ts.map +1 -1
- package/dist/core/index.d.ts +4 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/pers-api-client.d.ts +10 -126
- package/dist/core/pers-api-client.d.ts.map +1 -1
- package/dist/core/pers-config.d.ts +8 -3
- package/dist/core/pers-config.d.ts.map +1 -1
- package/dist/core/utils/jwt.function.d.ts.map +1 -1
- package/dist/core.cjs +22 -17
- package/dist/core.cjs.map +1 -1
- package/dist/core.js +13 -13
- package/dist/donation/index.d.ts +0 -15
- package/dist/donation/index.d.ts.map +1 -1
- package/dist/donation.cjs +5 -75
- package/dist/donation.cjs.map +1 -1
- package/dist/donation.js +1 -74
- package/dist/donation.js.map +1 -1
- package/dist/index.cjs +51 -56
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +16 -15
- package/dist/index.js.map +1 -1
- package/dist/managers/analytics-manager.d.ts +290 -10
- package/dist/managers/analytics-manager.d.ts.map +1 -1
- package/dist/managers/auth-manager.d.ts +123 -23
- package/dist/managers/auth-manager.d.ts.map +1 -1
- package/dist/managers/business-manager.d.ts +273 -18
- package/dist/managers/business-manager.d.ts.map +1 -1
- package/dist/managers/campaign-manager.d.ts +585 -46
- package/dist/managers/campaign-manager.d.ts.map +1 -1
- package/dist/managers/donation-manager.d.ts +5 -5
- package/dist/managers/donation-manager.d.ts.map +1 -1
- package/dist/managers/file-manager.d.ts +430 -13
- package/dist/managers/file-manager.d.ts.map +1 -1
- package/dist/managers/purchase-manager.d.ts +340 -15
- package/dist/managers/purchase-manager.d.ts.map +1 -1
- package/dist/managers/redemption-manager.d.ts +450 -27
- package/dist/managers/redemption-manager.d.ts.map +1 -1
- package/dist/managers/tenant-manager.d.ts +5 -5
- package/dist/managers/tenant-manager.d.ts.map +1 -1
- package/dist/managers/token-manager.d.ts +245 -21
- package/dist/managers/token-manager.d.ts.map +1 -1
- package/dist/managers/transaction-manager.d.ts +447 -18
- package/dist/managers/transaction-manager.d.ts.map +1 -1
- package/dist/managers/user-manager.d.ts +216 -14
- package/dist/managers/user-manager.d.ts.map +1 -1
- package/dist/managers/web3-manager.d.ts +4 -4
- package/dist/managers/web3-manager.d.ts.map +1 -1
- package/dist/package.json +9 -2
- package/dist/payment/index.d.ts +0 -21
- package/dist/payment/index.d.ts.map +1 -1
- package/dist/payment.cjs +5 -255
- package/dist/payment.cjs.map +1 -1
- package/dist/payment.js +1 -254
- package/dist/payment.js.map +1 -1
- package/dist/pers-sdk.d.ts +141 -34
- package/dist/pers-sdk.d.ts.map +1 -1
- package/dist/redemption/index.d.ts +0 -25
- package/dist/redemption/index.d.ts.map +1 -1
- package/dist/redemption.cjs +5 -365
- package/dist/redemption.cjs.map +1 -1
- package/dist/redemption.js +1 -364
- package/dist/redemption.js.map +1 -1
- package/dist/tenant/index.d.ts +0 -22
- package/dist/tenant/index.d.ts.map +1 -1
- package/dist/tenant.cjs +5 -203
- package/dist/tenant.cjs.map +1 -1
- package/dist/tenant.js +1 -202
- package/dist/tenant.js.map +1 -1
- package/dist/token.cjs +6 -6
- package/dist/token.js +2 -2
- package/dist/transaction/index.d.ts +0 -22
- package/dist/transaction/index.d.ts.map +1 -1
- package/dist/transaction.cjs +0 -40
- package/dist/transaction.cjs.map +1 -1
- package/dist/transaction.js +1 -40
- package/dist/transaction.js.map +1 -1
- package/dist/user/index.d.ts +0 -25
- package/dist/user/index.d.ts.map +1 -1
- package/dist/user.cjs +5 -185
- package/dist/user.cjs.map +1 -1
- package/dist/user.js +1 -184
- package/dist/user.js.map +1 -1
- package/dist/web3/index.d.ts +0 -11
- package/dist/web3/index.d.ts.map +1 -1
- package/dist/web3-chain/index.d.ts +0 -9
- package/dist/web3-chain/index.d.ts.map +1 -1
- package/dist/web3-chain/services/getWeb3FCD.service.d.ts.map +1 -1
- package/dist/web3-chain.cjs +5 -5
- package/dist/web3-chain.js +2 -1
- package/dist/web3-chain.js.map +1 -1
- package/dist/web3.cjs +6 -10
- package/dist/web3.cjs.map +1 -1
- package/dist/web3.js +1 -4
- package/dist/web3.js.map +1 -1
- package/package.json +9 -2
- package/dist/chunks/base-token-service-D0KANDgM.js +0 -139
- package/dist/chunks/base-token-service-D0KANDgM.js.map +0 -1
- package/dist/chunks/base-token-service-zNfPjHRx.cjs +0 -141
- package/dist/chunks/base-token-service-zNfPjHRx.cjs.map +0 -1
- package/dist/chunks/index-BfOoX87y.cjs.map +0 -1
- package/dist/chunks/index-CJ9Jfa4A.js.map +0 -1
- package/dist/chunks/index-CM21r58m.js.map +0 -1
- package/dist/chunks/index-CzEluQmf.cjs.map +0 -1
- package/dist/chunks/pers-sdk-DbPwFKrf.cjs +0 -3378
- package/dist/chunks/pers-sdk-DbPwFKrf.cjs.map +0 -1
- package/dist/chunks/pers-sdk-Z6MKeFBX.js +0 -3353
- package/dist/chunks/pers-sdk-Z6MKeFBX.js.map +0 -1
- package/dist/chunks/token-sdk-BW4kkJb3.js.map +0 -1
- package/dist/chunks/token-sdk-CiAbOb6c.cjs.map +0 -1
- package/dist/core/auth/auth-constants.d.ts +0 -33
- package/dist/core/auth/auth-constants.d.ts.map +0 -1
- package/dist/core/auth/auth-errors.d.ts +0 -8
- package/dist/core/auth/auth-errors.d.ts.map +0 -1
- package/dist/core/auth/create-auth-provider.d.ts +0 -27
- package/dist/core/auth/create-auth-provider.d.ts.map +0 -1
- package/dist/core/auth/token-refresh.d.ts +0 -91
- package/dist/core/auth/token-refresh.d.ts.map +0 -1
|
@@ -1,44 +1,369 @@
|
|
|
1
1
|
import { PersApiClient } from '../core/pers-api-client';
|
|
2
|
-
import {
|
|
2
|
+
import { PaymentService } from '../payment';
|
|
3
3
|
import type { PaymentIntentDTO, PurchaseDTO, PurchaseTokenDTO } from '../shared/interfaces/pers-shared-lib.interfaces';
|
|
4
4
|
/**
|
|
5
5
|
* Purchase Manager - Clean, high-level interface for purchase operations
|
|
6
6
|
*
|
|
7
|
-
* Provides a
|
|
8
|
-
*
|
|
7
|
+
* Provides a comprehensive API for purchase and payment management including payment
|
|
8
|
+
* intent creation, purchase token handling, user purchase history, and integration
|
|
9
|
+
* with payment processors. Handles both fiat currency payments and loyalty token
|
|
10
|
+
* purchases within the ecosystem.
|
|
11
|
+
*
|
|
12
|
+
* @group Managers
|
|
13
|
+
* @category Purchase Management
|
|
14
|
+
*
|
|
15
|
+
* @example Basic Purchase Operations
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // Create payment intent for fiat purchase
|
|
18
|
+
* const paymentIntent = await sdk.purchases.createPaymentIntent(
|
|
19
|
+
* 50.00,
|
|
20
|
+
* 'USD',
|
|
21
|
+
* 'customer@example.com',
|
|
22
|
+
* 'Loyalty token bundle purchase'
|
|
23
|
+
* );
|
|
24
|
+
* console.log('Payment intent created:', paymentIntent.id);
|
|
25
|
+
*
|
|
26
|
+
* // Get available purchase tokens
|
|
27
|
+
* const tokens = await sdk.purchases.getActivePurchaseTokens();
|
|
28
|
+
* console.log(`${tokens.length} token packages available`);
|
|
29
|
+
*
|
|
30
|
+
* // View purchase history
|
|
31
|
+
* const purchases = await sdk.purchases.getAllUserPurchases();
|
|
32
|
+
* console.log(`User has made ${purchases.length} purchases`);
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @example Purchase Token Discovery
|
|
36
|
+
* ```typescript
|
|
37
|
+
* // Browse available token packages
|
|
38
|
+
* const availableTokens = await sdk.purchases.getActivePurchaseTokens(true);
|
|
39
|
+
*
|
|
40
|
+
* console.log('💎 Available Token Packages:');
|
|
41
|
+
* availableTokens.forEach(token => {
|
|
42
|
+
* console.log(`\n${token.name}`);
|
|
43
|
+
* console.log(`Price: $${token.price} ${token.currency}`);
|
|
44
|
+
* console.log(`Tokens: ${token.tokenAmount} ${token.tokenSymbol}`);
|
|
45
|
+
* console.log(`Description: ${token.description}`);
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @example Payment Processing
|
|
50
|
+
* ```typescript
|
|
51
|
+
* // Create payment for specific token package
|
|
52
|
+
* const selectedPackage = availableTokens[0];
|
|
53
|
+
* const paymentIntent = await sdk.purchases.createPaymentIntent(
|
|
54
|
+
* selectedPackage.price,
|
|
55
|
+
* selectedPackage.currency,
|
|
56
|
+
* 'user@example.com',
|
|
57
|
+
* `Purchase: ${selectedPackage.name}`
|
|
58
|
+
* );
|
|
59
|
+
*
|
|
60
|
+
* // Use payment intent client secret for frontend payment processing
|
|
61
|
+
* console.log('Payment client secret:', paymentIntent.clientSecret);
|
|
62
|
+
* ```
|
|
9
63
|
*/
|
|
10
64
|
export declare class PurchaseManager {
|
|
11
65
|
private apiClient;
|
|
12
|
-
private
|
|
66
|
+
private paymentService;
|
|
13
67
|
constructor(apiClient: PersApiClient);
|
|
14
68
|
/**
|
|
15
69
|
* Create a payment intent
|
|
16
70
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
71
|
+
* Creates a payment intent for processing fiat currency payments through
|
|
72
|
+
* integrated payment processors (e.g., Stripe). Payment intents are used to
|
|
73
|
+
* securely handle payment processing on the frontend while maintaining
|
|
74
|
+
* server-side validation and security.
|
|
75
|
+
*
|
|
76
|
+
* @param amount - Payment amount in the specified currency's smallest unit (e.g., cents for USD)
|
|
77
|
+
* @param currency - Payment currency code (e.g., 'USD', 'EUR', 'GBP')
|
|
78
|
+
* @param receiptEmail - Email address for sending payment receipt
|
|
79
|
+
* @param description - Human-readable description of the payment
|
|
80
|
+
* @returns Promise resolving to payment intent with client secret
|
|
81
|
+
* @throws {PersApiError} When payment processing is unavailable or validation fails
|
|
82
|
+
*
|
|
83
|
+
* @example Simple Payment Intent
|
|
84
|
+
* ```typescript
|
|
85
|
+
* try {
|
|
86
|
+
* const paymentIntent = await sdk.purchases.createPaymentIntent(
|
|
87
|
+
* 2500, // $25.00 in cents
|
|
88
|
+
* 'USD',
|
|
89
|
+
* 'customer@example.com',
|
|
90
|
+
* '1000 Loyalty Points Package'
|
|
91
|
+
* );
|
|
92
|
+
*
|
|
93
|
+
* console.log('💳 Payment Intent Created:');
|
|
94
|
+
* console.log('ID:', paymentIntent.id);
|
|
95
|
+
* console.log('Amount:', paymentIntent.amount / 100, paymentIntent.currency);
|
|
96
|
+
* console.log('Status:', paymentIntent.status);
|
|
97
|
+
* console.log('Client Secret:', paymentIntent.clientSecret);
|
|
98
|
+
*
|
|
99
|
+
* // Use client secret in frontend payment processing
|
|
100
|
+
* // Example with Stripe Elements:
|
|
101
|
+
* // const { confirmPayment } = useStripe();
|
|
102
|
+
* // await confirmPayment({
|
|
103
|
+
* // elements,
|
|
104
|
+
* // confirmParams: {
|
|
105
|
+
* // return_url: 'https://yourapp.com/payment-success'
|
|
106
|
+
* // }
|
|
107
|
+
* // });
|
|
108
|
+
*
|
|
109
|
+
* } catch (error) {
|
|
110
|
+
* console.log('Payment intent creation failed:', error.message);
|
|
111
|
+
* }
|
|
112
|
+
* ```
|
|
113
|
+
*
|
|
114
|
+
* @example Token Package Purchase
|
|
115
|
+
* ```typescript
|
|
116
|
+
* // Get available token packages first
|
|
117
|
+
* const packages = await sdk.purchases.getActivePurchaseTokens(true);
|
|
118
|
+
* const selectedPackage = packages.find(p => p.name === 'Starter Package');
|
|
119
|
+
*
|
|
120
|
+
* if (selectedPackage) {
|
|
121
|
+
* const paymentIntent = await sdk.purchases.createPaymentIntent(
|
|
122
|
+
* selectedPackage.price * 100, // Convert to cents
|
|
123
|
+
* selectedPackage.currency,
|
|
124
|
+
* 'user@example.com',
|
|
125
|
+
* `Purchase: ${selectedPackage.name} - ${selectedPackage.tokenAmount} ${selectedPackage.tokenSymbol}`
|
|
126
|
+
* );
|
|
127
|
+
*
|
|
128
|
+
* console.log(`Payment setup for ${selectedPackage.name}`);
|
|
129
|
+
* console.log(`Will receive: ${selectedPackage.tokenAmount} ${selectedPackage.tokenSymbol}`);
|
|
130
|
+
* console.log(`Payment amount: $${selectedPackage.price}`);
|
|
131
|
+
*
|
|
132
|
+
* // Store payment intent for frontend processing
|
|
133
|
+
* localStorage.setItem('paymentIntentId', paymentIntent.id);
|
|
134
|
+
* localStorage.setItem('expectedTokens', selectedPackage.tokenAmount.toString());
|
|
135
|
+
* }
|
|
136
|
+
* ```
|
|
137
|
+
*
|
|
138
|
+
* @example Subscription Payment
|
|
139
|
+
* ```typescript
|
|
140
|
+
* // Create payment intent for recurring subscription
|
|
141
|
+
* const subscriptionPayment = await sdk.purchases.createPaymentIntent(
|
|
142
|
+
* 999, // $9.99/month
|
|
143
|
+
* 'USD',
|
|
144
|
+
* 'subscriber@example.com',
|
|
145
|
+
* 'Premium Loyalty Membership - Monthly'
|
|
146
|
+
* );
|
|
147
|
+
*
|
|
148
|
+
* console.log('Subscription payment intent:', subscriptionPayment.id);
|
|
149
|
+
* // Payment processor will handle recurring billing setup
|
|
150
|
+
* ```
|
|
22
151
|
*/
|
|
23
152
|
createPaymentIntent(amount: number, currency: string, receiptEmail: string, description: string): Promise<PaymentIntentDTO>;
|
|
24
153
|
/**
|
|
25
154
|
* Get active purchase tokens
|
|
26
155
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
156
|
+
* Retrieves available token packages that users can purchase with fiat currency.
|
|
157
|
+
* These packages represent bundles of loyalty tokens at various price points,
|
|
158
|
+
* often with bonus tokens for larger purchases.
|
|
159
|
+
*
|
|
160
|
+
* @param active - Optional filter to show only active packages (default: all packages)
|
|
161
|
+
* @returns Promise resolving to array of purchase token packages
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* const allPackages = await sdk.purchases.getActivePurchaseTokens();
|
|
166
|
+
* const activeOnly = await sdk.purchases.getActivePurchaseTokens(true);
|
|
167
|
+
*
|
|
168
|
+
* console.log('💎 Token Package Catalog:');
|
|
169
|
+
*
|
|
170
|
+
* activeOnly.forEach(package => {
|
|
171
|
+
* console.log(`\n📦 ${package.name}`);
|
|
172
|
+
* console.log(`💰 Price: $${package.price} ${package.currency}`);
|
|
173
|
+
* console.log(`🪙 Tokens: ${package.tokenAmount} ${package.tokenSymbol}`);
|
|
174
|
+
* console.log(`📝 ${package.description}`);
|
|
175
|
+
*
|
|
176
|
+
* // Calculate value per token
|
|
177
|
+
* const costPerToken = package.price / package.tokenAmount;
|
|
178
|
+
* console.log(`💡 Value: $${costPerToken.toFixed(4)} per token`);
|
|
179
|
+
*
|
|
180
|
+
* if (package.bonusTokens && package.bonusTokens > 0) {
|
|
181
|
+
* console.log(`🎁 Bonus: +${package.bonusTokens} extra tokens`);
|
|
182
|
+
* const totalTokens = package.tokenAmount + package.bonusTokens;
|
|
183
|
+
* const actualCostPerToken = package.price / totalTokens;
|
|
184
|
+
* console.log(`💡 With bonus: $${actualCostPerToken.toFixed(4)} per token`);
|
|
185
|
+
* }
|
|
186
|
+
*
|
|
187
|
+
* if (package.validUntil) {
|
|
188
|
+
* console.log(`⏰ Valid until: ${new Date(package.validUntil).toLocaleDateString()}`);
|
|
189
|
+
* }
|
|
190
|
+
* });
|
|
191
|
+
*
|
|
192
|
+
* // Find best value package
|
|
193
|
+
* const bestValue = activeOnly.reduce((best, current) => {
|
|
194
|
+
* const currentValue = current.price / (current.tokenAmount + (current.bonusTokens || 0));
|
|
195
|
+
* const bestValue = best.price / (best.tokenAmount + (best.bonusTokens || 0));
|
|
196
|
+
* return currentValue < bestValue ? current : best;
|
|
197
|
+
* });
|
|
198
|
+
*
|
|
199
|
+
* console.log(`\n🌟 Best Value: ${bestValue.name}`);
|
|
200
|
+
* ```
|
|
201
|
+
*
|
|
202
|
+
* @example Filter by Currency and Price
|
|
203
|
+
* ```typescript
|
|
204
|
+
* const packages = await sdk.purchases.getActivePurchaseTokens(true);
|
|
205
|
+
*
|
|
206
|
+
* // Filter by currency
|
|
207
|
+
* const usdPackages = packages.filter(p => p.currency === 'USD');
|
|
208
|
+
* const eurPackages = packages.filter(p => p.currency === 'EUR');
|
|
209
|
+
*
|
|
210
|
+
* console.log(`USD packages: ${usdPackages.length}`);
|
|
211
|
+
* console.log(`EUR packages: ${eurPackages.length}`);
|
|
212
|
+
*
|
|
213
|
+
* // Filter by price range
|
|
214
|
+
* const budgetPackages = packages.filter(p => p.price <= 25);
|
|
215
|
+
* const premiumPackages = packages.filter(p => p.price > 100);
|
|
216
|
+
*
|
|
217
|
+
* console.log(`Budget options (≤$25): ${budgetPackages.length}`);
|
|
218
|
+
* console.log(`Premium options (>$100): ${premiumPackages.length}`);
|
|
219
|
+
*
|
|
220
|
+
* // Sort by token amount
|
|
221
|
+
* const sortedByTokens = [...packages].sort((a, b) =>
|
|
222
|
+
* (b.tokenAmount + (b.bonusTokens || 0)) - (a.tokenAmount + (a.bonusTokens || 0))
|
|
223
|
+
* );
|
|
224
|
+
*
|
|
225
|
+
* console.log('\n🎯 Top 3 by token amount:');
|
|
226
|
+
* sortedByTokens.slice(0, 3).forEach((pkg, index) => {
|
|
227
|
+
* const totalTokens = pkg.tokenAmount + (pkg.bonusTokens || 0);
|
|
228
|
+
* console.log(`${index + 1}. ${pkg.name}: ${totalTokens} tokens`);
|
|
229
|
+
* });
|
|
230
|
+
* ```
|
|
29
231
|
*/
|
|
30
232
|
getActivePurchaseTokens(active?: boolean): Promise<PurchaseTokenDTO[]>;
|
|
31
233
|
/**
|
|
32
234
|
* Get all user purchases
|
|
33
235
|
*
|
|
34
|
-
*
|
|
236
|
+
* Retrieves the complete purchase history for the authenticated user,
|
|
237
|
+
* including both successful and failed purchases. Provides insights into
|
|
238
|
+
* user spending patterns, token acquisition, and payment history.
|
|
239
|
+
*
|
|
240
|
+
* @returns Promise resolving to array of user's purchase records
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```typescript
|
|
244
|
+
* const userPurchases = await sdk.purchases.getAllUserPurchases();
|
|
245
|
+
*
|
|
246
|
+
* console.log(`📜 Purchase History (${userPurchases.length} purchases):`);
|
|
247
|
+
*
|
|
248
|
+
* userPurchases.forEach((purchase, index) => {
|
|
249
|
+
* console.log(`\n${index + 1}. Purchase #${purchase.id}`);
|
|
250
|
+
* console.log(`📅 Date: ${new Date(purchase.createdAt).toLocaleDateString()}`);
|
|
251
|
+
* console.log(`💰 Amount: $${purchase.amount} ${purchase.currency}`);
|
|
252
|
+
* console.log(`📊 Status: ${purchase.status}`);
|
|
253
|
+
*
|
|
254
|
+
* if (purchase.description) {
|
|
255
|
+
* console.log(`📝 Description: ${purchase.description}`);
|
|
256
|
+
* }
|
|
257
|
+
*
|
|
258
|
+
* if (purchase.tokensReceived) {
|
|
259
|
+
* console.log(`🪙 Tokens received: ${purchase.tokensReceived}`);
|
|
260
|
+
* }
|
|
261
|
+
*
|
|
262
|
+
* if (purchase.paymentMethod) {
|
|
263
|
+
* console.log(`💳 Payment method: ${purchase.paymentMethod}`);
|
|
264
|
+
* }
|
|
265
|
+
*
|
|
266
|
+
* if (purchase.receiptEmail) {
|
|
267
|
+
* console.log(`📧 Receipt sent to: ${purchase.receiptEmail}`);
|
|
268
|
+
* }
|
|
269
|
+
* });
|
|
270
|
+
*
|
|
271
|
+
* // Calculate purchase statistics
|
|
272
|
+
* const successfulPurchases = userPurchases.filter(p => p.status === 'COMPLETED');
|
|
273
|
+
* const totalSpent = successfulPurchases.reduce((sum, p) => sum + p.amount, 0);
|
|
274
|
+
* const totalTokens = successfulPurchases.reduce((sum, p) => sum + (p.tokensReceived || 0), 0);
|
|
275
|
+
*
|
|
276
|
+
* console.log('\n📊 Purchase Statistics:');
|
|
277
|
+
* console.log(`Total purchases: ${userPurchases.length}`);
|
|
278
|
+
* console.log(`Successful purchases: ${successfulPurchases.length}`);
|
|
279
|
+
* console.log(`Total spent: $${totalSpent.toFixed(2)}`);
|
|
280
|
+
* console.log(`Total tokens acquired: ${totalTokens}`);
|
|
281
|
+
*
|
|
282
|
+
* if (totalTokens > 0) {
|
|
283
|
+
* const avgCostPerToken = totalSpent / totalTokens;
|
|
284
|
+
* console.log(`Average cost per token: $${avgCostPerToken.toFixed(4)}`);
|
|
285
|
+
* }
|
|
286
|
+
* ```
|
|
287
|
+
*
|
|
288
|
+
* @example Purchase Analysis
|
|
289
|
+
* ```typescript
|
|
290
|
+
* const purchases = await sdk.purchases.getAllUserPurchases();
|
|
291
|
+
*
|
|
292
|
+
* // Analyze by time period
|
|
293
|
+
* const last30Days = purchases.filter(p =>
|
|
294
|
+
* new Date(p.createdAt) > new Date(Date.now() - 30 * 24 * 60 * 60 * 1000)
|
|
295
|
+
* );
|
|
296
|
+
*
|
|
297
|
+
* const last6Months = purchases.filter(p =>
|
|
298
|
+
* new Date(p.createdAt) > new Date(Date.now() - 180 * 24 * 60 * 60 * 1000)
|
|
299
|
+
* );
|
|
300
|
+
*
|
|
301
|
+
* console.log('📅 Purchase Timeline:');
|
|
302
|
+
* console.log(`Last 30 days: ${last30Days.length} purchases`);
|
|
303
|
+
* console.log(`Last 6 months: ${last6Months.length} purchases`);
|
|
304
|
+
*
|
|
305
|
+
* // Analyze by status
|
|
306
|
+
* const statusCounts = purchases.reduce((acc, p) => {
|
|
307
|
+
* acc[p.status] = (acc[p.status] || 0) + 1;
|
|
308
|
+
* return acc;
|
|
309
|
+
* }, {});
|
|
310
|
+
*
|
|
311
|
+
* console.log('\n📊 By status:');
|
|
312
|
+
* Object.entries(statusCounts).forEach(([status, count]) => {
|
|
313
|
+
* console.log(`${status}: ${count} purchases`);
|
|
314
|
+
* });
|
|
315
|
+
*
|
|
316
|
+
* // Find largest and most recent purchases
|
|
317
|
+
* const largestPurchase = purchases.reduce((max, current) =>
|
|
318
|
+
* current.amount > max.amount ? current : max, purchases[0]
|
|
319
|
+
* );
|
|
320
|
+
*
|
|
321
|
+
* const mostRecent = purchases.reduce((newest, current) =>
|
|
322
|
+
* new Date(current.createdAt) > new Date(newest.createdAt) ? current : newest, purchases[0]
|
|
323
|
+
* );
|
|
324
|
+
*
|
|
325
|
+
* if (largestPurchase) {
|
|
326
|
+
* console.log(`\n💎 Largest purchase: $${largestPurchase.amount} on ${new Date(largestPurchase.createdAt).toLocaleDateString()}`);
|
|
327
|
+
* }
|
|
328
|
+
*
|
|
329
|
+
* if (mostRecent) {
|
|
330
|
+
* console.log(`⏰ Most recent: $${mostRecent.amount} on ${new Date(mostRecent.createdAt).toLocaleDateString()}`);
|
|
331
|
+
* }
|
|
332
|
+
* ```
|
|
35
333
|
*/
|
|
36
334
|
getAllUserPurchases(): Promise<PurchaseDTO[]>;
|
|
37
335
|
/**
|
|
38
|
-
* Get the full purchase
|
|
336
|
+
* Get the full purchase service for advanced operations
|
|
337
|
+
*
|
|
338
|
+
* Provides access to the complete PaymentService instance for advanced purchase
|
|
339
|
+
* operations, payment processor integrations, subscription management, and
|
|
340
|
+
* operations not covered by the high-level manager methods.
|
|
341
|
+
*
|
|
342
|
+
* @returns PaymentService instance with full API access
|
|
343
|
+
*
|
|
344
|
+
* @example Advanced Operations
|
|
345
|
+
* ```typescript
|
|
346
|
+
* const paymentService = sdk.purchases.getPurchaseService();
|
|
347
|
+
*
|
|
348
|
+
* // Access advanced payment analytics
|
|
349
|
+
* const analytics = await paymentService.getPaymentAnalytics();
|
|
350
|
+
*
|
|
351
|
+
* // Access subscription management
|
|
352
|
+
* const subscriptions = await paymentService.getUserSubscriptions();
|
|
353
|
+
*
|
|
354
|
+
* // Access payment method management
|
|
355
|
+
* const paymentMethods = await paymentService.getUserPaymentMethods();
|
|
356
|
+
*
|
|
357
|
+
* // Access payment API directly
|
|
358
|
+
* const paymentApi = paymentService.api;
|
|
359
|
+
*
|
|
360
|
+
* // Use advanced purchase validation
|
|
361
|
+
* const validation = await paymentService.validatePurchaseEligibility('token-package-123');
|
|
39
362
|
*
|
|
40
|
-
*
|
|
363
|
+
* // Access payment processor webhooks
|
|
364
|
+
* const webhookHandler = paymentService.createWebhookHandler();
|
|
365
|
+
* ```
|
|
41
366
|
*/
|
|
42
|
-
|
|
367
|
+
getPurchaseService(): PaymentService;
|
|
43
368
|
}
|
|
44
369
|
//# sourceMappingURL=purchase-manager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"purchase-manager.d.ts","sourceRoot":"","sources":["../../src/managers/purchase-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,
|
|
1
|
+
{"version":3,"file":"purchase-manager.d.ts","sourceRoot":"","sources":["../../src/managers/purchase-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAc,cAAc,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,KAAK,EACV,gBAAgB,EAEhB,WAAW,EAIX,gBAAgB,EACjB,MAAM,iDAAiD,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2DG;AACH,qBAAa,eAAe;IAGd,OAAO,CAAC,SAAS;IAF7B,OAAO,CAAC,cAAc,CAAiB;gBAEnB,SAAS,EAAE,aAAa;IAK5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmFG;IACG,mBAAmB,CACvB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,gBAAgB,CAAC;IAI5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8EG;IACG,uBAAuB,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAI5E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoGG;IACG,mBAAmB,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAInD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,kBAAkB,IAAI,cAAc;CAGrC"}
|