Summary of Stripe Implementation Analysis (#956)
Summary of Stripe Implementation Analysis (#956)
Current Status in Production
The system currently implements two distinct Stripe workflows:
User to Platform (Admin) Subscription:
- Goal: Users subscribe to the Platform (Admin) for system access.
- Implementation: Direct Stripe API using the platform’s secret key.
- Key Files:
StripePaymentSubscription.php,Subscriptionmodel, andUserPlantable. - Data: Users are registered as
Customersin the Platform’s Stripe account.
Customer to User One-time Payment:
- Goal: Customers pay Users for services (one-off payments).
- Implementation: Stripe Connect using Destination Charges.
- Key Files:
StripeConnectPayment.php,Ordermodel, andUserPaymentSetting(storingstripe_connect_id). - Fees: Commission is taken via
application_fee_amount.
New Requirement: Customer to User Subscription
Can it be done with Stripe? Yes.
Since the system already uses Stripe Connect for one-time payments, extending it to subscriptions is straightforward and uses a similar architecture.
Technical Feasibility & Strategy
- Architecture: Use Stripe Connect Subscriptions with Destination Charges.
- Mechanism: Create the subscription on the Platform account, but direct the recurring funds to the User’s Connected Account using
transfer_data[destination].
Implementation Path
- Stripe API (Connect): Extend the current
Subscription::createcall to include:transfer_data[destination]: The User’sstripe_connect_id.application_fee_percent: For recurring commission on each subscription cycle.
- Database:
- Add a new
customer_subscriptionstable to link Customers to Users/Services (modeled after the existingsubscriptionstable). - Leverage
Type::SUBSCRIPTION = 3in theServicemodel’s enum.
- Add a new
- Webhook Handlers:
- Add handlers for recurring events like
invoice.paid,customer.subscription.deleted, andcustomer.subscription.updatedwithin the Connect webhook flow.
- Add handlers for recurring events like
- UI/UX:
- Update the Customer-facing payment flow to handle recurring subscription initiation.
Verdict: The existing infrastructure for Stripe Connect (storing stripe_connect_id) and Subscriptions (using the standard Stripe API) provides a solid foundation for this feature without requiring a major architectural redesign.
Progress Update
Status: COMPLETED
- Frontend: Successfully implemented a 3-step customer checkout flow (
Select->Confirm & Payment->Complete). Integrated React Stripe Elements directly into the confirmation screen to tokenize credit cards securely. - Backend: Implemented
SubscriptionInteractorfor orders and payments to create Stripe Subscriptions using the Stripe Connect API with Destination Charges, automatically syncing customers and accurately routing funds. Webhook handling is in place to manage the subscription lifecycle.