Skip to content

Commit

Permalink
Merge pull request #598 from laravel/fix-invoice-taxes
Browse files Browse the repository at this point in the history
[9.0] Fix invoicing subscriptions and extend one off charges
  • Loading branch information
taylorotwell committed Dec 17, 2018
2 parents 552db2e + 8e309b2 commit dcc884a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
- Require Laravel 5.7 as minimum version ([#595](https://github.com/laravel/cashier/pull/595))
- Extract `updateCard` from `createAsStripeCustomer` method ([#588](https://github.com/laravel/cashier/pull/588))
- Remove `CASHIER_ENV` and event checks and encourage usage of `VerifyWebhookSignature` middleware ([#591](https://github.com/laravel/cashier/pull/591))
- The `invoice` method now accepts an `$options` param ([#598](https://github.com/laravel/cashier/pull/598))
- The `invoiceFor` method now accepts an `$invoiceOptions` param ([#598](https://github.com/laravel/cashier/pull/598))

### Fixed

- Fixed some DocBlocks ([#594](https://github.com/laravel/cashier/pull/594))
- Fixed a bug where the `swap` and `incrementAndInvoice` methods on the `Subscription` model would sometimes invoice other pending invoice items ([#598](https://github.com/laravel/cashier/pull/598))

## Version 2.0.4

Expand Down
19 changes: 11 additions & 8 deletions src/Billable.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ trait Billable
* @param int $amount
* @param array $options
* @return \Stripe\Charge
*
* @throws \InvalidArgumentException
*/
public function charge($amount, array $options = [])
Expand Down Expand Up @@ -109,14 +108,15 @@ public function tab($description, $amount, array $options = [])
*
* @param string $description
* @param int $amount
* @param array $options
* @param array $tabOptions
* @param array $invoiceOptions
* @return \Laravel\Cashier\Invoice|bool
*/
public function invoiceFor($description, $amount, array $options = [])
public function invoiceFor($description, $amount, array $tabOptions = [], array $invoiceOptions = [])
{
$this->tab($description, $amount, $options);
$this->tab($description, $amount, $tabOptions);

return $this->invoice();
return $this->invoice($invoiceOptions);
}

/**
Expand Down Expand Up @@ -215,13 +215,16 @@ public function subscriptions()
/**
* Invoice the billable entity outside of regular billing cycle.
*
* @param array $options
* @return \Stripe\Invoice|bool
*/
public function invoice()
public function invoice(array $options = [])
{
if ($this->stripe_id) {
$parameters = array_merge($options, ['customer' => $this->stripe_id]);

try {
return StripeInvoice::create(['customer' => $this->stripe_id], $this->getStripeKey())->pay();
return StripeInvoice::create($parameters, $this->getStripeKey())->pay();
} catch (StripeErrorInvalidRequest $e) {
return false;
}
Expand Down Expand Up @@ -587,7 +590,7 @@ public function preferredCurrency()
/**
* Get the tax percentage to apply to the subscription.
*
* @return int
* @return int|float
*/
public function taxPercentage()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function incrementAndInvoice($count = 1)
{
$this->incrementQuantity($count);

$this->user->invoice();
$this->user->invoice(['subscription' => $this->stripe_id]);

return $this;
}
Expand Down Expand Up @@ -278,7 +278,7 @@ public function swap($plan)

$subscription->save();

$this->user->invoice();
$this->user->invoice(['subscription' => $subscription->id]);

$this->fill([
'stripe_plan' => $plan,
Expand Down
2 changes: 1 addition & 1 deletion src/SubscriptionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ protected function getTrialEndForPayload()
/**
* Get the tax percentage for the Stripe payload.
*
* @return int|null
* @return int|float|null
*/
protected function getTaxPercentageForPayload()
{
Expand Down

0 comments on commit dcc884a

Please sign in to comment.