@revstackhq/provider-polar 0.0.0-dev-20260301193938
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/LICENSE +110 -0
- package/assets/logo.svg +6 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.js +1006 -0
- package/dist/logo.svg +6 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, MIT Future License
|
|
2
|
+
|
|
3
|
+
## Abbreviation
|
|
4
|
+
|
|
5
|
+
FSL-1.1-MIT
|
|
6
|
+
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2026 Revstack Inc.
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or
|
|
34
|
+
service that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software
|
|
39
|
+
that exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee
|
|
52
|
+
using the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to
|
|
59
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
79
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the MIT license that is effective on the second anniversary of the date we make
|
|
91
|
+
the Software available. On or after that date, you may use the Software under
|
|
92
|
+
the MIT license, in which case the following will apply:
|
|
93
|
+
|
|
94
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
95
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
96
|
+
the Software without restriction, including without limitation the rights to
|
|
97
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
98
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
99
|
+
so, subject to the following conditions:
|
|
100
|
+
|
|
101
|
+
The above copyright notice and this permission notice shall be included in all
|
|
102
|
+
copies or substantial portions of the Software.
|
|
103
|
+
|
|
104
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
105
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
106
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
107
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
108
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
109
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
110
|
+
SOFTWARE.
|
package/assets/logo.svg
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<svg width="100%" height="100%" viewBox="0 0 24 24" stroke-width="1.5" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path d="M12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
|
|
3
|
+
<path d="M12 22C9.79086 22 8 17.5228 8 12C8 6.47715 9.79086 2 12 2C14.2091 2 16 6.47715 16 12C16 17.5228 14.2091 22 12 22Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
|
|
4
|
+
<path d="M9 21C6 20 5 15.611 5 12.5C5 9.38904 6.5 5.5 10 3" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
|
|
5
|
+
<path d="M15 3C18 4 19 8.38904 19 11.5C19 14.611 17.5 18.5 14 21" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
|
|
6
|
+
</svg>
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
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, CreateAddonInput, Addon, UpdateAddonInput, DeleteAddonInput } from '@revstackhq/providers-core';
|
|
3
|
+
|
|
4
|
+
declare const manifest: ProviderManifest;
|
|
5
|
+
|
|
6
|
+
declare class PolarProvider extends BaseProvider {
|
|
7
|
+
static manifest: _revstackhq_providers_core.ProviderManifest;
|
|
8
|
+
manifest: _revstackhq_providers_core.ProviderManifest;
|
|
9
|
+
onInstall(ctx: ProviderContext, input: InstallInput): Promise<AsyncActionResult<InstallResult>>;
|
|
10
|
+
onUninstall(ctx: ProviderContext, input: UninstallInput): Promise<AsyncActionResult<boolean>>;
|
|
11
|
+
verifyWebhookSignature(ctx: ProviderContext, payload: string | Buffer, headers: Record<string, string | string[] | undefined>, secret: string): Promise<AsyncActionResult<boolean>>;
|
|
12
|
+
parseWebhookEvent(ctx: ProviderContext, payload: any): Promise<AsyncActionResult<RevstackEvent | null>>;
|
|
13
|
+
getWebhookResponse(): Promise<AsyncActionResult<WebhookResponse>>;
|
|
14
|
+
createPayment(ctx: ProviderContext, input: CreatePaymentInput): Promise<AsyncActionResult<string>>;
|
|
15
|
+
getPayment(ctx: ProviderContext, id: string): Promise<AsyncActionResult<Payment>>;
|
|
16
|
+
refundPayment(ctx: ProviderContext, input: RefundPaymentInput): Promise<AsyncActionResult<string>>;
|
|
17
|
+
listPayments(ctx: ProviderContext, pagination: PaginationOptions): Promise<AsyncActionResult<PaginatedResult<Payment>>>;
|
|
18
|
+
createSubscription(ctx: ProviderContext, input: CreateSubscriptionInput): Promise<AsyncActionResult<string>>;
|
|
19
|
+
getSubscription(ctx: ProviderContext, id: string): Promise<AsyncActionResult<Subscription>>;
|
|
20
|
+
cancelSubscription(ctx: ProviderContext, id: string, reason?: string): Promise<AsyncActionResult<string>>;
|
|
21
|
+
pauseSubscription(ctx: ProviderContext, id: string, reason?: string): Promise<AsyncActionResult<string>>;
|
|
22
|
+
resumeSubscription(ctx: ProviderContext, id: string, reason?: string): Promise<AsyncActionResult<string>>;
|
|
23
|
+
createCheckoutSession(ctx: ProviderContext, input: CheckoutSessionInput): Promise<AsyncActionResult<CheckoutSessionResult>>;
|
|
24
|
+
createCustomer(ctx: ProviderContext, input: CreateCustomerInput): Promise<AsyncActionResult<string>>;
|
|
25
|
+
updateCustomer(ctx: ProviderContext, id: string, input: UpdateCustomerInput): Promise<AsyncActionResult<string>>;
|
|
26
|
+
deleteCustomer(ctx: ProviderContext, id: string): Promise<AsyncActionResult<boolean>>;
|
|
27
|
+
getCustomer(ctx: ProviderContext, id: string): Promise<AsyncActionResult<Customer>>;
|
|
28
|
+
listPaymentMethods(ctx: ProviderContext, customerId: string): Promise<AsyncActionResult<PaymentMethod[]>>;
|
|
29
|
+
deletePaymentMethod(ctx: ProviderContext, id: string): Promise<AsyncActionResult<boolean>>;
|
|
30
|
+
capturePayment(ctx: ProviderContext, id: string, amount?: number): Promise<AsyncActionResult<string>>;
|
|
31
|
+
listSubscriptions(ctx: ProviderContext, pagination: PaginationOptions): Promise<AsyncActionResult<PaginatedResult<Subscription>>>;
|
|
32
|
+
updateSubscription(ctx: ProviderContext, id: string, input: UpdateSubscriptionInput): Promise<AsyncActionResult<string>>;
|
|
33
|
+
listCustomers(ctx: ProviderContext, pagination: PaginationOptions): Promise<AsyncActionResult<PaginatedResult<Customer>>>;
|
|
34
|
+
setupPaymentMethod(ctx: ProviderContext, input: SetupPaymentMethodInput): Promise<AsyncActionResult<CheckoutSessionResult>>;
|
|
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
|
+
}
|
|
42
|
+
|
|
43
|
+
export { PolarProvider, manifest };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,1006 @@
|
|
|
1
|
+
// src/manifest.ts
|
|
2
|
+
import { ProviderCategory } from "@revstackhq/providers-core";
|
|
3
|
+
var manifest = {
|
|
4
|
+
name: "Polar",
|
|
5
|
+
slug: "polar",
|
|
6
|
+
version: "1.0.0",
|
|
7
|
+
categories: [ProviderCategory.Card, ProviderCategory.Wallet],
|
|
8
|
+
engine: {
|
|
9
|
+
revstack: "^1.0.0",
|
|
10
|
+
node: ">=18.0.0"
|
|
11
|
+
},
|
|
12
|
+
media: {
|
|
13
|
+
icon: "https://cdn.jsdelivr.net/npm/@revstackhq/provider-polar/assets/logo.svg",
|
|
14
|
+
logo: "https://cdn.jsdelivr.net/npm/@revstackhq/provider-polar/assets/logo.svg"
|
|
15
|
+
},
|
|
16
|
+
status: "beta",
|
|
17
|
+
dashboardUrl: "https://polar.sh/dashboard",
|
|
18
|
+
hidden: false,
|
|
19
|
+
pricing: {
|
|
20
|
+
model: "transactional",
|
|
21
|
+
fees: "4% + 40\xA2 per transaction",
|
|
22
|
+
url: "https://polar.sh/resources/pricing"
|
|
23
|
+
},
|
|
24
|
+
capabilities: {
|
|
25
|
+
customers: {
|
|
26
|
+
supported: true,
|
|
27
|
+
features: {
|
|
28
|
+
create: true,
|
|
29
|
+
update: true,
|
|
30
|
+
delete: false
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
checkout: {
|
|
34
|
+
supported: true,
|
|
35
|
+
strategy: "redirect"
|
|
36
|
+
},
|
|
37
|
+
payments: {
|
|
38
|
+
supported: true,
|
|
39
|
+
features: {
|
|
40
|
+
capture: true,
|
|
41
|
+
disputes: true,
|
|
42
|
+
partialRefunds: true,
|
|
43
|
+
refunds: true
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
subscriptions: {
|
|
47
|
+
supported: true,
|
|
48
|
+
mode: "native",
|
|
49
|
+
features: {
|
|
50
|
+
cancellation: true,
|
|
51
|
+
pause: true,
|
|
52
|
+
resume: true,
|
|
53
|
+
proration: true
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
webhooks: {
|
|
57
|
+
supported: true,
|
|
58
|
+
verification: "signature"
|
|
59
|
+
},
|
|
60
|
+
catalog: {
|
|
61
|
+
supported: true,
|
|
62
|
+
strategy: "pre_created"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
author: "Revstack",
|
|
66
|
+
currencies: ["USD"],
|
|
67
|
+
description: "Merchant of record specifically tailored for software and SaaS developers.",
|
|
68
|
+
documentationUrl: "https://docs.revstack.dev/providers/polar",
|
|
69
|
+
regions: ["*"],
|
|
70
|
+
sandboxAvailable: true,
|
|
71
|
+
supportUrl: "https://polar.sh/docs/support",
|
|
72
|
+
configSchema: {
|
|
73
|
+
accessToken: {
|
|
74
|
+
label: "Access Token",
|
|
75
|
+
type: "password",
|
|
76
|
+
secure: true,
|
|
77
|
+
required: true,
|
|
78
|
+
description: "Polar Access Token",
|
|
79
|
+
pattern: "^polar_.*$",
|
|
80
|
+
errorMessage: "Must start with polar_"
|
|
81
|
+
},
|
|
82
|
+
organizationId: {
|
|
83
|
+
label: "Organization ID",
|
|
84
|
+
type: "text",
|
|
85
|
+
secure: false,
|
|
86
|
+
required: true,
|
|
87
|
+
description: "Polar Organization ID to process checkouts for."
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
dataSchema: {
|
|
91
|
+
webhookSecret: {
|
|
92
|
+
secure: true,
|
|
93
|
+
description: "Webhook signing secret"
|
|
94
|
+
},
|
|
95
|
+
webhookEndpointId: {
|
|
96
|
+
secure: false,
|
|
97
|
+
description: "Webhook endpoint ID"
|
|
98
|
+
},
|
|
99
|
+
accessToken: {
|
|
100
|
+
secure: true,
|
|
101
|
+
description: "Polar Access Token"
|
|
102
|
+
},
|
|
103
|
+
organizationId: {
|
|
104
|
+
secure: false,
|
|
105
|
+
description: "Polar Organization ID"
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// src/clients/v1/payments.ts
|
|
111
|
+
var createPayment = async (...args) => {
|
|
112
|
+
throw new Error("Not implemented");
|
|
113
|
+
};
|
|
114
|
+
var getPayment = async (...args) => {
|
|
115
|
+
throw new Error("Not implemented");
|
|
116
|
+
};
|
|
117
|
+
var refundPayment = async (...args) => {
|
|
118
|
+
throw new Error("Not implemented");
|
|
119
|
+
};
|
|
120
|
+
var listPayments = async (...args) => {
|
|
121
|
+
throw new Error("Not implemented");
|
|
122
|
+
};
|
|
123
|
+
var capturePayment = async (...args) => {
|
|
124
|
+
throw new Error("Not implemented");
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// src/clients/v1/subscriptions.ts
|
|
128
|
+
var createSubscription = async (...args) => {
|
|
129
|
+
throw new Error("Not implemented");
|
|
130
|
+
};
|
|
131
|
+
var getSubscription = async (...args) => {
|
|
132
|
+
throw new Error("Not implemented");
|
|
133
|
+
};
|
|
134
|
+
var cancelSubscription = async (...args) => {
|
|
135
|
+
throw new Error("Not implemented");
|
|
136
|
+
};
|
|
137
|
+
var pauseSubscription = async (...args) => {
|
|
138
|
+
throw new Error("Not implemented");
|
|
139
|
+
};
|
|
140
|
+
var resumeSubscription = async (...args) => {
|
|
141
|
+
throw new Error("Not implemented");
|
|
142
|
+
};
|
|
143
|
+
var listSubscriptions = async (...args) => {
|
|
144
|
+
throw new Error("Not implemented");
|
|
145
|
+
};
|
|
146
|
+
var updateSubscription = async (...args) => {
|
|
147
|
+
throw new Error("Not implemented");
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// src/clients/v1/checkout.ts
|
|
151
|
+
var createCheckoutSession = async (...args) => {
|
|
152
|
+
throw new Error("Not implemented");
|
|
153
|
+
};
|
|
154
|
+
var setupPaymentMethod = async (...args) => {
|
|
155
|
+
throw new Error("Not implemented");
|
|
156
|
+
};
|
|
157
|
+
var createBillingPortalSession = async (...args) => {
|
|
158
|
+
throw new Error("Not implemented");
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
// src/clients/v1/customers.ts
|
|
162
|
+
var createCustomer = async (...args) => {
|
|
163
|
+
throw new Error("Not implemented");
|
|
164
|
+
};
|
|
165
|
+
var updateCustomer = async (...args) => {
|
|
166
|
+
throw new Error("Not implemented");
|
|
167
|
+
};
|
|
168
|
+
var deleteCustomer = async (...args) => {
|
|
169
|
+
throw new Error("Not implemented");
|
|
170
|
+
};
|
|
171
|
+
var getCustomer = async (...args) => {
|
|
172
|
+
throw new Error("Not implemented");
|
|
173
|
+
};
|
|
174
|
+
var listCustomers = async (...args) => {
|
|
175
|
+
throw new Error("Not implemented");
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
// src/clients/v1/webhooks.ts
|
|
179
|
+
import { validateEvent } from "@polar-sh/sdk/webhooks.js";
|
|
180
|
+
|
|
181
|
+
// src/clients/v1/shared.ts
|
|
182
|
+
import { Polar } from "@polar-sh/sdk";
|
|
183
|
+
var polar = new Polar({
|
|
184
|
+
accessToken: process.env.POLAR_ACCESS_TOKEN,
|
|
185
|
+
server: process.env.POLAR_MODE
|
|
186
|
+
});
|
|
187
|
+
var polarClient = null;
|
|
188
|
+
var getOrCreatePolar = (accessToken) => {
|
|
189
|
+
if (!polarClient) {
|
|
190
|
+
polarClient = new Polar({
|
|
191
|
+
accessToken
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
return polarClient;
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
// src/maps/event-map.ts
|
|
198
|
+
var EVENT_MAP = {
|
|
199
|
+
// Checkout
|
|
200
|
+
"checkout.created": "CHECKOUT_COMPLETED",
|
|
201
|
+
"checkout.updated": "CHECKOUT_COMPLETED",
|
|
202
|
+
"checkout.expired": "CHECKOUT_EXPIRED",
|
|
203
|
+
// Subscriptions
|
|
204
|
+
"subscription.created": "SUBSCRIPTION_CREATED",
|
|
205
|
+
"subscription.updated": "SUBSCRIPTION_UPDATED",
|
|
206
|
+
"subscription.canceled": "SUBSCRIPTION_CANCELED",
|
|
207
|
+
"subscription.active": "SUBSCRIPTION_RESUMED",
|
|
208
|
+
"subscription.uncanceled": "SUBSCRIPTION_RESUMED",
|
|
209
|
+
"subscription.revoked": "SUBSCRIPTION_CANCELED",
|
|
210
|
+
"subscription.past_due": "SUBSCRIPTION_PAYMENT_FAILED",
|
|
211
|
+
// Orders
|
|
212
|
+
"order.created": "PAYMENT_CREATED",
|
|
213
|
+
"order.updated": "PAYMENT_PROCESSING",
|
|
214
|
+
"order.paid": "PAYMENT_SUCCEEDED",
|
|
215
|
+
"order.refunded": "REFUND_PROCESSED",
|
|
216
|
+
// Customers
|
|
217
|
+
"customer.created": "CUSTOMER_CREATED",
|
|
218
|
+
"customer.updated": "CUSTOMER_UPDATED",
|
|
219
|
+
"customer.deleted": "CUSTOMER_DELETED",
|
|
220
|
+
"customer.state_changed": "CUSTOMER_UPDATED",
|
|
221
|
+
// Refunds
|
|
222
|
+
"refund.created": "REFUND_CREATED",
|
|
223
|
+
"refund.updated": "REFUND_PROCESSED",
|
|
224
|
+
"product.created": null,
|
|
225
|
+
"product.updated": null,
|
|
226
|
+
"benefit.created": null,
|
|
227
|
+
"benefit.updated": null,
|
|
228
|
+
"benefit_grant.created": null,
|
|
229
|
+
"benefit_grant.cycled": null,
|
|
230
|
+
"benefit_grant.updated": null,
|
|
231
|
+
"benefit_grant.revoked": null,
|
|
232
|
+
"organization.updated": null,
|
|
233
|
+
"customer_seat.assigned": null,
|
|
234
|
+
"customer_seat.claimed": null,
|
|
235
|
+
"customer_seat.revoked": null,
|
|
236
|
+
"member.created": null,
|
|
237
|
+
"member.updated": null,
|
|
238
|
+
"member.deleted": null
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
// src/clients/v1/webhooks.ts
|
|
242
|
+
var validateCredentials = async (ctx) => {
|
|
243
|
+
if (!ctx.config.accessToken || !ctx.config.organizationId) {
|
|
244
|
+
return { data: false, status: "success" };
|
|
245
|
+
}
|
|
246
|
+
try {
|
|
247
|
+
const polar2 = getOrCreatePolar(ctx.config.accessToken);
|
|
248
|
+
await polar2.organizations.list({});
|
|
249
|
+
return { data: true, status: "success" };
|
|
250
|
+
} catch {
|
|
251
|
+
return { data: false, status: "failed" };
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
var setupWebhooks = async (ctx, webhookUrl) => {
|
|
255
|
+
const polar2 = getOrCreatePolar(ctx.config.accessToken);
|
|
256
|
+
try {
|
|
257
|
+
const events = [
|
|
258
|
+
"checkout.created",
|
|
259
|
+
"checkout.updated",
|
|
260
|
+
"customer.created",
|
|
261
|
+
"customer.updated",
|
|
262
|
+
"customer.deleted",
|
|
263
|
+
"order.created",
|
|
264
|
+
"order.updated",
|
|
265
|
+
"order.paid",
|
|
266
|
+
"order.refunded",
|
|
267
|
+
"subscription.created",
|
|
268
|
+
"subscription.updated",
|
|
269
|
+
"subscription.active",
|
|
270
|
+
"subscription.canceled",
|
|
271
|
+
"subscription.uncanceled",
|
|
272
|
+
"subscription.revoked",
|
|
273
|
+
"subscription.past_due",
|
|
274
|
+
"refund.created",
|
|
275
|
+
"refund.updated",
|
|
276
|
+
"product.created",
|
|
277
|
+
"product.updated"
|
|
278
|
+
];
|
|
279
|
+
const webhookEndpoint = await polar2.webhooks.createWebhookEndpoint({
|
|
280
|
+
url: webhookUrl,
|
|
281
|
+
format: "raw",
|
|
282
|
+
events,
|
|
283
|
+
name: "Revstack",
|
|
284
|
+
organizationId: ctx.config.organizationId
|
|
285
|
+
});
|
|
286
|
+
const data = {
|
|
287
|
+
webhookEndpointId: webhookEndpoint.id,
|
|
288
|
+
webhookSecret: webhookEndpoint.secret,
|
|
289
|
+
accessToken: ctx.config.accessToken,
|
|
290
|
+
organizationId: ctx.config.organizationId
|
|
291
|
+
};
|
|
292
|
+
return {
|
|
293
|
+
data: { success: true, data },
|
|
294
|
+
status: "success"
|
|
295
|
+
};
|
|
296
|
+
} catch (error) {
|
|
297
|
+
return {
|
|
298
|
+
data: { success: false, data: {} },
|
|
299
|
+
status: "failed",
|
|
300
|
+
error: { code: "UNKNOWN_ERROR", message: error.message }
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
var removeWebhooks = async (ctx, webhookId) => {
|
|
305
|
+
const polar2 = getOrCreatePolar(ctx.config.accessToken);
|
|
306
|
+
try {
|
|
307
|
+
await polar2.webhooks.deleteWebhookEndpoint({ id: webhookId });
|
|
308
|
+
return { data: true, status: "success" };
|
|
309
|
+
} catch (error) {
|
|
310
|
+
return { data: false, status: "failed" };
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
var verifyWebhookSignature = async (_ctx, payload, headers, secret) => {
|
|
314
|
+
try {
|
|
315
|
+
const normalizedHeaders = {};
|
|
316
|
+
for (const [k, v] of Object.entries(headers)) {
|
|
317
|
+
if (v)
|
|
318
|
+
normalizedHeaders[k] = Array.isArray(v) ? v[0] || "" : v;
|
|
319
|
+
}
|
|
320
|
+
validateEvent(payload, normalizedHeaders, secret);
|
|
321
|
+
return { data: true, status: "success" };
|
|
322
|
+
} catch (error) {
|
|
323
|
+
return { data: false, status: "failed" };
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
function extractResourceId(payload) {
|
|
327
|
+
const data = payload.data;
|
|
328
|
+
if (!data) return null;
|
|
329
|
+
return data.id || null;
|
|
330
|
+
}
|
|
331
|
+
var parseWebhookEvent = async (payload) => {
|
|
332
|
+
if (!payload || !payload.type) return { data: null, status: "failed" };
|
|
333
|
+
const mappedType = EVENT_MAP[payload.type];
|
|
334
|
+
if (!mappedType) return { data: null, status: "failed" };
|
|
335
|
+
const resourceId = extractResourceId(payload) || payload.id;
|
|
336
|
+
return {
|
|
337
|
+
data: {
|
|
338
|
+
type: mappedType,
|
|
339
|
+
providerEventId: payload.id,
|
|
340
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
341
|
+
resourceId,
|
|
342
|
+
originalPayload: payload,
|
|
343
|
+
metadata: { polarType: payload.type }
|
|
344
|
+
},
|
|
345
|
+
status: "success"
|
|
346
|
+
};
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
// src/clients/v1/addons.ts
|
|
350
|
+
var createAddon = async (...args) => {
|
|
351
|
+
throw new Error("Not implemented");
|
|
352
|
+
};
|
|
353
|
+
var getAddon = async (...args) => {
|
|
354
|
+
throw new Error("Not implemented");
|
|
355
|
+
};
|
|
356
|
+
var updateAddon = async (...args) => {
|
|
357
|
+
throw new Error("Not implemented");
|
|
358
|
+
};
|
|
359
|
+
var deleteAddon = async (...args) => {
|
|
360
|
+
throw new Error("Not implemented");
|
|
361
|
+
};
|
|
362
|
+
var listAddons = async (...args) => {
|
|
363
|
+
throw new Error("Not implemented");
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
// src/clients/v1/payment-methods.ts
|
|
367
|
+
var listPaymentMethods = async (...args) => {
|
|
368
|
+
throw new Error("Not implemented");
|
|
369
|
+
};
|
|
370
|
+
var deletePaymentMethod = async (...args) => {
|
|
371
|
+
throw new Error("Not implemented");
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
// src/clients/v1/index.ts
|
|
375
|
+
var PolarClientV1 = class {
|
|
376
|
+
// ===========================================================================
|
|
377
|
+
// LIFECYCLE & WEBHOOKS
|
|
378
|
+
// ===========================================================================
|
|
379
|
+
validateCredentials(ctx) {
|
|
380
|
+
return validateCredentials(ctx);
|
|
381
|
+
}
|
|
382
|
+
setupWebhooks(ctx, webhookUrl) {
|
|
383
|
+
return setupWebhooks(ctx, webhookUrl);
|
|
384
|
+
}
|
|
385
|
+
removeWebhooks(ctx, webhookId) {
|
|
386
|
+
return removeWebhooks(ctx, webhookId);
|
|
387
|
+
}
|
|
388
|
+
verifyWebhookSignature(ctx, payload, headers, secret) {
|
|
389
|
+
return verifyWebhookSignature(ctx, payload, headers, secret);
|
|
390
|
+
}
|
|
391
|
+
parseWebhookEvent(payload) {
|
|
392
|
+
return parseWebhookEvent(payload);
|
|
393
|
+
}
|
|
394
|
+
listPaymentMethods(ctx, customerId) {
|
|
395
|
+
return listPaymentMethods(ctx, customerId);
|
|
396
|
+
}
|
|
397
|
+
deletePaymentMethod(ctx, id) {
|
|
398
|
+
return deletePaymentMethod(ctx, id);
|
|
399
|
+
}
|
|
400
|
+
// ===========================================================================
|
|
401
|
+
// PAYMENTS
|
|
402
|
+
// ===========================================================================
|
|
403
|
+
createPayment(ctx, input) {
|
|
404
|
+
return createPayment(ctx, input, createCheckoutSession);
|
|
405
|
+
}
|
|
406
|
+
getPayment(ctx, id) {
|
|
407
|
+
return getPayment(ctx, id);
|
|
408
|
+
}
|
|
409
|
+
refundPayment(ctx, input) {
|
|
410
|
+
return refundPayment(ctx, input);
|
|
411
|
+
}
|
|
412
|
+
listPayments(ctx, pagination) {
|
|
413
|
+
return listPayments(ctx, pagination);
|
|
414
|
+
}
|
|
415
|
+
capturePayment(ctx, id, amount) {
|
|
416
|
+
return capturePayment(ctx, id, amount);
|
|
417
|
+
}
|
|
418
|
+
// ===========================================================================
|
|
419
|
+
// SUBSCRIPTIONS
|
|
420
|
+
// ===========================================================================
|
|
421
|
+
createSubscription(ctx, input) {
|
|
422
|
+
return createSubscription(
|
|
423
|
+
ctx,
|
|
424
|
+
input,
|
|
425
|
+
createCheckoutSession
|
|
426
|
+
);
|
|
427
|
+
}
|
|
428
|
+
getSubscription(ctx, id) {
|
|
429
|
+
return getSubscription(ctx, id);
|
|
430
|
+
}
|
|
431
|
+
cancelSubscription(ctx, id, reason) {
|
|
432
|
+
return cancelSubscription(ctx, id, reason);
|
|
433
|
+
}
|
|
434
|
+
pauseSubscription(ctx, id) {
|
|
435
|
+
return pauseSubscription(ctx, id);
|
|
436
|
+
}
|
|
437
|
+
resumeSubscription(ctx, id) {
|
|
438
|
+
return resumeSubscription(ctx, id);
|
|
439
|
+
}
|
|
440
|
+
listSubscriptions(ctx, pagination) {
|
|
441
|
+
return listSubscriptions(ctx, pagination);
|
|
442
|
+
}
|
|
443
|
+
updateSubscription(ctx, id, input) {
|
|
444
|
+
return updateSubscription(ctx, id, input);
|
|
445
|
+
}
|
|
446
|
+
// ===========================================================================
|
|
447
|
+
// CHECKOUT
|
|
448
|
+
// ===========================================================================
|
|
449
|
+
createCheckoutSession(ctx, input) {
|
|
450
|
+
return createCheckoutSession(ctx, input);
|
|
451
|
+
}
|
|
452
|
+
setupPaymentMethod(ctx, input) {
|
|
453
|
+
return setupPaymentMethod(ctx, input);
|
|
454
|
+
}
|
|
455
|
+
createBillingPortalSession(ctx, input) {
|
|
456
|
+
return createBillingPortalSession(ctx, input);
|
|
457
|
+
}
|
|
458
|
+
// ===========================================================================
|
|
459
|
+
// CUSTOMERS
|
|
460
|
+
// ===========================================================================
|
|
461
|
+
createCustomer(ctx, input) {
|
|
462
|
+
return createCustomer(ctx, input);
|
|
463
|
+
}
|
|
464
|
+
updateCustomer(ctx, id, input) {
|
|
465
|
+
return updateCustomer(ctx, id, input);
|
|
466
|
+
}
|
|
467
|
+
deleteCustomer(ctx, id) {
|
|
468
|
+
return deleteCustomer(ctx, id);
|
|
469
|
+
}
|
|
470
|
+
getCustomer(ctx, id) {
|
|
471
|
+
return getCustomer(ctx, id);
|
|
472
|
+
}
|
|
473
|
+
listCustomers(ctx, pagination) {
|
|
474
|
+
return listCustomers(ctx, pagination);
|
|
475
|
+
}
|
|
476
|
+
// ===========================================================================
|
|
477
|
+
// ADDONS
|
|
478
|
+
// ===========================================================================
|
|
479
|
+
createAddon(ctx, input) {
|
|
480
|
+
return createAddon(ctx, input);
|
|
481
|
+
}
|
|
482
|
+
getAddon(ctx, id) {
|
|
483
|
+
return getAddon(ctx, id);
|
|
484
|
+
}
|
|
485
|
+
updateAddon(ctx, id, input) {
|
|
486
|
+
return updateAddon(ctx, id, input);
|
|
487
|
+
}
|
|
488
|
+
deleteAddon(ctx, input) {
|
|
489
|
+
return deleteAddon(ctx, input);
|
|
490
|
+
}
|
|
491
|
+
listAddons(ctx, subscriptionId, pagination) {
|
|
492
|
+
return listAddons(ctx, subscriptionId, pagination);
|
|
493
|
+
}
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
// src/clients/factory.ts
|
|
497
|
+
function getClient(_config) {
|
|
498
|
+
return new PolarClientV1();
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// src/provider.ts
|
|
502
|
+
import {
|
|
503
|
+
BaseProvider,
|
|
504
|
+
RevstackErrorCode
|
|
505
|
+
} from "@revstackhq/providers-core";
|
|
506
|
+
var PolarProvider = class extends BaseProvider {
|
|
507
|
+
static manifest = manifest;
|
|
508
|
+
manifest = manifest;
|
|
509
|
+
async onInstall(ctx, input) {
|
|
510
|
+
const client = getClient(input.config);
|
|
511
|
+
const installVersion = manifest.version;
|
|
512
|
+
const isValid = await client.validateCredentials({
|
|
513
|
+
...ctx,
|
|
514
|
+
config: input.config
|
|
515
|
+
});
|
|
516
|
+
if (!isValid) {
|
|
517
|
+
return {
|
|
518
|
+
data: { success: false },
|
|
519
|
+
status: "failed",
|
|
520
|
+
error: {
|
|
521
|
+
code: RevstackErrorCode.InvalidCredentials,
|
|
522
|
+
message: "Failed to connect to provider. Please check your API Key / Secrets."
|
|
523
|
+
}
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
let webhookData = {};
|
|
527
|
+
if (client.setupWebhooks && input.webhookUrl) {
|
|
528
|
+
try {
|
|
529
|
+
const wh = await client.setupWebhooks(
|
|
530
|
+
{ ...ctx, config: input.config },
|
|
531
|
+
input.webhookUrl
|
|
532
|
+
);
|
|
533
|
+
const whData = wh.data;
|
|
534
|
+
if (!wh.data || !whData.success) {
|
|
535
|
+
return {
|
|
536
|
+
data: { success: false },
|
|
537
|
+
status: "failed",
|
|
538
|
+
error: {
|
|
539
|
+
code: RevstackErrorCode.UnknownError,
|
|
540
|
+
message: "Failed to setup webhooks in Polar"
|
|
541
|
+
}
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
webhookData = {
|
|
545
|
+
webhookEndpointId: whData.data?.webhookEndpointId,
|
|
546
|
+
webhookSecret: whData.data?.webhookSecret
|
|
547
|
+
};
|
|
548
|
+
} catch (error) {
|
|
549
|
+
console.warn("Webhook setup failed (non-fatal):", error.message);
|
|
550
|
+
return {
|
|
551
|
+
data: { success: false },
|
|
552
|
+
status: "failed",
|
|
553
|
+
error: {
|
|
554
|
+
code: RevstackErrorCode.MisconfiguredProvider,
|
|
555
|
+
message: `Webhook setup failed: ${error.message}`
|
|
556
|
+
}
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
return {
|
|
561
|
+
data: {
|
|
562
|
+
success: true,
|
|
563
|
+
data: {
|
|
564
|
+
...input.config,
|
|
565
|
+
...webhookData,
|
|
566
|
+
_providerVersion: installVersion
|
|
567
|
+
}
|
|
568
|
+
},
|
|
569
|
+
status: "success"
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
async onUninstall(ctx, input) {
|
|
573
|
+
const client = getClient(input.config);
|
|
574
|
+
if (client.removeWebhooks && input.data.webhookEndpointId) {
|
|
575
|
+
try {
|
|
576
|
+
await client.removeWebhooks(
|
|
577
|
+
ctx,
|
|
578
|
+
input.data.webhookEndpointId
|
|
579
|
+
);
|
|
580
|
+
} catch (e) {
|
|
581
|
+
console.warn("Failed to remove webhook on uninstall:", e);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
return {
|
|
585
|
+
data: true,
|
|
586
|
+
status: "success"
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
async verifyWebhookSignature(ctx, payload, headers, secret) {
|
|
590
|
+
const client = getClient(ctx.config);
|
|
591
|
+
return client.verifyWebhookSignature(ctx, payload, headers, secret);
|
|
592
|
+
}
|
|
593
|
+
async parseWebhookEvent(ctx, payload) {
|
|
594
|
+
const client = getClient(ctx.config);
|
|
595
|
+
return client.parseWebhookEvent(payload);
|
|
596
|
+
}
|
|
597
|
+
async getWebhookResponse() {
|
|
598
|
+
return {
|
|
599
|
+
data: { statusCode: 200, body: { received: true } },
|
|
600
|
+
status: "success"
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
// ===========================================================================
|
|
604
|
+
// PAYMENTS
|
|
605
|
+
// ===========================================================================
|
|
606
|
+
async createPayment(ctx, input) {
|
|
607
|
+
const client = getClient(ctx.config);
|
|
608
|
+
if (!client.createPayment) {
|
|
609
|
+
return {
|
|
610
|
+
data: null,
|
|
611
|
+
status: "failed",
|
|
612
|
+
error: {
|
|
613
|
+
code: RevstackErrorCode.NotImplemented,
|
|
614
|
+
message: `Provider '${this.manifest.slug}' does not support createPayment.`
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
return client.createPayment(ctx, input);
|
|
619
|
+
}
|
|
620
|
+
async getPayment(ctx, id) {
|
|
621
|
+
const client = getClient(ctx.config);
|
|
622
|
+
if (!client.getPayment) {
|
|
623
|
+
return {
|
|
624
|
+
data: null,
|
|
625
|
+
status: "failed",
|
|
626
|
+
error: {
|
|
627
|
+
code: RevstackErrorCode.NotImplemented,
|
|
628
|
+
message: "Get payment not supported"
|
|
629
|
+
}
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
return client.getPayment(ctx, id);
|
|
633
|
+
}
|
|
634
|
+
async refundPayment(ctx, input) {
|
|
635
|
+
const client = getClient(ctx.config);
|
|
636
|
+
if (!client.refundPayment) {
|
|
637
|
+
return {
|
|
638
|
+
data: null,
|
|
639
|
+
status: "failed",
|
|
640
|
+
error: {
|
|
641
|
+
code: RevstackErrorCode.NotImplemented,
|
|
642
|
+
message: "Refunds not supported by this provider version"
|
|
643
|
+
}
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
return client.refundPayment(ctx, input);
|
|
647
|
+
}
|
|
648
|
+
async listPayments(ctx, pagination) {
|
|
649
|
+
const client = getClient(ctx.config);
|
|
650
|
+
if (!client.listPayments) {
|
|
651
|
+
return {
|
|
652
|
+
data: null,
|
|
653
|
+
status: "failed",
|
|
654
|
+
error: {
|
|
655
|
+
code: RevstackErrorCode.NotImplemented,
|
|
656
|
+
message: "List payments not supported"
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
return client.listPayments(ctx, pagination);
|
|
661
|
+
}
|
|
662
|
+
// ===========================================================================
|
|
663
|
+
// SUBSCRIPTIONS
|
|
664
|
+
// ===========================================================================
|
|
665
|
+
async createSubscription(ctx, input) {
|
|
666
|
+
const client = getClient(ctx.config);
|
|
667
|
+
if (!client.createSubscription) {
|
|
668
|
+
return {
|
|
669
|
+
data: null,
|
|
670
|
+
status: "failed",
|
|
671
|
+
error: {
|
|
672
|
+
code: RevstackErrorCode.NotImplemented,
|
|
673
|
+
message: "Subscriptions not supported"
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
return client.createSubscription(ctx, input);
|
|
678
|
+
}
|
|
679
|
+
async getSubscription(ctx, id) {
|
|
680
|
+
const client = getClient(ctx.config);
|
|
681
|
+
if (!client.getSubscription) {
|
|
682
|
+
return {
|
|
683
|
+
data: null,
|
|
684
|
+
status: "failed",
|
|
685
|
+
error: {
|
|
686
|
+
code: RevstackErrorCode.NotImplemented,
|
|
687
|
+
message: "Get subscription not supported"
|
|
688
|
+
}
|
|
689
|
+
};
|
|
690
|
+
}
|
|
691
|
+
return client.getSubscription(ctx, id);
|
|
692
|
+
}
|
|
693
|
+
async cancelSubscription(ctx, id, reason) {
|
|
694
|
+
const client = getClient(ctx.config);
|
|
695
|
+
if (!client.cancelSubscription) {
|
|
696
|
+
return {
|
|
697
|
+
data: null,
|
|
698
|
+
status: "failed",
|
|
699
|
+
error: {
|
|
700
|
+
code: RevstackErrorCode.NotImplemented,
|
|
701
|
+
message: "Cancel subscription not supported"
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
return client.cancelSubscription(ctx, id, reason);
|
|
706
|
+
}
|
|
707
|
+
async pauseSubscription(ctx, id, reason) {
|
|
708
|
+
const client = getClient(ctx.config);
|
|
709
|
+
if (!client.pauseSubscription) {
|
|
710
|
+
return {
|
|
711
|
+
data: null,
|
|
712
|
+
status: "failed",
|
|
713
|
+
error: {
|
|
714
|
+
code: RevstackErrorCode.NotImplemented,
|
|
715
|
+
message: "Pause subscription not supported"
|
|
716
|
+
}
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
return client.pauseSubscription(ctx, id, reason);
|
|
720
|
+
}
|
|
721
|
+
async resumeSubscription(ctx, id, reason) {
|
|
722
|
+
const client = getClient(ctx.config);
|
|
723
|
+
if (!client.resumeSubscription) {
|
|
724
|
+
return {
|
|
725
|
+
data: null,
|
|
726
|
+
status: "failed",
|
|
727
|
+
error: {
|
|
728
|
+
code: RevstackErrorCode.NotImplemented,
|
|
729
|
+
message: "Resume subscription not supported"
|
|
730
|
+
}
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
return client.resumeSubscription(ctx, id, reason);
|
|
734
|
+
}
|
|
735
|
+
// ===========================================================================
|
|
736
|
+
// CHECKOUT
|
|
737
|
+
// ===========================================================================
|
|
738
|
+
async createCheckoutSession(ctx, input) {
|
|
739
|
+
const client = getClient(ctx.config);
|
|
740
|
+
if (!client.createCheckoutSession) {
|
|
741
|
+
return {
|
|
742
|
+
data: null,
|
|
743
|
+
status: "failed",
|
|
744
|
+
error: {
|
|
745
|
+
code: RevstackErrorCode.NotImplemented,
|
|
746
|
+
message: "Checkout not supported"
|
|
747
|
+
}
|
|
748
|
+
};
|
|
749
|
+
}
|
|
750
|
+
return client.createCheckoutSession(ctx, input);
|
|
751
|
+
}
|
|
752
|
+
// ===========================================================================
|
|
753
|
+
// CUSTOMERS
|
|
754
|
+
// ===========================================================================
|
|
755
|
+
async createCustomer(ctx, input) {
|
|
756
|
+
const client = getClient(ctx.config);
|
|
757
|
+
if (!client.createCustomer) {
|
|
758
|
+
return {
|
|
759
|
+
data: null,
|
|
760
|
+
status: "failed",
|
|
761
|
+
error: {
|
|
762
|
+
code: RevstackErrorCode.NotImplemented,
|
|
763
|
+
message: "Customer management not supported"
|
|
764
|
+
}
|
|
765
|
+
};
|
|
766
|
+
}
|
|
767
|
+
return client.createCustomer(ctx, input);
|
|
768
|
+
}
|
|
769
|
+
async updateCustomer(ctx, id, input) {
|
|
770
|
+
const client = getClient(ctx.config);
|
|
771
|
+
if (!client.updateCustomer) {
|
|
772
|
+
return {
|
|
773
|
+
data: null,
|
|
774
|
+
status: "failed",
|
|
775
|
+
error: {
|
|
776
|
+
code: RevstackErrorCode.NotImplemented,
|
|
777
|
+
message: "Customer update not supported"
|
|
778
|
+
}
|
|
779
|
+
};
|
|
780
|
+
}
|
|
781
|
+
return client.updateCustomer(ctx, id, input);
|
|
782
|
+
}
|
|
783
|
+
async deleteCustomer(ctx, id) {
|
|
784
|
+
const client = getClient(ctx.config);
|
|
785
|
+
if (!client.deleteCustomer) {
|
|
786
|
+
return {
|
|
787
|
+
data: false,
|
|
788
|
+
status: "failed",
|
|
789
|
+
error: {
|
|
790
|
+
code: RevstackErrorCode.NotImplemented,
|
|
791
|
+
message: "Customer deletion not supported"
|
|
792
|
+
}
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
return client.deleteCustomer(ctx, id);
|
|
796
|
+
}
|
|
797
|
+
async getCustomer(ctx, id) {
|
|
798
|
+
const client = getClient(ctx.config);
|
|
799
|
+
if (!client.getCustomer) {
|
|
800
|
+
return {
|
|
801
|
+
data: null,
|
|
802
|
+
status: "failed",
|
|
803
|
+
error: {
|
|
804
|
+
code: RevstackErrorCode.NotImplemented,
|
|
805
|
+
message: "Get customer not supported"
|
|
806
|
+
}
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
return client.getCustomer(ctx, id);
|
|
810
|
+
}
|
|
811
|
+
// ===========================================================================
|
|
812
|
+
// PAYMENT METHODS
|
|
813
|
+
// ===========================================================================
|
|
814
|
+
async listPaymentMethods(ctx, customerId) {
|
|
815
|
+
const client = getClient(ctx.config);
|
|
816
|
+
if (!client.listPaymentMethods) {
|
|
817
|
+
return {
|
|
818
|
+
data: null,
|
|
819
|
+
status: "failed",
|
|
820
|
+
error: {
|
|
821
|
+
code: RevstackErrorCode.NotImplemented,
|
|
822
|
+
message: "List payment methods not supported"
|
|
823
|
+
}
|
|
824
|
+
};
|
|
825
|
+
}
|
|
826
|
+
return client.listPaymentMethods(ctx, customerId);
|
|
827
|
+
}
|
|
828
|
+
async deletePaymentMethod(ctx, id) {
|
|
829
|
+
const client = getClient(ctx.config);
|
|
830
|
+
if (!client.deletePaymentMethod) {
|
|
831
|
+
return {
|
|
832
|
+
data: false,
|
|
833
|
+
status: "failed",
|
|
834
|
+
error: {
|
|
835
|
+
code: RevstackErrorCode.NotImplemented,
|
|
836
|
+
message: "Delete payment method not supported"
|
|
837
|
+
}
|
|
838
|
+
};
|
|
839
|
+
}
|
|
840
|
+
return client.deletePaymentMethod(ctx, id);
|
|
841
|
+
}
|
|
842
|
+
// ===========================================================================
|
|
843
|
+
// ADDITIONAL METHODS
|
|
844
|
+
// ===========================================================================
|
|
845
|
+
async capturePayment(ctx, id, amount) {
|
|
846
|
+
const client = getClient(ctx.config);
|
|
847
|
+
if (!client.capturePayment) {
|
|
848
|
+
return {
|
|
849
|
+
data: null,
|
|
850
|
+
status: "failed",
|
|
851
|
+
error: {
|
|
852
|
+
code: RevstackErrorCode.NotImplemented,
|
|
853
|
+
message: "Capture not supported"
|
|
854
|
+
}
|
|
855
|
+
};
|
|
856
|
+
}
|
|
857
|
+
return client.capturePayment(ctx, id, amount);
|
|
858
|
+
}
|
|
859
|
+
async listSubscriptions(ctx, pagination) {
|
|
860
|
+
const client = getClient(ctx.config);
|
|
861
|
+
if (!client.listSubscriptions) {
|
|
862
|
+
return {
|
|
863
|
+
data: null,
|
|
864
|
+
status: "failed",
|
|
865
|
+
error: {
|
|
866
|
+
code: RevstackErrorCode.NotImplemented,
|
|
867
|
+
message: "List subscriptions not supported"
|
|
868
|
+
}
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
return client.listSubscriptions(ctx, pagination);
|
|
872
|
+
}
|
|
873
|
+
async updateSubscription(ctx, id, input) {
|
|
874
|
+
const client = getClient(ctx.config);
|
|
875
|
+
if (!client.updateSubscription) {
|
|
876
|
+
return {
|
|
877
|
+
data: null,
|
|
878
|
+
status: "failed",
|
|
879
|
+
error: {
|
|
880
|
+
code: RevstackErrorCode.NotImplemented,
|
|
881
|
+
message: "Update subscription not supported"
|
|
882
|
+
}
|
|
883
|
+
};
|
|
884
|
+
}
|
|
885
|
+
return client.updateSubscription(ctx, id, input);
|
|
886
|
+
}
|
|
887
|
+
async listCustomers(ctx, pagination) {
|
|
888
|
+
const client = getClient(ctx.config);
|
|
889
|
+
if (!client.listCustomers) {
|
|
890
|
+
return {
|
|
891
|
+
data: null,
|
|
892
|
+
status: "failed",
|
|
893
|
+
error: {
|
|
894
|
+
code: RevstackErrorCode.NotImplemented,
|
|
895
|
+
message: "List customers not supported"
|
|
896
|
+
}
|
|
897
|
+
};
|
|
898
|
+
}
|
|
899
|
+
return client.listCustomers(ctx, pagination);
|
|
900
|
+
}
|
|
901
|
+
async setupPaymentMethod(ctx, input) {
|
|
902
|
+
const client = getClient(ctx.config);
|
|
903
|
+
if (!client.setupPaymentMethod) {
|
|
904
|
+
return {
|
|
905
|
+
data: null,
|
|
906
|
+
status: "failed",
|
|
907
|
+
error: {
|
|
908
|
+
code: RevstackErrorCode.NotImplemented,
|
|
909
|
+
message: "Setup payment method not supported"
|
|
910
|
+
}
|
|
911
|
+
};
|
|
912
|
+
}
|
|
913
|
+
return client.setupPaymentMethod(ctx, input);
|
|
914
|
+
}
|
|
915
|
+
async createBillingPortalSession(ctx, input) {
|
|
916
|
+
const client = getClient(ctx.config);
|
|
917
|
+
if (!client.createBillingPortalSession) {
|
|
918
|
+
return {
|
|
919
|
+
data: null,
|
|
920
|
+
status: "failed",
|
|
921
|
+
error: {
|
|
922
|
+
code: RevstackErrorCode.NotImplemented,
|
|
923
|
+
message: "Billing portal not supported"
|
|
924
|
+
}
|
|
925
|
+
};
|
|
926
|
+
}
|
|
927
|
+
return client.createBillingPortalSession(ctx, input);
|
|
928
|
+
}
|
|
929
|
+
// ===========================================================================
|
|
930
|
+
// ADDONS
|
|
931
|
+
// ===========================================================================
|
|
932
|
+
async createAddon(ctx, input) {
|
|
933
|
+
const client = getClient(ctx.config);
|
|
934
|
+
if (!client.createAddon) {
|
|
935
|
+
return {
|
|
936
|
+
data: null,
|
|
937
|
+
status: "failed",
|
|
938
|
+
error: {
|
|
939
|
+
code: RevstackErrorCode.NotImplemented,
|
|
940
|
+
message: "Create Addon not supported"
|
|
941
|
+
}
|
|
942
|
+
};
|
|
943
|
+
}
|
|
944
|
+
return client.createAddon(ctx, input);
|
|
945
|
+
}
|
|
946
|
+
async getAddon(ctx, id) {
|
|
947
|
+
const client = getClient(ctx.config);
|
|
948
|
+
if (!client.getAddon) {
|
|
949
|
+
return {
|
|
950
|
+
data: null,
|
|
951
|
+
status: "failed",
|
|
952
|
+
error: {
|
|
953
|
+
code: RevstackErrorCode.NotImplemented,
|
|
954
|
+
message: "Get Addon not supported"
|
|
955
|
+
}
|
|
956
|
+
};
|
|
957
|
+
}
|
|
958
|
+
return client.getAddon(ctx, id);
|
|
959
|
+
}
|
|
960
|
+
async updateAddon(ctx, id, input) {
|
|
961
|
+
const client = getClient(ctx.config);
|
|
962
|
+
if (!client.updateAddon) {
|
|
963
|
+
return {
|
|
964
|
+
data: null,
|
|
965
|
+
status: "failed",
|
|
966
|
+
error: {
|
|
967
|
+
code: RevstackErrorCode.NotImplemented,
|
|
968
|
+
message: "Update Addon not supported"
|
|
969
|
+
}
|
|
970
|
+
};
|
|
971
|
+
}
|
|
972
|
+
return client.updateAddon(ctx, id, input);
|
|
973
|
+
}
|
|
974
|
+
async deleteAddon(ctx, input) {
|
|
975
|
+
const client = getClient(ctx.config);
|
|
976
|
+
if (!client.deleteAddon) {
|
|
977
|
+
return {
|
|
978
|
+
data: false,
|
|
979
|
+
status: "failed",
|
|
980
|
+
error: {
|
|
981
|
+
code: RevstackErrorCode.NotImplemented,
|
|
982
|
+
message: "Delete Addon not supported"
|
|
983
|
+
}
|
|
984
|
+
};
|
|
985
|
+
}
|
|
986
|
+
return client.deleteAddon(ctx, input);
|
|
987
|
+
}
|
|
988
|
+
async listAddons(ctx, subscriptionId, pagination) {
|
|
989
|
+
const client = getClient(ctx.config);
|
|
990
|
+
if (!client.listAddons) {
|
|
991
|
+
return {
|
|
992
|
+
data: null,
|
|
993
|
+
status: "failed",
|
|
994
|
+
error: {
|
|
995
|
+
code: RevstackErrorCode.NotImplemented,
|
|
996
|
+
message: "List Addons not supported"
|
|
997
|
+
}
|
|
998
|
+
};
|
|
999
|
+
}
|
|
1000
|
+
return client.listAddons(ctx, subscriptionId, pagination);
|
|
1001
|
+
}
|
|
1002
|
+
};
|
|
1003
|
+
export {
|
|
1004
|
+
PolarProvider,
|
|
1005
|
+
manifest
|
|
1006
|
+
};
|
package/dist/logo.svg
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<svg width="100%" height="100%" viewBox="0 0 24 24" stroke-width="1.5" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path d="M12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
|
|
3
|
+
<path d="M12 22C9.79086 22 8 17.5228 8 12C8 6.47715 9.79086 2 12 2C14.2091 2 16 6.47715 16 12C16 17.5228 14.2091 22 12 22Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
|
|
4
|
+
<path d="M9 21C6 20 5 15.611 5 12.5C5 9.38904 6.5 5.5 10 3" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
|
|
5
|
+
<path d="M15 3C18 4 19 8.38904 19 11.5C19 14.611 17.5 18.5 14 21" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
|
|
6
|
+
</svg>
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@revstackhq/provider-polar",
|
|
3
|
+
"version": "0.0.0-dev-20260301193938",
|
|
4
|
+
"private": false,
|
|
5
|
+
"license": "FSL-1.1-MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": true,
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"module": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"require": "./dist/index.js",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"assets"
|
|
21
|
+
],
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@polar-sh/sdk": "^0.45.1",
|
|
24
|
+
"dotenv": "^17.2.4",
|
|
25
|
+
"@revstackhq/providers-core": "0.0.0-dev-20260227040420"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@eslint/js": "^9.39.1",
|
|
29
|
+
"@types/node": "^20.11.30",
|
|
30
|
+
"eslint": "^9.39.1",
|
|
31
|
+
"eslint-config-prettier": "^10.1.1",
|
|
32
|
+
"eslint-plugin-turbo": "^2.7.1",
|
|
33
|
+
"tsup": "^8.1.0",
|
|
34
|
+
"typescript": "5.9.2",
|
|
35
|
+
"typescript-eslint": "^8.50.0",
|
|
36
|
+
"@revstackhq/eslint-config": "0.0.0"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsup src/index.ts --format esm --dts --clean --publicDir assets --no-splitting",
|
|
43
|
+
"check-types": "tsc -p tsconfig.json --noEmit",
|
|
44
|
+
"lint": "eslint \"src/**/*.{ts,tsx}\"",
|
|
45
|
+
"dev:smoke": "tsx src/smoke.ts"
|
|
46
|
+
}
|
|
47
|
+
}
|