From 1e72f20c3dbd784a855e91adb98052a3b2f70e88 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 16 Mar 2021 07:35:19 +1100 Subject: [PATCH] Fix for invite resend permission --- .../Requests/Payment/UpdatePaymentRequest.php | 6 ++-- .../Requests/User/ReconfirmUserRequest.php | 2 +- .../BillingSubscriptionService.php | 30 ++++++++++++++++++- app/Transformers/InvoiceTransformer.php | 19 ++++++------ 4 files changed, 43 insertions(+), 14 deletions(-) diff --git a/app/Http/Requests/Payment/UpdatePaymentRequest.php b/app/Http/Requests/Payment/UpdatePaymentRequest.php index c4b3398581a9..e5436b55bb12 100644 --- a/app/Http/Requests/Payment/UpdatePaymentRequest.php +++ b/app/Http/Requests/Payment/UpdatePaymentRequest.php @@ -68,9 +68,9 @@ class UpdatePaymentRequest extends Request unset($input['amount']); } - if (isset($input['number'])) { - unset($input['number']); - } + // if (isset($input['number'])) { + // unset($input['number']); + // } if (isset($input['invoices']) && is_array($input['invoices']) !== false) { foreach ($input['invoices'] as $key => $value) { diff --git a/app/Http/Requests/User/ReconfirmUserRequest.php b/app/Http/Requests/User/ReconfirmUserRequest.php index 2e16a5fff61d..b70082b8c21f 100644 --- a/app/Http/Requests/User/ReconfirmUserRequest.php +++ b/app/Http/Requests/User/ReconfirmUserRequest.php @@ -23,6 +23,6 @@ class ReconfirmUserRequest extends Request */ public function authorize() : bool { - return auth()->user()->id == $this->user->id; + return auth()->user()->id == $this->user->id || auth()->user()->isAdmin(); } } diff --git a/app/Services/BillingSubscription/BillingSubscriptionService.php b/app/Services/BillingSubscription/BillingSubscriptionService.php index 7d2de3a33e9a..c3abf2f2ea20 100644 --- a/app/Services/BillingSubscription/BillingSubscriptionService.php +++ b/app/Services/BillingSubscription/BillingSubscriptionService.php @@ -11,6 +11,8 @@ namespace App\Services\BillingSubscription; +use App\Models\ClientSubscription; + class BillingSubscriptionService { @@ -24,11 +26,37 @@ class BillingSubscriptionService public function createInvoice($payment_hash) { //create the invoice if necessary ie. only is a payment was actually processed + + /* + + If trial_enabled -> return early + + -- what we need to know that we don't already + -- Has a promo code been entered, and does it match + -- Is this a recurring subscription + -- + + 1. Is this a recurring product? + 2. What is the quantity? ie is this a multi seat product ( does this mean we need this value stored in the client sub?) + */ } - public function createClientSubscription($payment_hash) + private function convertInvoiceToRecurring() + { + //The first invoice is a plain invoice - the second is fired on the recurring schedule. + } + + public function createClientSubscription($payment_hash, $recurring_invoice_id = null) { //create the client sub record + + //?trial enabled? + $cs = new ClientSubscription(); + $cs->subscription_id = $this->billing_subscription->id; + $cs->company_id = $this->billing_subscription->company_id; + + // client_id + $cs->save(); } public function triggerWebhook($payment_hash) diff --git a/app/Transformers/InvoiceTransformer.php b/app/Transformers/InvoiceTransformer.php index 836c15e2c86d..605629b738af 100644 --- a/app/Transformers/InvoiceTransformer.php +++ b/app/Transformers/InvoiceTransformer.php @@ -16,6 +16,7 @@ use App\Models\Client; use App\Models\Document; use App\Models\Invoice; use App\Models\InvoiceInvitation; +use App\Models\Payment; use App\Utils\Traits\MakesHash; class InvoiceTransformer extends EntityTransformer @@ -30,7 +31,7 @@ class InvoiceTransformer extends EntityTransformer protected $availableIncludes = [ // 'invitations', 'history', - // 'payments', + 'payments', 'client', // 'documents', ]; @@ -56,15 +57,15 @@ class InvoiceTransformer extends EntityTransformer return $this->includeItem($invoice->client, $transformer, Client::class); } + + public function includePayments(Invoice $invoice) + { + $transformer = new PaymentTransformer( $this->serializer); + + return $this->includeCollection($invoice->payments, $transformer, Payment::class); + } + /* - public function includePayments(Invoice $invoice) - { - $transformer = new PaymentTransformer($this->account, $this->serializer, $invoice); - - return $this->includeCollection($invoice->payments, $transformer, ENTITY_PAYMENT); - } - - public function includeExpenses(Invoice $invoice) { $transformer = new ExpenseTransformer($this->account, $this->serializer);