|
| 1 | +Sure, here's a step-by-step guide on setting up a subscription in Stripe using the `StripeProducts` and `StripeSubscription` classes: |
| 2 | + |
| 3 | +**1. Create a Product** |
| 4 | + |
| 5 | +Use the `StripeProducts` class to create a product: |
| 6 | + |
| 7 | +```php |
| 8 | +use Code4mk\LaraStripe\Lib\StripeProducts; |
| 9 | + |
| 10 | +$stripeProducts = new StripeProducts(); |
| 11 | + |
| 12 | +$productName = 'Your Product Name'; |
| 13 | + |
| 14 | +$product = $stripeProducts->name($productName) |
| 15 | + ->create(); |
| 16 | +``` |
| 17 | + |
| 18 | +**2. Set Price (Plan) with Product ID** |
| 19 | + |
| 20 | +Now that you have a product, you can set a price for that product. Use the product's ID when creating the price: |
| 21 | + |
| 22 | +```php |
| 23 | +use Code4mk\LaraStripe\Lib\StripePrices; // Assuming you have a StripePrices class |
| 24 | +$pricesInstance = new StripePrices(); |
| 25 | +$price = $stripePrices->description('gqa plan 1 - 10usd') |
| 26 | + ->amount(10) |
| 27 | + ->currency('usd') |
| 28 | + ->product($product->id) |
| 29 | + ->interval('day') |
| 30 | + ->createPrice(); |
| 31 | +``` |
| 32 | + |
| 33 | +**3. Create a Customer** |
| 34 | + |
| 35 | +Use the `StripeCustomer` class to create a customer. Make sure to collect the necessary customer information: |
| 36 | + |
| 37 | +```php |
| 38 | +use Code4mk\LaraStripe\Lib\StripeCustomer; // Assuming you have a StripeCustomer class |
| 39 | + |
| 40 | +$stripeCustomer = new StripeCustomer(); |
| 41 | + |
| 42 | +$customer = $stripeCustomer->name('Customer Name') |
| 43 | + |
| 44 | + ->create() |
| 45 | +``` |
| 46 | + |
| 47 | +**4. Add a Subscription** |
| 48 | + |
| 49 | +Finally, add a subscription for the customer using the `StripeSubscription` class: |
| 50 | + |
| 51 | +```php |
| 52 | +use Code4mk\LaraStripe\Lib\StripeSubscription; |
| 53 | + |
| 54 | +$stripeSubscription = new StripeSubscription(); |
| 55 | + |
| 56 | +$customerId = $customer->id; // Use the customer's ID |
| 57 | +$priceId = $price->id; // Use the price's ID |
| 58 | + |
| 59 | +$subscription = $stripeSubscription->customer($customerId) |
| 60 | + ->priceId($priceId) |
| 61 | + ->create(); |
| 62 | +``` |
| 63 | + |
| 64 | +Now you have set up a subscription for a customer, starting with the creation of a product, setting a price (plan) for that product, creating a customer, and finally adding a subscription to the customer. |
0 commit comments