mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 21:22:58 +01:00
- Use user from $billing_subscription to create client
- Disable generating the cache for temporary state - Generate the blank invoice based on the product
This commit is contained in:
parent
eb2cfde303
commit
81f5808bf6
@ -4,12 +4,9 @@ namespace App\Http\Livewire;
|
|||||||
|
|
||||||
use App\Factory\ClientFactory;
|
use App\Factory\ClientFactory;
|
||||||
use App\Models\ClientContact;
|
use App\Models\ClientContact;
|
||||||
use App\Models\Invoice;
|
|
||||||
use App\Models\User;
|
|
||||||
use App\Repositories\ClientContactRepository;
|
use App\Repositories\ClientContactRepository;
|
||||||
use App\Repositories\ClientRepository;
|
use App\Repositories\ClientRepository;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\Cache;
|
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
|
||||||
class BillingPortalPurchase extends Component
|
class BillingPortalPurchase extends Component
|
||||||
@ -75,7 +72,7 @@ class BillingPortalPurchase extends Component
|
|||||||
protected function createBlankClient()
|
protected function createBlankClient()
|
||||||
{
|
{
|
||||||
$company = $this->billing_subscription->company;
|
$company = $this->billing_subscription->company;
|
||||||
$user = User::first(); // TODO: What should be a value of $user?
|
$user = $this->billing_subscription->user;
|
||||||
|
|
||||||
$client_repo = new ClientRepository(new ClientContactRepository());
|
$client_repo = new ClientRepository(new ClientContactRepository());
|
||||||
|
|
||||||
@ -91,7 +88,7 @@ class BillingPortalPurchase extends Component
|
|||||||
|
|
||||||
protected function getPaymentMethods(ClientContact $contact): self
|
protected function getPaymentMethods(ClientContact $contact): self
|
||||||
{
|
{
|
||||||
Cache::put($this->hash, ['email' => $this->email ?? $this->contact->email, 'url' => url()->current()]);
|
// Cache::put($this->hash, ['email' => $this->email ?? $this->contact->email, 'url' => url()->current()]);
|
||||||
|
|
||||||
$this->steps['fetched_payment_methods'] = true;
|
$this->steps['fetched_payment_methods'] = true;
|
||||||
|
|
||||||
@ -116,38 +113,23 @@ class BillingPortalPurchase extends Component
|
|||||||
|
|
||||||
public function handleBeforePaymentEvents()
|
public function handleBeforePaymentEvents()
|
||||||
{
|
{
|
||||||
$company = $this->billing_subscription->company;
|
$data = [
|
||||||
$user = User::first(); // TODO: What should be a value of $user?
|
|
||||||
|
|
||||||
$invoice = [
|
|
||||||
'client_id' => $this->contact->client->id,
|
'client_id' => $this->contact->client->id,
|
||||||
'line_items' => [[
|
'date' => now()->format('Y-m-d'),
|
||||||
'quantity' => 1,
|
'invitations' => [[
|
||||||
'cost' => 10,
|
'key' => '',
|
||||||
'product_key' => 'example',
|
'client_contact_id' => $this->contact->hashed_id,
|
||||||
'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' => '',
|
|
||||||
]],
|
]],
|
||||||
|
'user_input_promo_code' => '', // Field to input the promo code,
|
||||||
|
'quantity' => 1, // Option to increase quantity
|
||||||
];
|
];
|
||||||
|
|
||||||
// TODO: Only for testing.
|
$this->invoice = $this->billing_subscription
|
||||||
$this->invoice = Invoice::where('status_id', Invoice::STATUS_SENT)->first();
|
->service()
|
||||||
// $this->invoice = (new \App\Repositories\InvoiceRepository)->save($invoice, InvoiceFactory::create($company->id, $user->id));
|
->createInvoice($data)
|
||||||
|
->service()
|
||||||
|
->markSent()
|
||||||
|
->save();
|
||||||
|
|
||||||
$this->emit('beforePaymentEventsCompleted');
|
$this->emit('beforePaymentEventsCompleted');
|
||||||
}
|
}
|
||||||
|
@ -73,5 +73,4 @@ class BillingSubscription extends BaseModel
|
|||||||
{
|
{
|
||||||
return $this->belongsTo(Product::class);
|
return $this->belongsTo(Product::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,13 +13,14 @@ namespace App\Services\BillingSubscription;
|
|||||||
|
|
||||||
use App\DataMapper\InvoiceItem;
|
use App\DataMapper\InvoiceItem;
|
||||||
use App\Factory\InvoiceFactory;
|
use App\Factory\InvoiceFactory;
|
||||||
|
use App\Models\BillingSubscription;
|
||||||
use App\Models\ClientSubscription;
|
use App\Models\ClientSubscription;
|
||||||
use App\Models\Product;
|
use App\Models\Product;
|
||||||
use App\Repositories\InvoiceRepository;
|
use App\Repositories\InvoiceRepository;
|
||||||
|
|
||||||
class BillingSubscriptionService
|
class BillingSubscriptionService
|
||||||
{
|
{
|
||||||
|
/** @var BillingSubscription */
|
||||||
private $billing_subscription;
|
private $billing_subscription;
|
||||||
|
|
||||||
public function __construct(BillingSubscription $billing_subscription)
|
public function __construct(BillingSubscription $billing_subscription)
|
||||||
@ -27,9 +28,8 @@ class BillingSubscriptionService
|
|||||||
$this->billing_subscription = $billing_subscription;
|
$this->billing_subscription = $billing_subscription;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createInvoice($data)
|
public function createInvoice($data): ?\App\Models\Invoice
|
||||||
{
|
{
|
||||||
|
|
||||||
$invoice_repo = new InvoiceRepository();
|
$invoice_repo = new InvoiceRepository();
|
||||||
|
|
||||||
// $data = [
|
// $data = [
|
||||||
@ -38,31 +38,31 @@ class BillingSubscriptionService
|
|||||||
// 'invitations' => [
|
// 'invitations' => [
|
||||||
// 'client_contact_id' => hashed_id
|
// 'client_contact_id' => hashed_id
|
||||||
// ],
|
// ],
|
||||||
// 'line_items' => [],
|
// 'line_items' => [],
|
||||||
// ];
|
// ];
|
||||||
|
$data['line_items'] = $this->createLineItems($data['quantity']);
|
||||||
|
|
||||||
$invoice = $invoice_repo->save($data, InvoiceFactory::create($billing_subscription->company_id, $billing_subscription->user_id));
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
If trial_enabled -> return early
|
If trial_enabled -> return early
|
||||||
|
|
||||||
-- what we need to know that we don't already
|
-- what we need to know that we don't already
|
||||||
-- Has a promo code been entered, and does it match
|
-- Has a promo code been entered, and does it match
|
||||||
-- Is this a recurring subscription
|
-- Is this a recurring subscription
|
||||||
--
|
--
|
||||||
|
|
||||||
1. Is this a recurring product?
|
1. Is this a recurring product?
|
||||||
2. What is the quantity? ie is this a multi seat product ( does this mean we need this value stored in the client sub?)
|
2. What is the quantity? ie is this a multi seat product ( does this mean we need this value stored in the client sub?)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return $invoice;
|
return $invoice_repo->save($data, InvoiceFactory::create($this->billing_subscription->company_id, $this->billing_subscription->user_id));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createLineItems($quantity)
|
private function createLineItems($quantity): array
|
||||||
{
|
{
|
||||||
$line_items = [];
|
$line_items = [];
|
||||||
|
|
||||||
$product = $this->billing_subscription->product;
|
$product = $this->billing_subscription->product;
|
||||||
|
|
||||||
$item = new InvoiceItem;
|
$item = new InvoiceItem;
|
||||||
@ -88,7 +88,7 @@ class BillingSubscriptionService
|
|||||||
public function createClientSubscription($payment_hash, $recurring_invoice_id = null)
|
public function createClientSubscription($payment_hash, $recurring_invoice_id = null)
|
||||||
{
|
{
|
||||||
//create the client sub record
|
//create the client sub record
|
||||||
|
|
||||||
//?trial enabled?
|
//?trial enabled?
|
||||||
$cs = new ClientSubscription();
|
$cs = new ClientSubscription();
|
||||||
$cs->subscription_id = $this->billing_subscription->id;
|
$cs->subscription_id = $this->billing_subscription->id;
|
||||||
|
@ -31,10 +31,13 @@
|
|||||||
<div>
|
<div>
|
||||||
@yield('gateway_content')
|
@yield('gateway_content')
|
||||||
</div>
|
</div>
|
||||||
<span class="block mx-4 mb-4 text-xs inline-flex items-center">
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="text-green-600"><rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect><path d="M7 11V7a5 5 0 0 1 10 0v4"></path></svg>
|
@if(Request::isSecure())
|
||||||
<span class="ml-1">Secure 256-bit encryption</span>
|
<span class="block mx-4 mb-4 text-xs inline-flex items-center">
|
||||||
</span>
|
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="text-green-600"><rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect><path d="M7 11V7a5 5 0 0 1 10 0v4"></path></svg>
|
||||||
|
<span class="ml-1">Secure 256-bit encryption</span>
|
||||||
|
</span>
|
||||||
|
@endif
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@endsection
|
@endsection
|
||||||
|
Loading…
Reference in New Issue
Block a user