Skip to content
This repository has been archived by the owner on Feb 2, 2022. It is now read-only.

Commit

Permalink
Release v1.7.0 (#113)
Browse files Browse the repository at this point in the history
* Fix case of traits (#112)

* Add downloadInvoice method

* VAT percentage float

* Keep item vat percentage on page

* Lazy load builder in skipTrial method

* Fix #117 temporary_mollie_payment_id

* Drop temp_ prefix

* Added SubscriptionResumed event (#116)

* Prepare release v1.7.0
  • Loading branch information
sandervanhooft authored Nov 28, 2019
1 parent 59f639d commit a3526a2
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 11 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,9 @@ A new subscription was started.
#### `SubscriptionCancelled` event
The subscription was cancelled.

#### `SubscriptionResumed` event
The subscription was resumed.

#### `SubscriptionPlanSwapped` event
The subscription plan was swapped.

Expand Down
2 changes: 1 addition & 1 deletion resources/views/receipt.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<td style="padding-bottom:16px;padding-left:20px;text-align:right;vertical-align:top;white-space:nowrap" align="right" valign="top">
{{ Laravel\Cashier\Cashier::formatAmount($item->getSubtotal()) }}
</td>
<td style="padding-bottom:16px;padding-left:16px;text-align:right;color:#a0aec0;vertical-align:top;white-space:nowrap" align="right" valign="top">
<td style="padding-bottom:16px;padding-left:16px;padding-right:16px;text-align:right;color:#a0aec0;vertical-align:top;white-space:nowrap" align="right" valign="top">
{{ $item->getTaxPercentage() }}%
</td>
</tr>
Expand Down
17 changes: 17 additions & 0 deletions src/Billable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Laravel\Cashier\Credit\Credit;
use Laravel\Cashier\Events\MandateClearedFromBillable;
use Laravel\Cashier\Exceptions\InvalidMandateException;
use Laravel\Cashier\Order\Invoice;
use Laravel\Cashier\Order\Order;
use Laravel\Cashier\Order\OrderItem;
use Laravel\Cashier\Plan\Contracts\PlanRepository;
Expand Down Expand Up @@ -374,6 +375,22 @@ public function invoices()
return $this->orders->invoices();
}

/**
* Create an invoice download response.
*
* @param $orderId
* @param null|array $data
* @param string $view
* @return \Symfony\Component\HttpFoundation\Response
*/
public function downloadInvoice($orderId, $data = [], $view = Invoice::DEFAULT_VIEW)
{
/** @var Order $order */
$order = $this->orders()->where('id', $orderId)->firstOrFail();

return $order->invoice()->download($data, $view);
}

/**
* @return null|string
*/
Expand Down
2 changes: 1 addition & 1 deletion src/CashierServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class CashierServiceProvider extends ServiceProvider
{
const PACKAGE_VERSION = '1.6.0';
const PACKAGE_VERSION = '1.7.0';

/**
* Bootstrap the application services.
Expand Down
21 changes: 21 additions & 0 deletions src/Events/SubscriptionResumed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Laravel\Cashier\Events;

use Illuminate\Queue\SerializesModels;
use Laravel\Cashier\Subscription;

class SubscriptionResumed
{
use SerializesModels;

/**
* @var \Laravel\Cashier\Subscription
*/
public $subscription;

public function __construct(Subscription $subscription)
{
$this->subscription = $subscription;
}
}
3 changes: 1 addition & 2 deletions src/FirstPayment/Actions/StartSubscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ public function trialDays(int $trialDays)
*
* @param Carbon $trialUntil
* @return $this
* @throws \Throwable|\Laravel\Cashier\Exceptions\PlanNotFoundException
*/
public function trialUntil(Carbon $trialUntil)
{
Expand All @@ -228,7 +227,7 @@ public function skipTrial()
{
$this->skipTrial = true;
$this->trialUntil = null;
$this->builder->skipTrial();
$this->builder()->skipTrial();
$this->subtotal = $this->plan->amount();

return $this;
Expand Down
3 changes: 1 addition & 2 deletions src/Http/Controllers/WebhookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ protected function getOrder(Payment $payment)

if(!$order) {
if(isset($payment->metadata, $payment->metadata->temporary_mollie_payment_id)) {
$uuid = 'temp_' . $payment->metadata->temporary_payment_id;
$order = Order::findByPaymentId($uuid);
$order = Order::findByPaymentId($payment->metadata->temporary_mollie_payment_id);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Order/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public function taxDetails()
});

return [
'tax_percentage' => $percentage,
'tax_percentage' => (float) $percentage,
'raw_over_subtotal' => $raw_over_subtotal,
'over_subtotal' => $this->formatAmount(money($raw_over_subtotal, $this->currency)),
'raw_total' => $raw_total,
Expand Down
2 changes: 1 addition & 1 deletion src/Order/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
class Order extends Model
{
use hasOwner;
use HasOwner;
use ConvertsToMoney;

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Order/OrderItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class OrderItem extends Model implements InvoicableItem
{
use hasOwner;
use HasOwner;
use FormatsAmount;
use ConvertsToMoney;

Expand Down Expand Up @@ -257,7 +257,7 @@ public function getSubtotal()
*/
public function getTaxPercentage()
{
return $this->tax_percentage;
return (float) $this->tax_percentage;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Event;
use Laravel\Cashier\Events\SubscriptionResumed;
use Laravel\Cashier\Order\Contracts\InteractsWithOrderItems;
use Laravel\Cashier\Order\Contracts\PreprocessesOrderItems;
use Laravel\Cashier\Coupon\AppliedCoupon;
Expand Down Expand Up @@ -44,7 +45,7 @@
*/
class Subscription extends Model implements InteractsWithOrderItems, PreprocessesOrderItems, AcceptsCoupons
{
use hasOwner;
use HasOwner;

/**
* The attributes that are not mass assignable.
Expand Down Expand Up @@ -321,6 +322,8 @@ public function resume()
'scheduled_order_item_id' => $item->id,
])->save();

Event::dispatch(new SubscriptionResumed($this));

return $this;
});
}
Expand Down
15 changes: 15 additions & 0 deletions tests/ManageSubscriptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Carbon\Carbon;
use Illuminate\Support\Facades\Event;
use Laravel\Cashier\Cashier;
use Laravel\Cashier\Events\SubscriptionResumed;
use Laravel\Cashier\Events\SubscriptionStarted;
use Laravel\Cashier\Events\SubscriptionQuantityUpdated;
use Laravel\Cashier\Order\OrderItem;
Expand Down Expand Up @@ -147,9 +148,16 @@ public function canCreateDirectDebitSubscriptionForMandatedCustomer()
$subscription->fill(['ends_at' => $oldGracePeriod])->save();

// Resume Subscription
Event::fake();

$old_subscription = $subscription->fresh();
$subscription = $subscription->resume()->fresh();

Event::assertDispatched(SubscriptionResumed::class, function (SubscriptionResumed $e) use ($subscription) {
$this->assertTrue($e->subscription->is($subscription));
return true;
});

$this->assertTrue($subscription->active());
$this->assertFalse($subscription->cancelled());
$this->assertFalse($subscription->onGracePeriod());
Expand Down Expand Up @@ -238,8 +246,15 @@ public function testCreatingSubscriptionWithTrial()
$this->assertEquals(0, OrderItem::count());

// Resume Subscription
Event::fake();

$subscription->resume();

Event::assertDispatched(SubscriptionResumed::class, function (SubscriptionResumed $e) use ($subscription) {
$this->assertTrue($e->subscription->is($subscription));
return true;
});

$this->assertTrue($subscription->active());
$this->assertFalse($subscription->onGracePeriod());
$this->assertTrue($subscription->onTrial());
Expand Down
10 changes: 10 additions & 0 deletions tests/SubscriptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Laravel\Cashier\Tests;

use Carbon\Carbon;
use Illuminate\Support\Facades\Event;
use Laravel\Cashier\Events\SubscriptionResumed;
use Laravel\Cashier\Order\OrderItem;
use Laravel\Cashier\Subscription;
use Laravel\Cashier\Tests\Fixtures\User;
Expand Down Expand Up @@ -74,7 +76,11 @@ public function cannotResumeIfNotCancelled()

$this->assertFalse($subscription->cancelled());

Event::fake();

$subscription->resume();

Event::assertNotDispatched(SubscriptionResumed::class);
}

/** @test */
Expand All @@ -89,7 +95,11 @@ public function cannotResumeIfNotOnGracePeriod()
$this->assertTrue($subscription->cancelled());
$this->assertFalse($subscription->onGracePeriod());

Event::fake();

$subscription->resume();

Event::assertNotDispatched(SubscriptionResumed::class);
}

/** @test */
Expand Down

0 comments on commit a3526a2

Please sign in to comment.