Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvints committed Aug 9, 2024
1 parent 7c928af commit 8cd1845
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 21 deletions.
1 change: 1 addition & 0 deletions src/Concerns/ManagesUsageBilling.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

namespace Laravel\Cashier\Concerns;

use Illuminate\Support\Collection;
use Stripe\Billing\MeterEvent;

Expand Down
1 change: 0 additions & 1 deletion src/SubscriptionItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Laravel\Cashier\Concerns\InteractsWithPaymentBehavior;
use Laravel\Cashier\Concerns\Prorates;
use Laravel\Cashier\Database\Factories\SubscriptionItemFactory;
use Stripe\Billing\MeterEvent;

/**
* @property \Laravel\Cashier\Subscription|null $subscription
Expand Down
24 changes: 4 additions & 20 deletions tests/Feature/UsageBasedBillingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
namespace Laravel\Cashier\Tests\Feature;

use Exception;
use Stripe\Exception\InvalidRequestException;
use InvalidArgumentException;

class UsageBasedBillingTest extends FeatureTestCase
{

/**
* @var string
*/
Expand Down Expand Up @@ -49,10 +47,9 @@ class UsageBasedBillingTest extends FeatureTestCase
*/
protected static $licensedPrice;


public static function setUpBeforeClass(): void
{
if (!getenv('STRIPE_SECRET')) {
if (! getenv('STRIPE_SECRET')) {
return;
}

Expand Down Expand Up @@ -138,31 +135,19 @@ public function test_report_usage_for_meter()
{
$user = $this->createCustomer('test_report_usage_for_meter');

$subscription = $user->newSubscription('main')
$user->newSubscription('main')
->meteredPrice(static::$meteredEventPrice)
->create('pm_card_visa');

sleep(1);
$user->reportMeterEvent(static::$meterEventName,10);

$user->reportMeterEvent(static::$meterEventName, 10);

$summary = $user->meterEventSummaries(static::$meterId)->first();

$this->assertSame($summary->aggregated_value, 10.0);
}

public function test_reporting_usage_for_legacy_metered_price_throws_exception()
{
$user = $this->createCustomer('reporting_usage_for_legacy_metered_price_throws_exception');

$subscription = $user->newSubscription('main')->meteredPrice(static::$meteredEventPrice)->create('pm_card_visa');

try {
$subscription->reportUsage();
} catch (Exception $e) {
$this->assertInstanceOf(InvalidRequestException::class, $e);
}
}

public function test_reporting_event_usage_for_subscriptions_with_multiple_prices()
{
$user = $this->createCustomer('reporting_usage_for_subscriptions_with_multiple_prices');
Expand Down Expand Up @@ -200,5 +185,4 @@ public function test_reporting_event_usage_for_subscriptions_with_multiple_price

$this->assertSame($summary->aggregated_value, 20.0);
}

}

0 comments on commit 8cd1845

Please sign in to comment.