@revstackhq/provider-polar 0.0.0-dev-20260301204402 → 0.0.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/dist/index.d.ts +4 -9
- package/dist/index.js +721 -235
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _revstackhq_providers_core from '@revstackhq/providers-core';
|
|
2
|
-
import { ProviderManifest, BaseProvider, ProviderContext, InstallInput, AsyncActionResult, InstallResult, UninstallInput, RevstackEvent, WebhookResponse, CreatePaymentInput, Payment, RefundPaymentInput, PaginationOptions, PaginatedResult, CreateSubscriptionInput, Subscription, CheckoutSessionInput, CheckoutSessionResult, CreateCustomerInput, UpdateCustomerInput, Customer, PaymentMethod, UpdateSubscriptionInput, SetupPaymentMethodInput, BillingPortalInput, BillingPortalResult
|
|
2
|
+
import { ProviderManifest, BaseProvider, ProviderContext, InstallInput, AsyncActionResult, InstallResult, UninstallInput, RevstackEvent, WebhookResponse, CreatePaymentInput, Payment, RefundPaymentInput, PaginationOptions, PaginatedResult, CreateSubscriptionInput, Subscription, CheckoutSessionInput, CheckoutSessionResult, CreateCustomerInput, UpdateCustomerInput, Customer, PaymentMethod, UpdateSubscriptionInput, SetupPaymentMethodInput, BillingPortalInput, BillingPortalResult } from '@revstackhq/providers-core';
|
|
3
3
|
|
|
4
4
|
declare const manifest: ProviderManifest;
|
|
5
5
|
|
|
@@ -14,7 +14,7 @@ declare class PolarProvider extends BaseProvider {
|
|
|
14
14
|
createPayment(ctx: ProviderContext, input: CreatePaymentInput): Promise<AsyncActionResult<string>>;
|
|
15
15
|
getPayment(ctx: ProviderContext, id: string): Promise<AsyncActionResult<Payment>>;
|
|
16
16
|
refundPayment(ctx: ProviderContext, input: RefundPaymentInput): Promise<AsyncActionResult<string>>;
|
|
17
|
-
listPayments(ctx: ProviderContext, pagination: PaginationOptions): Promise<AsyncActionResult<PaginatedResult<Payment>>>;
|
|
17
|
+
listPayments(ctx: ProviderContext, pagination: PaginationOptions, filters?: Record<string, any>): Promise<AsyncActionResult<PaginatedResult<Payment>>>;
|
|
18
18
|
createSubscription(ctx: ProviderContext, input: CreateSubscriptionInput): Promise<AsyncActionResult<string>>;
|
|
19
19
|
getSubscription(ctx: ProviderContext, id: string): Promise<AsyncActionResult<Subscription>>;
|
|
20
20
|
cancelSubscription(ctx: ProviderContext, id: string, reason?: string): Promise<AsyncActionResult<string>>;
|
|
@@ -28,16 +28,11 @@ declare class PolarProvider extends BaseProvider {
|
|
|
28
28
|
listPaymentMethods(ctx: ProviderContext, customerId: string): Promise<AsyncActionResult<PaymentMethod[]>>;
|
|
29
29
|
deletePaymentMethod(ctx: ProviderContext, id: string): Promise<AsyncActionResult<boolean>>;
|
|
30
30
|
capturePayment(ctx: ProviderContext, id: string, amount?: number): Promise<AsyncActionResult<string>>;
|
|
31
|
-
listSubscriptions(ctx: ProviderContext, pagination: PaginationOptions): Promise<AsyncActionResult<PaginatedResult<Subscription>>>;
|
|
31
|
+
listSubscriptions(ctx: ProviderContext, pagination: PaginationOptions, filters?: Record<string, any>): Promise<AsyncActionResult<PaginatedResult<Subscription>>>;
|
|
32
32
|
updateSubscription(ctx: ProviderContext, id: string, input: UpdateSubscriptionInput): Promise<AsyncActionResult<string>>;
|
|
33
|
-
listCustomers(ctx: ProviderContext, pagination: PaginationOptions): Promise<AsyncActionResult<PaginatedResult<Customer>>>;
|
|
33
|
+
listCustomers(ctx: ProviderContext, pagination: PaginationOptions, filters?: Record<string, any>): Promise<AsyncActionResult<PaginatedResult<Customer>>>;
|
|
34
34
|
setupPaymentMethod(ctx: ProviderContext, input: SetupPaymentMethodInput): Promise<AsyncActionResult<CheckoutSessionResult>>;
|
|
35
35
|
createBillingPortalSession(ctx: ProviderContext, input: BillingPortalInput): Promise<AsyncActionResult<BillingPortalResult>>;
|
|
36
|
-
createAddon(ctx: ProviderContext, input: CreateAddonInput): Promise<AsyncActionResult<string>>;
|
|
37
|
-
getAddon(ctx: ProviderContext, id: string): Promise<AsyncActionResult<Addon>>;
|
|
38
|
-
updateAddon(ctx: ProviderContext, id: string, input: UpdateAddonInput): Promise<AsyncActionResult<string>>;
|
|
39
|
-
deleteAddon(ctx: ProviderContext, input: DeleteAddonInput): Promise<AsyncActionResult<boolean>>;
|
|
40
|
-
listAddons(ctx: ProviderContext, subscriptionId: string, pagination: PaginationOptions): Promise<AsyncActionResult<PaginatedResult<Addon>>>;
|
|
41
36
|
}
|
|
42
37
|
|
|
43
38
|
export { PolarProvider, manifest };
|
package/dist/index.js
CHANGED
|
@@ -37,7 +37,7 @@ var manifest = {
|
|
|
37
37
|
payments: {
|
|
38
38
|
supported: true,
|
|
39
39
|
features: {
|
|
40
|
-
capture:
|
|
40
|
+
capture: false,
|
|
41
41
|
disputes: true,
|
|
42
42
|
partialRefunds: true,
|
|
43
43
|
refunds: true
|
|
@@ -48,8 +48,8 @@ var manifest = {
|
|
|
48
48
|
mode: "native",
|
|
49
49
|
features: {
|
|
50
50
|
cancellation: true,
|
|
51
|
-
pause:
|
|
52
|
-
resume:
|
|
51
|
+
pause: false,
|
|
52
|
+
resume: false,
|
|
53
53
|
proration: true
|
|
54
54
|
}
|
|
55
55
|
},
|
|
@@ -107,94 +107,649 @@ var manifest = {
|
|
|
107
107
|
}
|
|
108
108
|
};
|
|
109
109
|
|
|
110
|
-
// src/
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
throw new Error("Not implemented");
|
|
122
|
-
};
|
|
123
|
-
var capturePayment = async (...args) => {
|
|
124
|
-
throw new Error("Not implemented");
|
|
125
|
-
};
|
|
110
|
+
// src/api/v1/payments.ts
|
|
111
|
+
import {
|
|
112
|
+
buildPagePagination,
|
|
113
|
+
RevstackErrorCode as RevstackErrorCode3
|
|
114
|
+
} from "@revstackhq/providers-core";
|
|
115
|
+
|
|
116
|
+
// src/api/v1/mappers.ts
|
|
117
|
+
import {
|
|
118
|
+
SubscriptionStatus,
|
|
119
|
+
PaymentStatus
|
|
120
|
+
} from "@revstackhq/providers-core";
|
|
126
121
|
|
|
127
|
-
// src/
|
|
128
|
-
var
|
|
129
|
-
|
|
122
|
+
// src/shared/currency-map.ts
|
|
123
|
+
var currencyMap = {
|
|
124
|
+
aud: "AUD",
|
|
125
|
+
brl: "BRL",
|
|
126
|
+
cad: "CAD",
|
|
127
|
+
chf: "CHF",
|
|
128
|
+
eur: "EUR",
|
|
129
|
+
inr: "INR",
|
|
130
|
+
gbp: "GBP",
|
|
131
|
+
jpy: "JPY",
|
|
132
|
+
sek: "SEK",
|
|
133
|
+
usd: "USD"
|
|
130
134
|
};
|
|
131
|
-
|
|
132
|
-
|
|
135
|
+
|
|
136
|
+
// src/api/v1/mappers.ts
|
|
137
|
+
function mapPolarSubStatusToSubscriptionStatus(status) {
|
|
138
|
+
const map = {
|
|
139
|
+
incomplete: SubscriptionStatus.Incomplete,
|
|
140
|
+
incomplete_expired: SubscriptionStatus.IncompleteExpired,
|
|
141
|
+
trialing: SubscriptionStatus.Trialing,
|
|
142
|
+
active: SubscriptionStatus.Active,
|
|
143
|
+
past_due: SubscriptionStatus.PastDue,
|
|
144
|
+
canceled: SubscriptionStatus.Canceled,
|
|
145
|
+
unpaid: SubscriptionStatus.Unpaid
|
|
146
|
+
};
|
|
147
|
+
return map[status] || SubscriptionStatus.Active;
|
|
148
|
+
}
|
|
149
|
+
function mapPolarOrderStatusToPaymentStatus(status) {
|
|
150
|
+
return status === "paid" ? PaymentStatus.Succeeded : PaymentStatus.Pending;
|
|
151
|
+
}
|
|
152
|
+
function mapSessionToCheckoutResult(session) {
|
|
153
|
+
return {
|
|
154
|
+
id: session.id,
|
|
155
|
+
expiresAt: session.expiresAt ? new Date(session.expiresAt).toISOString() : void 0
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
function mapPolarSubscriptionToSubscription(sub) {
|
|
159
|
+
return {
|
|
160
|
+
id: sub.id,
|
|
161
|
+
providerId: "polar",
|
|
162
|
+
externalId: sub.id,
|
|
163
|
+
status: mapPolarSubStatusToSubscriptionStatus(sub.status),
|
|
164
|
+
amount: sub.amount || 0,
|
|
165
|
+
currency: currencyMap[sub.currency],
|
|
166
|
+
interval: sub.recurringInterval === "year" ? "year" : "month",
|
|
167
|
+
customerId: sub.customerId,
|
|
168
|
+
currentPeriodStart: new Date(sub.currentPeriodStart).toISOString(),
|
|
169
|
+
currentPeriodEnd: sub.currentPeriodEnd ? new Date(sub.currentPeriodEnd).toISOString() : new Date(sub.currentPeriodStart).toISOString(),
|
|
170
|
+
cancelAtPeriodEnd: sub.cancelAtPeriodEnd,
|
|
171
|
+
startedAt: sub.startedAt ? new Date(sub.startedAt).toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
|
|
172
|
+
canceledAt: sub.canceledAt ? new Date(sub.canceledAt).toISOString() : void 0,
|
|
173
|
+
raw: sub
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function mapPolarOrderToPayment(order) {
|
|
177
|
+
return {
|
|
178
|
+
id: order.id,
|
|
179
|
+
providerId: "polar",
|
|
180
|
+
externalId: order.id,
|
|
181
|
+
amount: order.subtotalAmount || 0,
|
|
182
|
+
amountRefunded: order.refundedAmount || 0,
|
|
183
|
+
currency: currencyMap[order.currency],
|
|
184
|
+
status: mapPolarOrderStatusToPaymentStatus(order.status),
|
|
185
|
+
customerId: order.customerId,
|
|
186
|
+
createdAt: new Date(order.createdAt).toISOString(),
|
|
187
|
+
raw: order
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
function mapPolarCustomerToCustomer(customer) {
|
|
191
|
+
return {
|
|
192
|
+
id: customer.id,
|
|
193
|
+
providerId: "polar",
|
|
194
|
+
externalId: customer.externalId || customer.id,
|
|
195
|
+
email: customer.email,
|
|
196
|
+
name: customer.name || void 0,
|
|
197
|
+
phone: void 0,
|
|
198
|
+
// Polar doesn't store phone natively yet
|
|
199
|
+
metadata: customer.metadata,
|
|
200
|
+
createdAt: new Date(customer.createdAt).toISOString(),
|
|
201
|
+
deleted: false
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// src/api/v1/client.ts
|
|
206
|
+
import { Polar } from "@polar-sh/sdk";
|
|
207
|
+
var polarClient = null;
|
|
208
|
+
var getOrCreatePolar = (accessToken, testMode = false) => {
|
|
209
|
+
if (!polarClient) {
|
|
210
|
+
polarClient = new Polar({
|
|
211
|
+
accessToken,
|
|
212
|
+
server: testMode ? "sandbox" : "production"
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
return polarClient;
|
|
133
216
|
};
|
|
134
|
-
|
|
135
|
-
|
|
217
|
+
function appendQueryParam(url, param) {
|
|
218
|
+
const sep = url.includes("?") ? "&" : "?";
|
|
219
|
+
return url + sep + param;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// src/utils/jit.ts
|
|
223
|
+
import { RevstackErrorCode } from "@revstackhq/providers-core";
|
|
224
|
+
async function resolveJitProductId(client, ctx, params) {
|
|
225
|
+
let needsCreation = !params.priceId;
|
|
226
|
+
if (params.priceId) {
|
|
227
|
+
try {
|
|
228
|
+
await client.products.get({ id: params.priceId });
|
|
229
|
+
} catch (err) {
|
|
230
|
+
if (err.status === 404) needsCreation = true;
|
|
231
|
+
else throw err;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (!needsCreation) return params.priceId;
|
|
235
|
+
if (params.jit.interval) {
|
|
236
|
+
if (params.jit.interval === "day" || params.jit.interval === "week") {
|
|
237
|
+
throw {
|
|
238
|
+
isRevstackError: true,
|
|
239
|
+
errorPayload: {
|
|
240
|
+
code: RevstackErrorCode.InvalidInput,
|
|
241
|
+
message: "Polar only supports 'month' or 'year' for subscriptions."
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
const newProduct = await client.products.create({
|
|
247
|
+
name: params.jit.name,
|
|
248
|
+
description: params.jit.description,
|
|
249
|
+
organizationId: ctx.config.organizationId,
|
|
250
|
+
recurringInterval: params.jit.interval || void 0,
|
|
251
|
+
prices: [
|
|
252
|
+
{
|
|
253
|
+
amountType: "fixed",
|
|
254
|
+
priceAmount: params.jit.amount,
|
|
255
|
+
priceCurrency: currencyMap[params.jit.currency.toLowerCase()]
|
|
256
|
+
}
|
|
257
|
+
]
|
|
258
|
+
});
|
|
259
|
+
return newProduct.id;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// src/shared/error-map.ts
|
|
263
|
+
import { RevstackErrorCode as RevstackErrorCode2 } from "@revstackhq/providers-core";
|
|
264
|
+
function mapError(error) {
|
|
265
|
+
const msg = error?.message || "Unknown error";
|
|
266
|
+
const name = error?.name || "Error";
|
|
267
|
+
if (error.status === 404) {
|
|
268
|
+
return {
|
|
269
|
+
code: RevstackErrorCode2.ResourceNotFound,
|
|
270
|
+
message: msg,
|
|
271
|
+
providerError: name
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
if (error.status === 401 || error.status === 403) {
|
|
275
|
+
return {
|
|
276
|
+
code: RevstackErrorCode2.InvalidCredentials,
|
|
277
|
+
message: msg,
|
|
278
|
+
providerError: name
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
if (error.status >= 500) {
|
|
282
|
+
return {
|
|
283
|
+
code: RevstackErrorCode2.ProviderUnavailable,
|
|
284
|
+
message: msg,
|
|
285
|
+
providerError: name
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
return {
|
|
289
|
+
code: RevstackErrorCode2.UnknownError,
|
|
290
|
+
message: msg,
|
|
291
|
+
providerError: name
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// src/api/v1/payments.ts
|
|
296
|
+
var createPayment = async (ctx, input, createCheckoutSession2) => {
|
|
297
|
+
try {
|
|
298
|
+
const polar = getOrCreatePolar(ctx.config.accessToken);
|
|
299
|
+
const resolvedProductId = await resolveJitProductId(polar, ctx, {
|
|
300
|
+
jit: {
|
|
301
|
+
name: input.jit?.name || input.description || "One-time Payment",
|
|
302
|
+
description: input.jit?.description,
|
|
303
|
+
amount: input.amount,
|
|
304
|
+
currency: input.currency
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
const result = await createCheckoutSession2(ctx, {
|
|
308
|
+
mode: "payment",
|
|
309
|
+
customerId: input.customerId,
|
|
310
|
+
successUrl: input.returnUrl || "",
|
|
311
|
+
cancelUrl: input.cancelUrl || "",
|
|
312
|
+
metadata: input.metadata,
|
|
313
|
+
lineItems: [
|
|
314
|
+
{
|
|
315
|
+
priceId: resolvedProductId,
|
|
316
|
+
quantity: 1
|
|
317
|
+
}
|
|
318
|
+
]
|
|
319
|
+
});
|
|
320
|
+
return {
|
|
321
|
+
data: result.data?.id || null,
|
|
322
|
+
status: result.status,
|
|
323
|
+
nextAction: result.nextAction,
|
|
324
|
+
error: result.error
|
|
325
|
+
};
|
|
326
|
+
} catch (error) {
|
|
327
|
+
if (error.isRevstackError) {
|
|
328
|
+
return { data: null, status: "failed", error: error.errorPayload };
|
|
329
|
+
}
|
|
330
|
+
return { data: null, status: "failed", error: mapError(error) };
|
|
331
|
+
}
|
|
136
332
|
};
|
|
137
|
-
var
|
|
138
|
-
|
|
333
|
+
var getPayment = async (ctx, paymentId) => {
|
|
334
|
+
try {
|
|
335
|
+
const polar = getOrCreatePolar(ctx.config.accessToken);
|
|
336
|
+
const order = await polar.orders.get({
|
|
337
|
+
id: paymentId
|
|
338
|
+
});
|
|
339
|
+
return {
|
|
340
|
+
data: mapPolarOrderToPayment(order),
|
|
341
|
+
status: "success"
|
|
342
|
+
};
|
|
343
|
+
} catch (error) {
|
|
344
|
+
if (error.isRevstackError) {
|
|
345
|
+
return { data: null, status: "failed", error: error.errorPayload };
|
|
346
|
+
}
|
|
347
|
+
return { data: null, status: "failed", error: mapError(error) };
|
|
348
|
+
}
|
|
139
349
|
};
|
|
140
|
-
var
|
|
141
|
-
|
|
350
|
+
var listPayments = async (ctx, options, filters) => {
|
|
351
|
+
try {
|
|
352
|
+
const polar = getOrCreatePolar(ctx.config.accessToken);
|
|
353
|
+
const targetPage = options?.page || options?.startingAfter && parseInt(options.startingAfter) + 1 || options?.endingBefore && Math.max(1, parseInt(options.endingBefore) - 1) || 1;
|
|
354
|
+
const limit = options?.limit || 10;
|
|
355
|
+
const ordersPage = await polar.orders.list({
|
|
356
|
+
customerId: options?.customerId,
|
|
357
|
+
limit,
|
|
358
|
+
page: targetPage,
|
|
359
|
+
...filters
|
|
360
|
+
});
|
|
361
|
+
return {
|
|
362
|
+
data: buildPagePagination(
|
|
363
|
+
ordersPage.result.items,
|
|
364
|
+
targetPage,
|
|
365
|
+
ordersPage.result.pagination.maxPage,
|
|
366
|
+
mapPolarOrderToPayment
|
|
367
|
+
),
|
|
368
|
+
status: "success"
|
|
369
|
+
};
|
|
370
|
+
} catch (error) {
|
|
371
|
+
if (error.isRevstackError) {
|
|
372
|
+
return { data: null, status: "failed", error: error.errorPayload };
|
|
373
|
+
}
|
|
374
|
+
return { data: null, status: "failed", error: mapError(error) };
|
|
375
|
+
}
|
|
142
376
|
};
|
|
143
|
-
var
|
|
144
|
-
|
|
377
|
+
var refundPayment = async (ctx, paymentId, amount) => {
|
|
378
|
+
try {
|
|
379
|
+
const polar = getOrCreatePolar(ctx.config.accessToken);
|
|
380
|
+
await polar.refunds.create({
|
|
381
|
+
orderId: paymentId,
|
|
382
|
+
amount: amount || 0,
|
|
383
|
+
// If 0, polar throws an error, which is correct (refunds must have amount > 1)
|
|
384
|
+
reason: "customer_request"
|
|
385
|
+
});
|
|
386
|
+
const order = await polar.orders.get({
|
|
387
|
+
id: paymentId
|
|
388
|
+
});
|
|
389
|
+
return {
|
|
390
|
+
data: order.id,
|
|
391
|
+
status: "success"
|
|
392
|
+
};
|
|
393
|
+
} catch (error) {
|
|
394
|
+
if (error.isRevstackError) {
|
|
395
|
+
return { data: null, status: "failed", error: error.errorPayload };
|
|
396
|
+
}
|
|
397
|
+
return { data: null, status: "failed", error: mapError(error) };
|
|
398
|
+
}
|
|
145
399
|
};
|
|
146
|
-
var
|
|
147
|
-
|
|
400
|
+
var capturePayment = async (_ctx, _paymentId, _amount) => {
|
|
401
|
+
return {
|
|
402
|
+
data: null,
|
|
403
|
+
status: "failed",
|
|
404
|
+
error: {
|
|
405
|
+
code: RevstackErrorCode3.NotImplemented,
|
|
406
|
+
message: "Manual capture is not supported by Polar logic yet."
|
|
407
|
+
}
|
|
408
|
+
};
|
|
148
409
|
};
|
|
149
410
|
|
|
150
|
-
// src/
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
411
|
+
// src/api/v1/subscriptions.ts
|
|
412
|
+
import {
|
|
413
|
+
RevstackErrorCode as RevstackErrorCode4,
|
|
414
|
+
buildPagePagination as buildPagePagination2
|
|
415
|
+
} from "@revstackhq/providers-core";
|
|
416
|
+
async function createSubscription(ctx, input, createCheckoutSession2) {
|
|
417
|
+
try {
|
|
418
|
+
const polar = getOrCreatePolar(ctx.config.accessToken);
|
|
419
|
+
const resolvedProductId = input.jit ? await resolveJitProductId(polar, ctx, {
|
|
420
|
+
priceId: input.priceId,
|
|
421
|
+
jit: input.jit
|
|
422
|
+
}) : input.priceId;
|
|
423
|
+
const result = await createCheckoutSession2(ctx, {
|
|
424
|
+
mode: "subscription",
|
|
425
|
+
customerId: input.customerId,
|
|
426
|
+
successUrl: input.returnUrl || "",
|
|
427
|
+
cancelUrl: input.cancelUrl || "",
|
|
428
|
+
metadata: input.metadata,
|
|
429
|
+
allowPromotionCodes: input.promotionCode ? true : void 0,
|
|
430
|
+
lineItems: [
|
|
431
|
+
{
|
|
432
|
+
priceId: resolvedProductId,
|
|
433
|
+
quantity: input.quantity || 1
|
|
434
|
+
}
|
|
435
|
+
]
|
|
436
|
+
});
|
|
437
|
+
return {
|
|
438
|
+
data: result.data?.id || null,
|
|
439
|
+
status: result.status,
|
|
440
|
+
nextAction: result.nextAction,
|
|
441
|
+
error: result.error
|
|
442
|
+
};
|
|
443
|
+
} catch (error) {
|
|
444
|
+
if (error.isRevstackError) {
|
|
445
|
+
return { data: null, status: "failed", error: error.errorPayload };
|
|
446
|
+
}
|
|
447
|
+
return { data: null, status: "failed", error: mapError(error) };
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
async function getSubscription(ctx, id) {
|
|
451
|
+
try {
|
|
452
|
+
const polar = getOrCreatePolar(ctx.config.accessToken);
|
|
453
|
+
const sub = await polar.subscriptions.get({ id });
|
|
454
|
+
return {
|
|
455
|
+
data: mapPolarSubscriptionToSubscription(sub),
|
|
456
|
+
status: "success"
|
|
457
|
+
};
|
|
458
|
+
} catch (error) {
|
|
459
|
+
if (error.isRevstackError) {
|
|
460
|
+
return { data: null, status: "failed", error: error.errorPayload };
|
|
461
|
+
}
|
|
462
|
+
return { data: null, status: "failed", error: mapError(error) };
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
async function cancelSubscription(ctx, id, _reason) {
|
|
466
|
+
try {
|
|
467
|
+
const polar = getOrCreatePolar(ctx.config.accessToken);
|
|
468
|
+
const sub = await polar.subscriptions.revoke({ id });
|
|
469
|
+
return {
|
|
470
|
+
data: sub.id,
|
|
471
|
+
status: "success"
|
|
472
|
+
};
|
|
473
|
+
} catch (error) {
|
|
474
|
+
if (error.status === 404) {
|
|
475
|
+
return {
|
|
476
|
+
data: null,
|
|
477
|
+
status: "failed",
|
|
478
|
+
error: {
|
|
479
|
+
code: RevstackErrorCode4.SubscriptionNotFound,
|
|
480
|
+
message: error.message,
|
|
481
|
+
providerError: error.name
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
if (error.isRevstackError) {
|
|
486
|
+
return { data: null, status: "failed", error: error.errorPayload };
|
|
487
|
+
}
|
|
488
|
+
return { data: null, status: "failed", error: mapError(error) };
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
async function pauseSubscription(_ctx, _id) {
|
|
492
|
+
return {
|
|
493
|
+
data: null,
|
|
494
|
+
status: "failed",
|
|
495
|
+
error: {
|
|
496
|
+
code: RevstackErrorCode4.NotImplemented,
|
|
497
|
+
message: "Polar does not natively support pausing subscriptions yet."
|
|
498
|
+
}
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
async function resumeSubscription(_ctx, _id) {
|
|
502
|
+
return {
|
|
503
|
+
data: null,
|
|
504
|
+
status: "failed",
|
|
505
|
+
error: {
|
|
506
|
+
code: RevstackErrorCode4.NotImplemented,
|
|
507
|
+
message: "Polar does not natively support resuming paused subscriptions."
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
async function listSubscriptions(ctx, pagination, filters) {
|
|
512
|
+
try {
|
|
513
|
+
const polar = getOrCreatePolar(ctx.config.accessToken);
|
|
514
|
+
const targetPage = pagination.page || pagination.startingAfter && parseInt(pagination.startingAfter) + 1 || pagination.endingBefore && Math.max(1, parseInt(pagination.endingBefore) - 1) || 1;
|
|
515
|
+
const subsResponse = await polar.subscriptions.list({
|
|
516
|
+
organizationId: ctx.config.organizationId,
|
|
517
|
+
limit: pagination.limit || 10,
|
|
518
|
+
page: targetPage,
|
|
519
|
+
...filters
|
|
520
|
+
});
|
|
521
|
+
return {
|
|
522
|
+
data: buildPagePagination2(
|
|
523
|
+
subsResponse.result.items,
|
|
524
|
+
targetPage,
|
|
525
|
+
subsResponse.result.pagination.maxPage,
|
|
526
|
+
mapPolarSubscriptionToSubscription
|
|
527
|
+
),
|
|
528
|
+
status: "success"
|
|
529
|
+
};
|
|
530
|
+
} catch (error) {
|
|
531
|
+
if (error.isRevstackError) {
|
|
532
|
+
return { data: null, status: "failed", error: error.errorPayload };
|
|
533
|
+
}
|
|
534
|
+
return { data: null, status: "failed", error: mapError(error) };
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
async function updateSubscription(ctx, id, input) {
|
|
538
|
+
try {
|
|
539
|
+
const polar = getOrCreatePolar(ctx.config.accessToken);
|
|
540
|
+
const sub = await polar.subscriptions.update({
|
|
541
|
+
id,
|
|
542
|
+
subscriptionUpdate: {
|
|
543
|
+
prorationBehavior: "prorate",
|
|
544
|
+
productId: input.priceId || ""
|
|
545
|
+
}
|
|
546
|
+
});
|
|
547
|
+
return {
|
|
548
|
+
data: sub.id,
|
|
549
|
+
status: "success"
|
|
550
|
+
};
|
|
551
|
+
} catch (error) {
|
|
552
|
+
if (error.isRevstackError) {
|
|
553
|
+
return { data: null, status: "failed", error: error.errorPayload };
|
|
554
|
+
}
|
|
555
|
+
return { data: null, status: "failed", error: mapError(error) };
|
|
556
|
+
}
|
|
557
|
+
}
|
|
160
558
|
|
|
161
|
-
// src/
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
|
|
559
|
+
// src/api/v1/checkout.ts
|
|
560
|
+
import {
|
|
561
|
+
RevstackErrorCode as RevstackErrorCode5
|
|
562
|
+
} from "@revstackhq/providers-core";
|
|
563
|
+
async function createCheckoutSession(ctx, input) {
|
|
564
|
+
const polar = getOrCreatePolar(ctx.config.accessToken);
|
|
565
|
+
try {
|
|
566
|
+
const productIds = input.lineItems.filter((item) => item.priceId).map((item) => item.priceId);
|
|
567
|
+
if (productIds.length === 0) {
|
|
568
|
+
return {
|
|
569
|
+
data: null,
|
|
570
|
+
status: "failed",
|
|
571
|
+
error: {
|
|
572
|
+
code: RevstackErrorCode5.InvalidInput,
|
|
573
|
+
message: "Failed to create checkout session. Please ensure you have a valid product or price.",
|
|
574
|
+
providerError: "missing_product"
|
|
575
|
+
}
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
const cleanMetadata = {};
|
|
579
|
+
if (input.metadata) {
|
|
580
|
+
Object.entries(input.metadata).forEach(([k, v]) => {
|
|
581
|
+
if (v !== null && v !== void 0) {
|
|
582
|
+
cleanMetadata[k] = v;
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
if (ctx.traceId) {
|
|
587
|
+
cleanMetadata.revstack_trace_id = ctx.traceId;
|
|
588
|
+
}
|
|
589
|
+
const sessionPayload = {
|
|
590
|
+
products: productIds,
|
|
591
|
+
successUrl: appendQueryParam(
|
|
592
|
+
input.successUrl,
|
|
593
|
+
"session_id={CHECKOUT_SESSION_ID}"
|
|
594
|
+
),
|
|
595
|
+
customerId: input.customerId || void 0,
|
|
596
|
+
customerEmail: !input.customerId ? input.customerEmail : void 0,
|
|
597
|
+
allowDiscountCodes: input.allowPromotionCodes ?? true,
|
|
598
|
+
metadata: cleanMetadata
|
|
599
|
+
};
|
|
600
|
+
const session = await polar.checkouts.create(sessionPayload);
|
|
601
|
+
return {
|
|
602
|
+
data: mapSessionToCheckoutResult(session),
|
|
603
|
+
status: "requires_action",
|
|
604
|
+
nextAction: {
|
|
605
|
+
type: "redirect",
|
|
606
|
+
url: session.url
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
} catch (error) {
|
|
610
|
+
const mapped = mapError(error);
|
|
611
|
+
return {
|
|
612
|
+
data: null,
|
|
613
|
+
status: "failed",
|
|
614
|
+
error: mapped
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
async function createBillingPortalSession(ctx, input) {
|
|
619
|
+
const polar = getOrCreatePolar(ctx.config.accessToken);
|
|
620
|
+
try {
|
|
621
|
+
const session = await polar.customerSessions.create({
|
|
622
|
+
customerId: input.customerId,
|
|
623
|
+
returnUrl: input.returnUrl || void 0
|
|
624
|
+
});
|
|
625
|
+
return {
|
|
626
|
+
data: null,
|
|
627
|
+
status: "requires_action",
|
|
628
|
+
nextAction: {
|
|
629
|
+
type: "redirect",
|
|
630
|
+
url: session.customerPortalUrl
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
} catch (error) {
|
|
634
|
+
return {
|
|
635
|
+
data: null,
|
|
636
|
+
status: "failed",
|
|
637
|
+
error: mapError(error)
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
// src/api/v1/customers.ts
|
|
643
|
+
import {
|
|
644
|
+
buildPagePagination as buildPagePagination3
|
|
645
|
+
} from "@revstackhq/providers-core";
|
|
646
|
+
var createCustomer = async (ctx, input) => {
|
|
647
|
+
try {
|
|
648
|
+
const polar = getOrCreatePolar(ctx.config.accessToken);
|
|
649
|
+
const customer = await polar.customers.create({
|
|
650
|
+
email: input.email,
|
|
651
|
+
name: input.name || void 0,
|
|
652
|
+
metadata: input.metadata || {}
|
|
653
|
+
});
|
|
654
|
+
return {
|
|
655
|
+
data: customer.id,
|
|
656
|
+
status: "success"
|
|
657
|
+
};
|
|
658
|
+
} catch (error) {
|
|
659
|
+
if (error.isRevstackError) {
|
|
660
|
+
return { data: null, status: "failed", error: error.errorPayload };
|
|
661
|
+
}
|
|
662
|
+
return { data: null, status: "failed", error: mapError(error) };
|
|
663
|
+
}
|
|
167
664
|
};
|
|
168
|
-
var
|
|
169
|
-
|
|
665
|
+
var updateCustomer = async (ctx, customerId, input) => {
|
|
666
|
+
try {
|
|
667
|
+
const polar = getOrCreatePolar(ctx.config.accessToken);
|
|
668
|
+
const customer = await polar.customers.update({
|
|
669
|
+
id: customerId,
|
|
670
|
+
customerUpdate: {
|
|
671
|
+
email: input.email,
|
|
672
|
+
name: input.name || void 0,
|
|
673
|
+
metadata: input.metadata || {}
|
|
674
|
+
}
|
|
675
|
+
});
|
|
676
|
+
return {
|
|
677
|
+
data: customer.id,
|
|
678
|
+
status: "success"
|
|
679
|
+
};
|
|
680
|
+
} catch (error) {
|
|
681
|
+
if (error.isRevstackError) {
|
|
682
|
+
return { data: null, status: "failed", error: error.errorPayload };
|
|
683
|
+
}
|
|
684
|
+
return { data: null, status: "failed", error: mapError(error) };
|
|
685
|
+
}
|
|
170
686
|
};
|
|
171
|
-
var
|
|
172
|
-
|
|
687
|
+
var deleteCustomer = async (ctx, customerId) => {
|
|
688
|
+
try {
|
|
689
|
+
const polar = getOrCreatePolar(ctx.config.accessToken);
|
|
690
|
+
await polar.customers.delete({
|
|
691
|
+
id: customerId
|
|
692
|
+
});
|
|
693
|
+
return {
|
|
694
|
+
data: true,
|
|
695
|
+
status: "success"
|
|
696
|
+
};
|
|
697
|
+
} catch (error) {
|
|
698
|
+
if (error.isRevstackError) {
|
|
699
|
+
return { data: false, status: "failed", error: error.errorPayload };
|
|
700
|
+
}
|
|
701
|
+
return { data: false, status: "failed", error: mapError(error) };
|
|
702
|
+
}
|
|
173
703
|
};
|
|
174
|
-
var
|
|
175
|
-
|
|
704
|
+
var getCustomer = async (ctx, customerId) => {
|
|
705
|
+
try {
|
|
706
|
+
const polar = getOrCreatePolar(ctx.config.accessToken);
|
|
707
|
+
const customer = await polar.customers.get({
|
|
708
|
+
id: customerId
|
|
709
|
+
});
|
|
710
|
+
return {
|
|
711
|
+
data: mapPolarCustomerToCustomer(customer),
|
|
712
|
+
status: "success"
|
|
713
|
+
};
|
|
714
|
+
} catch (error) {
|
|
715
|
+
if (error.isRevstackError) {
|
|
716
|
+
return { data: null, status: "failed", error: error.errorPayload };
|
|
717
|
+
}
|
|
718
|
+
return { data: null, status: "failed", error: mapError(error) };
|
|
719
|
+
}
|
|
176
720
|
};
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
var polarClient = null;
|
|
188
|
-
var getOrCreatePolar = (accessToken) => {
|
|
189
|
-
if (!polarClient) {
|
|
190
|
-
polarClient = new Polar({
|
|
191
|
-
accessToken
|
|
721
|
+
var listCustomers = async (ctx, options, filters) => {
|
|
722
|
+
try {
|
|
723
|
+
const polar = getOrCreatePolar(ctx.config.accessToken);
|
|
724
|
+
const targetPage = options?.page || options?.startingAfter && parseInt(options.startingAfter) + 1 || options?.endingBefore && Math.max(1, parseInt(options.endingBefore) - 1) || 1;
|
|
725
|
+
const limit = options?.limit || 10;
|
|
726
|
+
const customersPage = await polar.customers.list({
|
|
727
|
+
limit,
|
|
728
|
+
page: targetPage,
|
|
729
|
+
email: options?.email,
|
|
730
|
+
...filters
|
|
192
731
|
});
|
|
732
|
+
return {
|
|
733
|
+
data: buildPagePagination3(
|
|
734
|
+
customersPage.result.items,
|
|
735
|
+
targetPage,
|
|
736
|
+
customersPage.result.pagination.maxPage,
|
|
737
|
+
mapPolarCustomerToCustomer
|
|
738
|
+
),
|
|
739
|
+
status: "success"
|
|
740
|
+
};
|
|
741
|
+
} catch (error) {
|
|
742
|
+
if (error.isRevstackError) {
|
|
743
|
+
return { data: null, status: "failed", error: error.errorPayload };
|
|
744
|
+
}
|
|
745
|
+
return { data: null, status: "failed", error: mapError(error) };
|
|
193
746
|
}
|
|
194
|
-
return polarClient;
|
|
195
747
|
};
|
|
196
748
|
|
|
197
|
-
// src/
|
|
749
|
+
// src/api/v1/webhooks.ts
|
|
750
|
+
import { validateEvent } from "@polar-sh/sdk/webhooks.js";
|
|
751
|
+
|
|
752
|
+
// src/shared/event-map.ts
|
|
198
753
|
var EVENT_MAP = {
|
|
199
754
|
// Checkout
|
|
200
755
|
"checkout.created": "CHECKOUT_COMPLETED",
|
|
@@ -238,21 +793,21 @@ var EVENT_MAP = {
|
|
|
238
793
|
"member.deleted": null
|
|
239
794
|
};
|
|
240
795
|
|
|
241
|
-
// src/
|
|
796
|
+
// src/api/v1/webhooks.ts
|
|
242
797
|
var validateCredentials = async (ctx) => {
|
|
243
798
|
if (!ctx.config.accessToken || !ctx.config.organizationId) {
|
|
244
799
|
return { data: false, status: "success" };
|
|
245
800
|
}
|
|
246
801
|
try {
|
|
247
|
-
const
|
|
248
|
-
await
|
|
802
|
+
const polar = getOrCreatePolar(ctx.config.accessToken);
|
|
803
|
+
await polar.organizations.list({});
|
|
249
804
|
return { data: true, status: "success" };
|
|
250
805
|
} catch {
|
|
251
806
|
return { data: false, status: "failed" };
|
|
252
807
|
}
|
|
253
808
|
};
|
|
254
809
|
var setupWebhooks = async (ctx, webhookUrl) => {
|
|
255
|
-
const
|
|
810
|
+
const polar = getOrCreatePolar(ctx.config.accessToken);
|
|
256
811
|
try {
|
|
257
812
|
const events = [
|
|
258
813
|
"checkout.created",
|
|
@@ -278,18 +833,44 @@ var setupWebhooks = async (ctx, webhookUrl) => {
|
|
|
278
833
|
"product.created",
|
|
279
834
|
"product.updated"
|
|
280
835
|
];
|
|
281
|
-
const
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
events,
|
|
285
|
-
name: "Revstack"
|
|
836
|
+
const webhooksList = await polar.webhooks.listWebhookEndpoints({
|
|
837
|
+
organizationId: ctx.config.organizationId,
|
|
838
|
+
limit: 100
|
|
286
839
|
});
|
|
840
|
+
const existingWebhook = webhooksList.result.items.find(
|
|
841
|
+
(wh) => wh.url === webhookUrl
|
|
842
|
+
);
|
|
843
|
+
let webhookEndpointId;
|
|
844
|
+
let secret;
|
|
845
|
+
if (existingWebhook) {
|
|
846
|
+
const updated = await polar.webhooks.updateWebhookEndpoint({
|
|
847
|
+
id: existingWebhook.id,
|
|
848
|
+
webhookEndpointUpdate: {
|
|
849
|
+
url: webhookUrl,
|
|
850
|
+
format: "raw",
|
|
851
|
+
events
|
|
852
|
+
}
|
|
853
|
+
});
|
|
854
|
+
webhookEndpointId = updated.id;
|
|
855
|
+
secret = void 0;
|
|
856
|
+
} else {
|
|
857
|
+
const created = await polar.webhooks.createWebhookEndpoint({
|
|
858
|
+
url: webhookUrl,
|
|
859
|
+
format: "raw",
|
|
860
|
+
events,
|
|
861
|
+
name: "Revstack"
|
|
862
|
+
});
|
|
863
|
+
webhookEndpointId = created.id;
|
|
864
|
+
secret = created.secret;
|
|
865
|
+
}
|
|
287
866
|
const data = {
|
|
288
|
-
webhookEndpointId
|
|
289
|
-
webhookSecret: webhookEndpoint.secret,
|
|
867
|
+
webhookEndpointId,
|
|
290
868
|
accessToken: ctx.config.accessToken,
|
|
291
869
|
organizationId: ctx.config.organizationId
|
|
292
870
|
};
|
|
871
|
+
if (secret) {
|
|
872
|
+
data.webhookSecret = secret;
|
|
873
|
+
}
|
|
293
874
|
return {
|
|
294
875
|
data: { success: true, data },
|
|
295
876
|
status: "success"
|
|
@@ -303,9 +884,9 @@ var setupWebhooks = async (ctx, webhookUrl) => {
|
|
|
303
884
|
}
|
|
304
885
|
};
|
|
305
886
|
var removeWebhooks = async (ctx, webhookId) => {
|
|
306
|
-
const
|
|
887
|
+
const polar = getOrCreatePolar(ctx.config.accessToken);
|
|
307
888
|
try {
|
|
308
|
-
await
|
|
889
|
+
await polar.webhooks.deleteWebhookEndpoint({ id: webhookId });
|
|
309
890
|
return { data: true, status: "success" };
|
|
310
891
|
} catch (error) {
|
|
311
892
|
return { data: false, status: "failed" };
|
|
@@ -347,32 +928,28 @@ var parseWebhookEvent = async (payload) => {
|
|
|
347
928
|
};
|
|
348
929
|
};
|
|
349
930
|
|
|
350
|
-
// src/
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
};
|
|
354
|
-
var
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
}
|
|
360
|
-
var deleteAddon = async (...args) => {
|
|
361
|
-
throw new Error("Not implemented");
|
|
931
|
+
// src/api/v1/payment-methods.ts
|
|
932
|
+
import {
|
|
933
|
+
RevstackErrorCode as RevstackErrorCode6
|
|
934
|
+
} from "@revstackhq/providers-core";
|
|
935
|
+
var NOT_IMPLEMENTED = {
|
|
936
|
+
status: "failed",
|
|
937
|
+
error: {
|
|
938
|
+
code: RevstackErrorCode6.NotImplemented,
|
|
939
|
+
message: "Payment methods management is natively not supported by Polar"
|
|
940
|
+
}
|
|
362
941
|
};
|
|
363
|
-
var
|
|
364
|
-
|
|
942
|
+
var setupPaymentMethod = async (_ctx, _input) => {
|
|
943
|
+
return { ...NOT_IMPLEMENTED, data: null };
|
|
365
944
|
};
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
var listPaymentMethods = async (...args) => {
|
|
369
|
-
throw new Error("Not implemented");
|
|
945
|
+
var listPaymentMethods = async (_ctx, _customerId) => {
|
|
946
|
+
return { ...NOT_IMPLEMENTED, data: null };
|
|
370
947
|
};
|
|
371
|
-
var deletePaymentMethod = async (
|
|
372
|
-
|
|
948
|
+
var deletePaymentMethod = async (_ctx, _id) => {
|
|
949
|
+
return { ...NOT_IMPLEMENTED, data: false };
|
|
373
950
|
};
|
|
374
951
|
|
|
375
|
-
// src/
|
|
952
|
+
// src/api/v1/index.ts
|
|
376
953
|
var PolarClientV1 = class {
|
|
377
954
|
// ===========================================================================
|
|
378
955
|
// LIFECYCLE & WEBHOOKS
|
|
@@ -392,6 +969,9 @@ var PolarClientV1 = class {
|
|
|
392
969
|
parseWebhookEvent(payload) {
|
|
393
970
|
return parseWebhookEvent(payload);
|
|
394
971
|
}
|
|
972
|
+
setupPaymentMethod(ctx, input) {
|
|
973
|
+
return setupPaymentMethod(ctx, input);
|
|
974
|
+
}
|
|
395
975
|
listPaymentMethods(ctx, customerId) {
|
|
396
976
|
return listPaymentMethods(ctx, customerId);
|
|
397
977
|
}
|
|
@@ -408,7 +988,7 @@ var PolarClientV1 = class {
|
|
|
408
988
|
return getPayment(ctx, id);
|
|
409
989
|
}
|
|
410
990
|
refundPayment(ctx, input) {
|
|
411
|
-
return refundPayment(ctx, input);
|
|
991
|
+
return refundPayment(ctx, input.paymentId, input.amount);
|
|
412
992
|
}
|
|
413
993
|
listPayments(ctx, pagination) {
|
|
414
994
|
return listPayments(ctx, pagination);
|
|
@@ -450,9 +1030,6 @@ var PolarClientV1 = class {
|
|
|
450
1030
|
createCheckoutSession(ctx, input) {
|
|
451
1031
|
return createCheckoutSession(ctx, input);
|
|
452
1032
|
}
|
|
453
|
-
setupPaymentMethod(ctx, input) {
|
|
454
|
-
return setupPaymentMethod(ctx, input);
|
|
455
|
-
}
|
|
456
1033
|
createBillingPortalSession(ctx, input) {
|
|
457
1034
|
return createBillingPortalSession(ctx, input);
|
|
458
1035
|
}
|
|
@@ -474,27 +1051,9 @@ var PolarClientV1 = class {
|
|
|
474
1051
|
listCustomers(ctx, pagination) {
|
|
475
1052
|
return listCustomers(ctx, pagination);
|
|
476
1053
|
}
|
|
477
|
-
// ===========================================================================
|
|
478
|
-
// ADDONS
|
|
479
|
-
// ===========================================================================
|
|
480
|
-
createAddon(ctx, input) {
|
|
481
|
-
return createAddon(ctx, input);
|
|
482
|
-
}
|
|
483
|
-
getAddon(ctx, id) {
|
|
484
|
-
return getAddon(ctx, id);
|
|
485
|
-
}
|
|
486
|
-
updateAddon(ctx, id, input) {
|
|
487
|
-
return updateAddon(ctx, id, input);
|
|
488
|
-
}
|
|
489
|
-
deleteAddon(ctx, input) {
|
|
490
|
-
return deleteAddon(ctx, input);
|
|
491
|
-
}
|
|
492
|
-
listAddons(ctx, subscriptionId, pagination) {
|
|
493
|
-
return listAddons(ctx, subscriptionId, pagination);
|
|
494
|
-
}
|
|
495
1054
|
};
|
|
496
1055
|
|
|
497
|
-
// src/
|
|
1056
|
+
// src/api/factory.ts
|
|
498
1057
|
function getClient(_config) {
|
|
499
1058
|
return new PolarClientV1();
|
|
500
1059
|
}
|
|
@@ -502,7 +1061,7 @@ function getClient(_config) {
|
|
|
502
1061
|
// src/provider.ts
|
|
503
1062
|
import {
|
|
504
1063
|
BaseProvider,
|
|
505
|
-
RevstackErrorCode
|
|
1064
|
+
RevstackErrorCode as RevstackErrorCode7
|
|
506
1065
|
} from "@revstackhq/providers-core";
|
|
507
1066
|
var PolarProvider = class extends BaseProvider {
|
|
508
1067
|
static manifest = manifest;
|
|
@@ -519,7 +1078,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
519
1078
|
data: { success: false },
|
|
520
1079
|
status: "failed",
|
|
521
1080
|
error: {
|
|
522
|
-
code:
|
|
1081
|
+
code: RevstackErrorCode7.InvalidCredentials,
|
|
523
1082
|
message: "Failed to connect to provider. Please check your API Key / Secrets."
|
|
524
1083
|
}
|
|
525
1084
|
};
|
|
@@ -537,7 +1096,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
537
1096
|
data: { success: false },
|
|
538
1097
|
status: "failed",
|
|
539
1098
|
error: {
|
|
540
|
-
code:
|
|
1099
|
+
code: RevstackErrorCode7.UnknownError,
|
|
541
1100
|
message: "Failed to setup webhooks in Polar"
|
|
542
1101
|
}
|
|
543
1102
|
};
|
|
@@ -552,7 +1111,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
552
1111
|
data: { success: false },
|
|
553
1112
|
status: "failed",
|
|
554
1113
|
error: {
|
|
555
|
-
code:
|
|
1114
|
+
code: RevstackErrorCode7.MisconfiguredProvider,
|
|
556
1115
|
message: `Webhook setup failed: ${error.message}`
|
|
557
1116
|
}
|
|
558
1117
|
};
|
|
@@ -611,7 +1170,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
611
1170
|
data: null,
|
|
612
1171
|
status: "failed",
|
|
613
1172
|
error: {
|
|
614
|
-
code:
|
|
1173
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
615
1174
|
message: `Provider '${this.manifest.slug}' does not support createPayment.`
|
|
616
1175
|
}
|
|
617
1176
|
};
|
|
@@ -625,7 +1184,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
625
1184
|
data: null,
|
|
626
1185
|
status: "failed",
|
|
627
1186
|
error: {
|
|
628
|
-
code:
|
|
1187
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
629
1188
|
message: "Get payment not supported"
|
|
630
1189
|
}
|
|
631
1190
|
};
|
|
@@ -639,26 +1198,26 @@ var PolarProvider = class extends BaseProvider {
|
|
|
639
1198
|
data: null,
|
|
640
1199
|
status: "failed",
|
|
641
1200
|
error: {
|
|
642
|
-
code:
|
|
1201
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
643
1202
|
message: "Refunds not supported by this provider version"
|
|
644
1203
|
}
|
|
645
1204
|
};
|
|
646
1205
|
}
|
|
647
1206
|
return client.refundPayment(ctx, input);
|
|
648
1207
|
}
|
|
649
|
-
async listPayments(ctx, pagination) {
|
|
1208
|
+
async listPayments(ctx, pagination, filters) {
|
|
650
1209
|
const client = getClient(ctx.config);
|
|
651
1210
|
if (!client.listPayments) {
|
|
652
1211
|
return {
|
|
653
1212
|
data: null,
|
|
654
1213
|
status: "failed",
|
|
655
1214
|
error: {
|
|
656
|
-
code:
|
|
1215
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
657
1216
|
message: "List payments not supported"
|
|
658
1217
|
}
|
|
659
1218
|
};
|
|
660
1219
|
}
|
|
661
|
-
return client.listPayments(ctx, pagination);
|
|
1220
|
+
return client.listPayments(ctx, pagination, filters);
|
|
662
1221
|
}
|
|
663
1222
|
// ===========================================================================
|
|
664
1223
|
// SUBSCRIPTIONS
|
|
@@ -670,7 +1229,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
670
1229
|
data: null,
|
|
671
1230
|
status: "failed",
|
|
672
1231
|
error: {
|
|
673
|
-
code:
|
|
1232
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
674
1233
|
message: "Subscriptions not supported"
|
|
675
1234
|
}
|
|
676
1235
|
};
|
|
@@ -684,7 +1243,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
684
1243
|
data: null,
|
|
685
1244
|
status: "failed",
|
|
686
1245
|
error: {
|
|
687
|
-
code:
|
|
1246
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
688
1247
|
message: "Get subscription not supported"
|
|
689
1248
|
}
|
|
690
1249
|
};
|
|
@@ -698,7 +1257,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
698
1257
|
data: null,
|
|
699
1258
|
status: "failed",
|
|
700
1259
|
error: {
|
|
701
|
-
code:
|
|
1260
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
702
1261
|
message: "Cancel subscription not supported"
|
|
703
1262
|
}
|
|
704
1263
|
};
|
|
@@ -712,7 +1271,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
712
1271
|
data: null,
|
|
713
1272
|
status: "failed",
|
|
714
1273
|
error: {
|
|
715
|
-
code:
|
|
1274
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
716
1275
|
message: "Pause subscription not supported"
|
|
717
1276
|
}
|
|
718
1277
|
};
|
|
@@ -726,7 +1285,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
726
1285
|
data: null,
|
|
727
1286
|
status: "failed",
|
|
728
1287
|
error: {
|
|
729
|
-
code:
|
|
1288
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
730
1289
|
message: "Resume subscription not supported"
|
|
731
1290
|
}
|
|
732
1291
|
};
|
|
@@ -743,7 +1302,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
743
1302
|
data: null,
|
|
744
1303
|
status: "failed",
|
|
745
1304
|
error: {
|
|
746
|
-
code:
|
|
1305
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
747
1306
|
message: "Checkout not supported"
|
|
748
1307
|
}
|
|
749
1308
|
};
|
|
@@ -760,7 +1319,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
760
1319
|
data: null,
|
|
761
1320
|
status: "failed",
|
|
762
1321
|
error: {
|
|
763
|
-
code:
|
|
1322
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
764
1323
|
message: "Customer management not supported"
|
|
765
1324
|
}
|
|
766
1325
|
};
|
|
@@ -774,7 +1333,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
774
1333
|
data: null,
|
|
775
1334
|
status: "failed",
|
|
776
1335
|
error: {
|
|
777
|
-
code:
|
|
1336
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
778
1337
|
message: "Customer update not supported"
|
|
779
1338
|
}
|
|
780
1339
|
};
|
|
@@ -788,7 +1347,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
788
1347
|
data: false,
|
|
789
1348
|
status: "failed",
|
|
790
1349
|
error: {
|
|
791
|
-
code:
|
|
1350
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
792
1351
|
message: "Customer deletion not supported"
|
|
793
1352
|
}
|
|
794
1353
|
};
|
|
@@ -802,7 +1361,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
802
1361
|
data: null,
|
|
803
1362
|
status: "failed",
|
|
804
1363
|
error: {
|
|
805
|
-
code:
|
|
1364
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
806
1365
|
message: "Get customer not supported"
|
|
807
1366
|
}
|
|
808
1367
|
};
|
|
@@ -819,7 +1378,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
819
1378
|
data: null,
|
|
820
1379
|
status: "failed",
|
|
821
1380
|
error: {
|
|
822
|
-
code:
|
|
1381
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
823
1382
|
message: "List payment methods not supported"
|
|
824
1383
|
}
|
|
825
1384
|
};
|
|
@@ -833,7 +1392,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
833
1392
|
data: false,
|
|
834
1393
|
status: "failed",
|
|
835
1394
|
error: {
|
|
836
|
-
code:
|
|
1395
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
837
1396
|
message: "Delete payment method not supported"
|
|
838
1397
|
}
|
|
839
1398
|
};
|
|
@@ -850,26 +1409,26 @@ var PolarProvider = class extends BaseProvider {
|
|
|
850
1409
|
data: null,
|
|
851
1410
|
status: "failed",
|
|
852
1411
|
error: {
|
|
853
|
-
code:
|
|
1412
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
854
1413
|
message: "Capture not supported"
|
|
855
1414
|
}
|
|
856
1415
|
};
|
|
857
1416
|
}
|
|
858
1417
|
return client.capturePayment(ctx, id, amount);
|
|
859
1418
|
}
|
|
860
|
-
async listSubscriptions(ctx, pagination) {
|
|
1419
|
+
async listSubscriptions(ctx, pagination, filters) {
|
|
861
1420
|
const client = getClient(ctx.config);
|
|
862
1421
|
if (!client.listSubscriptions) {
|
|
863
1422
|
return {
|
|
864
1423
|
data: null,
|
|
865
1424
|
status: "failed",
|
|
866
1425
|
error: {
|
|
867
|
-
code:
|
|
1426
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
868
1427
|
message: "List subscriptions not supported"
|
|
869
1428
|
}
|
|
870
1429
|
};
|
|
871
1430
|
}
|
|
872
|
-
return client.listSubscriptions(ctx, pagination);
|
|
1431
|
+
return client.listSubscriptions(ctx, pagination, filters);
|
|
873
1432
|
}
|
|
874
1433
|
async updateSubscription(ctx, id, input) {
|
|
875
1434
|
const client = getClient(ctx.config);
|
|
@@ -878,26 +1437,26 @@ var PolarProvider = class extends BaseProvider {
|
|
|
878
1437
|
data: null,
|
|
879
1438
|
status: "failed",
|
|
880
1439
|
error: {
|
|
881
|
-
code:
|
|
1440
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
882
1441
|
message: "Update subscription not supported"
|
|
883
1442
|
}
|
|
884
1443
|
};
|
|
885
1444
|
}
|
|
886
1445
|
return client.updateSubscription(ctx, id, input);
|
|
887
1446
|
}
|
|
888
|
-
async listCustomers(ctx, pagination) {
|
|
1447
|
+
async listCustomers(ctx, pagination, filters) {
|
|
889
1448
|
const client = getClient(ctx.config);
|
|
890
1449
|
if (!client.listCustomers) {
|
|
891
1450
|
return {
|
|
892
1451
|
data: null,
|
|
893
1452
|
status: "failed",
|
|
894
1453
|
error: {
|
|
895
|
-
code:
|
|
1454
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
896
1455
|
message: "List customers not supported"
|
|
897
1456
|
}
|
|
898
1457
|
};
|
|
899
1458
|
}
|
|
900
|
-
return client.listCustomers(ctx, pagination);
|
|
1459
|
+
return client.listCustomers(ctx, pagination, filters);
|
|
901
1460
|
}
|
|
902
1461
|
async setupPaymentMethod(ctx, input) {
|
|
903
1462
|
const client = getClient(ctx.config);
|
|
@@ -906,7 +1465,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
906
1465
|
data: null,
|
|
907
1466
|
status: "failed",
|
|
908
1467
|
error: {
|
|
909
|
-
code:
|
|
1468
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
910
1469
|
message: "Setup payment method not supported"
|
|
911
1470
|
}
|
|
912
1471
|
};
|
|
@@ -920,86 +1479,13 @@ var PolarProvider = class extends BaseProvider {
|
|
|
920
1479
|
data: null,
|
|
921
1480
|
status: "failed",
|
|
922
1481
|
error: {
|
|
923
|
-
code:
|
|
1482
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
924
1483
|
message: "Billing portal not supported"
|
|
925
1484
|
}
|
|
926
1485
|
};
|
|
927
1486
|
}
|
|
928
1487
|
return client.createBillingPortalSession(ctx, input);
|
|
929
1488
|
}
|
|
930
|
-
// ===========================================================================
|
|
931
|
-
// ADDONS
|
|
932
|
-
// ===========================================================================
|
|
933
|
-
async createAddon(ctx, input) {
|
|
934
|
-
const client = getClient(ctx.config);
|
|
935
|
-
if (!client.createAddon) {
|
|
936
|
-
return {
|
|
937
|
-
data: null,
|
|
938
|
-
status: "failed",
|
|
939
|
-
error: {
|
|
940
|
-
code: RevstackErrorCode.NotImplemented,
|
|
941
|
-
message: "Create Addon not supported"
|
|
942
|
-
}
|
|
943
|
-
};
|
|
944
|
-
}
|
|
945
|
-
return client.createAddon(ctx, input);
|
|
946
|
-
}
|
|
947
|
-
async getAddon(ctx, id) {
|
|
948
|
-
const client = getClient(ctx.config);
|
|
949
|
-
if (!client.getAddon) {
|
|
950
|
-
return {
|
|
951
|
-
data: null,
|
|
952
|
-
status: "failed",
|
|
953
|
-
error: {
|
|
954
|
-
code: RevstackErrorCode.NotImplemented,
|
|
955
|
-
message: "Get Addon not supported"
|
|
956
|
-
}
|
|
957
|
-
};
|
|
958
|
-
}
|
|
959
|
-
return client.getAddon(ctx, id);
|
|
960
|
-
}
|
|
961
|
-
async updateAddon(ctx, id, input) {
|
|
962
|
-
const client = getClient(ctx.config);
|
|
963
|
-
if (!client.updateAddon) {
|
|
964
|
-
return {
|
|
965
|
-
data: null,
|
|
966
|
-
status: "failed",
|
|
967
|
-
error: {
|
|
968
|
-
code: RevstackErrorCode.NotImplemented,
|
|
969
|
-
message: "Update Addon not supported"
|
|
970
|
-
}
|
|
971
|
-
};
|
|
972
|
-
}
|
|
973
|
-
return client.updateAddon(ctx, id, input);
|
|
974
|
-
}
|
|
975
|
-
async deleteAddon(ctx, input) {
|
|
976
|
-
const client = getClient(ctx.config);
|
|
977
|
-
if (!client.deleteAddon) {
|
|
978
|
-
return {
|
|
979
|
-
data: false,
|
|
980
|
-
status: "failed",
|
|
981
|
-
error: {
|
|
982
|
-
code: RevstackErrorCode.NotImplemented,
|
|
983
|
-
message: "Delete Addon not supported"
|
|
984
|
-
}
|
|
985
|
-
};
|
|
986
|
-
}
|
|
987
|
-
return client.deleteAddon(ctx, input);
|
|
988
|
-
}
|
|
989
|
-
async listAddons(ctx, subscriptionId, pagination) {
|
|
990
|
-
const client = getClient(ctx.config);
|
|
991
|
-
if (!client.listAddons) {
|
|
992
|
-
return {
|
|
993
|
-
data: null,
|
|
994
|
-
status: "failed",
|
|
995
|
-
error: {
|
|
996
|
-
code: RevstackErrorCode.NotImplemented,
|
|
997
|
-
message: "List Addons not supported"
|
|
998
|
-
}
|
|
999
|
-
};
|
|
1000
|
-
}
|
|
1001
|
-
return client.listAddons(ctx, subscriptionId, pagination);
|
|
1002
|
-
}
|
|
1003
1489
|
};
|
|
1004
1490
|
export {
|
|
1005
1491
|
PolarProvider,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revstackhq/provider-polar",
|
|
3
|
-
"version": "0.0.0
|
|
3
|
+
"version": "0.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "FSL-1.1-MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@polar-sh/sdk": "^0.45.1",
|
|
24
24
|
"dotenv": "^17.2.4",
|
|
25
|
-
"@revstackhq/providers-core": "0.0.0
|
|
25
|
+
"@revstackhq/providers-core": "0.0.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@eslint/js": "^9.39.1",
|