lokicms-plugin-stripe 1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 MauricioPerera
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,209 @@
1
+ # Stripe Plugin for LokiCMS
2
+
3
+ Accept payments and manage subscriptions with Stripe.
4
+
5
+ ## Features
6
+
7
+ - **Checkout Sessions**: Create payment and subscription checkout flows
8
+ - **Customer Portal**: Allow customers to manage their subscriptions
9
+ - **Subscription Management**: Create, update, cancel subscriptions
10
+ - **Product & Price Sync**: Sync Stripe products/prices to LokiCMS entries
11
+ - **Webhook Handling**: Automatic sync on Stripe events
12
+ - **MCP Tools**: AI-accessible tools for payment operations
13
+
14
+ ## Installation
15
+
16
+ The plugin is included in LokiCMS. Enable it in `plugins.json`:
17
+
18
+ ```json
19
+ {
20
+ "plugins": [
21
+ {
22
+ "name": "stripe",
23
+ "enabled": true,
24
+ "source": "local",
25
+ "path": "./plugins/stripe",
26
+ "settings": {
27
+ "secretKey": "${STRIPE_SECRET_KEY}",
28
+ "webhookSecret": "${STRIPE_WEBHOOK_SECRET}",
29
+ "successUrl": "https://yoursite.com/checkout/success",
30
+ "cancelUrl": "https://yoursite.com/checkout/cancel",
31
+ "portalReturnUrl": "https://yoursite.com/account",
32
+ "currency": "usd"
33
+ }
34
+ }
35
+ ]
36
+ }
37
+ ```
38
+
39
+ ## Environment Variables
40
+
41
+ ```bash
42
+ STRIPE_SECRET_KEY=sk_live_... # or sk_test_... for testing
43
+ STRIPE_WEBHOOK_SECRET=whsec_...
44
+ ```
45
+
46
+ ## Content Types
47
+
48
+ The plugin creates these content types to sync Stripe data:
49
+
50
+ | Content Type | Description |
51
+ |--------------|-------------|
52
+ | `stripe-product` | Products from Stripe catalog |
53
+ | `stripe-price` | Prices (one-time or recurring) |
54
+ | `stripe-subscription` | Customer subscriptions |
55
+ | `stripe-invoice` | Invoices and payment records |
56
+ | `stripe-customer` | Customer records linked to users |
57
+
58
+ ## API Endpoints
59
+
60
+ Base path: `/api/plugins/stripe`
61
+
62
+ ### Checkout
63
+
64
+ ```bash
65
+ # Create checkout session
66
+ POST /checkout
67
+ {
68
+ "priceId": "price_xxx",
69
+ "customerEmail": "user@example.com",
70
+ "mode": "subscription"
71
+ }
72
+
73
+ # Response
74
+ {
75
+ "id": "cs_xxx",
76
+ "url": "https://checkout.stripe.com/..."
77
+ }
78
+ ```
79
+
80
+ ### Customer Portal
81
+
82
+ ```bash
83
+ # Create portal session
84
+ POST /portal
85
+ {
86
+ "customerId": "cus_xxx"
87
+ }
88
+ ```
89
+
90
+ ### Products & Prices
91
+
92
+ ```bash
93
+ GET /products
94
+ GET /products?active=true
95
+ GET /prices
96
+ GET /prices?productId=prod_xxx&type=recurring
97
+ ```
98
+
99
+ ### Subscriptions
100
+
101
+ ```bash
102
+ GET /subscriptions
103
+ GET /subscriptions/:id
104
+ POST /subscriptions/:id/cancel
105
+ POST /subscriptions/:id/resume
106
+ ```
107
+
108
+ ### Invoices
109
+
110
+ ```bash
111
+ GET /invoices
112
+ GET /invoices?customerId=cus_xxx
113
+ ```
114
+
115
+ ### Sync
116
+
117
+ ```bash
118
+ # Sync products from Stripe
119
+ POST /sync/products
120
+
121
+ # Sync prices from Stripe
122
+ POST /sync/prices
123
+ ```
124
+
125
+ ### Webhooks
126
+
127
+ ```bash
128
+ POST /webhook # Stripe webhook endpoint
129
+ ```
130
+
131
+ Configure in Stripe Dashboard:
132
+ - Endpoint: `https://yoursite.com/api/plugins/stripe/webhook`
133
+ - Events to send:
134
+ - `customer.subscription.created`
135
+ - `customer.subscription.updated`
136
+ - `customer.subscription.deleted`
137
+ - `invoice.paid`
138
+ - `invoice.payment_failed`
139
+ - `checkout.session.completed`
140
+ - `product.created`
141
+ - `product.updated`
142
+ - `price.created`
143
+ - `price.updated`
144
+
145
+ ## MCP Tools
146
+
147
+ Available tools for AI agents:
148
+
149
+ | Tool | Description |
150
+ |------|-------------|
151
+ | `stripe_create_checkout` | Create checkout session |
152
+ | `stripe_create_portal` | Create customer portal session |
153
+ | `stripe_get_subscription` | Get subscription details |
154
+ | `stripe_cancel_subscription` | Cancel subscription |
155
+ | `stripe_list_products` | List products |
156
+ | `stripe_list_prices` | List prices |
157
+ | `stripe_list_subscriptions` | List subscriptions |
158
+ | `stripe_list_invoices` | List invoices |
159
+ | `stripe_sync_products` | Sync products to LokiCMS |
160
+
161
+ ## Usage Examples
162
+
163
+ ### Create a Subscription Checkout
164
+
165
+ ```typescript
166
+ const response = await fetch('/api/plugins/stripe/checkout', {
167
+ method: 'POST',
168
+ headers: { 'Content-Type': 'application/json' },
169
+ body: JSON.stringify({
170
+ priceId: 'price_monthly_pro',
171
+ customerEmail: 'user@example.com',
172
+ mode: 'subscription',
173
+ trialDays: 14
174
+ })
175
+ });
176
+
177
+ const { url } = await response.json();
178
+ window.location.href = url;
179
+ ```
180
+
181
+ ### Check User Subscription
182
+
183
+ ```typescript
184
+ // Get subscriptions for a customer
185
+ const subs = await fetch('/api/plugins/stripe/subscriptions?customerId=cus_xxx');
186
+ const { subscriptions } = await subs.json();
187
+
188
+ const activeSub = subscriptions.find(s => s.status === 'active');
189
+ ```
190
+
191
+ ### Allow Customer to Manage Subscription
192
+
193
+ ```typescript
194
+ const response = await fetch('/api/plugins/stripe/portal', {
195
+ method: 'POST',
196
+ headers: { 'Content-Type': 'application/json' },
197
+ body: JSON.stringify({
198
+ customerId: 'cus_xxx',
199
+ returnUrl: window.location.href
200
+ })
201
+ });
202
+
203
+ const { url } = await response.json();
204
+ window.location.href = url;
205
+ ```
206
+
207
+ ## License
208
+
209
+ MIT
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "lokicms-plugin-stripe",
3
+ "version": "1.0.0",
4
+ "description": "Stripe payments and subscriptions plugin for LokiCMS",
5
+ "main": "src/index.ts",
6
+ "types": "src/index.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "dev": "tsc --watch"
10
+ },
11
+ "keywords": [
12
+ "lokicms",
13
+ "plugin",
14
+ "stripe",
15
+ "payments",
16
+ "subscriptions",
17
+ "checkout",
18
+ "billing",
19
+ "saas"
20
+ ],
21
+ "author": "MauricioPerera",
22
+ "license": "MIT",
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/MauricioPerera/lokicms-plugin-stripe.git"
26
+ },
27
+ "bugs": {
28
+ "url": "https://github.com/MauricioPerera/lokicms-plugin-stripe/issues"
29
+ },
30
+ "homepage": "https://github.com/MauricioPerera/lokicms-plugin-stripe#readme",
31
+ "dependencies": {
32
+ "stripe": "^17.7.0"
33
+ },
34
+ "peerDependencies": {
35
+ "hono": "^4.0.0",
36
+ "zod": "^3.0.0"
37
+ },
38
+ "lokicms": {
39
+ "displayName": "Stripe Payments",
40
+ "description": "Accept payments and manage subscriptions with Stripe",
41
+ "icon": "💳",
42
+ "minVersion": "1.0.0"
43
+ }
44
+ }