1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Merge pull request #9273 from beganovich/1323-subscriptions

RFF support for purchase links
This commit is contained in:
David Bomba 2024-02-08 07:46:20 +11:00 committed by GitHub
commit 0337576d89
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 81 additions and 2 deletions

View File

@ -106,6 +106,7 @@ class BillingPortalPurchase extends Component
public $steps = [ public $steps = [
'passed_email' => false, 'passed_email' => false,
'existing_user' => false, 'existing_user' => false,
'check_rff' => false,
'fetched_payment_methods' => false, 'fetched_payment_methods' => false,
'fetched_client' => false, 'fetched_client' => false,
'show_start_trial' => false, 'show_start_trial' => false,
@ -181,6 +182,12 @@ class BillingPortalPurchase extends Component
*/ */
public $campaign; public $campaign;
public ?string $contact_first_name;
public ?string $contact_last_name;
public ?string $contact_email;
public function mount() public function mount()
{ {
MultiDB::setDb($this->db); MultiDB::setDb($this->db);
@ -316,10 +323,14 @@ class BillingPortalPurchase extends Component
*/ */
protected function getPaymentMethods(ClientContact $contact): self protected function getPaymentMethods(ClientContact $contact): self
{ {
Auth::guard('contact')->loginUsingId($contact->id, true);
$this->contact = $contact; $this->contact = $contact;
if ($contact->showRff()) {
return $this->rff();
}
Auth::guard('contact')->loginUsingId($contact->id, true);
if ($this->subscription->trial_enabled) { if ($this->subscription->trial_enabled) {
$this->heading_text = ctrans('texts.plan_trial'); $this->heading_text = ctrans('texts.plan_trial');
$this->steps['show_start_trial'] = true; $this->steps['show_start_trial'] = true;
@ -340,6 +351,33 @@ class BillingPortalPurchase extends Component
return $this; return $this;
} }
protected function rff()
{
$this->contact_first_name = $this->contact->first_name;
$this->contact_last_name = $this->contact->last_name;
$this->contact_email = $this->contact->email;
$this->steps['check_rff'] = true;
return $this;
}
public function handleRff()
{
$validated = $this->validate([
'contact_first_name' => ['required'],
'contact_last_name' => ['required'],
'contact_email' => ['required', 'email'],
]);
$this->contact->first_name = $validated['contact_first_name'];
$this->contact->last_name = $validated['contact_last_name'];
$this->contact->email = $validated['contact_email'];
$this->contact->save();
return $this->getPaymentMethods($this->contact);
}
/** /**
* Middle method between selecting payment method & * Middle method between selecting payment method &
* submitting the from to the backend. * submitting the from to the backend.

View File

@ -138,6 +138,9 @@
<input type="hidden" name="action" value="payment"> <input type="hidden" name="action" value="payment">
<input type="hidden" name="company_gateway_id" value="{{ $company_gateway_id }}"/> <input type="hidden" name="company_gateway_id" value="{{ $company_gateway_id }}"/>
<input type="hidden" name="payment_method_id" value="{{ $payment_method_id }}"/> <input type="hidden" name="payment_method_id" value="{{ $payment_method_id }}"/>
<input type="hidden" name="contact_first_name" value="{{ $contact->first_name }}">
<input type="hidden" name="contact_last_name" value="{{ $contact->last_name }}">
<input type="hidden" name="contact_email" value="{{ $contact->email }}">
</form> </form>
@if($steps['started_payment'] == false) @if($steps['started_payment'] == false)
@ -174,7 +177,45 @@
{{ ctrans('texts.trial_call_to_action') }} {{ ctrans('texts.trial_call_to_action') }}
</button> </button>
</form> </form>
@elseif($steps['check_rff'])
@if($errors->any())
<div class="alert alert-failure mb-4">
@foreach($errors->all() as $error)
<p>{{ $error }}</p>
@endforeach
</div>
@endif
<form wire:submit="handleRff">
@csrf
@if(strlen($contact->first_name) === 0)
<div class="col-auto mt-3">
<label for="first_name" class="input-label">{{ ctrans('texts.first_name') }}</label>
<input id="first_name" class="input w-full" wire:model="contact_first_name" />
</div>
@endif
@if(strlen($contact->last_name) === 0)
<div class="col-auto mt-3 @if($contact->last_name) !== 0) hidden @endif">
<label for="last_name" class="input-label">{{ ctrans('texts.last_name') }}</label>
<input id="last_name" class="input w-full" wire:model="contact_last_name" />
</div>
@endif
@if(strlen($contact->email) === 0)
<div class="col-auto mt-3 @if($contact->email) !== 0) hidden @endif">
<label for="email" class="input-label">{{ ctrans('texts.email') }}</label>
<input id="email" class="input w-full" wire:model="contact_email" />
</div>
@endif
<button
type="submit"
class="button button-block bg-primary text-white mt-4">
{{ ctrans('texts.next') }}
</button>
</form>
@else @else
<form wire:submit="authenticate" class="mt-8"> <form wire:submit="authenticate" class="mt-8">
@csrf @csrf