|
1 |
| -# Coupon |
| 1 | +## Usage |
2 | 2 |
|
3 |
| -lara-stripe has `LaraStripeCoupon` alias for coupon related task. |
| 3 | +Here are some common operations you can perform using the `StripeCoupon` library: |
4 | 4 |
|
5 |
| -#Methods |
| 5 | +### Creating a Coupon |
6 | 6 |
|
7 |
| -## setup() `required` |
| 7 | +```php |
| 8 | +use Code4mk\LaraStripe\Lib\StripeCoupon; |
| 9 | + |
| 10 | +$stripeCoupon = new StripeCoupon(); |
8 | 11 |
|
9 |
| -setup method as usual setup secret key |
| 12 | +$stripeCoupon->amount(10.00) // Set the coupon amount |
| 13 | + ->name('my_coupon') // Set the coupon name |
| 14 | + ->duration('once') // Set the coupon duration |
| 15 | + ->create(); // Create the coupon |
| 16 | +``` |
10 | 17 |
|
11 |
| -* `secret_key` required |
| 18 | +### Retrieving a Coupon |
12 | 19 |
|
13 | 20 | ```php
|
14 |
| -setup([ |
15 |
| - 'secret_key' => '********' |
16 |
| -]) |
17 |
| -``` |
| 21 | +use Code4mk\LaraStripe\Lib\StripeCoupon; |
18 | 22 |
|
19 |
| -## name() `required` |
| 23 | +$stripeCoupon = new StripeCoupon(); |
20 | 24 |
|
21 |
| -Coupon name. Automatic convert camel_case |
| 25 | +$couponId = 'coupon_id_here'; |
22 | 26 |
|
23 |
| -```php |
24 |
| -name('launch_20') |
| 27 | +$stripeCoupon->retrieve($couponId); // Retrieve the coupon by ID |
25 | 28 | ```
|
26 | 29 |
|
27 |
| -## amount() `required` |
| 30 | +### Listing Coupons |
| 31 | + |
| 32 | +```php |
| 33 | +use Code4mk\LaraStripe\Lib\StripeCoupon; |
| 34 | + |
| 35 | +$stripeCoupon = new StripeCoupon(); |
28 | 36 |
|
29 |
| -Set coupon amount and copoun type `fixed/per` fixed or percent. |
| 37 | +$stripeCoupon->lists(); // Retrieve a list of all coupons |
| 38 | +``` |
30 | 39 |
|
31 |
| -* amount has 3 parameter amount (`required`) , type (`required`) and currency . `currency is required when type is fixed` |
| 40 | +### Deleting a Coupon |
32 | 41 |
|
33 | 42 | ```php
|
34 |
| -# percent |
35 |
| -amount(20,'per') |
36 |
| -# fixed |
37 |
| -amount(20.50,'fixed','usd') |
38 |
| -```` |
| 43 | +use Code4mk\LaraStripe\Lib\StripeCoupon; |
39 | 44 |
|
40 |
| -## duration() `required` |
| 45 | +$stripeCoupon = new StripeCoupon(); |
41 | 46 |
|
42 |
| -* duration has 2 parameter one is type another is month. |
43 |
| -* type `required` `[forever,once,repeating]` |
44 |
| -* if type `repeating` that time `month` is `required`. month is integer value. |
| 47 | +$couponId = 'coupon_id_here'; |
45 | 48 |
|
46 |
| -```php |
47 |
| -duration('once') |
48 |
| -# if repeating |
49 |
| -duration('repeating',4) |
| 49 | +$stripeCoupon->delete($couponId); // Delete the coupon by ID |
50 | 50 | ```
|
51 | 51 |
|
52 |
| -## get() `required` |
| 52 | +For more details on available methods and parameters, refer to the inline code comments and the [Stripe API documentation](https://stripe.com/docs/api/coupons). |
53 | 53 |
|
54 |
| -* create the coupon and retrive created coupon data. |
55 |
| -* return `object` |
| 54 | +## Error Handling |
| 55 | + |
| 56 | +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 and the Stripe error details. |
56 | 57 |
|
57 | 58 | ```php
|
58 |
| -get() |
| 59 | +$result = $stripeCoupon->create(); |
| 60 | + |
| 61 | +if ($result->isError === true) { |
| 62 | + // Handle the error |
| 63 | + echo "Error: " . $result->message; |
| 64 | + echo "Stripe Error: " . $result->stripe['message']; |
| 65 | +} |
59 | 66 | ```
|
60 | 67 |
|
61 |
| -# `Create coupon -> Full code` |
| 68 | +## License |
62 | 69 |
|
63 |
| -```php |
64 |
| -LaraStripeCoupon::setup(['secret_key' => '*****']) |
65 |
| - ->name('launch_20') |
66 |
| - ->amount(10,'per') |
67 |
| - ->duration('month') |
68 |
| - ->get() |
69 |
| -``` |
| 70 | +This library is open-source software licensed under the MIT License. You can find the full license text in the [LICENSE](LICENSE) file. |
70 | 71 |
|
71 |
| -# `Delete the coupon` |
| 72 | +## Author |
72 | 73 |
|
73 |
| -```php |
74 |
| -LaraStripeCoupon::setup(['secret_key' => '*****']) |
75 |
| - ->delete('coupon_id') |
76 |
| -``` |
| 74 | +This library was created by [Your Name] and is maintained by [Your Organization]. Feel free to contribute by submitting issues or pull requests on the [GitHub repository](https://github.com/your-repo-link). |
0 commit comments