Skip to content

Commit a88597c

Browse files
committed
add doc
1 parent 8d587f0 commit a88597c

File tree

6 files changed

+159
-89
lines changed

6 files changed

+159
-89
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ php artisan vendor:publish --provider="Code4mk\LaraStripe\LaraStripeServiceProvi
2626
* [Prices doc](https://github.com/code4mk/lara-stripe/blob/master/doc/prices.md)
2727
* [Subscription doc](https://github.com/code4mk/lara-stripe/blob/master/doc/subscription.md)
2828
* [Coupon doc](https://github.com/code4mk/lara-stripe/blob/master/doc/coupon.md)
29+
* [promotion doc](https://github.com/code4mk/lara-stripe/blob/master/doc/promotion.md)
2930

3031
# Demo repo
3132

@@ -34,5 +35,4 @@ php artisan vendor:publish --provider="Code4mk\LaraStripe\LaraStripeServiceProvi
3435
# Courtesy
3536

3637
* [stripe/stripe-php](https://github.com/stripe/stripe-php)
37-
3838
* https://jsfiddle.net/ywain/o2n3js2r/

doc/coupon.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use Code4mk\LaraStripe\Lib\StripeCoupon;
99

1010
$stripeCoupon = new StripeCoupon();
1111

12-
$stripeCoupon->amount(10.00) // Set the coupon amount
13-
->name('my_coupon') // Set the coupon name
12+
$stripeCoupon->name('my_coupon') // Set the coupon name
13+
->amount(10.00) // Set the coupon amount
1414
->duration('once') // Set the coupon duration
1515
->create(); // Create the coupon
1616
```

doc/customer.md

Lines changed: 96 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,140 @@
1-
# Customer
1+
## Usage
22

3-
`customer` for get future payment as like `subscription fee`.
3+
Here's how you can use the Stripe Customer Library to perform various customer-related actions in your Laravel application.
44

5-
LaraStripe has LaraStripeCustomer alias for customer related task.
6-
7-
# create new customer
8-
9-
## methods
10-
11-
### setup
12-
13-
Set secret key .
14-
15-
* `secret_key` required
5+
### Initialization
166

177
```php
18-
LaraStripeCustomer::setup([
19-
'secret_key'=>'sk_test_mBGoFuccDy2KCD4pobbaixKK00qUW0ghu1'
20-
])
8+
use Code4mk\LaraStripe\Lib\StripeCustomer;
219

10+
// Initialize the Stripe Customer instance
11+
$stripeCustomer = new StripeCustomer();
2212
```
2313

24-
### create
25-
26-
Customer important data as like source(card token),email
14+
### Creating a Customer
2715

28-
* `source` required
29-
* [see more on stripe](https://stripe.com/docs/api/customers/create)
16+
You can create a new customer by specifying their name, email, and optional metadata.
3017

3118
```php
32-
LaraStripeCustomer::create([
33-
['source' => 'card token','email' => '[email protected]']
34-
])
19+
$customer = $stripeCustomer
20+
->name($customerName)
21+
->email($customerEmail)
22+
->metadata($metadata)
23+
->create();
24+
25+
if ($customer->isError) {
26+
// Handle errors
27+
echo $customer->message;
28+
} else {
29+
// Customer created successfully
30+
}
3531
```
3632

37-
### metadata
33+
### Retrieving a Customer
3834

39-
* customer extra info or data set with metadata as array.
35+
You can retrieve a customer by their ID.
4036

4137
```php
42-
LaraStripeCustomer::metadata([
43-
'phone' => '212',
44-
'age' => 23
45-
])
38+
$customer = $stripeCustomer->retrieve($customerId);
39+
40+
if ($customer->isError) {
41+
// Handle errors
42+
echo $customer->message;
43+
} else {
44+
// Use $customer to access customer data
45+
}
4646
```
4747

48-
### get
48+
### Deleting a Customer
4949

50-
`get` method return customer data after customer create complete.
51-
52-
* return type `object`
50+
You can delete a customer by their ID.
5351

5452
```php
55-
LaraStripeCustomer::get();
53+
$customer = $stripeCustomer->delete($customerId);
54+
55+
if ($customer->isError) {
56+
// Handle errors
57+
echo $customer->message;
58+
} else {
59+
// Customer deleted successfully
60+
}
5661
```
5762

58-
## full code
63+
### Retrieving All Customers
64+
65+
You can retrieve a list of all customers.
5966

6067
```php
61-
$cus = LaraStripeCustomer::setup([
62-
'secret_key'=>'sk_test_mBGoFuccDy2KCD4pobbaixKK00qUW0ghu1'
63-
])
64-
->create(['source' => 'tok_visa','email' => '[email protected]'])
65-
->metadata(['phone' => '212','age'=>23])
66-
->get();
67-
68-
return response()->json($cus);
68+
$customers = $stripeCustomer->lists();
69+
70+
if ($customers->isError) {
71+
// Handle errors
72+
echo $customers->message;
73+
} else {
74+
// Use $customers to access the list of customers
75+
}
6976
```
7077

71-
`~ NB: store customer id on db for future payment`
78+
### Managing Customer Cards
7279

73-
## `see - charge with customer `
80+
You can manage a customer's cards, such as listing, adding, deleting, or setting a default card.
7481

75-
same as [charge create with card](https://github.com/code4mk/lara-stripe/blob/master/doc/charge.md#full-code) with card. only `card method` exchage with `customer method`
76-
77-
* `customer($cusId)`
82+
#### Listing Customer Cards
7883

7984
```php
80-
$charge = LaraStripeCharge::setup([
81-
'secret_key'=>'sk_test_mBGoFuccDy2KCD4pobbaixKK00qUW0ghu1',
82-
'public_key' => 'pk_test_VNi7F1zcwwffZIi1tAkX1dVs00JfKPsCGR',
83-
'currency'=>'usd'
84-
])
85-
->customer('cus_G2L2KoumL45hzn')
86-
->amount(25.54567)
87-
->metadata(['tnx_id' => 'tnx-32343','purchase_id' => 'trgtrg45'])
88-
->description('charge with customer id ')
89-
->purchase()
90-
->get();
91-
return response()->json($charge);
85+
$cards = $stripeCustomer->cards($customerId);
86+
87+
if ($cards->isError) {
88+
// Handle errors
89+
echo $cards->message;
90+
} else {
91+
// Use $cards to access the list of customer cards
92+
}
9293
```
9394

94-
# retrieve customer
95-
96-
* `retrieve` method has `cusId` param which is customer id.
97-
* return type `object`
95+
#### Adding a New Card
9896

9997
```php
100-
$cus = LaraStripeCustomer::setup([
101-
'secret_key'=>'sk_test_mBGoFuccDy2KCD4pobbaixKK00qUW0ghu1'
102-
])
103-
->retrieve('cus_G2L2KoumL45hzn');
98+
$cardToken = 'your_stripe_card_token';
99+
$cardMaxLimit = 3; // Set the maximum number of cards per customer
104100

105-
return response()->json($cus);
101+
$response = $stripeCustomer->addCard($customerId, $cardToken, $cardMaxLimit);
102+
103+
if ($response->isError) {
104+
// Handle errors
105+
echo $response->message;
106+
} else {
107+
// Card added successfully
108+
}
106109
```
107110

108-
# change card
111+
#### Deleting a Card
112+
113+
```php
114+
$cardId = 'stripe_card_id';
115+
116+
$response = $stripeCustomer->deleteCard($customerId, $cardId);
109117

110-
Sometimes customer want to change their card.
118+
if ($response->isError) {
119+
// Handle errors
120+
echo $response->message;
121+
} else {
122+
// Card deleted successfully
123+
}
124+
```
111125

112-
* `changeCard($cusId,$cardToken)` has `cusId` param which is customer id and `cardToken` param which is card token .
113-
* return type `object`
126+
#### Setting Default Card
114127

115128
```php
116-
$cus = LaraStripeCustomer::setup([
117-
'secret_key'=>'sk_test_mBGoFuccDy2KCD4pobbaixKK00qUW0ghu1'
118-
])
119-
->changeCard('cus_G2L2KoumL45hzn','tok_amex');
129+
$defaultCardId = 'stripe_default_card_id';
120130

121-
return response()->json($cus);
131+
$response = $stripeCustomer->setDefaultCard($customerId, $defaultCardId);
122132

133+
if ($response->isError) {
134+
// Handle errors
135+
echo $response->message;
136+
} else {
137+
// Default card set successfully
138+
}
123139
```
140+

doc/prices.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ use Code4mk\LaraStripe\Lib\StripePrices;
99

1010
$stripePrices = new StripePrices();
1111

12-
$stripePrices->product(['name' => 'Product Name']) // Set the product details
12+
$stripePrices->product('product id') // Set the product id
1313
->amount(10.00) // Set the price amount
1414
->interval('month') // Set the billing interval (day, week, month, year)
1515
->currency('usd') // Set the currency
16-
->extra(['metadata' => ['key' => 'value']]) // Set extra properties
1716
->trial(7) // Set the trial period in days (optional)
1817
->description('Subscription Plan') // Set a description (optional)
1918
->createPrice(); // Create the subscription price

doc/product.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
## Usage
2+
3+
Here are some common operations you can perform using the `StripeProducts` library:
4+
5+
### Creating a Product
6+
7+
```php
8+
use Code4mk\LaraStripe\Lib\StripeProducts;
9+
10+
$stripeProducts = new StripeProducts();
11+
12+
$productName = 'Product Name';
13+
14+
$stripeProducts->name($productName) // Set the product name
15+
->create(); // Create the product
16+
```
17+
18+
### Retrieving a Product
19+
20+
```php
21+
use Code4mk\LaraStripe\Lib\StripeProducts;
22+
23+
$stripeProducts = new StripeProducts();
24+
25+
$productId = 'product_id_here';
26+
27+
$stripeProducts->retrieve($productId); // Retrieve the product by ID
28+
```
29+
30+
### Deleting a Product
31+
32+
```php
33+
use Code4mk\LaraStripe\Lib\StripeProducts;
34+
35+
$stripeProducts = new StripeProducts();
36+
37+
$productId = 'product_id_here';
38+
39+
$stripeProducts->delete($productId); // Delete the product by ID
40+
```
41+
42+
For more details on available methods and parameters, refer to the inline code comments and the [Stripe API documentation](https://stripe.com/docs/api/products).
43+
44+
## Error Handling
45+
46+
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.
47+
48+
```php
49+
$result = $stripeProducts->create();
50+
51+
if ($result->isError === true) {
52+
// Handle the error
53+
echo "Error: " . $result->message;
54+
}
55+
```

doc/subscription.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ $customerId = 'customer_id_here';
1313
$priceId = 'price_id_here';
1414

1515
$stripeSubscription->customer($customerId) // Set the customer ID
16-
->priceId($priceId) // Set the price (plan) ID
16+
->priceId($priceId) // Set the price ID
1717
->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)
18+
->trial(7) // Set a custom trial period in days
19+
->source('card_source_id') // Set the card source
20+
->coupon('coupon_code_here') // Apply a coupon
2221
->create(); // Create the subscription
2322
```
2423

0 commit comments

Comments
 (0)