mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-17 18:54:38 -04:00
Stripe import customer
This commit is contained in:
parent
7f21696cca
commit
87c000a3e1
@ -33,9 +33,6 @@ class ClientFactory
|
|||||||
$client->client_hash = Str::random(40);
|
$client->client_hash = Str::random(40);
|
||||||
$client->settings = ClientSettings::defaults();
|
$client->settings = ClientSettings::defaults();
|
||||||
|
|
||||||
// $client_contact = ClientContactFactory::create($company_id, $user_id);
|
|
||||||
// $client->contacts->add($client_contact);
|
|
||||||
|
|
||||||
return $client;
|
return $client;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,13 +3,16 @@
|
|||||||
namespace App\Mail;
|
namespace App\Mail;
|
||||||
|
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
|
use App\Utils\Traits\MakesInvoiceHtml;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Mail\Mailable;
|
use Illuminate\Mail\Mailable;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Support\Facades\File;
|
||||||
|
|
||||||
class DownloadBackup extends Mailable
|
class DownloadBackup extends Mailable
|
||||||
{
|
{
|
||||||
// use Queueable, SerializesModels;
|
// use Queueable, SerializesModels;
|
||||||
|
use MakesInvoiceHtml;
|
||||||
|
|
||||||
public $file_path;
|
public $file_path;
|
||||||
|
|
||||||
@ -27,19 +30,20 @@ class DownloadBackup extends Mailable
|
|||||||
*/
|
*/
|
||||||
public function build()
|
public function build()
|
||||||
{
|
{
|
||||||
|
$template = File::get(resource_path('views/email/admin/download_files.blade.php'));
|
||||||
|
|
||||||
$company = Company::where('company_key', $this->company->company_key)->first();
|
$company = Company::where('company_key', $this->company->company_key)->first();
|
||||||
|
|
||||||
|
$view = $this->renderView($template, [
|
||||||
|
'url' => $this->file_path,
|
||||||
|
'logo' => $company->present()->logo,
|
||||||
|
'whitelabel' => $company->account->isPaid() ? true : false,
|
||||||
|
'settings' => $company->settings,
|
||||||
|
'greeting' => $company->present()->name(),
|
||||||
|
]);
|
||||||
|
|
||||||
return $this->from(config('mail.from.address'), config('mail.from.name'))
|
return $this->from(config('mail.from.address'), config('mail.from.name'))
|
||||||
->subject(ctrans('texts.download_backup_subject', ['company' => $company->present()->name()]))
|
->subject(ctrans('texts.download_backup_subject', ['company' => $company->present()->name()]))
|
||||||
->markdown(
|
->html($view);
|
||||||
'email.admin.download_files',
|
|
||||||
[
|
|
||||||
'url' => $this->file_path,
|
|
||||||
'logo' => $company->present()->logo,
|
|
||||||
'whitelabel' => $company->account->isPaid() ? true : false,
|
|
||||||
'settings' => $company->settings,
|
|
||||||
'greeting' => $company->present()->name(),
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
namespace App\PaymentDrivers\Stripe;
|
namespace App\PaymentDrivers\Stripe;
|
||||||
|
|
||||||
use App\Factory\ClientContactFactory;
|
use App\Factory\ClientContactFactory;
|
||||||
|
use App\Factory\ClientFactory;
|
||||||
use App\Factory\ClientGatewayTokenFactory;
|
use App\Factory\ClientGatewayTokenFactory;
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
use App\Models\ClientGatewayToken;
|
use App\Models\ClientGatewayToken;
|
||||||
@ -56,30 +57,36 @@ class ImportCustomers
|
|||||||
private function addCustomer(Customer $customer)
|
private function addCustomer(Customer $customer)
|
||||||
{
|
{
|
||||||
|
|
||||||
$account = $this->company_gateway->company->account;
|
$account = $this->stripe->company_gateway->company->account;
|
||||||
|
|
||||||
$existing_customer = $this->company_gateway
|
$existing_customer = $this->stripe
|
||||||
|
->company_gateway
|
||||||
->client_gateway_tokens()
|
->client_gateway_tokens()
|
||||||
->where('gateway_customer_reference', $customer->id)
|
->where('gateway_customer_reference', $customer->id)
|
||||||
->exists();
|
->exists();
|
||||||
|
|
||||||
|
|
||||||
if($existing_customer)
|
if($existing_customer)
|
||||||
return
|
return;
|
||||||
|
|
||||||
$client = ClientFactory::create($this->company_gateway->company_id, $this->company_gateway->user_id);
|
$client = ClientFactory::create($this->stripe->company_gateway->company_id, $this->stripe->company_gateway->user_id);
|
||||||
$client->address1 = $customer->address->line1 ?: '';
|
|
||||||
$client->address2 = $customer->address->line2 ?: '';
|
|
||||||
$client->city = $customer->address->city ?: '';
|
|
||||||
$client->state = $customer->address->state ?: '';
|
|
||||||
|
|
||||||
if($customer->address->country){
|
if(property_exists($customer, 'address'))
|
||||||
|
{
|
||||||
|
$client->address1 = property_exists($customer->address, 'line1') ? $customer->address->line1 : '';
|
||||||
|
$client->address2 = property_exists($customer->address, 'line2') ? $customer->address->line2 : '';
|
||||||
|
$client->city = property_exists($customer->address, 'city') ? $customer->address->city : '';
|
||||||
|
$client->state = property_exists($customer->address, 'state') ? $customer->address->state : '';
|
||||||
|
$client->phone = property_exists($customer->address, 'phone') ? $customer->phone : '';
|
||||||
|
|
||||||
$country = Country::where('iso_3166_2', $customer->address->country)->first()
|
if(property_exists($customer->address, 'country')){
|
||||||
|
|
||||||
if($country)
|
$country = Country::where('iso_3166_2', $customer->address->country)->first();
|
||||||
$client->country_id = $country->id;
|
|
||||||
|
|
||||||
|
if($country)
|
||||||
|
$client->country_id = $country->id;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($customer->currency) {
|
if($customer->currency) {
|
||||||
@ -96,12 +103,11 @@ class ImportCustomers
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$client->phone = $customer->phone ?: '';
|
$client->name = property_exists($customer, 'name') ? $customer->name : '';
|
||||||
$client->name = $customer->name ?: '';
|
|
||||||
|
|
||||||
if(!$account->isPaidHostedClient() && Client::where('company_id', $this->company_gateway->company_id)->count() <= config('ninja.quotas.free.clients')){
|
if(!$account->isPaidHostedClient() && Client::where('company_id', $this->stripe->company_gateway->company_id)->count() <= config('ninja.quotas.free.clients')){
|
||||||
|
|
||||||
$client->save()
|
$client->save();
|
||||||
|
|
||||||
$contact = ClientContactFactory::create($client->company_id, $client->user_id);
|
$contact = ClientContactFactory::create($client->company_id, $client->user_id);
|
||||||
$contact->client_id = $client->id;
|
$contact->client_id = $client->id;
|
||||||
|
@ -104,7 +104,7 @@ class UpdatePaymentMethods
|
|||||||
$cgt->token = $bank_account->id;
|
$cgt->token = $bank_account->id;
|
||||||
$cgt->gateway_customer_reference = $token->gateway_customer_reference;
|
$cgt->gateway_customer_reference = $token->gateway_customer_reference;
|
||||||
$cgt->company_gateway_id = $token->company_gateway_id;
|
$cgt->company_gateway_id = $token->company_gateway_id;
|
||||||
$cgt->gateway_type_id = GatewayType::BANK_TRANSFER
|
$cgt->gateway_type_id = GatewayType::BANK_TRANSFER;
|
||||||
$cgt->meta = new \stdClass;
|
$cgt->meta = new \stdClass;
|
||||||
$cgt->routing_number = $bank_account->routing_number;
|
$cgt->routing_number = $bank_account->routing_number;
|
||||||
$cgt->save();
|
$cgt->save();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user