Skip to content

Commit

Permalink
Fix validation payment intent (#959)
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvints authored Jun 12, 2020
1 parent eec60a9 commit 71f941e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ public function swap($plans, $options = [])

$this->unsetRelation('items');

if ($stripeSubscription->latest_invoice->payment_intent) {
if ($this->hasIncompletePayment()) {
(new Payment(
$stripeSubscription->latest_invoice->payment_intent
))->validate();
Expand Down
2 changes: 1 addition & 1 deletion src/SubscriptionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public function create($paymentMethod = null, array $customerOptions = [], array
]);
}

if ($subscription->incomplete()) {
if ($subscription->hasIncompletePayment()) {
(new Payment(
$stripeSubscription->latest_invoice->payment_intent
))->validate();
Expand Down
21 changes: 20 additions & 1 deletion tests/Feature/SubscriptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,6 @@ public function test_creating_subscription_with_explicit_trial()
$this->assertEquals(Carbon::tomorrow()->hour(3)->minute(15), $subscription->trial_ends_at);
}

/** @group Prorate */
public function test_subscription_changes_can_be_prorated()
{
$user = $this->createCustomer('subscription_changes_can_be_prorated');
Expand Down Expand Up @@ -505,6 +504,26 @@ public function test_subscription_changes_can_be_prorated()
$this->assertEquals(0, $user->upcomingInvoice()->rawTotal());
}

public function test_no_prorate_on_subscription_create()
{
$user = $this->createCustomer('no_prorate_on_subscription_create');

$subscription = $user->newSubscription('main', static::$planId)->noProrate()->create('pm_card_visa', [], [
'collection_method' => 'send_invoice',
'days_until_due' => 30,
'backdate_start_date' => Carbon::now()->addDays(5)->subYear()->startOfDay()->unix(),
'billing_cycle_anchor' => Carbon::now()->addDays(5)->startOfDay()->unix(),
]);

$this->assertEquals(static::$planId, $subscription->stripe_plan);
$this->assertTrue($subscription->active());

$subscription = $subscription->swap(self::$otherPlanId);

$this->assertEquals(static::$otherPlanId, $subscription->stripe_plan);
$this->assertTrue($subscription->active());
}

public function test_trials_can_be_extended()
{
$user = $this->createCustomer('trials_can_be_extended');
Expand Down

0 comments on commit 71f941e

Please sign in to comment.