Merge pull request #6458 from turbo124/v5-develop

Stripe Verify
This commit is contained in:
David Bomba 2021-08-15 15:17:57 +10:00 committed by GitHub
commit e17cd1ba2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 112 additions and 1 deletions

View File

@ -14,10 +14,13 @@ namespace App\Http\Controllers;
use App\Jobs\Util\ImportStripeCustomers;
use App\Jobs\Util\StripeUpdatePaymentMethods;
use App\Models\CompanyGateway;
class StripeController extends BaseController
{
private $stripe_keys = ['d14dd26a47cecc30fdd65700bfb67b34', 'd14dd26a37cecc30fdd65700bfb55b23'];
public function update()
{
if(auth()->user()->isAdmin())
@ -50,4 +53,22 @@ class StripeController extends BaseController
return response()->json(['message' => 'Unauthorized'], 403);
}
public function verify()
{
if(auth()->user()->isAdmin())
{
$company_gateway = CompanyGateway::where('company_id', auth()->user()->company()->id)
->where('is_deleted',0)
->whereIn('gateway_key', $this->stripe_keys)
->first();
return $company_gateway->driver(new Client)->verifyConnect();
}
return response()->json(['message' => 'Unauthorized'], 403);
}
}

View File

@ -49,6 +49,7 @@ class ImportStripeCustomers implements ShouldQueue
MultiDB::setDb($this->company->db);
$cgs = CompanyGateway::where('company_id', $this->company->id)
->where('is_deleted',0)
->whereIn('gateway_key', $this->stripe_keys)
->get();

View File

@ -0,0 +1,75 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\PaymentDrivers\Stripe\Connect;
use App\Exceptions\PaymentFailed;
use App\Http\Requests\ClientPortal\PaymentMethod\VerifyPaymentMethodRequest;
use App\Http\Requests\Request;
use App\Jobs\Mail\NinjaMailerJob;
use App\Jobs\Mail\NinjaMailerObject;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Mail\Gateways\ACHVerificationNotification;
use App\Models\ClientGatewayToken;
use App\Models\GatewayType;
use App\Models\Payment;
use App\Models\PaymentType;
use App\Models\SystemLog;
use App\PaymentDrivers\StripePaymentDriver;
use App\Utils\Traits\MakesHash;
use Exception;
use Stripe\Customer;
use Stripe\Exception\CardException;
use Stripe\Exception\InvalidRequestException;
class Verify
{
use MakesHash;
/** @var StripePaymentDriver */
public $stripe;
public function __construct(StripePaymentDriver $stripe)
{
$this->stripe = $stripe;
}
public function run()
{
$this->stripe->init();
if($this->stripe->stripe_connect && strlen($this->company_gateway->getConfigField('account_id')) < 1))
return response()->json("Stripe Connect not authenticated", 400);
$customers = Customer::all([], $this->stripe->stripe_connect_auth);
$stripe_customers = $this->stripe->company_gateway->client_gateway_tokens->map(function ($cgt){
$customer = Customer::retrieve($cgt->gateway_customer_reference, $this->stripe->stripe_connect_auth);
return [
'customer' => $cgt->gateway_customer_reference,
'record' => $customer
];
});
$data = [
'stripe_customer_count' => count($customers),
'stripe_customers' => $stripe_customers,
];
return response()->json($data, 200);
}
}

View File

@ -48,6 +48,9 @@ class ImportCustomers
$this->update_payment_methods = new UpdatePaymentMethods($this->stripe);
if(strlen($this->stripe->company_gateway->getConfigField('account_id')) < 1)
throw new \Exception('Stripe Connect has not been configured');
$customers = Customer::all([], $this->stripe->stripe_connect_auth);
foreach($customers as $customer)

View File

@ -25,6 +25,7 @@ use App\Models\SystemLog;
use App\PaymentDrivers\Stripe\ACH;
use App\PaymentDrivers\Stripe\Alipay;
use App\PaymentDrivers\Stripe\Charge;
use App\PaymentDrivers\Stripe\Connect\Verify;
use App\PaymentDrivers\Stripe\CreditCard;
use App\PaymentDrivers\Stripe\ImportCustomers;
use App\PaymentDrivers\Stripe\SOFORT;
@ -86,7 +87,10 @@ class StripePaymentDriver extends BaseDriver
{
Stripe::setApiKey(config('ninja.ninja_stripe_key'));
$this->stripe_connect_auth = ["stripe_account" => $this->company_gateway->getConfigField('account_id')];
if(strlen($this->company_gateway->getConfigField('account_id')) > 1)
$this->stripe_connect_auth = ["stripe_account" => $this->company_gateway->getConfigField('account_id')];
throw new \Exception('Stripe Connect has not been configured');
}
else
{
@ -533,4 +537,9 @@ class StripePaymentDriver extends BaseDriver
//match clients based on the gateway_customer_reference column
}
public function verifyConnect()
{
return (new Verify($this))->run();
}
}

View File

@ -190,6 +190,8 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a
Route::post('stripe/update_payment_methods', 'StripeController@update')->middleware('password_protected')->name('stripe.update');
Route::post('stripe/import_customers', 'StripeController@import')->middleware('password_protected')->name('stripe.import');
Route::post('stripe/verify', 'StripeController@verify')->middleware('password_protected')->name('stripe.verify');
Route::resource('subscriptions', 'SubscriptionController');
Route::post('subscriptions/bulk', 'SubscriptionController@bulk')->name('subscriptions.bulk');