Skip to content

Commit c3c351c

Browse files
committed
coupon
1 parent 1aa4f05 commit c3c351c

File tree

1 file changed

+45
-47
lines changed

1 file changed

+45
-47
lines changed

doc/coupon.md

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,74 @@
1-
# Coupon
1+
## Usage
22

3-
lara-stripe has `LaraStripeCoupon` alias for coupon related task.
3+
Here are some common operations you can perform using the `StripeCoupon` library:
44

5-
#Methods
5+
### Creating a Coupon
66

7-
## setup() `required`
7+
```php
8+
use Code4mk\LaraStripe\Lib\StripeCoupon;
9+
10+
$stripeCoupon = new StripeCoupon();
811

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+
```
1017

11-
* `secret_key` required
18+
### Retrieving a Coupon
1219

1320
```php
14-
setup([
15-
'secret_key' => '********'
16-
])
17-
```
21+
use Code4mk\LaraStripe\Lib\StripeCoupon;
1822

19-
## name() `required`
23+
$stripeCoupon = new StripeCoupon();
2024

21-
Coupon name. Automatic convert camel_case
25+
$couponId = 'coupon_id_here';
2226

23-
```php
24-
name('launch_20')
27+
$stripeCoupon->retrieve($couponId); // Retrieve the coupon by ID
2528
```
2629

27-
## amount() `required`
30+
### Listing Coupons
31+
32+
```php
33+
use Code4mk\LaraStripe\Lib\StripeCoupon;
34+
35+
$stripeCoupon = new StripeCoupon();
2836

29-
Set coupon amount and copoun type `fixed/per` fixed or percent.
37+
$stripeCoupon->lists(); // Retrieve a list of all coupons
38+
```
3039

31-
* amount has 3 parameter amount (`required`) , type (`required`) and currency . `currency is required when type is fixed`
40+
### Deleting a Coupon
3241

3342
```php
34-
# percent
35-
amount(20,'per')
36-
# fixed
37-
amount(20.50,'fixed','usd')
38-
````
43+
use Code4mk\LaraStripe\Lib\StripeCoupon;
3944

40-
## duration() `required`
45+
$stripeCoupon = new StripeCoupon();
4146

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';
4548

46-
```php
47-
duration('once')
48-
# if repeating
49-
duration('repeating',4)
49+
$stripeCoupon->delete($couponId); // Delete the coupon by ID
5050
```
5151

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).
5353

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.
5657

5758
```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+
}
5966
```
6067

61-
# `Create coupon -> Full code`
68+
## License
6269

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.
7071

71-
# `Delete the coupon`
72+
## Author
7273

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

Comments
 (0)