From 908678cdc4fd5b97ba27f097fdb1e970ddf2f873 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 12 Mar 2021 15:00:33 +0100 Subject: [PATCH] wip --- .../BillingSubscriptionPurchaseController.php | 2 +- app/Http/Livewire/BillingPortalPurchase.php | 46 ++++++++++++++++--- app/Repositories/ClientContactRepository.php | 3 +- composer.json | 1 + composer.lock | 16 +++---- .../views/billing-portal/purchase.blade.php | 2 +- .../billing-portal-purchase.blade.php | 23 +++++----- 7 files changed, 64 insertions(+), 29 deletions(-) diff --git a/app/Http/Controllers/ClientPortal/BillingSubscriptionPurchaseController.php b/app/Http/Controllers/ClientPortal/BillingSubscriptionPurchaseController.php index a6ac361d4a3c..148024659eec 100644 --- a/app/Http/Controllers/ClientPortal/BillingSubscriptionPurchaseController.php +++ b/app/Http/Controllers/ClientPortal/BillingSubscriptionPurchaseController.php @@ -20,6 +20,6 @@ class BillingSubscriptionPurchaseController extends Controller { public function index(BillingSubscription $billing_subscription) { - return view('billing-portal.purchase'); + return view('billing-portal.purchase', ['billing_subscription' => $billing_subscription]); } } diff --git a/app/Http/Livewire/BillingPortalPurchase.php b/app/Http/Livewire/BillingPortalPurchase.php index 1a37878ea0ab..ff3045288780 100644 --- a/app/Http/Livewire/BillingPortalPurchase.php +++ b/app/Http/Livewire/BillingPortalPurchase.php @@ -2,9 +2,12 @@ namespace App\Http\Livewire; +use App\Models\BillingSubscription; use App\Models\ClientContact; +use App\Models\Company; use Illuminate\Support\Facades\Auth; use Livewire\Component; +use Symfony\Component\HttpClient\HttpClient; class BillingPortalPurchase extends Component { @@ -14,15 +17,19 @@ class BillingPortalPurchase extends Component public $password; + public $billing_subscription; + + protected $rules = [ + 'email' => ['required', 'email'], + ]; + public $steps = [ 'passed_email' => false, 'existing_user' => false, 'fetched_payment_methods' => false, ]; - protected $rules = [ - 'email' => ['required', 'email'], - ]; + public $methods = []; public function authenticate() { @@ -41,20 +48,45 @@ class BillingPortalPurchase extends Component if ($contact && $this->steps['existing_user']) { $attempt = Auth::guard('contact')->attempt(['email' => $this->email, 'password' => $this->password]); - if (!$attempt) { - $this->password = ''; - + if ($attempt) { + return $this->getPaymentMethods($contact); + } else { session()->flash('message', 'These credentials do not match our records.'); } } $this->steps['existing_user'] = false; - $this->createBlankClient(); + + $this + ->createBlankClient() + ->getPaymentMethods(); } protected function createBlankClient() { + $company = Company::find($this->billing_subscription->company_id); + $http_client = HttpClient::create(); + +// $response = $http_client->request('GET', '/api/v1/contacts', [ +// 'headers' => [ +// 'X-Api-Token' => 'company-test-token', +// 'X-Requested-With' => 'XmlHttpRequest', +// ], +// ]); + +// dd($response->toArray()); + + return $this; + } + + protected function getPaymentMethods(ClientContact $contact): self + { + $this->steps['fetched_payment_methods'] = true; + + $this->methods = $contact->client->service()->getPaymentMethods(1000); + + return $this; } public function render() diff --git a/app/Repositories/ClientContactRepository.php b/app/Repositories/ClientContactRepository.php index 91b3e2ff3f8d..a6bd04d265f8 100644 --- a/app/Repositories/ClientContactRepository.php +++ b/app/Repositories/ClientContactRepository.php @@ -23,7 +23,7 @@ use Illuminate\Support\Str; class ClientContactRepository extends BaseRepository { public $is_primary; - + public function save(array $data, Client $client) : void { if (isset($data['contacts'])) { @@ -37,6 +37,7 @@ class ClientContactRepository extends BaseRepository }); $this->is_primary = true; + /* Set first record to primary - always */ $contacts = $contacts->sortByDesc('is_primary')->map(function ($contact) { $contact['is_primary'] = $this->is_primary; diff --git a/composer.json b/composer.json index 282714c21c2e..d4327c9ce569 100644 --- a/composer.json +++ b/composer.json @@ -65,6 +65,7 @@ "predis/predis": "^1.1", "sentry/sentry-laravel": "^2", "stripe/stripe-php": "^7.50", + "symfony/http-client": "^5.2", "turbo124/beacon": "^1", "webpatser/laravel-countries": "dev-master#75992ad", "wildbit/swiftmailer-postmark": "^3.3" diff --git a/composer.lock b/composer.lock index 0c24706f8acc..baa0027cb732 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "92627dd8c4b3734341ca730af796f4f1", + "content-hash": "f051c9703768368f9a74e9b2c57f2b80", "packages": [ { "name": "authorizenet/authorizenet", @@ -7567,16 +7567,16 @@ }, { "name": "symfony/http-client", - "version": "v5.2.3", + "version": "v5.2.4", "source": { "type": "git", "url": "https://github.com/symfony/http-client.git", - "reference": "22cb1a7844fff206cc5186409776e78865405ea5" + "reference": "c7d1f35a31ef153a302e3f80336170e1280b983d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-client/zipball/22cb1a7844fff206cc5186409776e78865405ea5", - "reference": "22cb1a7844fff206cc5186409776e78865405ea5", + "url": "https://api.github.com/repos/symfony/http-client/zipball/c7d1f35a31ef153a302e3f80336170e1280b983d", + "reference": "c7d1f35a31ef153a302e3f80336170e1280b983d", "shasum": "" }, "require": { @@ -7591,7 +7591,7 @@ "php-http/async-client-implementation": "*", "php-http/client-implementation": "*", "psr/http-client-implementation": "1.0", - "symfony/http-client-implementation": "1.1" + "symfony/http-client-implementation": "2.2" }, "require-dev": { "amphp/amp": "^2.5", @@ -7633,7 +7633,7 @@ "description": "Provides powerful methods to fetch HTTP resources synchronously or asynchronously", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/http-client/tree/v5.2.3" + "source": "https://github.com/symfony/http-client/tree/v5.2.4" }, "funding": [ { @@ -7649,7 +7649,7 @@ "type": "tidelift" } ], - "time": "2021-01-27T10:15:41+00:00" + "time": "2021-03-01T00:40:14+00:00" }, { "name": "symfony/http-client-contracts", diff --git a/resources/views/billing-portal/purchase.blade.php b/resources/views/billing-portal/purchase.blade.php index 118bd57bf022..d79ee245e94a 100644 --- a/resources/views/billing-portal/purchase.blade.php +++ b/resources/views/billing-portal/purchase.blade.php @@ -1,5 +1,5 @@ @extends('portal.ninja2020.layout.clean') @section('body') - @livewire('billing-portal-purchase') + @livewire('billing-portal-purchase', ['billing_subscription' => $billing_subscription]) @stop diff --git a/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php b/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php index 67c9415bb6be..aa87983ad772 100644 --- a/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php +++ b/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php @@ -37,11 +37,12 @@ @endcomponent @endif - @if($authenticated) + @if($this->steps['fetched_payment_methods'])
- - - + @foreach($this->methods as $method) + + @endforeach
@endif @@ -53,21 +54,21 @@ @error('email') - + @enderror @if($steps['existing_user']) @endif