Skip to content

Commit

Permalink
subscription trials don’t error (closes #73)
Browse files Browse the repository at this point in the history
  • Loading branch information
edalzell committed Mar 26, 2020
1 parent ccc1fd4 commit 95b8f84
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
30 changes: 15 additions & 15 deletions Charge/Traits/HasSubscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public function postSubscription(Request $request)
$customer = $this->getOrCreateCustomer($details['payment_method']);

/*
if there's a fixed billing date set the billing-cycle-anchor
if prorate, set prorate to true
if there's a fixed billing date set the billing-cycle-anchor
if prorate, set prorate to true
*/
$planId = $details['plan'];
$plan = Plan::retrieve(['id' => $planId, 'expand' => ['product']]);
Expand Down Expand Up @@ -76,7 +76,7 @@ public function postSubscription(Request $request)

$subscription = Subscription::create($subscription);

if ($subscription->latest_invoice->payment_intent->status == 'requires_action') {
if (isset($subscription->latest_invoice->payment_intent) && $subscription->latest_invoice->payment_intent->status == 'requires_action') {
return $this->subscriptionRequiresAction($subscription, $details);
}

Expand Down Expand Up @@ -143,7 +143,7 @@ public function deleteSubscription($id)
}

/**
* The {{ charge:create_subscription_form }} tag
* The {{ charge:create_subscription_form }} tag.
*
* @return string|array
*/
Expand All @@ -153,27 +153,27 @@ public function createSubscriptionForm()
}

/**
* The {{ charge:update_subscription_form }} tag
* The {{ charge:update_subscription_form }} tag.
*
* @return string|array
*/
public function updateSubscriptionForm()
{
return $this->createForm('subscription/' . $this->getParam('id'), [], 'PATCH');
return $this->createForm('subscription/'.$this->getParam('id'), [], 'PATCH');
}

/**
* The {{ charge:cancel_subscription_form }} tag
* The {{ charge:cancel_subscription_form }} tag.
*
* @return string
*/
public function cancelSubscriptionForm()
{
return $this->createForm('subscription/' . $this->getParam('id'), [], 'DELETE');
return $this->createForm('subscription/'.$this->getParam('id'), [], 'DELETE');
}

/**
* Get the plan details
* Get the plan details.
*
* @return string
*/
Expand All @@ -183,7 +183,7 @@ public function plan()
}

/**
* Get the Stripe plans
* Get the Stripe plans.
*
* @return string
*/
Expand All @@ -193,15 +193,15 @@ public function plans()
$plans = Plan::all(
[
'expand' => ['data.product'],
'limit' => $limit
'limit' => $limit,
]
)->toArray();

return $this->parseLoop($plans['data']);
}

/**
* The {{ charge:cancel_subscription_url }} tag
* The {{ charge:cancel_subscription_url }} tag.
*
* @return string
*/
Expand All @@ -211,7 +211,7 @@ public function cancelSubscriptionUrl()
}

/**
* The {{ charge:renew_subscription_url }} tag
* The {{ charge:renew_subscription_url }} tag.
*
* @return string
*/
Expand All @@ -226,7 +226,7 @@ private function makeUrl($action)

// if they want to redirect, add it as a queary param
if ($redirect = $this->getParam('redirect')) {
$url .= '?redirect=' . $redirect;
$url .= '?redirect='.$redirect;
}

return $url;
Expand All @@ -249,7 +249,7 @@ public function getSubscriptions(): array
'expiry_date' => $subscription['current_period_end'],
'plan' => $subscription['plan']['product']['name'],
'amount' => $subscription['plan']['amount'],
'auto_renew' => !$subscription['cancel_at_period_end'],
'auto_renew' => ! $subscription['cancel_at_period_end'],
'has_subscription' => true,
];
})->toArray();
Expand Down
2 changes: 1 addition & 1 deletion Charge/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Charge
version: 3.1.1
version: 3.1.2
description: Allows you to charge (one-time or subscription) your customer via Stripe
url: silentzconsulting.com/addons/charge
developer: Erin Dalzell
Expand Down

0 comments on commit 95b8f84

Please sign in to comment.