mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Improve subscriptions v2 for free subscriptions
This commit is contained in:
parent
1a60f8d9d8
commit
8ee1f8eaf1
@ -587,7 +587,6 @@ class BillingPortalPurchasev2 extends Component
|
|||||||
|
|
||||||
$this->is_eligible = false;
|
$this->is_eligible = false;
|
||||||
$this->not_eligible_message = $eligibility_check['message'];
|
$this->not_eligible_message = $eligibility_check['message'];
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -601,40 +600,9 @@ class BillingPortalPurchasev2 extends Component
|
|||||||
->markPaid()
|
->markPaid()
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
if (strlen($this->subscription->recurring_product_ids) >= 1) {
|
return $this->subscription
|
||||||
|
->service()
|
||||||
$recurring_invoice = $this->subscription->service()->convertInvoiceToRecurringBundle($this->contact->client_id, $this->bundle);
|
->handleNoPaymentFlow($invoice, $this->bundle, $this->contact);
|
||||||
|
|
||||||
/* Start the recurring service */
|
|
||||||
$recurring_invoice->service()
|
|
||||||
->start()
|
|
||||||
->save();
|
|
||||||
|
|
||||||
$invoice->recurring_id = $recurring_invoice->id;
|
|
||||||
$invoice->save();
|
|
||||||
|
|
||||||
$context = [
|
|
||||||
'context' => 'recurring_purchase',
|
|
||||||
'recurring_invoice' => $recurring_invoice->hashed_id,
|
|
||||||
'invoice' => $invoice->hashed_id,
|
|
||||||
'client' => $recurring_invoice->client->hashed_id,
|
|
||||||
'subscription' => $this->subscription->hashed_id,
|
|
||||||
'contact' => auth()->guard('contact')->user()->hashed_id,
|
|
||||||
'redirect_url' => "/client/recurring_invoices/{$recurring_invoice->hashed_id}",
|
|
||||||
];
|
|
||||||
|
|
||||||
return $context;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$redirect_url = "/client/invoices/{$invoice->hashed_id}";
|
|
||||||
|
|
||||||
return $this->handleRedirect($redirect_url);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -672,43 +640,6 @@ class BillingPortalPurchasev2 extends Component
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Handle user authentication
|
|
||||||
// *
|
|
||||||
// * @return $this|bool|void
|
|
||||||
// */
|
|
||||||
// public function authenticate()
|
|
||||||
// {
|
|
||||||
// $this->validate();
|
|
||||||
|
|
||||||
// $contact = ClientContact::where('email', $this->email)
|
|
||||||
// ->where('company_id', $this->subscription->company_id)
|
|
||||||
// ->first();
|
|
||||||
|
|
||||||
// if ($contact && $this->steps['existing_user'] === false) {
|
|
||||||
// return $this->steps['existing_user'] = true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if ($contact && $this->steps['existing_user']) {
|
|
||||||
// $attempt = Auth::guard('contact')->attempt(['email' => $this->email, 'password' => $this->password, 'company_id' => $this->subscription->company_id]);
|
|
||||||
|
|
||||||
// return $attempt
|
|
||||||
// ? $this->getPaymentMethods($contact)
|
|
||||||
// : session()->flash('message', 'These credentials do not match our records.');
|
|
||||||
// }
|
|
||||||
|
|
||||||
// $this->steps['existing_user'] = false;
|
|
||||||
|
|
||||||
// $contact = $this->createBlankClient();
|
|
||||||
|
|
||||||
// if ($contact && $contact instanceof ClientContact) {
|
|
||||||
// $this->getPaymentMethods($contact);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a blank client. Used for new customers purchasing.
|
* Create a blank client. Used for new customers purchasing.
|
||||||
*
|
*
|
||||||
|
@ -1358,6 +1358,50 @@ class SubscriptionService
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle case where no payment is required
|
||||||
|
* @param Invoice $invoice The Invoice
|
||||||
|
* @param array $bundle The bundle array
|
||||||
|
* @param ClientContact $contact The Client Contact
|
||||||
|
* @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse
|
||||||
|
*/
|
||||||
|
public function handleNoPaymentFlow(Invoice $invoice, $bundle, ClientContact $contact)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (strlen($this->subscription->recurring_product_ids) >= 1) {
|
||||||
|
|
||||||
|
$recurring_invoice = $this->convertInvoiceToRecurringBundle($contact->client_id, collect($bundle)->map(function ($bund){ return (object) $bund;}));
|
||||||
|
|
||||||
|
/* Start the recurring service */
|
||||||
|
$recurring_invoice->service()
|
||||||
|
->start()
|
||||||
|
->save();
|
||||||
|
|
||||||
|
$invoice->recurring_id = $recurring_invoice->id;
|
||||||
|
$invoice->save();
|
||||||
|
|
||||||
|
$context = [
|
||||||
|
'context' => 'recurring_purchase',
|
||||||
|
'recurring_invoice' => $recurring_invoice->hashed_id,
|
||||||
|
'invoice' => $invoice->hashed_id,
|
||||||
|
'client' => $recurring_invoice->client->hashed_id,
|
||||||
|
'subscription' => $this->subscription->hashed_id,
|
||||||
|
'contact' => $contact->hashed_id,
|
||||||
|
'redirect_url' => "/client/recurring_invoices/{$recurring_invoice->hashed_id}",
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->triggerWebhook($context);
|
||||||
|
|
||||||
|
return $this->handleRedirect($context['redirect_url']);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$redirect_url = "/client/invoices/{$invoice->hashed_id}";
|
||||||
|
|
||||||
|
return $this->handleRedirect($redirect_url);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 'email' => $this->email ?? $this->contact->email,
|
* 'email' => $this->email ?? $this->contact->email,
|
||||||
* 'quantity' => $this->quantity,
|
* 'quantity' => $this->quantity,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user