mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Prevent oauth_user_token updates
This commit is contained in:
parent
e2dd1cf0ce
commit
52177a48f1
18
app/Http/Requests/Vendor/StoreVendorRequest.php
vendored
18
app/Http/Requests/Vendor/StoreVendorRequest.php
vendored
@ -23,26 +23,20 @@ class StoreVendorRequest extends Request
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
* @method static \Illuminate\Contracts\Auth\Authenticatable|null user()
|
||||
*/
|
||||
public function authorize() : bool
|
||||
{
|
||||
/** @var \App\User|null $user */
|
||||
$user = auth()->user();
|
||||
|
||||
return $user->can('create', Vendor::class);
|
||||
return auth()->user()->can('create', Vendor::class);
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
/** @var \App\User|null $user */
|
||||
$user = auth()->user();
|
||||
|
||||
$rules = [];
|
||||
|
||||
$rules['contacts.*.email'] = 'bail|nullable|distinct|sometimes|email';
|
||||
|
||||
if (isset($this->number)) {
|
||||
$rules['number'] = Rule::unique('vendors')->where('company_id', $user->company()->id);
|
||||
$rules['number'] = Rule::unique('vendors')->where('company_id', auth()->user()->company()->id);
|
||||
}
|
||||
|
||||
$rules['currency_id'] = 'bail|required|exists:currencies,id';
|
||||
@ -63,13 +57,11 @@ class StoreVendorRequest extends Request
|
||||
|
||||
public function prepareForValidation()
|
||||
{
|
||||
/** @var \App\User|null $user */
|
||||
$user = auth()->user();
|
||||
|
||||
$input = $this->all();
|
||||
|
||||
if (!array_key_exists('currency_id', $input) || empty($input['currency_id'])) {
|
||||
$input['currency_id'] = $user->company()->settings->currency_id;
|
||||
$input['currency_id'] = auth()->user()->company()->settings->currency_id;
|
||||
}
|
||||
|
||||
$input = $this->decodePrimaryKeys($input);
|
||||
|
@ -182,8 +182,8 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
'accepted_terms_version',
|
||||
'oauth_user_id',
|
||||
'oauth_provider_id',
|
||||
'oauth_user_token',
|
||||
'oauth_user_refresh_token',
|
||||
// 'oauth_user_token',
|
||||
// 'oauth_user_refresh_token',
|
||||
'custom_value1',
|
||||
'custom_value2',
|
||||
'custom_value3',
|
||||
|
@ -11,38 +11,42 @@
|
||||
|
||||
namespace App\Services\Subscription;
|
||||
|
||||
use App\DataMapper\InvoiceItem;
|
||||
use App\Factory\CreditFactory;
|
||||
use App\Factory\InvoiceFactory;
|
||||
use App\Factory\PaymentFactory;
|
||||
use App\Factory\RecurringInvoiceFactory;
|
||||
use App\Jobs\Mail\NinjaMailer;
|
||||
use App\Jobs\Mail\NinjaMailerJob;
|
||||
use App\Jobs\Mail\NinjaMailerObject;
|
||||
use App\Jobs\Util\SystemLogger;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Mail\RecurringInvoice\ClientContactRequestCancellationObject;
|
||||
use Carbon\Carbon;
|
||||
use App\Models\Client;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\License;
|
||||
use App\Models\Product;
|
||||
use App\Models\SystemLog;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\PaymentHash;
|
||||
use App\Models\PaymentType;
|
||||
use App\Models\Product;
|
||||
use App\Models\RecurringInvoice;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Models\Subscription;
|
||||
use App\Models\SystemLog;
|
||||
use App\Models\ClientContact;
|
||||
use App\Services\Email\Email;
|
||||
use App\Factory\CreditFactory;
|
||||
use App\Jobs\Mail\NinjaMailer;
|
||||
use App\DataMapper\InvoiceItem;
|
||||
use App\Factory\InvoiceFactory;
|
||||
use App\Factory\PaymentFactory;
|
||||
use App\Jobs\Util\SystemLogger;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Models\RecurringInvoice;
|
||||
use App\Jobs\Mail\NinjaMailerJob;
|
||||
use App\Services\Email\EmailObject;
|
||||
use App\Jobs\Mail\NinjaMailerObject;
|
||||
use App\Utils\Traits\CleanLineItems;
|
||||
use App\Repositories\CreditRepository;
|
||||
use App\Repositories\InvoiceRepository;
|
||||
use App\Repositories\PaymentRepository;
|
||||
use App\Repositories\RecurringInvoiceRepository;
|
||||
use App\Repositories\SubscriptionRepository;
|
||||
use App\Utils\Traits\CleanLineItems;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Utils\Traits\Notifications\UserNotifies;
|
||||
use App\Factory\RecurringInvoiceFactory;
|
||||
use App\Utils\Traits\SubscriptionHooker;
|
||||
use Carbon\Carbon;
|
||||
use App\Repositories\SubscriptionRepository;
|
||||
use App\Repositories\RecurringInvoiceRepository;
|
||||
use App\Utils\Traits\Notifications\UserNotifies;
|
||||
use Illuminate\Contracts\Container\BindingResolutionException;
|
||||
use App\Mail\RecurringInvoice\ClientContactRequestCancellationObject;
|
||||
|
||||
class SubscriptionService
|
||||
{
|
||||
@ -54,6 +58,8 @@ class SubscriptionService
|
||||
/** @var subscription */
|
||||
private $subscription;
|
||||
|
||||
private const WHITE_LABEL = 4316;
|
||||
|
||||
private float $credit_payments = 0;
|
||||
|
||||
public function __construct(Subscription $subscription)
|
||||
@ -75,6 +81,11 @@ class SubscriptionService
|
||||
return $this->handlePlanChange($payment_hash);
|
||||
}
|
||||
|
||||
if ($payment_hash->data->billing_context->context == 'whitelabel') {
|
||||
return $this->handleWhiteLabelPurchase($payment_hash);
|
||||
}
|
||||
|
||||
|
||||
// if we have a recurring product - then generate a recurring invoice
|
||||
if (strlen($this->subscription->recurring_product_ids) >=1) {
|
||||
if (isset($payment_hash->data->billing_context->bundle)) {
|
||||
@ -153,6 +164,45 @@ class SubscriptionService
|
||||
return $response;
|
||||
}
|
||||
|
||||
private function handleWhiteLabelPurchase(PaymentHash $payment_hash): bool
|
||||
{
|
||||
//send license to the user.
|
||||
$invoice = $payment_hash->fee_invoice;
|
||||
$license_key = Str::uuid()->toString();
|
||||
$invoice->public_notes = $license_key;
|
||||
$invoice->save();
|
||||
$invoice->service()->touchPdf();
|
||||
|
||||
$contact = $invoice->client->contacts()->whereNotNull('email')->first();
|
||||
|
||||
$license = new License;
|
||||
$license->license_key = $license_key;
|
||||
$license->email = $contact ? $contact->email : ' ';
|
||||
$license->first_name = $contact ? $contact->first_name : ' ';
|
||||
$license->last_name = $contact ? $contact->last_name : ' ';
|
||||
$license->is_claimed = 1;
|
||||
$license->transaction_reference = $payment_hash?->payment?->transaction_reference ?: ' ';
|
||||
$license->product_id = self::WHITE_LABEL;
|
||||
|
||||
$license->save();
|
||||
|
||||
$email_object = new EmailObject;
|
||||
$email_object->to = $contact->email;
|
||||
$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;
|
||||
$email_object->client_contact_id = $contact->id;
|
||||
$email_object->invitation_key = $invoice->invitations()->first()->invitation_key;
|
||||
$email_object->entity_id = $invoice->id;
|
||||
$email_object->entity_class = Invoice::class;
|
||||
$email_object->user_id = $invoice->user_id;
|
||||
|
||||
Email::dispatch($email_object, $invoice->company);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/* 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
|
||||
|
@ -5014,6 +5014,8 @@ $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.',
|
||||
|
||||
);
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user