|
| 1 | +## Usage |
| 2 | + |
| 3 | +Here are some common operations you can perform using the `StripePrices` library: |
| 4 | + |
| 5 | +### Creating a Subscription Price |
| 6 | + |
| 7 | +```php |
| 8 | +use Code4mk\LaraStripe\Lib\StripePrices; |
| 9 | + |
| 10 | +$stripePrices = new StripePrices(); |
| 11 | + |
| 12 | +$stripePrices->product(['name' => 'Product Name']) // Set the product details |
| 13 | + ->amount(10.00) // Set the price amount |
| 14 | + ->interval('month') // Set the billing interval (day, week, month, year) |
| 15 | + ->currency('usd') // Set the currency |
| 16 | + ->extra(['metadata' => ['key' => 'value']]) // Set extra properties |
| 17 | + ->trial(7) // Set the trial period in days (optional) |
| 18 | + ->description('Subscription Plan') // Set a description (optional) |
| 19 | + ->createPrice(); // Create the subscription price |
| 20 | +``` |
| 21 | + |
| 22 | +### Retrieving a Subscription Price |
| 23 | + |
| 24 | +```php |
| 25 | +use Code4mk\LaraStripe\Lib\StripePrices; |
| 26 | + |
| 27 | +$stripePrices = new StripePrices(); |
| 28 | + |
| 29 | +$priceId = 'price_id_here'; |
| 30 | + |
| 31 | +$stripePrices->retrieve($priceId); // Retrieve the subscription price by ID |
| 32 | +``` |
| 33 | + |
| 34 | +### Activating a Subscription Price |
| 35 | + |
| 36 | +```php |
| 37 | +use Code4mk\LaraStripe\Lib\StripePrices; |
| 38 | + |
| 39 | +$stripePrices = new StripePrices(); |
| 40 | + |
| 41 | +$priceId = 'price_id_here'; |
| 42 | + |
| 43 | +$stripePrices->activate($priceId); // Activate the subscription price by ID |
| 44 | +``` |
| 45 | + |
| 46 | +### Deactivating a Subscription Price |
| 47 | + |
| 48 | +```php |
| 49 | +use Code4mk\LaraStripe\Lib\StripePrices; |
| 50 | + |
| 51 | +$stripePrices = new StripePrices(); |
| 52 | + |
| 53 | +$priceId = 'price_id_here'; |
| 54 | + |
| 55 | +$stripePrices->deactivate($priceId); // Deactivate the subscription price by ID |
| 56 | +``` |
| 57 | + |
| 58 | +### Deleting a Subscription Price |
| 59 | + |
| 60 | +```php |
| 61 | +use Code4mk\LaraStripe\Lib\StripePrices; |
| 62 | + |
| 63 | +$stripePrices = new StripePrices(); |
| 64 | + |
| 65 | +$priceId = 'price_id_here'; |
| 66 | + |
| 67 | +$stripePrices->delete($priceId); // Delete the subscription price by ID |
| 68 | +``` |
| 69 | + |
| 70 | +### Listing Subscription Prices |
| 71 | + |
| 72 | +```php |
| 73 | +use Code4mk\LaraStripe\Lib\StripePrices; |
| 74 | + |
| 75 | +$stripePrices = new StripePrices(); |
| 76 | + |
| 77 | +$stripePrices->lists(); // Retrieve a list of all subscription prices |
| 78 | +``` |
| 79 | + |
| 80 | +For more details on available methods and parameters, refer to the inline code comments and the [Stripe API documentation](https://stripe.com/docs/api/prices). |
| 81 | + |
| 82 | +## Error Handling |
| 83 | + |
| 84 | +The library provides basic error handling. If an error occurs during an operation, it returns an object with an `isError` property set to `true`, along with an error message. |
| 85 | + |
| 86 | +```php |
| 87 | +$result = $stripePrices->createPrice(); |
| 88 | + |
| 89 | +if ($result->isError === true) { |
| 90 | + // Handle the error |
| 91 | + echo "Error: " . $result->message; |
| 92 | +} |
| 93 | +``` |
0 commit comments