Feature #9773
openImplement Email/SMS Credit Blocking & Automatic Top-Up Credit Update via Stripe Webhook
100%
Description
Implement a credit management system that automatically stops Email and SMS sending when the subscribed plan limits are exhausted. Customers can purchase additional Email/SMS credits (Top-Up), and once the payment is successfully completed through Stripe, the purchased credits should be automatically added to their existing subscription balance.
Requirements
1. Usage Validation
Validate available Email and SMS credits before sending.
Check remaining credits for every Email and SMS request.
2. Block Sending When Limit is Reached
If Email credits are 0, block all Email sending.
If SMS credits are 0, block all SMS sending.
Return a clear error message indicating that the plan limit has been reached.
Example Messages
Email: "Your Email credits have been exhausted. Please purchase a Top-Up to continue sending emails."
SMS: "Your SMS credits have been exhausted. Please purchase a Top-Up to continue sending SMS."
3. Top-Up Purchase
Allow customers to purchase additional Email and/or SMS credits.
Support multiple Top-Up purchases.
Top-Up credits should be added to the existing account without changing the customer's current subscription plan.
Existing plan features, limits, billing cycle, and subscription should remain unchanged.
4. Stripe Webhook Integration
Handle successful Stripe payment events (e.g., checkout.session.completed or subscription-related payment events, depending on the implementation).
Verify the webhook signature before processing.
On successful payment:
Identify the company/customer.
Identify the purchased Top-Up package.
Automatically add the purchased Email/SMS credits to the company's existing balance.
Record the transaction in the Top-Up history.
Mark the payment as completed.
Prevent duplicate credit additions by ensuring webhook idempotency.
5. Credit Update Logic
New credits should be added to the remaining balance.
Existing unused credits must not be overwritten.
Example:
Current Email Balance: 120
Purchased Top-Up: 500
New Email Balance: 620
6. Audit & History
Maintain a history of:
Company
Top-Up package
Email credits purchased
SMS credits purchased
Stripe Payment Intent/Session ID
Payment status
Credits added
Purchase date and time
Webhook event ID
7. API Changes
Validate available credits before every Email/SMS send.
Update remaining credits after each successful send.
Automatically refresh balances after a successful Top-Up.
Acceptance Criteria
Email/SMS sending is blocked immediately when available credits reach zero.
Customers can purchase Top-Up credits without affecting their existing subscription.
Stripe webhook automatically adds purchased credits after successful payment.
Existing subscription details remain unchanged.
Remaining credits are increased correctly after each successful Top-Up.
Duplicate Stripe webhook events do not add credits more than once.
All Top-Up transactions are logged for audit purposes.
Email and SMS sending resumes automatically once new credits are added successfully.
Subtasks
Related issues
Updated by Pavan Kumar Murala 22 days ago
- Status changed from New to In Progress
Updated by Pavan Kumar Murala 22 days ago
- Status changed from In Progress to Resolved
- % Done changed from 0 to 100