Skip to content

Commit fc41884

Browse files
committed
subscription quantity and. promo code
1 parent f8833ab commit fc41884

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

doc/subscription.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ $stripeSubscription->customer($customerId) // Set the customer ID
1616
->priceId($priceId) // Set the price ID
1717
->metaData(['key' => 'value']) // Set additional metadata (optional)
1818
->trial(7) // Set a custom trial period in days
19+
->quantity(1) // set the quantity
1920
->source('card_source_id') // Set the card source
2021
->coupon('coupon_code_here') // Apply a coupon
22+
->promo('promotion_code_here') // Apply promotion
2123
->create(); // Create the subscription
2224
```
2325

src/Lib/StripeSubscription.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ class StripeSubscription
7171

7272
private $stripe;
7373

74+
private $promoCode;
75+
76+
private $quantity;
77+
7478
public function __construct()
7579
{
7680
$this->secretKey = config('lara-stripe.secret_key');
@@ -140,6 +144,12 @@ public function trial($day)
140144
return $this;
141145
}
142146

147+
public function quantity($data = 1)
148+
{
149+
$this->quantity = $data;
150+
return $this;
151+
}
152+
143153
/**
144154
* set customer card source
145155
*
@@ -164,6 +174,18 @@ public function coupon($code)
164174
return $this;
165175
}
166176

177+
/**
178+
* Coupon apply
179+
*
180+
* @param string $code
181+
* @return $this
182+
*/
183+
public function promo($code)
184+
{
185+
$this->promoCode = $code;
186+
return $this;
187+
}
188+
167189
/**
168190
* Create & retreive all data.
169191
*
@@ -174,7 +196,7 @@ public function create()
174196
$subscriptionsData = [
175197
'customer' => $this->customer,
176198
'items' => [
177-
['price' => $this->price],
199+
['price' => $this->price, 'quantity' => $this->quantity],
178200
],
179201
];
180202

@@ -188,6 +210,11 @@ public function create()
188210
$subscriptionsData['coupon'] = $this->couponCode;
189211
}
190212

213+
// promotion code
214+
if ($this->promoCode != '') {
215+
$subscriptionsData['promotion_code'] = $this->promoCode;
216+
}
217+
191218
// default source
192219
if ($this->source != '') {
193220
$subscriptionsData['default_source'] = $this->source;

0 commit comments

Comments
 (0)