Skip to content

Commit 8d587f0

Browse files
committed
subscription
1 parent 285503b commit 8d587f0

File tree

1 file changed

+34
-89
lines changed

1 file changed

+34
-89
lines changed

doc/subscription.md

Lines changed: 34 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,62 @@
1-
# Subscription
1+
## Usage
22

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

5-
# Methods
6-
7-
## `setup()` `required`
8-
9-
setup method as usual setup secret key
10-
11-
* `secret_key` `required`
12-
13-
```php
14-
setup([
15-
'secret_key' => '********'
16-
])
17-
```
18-
19-
## `customer()` `required`
20-
21-
which customer subscribe.
22-
23-
* [create customer first](https://github.com/code4mk/lara-stripe/blob/master/doc/customer.md)
24-
25-
```php
26-
customer('customer_id')
27-
```
28-
29-
## `plan()` `required`
30-
31-
Customer subscription which plan.
32-
33-
* [create a plan first](https://github.com/code4mk/lara-stripe/blob/master/doc/customer.md)
34-
35-
```php
36-
plan('plan_id')
37-
```
38-
39-
## `trialPlan()` `optional`
40-
41-
If want to set trial period from plan.
5+
### Creating a Subscription
426

437
```php
44-
trialPlan()
45-
```
8+
use Code4mk\LaraStripe\Lib\StripeSubscription;
469

47-
## `trail()` `optional`
10+
$stripeSubscription = new StripeSubscription();
4811

49-
Set tril period for the subscription. This override the plan trail.
12+
$customerId = 'customer_id_here';
13+
$priceId = 'price_id_here';
5014

51-
```php
52-
trial(5)
15+
$stripeSubscription->customer($customerId) // Set the customer ID
16+
->priceId($priceId) // Set the price (plan) ID
17+
->metaData(['key' => 'value']) // Set additional metadata (optional)
18+
->trialPlan() // Use the default trial from the plan (optional)
19+
->trial(7) // Set a custom trial period in days (optional)
20+
->source('card_source_id') // Set the card source (optional)
21+
->coupon('coupon_code_here') // Apply a coupon (optional)
22+
->create(); // Create the subscription
5323
```
5424

55-
## `source()` `optional`
56-
57-
set source (card token generate from stipe.js).
25+
### Retrieving a Subscription
5826

5927
```php
60-
source('tok_***')
61-
```
28+
use Code4mk\LaraStripe\Lib\StripeSubscription;
6229

63-
## `coupon()` `optioanl`
30+
$stripeSubscription = new StripeSubscription();
6431

65-
Subscription with a coupon
32+
$subscriptionId = 'subscription_id_here';
6633

67-
```php
68-
coupon('coupon_code')
34+
$stripeSubscription->retrieve($subscriptionId); // Retrieve the subscription by ID
6935
```
7036

71-
## extra `optional`
72-
73-
Add optional attributes which are not include this package for creating subscription.
74-
75-
* [all attributes lists](https://stripe.com/docs/api/subscriptions/create)
37+
### Canceling a Subscription
7638

7739
```php
78-
extra([
79-
.....
80-
])
81-
```
40+
use Code4mk\LaraStripe\Lib\StripeSubscription;
8241

83-
## `get()` `required`
42+
$stripeSubscription = new StripeSubscription();
8443

85-
* create the subscription and retrive created subscription data.
86-
* return `object`
44+
$subscriptionId = 'subscription_id_here';
8745

88-
```php
89-
get()
46+
$stripeSubscription->cancel($subscriptionId); // Cancel the subscription by ID
9047
```
9148

92-
# `Create a Subscription -> Full code`
93-
49+
For more details on available methods and parameters, refer to the inline code comments and the [Stripe API documentation](https://stripe.com/docs/api/subscriptions).
9450

95-
```php
96-
LaraStripeSubs::setup(['secret_key'=>'******'])
97-
->customer('customer_id')
98-
->plan('plan_id')
99-
->source('tok_***')
100-
->trialPlan()
101-
->coupon('coupon_id')
102-
->get();
103-
```
51+
## Error Handling
10452

105-
# `Retrieve the subscription`
53+
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.
10654

10755
```php
108-
LaraStripeSubs::setup(['secret_key'=>'******'])
109-
->retrieve('subs_id')
110-
```
111-
112-
# `Cancel the subscription`
56+
$result = $stripeSubscription->create();
11357

114-
```php
115-
LaraStripeSubs::setup(['secret_key'=>'******'])
116-
->cancel('subs_id')
117-
```
58+
if ($result->isError === true) {
59+
// Handle the error
60+
echo "Error: " . $result->message;
61+
}
62+
```

0 commit comments

Comments
 (0)