1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-13 06:32:40 +01:00

Merge pull request #5316 from beganovich/v5-0104-billing-portal

V5 0104 billing portal
This commit is contained in:
Benjamin Beganović 2021-04-01 16:43:52 +02:00 committed by GitHub
commit 698647cb96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 91 additions and 78 deletions

View File

@ -61,9 +61,7 @@ class RecurringInvoiceController extends Controller
public function requestCancellation(Request $request, RecurringInvoice $recurring_invoice)
{
//todo double check the user is able to request a cancellation
//can add locale specific by chaining ->locale();
if (is_null($recurring_invoice->subscription_id) || optional($recurring_invoice->subscription)->allow_cancellation) {
$nmo = new NinjaMailerObject;
$nmo->mailable = (new NinjaMailer((new ClientContactRequestCancellationObject($recurring_invoice, auth()->user()))->build()));
$nmo->company = $recurring_invoice->company;
@ -84,4 +82,7 @@ class RecurringInvoiceController extends Controller
'invoice' => $recurring_invoice,
]);
}
return back();
}
}

View File

@ -106,6 +106,7 @@ class BillingPortalPurchase extends Component
'fetched_client' => false,
'show_start_trial' => false,
'passwordless_login_sent' => false,
'started_payment' => false,
];
/**
@ -157,7 +158,12 @@ class BillingPortalPurchase extends Component
public function mount()
{
$this->price = $this->subscription->service()->price();
$this->price = $this->subscription->price;
if (request()->query('coupon')) {
$this->coupon = request()->query('coupon');
$this->handleCoupon();
}
}
/**
@ -280,6 +286,8 @@ class BillingPortalPurchase extends Component
*/
public function handleBeforePaymentEvents()
{
$this->steps['started_payment'] = true;
$data = [
'client_id' => $this->contact->client->id,
'date' => now()->format('Y-m-d'),
@ -368,7 +376,7 @@ class BillingPortalPurchase extends Component
->first();
$mailer = new NinjaMailerObject();
$mailer->mailable = new ContactPasswordlessLogin($this->email, (string)route('client.subscription.purchase', $this->subscription->hashed_id));
$mailer->mailable = new ContactPasswordlessLogin($this->email, (string)route('client.subscription.purchase', $this->subscription->hashed_id) . '?coupon=' . $this->coupon);
$mailer->company = $this->subscription->company;
$mailer->settings = $this->subscription->company->settings;
$mailer->to_user = $contact;

View File

@ -468,4 +468,9 @@ class RecurringInvoice extends BaseModel
{
return new RecurringService($this);
}
public function subscription(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Subscription::class);
}
}

View File

@ -249,10 +249,4 @@ class SubscriptionService
{
return Product::whereIn('id', $this->transformKeys(explode(",", $this->subscription->recurring_product_ids)))->get();
}
public function price()
{
return 1;
}
}

View File

@ -3,8 +3,8 @@
@include('email.components.header', ['logo' => 'https://www.invoiceninja.com/wp-content/uploads/2015/10/logo-white-horizontal-1.png'])
@endslot
<h2>Passwordless login link requested</h2>
<p>Hey, there was a request to log in using passwordless link.</p>
<h2>Login link requested</h2>
<p>Hey, there was a request to log in using link.</p>
<a href="{{ $url }}" target="_blank" class="button">Sign in to Invoice Ninja</a>

View File

@ -5,20 +5,6 @@
alt="{{ $subscription->company->present()->name }}">
<div class="mt-6">
@if(!empty($subscription->product_ids))
<p
class="mb-4 uppercase leading-4 tracking-wide inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-primary text-white">
One-time purchase
</p>
@endif
@if(!empty($subscription->recurring_product_ids))
<p
class="mb-4 uppercase leading-4 tracking-wide inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-primary text-white">
Subscription
</p>
@endif
<h1 id="billing-page-company-logo" class="text-3xl font-bold tracking-wide">
{{ $subscription->name }}
</h1>
@ -71,7 +57,8 @@
<div class="relative flex justify-center text-sm leading-5">
<h1 class="text-2xl font-bold tracking-wide bg-gray-50 px-6 py-0">
{{ ctrans('texts.total') }}: {{ \App\Utils\Number::formatMoney($price, $subscription->company) }}
{{ ctrans('texts.total') }}
: {{ \App\Utils\Number::formatMoney($price, $subscription->company) }}
</h1>
</div>
</div>
@ -121,6 +108,7 @@
<input type="hidden" name="payment_method_id" value="{{ $payment_method_id }}"/>
</form>
@if($steps['started_payment'] == false)
@foreach($this->methods as $method)
<button
wire:click="handleMethodSelectingEvent('{{ $method['company_gateway_id'] }}', '{{ $method['gateway_type_id'] }}')"
@ -128,6 +116,17 @@
{{ $method['label'] }}
</button>
@endforeach
@endif
@if($steps['started_payment'])
<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>
@endif
</div>
@elseif($steps['show_start_trial'])
<form wire:submit.prevent="handleTrial" class="mt-8">
@ -167,12 +166,14 @@
@enderror
</label>
<button wire:loading.attr="disabled" type="button" wire:click="passwordlessLogin" class="mt-4 text-sm active:outline-none focus:outline-none">
<button wire:loading.attr="disabled" type="button" wire:click="passwordlessLogin"
class="mt-4 text-sm active:outline-none focus:outline-none">
Log in without password
</button>
@if($steps['passwordless_login_sent'])
<span class="block mt-2 text-sm text-green-600">E-mail sent. Please check your inbox!</span>
<span
class="block mt-2 text-sm text-green-600">E-mail sent. Please check your inbox!</span>
@endif
@endif

View File

@ -55,9 +55,11 @@
{{ \App\Utils\Number::formatMoney($invoice->amount, $invoice->client) }}
</div>
</div>
</dl>
</div>
</div>
@if(is_null($invoice->subscription_id) || optional($invoice->subscription)->allow_cancellation)
<div class="bg-white shadow sm:rounded-lg mb-4 mt-4">
<div class="px-4 py-5 sm:p-6">
<div class="sm:flex sm:items-start sm:justify-between">
@ -81,5 +83,7 @@
</div>
</div>
</div>
@endif
</div>
@endsection