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)
{
return view('billing-portal.purchase');
return view('billing-portal.purchase', ['billing_subscription' => $billing_subscription]);
}
}

View File

@ -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()

View File

@ -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;

View File

@ -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"

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",
"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",

View File

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

View File

@ -37,11 +37,12 @@
@endcomponent
@endif
@if($authenticated)
@if($this->steps['fetched_payment_methods'])
<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>
<button class="pb-2 border-b-2 border-transparent hover:border-blue-600">Bank transfer</button>
<button class="pb-2 border-b-2 border-transparent hover:border-blue-600">PayPal</button>
@foreach($this->methods as $method)
<button
class="pb-2 border-b-2 border-transparent hover:border-blue-600">{{ $method['label'] }}</button>
@endforeach
</div>
@endif
@ -53,21 +54,21 @@
<input wire:model="email" type="email" class="input w-full"/>
@error('email')
<p class="validation validation-fail block w-full" role="alert">
{{ $message }}
</p>
<p class="validation validation-fail block w-full" role="alert">
{{ $message }}
</p>
@enderror
</label>
@if($steps['existing_user'])
<label for="password" class="block mt-2">
<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')
<p class="validation validation-fail block w-full" role="alert">
{{ $message }}
</p>
<p class="validation validation-fail block w-full" role="alert">
{{ $message }}
</p>
@enderror
</label>
@endif