Add RFF functionality to BillingPortalPurchase class

This commit is contained in:
Benjamin Beganović 2024-02-07 17:30:52 +01:00
parent e2eb53ed30
commit ecefa336d2

View File

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