mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Import stripe customers and update their payment methods
This commit is contained in:
parent
841ad2764f
commit
12d8da942e
@ -12,6 +12,7 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Jobs\Util\ImportStripeCustomers;
|
||||
use App\Jobs\Util\StripeUpdatePaymentMethods;
|
||||
|
||||
class StripeController extends BaseController
|
||||
@ -29,6 +30,22 @@ class StripeController extends BaseController
|
||||
}
|
||||
|
||||
|
||||
return response()->json(['message' => 'Unauthorized'], 403);
|
||||
}
|
||||
|
||||
public function import()
|
||||
{
|
||||
|
||||
if(auth()->user()->isAdmin())
|
||||
{
|
||||
|
||||
ImportStripeCustomers::dispatch(auth()->user()->getCompany());
|
||||
|
||||
return response()->json(['message' => 'Processing'], 403);
|
||||
|
||||
}
|
||||
|
||||
|
||||
return response()->json(['message' => 'Unauthorized'], 403);
|
||||
}
|
||||
|
||||
|
68
app/Jobs/Util/ImportStripeCustomers.php
Normal file
68
app/Jobs/Util/ImportStripeCustomers.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?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://opensource.org/licenses/AAL
|
||||
*/
|
||||
namespace App\Jobs\Util;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Client;
|
||||
use App\Models\CompanyGateway;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
|
||||
class ImportStripeCustomers implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public $company;
|
||||
|
||||
private $stripe_keys = ['d14dd26a47cecc30fdd65700bfb67b34', 'd14dd26a37cecc30fdd65700bfb55b23'];
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $event_id
|
||||
* @param $entity
|
||||
*/
|
||||
public function __construct($company)
|
||||
{
|
||||
$this->company = $company;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
MultiDB::setDb($this->company->db);
|
||||
|
||||
$cgs = CompanyGateway::where('company_id', $this->company->id)
|
||||
->whereIn('gateway_key', $this->stripe_keys)
|
||||
->get();
|
||||
|
||||
$cgs->each(function ($company_gateway){
|
||||
|
||||
$company_gateway->driver(new Client)->importCustomers();
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public function failed($exception)
|
||||
{
|
||||
nlog("Stripe import customer methods exception");
|
||||
nlog($exception->getMessage());
|
||||
}
|
||||
}
|
@ -48,6 +48,9 @@ class ImportCustomers
|
||||
$this->addCustomer($customer);
|
||||
}
|
||||
|
||||
/* Now call the update payment methods handler*/
|
||||
$this->stripe->updateAllPaymentMethods();
|
||||
|
||||
}
|
||||
|
||||
private function addCustomer(Customer $customer)
|
||||
|
@ -25,6 +25,7 @@ use App\PaymentDrivers\Stripe\ACH;
|
||||
use App\PaymentDrivers\Stripe\Alipay;
|
||||
use App\PaymentDrivers\Stripe\Charge;
|
||||
use App\PaymentDrivers\Stripe\CreditCard;
|
||||
use App\PaymentDrivers\Stripe\ImportCustomers;
|
||||
use App\PaymentDrivers\Stripe\SOFORT;
|
||||
use App\PaymentDrivers\Stripe\UpdatePaymentMethods;
|
||||
use App\PaymentDrivers\Stripe\Utilities;
|
||||
@ -513,9 +514,10 @@ class StripePaymentDriver extends BaseDriver
|
||||
* Phone
|
||||
* Email
|
||||
*/
|
||||
public function importAndUpdateCustomers()
|
||||
public function importCustomers()
|
||||
{
|
||||
|
||||
return (new ImportCustomers($this))->run();
|
||||
//match clients based on the gateway_customer_reference column
|
||||
|
||||
}
|
||||
|
@ -184,6 +184,7 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a
|
||||
// Route::delete('hooks/{subscription_id}', 'SubscriptionController@unsubscribe')->name('hooks.unsubscribe');
|
||||
|
||||
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::resource('subscriptions', 'SubscriptionController');
|
||||
Route::post('subscriptions/bulk', 'SubscriptionController@bulk')->name('subscriptions.bulk');
|
||||
|
Loading…
x
Reference in New Issue
Block a user