mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
- Rename: $target_subscription to $target and all references
- Ability to pay for the upgrade
This commit is contained in:
parent
88a1fda199
commit
ec1d4e05c1
@ -24,14 +24,14 @@ class SubscriptionPlanSwitchController extends Controller
|
||||
*
|
||||
* @param ShowPlanSwitchRequest $request
|
||||
* @param Subscription $subscription
|
||||
* @param string $target_subscription
|
||||
* @param string $target
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function index(ShowPlanSwitchRequest $request, Subscription $subscription, Subscription $target_subscription)
|
||||
public function index(ShowPlanSwitchRequest $request, Subscription $subscription, Subscription $target)
|
||||
{
|
||||
return render('subscriptions.switch', [
|
||||
'subscription' => $subscription,
|
||||
'target_subscription' => $target_subscription,
|
||||
'target' => $target,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -12,30 +12,90 @@
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Subscription;
|
||||
use Illuminate\Support\Str;
|
||||
use Livewire\Component;
|
||||
|
||||
class SubscriptionPlanSwitch extends Component
|
||||
{
|
||||
/**
|
||||
* @var Subscription
|
||||
*/
|
||||
public $subscription;
|
||||
|
||||
public $target_subscription;
|
||||
/**
|
||||
* @var Subscription
|
||||
*/
|
||||
public $target;
|
||||
|
||||
/**
|
||||
* @var ClientContact
|
||||
*/
|
||||
public $contact;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $methods = [];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $total;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $state = [
|
||||
'payment_initialised' => false,
|
||||
'show_loading_bar' => false,
|
||||
'invoice' => null,
|
||||
'company_gateway_id' => null,
|
||||
'payment_method_id' => null,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var mixed|string
|
||||
*/
|
||||
public $hash;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->total = $this->subscription->service()->getPriceBetweenSubscriptions($this->subscription, $this->target);
|
||||
|
||||
$this->methods = $this->contact->client->service()->getPaymentMethods(100);
|
||||
|
||||
$this->total = 1;
|
||||
$this->hash = Str::uuid()->toString();
|
||||
}
|
||||
|
||||
public function handleBeforePaymentEvents()
|
||||
public function handleBeforePaymentEvents(): void
|
||||
{
|
||||
// ..
|
||||
$this->state['show_loading_bar'] = true;
|
||||
|
||||
$this->state['invoice'] = $this->subscription->service()->createChangePlanInvoice([
|
||||
'subscription' => $this->subscription,
|
||||
'target' => $this->target,
|
||||
]);
|
||||
|
||||
$this->state['payment_initialised'] = true;
|
||||
|
||||
$this->emit('beforePaymentEventsCompleted');
|
||||
}
|
||||
|
||||
/**
|
||||
* Middle method between selecting payment method &
|
||||
* submitting the from to the backend.
|
||||
*
|
||||
* @param $company_gateway_id
|
||||
* @param $gateway_type_id
|
||||
*/
|
||||
public function handleMethodSelectingEvent($company_gateway_id, $gateway_type_id)
|
||||
{
|
||||
$this->state['company_gateway_id'] = $company_gateway_id;
|
||||
$this->state['payment_method_id'] = $gateway_type_id;
|
||||
|
||||
$this->handleBeforePaymentEvents();
|
||||
}
|
||||
|
||||
public function render()
|
||||
|
@ -184,7 +184,7 @@ class SubscriptionService
|
||||
|
||||
public function createChangePlanInvoice($data)
|
||||
{
|
||||
|
||||
return Invoice::where('status_id', Invoice::STATUS_SENT)->first();
|
||||
}
|
||||
|
||||
public function createInvoice($data): ?\App\Models\Invoice
|
||||
@ -275,9 +275,9 @@ class SubscriptionService
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the single charge products for the
|
||||
* Get the single charge products for the
|
||||
* subscription
|
||||
*
|
||||
*
|
||||
* @return ?Product Collection
|
||||
*/
|
||||
public function products()
|
||||
@ -286,9 +286,9 @@ class SubscriptionService
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the recurring products for the
|
||||
* Get the recurring products for the
|
||||
* subscription
|
||||
*
|
||||
*
|
||||
* @return ?Product Collection
|
||||
*/
|
||||
public function recurring_products()
|
||||
@ -319,4 +319,17 @@ class SubscriptionService
|
||||
{
|
||||
// ..
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pro rata calculation between subscriptions.
|
||||
*
|
||||
* @param Subscription $current
|
||||
* @param Subscription $target
|
||||
*/
|
||||
public function getPriceBetweenSubscriptions(Subscription $current, Subscription $target): int
|
||||
{
|
||||
// Calculate the pro rata. Return negative value if credits needed.
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -7,24 +7,58 @@
|
||||
</div>
|
||||
|
||||
<div class="relative flex justify-center text-sm leading-5">
|
||||
<h1 class="text-2xl font-bold tracking-wide bg-gray-100 px-6 py-0">
|
||||
{{ ctrans('texts.total') }}: {{ \App\Utils\Number::formatMoney($total, $subscription->company) }}
|
||||
{{-- <small class="ml-1 line-through text-gray-500">{{ \App\Utils\Number::formatMoney($subscription->price, $subscription->company) }}</small>--}}
|
||||
</h1>
|
||||
<span class="font-bold tracking-wide bg-gray-100 px-6 py-0">Select a payment method:</span>
|
||||
{{-- <h1 class="text-2xl font-bold tracking-wide bg-gray-100 px-6 py-0">--}}
|
||||
{{-- {{ ctrans('texts.total') }}: {{ \App\Utils\Number::formatMoney($total, $subscription->company) }}--}}
|
||||
{{-- <small class="ml-1 line-through text-gray-500">{{ \App\Utils\Number::formatMoney($subscription->price, $subscription->company) }}</small>--}}
|
||||
{{-- </h1>--}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Payment methods -->
|
||||
@if($state['invoice'])
|
||||
<form action="{{ route('client.payments.process', ['hash' => $hash, 'sidebar' => 'hidden']) }}"
|
||||
method="post" id="payment-method-form">
|
||||
@csrf
|
||||
|
||||
@if($state['invoice'] instanceof \App\Models\Invoice)
|
||||
<input type="hidden" name="invoices[]" value="{{ $state['invoice']->hashed_id }}">
|
||||
<input type="hidden" name="payable_invoices[0][amount]"
|
||||
value="{{ $state['invoice']->partial > 0 ? \App\Utils\Number::formatValue($state['invoice']->partial, $state['invoice']->client->currency()) : \App\Utils\Number::formatValue($state['invoice']->balance, $state['invoice']->client->currency()) }}">
|
||||
<input type="hidden" name="payable_invoices[0][invoice_id]"
|
||||
value="{{ $state['invoice']->hashed_id }}">
|
||||
@endif
|
||||
|
||||
<input type="hidden" name="action" value="payment">
|
||||
<input type="hidden" name="company_gateway_id" value="{{ $state['company_gateway_id'] }}"/>
|
||||
<input type="hidden" name="payment_method_id" value="{{ $state['payment_method_id'] }}"/>
|
||||
</form>
|
||||
@endif
|
||||
|
||||
<!-- Payment methods -->
|
||||
<div class="mt-8 flex flex-col items-center">
|
||||
<small class="block mb-4">Select a payment method:</small>
|
||||
<div>
|
||||
@foreach($this->methods as $method)
|
||||
<button
|
||||
{{-- wire:click="handleMethodSelectingEvent('{{ $method['company_gateway_id'] }}', '{{ $method['gateway_type_id'] }}')"--}}
|
||||
class="px-3 py-2 border bg-white rounded mr-4 hover:border-blue-600">
|
||||
{{ $method['label'] }}
|
||||
</button>
|
||||
@endforeach
|
||||
|
||||
@if(!$state['payment_initialised'])
|
||||
@foreach($this->methods as $method)
|
||||
<button
|
||||
wire:click="handleMethodSelectingEvent('{{ $method['company_gateway_id'] }}', '{{ $method['gateway_type_id'] }}')"
|
||||
class="px-3 py-2 border bg-white rounded mr-4 hover:border-blue-600">
|
||||
{{ $method['label'] }}
|
||||
</button>
|
||||
@endforeach
|
||||
@endif
|
||||
|
||||
@if($state['show_loading_bar'])
|
||||
<div class="flex justify-center">
|
||||
<svg class="animate-spin h-8 w-8 text-primary" xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none" viewBox="0 0 24 24">
|
||||
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor"
|
||||
stroke-width="4"></circle>
|
||||
<path class="opacity-75" fill="currentColor"
|
||||
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
||||
</svg>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -92,7 +92,7 @@
|
||||
|
||||
<div class="flex mt-4">
|
||||
@foreach($invoice->subscription->service()->getPlans() as $subscription)
|
||||
<a href="{{ route('client.subscription.plan_switch', ['subscription' => $invoice->subscription->hashed_id, 'target_subscription' => $subscription->hashed_id]) }}" class="border rounded px-5 py-2 hover:border-gray-800 text-sm cursor-pointer">{{ $subscription->name }}</a>
|
||||
<a href="{{ route('client.subscription.plan_switch', ['subscription' => $invoice->subscription->hashed_id, 'target' => $subscription->hashed_id]) }}" class="border rounded px-5 py-2 hover:border-gray-800 text-sm cursor-pointer">{{ $subscription->name }}</a>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
|
@ -42,6 +42,12 @@
|
||||
</div>
|
||||
|
||||
<!-- Payment box -->
|
||||
@livewire('subscription-plan-switch', compact('subscription', 'target_subscription', 'contact'))
|
||||
@livewire('subscription-plan-switch', compact('subscription', 'target', 'contact'))
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('footer')
|
||||
<script>
|
||||
Livewire.on('beforePaymentEventsCompleted', () => document.getElementById('payment-method-form').submit());
|
||||
</script>
|
||||
@endpush
|
||||
|
@ -72,7 +72,7 @@ Route::group(['middleware' => ['auth:contact', 'locale', 'check_client_existence
|
||||
Route::get('documents/{document}/download', 'ClientPortal\DocumentController@download')->name('documents.download');
|
||||
Route::resource('documents', 'ClientPortal\DocumentController')->only(['index', 'show']);
|
||||
|
||||
Route::get('subscriptions/{subscription}/plan_switch/{target_subscription}', 'ClientPortal\SubscriptionPlanSwitchController@index')->name('subscription.plan_switch');
|
||||
Route::get('subscriptions/{subscription}/plan_switch/{target}', 'ClientPortal\SubscriptionPlanSwitchController@index')->name('subscription.plan_switch');
|
||||
|
||||
Route::resource('subscriptions', 'ClientPortal\SubscriptionController')->only(['index']);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user