mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 21:22:58 +01:00
Update customers for stripe
This commit is contained in:
parent
b2ac80a814
commit
cbcf0dc238
@ -97,10 +97,6 @@ class UpdateClientRequest extends Request
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
if (isset($input['group_settings_id'])) {
|
||||
$input['group_settings_id'] = $this->decodePrimaryKey($input['group_settings_id']);
|
||||
}
|
||||
|
||||
/* If the user removes the currency we must always set the default */
|
||||
if (array_key_exists('settings', $input) && ! array_key_exists('currency_id', $input['settings'])) {
|
||||
$input['settings']['currency_id'] = (string) auth()->user()->company()->settings->currency_id;
|
||||
|
86
app/PaymentDrivers/Stripe/Jobs/UpdateCustomer.php
Normal file
86
app/PaymentDrivers/Stripe/Jobs/UpdateCustomer.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\PaymentDrivers\Stripe\Jobs;
|
||||
|
||||
use App\Jobs\Mail\PaymentFailedMailer;
|
||||
use App\Jobs\Util\SystemLogger;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Client;
|
||||
use App\Models\Company;
|
||||
use App\Models\CompanyGateway;
|
||||
use App\Models\GatewayType;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\PaymentHash;
|
||||
use App\Models\PaymentType;
|
||||
use App\Models\SystemLog;
|
||||
use App\PaymentDrivers\Stripe\Utilities;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class UpdateCustomer implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, Utilities;
|
||||
|
||||
public $tries = 1;
|
||||
|
||||
public $deleteWhenMissingModels = true;
|
||||
|
||||
public int $company_gateway_id;
|
||||
|
||||
public string $company_key;
|
||||
|
||||
private int $client_id;
|
||||
|
||||
private string $customer_id;
|
||||
|
||||
public function __construct(string $company_key, int $company_gateway_id, int $client_id, string $customer_id)
|
||||
{
|
||||
$this->company_key = $company_key;
|
||||
$this->company_gateway_id = $company_gateway_id;
|
||||
$this->client_id = $client_id;
|
||||
$this->customer_id = $customer_id;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
MultiDB::findAndSetDbByCompanyKey($this->company_key);
|
||||
|
||||
$company = Company::where('company_key', $this->company_key)->first();
|
||||
|
||||
$company_gateway = CompanyGateway::find($this->company_gateway_id);
|
||||
|
||||
$stripe = $company_gateway->driver()->init();
|
||||
|
||||
$customer = $company_gateway->getCustomer($this->customer_id);
|
||||
|
||||
$client = Client::withTrashed()->find($this->client_id);
|
||||
|
||||
//Else create a new record
|
||||
$data['name'] = $client->present()->name();
|
||||
$data['phone'] = substr($client->present()->phone(), 0, 20);
|
||||
|
||||
$data['address']['line1'] = $client->address1;
|
||||
$data['address']['line2'] = $client->address2;
|
||||
$data['address']['city'] = $client->city;
|
||||
$data['address']['postal_code'] = $client->postal_code;
|
||||
$data['address']['state'] = $client->state;
|
||||
$data['address']['country'] = $client->country ? $client->country->iso_3166_2 : '';
|
||||
|
||||
\Stripe\Customer::update($this->customer_id, $data, $stripe->stripe_connect_auth);
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user