-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSUBSCRIPTION_QUICK_REFERENCE.sh
More file actions
350 lines (276 loc) · 14.4 KB
/
SUBSCRIPTION_QUICK_REFERENCE.sh
File metadata and controls
350 lines (276 loc) · 14.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#!/bin/bash
# Phu AI Subscription - Quick Reference Guide
# Run this guide anytime: bash SUBSCRIPTION_QUICK_REFERENCE.sh
clear
cat << 'EOF'
╔═══════════════════════════════════════════════════════════════════╗
║ ║
║ ⚡ PHU AI SUBSCRIPTION SYSTEM - QUICK REFERENCE ║
║ ║
║ Your complete guide to monthly & yearly subscriptions ║
║ with $8.99/month and $49.99/year payment plans ║
║ ║
╚═══════════════════════════════════════════════════════════════════╝
═══════════════════════════════════════════════════════════════════
1️⃣ SUBSCRIPTION PLANS
═══════════════════════════════════════════════════════════════════
MONTHLY PLAN
Price: $8.99 per month
Credits: 100 per month
Cost per credit: $0.0899
Renewal: Every 30 days
Best for: Testing & casual users
YEARLY PLAN
Price: $49.99 per year
Credits: 1,200 per year
Cost per credit: $0.0416
Renewal: Every 365 days
Savings: 42% vs monthly ($59.88 saved)
Best for: Regular users
═══════════════════════════════════════════════════════════════════
2️⃣ SETUP CHECKLIST
═══════════════════════════════════════════════════════════════════
Step 1: Get Stripe Keys
✓ Go to https://dashboard.stripe.com
✓ API Keys section
✓ Copy Secret Key (sk_test_...)
✓ Copy Publishable Key (pk_test_...)
Step 2: Create Products in Stripe
✓ Monthly Plan: $8.99/month
✓ Yearly Plan: $49.99/year
✓ Copy Price IDs (price_...)
Step 3: Set Up Webhook
✓ Webhook URL: https://yourdomain.com/api/payments/webhook
✓ Events: subscription.updated, subscription.deleted, invoice.payment_succeeded, invoice.payment_failed
✓ Copy Webhook Secret (whsec_...)
Step 4: Update .env File
STRIPE_SECRET_KEY=sk_test_your_key
STRIPE_PUBLISHABLE_KEY=pk_test_your_key
STRIPE_WEBHOOK_SECRET=whsec_your_secret
STRIPE_MONTHLY_PRICE_ID=price_monthly_id
STRIPE_YEARLY_PRICE_ID=price_yearly_id
Step 5: Update Controller
File: src/controllers/subscriptionController.js
Update PLANS object with your actual Price IDs
═══════════════════════════════════════════════════════════════════
3️⃣ API ENDPOINTS
═══════════════════════════════════════════════════════════════════
GET /api/subscriptions/plans
Purpose: View available plans
Auth: Not required
Response: List of plans with pricing
POST /api/subscriptions/create
Purpose: Create new subscription
Auth: Required
Body: { plan: "monthly"|"yearly", paymentMethodId: "pm_..." }
GET /api/subscriptions/current
Purpose: Get active subscription
Auth: Required
Response: Current subscription details
POST /api/subscriptions/cancel
Purpose: Cancel subscription
Auth: Required
Body: { cancelImmediately: true|false }
POST /api/subscriptions/resume
Purpose: Resume cancelled subscription
Auth: Required
PUT /api/subscriptions/update-plan
Purpose: Change subscription plan
Auth: Required
Body: { newPlan: "monthly"|"yearly" }
GET /api/subscriptions/history
Purpose: View all subscriptions
Auth: Required
Response: Array of past subscriptions
═══════════════════════════════════════════════════════════════════
4️⃣ TESTING WITH STRIPE
═══════════════════════════════════════════════════════════════════
Test Card - Successful Payment
Card Number: 4242 4242 4242 4242
Expiry: 12/25 (any future date)
CVC: 123 (any 3 digits)
ZIP: 12345 (any)
Test Card - Failed Payment
Card Number: 4000 0000 0000 0002
Expiry: 12/25 (any future date)
CVC: 123 (any 3 digits)
How to Test:
1. Go to http://localhost:3000/subscription
2. Click "Subscribe Now" on a plan
3. Enter test card details
4. Click "Subscribe"
5. Check Stripe webhook deliveries in dashboard
═══════════════════════════════════════════════════════════════════
5️⃣ USER FLOW
═══════════════════════════════════════════════════════════════════
1. User navigates to /subscription
2. Views monthly ($8.99) and yearly ($49.99) plans
3. Clicks "Subscribe Now"
4. Enters card details
5. Payment processed by Stripe
6. Subscription activated
7. Credits added to account
8. Confirmation sent to user
Subscription Statuses:
• active - Currently subscribed
• cancelled - Cancelled, not renewing
• past_due - Payment failed
• paused - Temporarily disabled
• incomplete - Not finished setup
═══════════════════════════════════════════════════════════════════
6️⃣ COMMON COMMANDS
═══════════════════════════════════════════════════════════════════
Start Backend (with auto-reload)
$ npm run dev
Start Frontend
$ cd client && npm start
Test Specific Endpoint
$ curl -X GET http://localhost:5000/api/subscriptions/plans
Monitor Webhooks
$ tail -f logs/webhook.log
Test Stripe Locally (with Stripe CLI)
$ stripe listen --forward-to localhost:5000/api/payments/webhook
═══════════════════════════════════════════════════════════════════
7️⃣ TROUBLESHOOTING
═══════════════════════════════════════════════════════════════════
Issue: Webhook not updating subscription
Fix: Verify webhook secret in .env matches Stripe dashboard
Check server is running
Monitor webhook deliveries in Stripe dashboard
Issue: "Payment method required" error
Fix: Create Stripe payment method first
Use correct payment method ID
Issue: Credits not added after subscription
Fix: Check webhook is being delivered
Verify webhook signature
Check server logs
Issue: Plan change failing
Fix: Ensure both plans exist in Stripe
Verify Price IDs are correct
Check user has active subscription
═══════════════════════════════════════════════════════════════════
8️⃣ REVENUE TRACKING
═══════════════════════════════════════════════════════════════════
100 Monthly Subscribers:
Monthly Revenue: $899
Annual Revenue: $10,788
100 Yearly Subscribers:
Monthly Revenue: $417
Annual Revenue: $4,999
100 Mixed (80% monthly, 20% yearly):
Monthly Revenue: $1,719
Annual Revenue: $20,628
Break-even (per user):
Monthly: 1.1 users × $8.99 = ~$10/month
Yearly: 0.1 users × $49.99 = ~$5/month
═══════════════════════════════════════════════════════════════════
9️⃣ DATABASE QUERIES
═══════════════════════════════════════════════════════════════════
Get User's Active Subscription:
db.subscriptions.findOne({
userId: ObjectId("user_id"),
status: "active"
})
Get All Subscriptions for Plan:
db.subscriptions.find({ plan: "monthly" })
Get Cancelled Subscriptions:
db.subscriptions.find({ status: "cancelled" })
Count Total Revenue:
db.subscriptions.aggregate([
{ $match: { status: "active" } },
{ $group: { _id: null, total: { $sum: "$price" } } }
])
═══════════════════════════════════════════════════════════════════
🔟 DEPLOYMENT CHECKLIST
═══════════════════════════════════════════════════════════════════
Local Testing:
✓ Create subscriptions
✓ Test plan changes
✓ Test cancellations
✓ Verify webhooks
✓ Check credits addition
Pre-Deployment:
✓ Switch Stripe keys to LIVE
✓ Update webhook URL to production
✓ Test with live keys in staging
✓ Set NODE_ENV to "production"
✓ Enable security headers
✓ Set up error monitoring
✓ Configure backups
✓ Set up logging
Post-Deployment:
✓ Monitor webhook deliveries
✓ Track payment success rate
✓ Monitor failed payments
✓ Review user feedback
✓ Track subscription metrics
✓ Update documentation
═══════════════════════════════════════════════════════════════════
1️⃣1️⃣ BANK DETAILS
═══════════════════════════════════════════════════════════════════
Payment Recipient Information:
Name: Phu Quoc Nguyen
Bank: TD Bank Canada Trust
Account: 43821 004 6369582
Transit: 00000
Currency: CAD
All subscription revenue flows to this account!
═══════════════════════════════════════════════════════════════════
1️⃣2️⃣ DOCUMENTATION
═══════════════════════════════════════════════════════════════════
📖 Read these files for more info:
• SUBSCRIPTION.md - Complete feature documentation
• STRIPE_SETUP.sh - Interactive Stripe setup guide
• README.md - Overview & getting started
• API.md - Complete API reference
• SUBSCRIPTION_IMPLEMENTATION.md - What was built
═══════════════════════════════════════════════════════════════════
1️⃣3️⃣ IMPORTANT SECURITY NOTES
═══════════════════════════════════════════════════════════════════
⚠️ NEVER commit .env to Git
⚠️ NEVER share Stripe Secret Keys
⚠️ ALWAYS verify webhook signatures
⚠️ USE test keys during development
⚠️ SWITCH to live keys in production only
⚠️ ROTATE webhook secrets regularly
⚠️ MONITOR webhook delivery failures
═══════════════════════════════════════════════════════════════════
1️⃣4️⃣ QUICK LINKS
═══════════════════════════════════════════════════════════════════
Stripe Dashboard:
https://dashboard.stripe.com
API Keys:
https://dashboard.stripe.com/apikeys
Webhooks:
https://dashboard.stripe.com/webhooks
Subscriptions:
https://dashboard.stripe.com/subscriptions
Products:
https://dashboard.stripe.com/products
Stripe Documentation:
https://stripe.com/docs/subscriptions
═══════════════════════════════════════════════════════════════════
1️⃣5️⃣ NEED HELP?
═══════════════════════════════════════════════════════════════════
Check these in order:
1. Read SUBSCRIPTION.md
2. Read STRIPE_SETUP.sh
3. Check server logs
4. Monitor Stripe webhooks
5. Review Stripe documentation
6. Contact support
═══════════════════════════════════════════════════════════════════
🚀 Ready to launch subscriptions?
Next steps:
1. Run: bash STRIPE_SETUP.sh
2. Edit: nano .env
3. Add your Stripe keys & Price IDs
4. Test: npm run dev
5. Deploy!
═══════════════════════════════════════════════════════════════════
Made with ❤️ for Phu Quoc Nguyen
Phu AI Revenue Automation © 2026
EOF
echo ""
echo "Press Enter to exit..."
read