mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-03 20:18:33 -05:00 
			
		
		
		
	Merge pull request #3978 from turbo124/v2
Changing error structure, regression fixes for shop/client route
This commit is contained in:
		
						commit
						9b29460630
					
				@ -134,8 +134,6 @@ class Handler extends ExceptionHandler
 | 
			
		||||
        return parent::render($request, $exception);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    protected function unauthenticated($request, AuthenticationException $exception)
 | 
			
		||||
    {
 | 
			
		||||
        if ($request->expectsJson()) {
 | 
			
		||||
 | 
			
		||||
@ -245,8 +245,8 @@ class LoginController extends BaseController
 | 
			
		||||
        $company_token = CompanyToken::whereRaw("BINARY `token`= ?", [$request->header('X-API-TOKEN')])->first();
 | 
			
		||||
 | 
			
		||||
        $cu = CompanyUser::query()
 | 
			
		||||
                          ->where('user_id', $company_token->user_id)
 | 
			
		||||
                          ->where('company_id', $company_token->company_id);
 | 
			
		||||
                          ->where('user_id', $company_token->user_id);
 | 
			
		||||
                          //->where('company_id', $company_token->company_id);
 | 
			
		||||
 | 
			
		||||
        //$ct = CompanyUser::whereUserId(auth()->user()->id);
 | 
			
		||||
        return $this->refreshResponse($cu);
 | 
			
		||||
 | 
			
		||||
@ -93,7 +93,7 @@ class LicenseController extends BaseController
 | 
			
		||||
            if ($data == Account::RESULT_FAILURE) {
 | 
			
		||||
                $error = [
 | 
			
		||||
                    'message' => trans('texts.invalid_white_label_license'),
 | 
			
		||||
                    'errors' => []
 | 
			
		||||
                    'errors' => new \stdClass
 | 
			
		||||
                ];
 | 
			
		||||
 | 
			
		||||
                return response()->json($error, 400);
 | 
			
		||||
@ -103,7 +103,7 @@ class LicenseController extends BaseController
 | 
			
		||||
                if ($date < date_create()) {
 | 
			
		||||
                    $error = [
 | 
			
		||||
                        'message' => trans('texts.invalid_white_label_license'),
 | 
			
		||||
                        'errors' => []
 | 
			
		||||
                        'errors' => new \stdClass
 | 
			
		||||
                    ];
 | 
			
		||||
 | 
			
		||||
                    return response()->json($error, 400);
 | 
			
		||||
@ -118,7 +118,7 @@ class LicenseController extends BaseController
 | 
			
		||||
 | 
			
		||||
                    $error = [
 | 
			
		||||
                        'message' => trans('texts.bought_white_label'),
 | 
			
		||||
                        'errors' => []
 | 
			
		||||
                        'errors' => new \stdClass
 | 
			
		||||
                    ];
 | 
			
		||||
 | 
			
		||||
                    return response()->json($error, 200);
 | 
			
		||||
@ -126,7 +126,7 @@ class LicenseController extends BaseController
 | 
			
		||||
            } else {
 | 
			
		||||
                $error = [
 | 
			
		||||
                        'message' => trans('texts.white_label_license_error'),
 | 
			
		||||
                        'errors' => []
 | 
			
		||||
                        'errors' => new \stdClass
 | 
			
		||||
                    ];
 | 
			
		||||
 | 
			
		||||
                return response()->json($error, 400);
 | 
			
		||||
@ -135,7 +135,7 @@ class LicenseController extends BaseController
 | 
			
		||||
 | 
			
		||||
        $error = [
 | 
			
		||||
            'message' => "Invalid license, or invalid environment ".config('ninja.environment'),
 | 
			
		||||
            'errors' => []
 | 
			
		||||
            'errors' => new \stdClass
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        return response()->json($error, 400);
 | 
			
		||||
 | 
			
		||||
@ -57,7 +57,7 @@ class ClientController extends BaseController
 | 
			
		||||
        $company = Company::where('company_key', $request->header('X-API-COMPANY-KEY'))->first();
 | 
			
		||||
 | 
			
		||||
        if(!$company->enable_shop_api)
 | 
			
		||||
            return response()->json(['message' => 'Shop is disabled', 'errors' => []],403);
 | 
			
		||||
            return response()->json(['message' => 'Shop is disabled', 'errors' => new \stdClass],403);
 | 
			
		||||
 | 
			
		||||
        $contact = ClientContact::with('client')
 | 
			
		||||
                            ->where('company_id', $company->id)
 | 
			
		||||
@ -72,7 +72,7 @@ class ClientController extends BaseController
 | 
			
		||||
        $company = Company::where('company_key', $request->header('X-API-COMPANY-KEY'))->first();
 | 
			
		||||
 | 
			
		||||
        if(!$company->enable_shop_api)
 | 
			
		||||
            return response()->json(['message' => 'Shop is disabled', 'errors' => []],403);
 | 
			
		||||
            return response()->json(['message' => 'Shop is disabled', 'errors' => new \stdClass],403);
 | 
			
		||||
        
 | 
			
		||||
        app('queue')->createPayloadUsing(function () use ($company) {
 | 
			
		||||
            return ['db' => $company->db];
 | 
			
		||||
 | 
			
		||||
@ -57,7 +57,7 @@ class InvoiceController extends BaseController
 | 
			
		||||
        $company = Company::where('company_key', $request->header('X-API-COMPANY-KEY'))->first();
 | 
			
		||||
 | 
			
		||||
        if(!$company->enable_shop_api)
 | 
			
		||||
            return response()->json(['message' => 'Shop is disabled', 'errors' => []],403);
 | 
			
		||||
            return response()->json(['message' => 'Shop is disabled', 'errors' => new \stdClass],403);
 | 
			
		||||
 | 
			
		||||
        $invitation = InvoiceInvitation::with(['invoice'])
 | 
			
		||||
                                        ->where('company_id', $company->id)
 | 
			
		||||
@ -74,7 +74,7 @@ class InvoiceController extends BaseController
 | 
			
		||||
        $company = Company::where('company_key', $request->header('X-API-COMPANY-KEY'))->first();
 | 
			
		||||
 | 
			
		||||
        if(!$company->enable_shop_api)
 | 
			
		||||
            return response()->json(['message' => 'Shop is disabled', 'errors' => []],403);
 | 
			
		||||
            return response()->json(['message' => 'Shop is disabled', 'errors' => new \stdClass],403);
 | 
			
		||||
 | 
			
		||||
        app('queue')->createPayloadUsing(function () use ($company) {
 | 
			
		||||
            return ['db' => $company->db];
 | 
			
		||||
 | 
			
		||||
@ -37,7 +37,7 @@ class ProductController extends BaseController
 | 
			
		||||
        $company = Company::where('company_key', $request->header('X-API-COMPANY-KEY'))->first();
 | 
			
		||||
 | 
			
		||||
        if(!$company->enable_shop_api)
 | 
			
		||||
            return response()->json(['message' => 'Shop is disabled', 'errors' => []],403);
 | 
			
		||||
            return response()->json(['message' => 'Shop is disabled', 'errors' => new \stdClass],403);
 | 
			
		||||
 | 
			
		||||
        $products = Product::where('company_id', $company->id);
 | 
			
		||||
 | 
			
		||||
@ -49,7 +49,7 @@ class ProductController extends BaseController
 | 
			
		||||
        $company = Company::where('company_key', $request->header('X-API-COMPANY-KEY'))->first();
 | 
			
		||||
 | 
			
		||||
        if(!$company->enable_shop_api)
 | 
			
		||||
            return response()->json(['message' => 'Shop is disabled', 'errors' => []],403);
 | 
			
		||||
            return response()->json(['message' => 'Shop is disabled', 'errors' => new \stdClass],403);
 | 
			
		||||
        
 | 
			
		||||
        $product = Product::where('company_id', $company->id)
 | 
			
		||||
                            ->where('product_key', $product_key)
 | 
			
		||||
 | 
			
		||||
@ -34,7 +34,7 @@ class ProfileController extends BaseController
 | 
			
		||||
        $company = Company::where('company_key', $request->header('X-API-COMPANY-KEY'))->first();
 | 
			
		||||
 | 
			
		||||
        if(!$company->enable_shop_api)
 | 
			
		||||
            return response()->json(['message' => 'Shop is disabled', 'errors' => []],403);
 | 
			
		||||
            return response()->json(['message' => 'Shop is disabled', 'errors' => new \stdClass],403);
 | 
			
		||||
 | 
			
		||||
        return $this->itemResponse($company);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -30,7 +30,7 @@ class ApiSecretCheck
 | 
			
		||||
        } else {
 | 
			
		||||
            $error = [
 | 
			
		||||
                'message' => 'Invalid secret',
 | 
			
		||||
                'errors' => []
 | 
			
		||||
                'errors' => new \stdClass
 | 
			
		||||
            ];
 | 
			
		||||
            return response()
 | 
			
		||||
            ->json($error, 403)
 | 
			
		||||
 | 
			
		||||
@ -29,7 +29,7 @@ class ContactSetDb
 | 
			
		||||
    {
 | 
			
		||||
        $error = [
 | 
			
		||||
                'message' => 'Invalid Token',
 | 
			
		||||
                'errors' => []
 | 
			
		||||
                'errors' => new \stdClass
 | 
			
		||||
            ];
 | 
			
		||||
 | 
			
		||||
        if ($request->header('X-API-TOKEN') && config('ninja.db.multi_db_enabled')) {
 | 
			
		||||
 | 
			
		||||
@ -32,7 +32,7 @@ class ContactTokenAuth
 | 
			
		||||
        if ($request->header('X-API-TOKEN') && ($client_contact = ClientContact::with(['company'])->whereRaw("BINARY `token`= ?", [$request->header('X-API-TOKEN')])->first())) {
 | 
			
		||||
            $error = [
 | 
			
		||||
                'message' => 'Authentication disabled for user.',
 | 
			
		||||
                'errors' => []
 | 
			
		||||
                'errors' => new \stdClass
 | 
			
		||||
            ];
 | 
			
		||||
 | 
			
		||||
            //client_contact who once existed, but has been soft deleted
 | 
			
		||||
@ -43,7 +43,7 @@ class ContactTokenAuth
 | 
			
		||||
 | 
			
		||||
            $error = [
 | 
			
		||||
                'message' => 'Access is locked.',
 | 
			
		||||
                'errors' => []
 | 
			
		||||
                'errors' => new \stdClass
 | 
			
		||||
            ];
 | 
			
		||||
 | 
			
		||||
            //client_contact who has been disabled
 | 
			
		||||
@ -58,7 +58,7 @@ class ContactTokenAuth
 | 
			
		||||
        } else {
 | 
			
		||||
            $error = [
 | 
			
		||||
                'message' => 'Invalid token',
 | 
			
		||||
                'errors' => []
 | 
			
		||||
                'errors' => new \stdClass
 | 
			
		||||
            ];
 | 
			
		||||
 | 
			
		||||
            return response()->json($error, 403);
 | 
			
		||||
 | 
			
		||||
@ -32,7 +32,7 @@ class PasswordProtection
 | 
			
		||||
    {
 | 
			
		||||
        $error = [
 | 
			
		||||
            'message' => 'Invalid Password',
 | 
			
		||||
            'errors' => []
 | 
			
		||||
            'errors' => new \stdClass
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        if ($request->header('X-API-PASSWORD')) {
 | 
			
		||||
@ -47,7 +47,7 @@ class PasswordProtection
 | 
			
		||||
        } else {
 | 
			
		||||
            $error = [
 | 
			
		||||
                'message' => 'Access denied',
 | 
			
		||||
                'errors' => []
 | 
			
		||||
                'errors' => new \stdClass
 | 
			
		||||
            ];
 | 
			
		||||
            return response()->json($error, 412);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -29,7 +29,7 @@ class SetDb
 | 
			
		||||
    {
 | 
			
		||||
        $error = [
 | 
			
		||||
            'message' => 'Invalid Token',
 | 
			
		||||
            'errors' => []
 | 
			
		||||
            'errors' => new \stdClass
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -29,7 +29,7 @@ class SetDbByCompanyKey
 | 
			
		||||
    {
 | 
			
		||||
        $error = [
 | 
			
		||||
            'message' => 'Invalid Token',
 | 
			
		||||
            'errors' => []
 | 
			
		||||
            'errors' => new \stdClass
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -28,7 +28,7 @@ class SetDomainNameDb
 | 
			
		||||
    {
 | 
			
		||||
        $error = [
 | 
			
		||||
                'message' => 'Invalid token',
 | 
			
		||||
                'errors' => []
 | 
			
		||||
                'errors' => new \stdClass
 | 
			
		||||
            ];
 | 
			
		||||
        /*
 | 
			
		||||
         * Use the host name to set the active DB
 | 
			
		||||
 | 
			
		||||
@ -29,7 +29,7 @@ class SetEmailDb
 | 
			
		||||
    {
 | 
			
		||||
        $error = [
 | 
			
		||||
            'message' => 'Email not set or not found',
 | 
			
		||||
            'errors' => []
 | 
			
		||||
            'errors' => new \stdClass
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        if ($request->input('email') && config('ninja.db.multi_db_enabled')) {
 | 
			
		||||
 | 
			
		||||
@ -28,7 +28,7 @@ class SetInviteDb
 | 
			
		||||
    {
 | 
			
		||||
        $error = [
 | 
			
		||||
                'message' => 'Invalid URL',
 | 
			
		||||
                'errors' => []
 | 
			
		||||
                'errors' => new \stdClass
 | 
			
		||||
            ];
 | 
			
		||||
        /*
 | 
			
		||||
         * Use the host name to set the active DB
 | 
			
		||||
 | 
			
		||||
@ -34,7 +34,7 @@ class TokenAuth
 | 
			
		||||
 | 
			
		||||
            $error = [
 | 
			
		||||
                'message' => 'User inactive',
 | 
			
		||||
                'errors' => []
 | 
			
		||||
                'errors' => new \stdClass
 | 
			
		||||
            ];
 | 
			
		||||
            //user who once existed, but has been soft deleted
 | 
			
		||||
            if (!$user) {
 | 
			
		||||
@ -60,7 +60,7 @@ class TokenAuth
 | 
			
		||||
            if ($user->company_user->is_locked) {
 | 
			
		||||
                $error = [
 | 
			
		||||
                    'message' => 'User access locked',
 | 
			
		||||
                    'errors' => []
 | 
			
		||||
                    'errors' => new \stdClass
 | 
			
		||||
                ];
 | 
			
		||||
 | 
			
		||||
                return response()->json($error, 403);
 | 
			
		||||
@ -73,7 +73,7 @@ class TokenAuth
 | 
			
		||||
        } else {
 | 
			
		||||
            $error = [
 | 
			
		||||
                'message' => 'Invalid token',
 | 
			
		||||
                'errors' => []
 | 
			
		||||
                'errors' => new \stdClass
 | 
			
		||||
            ];
 | 
			
		||||
 | 
			
		||||
            return response()->json($error, 403);
 | 
			
		||||
 | 
			
		||||
@ -117,6 +117,8 @@ class BaseDriver extends AbstractPaymentDriver
 | 
			
		||||
        $payment->invoices()->sync($invoices);
 | 
			
		||||
        $payment->save();
 | 
			
		||||
 | 
			
		||||
        $payment->service()->applyNumber()->save();
 | 
			
		||||
 | 
			
		||||
        return $payment;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -16,7 +16,9 @@ use App\Models\Activity;
 | 
			
		||||
use App\Models\Backup;
 | 
			
		||||
use App\Models\Client;
 | 
			
		||||
use App\Models\CompanyToken;
 | 
			
		||||
use App\Models\Credit;
 | 
			
		||||
use App\Models\Invoice;
 | 
			
		||||
use App\Models\Quote;
 | 
			
		||||
use App\Models\User;
 | 
			
		||||
use App\Utils\Traits\MakesInvoiceHtml;
 | 
			
		||||
use Illuminate\Support\Facades\Log;
 | 
			
		||||
@ -64,14 +66,9 @@ class ActivityRepository extends BaseRepository
 | 
			
		||||
    {
 | 
			
		||||
        $backup = new Backup();
 | 
			
		||||
 | 
			
		||||
        // if (get_class($entity) == Client::class) {
 | 
			
		||||
        //     $entity->load('company');
 | 
			
		||||
        // } elseif (get_class($entity) == User::class) {
 | 
			
		||||
        // } else {
 | 
			
		||||
        //     $entity->load('company', 'client');
 | 
			
		||||
        // }
 | 
			
		||||
        if (get_class($entity) == Invoice::class || get_class($entity) == Quote::class || get_class($entity) == Credit::class)
 | 
			
		||||
            $backup->html_backup = $this->generateEntityHtml($entity->getEntityDesigner(), $entity);
 | 
			
		||||
 | 
			
		||||
        $backup->html_backup = $this->generateEntityHtml($entity->getEntityDesigner(), $entity);
 | 
			
		||||
        $backup->activity_id = $activity->id;
 | 
			
		||||
        $backup->json_backup = '';
 | 
			
		||||
        //$backup->json_backup = $entity->toJson();
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										46
									
								
								app/Services/Payment/ApplyNumber.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								app/Services/Payment/ApplyNumber.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,46 @@
 | 
			
		||||
<?php
 | 
			
		||||
/**
 | 
			
		||||
 * Payment Ninja (https://paymentninja.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @link https://github.com/paymentninja/paymentninja source repository
 | 
			
		||||
 *
 | 
			
		||||
 * @copyright Copyright (c) 2020. Payment Ninja LLC (https://paymentninja.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://opensource.org/licenses/AAL
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
namespace App\Services\Payment;
 | 
			
		||||
 | 
			
		||||
use App\Events\Payment\PaymentWasCreated;
 | 
			
		||||
use App\Factory\PaymentFactory;
 | 
			
		||||
use App\Models\Client;
 | 
			
		||||
use App\Models\Payment;
 | 
			
		||||
use App\Services\AbstractService;
 | 
			
		||||
use App\Services\Client\ClientService;
 | 
			
		||||
use App\Services\Payment\PaymentService;
 | 
			
		||||
use App\Utils\Traits\GeneratesCounter;
 | 
			
		||||
 | 
			
		||||
class ApplyNumber extends AbstractService
 | 
			
		||||
{
 | 
			
		||||
    use GeneratesCounter;
 | 
			
		||||
 | 
			
		||||
    private $payment;
 | 
			
		||||
 | 
			
		||||
    public function __construct(Payment $payment)
 | 
			
		||||
    {
 | 
			
		||||
        $this->client = $payment->client;
 | 
			
		||||
        
 | 
			
		||||
        $this->payment = $payment;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function run()
 | 
			
		||||
    {
 | 
			
		||||
        if ($this->payment->number != '') {
 | 
			
		||||
            return $this->payment;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $this->payment->number = $this->getNextPaymentNumber($this->client);
 | 
			
		||||
 | 
			
		||||
        return $this->payment;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -14,6 +14,7 @@ namespace App\Services\Payment;
 | 
			
		||||
use App\Factory\PaymentFactory;
 | 
			
		||||
use App\Models\Invoice;
 | 
			
		||||
use App\Models\Payment;
 | 
			
		||||
use App\Services\Payment\ApplyNumber;
 | 
			
		||||
use App\Services\Payment\DeletePayment;
 | 
			
		||||
use App\Services\Payment\RefundPayment;
 | 
			
		||||
use App\Services\Payment\UpdateInvoicePayment;
 | 
			
		||||
@ -87,4 +88,12 @@ class PaymentService
 | 
			
		||||
    {
 | 
			
		||||
        return ((new UpdateInvoicePayment($this->payment)))->run();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function applyNumber()
 | 
			
		||||
    {
 | 
			
		||||
        $this->payment = (new ApplyNumber($this->payment))->run();
 | 
			
		||||
 | 
			
		||||
        return $this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -39,6 +39,7 @@ class ClientGatewayTokenTransformer extends EntityTransformer
 | 
			
		||||
            'created_at' => (int)$cgt->created_at,
 | 
			
		||||
            'updated_at' => (int)$cgt->updated_at,
 | 
			
		||||
            'archived_at' => (int)$cgt->deleted_at,
 | 
			
		||||
            'is_deleted' => (bool) $cgt->is_deleted,
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -33,6 +33,7 @@ class ClientTransformer extends EntityTransformer
 | 
			
		||||
    protected $defaultIncludes = [
 | 
			
		||||
        'contacts',
 | 
			
		||||
        'documents',
 | 
			
		||||
        'gateway_tokens',
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,30 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
use Illuminate\Database\Migrations\Migration;
 | 
			
		||||
use Illuminate\Database\Schema\Blueprint;
 | 
			
		||||
use Illuminate\Support\Facades\Schema;
 | 
			
		||||
 | 
			
		||||
class AddIsDeletedFlagToClientGatewayTokenTable extends Migration
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Run the migrations.
 | 
			
		||||
     *
 | 
			
		||||
     * @return void
 | 
			
		||||
     */
 | 
			
		||||
    public function up()
 | 
			
		||||
    {
 | 
			
		||||
        Schema::table('client_gateway_tokens', function (Blueprint $table) {
 | 
			
		||||
            $table->boolean('is_deleted')->default(0);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Reverse the migrations.
 | 
			
		||||
     *
 | 
			
		||||
     * @return void
 | 
			
		||||
     */
 | 
			
		||||
    public function down()
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user