1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

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,
'started_payment' => false,
'discount_applied' => false,
'show_loading_bar' => false,
'not_eligible' => null,
];
/**
@ -299,6 +301,7 @@ class BillingPortalPurchase extends Component
public function handleBeforePaymentEvents()
{
$this->steps['started_payment'] = true;
$this->steps['show_loading_bar'] = true;
$data = [
'client_id' => $this->contact->client->id,
@ -320,6 +323,15 @@ class BillingPortalPurchase extends Component
->fillDefaults()
->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, [
'subscription_id' => $this->subscription->id,
'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 */
public function isEligible($contact)
{
$context = [
'context' => 'is_eligible',
'subscription' => $this->subscription->hashed_id,
@ -131,7 +130,7 @@ class SubscriptionService
return $response;
}
/* Starts the process to create a trial
/* Starts the process to create a trial
- we create a recurring invoice, which is has its next_send_date as now() + trial_duration
- we then hit the client API end point to advise the trial payload
- we then return the user to either a predefined user endpoint, OR we return the user to the recurring invoice page.
@ -229,10 +228,10 @@ class SubscriptionService
$response = false;
$body = array_merge($context, [
'company_key' => $this->subscription->company->company_key,
'company_key' => $this->subscription->company->company_key,
'account_key' => $this->subscription->company->account->key,
'db' => $this->subscription->company->db,
]);
]);
$response = $this->sendLoad($this->subscription, $body);
@ -240,10 +239,10 @@ class SubscriptionService
if(is_array($response)){
$body = $response;
}
else {
$status = $response->getStatusCode();
$response_body = $response->getBody();
$body = array_merge($body, ['status' => $status, 'response_body' => $response_body]);

View File

@ -124,7 +124,7 @@
@endforeach
@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"
fill="none" viewBox="0 0 24 24">
<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>
</form>
@endif
@if($steps['not_eligible'] && !is_null($steps['not_eligible']))
<h1>{{ ctrans('texts.payment_error') }}</h1>
@endif
</div>
</div>
</div>