mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-06-01 14:52:02 +00:00
5.9 KiB
5.9 KiB
Yearly Subscription Implementation Plan
1. Database Schema Updates
model Role {
// Existing fields...
subscriptionType String @default("monthly") // Options: "monthly", "yearly"
// Other fields remain the same
}
2. UI Component Updates
SubscribeModal.js
- Add toggle between monthly/yearly subscription options
- Update pricing display (50,000 sats monthly / 500,000 sats yearly)
- Show savings message for yearly option (~17% discount)
SubscriptionPaymentButton.js
- Add subscription type parameter
- Modify amount calculation based on subscription type
- Update NWC configuration for yearly budgets
// Example modification
const getAmount = (subscriptionType) => {
return subscriptionType === 'yearly' ? 500000 : 50000;
};
// For NWC setup
const budgetRenewal = subscriptionType === 'yearly' ? 'yearly' : 'monthly';
3. API Endpoints Updates
/api/users/subscription
- Update to accept subscriptionType parameter
- Modify database update to store subscription type
// Example modification
export const updateUserSubscription = async (userId, isSubscribed, nwc, subscriptionType = 'monthly') => {
try {
const now = new Date();
return await prisma.user.update({
where: { id: userId },
data: {
role: {
upsert: {
create: {
subscribed: isSubscribed,
subscriptionType: subscriptionType,
// Other fields remain the same
},
update: {
subscribed: isSubscribed,
subscriptionType: subscriptionType,
// Other fields remain the same
},
},
},
},
include: {
role: true,
},
});
} finally {
await prisma.$disconnect();
}
};
4. Cron Job Modifications
cron.js
- Update expiration calculation to check subscription type
- For monthly: expire after 30 days + 1 hour
- For yearly: expire after 365 days + 1 hour
export const findExpiredSubscriptions = async () => {
const now = new Date();
// Define expiration periods
const monthlyExpiration = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000 - 1 * 60 * 60 * 1000);
const yearlyExpiration = new Date(now.getTime() - 365 * 24 * 60 * 60 * 1000 - 1 * 60 * 60 * 1000);
// Find expired subscriptions of both types
const expiredSubscriptions = await prisma.role.findMany({
where: {
subscribed: true,
OR: [
{
subscriptionType: 'monthly',
lastPaymentAt: { lt: monthlyExpiration }
},
{
subscriptionType: 'yearly',
lastPaymentAt: { lt: yearlyExpiration }
}
]
},
select: {
userId: true,
nwc: true,
subscriptionType: true,
subscriptionExpiredAt: true,
subscriptionStartDate: true,
admin: true,
}
});
return expiredSubscriptions;
};
5. Testing Plan
Database Testing
- Verify Prisma schema correctly includes the subscriptionType field with default value "monthly"
- Confirm migrations apply correctly to existing database
UI Testing
-
Monthly Subscription UI
- Verify the subscription selector defaults to monthly
- Check pricing shows 50,000 sats for monthly
- Ensure subscription buttons show "Monthly" where appropriate
-
Yearly Subscription UI
- Verify selecting yearly plan updates all UI elements
- Check pricing shows 500,000 sats for yearly
- Confirm ~17% savings message appears
- Ensure subscription buttons show "Yearly" where appropriate
Payment Flow Testing
-
Monthly One-time Payment
- Test subscription purchase with "Pay as you go" for monthly plan
- Verify subscription is created with type "monthly"
- Confirm user profile shows correct subscription expiration date (30 days)
-
Monthly Recurring Payment
- Test subscription setup with "Setup Recurring Monthly Subscription"
- Verify NWC configuration with monthly budget renewal
- Confirm subscription is created with type "monthly"
-
Yearly One-time Payment
- Test subscription purchase with "Pay as you go" for yearly plan
- Verify subscription is created with type "yearly"
- Confirm user profile shows correct subscription expiration date (365 days)
-
Yearly Recurring Payment
- Test subscription setup with "Setup Recurring Yearly Subscription"
- Verify NWC configuration with yearly budget renewal
- Confirm subscription is created with type "yearly"
Cron Job Testing
-
Recently Active Monthly Subscription
- Set up test account with monthly subscription
- Verify subscription not marked as expired by cron job
-
Recently Active Yearly Subscription
- Set up test account with yearly subscription
- Verify subscription not marked as expired by cron job
-
Expired Monthly Subscription
- Create test account with monthly subscription
- Manually adjust lastPaymentAt date to be >30 days ago
- Run cron job and verify subscription is expired
-
Expired Yearly Subscription
- Create test account with yearly subscription
- Manually adjust lastPaymentAt date to be >365 days ago
- Run cron job and verify subscription is expired
-
Auto-renewal Testing
- Set up NWC for test accounts (both monthly and yearly)
- Manually adjust lastPaymentAt date to trigger expiration
- Run cron job and verify proper renewal amount is charged
- Confirm subscription type is maintained after renewal
6. Implementation Steps
- ✅ Create database migration for schema changes
- ✅ Modify frontend subscription components
- ✅ Update backend models and API endpoints
- ✅ Update cron job logic
- Test all flows thoroughly
- Deploy changes
7. Marketing Considerations
- Highlight savings with yearly subscription (~17% discount)
- Update documentation and marketing materials
- Consider grandfathering existing subscribers or offering upgrade path