2019-10-03 05:23:00 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-10-03 05:23:00 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2024-04-12 06:15:41 +02:00
|
|
|
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-10-03 05:23:00 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2019-10-03 05:23:00 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2024-03-18 03:50:12 +01:00
|
|
|
use App\Models\Client;
|
|
|
|
use App\Libraries\MultiDB;
|
|
|
|
use Illuminate\Http\Response;
|
|
|
|
use App\Models\CompanyGateway;
|
|
|
|
use App\Utils\Traits\MakesHash;
|
2021-01-21 22:36:25 +01:00
|
|
|
use App\DataMapper\FeesAndLimits;
|
2024-03-18 03:50:12 +01:00
|
|
|
use App\Jobs\Util\ApplePayDomain;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
2019-10-03 05:23:00 +02:00
|
|
|
use App\Factory\CompanyGatewayFactory;
|
2022-01-03 02:35:31 +01:00
|
|
|
use App\Filters\CompanyGatewayFilters;
|
2024-03-18 03:50:12 +01:00
|
|
|
use App\Repositories\CompanyRepository;
|
|
|
|
use Illuminate\Foundation\Bus\DispatchesJobs;
|
|
|
|
use App\Transformers\CompanyGatewayTransformer;
|
|
|
|
use App\PaymentDrivers\Stripe\Jobs\StripeWebhook;
|
|
|
|
use App\PaymentDrivers\CheckoutCom\CheckoutSetupWebhook;
|
2023-01-22 05:11:33 +01:00
|
|
|
use App\Http\Requests\CompanyGateway\BulkCompanyGatewayRequest;
|
2019-10-03 05:23:00 +02:00
|
|
|
use App\Http\Requests\CompanyGateway\EditCompanyGatewayRequest;
|
|
|
|
use App\Http\Requests\CompanyGateway\ShowCompanyGatewayRequest;
|
2024-03-17 02:07:20 +01:00
|
|
|
use App\Http\Requests\CompanyGateway\TestCompanyGatewayRequest;
|
2024-03-18 03:50:12 +01:00
|
|
|
use App\Http\Requests\CompanyGateway\StoreCompanyGatewayRequest;
|
|
|
|
use App\Http\Requests\CompanyGateway\CreateCompanyGatewayRequest;
|
2019-10-03 05:23:00 +02:00
|
|
|
use App\Http\Requests\CompanyGateway\UpdateCompanyGatewayRequest;
|
2024-03-18 03:50:12 +01:00
|
|
|
use App\Http\Requests\CompanyGateway\DestroyCompanyGatewayRequest;
|
2019-10-03 05:23:00 +02:00
|
|
|
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Class CompanyGatewayController.
|
2019-10-03 05:23:00 +02:00
|
|
|
*/
|
|
|
|
class CompanyGatewayController extends BaseController
|
|
|
|
{
|
|
|
|
use DispatchesJobs;
|
|
|
|
use MakesHash;
|
|
|
|
|
|
|
|
protected $entity_type = CompanyGateway::class;
|
|
|
|
|
|
|
|
protected $entity_transformer = CompanyGatewayTransformer::class;
|
|
|
|
|
|
|
|
protected $company_repo;
|
|
|
|
|
|
|
|
public $forced_includes = [];
|
|
|
|
|
2022-01-06 01:19:29 +01:00
|
|
|
private array $stripe_keys = ['d14dd26a47cecc30fdd65700bfb67b34', 'd14dd26a37cecc30fdd65700bfb55b23'];
|
|
|
|
|
2023-07-21 13:58:04 +02:00
|
|
|
private string $checkout_key = '3758e7f7c6f4cecf0f4f348b9a00f456';
|
|
|
|
|
2024-03-19 00:38:54 +01:00
|
|
|
private string $forte_key = 'kivcvjexxvdiyqtj3mju5d6yhpeht2xs';
|
|
|
|
|
|
|
|
|
2019-10-03 05:23:00 +02:00
|
|
|
/**
|
|
|
|
* CompanyGatewayController constructor.
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param CompanyRepository $company_repo
|
2019-10-03 05:23:00 +02:00
|
|
|
*/
|
|
|
|
public function __construct(CompanyRepository $company_repo)
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->company_repo = $company_repo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*
|
2024-06-16 00:30:25 +02:00
|
|
|
* @return Response| \Illuminate\Http\JsonResponse
|
2019-10-07 06:09:04 +02:00
|
|
|
*
|
2019-12-30 22:59:12 +01:00
|
|
|
*
|
|
|
|
*
|
2019-10-07 06:09:04 +02:00
|
|
|
* @OA\Get(
|
|
|
|
* path="/api/v1/company_gateways",
|
|
|
|
* operationId="getCompanyGateways",
|
|
|
|
* tags={"company_gateways"},
|
|
|
|
* summary="Gets a list of company_gateways",
|
|
|
|
* description="Lists company_gateways, search and filters allow fine grained lists to be generated.
|
|
|
|
|
|
|
|
Query parameters can be added to performed more fine grained filtering of the company_gateways, these are handled by the CompanyGatewayFilters class which defines the methods available",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2019-10-07 06:09:04 +02:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="A list of company_gateways",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
2019-10-07 06:09:04 +02:00
|
|
|
* @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/CompanyGateway"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
2019-12-30 22:59:12 +01:00
|
|
|
* response="default",
|
2019-10-07 06:09:04 +02:00
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
2019-10-03 05:23:00 +02:00
|
|
|
*/
|
2022-01-03 02:35:31 +01:00
|
|
|
public function index(CompanyGatewayFilters $filters)
|
2019-10-03 05:23:00 +02:00
|
|
|
{
|
2022-01-03 02:35:31 +01:00
|
|
|
$company_gateways = CompanyGateway::filter($filters);
|
2019-10-03 05:23:00 +02:00
|
|
|
|
|
|
|
return $this->listResponse($company_gateways);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param CreateCompanyGatewayRequest $request
|
2024-06-16 00:30:25 +02:00
|
|
|
* @return Response| \Illuminate\Http\JsonResponse
|
2019-10-07 06:09:04 +02:00
|
|
|
*
|
2019-12-30 22:59:12 +01:00
|
|
|
*
|
|
|
|
*
|
2019-10-07 06:09:04 +02:00
|
|
|
* @OA\Get(
|
|
|
|
* path="/api/v1/company_gateways/create",
|
|
|
|
* operationId="getCompanyGatewaysCreate",
|
|
|
|
* tags={"company_gateways"},
|
|
|
|
* summary="Gets a new blank CompanyGateway object",
|
|
|
|
* description="Returns a blank object with default values",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2019-10-07 06:09:04 +02:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="A blank CompanyGateway object",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
2019-10-07 06:09:04 +02:00
|
|
|
* @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/CompanyGateway"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
2019-12-30 22:59:12 +01:00
|
|
|
* response="default",
|
2019-10-07 06:09:04 +02:00
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
2019-10-03 05:23:00 +02:00
|
|
|
*/
|
|
|
|
public function create(CreateCompanyGatewayRequest $request)
|
|
|
|
{
|
2024-02-13 05:25:18 +01:00
|
|
|
|
2024-01-14 05:51:31 +01:00
|
|
|
/** @var \App\Models\User $user */
|
|
|
|
$user = auth()->user();
|
|
|
|
|
|
|
|
$company_gateway = CompanyGatewayFactory::create($user->company()->id, auth()->user()->id);
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-10-03 05:23:00 +02:00
|
|
|
return $this->itemResponse($company_gateway);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param StoreCompanyGatewayRequest $request
|
2024-06-16 00:30:25 +02:00
|
|
|
* @return Response| \Illuminate\Http\JsonResponse
|
2019-10-07 06:09:04 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @OA\Post(
|
|
|
|
* path="/api/v1/company_gateways",
|
|
|
|
* operationId="storeCompanyGateway",
|
|
|
|
* tags={"company_gateways"},
|
|
|
|
* summary="Adds a CompanyGateway",
|
|
|
|
* description="Adds an CompanyGateway to the system",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2019-10-07 06:09:04 +02:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns the saved CompanyGateway object",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
2019-10-07 06:09:04 +02:00
|
|
|
* @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/CompanyGateway"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
2019-12-30 22:59:12 +01:00
|
|
|
* response="default",
|
2019-10-07 06:09:04 +02:00
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
2019-10-03 05:23:00 +02:00
|
|
|
*/
|
|
|
|
public function store(StoreCompanyGatewayRequest $request)
|
|
|
|
{
|
2023-10-16 03:05:19 +02:00
|
|
|
/** @var \App\Models\User $user */
|
|
|
|
$user = auth()->user();
|
|
|
|
|
|
|
|
$company_gateway = CompanyGatewayFactory::create($user->company()->id, $user->id);
|
2019-10-03 05:23:00 +02:00
|
|
|
$company_gateway->fill($request->all());
|
|
|
|
$company_gateway->save();
|
|
|
|
|
2023-11-26 08:41:42 +01:00
|
|
|
/*Always ensure at least one fees and limits object is set per gateway*/
|
2024-01-14 05:05:00 +01:00
|
|
|
$gateway_types = $company_gateway->driver(new Client())->getAvailableMethods();
|
|
|
|
|
2023-10-16 03:05:19 +02:00
|
|
|
$fees_and_limits = $company_gateway->fees_and_limits;
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2023-11-26 08:41:42 +01:00
|
|
|
foreach($gateway_types as $key => $gateway_type) {
|
|
|
|
if(!property_exists($fees_and_limits, $key)) {
|
2024-01-14 05:05:00 +01:00
|
|
|
$fees_and_limits->{$key} = new FeesAndLimits();
|
2023-11-26 08:41:42 +01:00
|
|
|
}
|
2021-01-21 22:36:25 +01:00
|
|
|
}
|
|
|
|
|
2023-10-16 03:05:19 +02:00
|
|
|
$company_gateway->fees_and_limits = $fees_and_limits;
|
|
|
|
$company_gateway->save();
|
|
|
|
|
2022-01-06 01:52:24 +01:00
|
|
|
ApplePayDomain::dispatch($company_gateway, $company_gateway->company->db);
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if (in_array($company_gateway->gateway_key, $this->stripe_keys)) {
|
2022-05-30 12:08:12 +02:00
|
|
|
StripeWebhook::dispatch($company_gateway->company->company_key, $company_gateway->id);
|
2023-10-26 04:57:44 +02:00
|
|
|
} elseif($company_gateway->gateway_key == $this->checkout_key) {
|
2023-07-21 13:58:04 +02:00
|
|
|
CheckoutSetupWebhook::dispatch($company_gateway->company->company_key, $company_gateway->id);
|
2024-03-19 00:38:54 +01:00
|
|
|
} elseif($company_gateway->gateway_key == $this->forte_key) {
|
2024-06-14 09:09:44 +02:00
|
|
|
|
2024-03-19 00:38:54 +01:00
|
|
|
dispatch(function () use ($company_gateway) {
|
|
|
|
MultiDB::setDb($company_gateway->company->db);
|
|
|
|
$company_gateway->driver()->updateFees();
|
|
|
|
})->afterResponse();
|
|
|
|
|
2023-07-21 13:58:04 +02:00
|
|
|
}
|
2022-05-30 12:08:12 +02:00
|
|
|
|
2019-10-03 05:23:00 +02:00
|
|
|
return $this->itemResponse($company_gateway);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param ShowCompanyGatewayRequest $request
|
|
|
|
* @param CompanyGateway $company_gateway
|
2024-06-16 00:30:25 +02:00
|
|
|
* @return Response| \Illuminate\Http\JsonResponse
|
2019-10-07 06:09:04 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* @OA\Get(
|
|
|
|
* path="/api/v1/company_gateways/{id}",
|
|
|
|
* operationId="showCompanyGateway",
|
|
|
|
* tags={"company_gateways"},
|
|
|
|
* summary="Shows an CompanyGateway",
|
|
|
|
* description="Displays an CompanyGateway by id",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2019-10-07 06:09:04 +02:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="id",
|
|
|
|
* in="path",
|
|
|
|
* description="The CompanyGateway Hashed ID",
|
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns the CompanyGateway object",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
2019-10-07 06:09:04 +02:00
|
|
|
* @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/CompanyGateway"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
2019-12-30 22:59:12 +01:00
|
|
|
* response="default",
|
2019-10-07 06:09:04 +02:00
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
2019-12-30 22:59:12 +01:00
|
|
|
*/
|
2019-10-03 05:23:00 +02:00
|
|
|
public function show(ShowCompanyGatewayRequest $request, CompanyGateway $company_gateway)
|
|
|
|
{
|
|
|
|
return $this->itemResponse($company_gateway);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param EditCompanyGatewayRequest $request
|
|
|
|
* @param CompanyGateway $company_gateway
|
2024-06-16 00:30:25 +02:00
|
|
|
* @return Response| \Illuminate\Http\JsonResponse
|
2019-10-07 06:09:04 +02:00
|
|
|
*
|
2019-12-30 22:59:12 +01:00
|
|
|
*
|
2019-10-07 06:09:04 +02:00
|
|
|
* @OA\Get(
|
|
|
|
* path="/api/v1/company_gateways/{id}/edit",
|
|
|
|
* operationId="editCompanyGateway",
|
|
|
|
* tags={"company_gateways"},
|
|
|
|
* summary="Shows an CompanyGateway for editting",
|
|
|
|
* description="Displays an CompanyGateway by id",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2019-10-07 06:09:04 +02:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="id",
|
|
|
|
* in="path",
|
|
|
|
* description="The CompanyGateway Hashed ID",
|
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns the CompanyGateway object",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
2019-10-07 06:09:04 +02:00
|
|
|
* @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/CompanyGateway"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
2019-12-30 22:59:12 +01:00
|
|
|
* response="default",
|
2019-10-07 06:09:04 +02:00
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
2019-10-03 05:23:00 +02:00
|
|
|
*/
|
|
|
|
public function edit(EditCompanyGatewayRequest $request, CompanyGateway $company_gateway)
|
|
|
|
{
|
2019-12-30 22:59:12 +01:00
|
|
|
return $this->itemResponse($company_gateway);
|
2019-10-03 05:23:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param UpdateCompanyGatewayRequest $request
|
|
|
|
* @param CompanyGateway $company_gateway
|
2024-06-16 00:30:25 +02:00
|
|
|
* @return Response| \Illuminate\Http\JsonResponse
|
2019-10-07 06:09:04 +02:00
|
|
|
*
|
2019-12-30 22:59:12 +01:00
|
|
|
*
|
2019-10-07 06:09:04 +02:00
|
|
|
* @OA\Put(
|
|
|
|
* path="/api/v1/company_gateways/{id}",
|
|
|
|
* operationId="updateCompanyGateway",
|
|
|
|
* tags={"company_gateways"},
|
|
|
|
* summary="Updates an CompanyGateway",
|
|
|
|
* description="Handles the updating of an CompanyGateway by id",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2019-10-07 06:09:04 +02:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="id",
|
|
|
|
* in="path",
|
|
|
|
* description="The CompanyGateway Hashed ID",
|
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns the CompanyGateway object",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
2019-10-07 06:09:04 +02:00
|
|
|
* @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/CompanyGateway"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
2019-12-30 22:59:12 +01:00
|
|
|
* response="default",
|
2019-10-07 06:09:04 +02:00
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
2019-12-30 22:59:12 +01:00
|
|
|
*/
|
2019-10-03 05:23:00 +02:00
|
|
|
public function update(UpdateCompanyGatewayRequest $request, CompanyGateway $company_gateway)
|
|
|
|
{
|
|
|
|
$company_gateway->fill($request->all());
|
2019-11-11 13:21:19 +01:00
|
|
|
|
2023-10-16 03:05:19 +02:00
|
|
|
/*Always ensure at least one fees and limits object is set per gateway*/
|
2024-01-14 05:05:00 +01:00
|
|
|
$gateway_types = $company_gateway->driver(new Client())->getAvailableMethods();
|
|
|
|
|
2023-10-16 03:05:19 +02:00
|
|
|
$fees_and_limits = $company_gateway->fees_and_limits;
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2023-10-16 03:05:19 +02:00
|
|
|
foreach($gateway_types as $key => $gateway_type) {
|
|
|
|
if(!property_exists($fees_and_limits, $key)) {
|
2024-01-14 05:05:00 +01:00
|
|
|
$fees_and_limits->{$key} = new FeesAndLimits();
|
2023-10-16 03:05:19 +02:00
|
|
|
}
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|
2019-11-11 13:21:19 +01:00
|
|
|
|
2023-10-16 03:05:19 +02:00
|
|
|
$company_gateway->fees_and_limits = $fees_and_limits;
|
2019-10-03 05:23:00 +02:00
|
|
|
$company_gateway->save();
|
|
|
|
|
2023-07-21 13:58:04 +02:00
|
|
|
if($company_gateway->gateway_key == $this->checkout_key) {
|
|
|
|
CheckoutSetupWebhook::dispatch($company_gateway->company->company_key, $company_gateway->fresh()->id);
|
2024-06-14 09:09:44 +02:00
|
|
|
} elseif($company_gateway->gateway_key == $this->forte_key) {
|
|
|
|
|
2024-03-19 00:38:54 +01:00
|
|
|
dispatch(function () use ($company_gateway) {
|
|
|
|
MultiDB::setDb($company_gateway->company->db);
|
|
|
|
$company_gateway->driver()->updateFees();
|
|
|
|
})->afterResponse();
|
|
|
|
|
2023-07-21 13:58:04 +02:00
|
|
|
}
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2019-10-03 05:23:00 +02:00
|
|
|
return $this->itemResponse($company_gateway);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param DestroyCompanyGatewayRequest $request
|
|
|
|
* @param CompanyGateway $company_gateway
|
2024-06-16 00:30:25 +02:00
|
|
|
* @return Response| \Illuminate\Http\JsonResponse
|
2019-10-07 06:09:04 +02:00
|
|
|
*
|
2019-12-30 22:59:12 +01:00
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @throws \Exception
|
2019-10-07 06:09:04 +02:00
|
|
|
* @OA\Delete(
|
|
|
|
* path="/api/v1/company_gateways/{id}",
|
|
|
|
* operationId="deleteCompanyGateway",
|
|
|
|
* tags={"company_gateways"},
|
|
|
|
* summary="Deletes a CompanyGateway",
|
|
|
|
* description="Handles the deletion of an CompanyGateway by id",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2019-10-07 06:09:04 +02:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="id",
|
|
|
|
* in="path",
|
|
|
|
* description="The CompanyGateway Hashed ID",
|
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns a HTTP status",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
2019-10-07 06:09:04 +02:00
|
|
|
* @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\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
2019-12-30 22:59:12 +01:00
|
|
|
* response="default",
|
2019-10-07 06:09:04 +02:00
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
2019-10-03 05:23:00 +02:00
|
|
|
*/
|
|
|
|
public function destroy(DestroyCompanyGatewayRequest $request, CompanyGateway $company_gateway)
|
|
|
|
{
|
2024-01-14 05:05:00 +01:00
|
|
|
$company_gateway->driver(new Client())
|
2021-08-17 06:01:11 +02:00
|
|
|
->disconnect();
|
|
|
|
|
2019-10-03 05:23:00 +02:00
|
|
|
$company_gateway->delete();
|
|
|
|
|
2021-01-17 05:28:03 +01:00
|
|
|
return $this->itemResponse($company_gateway->fresh());
|
2019-10-03 05:23:00 +02:00
|
|
|
}
|
2020-06-04 00:18:27 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
/**
|
|
|
|
* Perform bulk actions on the list view.
|
2020-06-04 00:18:27 +02:00
|
|
|
*
|
2024-06-16 00:30:25 +02:00
|
|
|
* @return Response| \Illuminate\Http\JsonResponse
|
2020-06-04 00:18:27 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* @OA\Post(
|
|
|
|
* path="/api/v1/company_gateways/bulk",
|
|
|
|
* operationId="bulkCompanyGateways",
|
|
|
|
* tags={"company_gateways"},
|
|
|
|
* summary="Performs bulk actions on an array of company_gateways",
|
|
|
|
* description="",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2020-06-04 00:18:27 +02:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/index"),
|
|
|
|
* @OA\RequestBody(
|
|
|
|
* description="Array of company gateway IDs",
|
|
|
|
* 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 Company Gateways response",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
2020-06-04 00:18:27 +02:00
|
|
|
* @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/CompanyGateway"),
|
|
|
|
* ),
|
|
|
|
* @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"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*/
|
2023-01-22 05:11:33 +01:00
|
|
|
public function bulk(BulkCompanyGatewayRequest $request)
|
2020-06-04 00:18:27 +02:00
|
|
|
{
|
2023-01-22 05:11:33 +01:00
|
|
|
$action = $request->input('action');
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2023-01-22 05:11:33 +01:00
|
|
|
$company_gateways = CompanyGateway::withTrashed()
|
2023-01-22 06:40:02 +01:00
|
|
|
->whereIn('id', $request->ids)
|
2023-01-22 06:34:47 +01:00
|
|
|
->company()
|
2023-01-22 05:11:33 +01:00
|
|
|
->cursor()
|
|
|
|
->each(function ($company_gateway, $key) use ($action) {
|
2023-02-16 02:36:09 +01:00
|
|
|
$this->company_repo->{$action}($company_gateway);
|
|
|
|
});
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2023-01-22 06:40:02 +01:00
|
|
|
return $this->listResponse(CompanyGateway::withTrashed()->company()->whereIn('id', $request->ids));
|
2020-06-04 00:18:27 +02:00
|
|
|
}
|
2024-03-17 02:07:20 +01:00
|
|
|
|
|
|
|
public function test(TestCompanyGatewayRequest $request, CompanyGateway $company_gateway)
|
|
|
|
{
|
|
|
|
|
|
|
|
return response()->json(['message' => $company_gateway->driver()->auth() ? 'true' : 'false'], 200);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-03-18 02:58:42 +01:00
|
|
|
public function importCustomers(TestCompanyGatewayRequest $request, CompanyGateway $company_gateway)
|
|
|
|
{
|
2024-06-14 09:09:44 +02:00
|
|
|
|
2024-03-18 03:50:12 +01:00
|
|
|
//Throttle here
|
2024-06-14 09:09:44 +02:00
|
|
|
if (Cache::has("throttle_polling:import_customers:{$company_gateway->company->company_key}:{$company_gateway->hashed_id}")) {
|
2024-04-02 03:37:55 +02:00
|
|
|
return response()->json(['message' => 'Please wait whilst your previous attempts complete.'], 200);
|
2024-06-14 09:09:44 +02:00
|
|
|
}
|
2024-03-18 03:50:12 +01:00
|
|
|
|
2024-06-14 09:09:44 +02:00
|
|
|
dispatch(function () use ($company_gateway) {
|
2024-03-18 02:58:42 +01:00
|
|
|
MultiDB::setDb($company_gateway->company->db);
|
|
|
|
$company_gateway->driver()->importCustomers();
|
|
|
|
})->afterResponse();
|
|
|
|
|
2024-03-18 03:50:12 +01:00
|
|
|
Cache::put("throttle_polling:import_customers:{$company_gateway->company->company_key}:{$company_gateway->hashed_id}", true, 300);
|
|
|
|
|
2024-03-18 02:58:42 +01:00
|
|
|
return response()->json(['message' => ctrans('texts.import_started')], 200);
|
|
|
|
}
|
|
|
|
|
2019-10-03 05:23:00 +02:00
|
|
|
}
|