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

        $credits = $this->config['plans'][$this->subscription->stripe_plan]['credits'];

        $appModel = app($model);

        $creditQuery = $appModel->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');

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

        $creditCollection = $creditQuery->get();

        foreach ($creditCollection as $item) {
            $creditCount =+ $item->{$credits['column']};
        }

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

        $credits = $this->config['plans'][$this->subscription->stripe_plan]['credits'];

        $appModel = app($model);

        $creditQuery = $appModel->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');

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

        $creditCollection = $creditQuery->get();

        foreach ($creditCollection as $item) {
            $creditCount =+ $item->{$credits['column']};
        }

        return $creditCount;
    }
public function creditsUsed ( $ model , $ key = 'user_id' , $ value = null ) { if ( is_null ( $ value ) ) { $ value = $ this -> user -> id ; } $ credits = $ this -> config [ 'plans' ] [ $ this -> subscription -> stripe_plan ] [ 'credits' ] ; $ appModel = app ( $ model ) ; $ creditQuery = $ appModel -> 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' ) ; $ creditQuery -> where ( 'created_at' , '>=' , $ currentPeriodStart ) -> where ( 'created_at' , '<=' , $ currentPeriodEnd ) ; } $ creditCollection = $ creditQuery -> get ( ) ; foreach ( $ creditCollection as $ item ) { $ creditCount = + $ item -> { $ credits [ 'column' ] } ; } return $ creditCount ; }
Credits used by user
@param  string $model
@return int
Credits used by user