controller refactoring part 1

This commit is contained in:
Peter Papp
2021-07-20 08:58:20 +02:00
parent 29d1b68dd5
commit d6db2f3a7c
25 changed files with 717 additions and 546 deletions

View File

@@ -0,0 +1,44 @@
<?php
namespace Domain\Subscriptions\Traits;
use App\Users\Models\UserSettings;
use Domain\Subscriptions\Services\StripeService;
trait Subscription
{
/**
* Get tax rate id for user
*/
public function userTaxRates(): array
{
// Get tax rates
$rates = collect(
resolve(StripeService::class)->getTaxRates()
);
// Find tax rate
$user_tax_rate = $rates->first(function ($item) {
return $item['country'] === $this->settings->country && $item['active'];
});
return $user_tax_rate ? [$user_tax_rate['id']] : [];
}
/**
* Set user billing info into user settings table
*/
public function setBilling($billing): UserSettings
{
$this->settings()->update([
'address' => $billing['billing_address'],
'city' => $billing['billing_city'],
'country' => $billing['billing_country'],
'name' => $billing['billing_name'],
'phone_number' => $billing['billing_phone_number'],
'postal_code' => $billing['billing_postal_code'],
'state' => $billing['billing_state'],
]);
return $this->settings;
}
}