Determine if the Stripe model is on trial.

@param  string  $subscription
@param  string|null  $plan
@return bool
322759
public function onTrial($subscription = 'default', $plan = null)
    {
        if (func_num_args() === 0 && $this->onGenericTrial()) {
            return true;
        }

        $subscription = $this->subscription($subscription);

        if (is_null($plan)) {
            return $subscription && $subscription->onTrial();
        }

        return $subscription && $subscription->onTrial() &&
               $subscription->stripe_plan === $plan;
    }
243913
public function swap($plan)
    {
        if ($this->onGracePeriod() && $this->braintree_plan === $plan) {
            return $this->resume();
        }

        if (! $this->active()) {
            return $this->owner->newSubscription($this->name, $plan)
                                ->skipTrial()->create();
        }

        $plan = BraintreeService::findPlan($plan);

        if ($this->wouldChangeBillingFrequency($plan) && $this->prorate) {
            return $this->swapAcrossFrequencies($plan);
        }

        $subscription = $this->asBraintreeSubscription();

        $response = BraintreeSubscription::update($subscription->id, [
            'planId' => $plan->id,
            'price' => number_format($plan->price * (1 + ($this->owner->taxPercentage() / 100)), 2, '.', ''),
            'neverExpires' => true,
            'numberOfBillingCycles' => null,
            'options' => [
                'prorateCharges' => $this->prorate,
            ],
        ]);

        if ($response->success) {
            $this->fill([
                'braintree_plan' => $plan->id,
                'ends_at' => null,
            ])->save();
        } else {
            throw new Exception('Braintree failed to swap plans: '.$response->message);
        }

        return $this;
    }
501654
public function subscribed($subscriber)
    {
        if ($subscriber->id && $this->subscriberIds->offsetExists($subscriber->id)) {
            return true;
        }

        return false;
    }
237656
public function withinLimit($model, $key = 'user_id', $value = null)
    {
        if (is_null($value)) {
            $value = $this->user->id;
        }

        $limit = $this->config['plans'][$this->subscription->stripe_plan]['limits'][$model];

        if (Schema::hasTable($model)) {
            $newModel = DB::table($model);
        } else {
            $newModel = app($model);
        }

        $countQuery = $newModel->where($key, $value);

        if ($this->inBillingCycle) {
            $customer = Customer::retrieve($this->user->meta->stripe_id);
            $stripeSubscription = $customer->subscriptions->retrieve($this->subscription->stripe_id);

            $currentPeriodStart = Carbon::createFromTimestamp($stripeSubscription->current_period_start)->format('Y-m-d h:i:s');
            $currentPeriodEnd = Carbon::createFromTimestamp($stripeSubscription->current_period_end)->format('Y-m-d h:i:s');

            $countQuery
                ->where('created_at', '>=', $currentPeriodStart)
                ->where('created_at', '<=', $currentPeriodEnd);
        }

        $count = $countQuery->get()->count();

        if ($count < $limit) {
            return true;
        }

        return false;
    }
439344
private function createDeleteForm(Plan $plan)
    {
        return $this->createFormBuilder()
            ->setAction($this->generateUrl('ecommerce_plan_delete', array('id' => $plan->getId())))
            ->setMethod('DELETE')
            ->getForm()
        ;
    }
853969
function is_trial_plan( $plan, $exact = false ) {
            $this->_logger->entrance();

            if ( ! $this->is_registered() ) {
                return false;
            }

            if ( ! $this->is_trial() ) {
                return false;
            }

            $trial_plan = $this->get_trial_plan();

            if ( $trial_plan->name === $plan ) {
                // Exact plan.
                return true;
            } else if ( $exact ) {
                // Required exact, but plans are different.
                return false;
            }

            $current_plan_order  = - 1;
            $required_plan_order = - 1;
            for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
                if ( $plan === $this->_plans[ $i ]->name ) {
                    $required_plan_order = $i;
                } else if ( $trial_plan->name === $this->_plans[ $i ]->name ) {
                    $current_plan_order = $i;
                }
            }

            return ( $current_plan_order > $required_plan_order );
        }
412271
public function isForSubscription(Subscription $subscription)
    {
        if ($this->hasDataProperty('subscription')) {
            return $this->getSubscriptionId() == $subscription->getId();
        }

        foreach ($this->getSubscriptionLines() as $subscriptionLine) {
            if ($subscriptionLine->getId() == $subscription->getId()) {
                return true;
            }
        }

        return false;
    }
877882
public function onPlan($plan): bool
    {
        $plan = $this->getSubscriptions()->where(['stripe_plan' => $plan])->one();

        return !is_null($plan) && $plan->valid();
    }
