Streamlining Subscription Management and Credit Purchases in Breniapp
Introduction
Managing subscriptions and in-app credits can be complex, especially when integrating with payment gateways like Stripe. Breniapp is enhancing its platform to provide a smoother experience for both administrators and users by focusing on plan management and credit purchasing.
Plan Deletion and Stripe Product Archival
Previously, deleting a plan might have left lingering data or inconsistencies within the Stripe integration. Now, Breniapp implements a soft-delete mechanism for plans. When a plan is deleted within the application, the corresponding product in Stripe is archived. This ensures that the plan is no longer available for new subscriptions while preserving historical data and maintaining consistency between Breniapp and Stripe.
Credit Packs with Stripe Sync
To enhance the credit purchasing system, Breniapp introduces a CreditPack model. This model, managed through Filament CRUD, allows administrators to define various credit packages with associated prices. The prices are synchronized with Stripe's one-time pricing feature, meaning updates to the price in Breniapp will propagate to Stripe, ensuring consistent pricing across platforms.
Here's an example of how you might define a method to sync the price of a credit pack with Stripe:
use Stripe\Price;
class CreditPack extends Model
{
public function syncPriceWithStripe(float $price):
{
$stripePrice = Price::create([
'unit_amount' => $price * 100, // Stripe uses cents
'currency' => 'usd',
'product' => $this->stripe_product_id,
]);
$this->stripe_price_id = $stripePrice->id;
$this->save();
}
}
This code snippet demonstrates how to create a new price in Stripe for a credit pack, ensuring that the amount is formatted correctly for Stripe's API (in cents).
Dedicated Credit Purchase Page
A dedicated /credits/buy page has been created to provide a user-friendly interface for purchasing credit packs. This page streamlines the purchase process, making it easier for users to understand the available options and complete their transactions.
Webhook Handling for Credit Allocation
The webhook handler has been updated to accurately resolve credits based on the purchased pack ID. This ensures that users receive the correct amount of credits after a successful purchase, improving the reliability of the credit system.
Key Insight
By integrating Stripe more closely with Breniapp's plan and credit systems, the platform delivers a more cohesive and reliable experience. This involves not only facilitating purchases but also maintaining data consistency and providing clear management interfaces.