mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-04 03:57:32 -05:00 
			
		
		
		
	
						commit
						d69bc00ce5
					
				@ -76,6 +76,7 @@ class DemoMode extends Command
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        $this->info("Seeding Random Data");
 | 
					        $this->info("Seeding Random Data");
 | 
				
			||||||
        $this->createSmallAccount();
 | 
					        $this->createSmallAccount();
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -361,6 +362,10 @@ class DemoMode extends Command
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            $invoice = $invoice->service()->markPaid()->save();
 | 
					            $invoice = $invoice->service()->markPaid()->save();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            $invoice->payments->each(function ($payment){
 | 
				
			||||||
 | 
					                $payment->date = now()->addDays(rand(0,90));
 | 
				
			||||||
 | 
					                $payment->save();
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        //@todo this slow things down, but gives us PDFs of the invoices for inspection whilst debugging.
 | 
					        //@todo this slow things down, but gives us PDFs of the invoices for inspection whilst debugging.
 | 
				
			||||||
        event(new InvoiceWasCreated($invoice, $invoice->company, Ninja::eventVars()));
 | 
					        event(new InvoiceWasCreated($invoice, $invoice->company, Ninja::eventVars()));
 | 
				
			||||||
 | 
				
			|||||||
@ -321,6 +321,8 @@ class BaseController extends Controller
 | 
				
			|||||||
          'company.tasks',
 | 
					          'company.tasks',
 | 
				
			||||||
          'company.projects',
 | 
					          'company.projects',
 | 
				
			||||||
          'company.designs',
 | 
					          'company.designs',
 | 
				
			||||||
 | 
					          'company.webhooks',
 | 
				
			||||||
 | 
					          'company.tokens_hashed'
 | 
				
			||||||
        ];
 | 
					        ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $mini_load = [
 | 
					        $mini_load = [
 | 
				
			||||||
 | 
				
			|||||||
@ -6,5 +6,6 @@
 | 
				
			|||||||
 *       @OA\Property(property="id", type="string", example="Opnel5aKBz", description="______"),
 | 
					 *       @OA\Property(property="id", type="string", example="Opnel5aKBz", description="______"),
 | 
				
			||||||
 *       @OA\Property(property="name", type="string", example="GST", description="______"),
 | 
					 *       @OA\Property(property="name", type="string", example="GST", description="______"),
 | 
				
			||||||
 *       @OA\Property(property="rate", type="number", example="10", description="______"),
 | 
					 *       @OA\Property(property="rate", type="number", example="10", description="______"),
 | 
				
			||||||
 | 
					 *       @OA\Property(property="is_deleted", type="boolean", example=true, description="______"),
 | 
				
			||||||
 * )
 | 
					 * )
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
				
			|||||||
@ -12,13 +12,14 @@
 | 
				
			|||||||
namespace App\Http\Controllers;
 | 
					namespace App\Http\Controllers;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use App\Factory\TaxRateFactory;
 | 
					use App\Factory\TaxRateFactory;
 | 
				
			||||||
 | 
					use App\Http\Requests\TaxRate\CreateTaxRateRequest;
 | 
				
			||||||
use App\Http\Requests\TaxRate\DestroyTaxRateRequest;
 | 
					use App\Http\Requests\TaxRate\DestroyTaxRateRequest;
 | 
				
			||||||
use App\Http\Requests\TaxRate\EditTaxRateRequest;
 | 
					use App\Http\Requests\TaxRate\EditTaxRateRequest;
 | 
				
			||||||
use App\Http\Requests\TaxRate\ShowTaxRateRequest;
 | 
					use App\Http\Requests\TaxRate\ShowTaxRateRequest;
 | 
				
			||||||
use App\Http\Requests\TaxRate\StoreTaxRateRequest;
 | 
					use App\Http\Requests\TaxRate\StoreTaxRateRequest;
 | 
				
			||||||
use App\Http\Requests\TaxRate\UpdateTaxRateRequest;
 | 
					use App\Http\Requests\TaxRate\UpdateTaxRateRequest;
 | 
				
			||||||
use App\Http\Requests\TaxRate\CreateTaxRateRequest;
 | 
					 | 
				
			||||||
use App\Models\TaxRate;
 | 
					use App\Models\TaxRate;
 | 
				
			||||||
 | 
					use App\Repositories\BaseRepository;
 | 
				
			||||||
use App\Transformers\TaxRateTransformer;
 | 
					use App\Transformers\TaxRateTransformer;
 | 
				
			||||||
use Illuminate\Http\Request;
 | 
					use Illuminate\Http\Request;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -32,9 +33,13 @@ class TaxRateController extends BaseController
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    protected $entity_transformer = TaxRateTransformer::class;
 | 
					    protected $entity_transformer = TaxRateTransformer::class;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function __construct()
 | 
					    protected $base_repo;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function __construct(BaseRepository $base_repo)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        parent::__construct();
 | 
					        parent::__construct();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->base_repo = $base_repo;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -354,8 +359,82 @@ class TaxRateController extends BaseController
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public function destroy(DestroyTaxRateRequest $request, TaxRate $tax_rate)
 | 
					    public function destroy(DestroyTaxRateRequest $request, TaxRate $tax_rate)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					        $tax_rate->is_deleted = true;
 | 
				
			||||||
 | 
					        $tax_rate->save();
 | 
				
			||||||
        $tax_rate->delete();
 | 
					        $tax_rate->delete();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return response()->json([], 200);
 | 
					        return $this->itemResponse($tax_rate);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Perform bulk actions on the list view
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param BulkTaxRateRequest $request
 | 
				
			||||||
 | 
					     * @return \Illuminate\Http\Response
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @OA\Post(
 | 
				
			||||||
 | 
					     *      path="/api/v1/tax_rates/bulk",
 | 
				
			||||||
 | 
					     *      operationId="bulkTaxRates",
 | 
				
			||||||
 | 
					     *      tags={"tax_rates"},
 | 
				
			||||||
 | 
					     *      summary="Performs bulk actions on an array of TaxRates",
 | 
				
			||||||
 | 
					     *      description="",
 | 
				
			||||||
 | 
					     *      @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
 | 
				
			||||||
 | 
					     *      @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
 | 
				
			||||||
 | 
					     *      @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
 | 
				
			||||||
 | 
					     *      @OA\Parameter(ref="#/components/parameters/index"),
 | 
				
			||||||
 | 
					     *      @OA\RequestBody(
 | 
				
			||||||
 | 
					     *         description="Tax Rates",
 | 
				
			||||||
 | 
					     *         required=true,
 | 
				
			||||||
 | 
					     *         @OA\MediaType(
 | 
				
			||||||
 | 
					     *             mediaType="application/json",
 | 
				
			||||||
 | 
					     *             @OA\Schema(
 | 
				
			||||||
 | 
					     *                 type="array",
 | 
				
			||||||
 | 
					     *                 @OA\Items(
 | 
				
			||||||
 | 
					     *                     type="integer",
 | 
				
			||||||
 | 
					     *                     description="Array of hashed IDs to be bulk 'actioned",
 | 
				
			||||||
 | 
					     *                     example="[0,1,2,3]",
 | 
				
			||||||
 | 
					     *                 ),
 | 
				
			||||||
 | 
					     *             )
 | 
				
			||||||
 | 
					     *         )
 | 
				
			||||||
 | 
					     *     ),
 | 
				
			||||||
 | 
					     *      @OA\Response(
 | 
				
			||||||
 | 
					     *          response=200,
 | 
				
			||||||
 | 
					     *          description="The TaxRate List response",
 | 
				
			||||||
 | 
					     *          @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
 | 
				
			||||||
 | 
					     *          @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
 | 
				
			||||||
 | 
					     *          @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
 | 
				
			||||||
 | 
					     *          @OA\JsonContent(ref="#/components/schemas/Webhook"),
 | 
				
			||||||
 | 
					     *       ),
 | 
				
			||||||
 | 
					     *       @OA\Response(
 | 
				
			||||||
 | 
					     *          response=422,
 | 
				
			||||||
 | 
					     *          description="Validation error",
 | 
				
			||||||
 | 
					     *          @OA\JsonContent(ref="#/components/schemas/ValidationError"),
 | 
				
			||||||
 | 
					     *       ),
 | 
				
			||||||
 | 
					     *       @OA\Response(
 | 
				
			||||||
 | 
					     *           response="default",
 | 
				
			||||||
 | 
					     *           description="Unexpected Error",
 | 
				
			||||||
 | 
					     *           @OA\JsonContent(ref="#/components/schemas/Error"),
 | 
				
			||||||
 | 
					     *       ),
 | 
				
			||||||
 | 
					     *     )
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public function bulk()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $action = request()->input('action');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $ids = request()->input('ids');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $tax_rate = TaxRate::withTrashed()->find($this->transformKeys($ids));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $tax_rate->each(function ($tax_rat, $key) use ($action) {
 | 
				
			||||||
 | 
					            if (auth()->user()->can('edit', $tax_rate)) {
 | 
				
			||||||
 | 
					                $this->base_repo->{$action}($tax_rate);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return $this->listResponse(TaxRate::withTrashed()->whereIn('id', $this->transformKeys($ids)));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -51,7 +51,7 @@ class QueryLogging
 | 
				
			|||||||
            //    Log::info($request->method() . ' - ' . $request->url() . ": $count queries - " . $time);
 | 
					            //    Log::info($request->method() . ' - ' . $request->url() . ": $count queries - " . $time);
 | 
				
			||||||
                
 | 
					                
 | 
				
			||||||
             //if($count > 10)
 | 
					             //if($count > 10)
 | 
				
			||||||
                 Log::info($queries);
 | 
					             //    Log::info($queries);
 | 
				
			||||||
                 
 | 
					                 
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
@ -72,17 +72,17 @@ class UpdatePaymentRequest extends Request
 | 
				
			|||||||
            unset($input['amount']);
 | 
					            unset($input['amount']);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (isset($input['type_id'])) {
 | 
					        // if (isset($input['type_id'])) {
 | 
				
			||||||
            unset($input['type_id']);
 | 
					        //     unset($input['type_id']);
 | 
				
			||||||
        }
 | 
					        // }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (isset($input['date'])) {
 | 
					        // if (isset($input['date'])) {
 | 
				
			||||||
            unset($input['date']);
 | 
					        //     unset($input['date']);
 | 
				
			||||||
        }
 | 
					        // }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (isset($input['transaction_reference'])) {
 | 
					        // if (isset($input['transaction_reference'])) {
 | 
				
			||||||
            unset($input['transaction_reference']);
 | 
					        //     unset($input['transaction_reference']);
 | 
				
			||||||
        }
 | 
					        // }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (isset($input['number'])) {
 | 
					        if (isset($input['number'])) {
 | 
				
			||||||
            unset($input['number']);
 | 
					            unset($input['number']);
 | 
				
			||||||
 | 
				
			|||||||
@ -374,6 +374,11 @@ class Company extends BaseModel
 | 
				
			|||||||
        return $this->hasMany(CompanyToken::class);
 | 
					        return $this->hasMany(CompanyToken::class);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function tokens_hashed()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return $this->hasMany(CompanyToken::class);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function company_users()
 | 
					    public function company_users()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        //return $this->hasMany(CompanyUser::class)->withTimestamps();
 | 
					        //return $this->hasMany(CompanyUser::class)->withTimestamps();
 | 
				
			||||||
 | 
				
			|||||||
@ -254,7 +254,6 @@ class CompanyGateway extends BaseModel
 | 
				
			|||||||
            $fee += $pre_tax_fee * $this->fee_tax_rate2 / 100;
 | 
					            $fee += $pre_tax_fee * $this->fee_tax_rate2 / 100;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        return $fee;
 | 
					        return $fee;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -102,6 +102,33 @@ class AuthorizeCreditCard
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    private function tokenBilling($cgt, $amount, $invoice)
 | 
					    private function tokenBilling($cgt, $amount, $invoice)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					        $data = (new ChargePaymentProfile($this->authorize))->chargeCustomerProfile($cgt->gateway_customer_reference, $cgt->token, $amounts);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if($data['response'] != null && $data['response']->getMessages()->getResultCode() == "Ok") {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            $payment = $this->createPaymentRecord($data, $amount);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            $this->authorize->attachInvoices($payment, $invoice->hashed_id);
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars()));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            $vars = [
 | 
				
			||||||
 | 
					                'hashed_ids' => $invoice->hashed_id,
 | 
				
			||||||
 | 
					                'amount' => $amount
 | 
				
			||||||
 | 
					            ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            $logger_message = [
 | 
				
			||||||
 | 
					                'server_response' => $response->getTransactionResponse()->getTransId(),
 | 
				
			||||||
 | 
					                'data' => $this->formatGatewayResponse($data, $vars)
 | 
				
			||||||
 | 
					            ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            SystemLogger::dispatch($logger_message, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_AUTHORIZE, $this->authorize->client);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        else {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
@ -115,10 +142,11 @@ class AuthorizeCreditCard
 | 
				
			|||||||
        return $this->processFailedResponse($data, $request);
 | 
					        return $this->processFailedResponse($data, $request);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private function processSuccessfulResponse($data, $request)
 | 
					    private function createPaymentRecord($data, $amount) :?Payment
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $response = $data['response'];
 | 
					        $response = $data['response'];
 | 
				
			||||||
        //create a payment record and fire notifications and then return 
 | 
					        //create a payment record 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $payment = PaymentFactory::create($this->authorize->client->company_id, $this->authorize->client->user_id);
 | 
					        $payment = PaymentFactory::create($this->authorize->client->company_id, $this->authorize->client->user_id);
 | 
				
			||||||
        $payment->client_id = $this->authorize->client->id;
 | 
					        $payment->client_id = $this->authorize->client->id;
 | 
				
			||||||
@ -129,20 +157,32 @@ class AuthorizeCreditCard
 | 
				
			|||||||
        $payment->currency_id = $this->authorize->client->getSetting('currency_id');
 | 
					        $payment->currency_id = $this->authorize->client->getSetting('currency_id');
 | 
				
			||||||
        $payment->date = Carbon::now();
 | 
					        $payment->date = Carbon::now();
 | 
				
			||||||
        $payment->transaction_reference = $response->getTransactionResponse()->getTransId();
 | 
					        $payment->transaction_reference = $response->getTransactionResponse()->getTransId();
 | 
				
			||||||
        $payment->amount = $request->input('amount_with_fee'); 
 | 
					        $payment->amount = $amount; 
 | 
				
			||||||
        $payment->currency_id = $this->authorize->client->getSetting('currency_id');
 | 
					        $payment->currency_id = $this->authorize->client->getSetting('currency_id');
 | 
				
			||||||
        $payment->client->getNextPaymentNumber($this->authorize->client);
 | 
					        $payment->client->getNextPaymentNumber($this->authorize->client);
 | 
				
			||||||
        $payment->save();
 | 
					        $payment->save();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return $payment;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private function processSuccessfulResponse($data, $request)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $payment = $this->createPaymentRecord($data, $request->input('amount_with_fee'));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $this->authorize->attachInvoices($payment, $request->hashed_ids);
 | 
					        $this->authorize->attachInvoices($payment, $request->hashed_ids);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $payment->service()->updateInvoicePayment();
 | 
					        $payment->service()->updateInvoicePayment();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars()));
 | 
					        event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars()));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $vars = [
 | 
				
			||||||
 | 
					            'hashed_ids' => $request->input('hashed_ids'),
 | 
				
			||||||
 | 
					            'amount' => $request->input('amount')
 | 
				
			||||||
 | 
					        ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $logger_message = [
 | 
					        $logger_message = [
 | 
				
			||||||
            'server_response' => $response->getTransactionResponse()->getTransId(),
 | 
					            'server_response' => $response->getTransactionResponse()->getTransId(),
 | 
				
			||||||
            'data' => $this->formatGatewayResponse($data, $request)
 | 
					            'data' => $this->formatGatewayResponse($data, $vars)
 | 
				
			||||||
        ];
 | 
					        ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        SystemLogger::dispatch($logger_message, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_AUTHORIZE, $this->authorize->client);
 | 
					        SystemLogger::dispatch($logger_message, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_AUTHORIZE, $this->authorize->client);
 | 
				
			||||||
@ -156,17 +196,17 @@ class AuthorizeCreditCard
 | 
				
			|||||||
        info(print_r($data,1));
 | 
					        info(print_r($data,1));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private function formatGatewayResponse($data, $request)
 | 
					    private function formatGatewayResponse($data, $vars)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $response = $data['response'];
 | 
					        $response = $data['response'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return [
 | 
					        return [
 | 
				
			||||||
            'transaction_reference' => $response->getTransactionResponse()->getTransId(),
 | 
					            'transaction_reference' => $response->getTransactionResponse()->getTransId(),
 | 
				
			||||||
            'amount' => $request->input('amount'),
 | 
					            'amount' => $vars['amount'],
 | 
				
			||||||
            'auth_code' => $response->getTransactionResponse()->getAuthCode(),
 | 
					            'auth_code' => $response->getTransactionResponse()->getAuthCode(),
 | 
				
			||||||
            'code' => $response->getTransactionResponse()->getMessages()[0]->getCode(),
 | 
					            'code' => $response->getTransactionResponse()->getMessages()[0]->getCode(),
 | 
				
			||||||
            'description' => $response->getTransactionResponse()->getMessages()[0]->getDescription(),
 | 
					            'description' => $response->getTransactionResponse()->getMessages()[0]->getDescription(),
 | 
				
			||||||
            'invoices' => $request->hashed_ids,
 | 
					            'invoices' => $vars['hashed_ids'],
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        ];
 | 
					        ];
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -47,10 +47,23 @@ class AutoBillInvoice extends AbstractService
 | 
				
			|||||||
        else
 | 
					        else
 | 
				
			||||||
            return $this->invoice->service()->markPaid()->save();
 | 
					            return $this->invoice->service()->markPaid()->save();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if(!$gateway_token)
 | 
				
			||||||
 | 
					            return $this->invoice;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if($this->invoice->partial){
 | 
				
			||||||
 | 
					            $fee = $gateway_token->gateway->calcGatewayFee($this->invoice->partial);
 | 
				
			||||||
 | 
					            $amount = $this->invoice->partial + $fee;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        else{
 | 
				
			||||||
            $fee = $gateway_token->gateway->calcGatewayFee($this->invoice->balance);
 | 
					            $fee = $gateway_token->gateway->calcGatewayFee($this->invoice->balance);
 | 
				
			||||||
 | 
					            $amount = $this->invoice->balance + $fee;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /* Make sure we remove any stale fees*/
 | 
				
			||||||
 | 
					        $this->purgeStaleGatewayFees();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if($fee > 0)
 | 
					        if($fee > 0)
 | 
				
			||||||
            $this->purgeStaleGatewayFees()->addFeeToInvoice($fee);
 | 
					            $this->addFeeToInvoice($fee);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $response = $gateway_token->gateway->driver($this->client)->tokenBilling($gateway_token, $amount, $this->invoice);
 | 
					        $response = $gateway_token->gateway->driver($this->client)->tokenBilling($gateway_token, $amount, $this->invoice);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -60,13 +73,22 @@ class AutoBillInvoice extends AbstractService
 | 
				
			|||||||
    private function getGateway($amount)
 | 
					    private function getGateway($amount)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $gateway_tokens = $this->client->gateway_tokens()->orderBy('is_default', 'DESC');
 | 
					        // $gateway_tokens = $this->client->gateway_tokens()->orderBy('is_default', 'DESC');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $gateway_tokens->filter(function ($token) use ($amount){
 | 
					        // return $gateway_tokens->filter(function ($token) use ($amount){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return $this->validGatewayLimits($token, $amount);
 | 
					        //     return $this->validGatewayLimits($token, $amount);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        })->all()->first();
 | 
					        // })->all()->first();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $gateway_tokens = $this->client->gateway_tokens()->orderBy('is_default', 'DESC')->get();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        foreach($gateway_tokens as $gateway_token)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if($this->validGatewayLimits($gateway_token, $amount))
 | 
				
			||||||
 | 
					                return $gateway_token;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										56
									
								
								app/Transformers/CompanyTokenHashedTransformer.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								app/Transformers/CompanyTokenHashedTransformer.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,56 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Invoice Ninja (https://invoiceninja.com)
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @link https://github.com/invoiceninja/invoiceninja source repository
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @license https://opensource.org/licenses/AAL
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace App\Transformers;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use App\Models\CompanyToken;
 | 
				
			||||||
 | 
					use App\Utils\Traits\MakesHash;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Class CompanyTokenHashedTransformer.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					class CompanyTokenHashedTransformer extends EntityTransformer
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    use MakesHash;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * @var array
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    protected $defaultIncludes = [
 | 
				
			||||||
 | 
					    ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * @var array
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    protected $availableIncludes = [
 | 
				
			||||||
 | 
					    ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * @param CompanyToken $company_token
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @return array
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public function transform(CompanyToken $company_token)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return [
 | 
				
			||||||
 | 
					            'id' => $this->encodePrimaryKey($company_token->id),
 | 
				
			||||||
 | 
					            'user_id' => $this->encodePrimaryKey($company_token->user_id),
 | 
				
			||||||
 | 
					            'token' => substr($company_token->token, 0 ,10)."xxxxxxxxxxx",
 | 
				
			||||||
 | 
					            'name' => $company_token->name ?: '',
 | 
				
			||||||
 | 
					            'is_system' =>(bool)$company_token->is_system,
 | 
				
			||||||
 | 
					            'updated_at' => (int)$company_token->updated_at,
 | 
				
			||||||
 | 
					            'archived_at' => (int)$company_token->deleted_at,
 | 
				
			||||||
 | 
					            'created_at' => (int)$company_token->created_at,
 | 
				
			||||||
 | 
					            'is_deleted' => (bool)$company_token->is_deleted,
 | 
				
			||||||
 | 
					        ];
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -33,6 +33,7 @@ use App\Models\TaxRate;
 | 
				
			|||||||
use App\Models\User;
 | 
					use App\Models\User;
 | 
				
			||||||
use App\Models\Webhook;
 | 
					use App\Models\Webhook;
 | 
				
			||||||
use App\Transformers\CompanyLedgerTransformer;
 | 
					use App\Transformers\CompanyLedgerTransformer;
 | 
				
			||||||
 | 
					use App\Transformers\CompanyTokenHashedTransformer;
 | 
				
			||||||
use App\Transformers\CompanyTokenTransformer;
 | 
					use App\Transformers\CompanyTokenTransformer;
 | 
				
			||||||
use App\Transformers\CreditTransformer;
 | 
					use App\Transformers\CreditTransformer;
 | 
				
			||||||
use App\Transformers\PaymentTermTransformer;
 | 
					use App\Transformers\PaymentTermTransformer;
 | 
				
			||||||
@ -82,7 +83,8 @@ class CompanyTransformer extends EntityTransformer
 | 
				
			|||||||
        'tasks',
 | 
					        'tasks',
 | 
				
			||||||
        'ledger',
 | 
					        'ledger',
 | 
				
			||||||
        'webhooks',
 | 
					        'webhooks',
 | 
				
			||||||
        'tokens'
 | 
					        'tokens',
 | 
				
			||||||
 | 
					        'tokens_hashed'
 | 
				
			||||||
    ];
 | 
					    ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -147,6 +149,13 @@ class CompanyTransformer extends EntityTransformer
 | 
				
			|||||||
        return $this->includeCollection($company->tokens, $transformer, CompanyToken::class);
 | 
					        return $this->includeCollection($company->tokens, $transformer, CompanyToken::class);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function includeTokensHashed(Company $company)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $transformer = new CompanyTokenHashedTransformer($this->serializer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return $this->includeCollection($company->tokens, $transformer, CompanyToken::class);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function includeWebhooks(Company $company)
 | 
					    public function includeWebhooks(Company $company)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $transformer = new WebhookTransformer($this->serializer);
 | 
					        $transformer = new WebhookTransformer($this->serializer);
 | 
				
			||||||
 | 
				
			|||||||
@ -18,6 +18,7 @@ class TaxRateTransformer extends EntityTransformer
 | 
				
			|||||||
            'id' => (string) $this->encodePrimaryKey($tax_rate->id),
 | 
					            'id' => (string) $this->encodePrimaryKey($tax_rate->id),
 | 
				
			||||||
            'name' => (string) $tax_rate->name,
 | 
					            'name' => (string) $tax_rate->name,
 | 
				
			||||||
            'rate' => (float) $tax_rate->rate,
 | 
					            'rate' => (float) $tax_rate->rate,
 | 
				
			||||||
 | 
					            'is_deleted' => (bool) $tax_rate->is_deleted,
 | 
				
			||||||
            'updated_at' => (int)$tax_rate->updated_at,
 | 
					            'updated_at' => (int)$tax_rate->updated_at,
 | 
				
			||||||
            'archived_at' => (int)$tax_rate->deleted_at,
 | 
					            'archived_at' => (int)$tax_rate->deleted_at,
 | 
				
			||||||
            'created_at' => (int)$tax_rate->created_at,
 | 
					            'created_at' => (int)$tax_rate->created_at,
 | 
				
			||||||
 | 
				
			|||||||
@ -11,7 +11,7 @@ $factory->define(App\Models\Company::class, function (Faker $faker) {
 | 
				
			|||||||
        'db' => config('database.default'),
 | 
					        'db' => config('database.default'),
 | 
				
			||||||
        'settings' => CompanySettings::defaults(),
 | 
					        'settings' => CompanySettings::defaults(),
 | 
				
			||||||
        'custom_fields' => (object) [
 | 
					        'custom_fields' => (object) [
 | 
				
			||||||
            'invoice1' => 'Custom Date|date',
 | 
					            //'invoice1' => 'Custom Date|date',
 | 
				
			||||||
            // 'invoice2' => '2|switch',
 | 
					            // 'invoice2' => '2|switch',
 | 
				
			||||||
            // 'invoice3' => '3|',
 | 
					            // 'invoice3' => '3|',
 | 
				
			||||||
            // 'invoice4' => '4',
 | 
					            // 'invoice4' => '4',
 | 
				
			||||||
 | 
				
			|||||||
@ -16,6 +16,10 @@ class AddTokenIdToActivityTable extends Migration
 | 
				
			|||||||
        Schema::table('activities', function (Blueprint $table) {
 | 
					        Schema::table('activities', function (Blueprint $table) {
 | 
				
			||||||
            $table->unsignedInteger('token_id')->nullable();
 | 
					            $table->unsignedInteger('token_id')->nullable();
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Schema::table('tax_rates', function (Blueprint $table) {
 | 
				
			||||||
 | 
					            $table->boolean('is_deleted')->default(0);
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 | 
				
			|||||||
@ -106,6 +106,8 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a
 | 
				
			|||||||
    Route::resource('companies', 'CompanyController');// name = (companies. index / create / show / update / destroy / edit
 | 
					    Route::resource('companies', 'CompanyController');// name = (companies. index / create / show / update / destroy / edit
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    Route::resource('tokens', 'TokenController')->middleware('password_protected');// name = (tokens. index / create / show / update / destroy / edit
 | 
					    Route::resource('tokens', 'TokenController')->middleware('password_protected');// name = (tokens. index / create / show / update / destroy / edit
 | 
				
			||||||
 | 
					    Route::post('tokens/bulk', 'TokenController@bulk')->name('tokens.bulk')->middleware('password_protected');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Route::resource('company_gateways', 'CompanyGatewayController');
 | 
					    Route::resource('company_gateways', 'CompanyGatewayController');
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
@ -117,6 +119,7 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a
 | 
				
			|||||||
    Route::post('group_settings/bulk', 'GroupSettingController@bulk');
 | 
					    Route::post('group_settings/bulk', 'GroupSettingController@bulk');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Route::resource('tax_rates', 'TaxRateController');// name = (tasks. index / create / show / update / destroy / edit
 | 
					    Route::resource('tax_rates', 'TaxRateController');// name = (tasks. index / create / show / update / destroy / edit
 | 
				
			||||||
 | 
					    Route::post('tax_rates/bulk', 'TaxRateController@bulk')->name('tax_rates.bulk');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Route::post('refresh', 'Auth\LoginController@refresh');
 | 
					    Route::post('refresh', 'Auth\LoginController@refresh');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user