2021-05-17 06:02:43 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @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)
|
2021-05-17 06:02:43 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2021-05-17 06:02:43 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2021-05-17 10:56:14 +02:00
|
|
|
use App\Jobs\Util\ImportStripeCustomers;
|
2021-05-17 06:02:43 +02:00
|
|
|
use App\Jobs\Util\StripeUpdatePaymentMethods;
|
2021-09-02 04:08:16 +02:00
|
|
|
use App\Libraries\MultiDB;
|
2021-08-15 07:49:36 +02:00
|
|
|
use App\Models\Client;
|
2021-08-15 07:13:20 +02:00
|
|
|
use App\Models\CompanyGateway;
|
2021-10-09 09:07:05 +02:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2021-05-17 06:02:43 +02:00
|
|
|
|
|
|
|
class StripeController extends BaseController
|
|
|
|
{
|
2022-06-21 11:57:17 +02:00
|
|
|
use MakesHash;
|
2021-05-17 06:02:43 +02:00
|
|
|
|
2021-08-15 07:13:20 +02:00
|
|
|
private $stripe_keys = ['d14dd26a47cecc30fdd65700bfb67b34', 'd14dd26a37cecc30fdd65700bfb55b23'];
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
public function update()
|
|
|
|
{
|
2023-08-04 10:13:26 +02:00
|
|
|
/** @var \App\Models\User $user */
|
|
|
|
$user = auth()->user();
|
|
|
|
|
|
|
|
if ($user->isAdmin()) {
|
|
|
|
StripeUpdatePaymentMethods::dispatch($user->company());
|
2021-05-17 06:02:43 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
return response()->json(['message' => 'Processing'], 200);
|
|
|
|
}
|
2021-05-17 06:02:43 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
return response()->json(['message' => 'Unauthorized'], 403);
|
|
|
|
}
|
2021-05-17 06:02:43 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
public function import()
|
|
|
|
{
|
2023-08-04 10:13:26 +02:00
|
|
|
/** @var \App\Models\User $user */
|
|
|
|
$user = auth()->user();
|
2021-05-17 10:56:14 +02:00
|
|
|
|
2023-08-04 10:13:26 +02:00
|
|
|
if ($user->isAdmin()) {
|
|
|
|
ImportStripeCustomers::dispatch($user->company());
|
2021-07-09 02:44:34 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
return response()->json(['message' => 'Processing'], 200);
|
|
|
|
}
|
2021-07-09 02:44:34 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
return response()->json(['message' => 'Unauthorized'], 403);
|
|
|
|
}
|
2021-05-17 10:56:14 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
public function verify()
|
|
|
|
{
|
2023-08-04 10:13:26 +02:00
|
|
|
/** @var \App\Models\User $user */
|
|
|
|
$user = auth()->user();
|
|
|
|
|
|
|
|
if ($user->isAdmin()) {
|
|
|
|
MultiDB::findAndSetDbByCompanyKey($user->company()->company_key);
|
2021-05-17 10:56:14 +02:00
|
|
|
|
2023-08-04 10:13:26 +02:00
|
|
|
/** @var \App\Models\CompanyGateway $company_gateway */
|
|
|
|
$company_gateway = CompanyGateway::where('company_id', $user->company()->id)
|
2022-06-21 11:57:17 +02:00
|
|
|
->where('is_deleted', 0)
|
|
|
|
->whereIn('gateway_key', $this->stripe_keys)
|
|
|
|
->first();
|
2021-05-17 06:02:43 +02:00
|
|
|
|
2024-01-14 05:05:00 +01:00
|
|
|
return $company_gateway->driver(new Client())->verifyConnect();
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2021-08-15 07:13:20 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
return response()->json(['message' => 'Unauthorized'], 403);
|
|
|
|
}
|
2021-08-15 07:13:20 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
public function disconnect(string $company_gateway_id)
|
|
|
|
{
|
2023-08-04 10:13:26 +02:00
|
|
|
/** @var \App\Models\User $user */
|
|
|
|
$user = auth()->user();
|
|
|
|
|
|
|
|
/** @var \App\Models\CompanyGateway $company_gateway */
|
|
|
|
$company_gateway = CompanyGateway::where('company_id', $user->company()->id)
|
2022-06-21 11:57:17 +02:00
|
|
|
->where('id', $this->decodePrimaryKey($company_gateway_id))
|
|
|
|
->whereIn('gateway_key', $this->stripe_keys)
|
|
|
|
->firstOrFail();
|
2021-08-15 07:13:20 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
return $company_gateway->driver()->disconnect();
|
|
|
|
}
|
|
|
|
}
|