Skip to content

Commit

Permalink
Update setting trial periods
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvints committed Oct 5, 2020
1 parent f2f54f2 commit 01496b8
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/SubscriptionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,15 @@ public function create($paymentMethod = null, array $customerOptions = [], array
*/
public function checkout(array $sessionOptions = [], array $customerOptions = [])
{
// Checkout Sessions are active for 24 hours after their creation and within that time frame the customer
// can complete the payment at any time. Stripe requires the trial end at least 48 hours in the future
// so that there is still at least a one day trial if your customer pays at the end of the 24 hours.
$minimumTrialPeriod = Carbon::now()->addHours(48);
if (! $this->skipTrial && $this->trialExpires) {
// Checkout Sessions are active for 24 hours after their creation and within that time frame the customer
// can complete the payment at any time. Stripe requires the trial end at least 48 hours in the future
// so that there is still at least a one day trial if your customer pays at the end of the 24 hours.
$minimumTrialPeriod = Carbon::now()->addHours(48);

if ($this->trialExpires && $this->trialExpires->gt($minimumTrialPeriod)) {
$trialEnd = $this->trialExpires;
$trialEnd = $this->trialExpires->gt($minimumTrialPeriod) ? $this->trialExpires : $minimumTrialPeriod;
} else {
$trialEnd = $minimumTrialPeriod;
$trialEnd = null;
}

return Checkout::create($this->owner, array_merge([
Expand All @@ -315,7 +315,7 @@ public function checkout(array $sessionOptions = [], array $customerOptions = []
'default_tax_rates' => $this->getTaxRatesForPayload(),
'subscription_data' => [
'coupon' => $this->coupon,
'trial_end' => $trialEnd->getTimestamp(),
'trial_end' => $trialEnd ? $trialEnd->getTimestamp() : null,
'metadata' => array_merge($this->metadata, ['name' => $this->name]),
],
], $sessionOptions), $customerOptions);
Expand Down

0 comments on commit 01496b8

Please sign in to comment.