mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 21:22:58 +01:00
Proof of concept for billing page
This commit is contained in:
parent
4350816804
commit
851a31b3c0
@ -4,7 +4,7 @@ namespace App\Http\Livewire;
|
||||
|
||||
use App\Factory\ClientFactory;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Company;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\User;
|
||||
use App\Repositories\ClientContactRepository;
|
||||
use App\Repositories\ClientRepository;
|
||||
@ -43,6 +43,8 @@ class BillingPortalPurchase extends Component
|
||||
|
||||
public $methods = [];
|
||||
|
||||
public $invoice;
|
||||
|
||||
public function authenticate()
|
||||
{
|
||||
$this->validate();
|
||||
@ -72,18 +74,17 @@ class BillingPortalPurchase extends Component
|
||||
|
||||
protected function createBlankClient()
|
||||
{
|
||||
$company = Company::first();
|
||||
$user = User::first();
|
||||
$company = $this->billing_subscription->company;
|
||||
$user = User::first(); // TODO: What should be a value of $user?
|
||||
|
||||
$client_repo = new ClientRepository(new ClientContactRepository());
|
||||
$client_data = [
|
||||
|
||||
$client = $client_repo->save([
|
||||
'name' => 'Client Name',
|
||||
'contacts' => [
|
||||
['email' => $this->email],
|
||||
]
|
||||
];
|
||||
|
||||
$client = $client_repo->save($client_data, ClientFactory::create($company->id, $user->id));
|
||||
], ClientFactory::create($company->id, $user->id));
|
||||
|
||||
return $client->contacts->first();
|
||||
}
|
||||
@ -105,6 +106,52 @@ class BillingPortalPurchase extends Component
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function handleMethodSelectingEvent($company_gateway_id, $gateway_type_id)
|
||||
{
|
||||
$this->company_gateway_id = $company_gateway_id;
|
||||
$this->payment_method_id = $gateway_type_id;
|
||||
|
||||
$this->handleBeforePaymentEvents();
|
||||
}
|
||||
|
||||
public function handleBeforePaymentEvents()
|
||||
{
|
||||
$company = $this->billing_subscription->company;
|
||||
$user = User::first(); // TODO: What should be a value of $user?
|
||||
|
||||
$invoice = [
|
||||
'client_id' => $this->contact->client->id,
|
||||
'line_items' => [[
|
||||
'quantity' => 1,
|
||||
'cost' => 10,
|
||||
'product_key' => 'example',
|
||||
'notes' => 'example',
|
||||
'discount' => 0,
|
||||
'is_amount_discount' => true,
|
||||
'tax_rate1' => 0,
|
||||
'tax_rate2' => 0,
|
||||
'tax_rate3' => 0,
|
||||
'tax_name1' => '',
|
||||
'tax_name2' => '',
|
||||
'tax_name3' => '',
|
||||
'sort_id' => 0,
|
||||
'line_total' => 1,
|
||||
'custom_value1' => 'example',
|
||||
'custom_value2' => 'example',
|
||||
'custom_value3' => 'example',
|
||||
'custom_value4' => 'example',
|
||||
'type_id' => 1,
|
||||
'date' => '',
|
||||
]],
|
||||
];
|
||||
|
||||
// TODO: Only for testing.
|
||||
$this->invoice = Invoice::where('status_id', Invoice::STATUS_SENT)->first();
|
||||
// $this->invoice = (new \App\Repositories\InvoiceRepository)->save($invoice, InvoiceFactory::create($company->id, $user->id));
|
||||
|
||||
$this->emit('beforePaymentEventsCompleted');
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
if ($this->contact instanceof ClientContact) {
|
||||
|
@ -10,7 +10,8 @@
|
||||
function updateGatewayFields(companyGatewayId, paymentMethodId) {
|
||||
document.getElementById('company_gateway_id').value = companyGatewayId;
|
||||
document.getElementById('payment_method_id').value = paymentMethodId;
|
||||
document.getElementById('payment-method-form').submit();
|
||||
}
|
||||
|
||||
Livewire.on('beforePaymentEventsCompleted', () => document.getElementById('payment-method-form').submit());
|
||||
</script>
|
||||
@endpush
|
||||
|
@ -38,19 +38,27 @@
|
||||
|
||||
@if($this->steps['fetched_payment_methods'])
|
||||
<div class="flex items-center mt-4 text-sm">
|
||||
<form action="{{ route('client.payments.process', ['hash' => $hash, 'sidebar' => 'hidden']) }}" method="post"
|
||||
<form action="{{ route('client.payments.process', ['hash' => $hash, 'sidebar' => 'hidden']) }}"
|
||||
method="post"
|
||||
id="payment-method-form">
|
||||
@csrf
|
||||
|
||||
@if($invoice instanceof \App\Models\Invoice)
|
||||
<input type="hidden" name="invoices[]" value="{{ $invoice->hashed_id }}">
|
||||
<input type="hidden" name="payable_invoices[0][amount]"
|
||||
value="{{ $invoice->partial > 0 ? \App\Utils\Number::formatValue($invoice->partial, $invoice->client->currency()) : \App\Utils\Number::formatValue($invoice->balance, $invoice->client->currency()) }}">
|
||||
<input type="hidden" name="payable_invoices[0][invoice_id]"
|
||||
value="{{ $invoice->hashed_id }}">
|
||||
@endif
|
||||
|
||||
<input type="hidden" name="action" value="payment">
|
||||
<input type="hidden" name="company_gateway_id" id="company_gateway_id">
|
||||
<input type="hidden" name="payment_method_id" id="payment_method_id">
|
||||
<input type="hidden" name="company_gateway_id" value="{{ $company_gateway_id }}"/>
|
||||
<input type="hidden" name="payment_method_id" value="{{ $payment_method_id }}"/>
|
||||
</form>
|
||||
|
||||
@foreach($this->methods as $method)
|
||||
<button
|
||||
data-company-gateway-id="{{ $method['company_gateway_id'] }}"
|
||||
data-payment-method-id="{{ $method['gateway_type_id'] }}"
|
||||
onclick="updateGatewayFields(this.dataset.companyGatewayId, this.dataset.paymentMethodId);"
|
||||
wire:click="handleMethodSelectingEvent('{{ $method['company_gateway_id'] }}', '{{ $method['gateway_type_id'] }}')"
|
||||
class="p-4 border rounded mr-4 hover:border-blue-600">
|
||||
{{ $method['label'] }}
|
||||
</button>
|
||||
|
Loading…
Reference in New Issue
Block a user