����JFIF��x�x����'
| Server IP : 78.140.185.180 / Your IP : 216.73.216.170 Web Server : LiteSpeed System : Linux cpanel13.v.fozzy.com 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64 User : builderbox ( 1072) PHP Version : 7.3.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /proc/self/root/proc/self/root/home/builderbox/./public_html/common/Billing/ |
Upload File : |
<?php namespace Common\Billing;
use Carbon\Carbon;
use DB;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* Trait Billable
* @property-read Collection|Subscription[] $subscriptions
*/
trait Billable
{
public function subscribe($gateway, $gatewayId, BillingPlan $plan)
{
if ($plan->interval === 'year') {
$renewsAt = Carbon::now()->addYears($plan->interval_count);
} else if ($plan->interval === 'week') {
$renewsAt = Carbon::now()->addWeeks($plan->interval_count);
} else {
$renewsAt = Carbon::now()->addMonths($plan->interval_count);
}
$this->subscriptions()->create([
'plan_id' => $plan->id,
'ends_at' => null,
'renews_at' => $renewsAt,
'gateway' => $gateway,
'gateway_id' => $gatewayId,
]);
$this->load('subscriptions');
}
/**
* Determine if user is subscribed.
*
* @return bool
*/
public function subscribed()
{
$subscription = $this->subscriptions->first(function(Subscription $sub) {
return $sub->valid();
});
return ! is_null($subscription);
}
/**
* Check if user is subscribed to specified plan and gateway.
*/
public function subscribedTo(BillingPlan $plan, string $gateway): bool {
return ! is_null($this->subscriptions->first(function(Subscription $sub) use($plan, $gateway) {
return $sub->valid && $sub->plan_id === $plan->id && $sub->gateway_name === $gateway;
}));
}
/**
* @return HasMany
*/
public function subscriptions()
{
// always return subscriptions that are not attached to any gateway last
return $this->hasMany(Subscription::class, 'user_id')->orderBy(DB::raw('FIELD(gateway_name, "none")'), 'asc');
}
}