1027140
public function synchronise(Subscription $subscription)
    {
        try {
            $contact = [
                'update' => true,
                'purge' => false,
                'contact' => [
                    'externalId' => $subscription->getId(),
                    'properties' => [
                        'email' => $subscription->getEmail(),
                    ],
                ],
            ];

            $response = $this->post('contact', $contact);

            if ($response->getStatusCode() == '204') { //Contact added successfully status code
                $this->subscriptionManager->updateStatus($subscription, Subscription::STATUS_SYNCED);

                return true;
            } else {
                $this->subscriptionManager->updateStatus($subscription, Subscription::STATUS_FAILED);

                return false;
            }
        } catch (\Exception $e) {
            $this->subscriptionManager->updateStatus($subscription, Subscription::STATUS_FAILED);

            return true;
        }
    }
517468
public function triggerSubscriptionPaymentFailed(GatewayInterface $gateway, SubscriptionInterface $subscription, FailedPaymentInterface $failed_payment, $note = null)
    {
        $this->trigger(self::ON_SUBSCRIPTION_PAYMENT_FAILED, $gateway, $subscription, $failed_payment, $note);
    }
1309650
public function has_subscriber($subscriptions)
    {
        $enabled_components = $this->wrappedObject->enabled_components()->orderBy('order')->pluck('id')->toArray();
        $intersected = array_intersect($enabled_components, $subscriptions);

        return count($intersected) != 0;
    }
1289635
function is_paid_trial() {
            $this->_logger->entrance();

            if ( ! $this->is_trial() ) {
                return false;
            }

            return $this->has_active_valid_license() && ( $this->_site->trial_plan_id == $this->_license->plan_id );
        }
470622
public static Subscription retrieve(String subscriptionExposedId) throws StripeException {
    return retrieve(subscriptionExposedId, (Map<String, Object>) null, (RequestOptions) null);
  }
545235
public function plan($plan = null)
    {
        if ($plan === null) {
            return $this->subscription_plan;
        } else {
            $this->subscription_plan = $plan;
            return $this;
        }
    }
526785
public function subscribed($subscription = 'default', $plan = null)
    {
        $subscription = $this->subscription($subscription);

        if (is_null($subscription)) {
            return false;
        }

        if (is_null($plan)) {
            return $subscription->valid();
        }

        return $subscription->valid() &&
               $subscription->stripe_plan === $plan;
    }
554192
public function swap(string $plan)
    {
        $subscription = $this->asStripeSubscription();

        $subscription->plan = $plan;

        $subscription->prorate = $this->prorate;

        if (!is_null($this->billingCycleAnchor)) {
            $subscription->billingCycleAnchor = $this->billingCycleAnchor;
        }

        // If no specific trial end date has been set, the default behavior should be
        // to maintain the current trial state, whether that is "active" or to run
        // the swap out with the exact number of days left on this current plan.
        if ($this->onTrial()) {
            $subscription->trial_end = $this->trial_ends_at->getTimestamp();
        } else {
            $subscription->trial_end = 'now';
        }

        // Again, if no explicit quantity was set, the default behaviors should be to
        // maintain the current quantity onto the new plan. This is a sensible one
        // that should be the expected behavior for most developers with Stripe.
        if ($this->quantity) {
            $subscription->quantity = $this->quantity;
        }

        $subscription->save();

        $this->user->invoice();

        $this->stripe_plan = $plan;
        $this->ends_at = null;
        $this->save();

        return $this;
    }
1164608
protected function handleCustomerSubscriptionUpdated(array $payload)
    {
        $user = $this->getUserByStripeId($payload['data']['object']['customer']);

        if ($user) {
            $data = $payload['data']['object'];

            $user->subscriptions->filter(function (Subscription $subscription) use ($data) {
                return $subscription->stripe_id === $data['id'];
            })->each(function (Subscription $subscription) use ($data) {
                // Quantity...
                if (isset($data['quantity'])) {
                    $subscription->quantity = $data['quantity'];
                }

                // Plan...
                if (isset($data['plan']['id'])) {
                    $subscription->stripe_plan = $data['plan']['id'];
                }

                // Trial ending date...
                if (isset($data['trial_end'])) {
                    $trial_ends = Carbon::createFromTimestamp($data['trial_end']);

                    if (! $subscription->trial_ends_at || $subscription->trial_ends_at->ne($trial_ends)) {
                        $subscription->trial_ends_at = $trial_ends;
                    }
                }

                // Cancellation date...
                if (isset($data['cancel_at_period_end']) && $data['cancel_at_period_end']) {
                    $subscription->ends_at = $subscription->onTrial()
                                ? $subscription->trial_ends_at
                                : Carbon::createFromTimestamp($data['current_period_end']);
                }

                $subscription->save();
            });
        }

        return new Response('Webhook Handled', 200);
    }