mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-04 02:27:29 -05: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\Models\ClientContact;
 | 
			
		||||
use App\Models\Invoice;
 | 
			
		||||
use App\Models\User;
 | 
			
		||||
use App\Repositories\ClientContactRepository;
 | 
			
		||||
use App\Repositories\ClientRepository;
 | 
			
		||||
use Illuminate\Support\Facades\Auth;
 | 
			
		||||
use Illuminate\Support\Facades\Cache;
 | 
			
		||||
use Livewire\Component;
 | 
			
		||||
 | 
			
		||||
class BillingPortalPurchase extends Component
 | 
			
		||||
@ -75,7 +72,7 @@ class BillingPortalPurchase extends Component
 | 
			
		||||
    protected function createBlankClient()
 | 
			
		||||
    {
 | 
			
		||||
        $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());
 | 
			
		||||
 | 
			
		||||
@ -91,7 +88,7 @@ class BillingPortalPurchase extends Component
 | 
			
		||||
 | 
			
		||||
    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;
 | 
			
		||||
 | 
			
		||||
@ -116,38 +113,23 @@ class BillingPortalPurchase extends Component
 | 
			
		||||
 | 
			
		||||
    public function handleBeforePaymentEvents()
 | 
			
		||||
    {
 | 
			
		||||
        $company = $this->billing_subscription->company;
 | 
			
		||||
        $user = User::first(); // TODO: What should be a value of $user?
 | 
			
		||||
 | 
			
		||||
        $invoice = [
 | 
			
		||||
        $data = [
 | 
			
		||||
            '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' => '',
 | 
			
		||||
            'date' => now()->format('Y-m-d'),
 | 
			
		||||
            'invitations' => [[
 | 
			
		||||
                'key' => '',
 | 
			
		||||
                'client_contact_id' => $this->contact->hashed_id,
 | 
			
		||||
            ]],
 | 
			
		||||
            'user_input_promo_code' => '', // Field to input the promo code,
 | 
			
		||||
            'quantity' => 1, // Option to increase quantity
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        // 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->invoice = $this->billing_subscription
 | 
			
		||||
            ->service()
 | 
			
		||||
            ->createInvoice($data)
 | 
			
		||||
            ->service()
 | 
			
		||||
            ->markSent()
 | 
			
		||||
            ->save();
 | 
			
		||||
 | 
			
		||||
        $this->emit('beforePaymentEventsCompleted');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -73,5 +73,4 @@ class BillingSubscription extends BaseModel
 | 
			
		||||
    {
 | 
			
		||||
        return $this->belongsTo(Product::class);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -13,13 +13,14 @@ namespace App\Services\BillingSubscription;
 | 
			
		||||
 | 
			
		||||
use App\DataMapper\InvoiceItem;
 | 
			
		||||
use App\Factory\InvoiceFactory;
 | 
			
		||||
use App\Models\BillingSubscription;
 | 
			
		||||
use App\Models\ClientSubscription;
 | 
			
		||||
use App\Models\Product;
 | 
			
		||||
use App\Repositories\InvoiceRepository;
 | 
			
		||||
 | 
			
		||||
class BillingSubscriptionService
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    /** @var BillingSubscription */
 | 
			
		||||
    private $billing_subscription;
 | 
			
		||||
 | 
			
		||||
    public function __construct(BillingSubscription $billing_subscription)
 | 
			
		||||
@ -27,9 +28,8 @@ class BillingSubscriptionService
 | 
			
		||||
        $this->billing_subscription = $billing_subscription;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function createInvoice($data)
 | 
			
		||||
    public function createInvoice($data): ?\App\Models\Invoice
 | 
			
		||||
    {
 | 
			
		||||
       
 | 
			
		||||
        $invoice_repo = new InvoiceRepository();
 | 
			
		||||
 | 
			
		||||
        // $data = [
 | 
			
		||||
@ -40,8 +40,8 @@ class BillingSubscriptionService
 | 
			
		||||
        //                      ],
 | 
			
		||||
        //      '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
 | 
			
		||||
@ -55,11 +55,11 @@ class BillingSubscriptionService
 | 
			
		||||
            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 = [];
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -31,10 +31,13 @@
 | 
			
		||||
            <div>
 | 
			
		||||
                @yield('gateway_content')
 | 
			
		||||
            </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>
 | 
			
		||||
                <span class="ml-1">Secure 256-bit encryption</span>
 | 
			
		||||
            </span>
 | 
			
		||||
 | 
			
		||||
            @if(Request::isSecure())
 | 
			
		||||
                <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>
 | 
			
		||||
                    <span class="ml-1">Secure 256-bit encryption</span>
 | 
			
		||||
                </span>
 | 
			
		||||
            @endif
 | 
			
		||||
        </div>
 | 
			
		||||
    </div>
 | 
			
		||||
@endsection
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user