From ceb4708b5d91de4da0ec792a8b49610673c3ec79 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 16 Feb 2024 18:33:45 +1100 Subject: [PATCH] White label license server --- app/Models/License.php | 25 +++++++++++++++++-- .../Subscription/SubscriptionService.php | 3 ++- lang/en/texts.php | 2 +- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/app/Models/License.php b/app/Models/License.php index d2af140651e3..d7af06bb61e9 100644 --- a/app/Models/License.php +++ b/app/Models/License.php @@ -17,7 +17,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; * App\Models\License * * @property int $id - * @property int|null $created_at + * @property \Carbon\Carbon $created_at * @property int|null $updated_at * @property int|null $deleted_at * @property string|null $first_name @@ -28,6 +28,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @property string|null $transaction_reference * @property int|null $product_id * @property int|null $recurring_invoice_id + * @property-read \App\Models\RecurringInvoice $recurring_invoice * @method static \Illuminate\Database\Eloquent\Builder|StaticModel company() * @method static \Illuminate\Database\Eloquent\Builder|StaticModel exclude($columns) * @method static \Illuminate\Database\Eloquent\Builder|License newModelQuery() @@ -53,4 +54,24 @@ use Illuminate\Database\Eloquent\SoftDeletes; class License extends StaticModel { use SoftDeletes; -} + + protected $casts = [ + 'created_at' => 'date', + ]; + + public function expiry(): string + { + return $this->created_at->addYear()->format('Y-m-d'); + } + + public function recurring_invoice() + { + return $this->belongsTo(RecurringInvoice::class); + } + + public function url() + { + $contact = $this->recurring_invoice->client->contacts()->where('email', $this->email)->first(); + + } +} \ No newline at end of file diff --git a/app/Services/Subscription/SubscriptionService.php b/app/Services/Subscription/SubscriptionService.php index 3d9d21c1b3a5..cdfc7b430b6f 100644 --- a/app/Services/Subscription/SubscriptionService.php +++ b/app/Services/Subscription/SubscriptionService.php @@ -47,6 +47,7 @@ use App\Utils\Traits\SubscriptionHooker; use Carbon\Carbon; use Illuminate\Contracts\Container\BindingResolutionException; use Illuminate\Support\Str; +use Illuminate\Mail\Mailables\Address; class SubscriptionService { @@ -208,7 +209,7 @@ class SubscriptionService $invitation = $invoice->invitations()->first(); $email_object = new EmailObject(); - $email_object->to = [$contact->email]; + $email_object->to = [new Address($contact->email, $contact->present()->name())]; $email_object->subject = ctrans('texts.white_label_link') . " " .ctrans('texts.payment_subject'); $email_object->body = ctrans('texts.white_label_body', ['license_key' => $license_key]); $email_object->client_id = $invoice->client_id; diff --git a/lang/en/texts.php b/lang/en/texts.php index 3e995d821340..8b6027093966 100644 --- a/lang/en/texts.php +++ b/lang/en/texts.php @@ -4925,7 +4925,7 @@ $lang = array( 'no_assigned_tasks' => 'No billable tasks for this project', 'authorization_failure' => 'Insufficient permissions to perform this action', 'authorization_sms_failure' => 'Please verify your account to send emails.', - 'white_label_body' => 'Thank you for purchasing a white label license.

Your license key is:

:license_key', + 'white_label_body' => 'Thank you for purchasing a white label license.

Your license key is:

:license_key

You can manage your license here: https://invoiceninja.invoicing.co/client/login', 'payment_type_Klarna' => 'Klarna', 'payment_type_Interac E Transfer' => 'Interac E Transfer', 'xinvoice_payable' => 'Payable within :payeddue days net until :paydate',