mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Update customer details
This commit is contained in:
parent
0c0687febe
commit
be19d42e78
@ -14,6 +14,7 @@ namespace App\Http\Livewire;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\CompanyGateway;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Str;
|
||||
use Livewire\Component;
|
||||
@ -105,6 +106,8 @@ class RequiredClientInfo extends Component
|
||||
|
||||
public $company;
|
||||
|
||||
public $company_gateway_id;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
MultiDB::setDb($this->company->db);
|
||||
@ -141,6 +144,8 @@ class RequiredClientInfo extends Component
|
||||
'client_postal_code' => $this->contact->client->postal_code,
|
||||
]);
|
||||
|
||||
//if stripe is enabled, we want to update the customer at this point.
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -150,6 +155,7 @@ class RequiredClientInfo extends Component
|
||||
|
||||
private function updateClientDetails(array $data): bool
|
||||
{
|
||||
nlog($this->company->id);
|
||||
$client = [];
|
||||
$contact = [];
|
||||
|
||||
@ -172,6 +178,16 @@ class RequiredClientInfo extends Component
|
||||
->push();
|
||||
|
||||
if ($contact_update && $client_update) {
|
||||
|
||||
$cg = CompanyGateway::find($this->company_gateway_id);
|
||||
|
||||
if($cg && $cg->update_details){
|
||||
$payment_gateway = $cg->driver($this->client)->init();
|
||||
|
||||
if(method_exists($payment_gateway, "updateCustomer"))
|
||||
$payment_gateway->updateCustomer();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -58,12 +58,12 @@ class UpdateCustomer implements ShouldQueue
|
||||
|
||||
$company = Company::where('company_key', $this->company_key)->first();
|
||||
|
||||
if($company->id !== config('ninja.ninja_default_company_id'))
|
||||
return;
|
||||
|
||||
$company_gateway = CompanyGateway::find($this->company_gateway_id);
|
||||
$client = Client::withTrashed()->find($this->client_id);
|
||||
|
||||
if(!$company_gateway->update_details)
|
||||
return;
|
||||
|
||||
$stripe = $company_gateway->driver($client)->init();
|
||||
|
||||
$customer = $stripe->findOrCreateCustomer();
|
||||
|
@ -511,6 +511,36 @@ class StripePaymentDriver extends BaseDriver
|
||||
}
|
||||
}
|
||||
|
||||
public function updateCustomer()
|
||||
{
|
||||
if($this->client)
|
||||
{
|
||||
|
||||
$customer = $this->findOrCreateCustomer();
|
||||
//Else create a new record
|
||||
$data['name'] = $this->client->present()->name();
|
||||
$data['phone'] = substr($this->client->present()->phone(), 0, 20);
|
||||
|
||||
$data['address']['line1'] = $this->client->address1;
|
||||
$data['address']['line2'] = $this->client->address2;
|
||||
$data['address']['city'] = $this->client->city;
|
||||
$data['address']['postal_code'] = $this->client->postal_code;
|
||||
$data['address']['state'] = $this->client->state;
|
||||
$data['address']['country'] = $this->client->country ? $this->client->country->iso_3166_2 : '';
|
||||
|
||||
$data['shipping']['name'] = $this->client->present()->name();
|
||||
$data['shipping']['address']['line1'] = $this->client->shipping_address1;
|
||||
$data['shipping']['address']['line2'] = $this->client->shipping_address2;
|
||||
$data['shipping']['address']['city'] = $this->client->shipping_city;
|
||||
$data['shipping']['address']['postal_code'] = $this->client->shipping_postal_code;
|
||||
$data['shipping']['address']['state'] = $this->client->shipping_state;
|
||||
$data['shipping']['address']['country'] = $this->client->shipping_country ? $this->client->shipping_country->iso_3166_2 : '';
|
||||
|
||||
\Stripe\Customer::update($customer->id, $data, $this->stripe_connect_auth);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function refund(Payment $payment, $amount, $return_client_response = false)
|
||||
{
|
||||
$this->init();
|
||||
|
@ -11,7 +11,7 @@
|
||||
@endpush
|
||||
|
||||
@section('body')
|
||||
@livewire('required-client-info', ['fields' => method_exists($gateway, 'getClientRequiredFields') ? $gateway->getClientRequiredFields() : [], 'contact' => auth()->guard('contact')->user(), 'countries' => $countries, 'company' => $company])
|
||||
@livewire('required-client-info', ['fields' => method_exists($gateway, 'getClientRequiredFields') ? $gateway->getClientRequiredFields() : [], 'contact' => auth()->guard('contact')->user(), 'countries' => $countries, 'company' => $company, 'company_gateway_id' => $gateway->company_gateway->id])
|
||||
|
||||
<div class="container mx-auto grid grid-cols-12 opacity-25 pointer-events-none" data-ref="gateway-container">
|
||||
<div class="col-span-12 lg:col-span-6 lg:col-start-4 bg-white shadow rounded-lg">
|
||||
|
Loading…
Reference in New Issue
Block a user