@revstackhq/provider-polar 0.0.0-dev-20260301205307 → 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 +691 -231
- 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,7 +833,7 @@ var setupWebhooks = async (ctx, webhookUrl) => {
|
|
|
278
833
|
"product.created",
|
|
279
834
|
"product.updated"
|
|
280
835
|
];
|
|
281
|
-
const webhooksList = await
|
|
836
|
+
const webhooksList = await polar.webhooks.listWebhookEndpoints({
|
|
282
837
|
organizationId: ctx.config.organizationId,
|
|
283
838
|
limit: 100
|
|
284
839
|
});
|
|
@@ -288,7 +843,7 @@ var setupWebhooks = async (ctx, webhookUrl) => {
|
|
|
288
843
|
let webhookEndpointId;
|
|
289
844
|
let secret;
|
|
290
845
|
if (existingWebhook) {
|
|
291
|
-
const updated = await
|
|
846
|
+
const updated = await polar.webhooks.updateWebhookEndpoint({
|
|
292
847
|
id: existingWebhook.id,
|
|
293
848
|
webhookEndpointUpdate: {
|
|
294
849
|
url: webhookUrl,
|
|
@@ -299,7 +854,7 @@ var setupWebhooks = async (ctx, webhookUrl) => {
|
|
|
299
854
|
webhookEndpointId = updated.id;
|
|
300
855
|
secret = void 0;
|
|
301
856
|
} else {
|
|
302
|
-
const created = await
|
|
857
|
+
const created = await polar.webhooks.createWebhookEndpoint({
|
|
303
858
|
url: webhookUrl,
|
|
304
859
|
format: "raw",
|
|
305
860
|
events,
|
|
@@ -329,9 +884,9 @@ var setupWebhooks = async (ctx, webhookUrl) => {
|
|
|
329
884
|
}
|
|
330
885
|
};
|
|
331
886
|
var removeWebhooks = async (ctx, webhookId) => {
|
|
332
|
-
const
|
|
887
|
+
const polar = getOrCreatePolar(ctx.config.accessToken);
|
|
333
888
|
try {
|
|
334
|
-
await
|
|
889
|
+
await polar.webhooks.deleteWebhookEndpoint({ id: webhookId });
|
|
335
890
|
return { data: true, status: "success" };
|
|
336
891
|
} catch (error) {
|
|
337
892
|
return { data: false, status: "failed" };
|
|
@@ -373,32 +928,28 @@ var parseWebhookEvent = async (payload) => {
|
|
|
373
928
|
};
|
|
374
929
|
};
|
|
375
930
|
|
|
376
|
-
// src/
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
};
|
|
380
|
-
var
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
}
|
|
386
|
-
var deleteAddon = async (...args) => {
|
|
387
|
-
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
|
+
}
|
|
388
941
|
};
|
|
389
|
-
var
|
|
390
|
-
|
|
942
|
+
var setupPaymentMethod = async (_ctx, _input) => {
|
|
943
|
+
return { ...NOT_IMPLEMENTED, data: null };
|
|
391
944
|
};
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
var listPaymentMethods = async (...args) => {
|
|
395
|
-
throw new Error("Not implemented");
|
|
945
|
+
var listPaymentMethods = async (_ctx, _customerId) => {
|
|
946
|
+
return { ...NOT_IMPLEMENTED, data: null };
|
|
396
947
|
};
|
|
397
|
-
var deletePaymentMethod = async (
|
|
398
|
-
|
|
948
|
+
var deletePaymentMethod = async (_ctx, _id) => {
|
|
949
|
+
return { ...NOT_IMPLEMENTED, data: false };
|
|
399
950
|
};
|
|
400
951
|
|
|
401
|
-
// src/
|
|
952
|
+
// src/api/v1/index.ts
|
|
402
953
|
var PolarClientV1 = class {
|
|
403
954
|
// ===========================================================================
|
|
404
955
|
// LIFECYCLE & WEBHOOKS
|
|
@@ -418,6 +969,9 @@ var PolarClientV1 = class {
|
|
|
418
969
|
parseWebhookEvent(payload) {
|
|
419
970
|
return parseWebhookEvent(payload);
|
|
420
971
|
}
|
|
972
|
+
setupPaymentMethod(ctx, input) {
|
|
973
|
+
return setupPaymentMethod(ctx, input);
|
|
974
|
+
}
|
|
421
975
|
listPaymentMethods(ctx, customerId) {
|
|
422
976
|
return listPaymentMethods(ctx, customerId);
|
|
423
977
|
}
|
|
@@ -434,7 +988,7 @@ var PolarClientV1 = class {
|
|
|
434
988
|
return getPayment(ctx, id);
|
|
435
989
|
}
|
|
436
990
|
refundPayment(ctx, input) {
|
|
437
|
-
return refundPayment(ctx, input);
|
|
991
|
+
return refundPayment(ctx, input.paymentId, input.amount);
|
|
438
992
|
}
|
|
439
993
|
listPayments(ctx, pagination) {
|
|
440
994
|
return listPayments(ctx, pagination);
|
|
@@ -476,9 +1030,6 @@ var PolarClientV1 = class {
|
|
|
476
1030
|
createCheckoutSession(ctx, input) {
|
|
477
1031
|
return createCheckoutSession(ctx, input);
|
|
478
1032
|
}
|
|
479
|
-
setupPaymentMethod(ctx, input) {
|
|
480
|
-
return setupPaymentMethod(ctx, input);
|
|
481
|
-
}
|
|
482
1033
|
createBillingPortalSession(ctx, input) {
|
|
483
1034
|
return createBillingPortalSession(ctx, input);
|
|
484
1035
|
}
|
|
@@ -500,27 +1051,9 @@ var PolarClientV1 = class {
|
|
|
500
1051
|
listCustomers(ctx, pagination) {
|
|
501
1052
|
return listCustomers(ctx, pagination);
|
|
502
1053
|
}
|
|
503
|
-
// ===========================================================================
|
|
504
|
-
// ADDONS
|
|
505
|
-
// ===========================================================================
|
|
506
|
-
createAddon(ctx, input) {
|
|
507
|
-
return createAddon(ctx, input);
|
|
508
|
-
}
|
|
509
|
-
getAddon(ctx, id) {
|
|
510
|
-
return getAddon(ctx, id);
|
|
511
|
-
}
|
|
512
|
-
updateAddon(ctx, id, input) {
|
|
513
|
-
return updateAddon(ctx, id, input);
|
|
514
|
-
}
|
|
515
|
-
deleteAddon(ctx, input) {
|
|
516
|
-
return deleteAddon(ctx, input);
|
|
517
|
-
}
|
|
518
|
-
listAddons(ctx, subscriptionId, pagination) {
|
|
519
|
-
return listAddons(ctx, subscriptionId, pagination);
|
|
520
|
-
}
|
|
521
1054
|
};
|
|
522
1055
|
|
|
523
|
-
// src/
|
|
1056
|
+
// src/api/factory.ts
|
|
524
1057
|
function getClient(_config) {
|
|
525
1058
|
return new PolarClientV1();
|
|
526
1059
|
}
|
|
@@ -528,7 +1061,7 @@ function getClient(_config) {
|
|
|
528
1061
|
// src/provider.ts
|
|
529
1062
|
import {
|
|
530
1063
|
BaseProvider,
|
|
531
|
-
RevstackErrorCode
|
|
1064
|
+
RevstackErrorCode as RevstackErrorCode7
|
|
532
1065
|
} from "@revstackhq/providers-core";
|
|
533
1066
|
var PolarProvider = class extends BaseProvider {
|
|
534
1067
|
static manifest = manifest;
|
|
@@ -545,7 +1078,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
545
1078
|
data: { success: false },
|
|
546
1079
|
status: "failed",
|
|
547
1080
|
error: {
|
|
548
|
-
code:
|
|
1081
|
+
code: RevstackErrorCode7.InvalidCredentials,
|
|
549
1082
|
message: "Failed to connect to provider. Please check your API Key / Secrets."
|
|
550
1083
|
}
|
|
551
1084
|
};
|
|
@@ -563,7 +1096,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
563
1096
|
data: { success: false },
|
|
564
1097
|
status: "failed",
|
|
565
1098
|
error: {
|
|
566
|
-
code:
|
|
1099
|
+
code: RevstackErrorCode7.UnknownError,
|
|
567
1100
|
message: "Failed to setup webhooks in Polar"
|
|
568
1101
|
}
|
|
569
1102
|
};
|
|
@@ -578,7 +1111,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
578
1111
|
data: { success: false },
|
|
579
1112
|
status: "failed",
|
|
580
1113
|
error: {
|
|
581
|
-
code:
|
|
1114
|
+
code: RevstackErrorCode7.MisconfiguredProvider,
|
|
582
1115
|
message: `Webhook setup failed: ${error.message}`
|
|
583
1116
|
}
|
|
584
1117
|
};
|
|
@@ -637,7 +1170,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
637
1170
|
data: null,
|
|
638
1171
|
status: "failed",
|
|
639
1172
|
error: {
|
|
640
|
-
code:
|
|
1173
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
641
1174
|
message: `Provider '${this.manifest.slug}' does not support createPayment.`
|
|
642
1175
|
}
|
|
643
1176
|
};
|
|
@@ -651,7 +1184,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
651
1184
|
data: null,
|
|
652
1185
|
status: "failed",
|
|
653
1186
|
error: {
|
|
654
|
-
code:
|
|
1187
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
655
1188
|
message: "Get payment not supported"
|
|
656
1189
|
}
|
|
657
1190
|
};
|
|
@@ -665,26 +1198,26 @@ var PolarProvider = class extends BaseProvider {
|
|
|
665
1198
|
data: null,
|
|
666
1199
|
status: "failed",
|
|
667
1200
|
error: {
|
|
668
|
-
code:
|
|
1201
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
669
1202
|
message: "Refunds not supported by this provider version"
|
|
670
1203
|
}
|
|
671
1204
|
};
|
|
672
1205
|
}
|
|
673
1206
|
return client.refundPayment(ctx, input);
|
|
674
1207
|
}
|
|
675
|
-
async listPayments(ctx, pagination) {
|
|
1208
|
+
async listPayments(ctx, pagination, filters) {
|
|
676
1209
|
const client = getClient(ctx.config);
|
|
677
1210
|
if (!client.listPayments) {
|
|
678
1211
|
return {
|
|
679
1212
|
data: null,
|
|
680
1213
|
status: "failed",
|
|
681
1214
|
error: {
|
|
682
|
-
code:
|
|
1215
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
683
1216
|
message: "List payments not supported"
|
|
684
1217
|
}
|
|
685
1218
|
};
|
|
686
1219
|
}
|
|
687
|
-
return client.listPayments(ctx, pagination);
|
|
1220
|
+
return client.listPayments(ctx, pagination, filters);
|
|
688
1221
|
}
|
|
689
1222
|
// ===========================================================================
|
|
690
1223
|
// SUBSCRIPTIONS
|
|
@@ -696,7 +1229,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
696
1229
|
data: null,
|
|
697
1230
|
status: "failed",
|
|
698
1231
|
error: {
|
|
699
|
-
code:
|
|
1232
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
700
1233
|
message: "Subscriptions not supported"
|
|
701
1234
|
}
|
|
702
1235
|
};
|
|
@@ -710,7 +1243,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
710
1243
|
data: null,
|
|
711
1244
|
status: "failed",
|
|
712
1245
|
error: {
|
|
713
|
-
code:
|
|
1246
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
714
1247
|
message: "Get subscription not supported"
|
|
715
1248
|
}
|
|
716
1249
|
};
|
|
@@ -724,7 +1257,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
724
1257
|
data: null,
|
|
725
1258
|
status: "failed",
|
|
726
1259
|
error: {
|
|
727
|
-
code:
|
|
1260
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
728
1261
|
message: "Cancel subscription not supported"
|
|
729
1262
|
}
|
|
730
1263
|
};
|
|
@@ -738,7 +1271,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
738
1271
|
data: null,
|
|
739
1272
|
status: "failed",
|
|
740
1273
|
error: {
|
|
741
|
-
code:
|
|
1274
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
742
1275
|
message: "Pause subscription not supported"
|
|
743
1276
|
}
|
|
744
1277
|
};
|
|
@@ -752,7 +1285,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
752
1285
|
data: null,
|
|
753
1286
|
status: "failed",
|
|
754
1287
|
error: {
|
|
755
|
-
code:
|
|
1288
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
756
1289
|
message: "Resume subscription not supported"
|
|
757
1290
|
}
|
|
758
1291
|
};
|
|
@@ -769,7 +1302,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
769
1302
|
data: null,
|
|
770
1303
|
status: "failed",
|
|
771
1304
|
error: {
|
|
772
|
-
code:
|
|
1305
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
773
1306
|
message: "Checkout not supported"
|
|
774
1307
|
}
|
|
775
1308
|
};
|
|
@@ -786,7 +1319,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
786
1319
|
data: null,
|
|
787
1320
|
status: "failed",
|
|
788
1321
|
error: {
|
|
789
|
-
code:
|
|
1322
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
790
1323
|
message: "Customer management not supported"
|
|
791
1324
|
}
|
|
792
1325
|
};
|
|
@@ -800,7 +1333,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
800
1333
|
data: null,
|
|
801
1334
|
status: "failed",
|
|
802
1335
|
error: {
|
|
803
|
-
code:
|
|
1336
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
804
1337
|
message: "Customer update not supported"
|
|
805
1338
|
}
|
|
806
1339
|
};
|
|
@@ -814,7 +1347,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
814
1347
|
data: false,
|
|
815
1348
|
status: "failed",
|
|
816
1349
|
error: {
|
|
817
|
-
code:
|
|
1350
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
818
1351
|
message: "Customer deletion not supported"
|
|
819
1352
|
}
|
|
820
1353
|
};
|
|
@@ -828,7 +1361,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
828
1361
|
data: null,
|
|
829
1362
|
status: "failed",
|
|
830
1363
|
error: {
|
|
831
|
-
code:
|
|
1364
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
832
1365
|
message: "Get customer not supported"
|
|
833
1366
|
}
|
|
834
1367
|
};
|
|
@@ -845,7 +1378,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
845
1378
|
data: null,
|
|
846
1379
|
status: "failed",
|
|
847
1380
|
error: {
|
|
848
|
-
code:
|
|
1381
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
849
1382
|
message: "List payment methods not supported"
|
|
850
1383
|
}
|
|
851
1384
|
};
|
|
@@ -859,7 +1392,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
859
1392
|
data: false,
|
|
860
1393
|
status: "failed",
|
|
861
1394
|
error: {
|
|
862
|
-
code:
|
|
1395
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
863
1396
|
message: "Delete payment method not supported"
|
|
864
1397
|
}
|
|
865
1398
|
};
|
|
@@ -876,26 +1409,26 @@ var PolarProvider = class extends BaseProvider {
|
|
|
876
1409
|
data: null,
|
|
877
1410
|
status: "failed",
|
|
878
1411
|
error: {
|
|
879
|
-
code:
|
|
1412
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
880
1413
|
message: "Capture not supported"
|
|
881
1414
|
}
|
|
882
1415
|
};
|
|
883
1416
|
}
|
|
884
1417
|
return client.capturePayment(ctx, id, amount);
|
|
885
1418
|
}
|
|
886
|
-
async listSubscriptions(ctx, pagination) {
|
|
1419
|
+
async listSubscriptions(ctx, pagination, filters) {
|
|
887
1420
|
const client = getClient(ctx.config);
|
|
888
1421
|
if (!client.listSubscriptions) {
|
|
889
1422
|
return {
|
|
890
1423
|
data: null,
|
|
891
1424
|
status: "failed",
|
|
892
1425
|
error: {
|
|
893
|
-
code:
|
|
1426
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
894
1427
|
message: "List subscriptions not supported"
|
|
895
1428
|
}
|
|
896
1429
|
};
|
|
897
1430
|
}
|
|
898
|
-
return client.listSubscriptions(ctx, pagination);
|
|
1431
|
+
return client.listSubscriptions(ctx, pagination, filters);
|
|
899
1432
|
}
|
|
900
1433
|
async updateSubscription(ctx, id, input) {
|
|
901
1434
|
const client = getClient(ctx.config);
|
|
@@ -904,26 +1437,26 @@ var PolarProvider = class extends BaseProvider {
|
|
|
904
1437
|
data: null,
|
|
905
1438
|
status: "failed",
|
|
906
1439
|
error: {
|
|
907
|
-
code:
|
|
1440
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
908
1441
|
message: "Update subscription not supported"
|
|
909
1442
|
}
|
|
910
1443
|
};
|
|
911
1444
|
}
|
|
912
1445
|
return client.updateSubscription(ctx, id, input);
|
|
913
1446
|
}
|
|
914
|
-
async listCustomers(ctx, pagination) {
|
|
1447
|
+
async listCustomers(ctx, pagination, filters) {
|
|
915
1448
|
const client = getClient(ctx.config);
|
|
916
1449
|
if (!client.listCustomers) {
|
|
917
1450
|
return {
|
|
918
1451
|
data: null,
|
|
919
1452
|
status: "failed",
|
|
920
1453
|
error: {
|
|
921
|
-
code:
|
|
1454
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
922
1455
|
message: "List customers not supported"
|
|
923
1456
|
}
|
|
924
1457
|
};
|
|
925
1458
|
}
|
|
926
|
-
return client.listCustomers(ctx, pagination);
|
|
1459
|
+
return client.listCustomers(ctx, pagination, filters);
|
|
927
1460
|
}
|
|
928
1461
|
async setupPaymentMethod(ctx, input) {
|
|
929
1462
|
const client = getClient(ctx.config);
|
|
@@ -932,7 +1465,7 @@ var PolarProvider = class extends BaseProvider {
|
|
|
932
1465
|
data: null,
|
|
933
1466
|
status: "failed",
|
|
934
1467
|
error: {
|
|
935
|
-
code:
|
|
1468
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
936
1469
|
message: "Setup payment method not supported"
|
|
937
1470
|
}
|
|
938
1471
|
};
|
|
@@ -946,86 +1479,13 @@ var PolarProvider = class extends BaseProvider {
|
|
|
946
1479
|
data: null,
|
|
947
1480
|
status: "failed",
|
|
948
1481
|
error: {
|
|
949
|
-
code:
|
|
1482
|
+
code: RevstackErrorCode7.NotImplemented,
|
|
950
1483
|
message: "Billing portal not supported"
|
|
951
1484
|
}
|
|
952
1485
|
};
|
|
953
1486
|
}
|
|
954
1487
|
return client.createBillingPortalSession(ctx, input);
|
|
955
1488
|
}
|
|
956
|
-
// ===========================================================================
|
|
957
|
-
// ADDONS
|
|
958
|
-
// ===========================================================================
|
|
959
|
-
async createAddon(ctx, input) {
|
|
960
|
-
const client = getClient(ctx.config);
|
|
961
|
-
if (!client.createAddon) {
|
|
962
|
-
return {
|
|
963
|
-
data: null,
|
|
964
|
-
status: "failed",
|
|
965
|
-
error: {
|
|
966
|
-
code: RevstackErrorCode.NotImplemented,
|
|
967
|
-
message: "Create Addon not supported"
|
|
968
|
-
}
|
|
969
|
-
};
|
|
970
|
-
}
|
|
971
|
-
return client.createAddon(ctx, input);
|
|
972
|
-
}
|
|
973
|
-
async getAddon(ctx, id) {
|
|
974
|
-
const client = getClient(ctx.config);
|
|
975
|
-
if (!client.getAddon) {
|
|
976
|
-
return {
|
|
977
|
-
data: null,
|
|
978
|
-
status: "failed",
|
|
979
|
-
error: {
|
|
980
|
-
code: RevstackErrorCode.NotImplemented,
|
|
981
|
-
message: "Get Addon not supported"
|
|
982
|
-
}
|
|
983
|
-
};
|
|
984
|
-
}
|
|
985
|
-
return client.getAddon(ctx, id);
|
|
986
|
-
}
|
|
987
|
-
async updateAddon(ctx, id, input) {
|
|
988
|
-
const client = getClient(ctx.config);
|
|
989
|
-
if (!client.updateAddon) {
|
|
990
|
-
return {
|
|
991
|
-
data: null,
|
|
992
|
-
status: "failed",
|
|
993
|
-
error: {
|
|
994
|
-
code: RevstackErrorCode.NotImplemented,
|
|
995
|
-
message: "Update Addon not supported"
|
|
996
|
-
}
|
|
997
|
-
};
|
|
998
|
-
}
|
|
999
|
-
return client.updateAddon(ctx, id, input);
|
|
1000
|
-
}
|
|
1001
|
-
async deleteAddon(ctx, input) {
|
|
1002
|
-
const client = getClient(ctx.config);
|
|
1003
|
-
if (!client.deleteAddon) {
|
|
1004
|
-
return {
|
|
1005
|
-
data: false,
|
|
1006
|
-
status: "failed",
|
|
1007
|
-
error: {
|
|
1008
|
-
code: RevstackErrorCode.NotImplemented,
|
|
1009
|
-
message: "Delete Addon not supported"
|
|
1010
|
-
}
|
|
1011
|
-
};
|
|
1012
|
-
}
|
|
1013
|
-
return client.deleteAddon(ctx, input);
|
|
1014
|
-
}
|
|
1015
|
-
async listAddons(ctx, subscriptionId, pagination) {
|
|
1016
|
-
const client = getClient(ctx.config);
|
|
1017
|
-
if (!client.listAddons) {
|
|
1018
|
-
return {
|
|
1019
|
-
data: null,
|
|
1020
|
-
status: "failed",
|
|
1021
|
-
error: {
|
|
1022
|
-
code: RevstackErrorCode.NotImplemented,
|
|
1023
|
-
message: "List Addons not supported"
|
|
1024
|
-
}
|
|
1025
|
-
};
|
|
1026
|
-
}
|
|
1027
|
-
return client.listAddons(ctx, subscriptionId, pagination);
|
|
1028
|
-
}
|
|
1029
1489
|
};
|
|
1030
1490
|
export {
|
|
1031
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",
|