@pubflow/core 0.3.1 → 0.4.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/README.md +45 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -1
- package/dist/payments/client.d.ts +301 -0
- package/dist/payments/client.js +477 -0
- package/dist/payments/index.d.ts +7 -0
- package/dist/payments/index.js +11 -0
- package/dist/payments/types.d.ts +384 -0
- package/dist/payments/types.js +7 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Core functionality for the Pubflow framework.
|
|
4
4
|
|
|
5
|
+
## 📚 Documentation
|
|
6
|
+
|
|
7
|
+
- **Flowless (Authentication Backend)**: [https://flowless.dev/](https://flowless.dev/)
|
|
8
|
+
- **Flowfull Client Libraries**: [https://clients.flowfull.dev/](https://clients.flowfull.dev/)
|
|
9
|
+
- **Bridge Payments**: [https://bridgepayments.dev/](https://bridgepayments.dev/)
|
|
10
|
+
|
|
5
11
|
## Overview
|
|
6
12
|
|
|
7
13
|
`@pubflow/core` provides the foundation for the Pubflow framework, including:
|
|
@@ -10,6 +16,7 @@ Core functionality for the Pubflow framework.
|
|
|
10
16
|
- API client for making authenticated HTTP requests
|
|
11
17
|
- Authentication service for user management and session handling
|
|
12
18
|
- Bridge API service for standardized CRUD operations
|
|
19
|
+
- **Bridge Payment Client** for payment processing (NEW in v0.4.0)
|
|
13
20
|
- Schema validation using Zod
|
|
14
21
|
- Storage adapter interface for different storage mechanisms
|
|
15
22
|
- Utility functions for common tasks
|
|
@@ -161,4 +168,41 @@ const result = validateWithSchema(schemas.create, {
|
|
|
161
168
|
if (!result.success) {
|
|
162
169
|
console.error(result.errors);
|
|
163
170
|
}
|
|
164
|
-
```
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Bridge Payments (NEW in v0.4.0)
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
import { BridgePaymentClient } from '@pubflow/core';
|
|
177
|
+
|
|
178
|
+
// Create payment client
|
|
179
|
+
const paymentClient = new BridgePaymentClient({
|
|
180
|
+
baseUrl: 'https://payments.example.com',
|
|
181
|
+
storage: new LocalStorageAdapter() // Optional, defaults to MemoryStorage
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
// Create payment intent
|
|
185
|
+
const intent = await paymentClient.createPaymentIntent({
|
|
186
|
+
total_cents: 2000, // $20.00
|
|
187
|
+
currency: 'USD',
|
|
188
|
+
description: 'Premium Subscription',
|
|
189
|
+
provider_id: 'stripe'
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
// List payment methods
|
|
193
|
+
const methods = await paymentClient.listPaymentMethods();
|
|
194
|
+
|
|
195
|
+
// Create subscription
|
|
196
|
+
const subscription = await paymentClient.createSubscription({
|
|
197
|
+
plan_id: 'plan_premium_monthly',
|
|
198
|
+
payment_method_id: 'pm_123'
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
// Manage organizations (multi-tenant)
|
|
202
|
+
const org = await paymentClient.createOrganization({
|
|
203
|
+
name: 'Acme Corp',
|
|
204
|
+
email: 'billing@acme.com'
|
|
205
|
+
});
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
For complete payment integration examples, see the [Bridge Payments documentation](https://bridgepayments.dev/).
|
package/dist/index.d.ts
CHANGED
|
@@ -17,3 +17,5 @@ export type { LoginCredentials, LoginResult, SessionValidationResult, SessionRef
|
|
|
17
17
|
export { ApiClient } from './api/client';
|
|
18
18
|
export { AuthService } from './auth/service';
|
|
19
19
|
export { StorageAdapter } from './storage/adapter';
|
|
20
|
+
export * from './payments';
|
|
21
|
+
export { BridgePaymentClient } from './payments/client';
|
package/dist/index.js
CHANGED
|
@@ -19,7 +19,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
19
19
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.AuthService = exports.ApiClient = void 0;
|
|
22
|
+
exports.BridgePaymentClient = exports.AuthService = exports.ApiClient = void 0;
|
|
23
23
|
// Export API
|
|
24
24
|
__exportStar(require("./api/client"), exports);
|
|
25
25
|
__exportStar(require("./api/types"), exports);
|
|
@@ -40,3 +40,7 @@ Object.defineProperty(exports, "ApiClient", { enumerable: true, get: function ()
|
|
|
40
40
|
// Export auth service
|
|
41
41
|
var service_1 = require("./auth/service");
|
|
42
42
|
Object.defineProperty(exports, "AuthService", { enumerable: true, get: function () { return service_1.AuthService; } });
|
|
43
|
+
// Export Bridge Payments
|
|
44
|
+
__exportStar(require("./payments"), exports);
|
|
45
|
+
var client_2 = require("./payments/client");
|
|
46
|
+
Object.defineProperty(exports, "BridgePaymentClient", { enumerable: true, get: function () { return client_2.BridgePaymentClient; } });
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bridge Payment Client
|
|
3
|
+
*
|
|
4
|
+
* Client for interacting with Bridge Payments API
|
|
5
|
+
*/
|
|
6
|
+
import { BridgePaymentConfig, PaymentRequestOptions, CreatePaymentIntentRequest, PaymentIntent, Payment, PaymentMethod, UpdatePaymentMethodRequest, Address, CreateAddressRequest, UpdateAddressRequest, Customer, CreateCustomerRequest, UpdateCustomerRequest, Subscription, CreateSubscriptionRequest, CancelSubscriptionRequest, Organization, CreateOrganizationRequest, UpdateOrganizationRequest, OrganizationMember, AddOrganizationMemberRequest, UpdateOrganizationMemberRoleRequest, ConvertGuestToUserRequest, ConvertGuestToUserResponse, PaginationParams } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* Bridge Payment Client
|
|
9
|
+
*
|
|
10
|
+
* Provides a simple interface for interacting with Bridge Payments API
|
|
11
|
+
*/
|
|
12
|
+
export declare class BridgePaymentClient {
|
|
13
|
+
private apiClient;
|
|
14
|
+
private guestToken?;
|
|
15
|
+
private organizationId?;
|
|
16
|
+
private baseUrl;
|
|
17
|
+
/**
|
|
18
|
+
* Create a new Bridge Payment Client
|
|
19
|
+
*
|
|
20
|
+
* @param config Client configuration
|
|
21
|
+
*/
|
|
22
|
+
constructor(config: BridgePaymentConfig);
|
|
23
|
+
/**
|
|
24
|
+
* Make a request to the Bridge Payments API
|
|
25
|
+
*
|
|
26
|
+
* @param endpoint API endpoint
|
|
27
|
+
* @param method HTTP method
|
|
28
|
+
* @param body Request body
|
|
29
|
+
* @param options Request options
|
|
30
|
+
* @returns Response data
|
|
31
|
+
*/
|
|
32
|
+
private request;
|
|
33
|
+
/**
|
|
34
|
+
* Create a payment intent
|
|
35
|
+
*
|
|
36
|
+
* @param data Payment intent data
|
|
37
|
+
* @param options Request options
|
|
38
|
+
* @returns Payment intent
|
|
39
|
+
*/
|
|
40
|
+
createPaymentIntent(data: CreatePaymentIntentRequest, options?: PaymentRequestOptions): Promise<PaymentIntent>;
|
|
41
|
+
/**
|
|
42
|
+
* Get a payment intent by ID
|
|
43
|
+
*
|
|
44
|
+
* @param id Payment intent ID
|
|
45
|
+
* @param options Request options
|
|
46
|
+
* @returns Payment intent
|
|
47
|
+
*/
|
|
48
|
+
getPaymentIntent(id: string, options?: PaymentRequestOptions): Promise<PaymentIntent>;
|
|
49
|
+
/**
|
|
50
|
+
* List payments
|
|
51
|
+
*
|
|
52
|
+
* @param params Pagination parameters
|
|
53
|
+
* @param options Request options
|
|
54
|
+
* @returns List of payments
|
|
55
|
+
*/
|
|
56
|
+
listPayments(params?: PaginationParams, options?: PaymentRequestOptions): Promise<Payment[]>;
|
|
57
|
+
/**
|
|
58
|
+
* Get a payment by ID
|
|
59
|
+
*
|
|
60
|
+
* @param id Payment ID
|
|
61
|
+
* @param options Request options
|
|
62
|
+
* @returns Payment
|
|
63
|
+
*/
|
|
64
|
+
getPayment(id: string, options?: PaymentRequestOptions): Promise<Payment>;
|
|
65
|
+
/**
|
|
66
|
+
* List payment methods
|
|
67
|
+
*
|
|
68
|
+
* @param params Pagination parameters
|
|
69
|
+
* @param options Request options
|
|
70
|
+
* @returns List of payment methods
|
|
71
|
+
*/
|
|
72
|
+
listPaymentMethods(params?: PaginationParams, options?: PaymentRequestOptions): Promise<PaymentMethod[]>;
|
|
73
|
+
/**
|
|
74
|
+
* Get a payment method by ID
|
|
75
|
+
*
|
|
76
|
+
* @param id Payment method ID
|
|
77
|
+
* @param options Request options
|
|
78
|
+
* @returns Payment method
|
|
79
|
+
*/
|
|
80
|
+
getPaymentMethod(id: string, options?: PaymentRequestOptions): Promise<PaymentMethod>;
|
|
81
|
+
/**
|
|
82
|
+
* Update a payment method
|
|
83
|
+
*
|
|
84
|
+
* @param id Payment method ID
|
|
85
|
+
* @param data Update data
|
|
86
|
+
* @param options Request options
|
|
87
|
+
* @returns Updated payment method
|
|
88
|
+
*/
|
|
89
|
+
updatePaymentMethod(id: string, data: UpdatePaymentMethodRequest, options?: PaymentRequestOptions): Promise<PaymentMethod>;
|
|
90
|
+
/**
|
|
91
|
+
* Delete a payment method
|
|
92
|
+
*
|
|
93
|
+
* @param id Payment method ID
|
|
94
|
+
* @param options Request options
|
|
95
|
+
*/
|
|
96
|
+
deletePaymentMethod(id: string, options?: PaymentRequestOptions): Promise<void>;
|
|
97
|
+
/**
|
|
98
|
+
* Create an address
|
|
99
|
+
*
|
|
100
|
+
* @param data Address data
|
|
101
|
+
* @param options Request options
|
|
102
|
+
* @returns Created address
|
|
103
|
+
*/
|
|
104
|
+
createAddress(data: CreateAddressRequest, options?: PaymentRequestOptions): Promise<Address>;
|
|
105
|
+
/**
|
|
106
|
+
* List addresses
|
|
107
|
+
*
|
|
108
|
+
* @param params Pagination parameters
|
|
109
|
+
* @param options Request options
|
|
110
|
+
* @returns List of addresses
|
|
111
|
+
*/
|
|
112
|
+
listAddresses(params?: PaginationParams, options?: PaymentRequestOptions): Promise<Address[]>;
|
|
113
|
+
/**
|
|
114
|
+
* Get an address by ID
|
|
115
|
+
*
|
|
116
|
+
* @param id Address ID
|
|
117
|
+
* @param options Request options
|
|
118
|
+
* @returns Address
|
|
119
|
+
*/
|
|
120
|
+
getAddress(id: string, options?: PaymentRequestOptions): Promise<Address>;
|
|
121
|
+
/**
|
|
122
|
+
* Update an address
|
|
123
|
+
*
|
|
124
|
+
* @param id Address ID
|
|
125
|
+
* @param data Update data
|
|
126
|
+
* @param options Request options
|
|
127
|
+
* @returns Updated address
|
|
128
|
+
*/
|
|
129
|
+
updateAddress(id: string, data: UpdateAddressRequest, options?: PaymentRequestOptions): Promise<Address>;
|
|
130
|
+
/**
|
|
131
|
+
* Delete an address
|
|
132
|
+
*
|
|
133
|
+
* @param id Address ID
|
|
134
|
+
* @param options Request options
|
|
135
|
+
*/
|
|
136
|
+
deleteAddress(id: string, options?: PaymentRequestOptions): Promise<void>;
|
|
137
|
+
/**
|
|
138
|
+
* Create a customer
|
|
139
|
+
*
|
|
140
|
+
* @param data Customer data
|
|
141
|
+
* @param options Request options
|
|
142
|
+
* @returns Created customer
|
|
143
|
+
*/
|
|
144
|
+
createCustomer(data: CreateCustomerRequest, options?: PaymentRequestOptions): Promise<Customer>;
|
|
145
|
+
/**
|
|
146
|
+
* List customers
|
|
147
|
+
*
|
|
148
|
+
* @param params Pagination parameters
|
|
149
|
+
* @param options Request options
|
|
150
|
+
* @returns List of customers
|
|
151
|
+
*/
|
|
152
|
+
listCustomers(params?: PaginationParams, options?: PaymentRequestOptions): Promise<Customer[]>;
|
|
153
|
+
/**
|
|
154
|
+
* Get a customer by ID
|
|
155
|
+
*
|
|
156
|
+
* @param id Customer ID
|
|
157
|
+
* @param options Request options
|
|
158
|
+
* @returns Customer
|
|
159
|
+
*/
|
|
160
|
+
getCustomer(id: string, options?: PaymentRequestOptions): Promise<Customer>;
|
|
161
|
+
/**
|
|
162
|
+
* Update a customer
|
|
163
|
+
*
|
|
164
|
+
* @param id Customer ID
|
|
165
|
+
* @param data Update data
|
|
166
|
+
* @param options Request options
|
|
167
|
+
* @returns Updated customer
|
|
168
|
+
*/
|
|
169
|
+
updateCustomer(id: string, data: UpdateCustomerRequest, options?: PaymentRequestOptions): Promise<Customer>;
|
|
170
|
+
/**
|
|
171
|
+
* Delete a customer
|
|
172
|
+
*
|
|
173
|
+
* @param id Customer ID
|
|
174
|
+
* @param options Request options
|
|
175
|
+
*/
|
|
176
|
+
deleteCustomer(id: string, options?: PaymentRequestOptions): Promise<void>;
|
|
177
|
+
/**
|
|
178
|
+
* Create a subscription
|
|
179
|
+
*
|
|
180
|
+
* @param data Subscription data
|
|
181
|
+
* @param options Request options
|
|
182
|
+
* @returns Created subscription
|
|
183
|
+
*/
|
|
184
|
+
createSubscription(data: CreateSubscriptionRequest, options?: PaymentRequestOptions): Promise<Subscription>;
|
|
185
|
+
/**
|
|
186
|
+
* List subscriptions
|
|
187
|
+
*
|
|
188
|
+
* @param params Pagination parameters
|
|
189
|
+
* @param options Request options
|
|
190
|
+
* @returns List of subscriptions
|
|
191
|
+
*/
|
|
192
|
+
listSubscriptions(params?: PaginationParams, options?: PaymentRequestOptions): Promise<Subscription[]>;
|
|
193
|
+
/**
|
|
194
|
+
* Get a subscription by ID
|
|
195
|
+
*
|
|
196
|
+
* @param id Subscription ID
|
|
197
|
+
* @param options Request options
|
|
198
|
+
* @returns Subscription
|
|
199
|
+
*/
|
|
200
|
+
getSubscription(id: string, options?: PaymentRequestOptions): Promise<Subscription>;
|
|
201
|
+
/**
|
|
202
|
+
* Cancel a subscription
|
|
203
|
+
*
|
|
204
|
+
* @param id Subscription ID
|
|
205
|
+
* @param data Cancel data
|
|
206
|
+
* @param options Request options
|
|
207
|
+
* @returns Canceled subscription
|
|
208
|
+
*/
|
|
209
|
+
cancelSubscription(id: string, data?: CancelSubscriptionRequest, options?: PaymentRequestOptions): Promise<Subscription>;
|
|
210
|
+
/**
|
|
211
|
+
* Create an organization
|
|
212
|
+
*
|
|
213
|
+
* @param data Organization data
|
|
214
|
+
* @param options Request options
|
|
215
|
+
* @returns Created organization
|
|
216
|
+
*/
|
|
217
|
+
createOrganization(data: CreateOrganizationRequest, options?: PaymentRequestOptions): Promise<Organization>;
|
|
218
|
+
/**
|
|
219
|
+
* List organizations
|
|
220
|
+
*
|
|
221
|
+
* @param params Pagination parameters
|
|
222
|
+
* @param options Request options
|
|
223
|
+
* @returns List of organizations
|
|
224
|
+
*/
|
|
225
|
+
listOrganizations(params?: PaginationParams, options?: PaymentRequestOptions): Promise<Organization[]>;
|
|
226
|
+
/**
|
|
227
|
+
* Get an organization by ID
|
|
228
|
+
*
|
|
229
|
+
* @param id Organization ID
|
|
230
|
+
* @param options Request options
|
|
231
|
+
* @returns Organization
|
|
232
|
+
*/
|
|
233
|
+
getOrganization(id: string, options?: PaymentRequestOptions): Promise<Organization>;
|
|
234
|
+
/**
|
|
235
|
+
* Update an organization
|
|
236
|
+
*
|
|
237
|
+
* @param id Organization ID
|
|
238
|
+
* @param data Update data
|
|
239
|
+
* @param options Request options
|
|
240
|
+
* @returns Updated organization
|
|
241
|
+
*/
|
|
242
|
+
updateOrganization(id: string, data: UpdateOrganizationRequest, options?: PaymentRequestOptions): Promise<Organization>;
|
|
243
|
+
/**
|
|
244
|
+
* Delete an organization
|
|
245
|
+
*
|
|
246
|
+
* @param id Organization ID
|
|
247
|
+
* @param options Request options
|
|
248
|
+
*/
|
|
249
|
+
deleteOrganization(id: string, options?: PaymentRequestOptions): Promise<void>;
|
|
250
|
+
/**
|
|
251
|
+
* List organization members
|
|
252
|
+
*
|
|
253
|
+
* @param organizationId Organization ID
|
|
254
|
+
* @param params Pagination parameters
|
|
255
|
+
* @param options Request options
|
|
256
|
+
* @returns List of organization members
|
|
257
|
+
*/
|
|
258
|
+
listOrganizationMembers(organizationId: string, params?: PaginationParams, options?: PaymentRequestOptions): Promise<OrganizationMember[]>;
|
|
259
|
+
/**
|
|
260
|
+
* Add an organization member
|
|
261
|
+
*
|
|
262
|
+
* @param organizationId Organization ID
|
|
263
|
+
* @param data Member data
|
|
264
|
+
* @param options Request options
|
|
265
|
+
* @returns Added member
|
|
266
|
+
*/
|
|
267
|
+
addOrganizationMember(organizationId: string, data: AddOrganizationMemberRequest, options?: PaymentRequestOptions): Promise<OrganizationMember>;
|
|
268
|
+
/**
|
|
269
|
+
* Update an organization member role
|
|
270
|
+
*
|
|
271
|
+
* @param organizationId Organization ID
|
|
272
|
+
* @param memberId Member ID
|
|
273
|
+
* @param data Update data
|
|
274
|
+
* @param options Request options
|
|
275
|
+
* @returns Updated member
|
|
276
|
+
*/
|
|
277
|
+
updateOrganizationMemberRole(organizationId: string, memberId: string, data: UpdateOrganizationMemberRoleRequest, options?: PaymentRequestOptions): Promise<OrganizationMember>;
|
|
278
|
+
/**
|
|
279
|
+
* Remove an organization member
|
|
280
|
+
*
|
|
281
|
+
* @param organizationId Organization ID
|
|
282
|
+
* @param memberId Member ID
|
|
283
|
+
* @param options Request options
|
|
284
|
+
*/
|
|
285
|
+
removeOrganizationMember(organizationId: string, memberId: string, options?: PaymentRequestOptions): Promise<void>;
|
|
286
|
+
/**
|
|
287
|
+
* Leave an organization
|
|
288
|
+
*
|
|
289
|
+
* @param organizationId Organization ID
|
|
290
|
+
* @param options Request options
|
|
291
|
+
*/
|
|
292
|
+
leaveOrganization(organizationId: string, options?: PaymentRequestOptions): Promise<void>;
|
|
293
|
+
/**
|
|
294
|
+
* Convert guest to user
|
|
295
|
+
*
|
|
296
|
+
* @param data Conversion data
|
|
297
|
+
* @param options Request options
|
|
298
|
+
* @returns Conversion result
|
|
299
|
+
*/
|
|
300
|
+
convertGuestToUser(data: ConvertGuestToUserRequest, options?: PaymentRequestOptions): Promise<ConvertGuestToUserResponse>;
|
|
301
|
+
}
|
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Bridge Payment Client
|
|
4
|
+
*
|
|
5
|
+
* Client for interacting with Bridge Payments API
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.BridgePaymentClient = void 0;
|
|
9
|
+
const client_1 = require("../api/client");
|
|
10
|
+
const adapter_1 = require("../storage/adapter");
|
|
11
|
+
/**
|
|
12
|
+
* Bridge Payment Client
|
|
13
|
+
*
|
|
14
|
+
* Provides a simple interface for interacting with Bridge Payments API
|
|
15
|
+
*/
|
|
16
|
+
class BridgePaymentClient {
|
|
17
|
+
/**
|
|
18
|
+
* Create a new Bridge Payment Client
|
|
19
|
+
*
|
|
20
|
+
* @param config Client configuration
|
|
21
|
+
*/
|
|
22
|
+
constructor(config) {
|
|
23
|
+
this.baseUrl = config.baseUrl;
|
|
24
|
+
this.guestToken = config.guestToken;
|
|
25
|
+
this.organizationId = config.organizationId;
|
|
26
|
+
// Create API client with Pubflow configuration
|
|
27
|
+
this.apiClient = new client_1.ApiClient({
|
|
28
|
+
id: config.instanceId || 'bridge-payments',
|
|
29
|
+
baseUrl: config.baseUrl,
|
|
30
|
+
headers: config.headers || {},
|
|
31
|
+
storageConfig: {
|
|
32
|
+
prefix: 'pubflow',
|
|
33
|
+
sessionKey: 'session_id'
|
|
34
|
+
}
|
|
35
|
+
}, config.storage || new adapter_1.MemoryStorageAdapter());
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Make a request to the Bridge Payments API
|
|
39
|
+
*
|
|
40
|
+
* @param endpoint API endpoint
|
|
41
|
+
* @param method HTTP method
|
|
42
|
+
* @param body Request body
|
|
43
|
+
* @param options Request options
|
|
44
|
+
* @returns Response data
|
|
45
|
+
*/
|
|
46
|
+
async request(endpoint, method, body, options) {
|
|
47
|
+
const requestOptions = {
|
|
48
|
+
headers: {},
|
|
49
|
+
includeSession: true,
|
|
50
|
+
...options,
|
|
51
|
+
};
|
|
52
|
+
// 1. Guest Token (if available) - Uses X-Guest-Token header
|
|
53
|
+
if (this.guestToken || (options === null || options === void 0 ? void 0 : options.guestToken)) {
|
|
54
|
+
const token = (options === null || options === void 0 ? void 0 : options.guestToken) || this.guestToken;
|
|
55
|
+
if (token) {
|
|
56
|
+
requestOptions.headers['X-Guest-Token'] = token;
|
|
57
|
+
requestOptions.includeSession = false; // Don't include session for guests
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// 2. Organization ID (if available) - Included in body
|
|
61
|
+
// ⚠️ NOTE: Only works in Subscriptions and Customers currently
|
|
62
|
+
// Addresses, Payments and Payment Methods have organization_id hardcoded to null in backend
|
|
63
|
+
if (body && (this.organizationId || (options === null || options === void 0 ? void 0 : options.organizationId))) {
|
|
64
|
+
const orgId = (options === null || options === void 0 ? void 0 : options.organizationId) || this.organizationId;
|
|
65
|
+
// Only include organization_id in endpoints that support it
|
|
66
|
+
if (endpoint.includes('/subscriptions') || endpoint.includes('/customers')) {
|
|
67
|
+
body.organization_id = orgId;
|
|
68
|
+
}
|
|
69
|
+
// For other endpoints, backend ignores it (hardcoded null)
|
|
70
|
+
// When implemented in backend, it will work automatically
|
|
71
|
+
}
|
|
72
|
+
// 3. ApiClient automatically handles X-Session-ID for authenticated users
|
|
73
|
+
const response = await this.apiClient.request(`/bridge-payment${endpoint}`, method, body, requestOptions);
|
|
74
|
+
if (!response.success) {
|
|
75
|
+
throw new Error(response.error || 'Request failed');
|
|
76
|
+
}
|
|
77
|
+
return response.data;
|
|
78
|
+
}
|
|
79
|
+
// ============================================================================
|
|
80
|
+
// PAYMENT INTENTS
|
|
81
|
+
// ============================================================================
|
|
82
|
+
/**
|
|
83
|
+
* Create a payment intent
|
|
84
|
+
*
|
|
85
|
+
* @param data Payment intent data
|
|
86
|
+
* @param options Request options
|
|
87
|
+
* @returns Payment intent
|
|
88
|
+
*/
|
|
89
|
+
async createPaymentIntent(data, options) {
|
|
90
|
+
return this.request('/payments/intents', 'POST', data, options);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Get a payment intent by ID
|
|
94
|
+
*
|
|
95
|
+
* @param id Payment intent ID
|
|
96
|
+
* @param options Request options
|
|
97
|
+
* @returns Payment intent
|
|
98
|
+
*/
|
|
99
|
+
async getPaymentIntent(id, options) {
|
|
100
|
+
return this.request(`/payments/intents/${id}`, 'GET', undefined, options);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* List payments
|
|
104
|
+
*
|
|
105
|
+
* @param params Pagination parameters
|
|
106
|
+
* @param options Request options
|
|
107
|
+
* @returns List of payments
|
|
108
|
+
*/
|
|
109
|
+
async listPayments(params, options) {
|
|
110
|
+
const queryParams = new URLSearchParams();
|
|
111
|
+
if (params === null || params === void 0 ? void 0 : params.page)
|
|
112
|
+
queryParams.set('page', params.page.toString());
|
|
113
|
+
if (params === null || params === void 0 ? void 0 : params.limit)
|
|
114
|
+
queryParams.set('limit', params.limit.toString());
|
|
115
|
+
const endpoint = `/payments${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
|
|
116
|
+
return this.request(endpoint, 'GET', undefined, options);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Get a payment by ID
|
|
120
|
+
*
|
|
121
|
+
* @param id Payment ID
|
|
122
|
+
* @param options Request options
|
|
123
|
+
* @returns Payment
|
|
124
|
+
*/
|
|
125
|
+
async getPayment(id, options) {
|
|
126
|
+
return this.request(`/payments/${id}`, 'GET', undefined, options);
|
|
127
|
+
}
|
|
128
|
+
// ============================================================================
|
|
129
|
+
// PAYMENT METHODS
|
|
130
|
+
// ============================================================================
|
|
131
|
+
/**
|
|
132
|
+
* List payment methods
|
|
133
|
+
*
|
|
134
|
+
* @param params Pagination parameters
|
|
135
|
+
* @param options Request options
|
|
136
|
+
* @returns List of payment methods
|
|
137
|
+
*/
|
|
138
|
+
async listPaymentMethods(params, options) {
|
|
139
|
+
const queryParams = new URLSearchParams();
|
|
140
|
+
if (params === null || params === void 0 ? void 0 : params.page)
|
|
141
|
+
queryParams.set('page', params.page.toString());
|
|
142
|
+
if (params === null || params === void 0 ? void 0 : params.limit)
|
|
143
|
+
queryParams.set('limit', params.limit.toString());
|
|
144
|
+
const endpoint = `/payment-methods${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
|
|
145
|
+
return this.request(endpoint, 'GET', undefined, options);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Get a payment method by ID
|
|
149
|
+
*
|
|
150
|
+
* @param id Payment method ID
|
|
151
|
+
* @param options Request options
|
|
152
|
+
* @returns Payment method
|
|
153
|
+
*/
|
|
154
|
+
async getPaymentMethod(id, options) {
|
|
155
|
+
return this.request(`/payment-methods/${id}`, 'GET', undefined, options);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Update a payment method
|
|
159
|
+
*
|
|
160
|
+
* @param id Payment method ID
|
|
161
|
+
* @param data Update data
|
|
162
|
+
* @param options Request options
|
|
163
|
+
* @returns Updated payment method
|
|
164
|
+
*/
|
|
165
|
+
async updatePaymentMethod(id, data, options) {
|
|
166
|
+
return this.request(`/payment-methods/${id}`, 'PUT', data, options);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Delete a payment method
|
|
170
|
+
*
|
|
171
|
+
* @param id Payment method ID
|
|
172
|
+
* @param options Request options
|
|
173
|
+
*/
|
|
174
|
+
async deletePaymentMethod(id, options) {
|
|
175
|
+
await this.request(`/payment-methods/${id}`, 'DELETE', undefined, options);
|
|
176
|
+
}
|
|
177
|
+
// ============================================================================
|
|
178
|
+
// ADDRESSES
|
|
179
|
+
// ============================================================================
|
|
180
|
+
/**
|
|
181
|
+
* Create an address
|
|
182
|
+
*
|
|
183
|
+
* @param data Address data
|
|
184
|
+
* @param options Request options
|
|
185
|
+
* @returns Created address
|
|
186
|
+
*/
|
|
187
|
+
async createAddress(data, options) {
|
|
188
|
+
return this.request('/addresses', 'POST', data, options);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* List addresses
|
|
192
|
+
*
|
|
193
|
+
* @param params Pagination parameters
|
|
194
|
+
* @param options Request options
|
|
195
|
+
* @returns List of addresses
|
|
196
|
+
*/
|
|
197
|
+
async listAddresses(params, options) {
|
|
198
|
+
const queryParams = new URLSearchParams();
|
|
199
|
+
if (params === null || params === void 0 ? void 0 : params.page)
|
|
200
|
+
queryParams.set('page', params.page.toString());
|
|
201
|
+
if (params === null || params === void 0 ? void 0 : params.limit)
|
|
202
|
+
queryParams.set('limit', params.limit.toString());
|
|
203
|
+
const endpoint = `/addresses${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
|
|
204
|
+
return this.request(endpoint, 'GET', undefined, options);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Get an address by ID
|
|
208
|
+
*
|
|
209
|
+
* @param id Address ID
|
|
210
|
+
* @param options Request options
|
|
211
|
+
* @returns Address
|
|
212
|
+
*/
|
|
213
|
+
async getAddress(id, options) {
|
|
214
|
+
return this.request(`/addresses/${id}`, 'GET', undefined, options);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Update an address
|
|
218
|
+
*
|
|
219
|
+
* @param id Address ID
|
|
220
|
+
* @param data Update data
|
|
221
|
+
* @param options Request options
|
|
222
|
+
* @returns Updated address
|
|
223
|
+
*/
|
|
224
|
+
async updateAddress(id, data, options) {
|
|
225
|
+
return this.request(`/addresses/${id}`, 'PUT', data, options);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Delete an address
|
|
229
|
+
*
|
|
230
|
+
* @param id Address ID
|
|
231
|
+
* @param options Request options
|
|
232
|
+
*/
|
|
233
|
+
async deleteAddress(id, options) {
|
|
234
|
+
await this.request(`/addresses/${id}`, 'DELETE', undefined, options);
|
|
235
|
+
}
|
|
236
|
+
// ============================================================================
|
|
237
|
+
// CUSTOMERS
|
|
238
|
+
// ============================================================================
|
|
239
|
+
/**
|
|
240
|
+
* Create a customer
|
|
241
|
+
*
|
|
242
|
+
* @param data Customer data
|
|
243
|
+
* @param options Request options
|
|
244
|
+
* @returns Created customer
|
|
245
|
+
*/
|
|
246
|
+
async createCustomer(data, options) {
|
|
247
|
+
return this.request('/customers', 'POST', data, options);
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* List customers
|
|
251
|
+
*
|
|
252
|
+
* @param params Pagination parameters
|
|
253
|
+
* @param options Request options
|
|
254
|
+
* @returns List of customers
|
|
255
|
+
*/
|
|
256
|
+
async listCustomers(params, options) {
|
|
257
|
+
const queryParams = new URLSearchParams();
|
|
258
|
+
if (params === null || params === void 0 ? void 0 : params.page)
|
|
259
|
+
queryParams.set('page', params.page.toString());
|
|
260
|
+
if (params === null || params === void 0 ? void 0 : params.limit)
|
|
261
|
+
queryParams.set('limit', params.limit.toString());
|
|
262
|
+
const endpoint = `/customers${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
|
|
263
|
+
return this.request(endpoint, 'GET', undefined, options);
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Get a customer by ID
|
|
267
|
+
*
|
|
268
|
+
* @param id Customer ID
|
|
269
|
+
* @param options Request options
|
|
270
|
+
* @returns Customer
|
|
271
|
+
*/
|
|
272
|
+
async getCustomer(id, options) {
|
|
273
|
+
return this.request(`/customers/${id}`, 'GET', undefined, options);
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Update a customer
|
|
277
|
+
*
|
|
278
|
+
* @param id Customer ID
|
|
279
|
+
* @param data Update data
|
|
280
|
+
* @param options Request options
|
|
281
|
+
* @returns Updated customer
|
|
282
|
+
*/
|
|
283
|
+
async updateCustomer(id, data, options) {
|
|
284
|
+
return this.request(`/customers/${id}`, 'PUT', data, options);
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Delete a customer
|
|
288
|
+
*
|
|
289
|
+
* @param id Customer ID
|
|
290
|
+
* @param options Request options
|
|
291
|
+
*/
|
|
292
|
+
async deleteCustomer(id, options) {
|
|
293
|
+
await this.request(`/customers/${id}`, 'DELETE', undefined, options);
|
|
294
|
+
}
|
|
295
|
+
// ============================================================================
|
|
296
|
+
// SUBSCRIPTIONS
|
|
297
|
+
// ============================================================================
|
|
298
|
+
/**
|
|
299
|
+
* Create a subscription
|
|
300
|
+
*
|
|
301
|
+
* @param data Subscription data
|
|
302
|
+
* @param options Request options
|
|
303
|
+
* @returns Created subscription
|
|
304
|
+
*/
|
|
305
|
+
async createSubscription(data, options) {
|
|
306
|
+
return this.request('/subscriptions', 'POST', data, options);
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* List subscriptions
|
|
310
|
+
*
|
|
311
|
+
* @param params Pagination parameters
|
|
312
|
+
* @param options Request options
|
|
313
|
+
* @returns List of subscriptions
|
|
314
|
+
*/
|
|
315
|
+
async listSubscriptions(params, options) {
|
|
316
|
+
const queryParams = new URLSearchParams();
|
|
317
|
+
if (params === null || params === void 0 ? void 0 : params.page)
|
|
318
|
+
queryParams.set('page', params.page.toString());
|
|
319
|
+
if (params === null || params === void 0 ? void 0 : params.limit)
|
|
320
|
+
queryParams.set('limit', params.limit.toString());
|
|
321
|
+
const endpoint = `/subscriptions${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
|
|
322
|
+
return this.request(endpoint, 'GET', undefined, options);
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Get a subscription by ID
|
|
326
|
+
*
|
|
327
|
+
* @param id Subscription ID
|
|
328
|
+
* @param options Request options
|
|
329
|
+
* @returns Subscription
|
|
330
|
+
*/
|
|
331
|
+
async getSubscription(id, options) {
|
|
332
|
+
return this.request(`/subscriptions/${id}`, 'GET', undefined, options);
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Cancel a subscription
|
|
336
|
+
*
|
|
337
|
+
* @param id Subscription ID
|
|
338
|
+
* @param data Cancel data
|
|
339
|
+
* @param options Request options
|
|
340
|
+
* @returns Canceled subscription
|
|
341
|
+
*/
|
|
342
|
+
async cancelSubscription(id, data, options) {
|
|
343
|
+
return this.request(`/subscriptions/${id}/cancel`, 'POST', data, options);
|
|
344
|
+
}
|
|
345
|
+
// ============================================================================
|
|
346
|
+
// ORGANIZATIONS
|
|
347
|
+
// ============================================================================
|
|
348
|
+
/**
|
|
349
|
+
* Create an organization
|
|
350
|
+
*
|
|
351
|
+
* @param data Organization data
|
|
352
|
+
* @param options Request options
|
|
353
|
+
* @returns Created organization
|
|
354
|
+
*/
|
|
355
|
+
async createOrganization(data, options) {
|
|
356
|
+
return this.request('/organizations', 'POST', data, options);
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* List organizations
|
|
360
|
+
*
|
|
361
|
+
* @param params Pagination parameters
|
|
362
|
+
* @param options Request options
|
|
363
|
+
* @returns List of organizations
|
|
364
|
+
*/
|
|
365
|
+
async listOrganizations(params, options) {
|
|
366
|
+
const queryParams = new URLSearchParams();
|
|
367
|
+
if (params === null || params === void 0 ? void 0 : params.page)
|
|
368
|
+
queryParams.set('page', params.page.toString());
|
|
369
|
+
if (params === null || params === void 0 ? void 0 : params.limit)
|
|
370
|
+
queryParams.set('limit', params.limit.toString());
|
|
371
|
+
const endpoint = `/organizations${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
|
|
372
|
+
return this.request(endpoint, 'GET', undefined, options);
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Get an organization by ID
|
|
376
|
+
*
|
|
377
|
+
* @param id Organization ID
|
|
378
|
+
* @param options Request options
|
|
379
|
+
* @returns Organization
|
|
380
|
+
*/
|
|
381
|
+
async getOrganization(id, options) {
|
|
382
|
+
return this.request(`/organizations/${id}`, 'GET', undefined, options);
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Update an organization
|
|
386
|
+
*
|
|
387
|
+
* @param id Organization ID
|
|
388
|
+
* @param data Update data
|
|
389
|
+
* @param options Request options
|
|
390
|
+
* @returns Updated organization
|
|
391
|
+
*/
|
|
392
|
+
async updateOrganization(id, data, options) {
|
|
393
|
+
return this.request(`/organizations/${id}`, 'PUT', data, options);
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Delete an organization
|
|
397
|
+
*
|
|
398
|
+
* @param id Organization ID
|
|
399
|
+
* @param options Request options
|
|
400
|
+
*/
|
|
401
|
+
async deleteOrganization(id, options) {
|
|
402
|
+
await this.request(`/organizations/${id}`, 'DELETE', undefined, options);
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* List organization members
|
|
406
|
+
*
|
|
407
|
+
* @param organizationId Organization ID
|
|
408
|
+
* @param params Pagination parameters
|
|
409
|
+
* @param options Request options
|
|
410
|
+
* @returns List of organization members
|
|
411
|
+
*/
|
|
412
|
+
async listOrganizationMembers(organizationId, params, options) {
|
|
413
|
+
const queryParams = new URLSearchParams();
|
|
414
|
+
if (params === null || params === void 0 ? void 0 : params.page)
|
|
415
|
+
queryParams.set('page', params.page.toString());
|
|
416
|
+
if (params === null || params === void 0 ? void 0 : params.limit)
|
|
417
|
+
queryParams.set('limit', params.limit.toString());
|
|
418
|
+
const endpoint = `/organizations/${organizationId}/members${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
|
|
419
|
+
return this.request(endpoint, 'GET', undefined, options);
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Add an organization member
|
|
423
|
+
*
|
|
424
|
+
* @param organizationId Organization ID
|
|
425
|
+
* @param data Member data
|
|
426
|
+
* @param options Request options
|
|
427
|
+
* @returns Added member
|
|
428
|
+
*/
|
|
429
|
+
async addOrganizationMember(organizationId, data, options) {
|
|
430
|
+
return this.request(`/organizations/${organizationId}/members`, 'POST', data, options);
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Update an organization member role
|
|
434
|
+
*
|
|
435
|
+
* @param organizationId Organization ID
|
|
436
|
+
* @param memberId Member ID
|
|
437
|
+
* @param data Update data
|
|
438
|
+
* @param options Request options
|
|
439
|
+
* @returns Updated member
|
|
440
|
+
*/
|
|
441
|
+
async updateOrganizationMemberRole(organizationId, memberId, data, options) {
|
|
442
|
+
return this.request(`/organizations/${organizationId}/members/${memberId}`, 'PUT', data, options);
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Remove an organization member
|
|
446
|
+
*
|
|
447
|
+
* @param organizationId Organization ID
|
|
448
|
+
* @param memberId Member ID
|
|
449
|
+
* @param options Request options
|
|
450
|
+
*/
|
|
451
|
+
async removeOrganizationMember(organizationId, memberId, options) {
|
|
452
|
+
await this.request(`/organizations/${organizationId}/members/${memberId}`, 'DELETE', undefined, options);
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Leave an organization
|
|
456
|
+
*
|
|
457
|
+
* @param organizationId Organization ID
|
|
458
|
+
* @param options Request options
|
|
459
|
+
*/
|
|
460
|
+
async leaveOrganization(organizationId, options) {
|
|
461
|
+
await this.request(`/organizations/${organizationId}/leave`, 'POST', undefined, options);
|
|
462
|
+
}
|
|
463
|
+
// ============================================================================
|
|
464
|
+
// GUEST CONVERSION
|
|
465
|
+
// ============================================================================
|
|
466
|
+
/**
|
|
467
|
+
* Convert guest to user
|
|
468
|
+
*
|
|
469
|
+
* @param data Conversion data
|
|
470
|
+
* @param options Request options
|
|
471
|
+
* @returns Conversion result
|
|
472
|
+
*/
|
|
473
|
+
async convertGuestToUser(data, options) {
|
|
474
|
+
return this.request('/guest/convert', 'POST', data, options);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
exports.BridgePaymentClient = BridgePaymentClient;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bridge Payments Module
|
|
3
|
+
*
|
|
4
|
+
* Exports for Bridge Payments client and types
|
|
5
|
+
*/
|
|
6
|
+
export { BridgePaymentClient } from './client';
|
|
7
|
+
export type { BridgePaymentConfig, PaymentRequestOptions, CreatePaymentIntentRequest, PaymentIntent, Payment, PaymentMethodType, PaymentMethod, UpdatePaymentMethodRequest, AddressType, Address, CreateAddressRequest, UpdateAddressRequest, Customer, CreateCustomerRequest, UpdateCustomerRequest, SubscriptionStatus, Subscription, CreateSubscriptionRequest, CancelSubscriptionRequest, OrganizationRole, Organization, CreateOrganizationRequest, UpdateOrganizationRequest, OrganizationMember, AddOrganizationMemberRequest, UpdateOrganizationMemberRoleRequest, ConvertGuestToUserRequest, ConvertGuestToUserResponse, PaginationParams, ListResponse } from './types';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Bridge Payments Module
|
|
4
|
+
*
|
|
5
|
+
* Exports for Bridge Payments client and types
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.BridgePaymentClient = void 0;
|
|
9
|
+
// Export client
|
|
10
|
+
var client_1 = require("./client");
|
|
11
|
+
Object.defineProperty(exports, "BridgePaymentClient", { enumerable: true, get: function () { return client_1.BridgePaymentClient; } });
|
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bridge Payments Types
|
|
3
|
+
*
|
|
4
|
+
* TypeScript interfaces for Bridge Payments API
|
|
5
|
+
*/
|
|
6
|
+
import { RequestOptions } from '../api/types';
|
|
7
|
+
/**
|
|
8
|
+
* Configuration for Bridge Payment Client
|
|
9
|
+
*/
|
|
10
|
+
export interface BridgePaymentConfig {
|
|
11
|
+
/**
|
|
12
|
+
* Base URL of the Bridge Payments instance
|
|
13
|
+
* Example: 'https://your-instance.pubflow.com'
|
|
14
|
+
*/
|
|
15
|
+
baseUrl: string;
|
|
16
|
+
/**
|
|
17
|
+
* Guest token (optional)
|
|
18
|
+
* If provided, all requests will use X-Guest-Token header
|
|
19
|
+
*/
|
|
20
|
+
guestToken?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Organization ID (optional)
|
|
23
|
+
*
|
|
24
|
+
* ✅ SUPPORTED IN:
|
|
25
|
+
* - Subscriptions (complete)
|
|
26
|
+
* - Customers (complete)
|
|
27
|
+
*
|
|
28
|
+
* ⚠️ NOT SUPPORTED IN (backend hardcoded null):
|
|
29
|
+
* - Addresses
|
|
30
|
+
* - Payments (partial - only customers)
|
|
31
|
+
* - Payment Methods
|
|
32
|
+
*
|
|
33
|
+
* The client is prepared for when the backend is updated.
|
|
34
|
+
*/
|
|
35
|
+
organizationId?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Pubflow instance ID (optional)
|
|
38
|
+
* Default: 'bridge-payments'
|
|
39
|
+
*/
|
|
40
|
+
instanceId?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Custom headers (optional)
|
|
43
|
+
*/
|
|
44
|
+
headers?: Record<string, string>;
|
|
45
|
+
/**
|
|
46
|
+
* Storage adapter (optional, uses Pubflow default)
|
|
47
|
+
*/
|
|
48
|
+
storage?: any;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Request options for payment operations
|
|
52
|
+
*/
|
|
53
|
+
export interface PaymentRequestOptions extends RequestOptions {
|
|
54
|
+
/**
|
|
55
|
+
* Guest token for this specific request
|
|
56
|
+
* Overrides the client's guestToken
|
|
57
|
+
*/
|
|
58
|
+
guestToken?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Organization ID for this specific request
|
|
61
|
+
* Overrides the client's organizationId
|
|
62
|
+
*/
|
|
63
|
+
organizationId?: string;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Request to create a payment intent
|
|
67
|
+
*/
|
|
68
|
+
export interface CreatePaymentIntentRequest {
|
|
69
|
+
total_cents?: number;
|
|
70
|
+
subtotal_cents?: number;
|
|
71
|
+
tax_cents?: number;
|
|
72
|
+
discount_cents?: number;
|
|
73
|
+
shipping_cents?: number;
|
|
74
|
+
currency: string;
|
|
75
|
+
provider_id: string;
|
|
76
|
+
description?: string;
|
|
77
|
+
concept?: string;
|
|
78
|
+
reference_code?: string;
|
|
79
|
+
category?: string;
|
|
80
|
+
guest_data?: {
|
|
81
|
+
email: string;
|
|
82
|
+
name: string;
|
|
83
|
+
phone?: string;
|
|
84
|
+
};
|
|
85
|
+
payment_method_id?: string;
|
|
86
|
+
save_payment_method?: boolean;
|
|
87
|
+
metadata?: Record<string, any>;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Payment Intent response
|
|
91
|
+
*/
|
|
92
|
+
export interface PaymentIntent {
|
|
93
|
+
id: string;
|
|
94
|
+
client_secret: string;
|
|
95
|
+
status: string;
|
|
96
|
+
total_cents: number;
|
|
97
|
+
currency: string;
|
|
98
|
+
provider_id: string;
|
|
99
|
+
user_id?: string;
|
|
100
|
+
guest_email?: string;
|
|
101
|
+
guest_token?: string;
|
|
102
|
+
created_at: string;
|
|
103
|
+
updated_at: string;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Payment response
|
|
107
|
+
*/
|
|
108
|
+
export interface Payment {
|
|
109
|
+
id: string;
|
|
110
|
+
user_id?: string;
|
|
111
|
+
guest_email?: string;
|
|
112
|
+
provider_id: string;
|
|
113
|
+
provider_payment_id: string;
|
|
114
|
+
total_cents: number;
|
|
115
|
+
currency: string;
|
|
116
|
+
status: string;
|
|
117
|
+
description?: string;
|
|
118
|
+
metadata?: Record<string, any>;
|
|
119
|
+
created_at: string;
|
|
120
|
+
updated_at: string;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Payment method type
|
|
124
|
+
*/
|
|
125
|
+
export type PaymentMethodType = 'card' | 'bank_account' | 'paypal' | 'apple_pay' | 'google_pay';
|
|
126
|
+
/**
|
|
127
|
+
* Payment Method response
|
|
128
|
+
*/
|
|
129
|
+
export interface PaymentMethod {
|
|
130
|
+
id: string;
|
|
131
|
+
user_id?: string;
|
|
132
|
+
guest_email?: string;
|
|
133
|
+
organization_id?: string;
|
|
134
|
+
provider_id: string;
|
|
135
|
+
provider_payment_method_id: string;
|
|
136
|
+
type: PaymentMethodType;
|
|
137
|
+
last4?: string;
|
|
138
|
+
brand?: string;
|
|
139
|
+
exp_month?: number;
|
|
140
|
+
exp_year?: number;
|
|
141
|
+
alias?: string;
|
|
142
|
+
is_default: boolean;
|
|
143
|
+
created_at: string;
|
|
144
|
+
updated_at: string;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Request to update a payment method
|
|
148
|
+
*/
|
|
149
|
+
export interface UpdatePaymentMethodRequest {
|
|
150
|
+
alias?: string;
|
|
151
|
+
is_default?: boolean;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Address type
|
|
155
|
+
*/
|
|
156
|
+
export type AddressType = 'billing' | 'shipping';
|
|
157
|
+
/**
|
|
158
|
+
* Address response
|
|
159
|
+
*/
|
|
160
|
+
export interface Address {
|
|
161
|
+
id: string;
|
|
162
|
+
user_id?: string;
|
|
163
|
+
guest_email?: string;
|
|
164
|
+
organization_id?: string;
|
|
165
|
+
address_type: AddressType;
|
|
166
|
+
name: string;
|
|
167
|
+
line1: string;
|
|
168
|
+
line2?: string;
|
|
169
|
+
city: string;
|
|
170
|
+
state?: string;
|
|
171
|
+
postal_code: string;
|
|
172
|
+
country: string;
|
|
173
|
+
phone?: string;
|
|
174
|
+
is_default: boolean;
|
|
175
|
+
created_at: string;
|
|
176
|
+
updated_at: string;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Request to create an address
|
|
180
|
+
*/
|
|
181
|
+
export interface CreateAddressRequest {
|
|
182
|
+
address_type: AddressType;
|
|
183
|
+
name: string;
|
|
184
|
+
line1: string;
|
|
185
|
+
line2?: string;
|
|
186
|
+
city: string;
|
|
187
|
+
state?: string;
|
|
188
|
+
postal_code: string;
|
|
189
|
+
country: string;
|
|
190
|
+
phone?: string;
|
|
191
|
+
is_default?: boolean;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Request to update an address
|
|
195
|
+
*/
|
|
196
|
+
export interface UpdateAddressRequest {
|
|
197
|
+
address_type?: AddressType;
|
|
198
|
+
name?: string;
|
|
199
|
+
line1?: string;
|
|
200
|
+
line2?: string;
|
|
201
|
+
city?: string;
|
|
202
|
+
state?: string;
|
|
203
|
+
postal_code?: string;
|
|
204
|
+
country?: string;
|
|
205
|
+
phone?: string;
|
|
206
|
+
is_default?: boolean;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Customer response
|
|
210
|
+
*/
|
|
211
|
+
export interface Customer {
|
|
212
|
+
id: string;
|
|
213
|
+
user_id?: string;
|
|
214
|
+
guest_email?: string;
|
|
215
|
+
organization_id?: string;
|
|
216
|
+
provider_id: string;
|
|
217
|
+
provider_customer_id: string;
|
|
218
|
+
email: string;
|
|
219
|
+
name: string;
|
|
220
|
+
phone?: string;
|
|
221
|
+
metadata?: Record<string, any>;
|
|
222
|
+
created_at: string;
|
|
223
|
+
updated_at: string;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Request to create a customer
|
|
227
|
+
*/
|
|
228
|
+
export interface CreateCustomerRequest {
|
|
229
|
+
email: string;
|
|
230
|
+
name: string;
|
|
231
|
+
phone?: string;
|
|
232
|
+
provider_id?: string;
|
|
233
|
+
metadata?: Record<string, any>;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Request to update a customer
|
|
237
|
+
*/
|
|
238
|
+
export interface UpdateCustomerRequest {
|
|
239
|
+
email?: string;
|
|
240
|
+
name?: string;
|
|
241
|
+
phone?: string;
|
|
242
|
+
metadata?: Record<string, any>;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Subscription status
|
|
246
|
+
*/
|
|
247
|
+
export type SubscriptionStatus = 'active' | 'canceled' | 'past_due' | 'unpaid' | 'incomplete' | 'trialing';
|
|
248
|
+
/**
|
|
249
|
+
* Subscription response
|
|
250
|
+
*/
|
|
251
|
+
export interface Subscription {
|
|
252
|
+
id: string;
|
|
253
|
+
user_id?: string;
|
|
254
|
+
organization_id?: string;
|
|
255
|
+
customer_id: string;
|
|
256
|
+
product_id?: string;
|
|
257
|
+
provider_id: string;
|
|
258
|
+
provider_subscription_id: string;
|
|
259
|
+
status: SubscriptionStatus;
|
|
260
|
+
current_period_start: string;
|
|
261
|
+
current_period_end: string;
|
|
262
|
+
cancel_at_period_end: boolean;
|
|
263
|
+
canceled_at?: string;
|
|
264
|
+
metadata?: Record<string, any>;
|
|
265
|
+
created_at: string;
|
|
266
|
+
updated_at: string;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Request to create a subscription
|
|
270
|
+
*/
|
|
271
|
+
export interface CreateSubscriptionRequest {
|
|
272
|
+
customer_id: string;
|
|
273
|
+
product_id?: string;
|
|
274
|
+
payment_method_id: string;
|
|
275
|
+
provider_id?: string;
|
|
276
|
+
trial_days?: number;
|
|
277
|
+
metadata?: Record<string, any>;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Request to cancel a subscription
|
|
281
|
+
*/
|
|
282
|
+
export interface CancelSubscriptionRequest {
|
|
283
|
+
cancel_at_period_end?: boolean;
|
|
284
|
+
reason?: string;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Organization role
|
|
288
|
+
*/
|
|
289
|
+
export type OrganizationRole = 'owner' | 'admin' | 'billing' | 'member';
|
|
290
|
+
/**
|
|
291
|
+
* Organization response
|
|
292
|
+
*/
|
|
293
|
+
export interface Organization {
|
|
294
|
+
id: string;
|
|
295
|
+
name: string;
|
|
296
|
+
business_email?: string;
|
|
297
|
+
business_phone?: string;
|
|
298
|
+
tax_id?: string;
|
|
299
|
+
address?: string;
|
|
300
|
+
metadata?: Record<string, any>;
|
|
301
|
+
created_at: string;
|
|
302
|
+
updated_at: string;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Request to create an organization
|
|
306
|
+
*/
|
|
307
|
+
export interface CreateOrganizationRequest {
|
|
308
|
+
name: string;
|
|
309
|
+
business_email?: string;
|
|
310
|
+
business_phone?: string;
|
|
311
|
+
tax_id?: string;
|
|
312
|
+
address?: string;
|
|
313
|
+
metadata?: Record<string, any>;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Request to update an organization
|
|
317
|
+
*/
|
|
318
|
+
export interface UpdateOrganizationRequest {
|
|
319
|
+
name?: string;
|
|
320
|
+
business_email?: string;
|
|
321
|
+
business_phone?: string;
|
|
322
|
+
tax_id?: string;
|
|
323
|
+
address?: string;
|
|
324
|
+
metadata?: Record<string, any>;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Organization member response
|
|
328
|
+
*/
|
|
329
|
+
export interface OrganizationMember {
|
|
330
|
+
id: string;
|
|
331
|
+
organization_id: string;
|
|
332
|
+
user_id: string;
|
|
333
|
+
role: OrganizationRole;
|
|
334
|
+
created_at: string;
|
|
335
|
+
updated_at: string;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Request to add an organization member
|
|
339
|
+
*/
|
|
340
|
+
export interface AddOrganizationMemberRequest {
|
|
341
|
+
email: string;
|
|
342
|
+
role: OrganizationRole;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Request to update an organization member role
|
|
346
|
+
*/
|
|
347
|
+
export interface UpdateOrganizationMemberRoleRequest {
|
|
348
|
+
role: OrganizationRole;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Request to convert guest to user
|
|
352
|
+
*/
|
|
353
|
+
export interface ConvertGuestToUserRequest {
|
|
354
|
+
guest_email: string;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Response from guest conversion
|
|
358
|
+
*/
|
|
359
|
+
export interface ConvertGuestToUserResponse {
|
|
360
|
+
success: boolean;
|
|
361
|
+
message: string;
|
|
362
|
+
payments_count: number;
|
|
363
|
+
payment_methods_count: number;
|
|
364
|
+
addresses_count: number;
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Pagination parameters
|
|
368
|
+
*/
|
|
369
|
+
export interface PaginationParams {
|
|
370
|
+
page?: number;
|
|
371
|
+
limit?: number;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* List response with pagination
|
|
375
|
+
*/
|
|
376
|
+
export interface ListResponse<T> {
|
|
377
|
+
data: T[];
|
|
378
|
+
pagination: {
|
|
379
|
+
page: number;
|
|
380
|
+
limit: number;
|
|
381
|
+
total: number;
|
|
382
|
+
hasMore: boolean;
|
|
383
|
+
};
|
|
384
|
+
}
|