This commit is contained in:
Benjamin Beganović 2021-03-12 15:00:33 +01:00
parent d546c4711c
commit 908678cdc4
7 changed files with 64 additions and 29 deletions

View File

@ -20,6 +20,6 @@ class BillingSubscriptionPurchaseController extends Controller
{ {
public function index(BillingSubscription $billing_subscription) public function index(BillingSubscription $billing_subscription)
{ {
return view('billing-portal.purchase'); return view('billing-portal.purchase', ['billing_subscription' => $billing_subscription]);
} }
} }

View File

@ -2,9 +2,12 @@
namespace App\Http\Livewire; namespace App\Http\Livewire;
use App\Models\BillingSubscription;
use App\Models\ClientContact; use App\Models\ClientContact;
use App\Models\Company;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Livewire\Component; use Livewire\Component;
use Symfony\Component\HttpClient\HttpClient;
class BillingPortalPurchase extends Component class BillingPortalPurchase extends Component
{ {
@ -14,15 +17,19 @@ class BillingPortalPurchase extends Component
public $password; public $password;
public $billing_subscription;
protected $rules = [
'email' => ['required', 'email'],
];
public $steps = [ public $steps = [
'passed_email' => false, 'passed_email' => false,
'existing_user' => false, 'existing_user' => false,
'fetched_payment_methods' => false, 'fetched_payment_methods' => false,
]; ];
protected $rules = [ public $methods = [];
'email' => ['required', 'email'],
];
public function authenticate() public function authenticate()
{ {
@ -41,20 +48,45 @@ class BillingPortalPurchase extends Component
if ($contact && $this->steps['existing_user']) { if ($contact && $this->steps['existing_user']) {
$attempt = Auth::guard('contact')->attempt(['email' => $this->email, 'password' => $this->password]); $attempt = Auth::guard('contact')->attempt(['email' => $this->email, 'password' => $this->password]);
if (!$attempt) { if ($attempt) {
$this->password = ''; return $this->getPaymentMethods($contact);
} else {
session()->flash('message', 'These credentials do not match our records.'); session()->flash('message', 'These credentials do not match our records.');
} }
} }
$this->steps['existing_user'] = false; $this->steps['existing_user'] = false;
$this->createBlankClient();
$this
->createBlankClient()
->getPaymentMethods();
} }
protected function createBlankClient() 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() public function render()

View File

@ -23,7 +23,7 @@ use Illuminate\Support\Str;
class ClientContactRepository extends BaseRepository class ClientContactRepository extends BaseRepository
{ {
public $is_primary; public $is_primary;
public function save(array $data, Client $client) : void public function save(array $data, Client $client) : void
{ {
if (isset($data['contacts'])) { if (isset($data['contacts'])) {
@ -37,6 +37,7 @@ class ClientContactRepository extends BaseRepository
}); });
$this->is_primary = true; $this->is_primary = true;
/* Set first record to primary - always */ /* Set first record to primary - always */
$contacts = $contacts->sortByDesc('is_primary')->map(function ($contact) { $contacts = $contacts->sortByDesc('is_primary')->map(function ($contact) {
$contact['is_primary'] = $this->is_primary; $contact['is_primary'] = $this->is_primary;

View File

@ -65,6 +65,7 @@
"predis/predis": "^1.1", "predis/predis": "^1.1",
"sentry/sentry-laravel": "^2", "sentry/sentry-laravel": "^2",
"stripe/stripe-php": "^7.50", "stripe/stripe-php": "^7.50",
"symfony/http-client": "^5.2",
"turbo124/beacon": "^1", "turbo124/beacon": "^1",
"webpatser/laravel-countries": "dev-master#75992ad", "webpatser/laravel-countries": "dev-master#75992ad",
"wildbit/swiftmailer-postmark": "^3.3" "wildbit/swiftmailer-postmark": "^3.3"

16
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "92627dd8c4b3734341ca730af796f4f1", "content-hash": "f051c9703768368f9a74e9b2c57f2b80",
"packages": [ "packages": [
{ {
"name": "authorizenet/authorizenet", "name": "authorizenet/authorizenet",
@ -7567,16 +7567,16 @@
}, },
{ {
"name": "symfony/http-client", "name": "symfony/http-client",
"version": "v5.2.3", "version": "v5.2.4",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/http-client.git", "url": "https://github.com/symfony/http-client.git",
"reference": "22cb1a7844fff206cc5186409776e78865405ea5" "reference": "c7d1f35a31ef153a302e3f80336170e1280b983d"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/http-client/zipball/22cb1a7844fff206cc5186409776e78865405ea5", "url": "https://api.github.com/repos/symfony/http-client/zipball/c7d1f35a31ef153a302e3f80336170e1280b983d",
"reference": "22cb1a7844fff206cc5186409776e78865405ea5", "reference": "c7d1f35a31ef153a302e3f80336170e1280b983d",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -7591,7 +7591,7 @@
"php-http/async-client-implementation": "*", "php-http/async-client-implementation": "*",
"php-http/client-implementation": "*", "php-http/client-implementation": "*",
"psr/http-client-implementation": "1.0", "psr/http-client-implementation": "1.0",
"symfony/http-client-implementation": "1.1" "symfony/http-client-implementation": "2.2"
}, },
"require-dev": { "require-dev": {
"amphp/amp": "^2.5", "amphp/amp": "^2.5",
@ -7633,7 +7633,7 @@
"description": "Provides powerful methods to fetch HTTP resources synchronously or asynchronously", "description": "Provides powerful methods to fetch HTTP resources synchronously or asynchronously",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"support": { "support": {
"source": "https://github.com/symfony/http-client/tree/v5.2.3" "source": "https://github.com/symfony/http-client/tree/v5.2.4"
}, },
"funding": [ "funding": [
{ {
@ -7649,7 +7649,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2021-01-27T10:15:41+00:00" "time": "2021-03-01T00:40:14+00:00"
}, },
{ {
"name": "symfony/http-client-contracts", "name": "symfony/http-client-contracts",

View File

@ -1,5 +1,5 @@
@extends('portal.ninja2020.layout.clean') @extends('portal.ninja2020.layout.clean')
@section('body') @section('body')
@livewire('billing-portal-purchase') @livewire('billing-portal-purchase', ['billing_subscription' => $billing_subscription])
@stop @stop

View File

@ -37,11 +37,12 @@
@endcomponent @endcomponent
@endif @endif
@if($authenticated) @if($this->steps['fetched_payment_methods'])
<div class="flex items-center space-x-4 mt-4 text-sm"> <div class="flex items-center space-x-4 mt-4 text-sm">
<button class="pb-2 border-b-2 border-blue-600">Credit card</button> @foreach($this->methods as $method)
<button class="pb-2 border-b-2 border-transparent hover:border-blue-600">Bank transfer</button> <button
<button class="pb-2 border-b-2 border-transparent hover:border-blue-600">PayPal</button> class="pb-2 border-b-2 border-transparent hover:border-blue-600">{{ $method['label'] }}</button>
@endforeach
</div> </div>
@endif @endif
@ -53,21 +54,21 @@
<input wire:model="email" type="email" class="input w-full"/> <input wire:model="email" type="email" class="input w-full"/>
@error('email') @error('email')
<p class="validation validation-fail block w-full" role="alert"> <p class="validation validation-fail block w-full" role="alert">
{{ $message }} {{ $message }}
</p> </p>
@enderror @enderror
</label> </label>
@if($steps['existing_user']) @if($steps['existing_user'])
<label for="password" class="block mt-2"> <label for="password" class="block mt-2">
<span class="input-label">Password</span> <span class="input-label">Password</span>
<input wire:model="password" type="password" class="input w-full"/> <input wire:model="password" type="password" class="input w-full" autofocus/>
@error('password') @error('password')
<p class="validation validation-fail block w-full" role="alert"> <p class="validation validation-fail block w-full" role="alert">
{{ $message }} {{ $message }}
</p> </p>
@enderror @enderror
</label> </label>
@endif @endif