Skip to content

Commit

Permalink
subscription quantity and. promo code
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafa6765 committed Oct 19, 2023
1 parent f8833ab commit fc41884
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions doc/subscription.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ $stripeSubscription->customer($customerId) // Set the customer ID
->priceId($priceId) // Set the price ID
->metaData(['key' => 'value']) // Set additional metadata (optional)
->trial(7) // Set a custom trial period in days
->quantity(1) // set the quantity
->source('card_source_id') // Set the card source
->coupon('coupon_code_here') // Apply a coupon
->promo('promotion_code_here') // Apply promotion
->create(); // Create the subscription
```

Expand Down
29 changes: 28 additions & 1 deletion src/Lib/StripeSubscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ class StripeSubscription

private $stripe;

private $promoCode;

private $quantity;

public function __construct()
{
$this->secretKey = config('lara-stripe.secret_key');
Expand Down Expand Up @@ -140,6 +144,12 @@ public function trial($day)
return $this;
}

public function quantity($data = 1)
{
$this->quantity = $data;
return $this;
}

/**
* set customer card source
*
Expand All @@ -164,6 +174,18 @@ public function coupon($code)
return $this;
}

/**
* Coupon apply
*
* @param string $code
* @return $this
*/
public function promo($code)
{
$this->promoCode = $code;
return $this;
}

/**
* Create & retreive all data.
*
Expand All @@ -174,7 +196,7 @@ public function create()
$subscriptionsData = [
'customer' => $this->customer,
'items' => [
['price' => $this->price],
['price' => $this->price, 'quantity' => $this->quantity],
],
];

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

// promotion code
if ($this->promoCode != '') {
$subscriptionsData['promotion_code'] = $this->promoCode;
}

// default source
if ($this->source != '') {
$subscriptionsData['default_source'] = $this->source;
Expand Down

0 comments on commit fc41884

Please sign in to comment.