Check if payment is eligible to process

This commit is contained in:
Benjamin Beganović 2021-04-07 13:26:50 +02:00
parent b351edebe1
commit 43e6ba2ec6
3 changed files with 22 additions and 7 deletions

View File

@ -109,6 +109,8 @@ class BillingPortalPurchase extends Component
'passwordless_login_sent' => false, 'passwordless_login_sent' => false,
'started_payment' => false, 'started_payment' => false,
'discount_applied' => false, 'discount_applied' => false,
'show_loading_bar' => false,
'not_eligible' => null,
]; ];
/** /**
@ -299,6 +301,7 @@ class BillingPortalPurchase extends Component
public function handleBeforePaymentEvents() public function handleBeforePaymentEvents()
{ {
$this->steps['started_payment'] = true; $this->steps['started_payment'] = true;
$this->steps['show_loading_bar'] = true;
$data = [ $data = [
'client_id' => $this->contact->client->id, 'client_id' => $this->contact->client->id,
@ -320,6 +323,15 @@ class BillingPortalPurchase extends Component
->fillDefaults() ->fillDefaults()
->save(); ->save();
$is_eligible = $this->subscription->service()->isEligible($this->contact);
if (is_array($is_eligible)) {
$this->steps['not_eligible'] = true;
$this->steps['show_loading_bar'] = false;
return;
}
Cache::put($this->hash, [ Cache::put($this->hash, [
'subscription_id' => $this->subscription->id, 'subscription_id' => $this->subscription->id,
'email' => $this->email ?? $this->contact->email, 'email' => $this->email ?? $this->contact->email,

View File

@ -118,7 +118,6 @@ class SubscriptionService
/* Hits the client endpoint to determine whether the user is able to access this subscription */ /* Hits the client endpoint to determine whether the user is able to access this subscription */
public function isEligible($contact) public function isEligible($contact)
{ {
$context = [ $context = [
'context' => 'is_eligible', 'context' => 'is_eligible',
'subscription' => $this->subscription->hashed_id, 'subscription' => $this->subscription->hashed_id,

View File

@ -124,7 +124,7 @@
@endforeach @endforeach
@endif @endif
@if($steps['started_payment']) @if($steps['started_payment'] && $steps['show_loading_bar'])
<svg class="animate-spin h-8 w-8 text-primary" xmlns="http://www.w3.org/2000/svg" <svg class="animate-spin h-8 w-8 text-primary" xmlns="http://www.w3.org/2000/svg"
fill="none" viewBox="0 0 24 24"> fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor"
@ -209,6 +209,10 @@
<button class="button button-primary bg-primary">Apply</button> <button class="button button-primary bg-primary">Apply</button>
</form> </form>
@endif @endif
@if($steps['not_eligible'] && !is_null($steps['not_eligible']))
<h1>{{ ctrans('texts.payment_error') }}</h1>
@endif
</div> </div>
</div> </div>
</div> </div>