1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-15 07:33:04 +01:00
invoiceninja/app/PaymentDrivers/Factory/ForteCustomerFactory.php

138 lines
4.4 KiB
PHP
Raw Normal View History

2024-03-18 07:01:00 +01:00
<?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\Factory;
use App\Models\Client;
use App\Models\Company;
class ForteCustomerFactory
{
public function convertToNinja(array $customer, Company $company): array
{
2024-06-14 09:09:44 +02:00
return
2024-03-18 07:01:00 +01:00
collect([
2024-06-14 09:09:44 +02:00
'name' => $customer['company_name'] ?? $customer['first_name'],
'contacts' => [
[
'first_name' => $customer['first_name'],
'last_name' => $customer['last_name'],
'email' => $this->getBillingAddress($customer)['email'],
'phone' => $this->getBillingAddress($customer)['phone'],
]
],
'settings' => [
'currency_id' => $company->settings->currency_id,
],
2024-03-19 00:38:54 +01:00
])->merge($this->getShippingAddress($customer))
->merge($this->getBillingAddress($customer))
2024-03-18 07:01:00 +01:00
->toArray();
}
// public function convertToGateway(Client $client): array
// {
2024-06-14 09:09:44 +02:00
2024-03-18 07:01:00 +01:00
// }
private function getBillingAddress(array $customer): array
{
if(isset($customer['default_billing_address_token'])) {
foreach($customer['addresses'] as $address) {
2024-06-14 09:09:44 +02:00
if($address['address_token'] != $customer['default_billing_address_token']) {
2024-03-18 07:01:00 +01:00
continue;
2024-06-14 09:09:44 +02:00
}
2024-03-18 07:01:00 +01:00
return [
'address1' => $address['physical_address']['street_line1'],
'address2' => $address['physical_address']['street_line2'],
'city' => $address['physical_address']['locality'],
'state' => $address['physical_address']['region'],
'postal_code' => $address['physical_address']['postal_code'],
'country_id' => '840',
'email' => $address['email'],
'phone' => $address['phone'],
];
}
}
if(isset($customer['addresses'][0])) {
$address = $customer['addresses'][0];
return [
'address1' => $address['physical_address']['street_line1'],
'address2' => $address['physical_address']['street_line2'],
'city' => $address['physical_address']['locality'],
'state' => $address['physical_address']['region'],
'postal_code' => $address['physical_address']['postal_code'],
'email' => $address['email'],
'phone' => $address['phone'],
'country_id' => '840',
];
}
return ['email' => '', 'phone' => ''];
}
private function getShippingAddress(array $customer): array
{
if(isset($customer['default_shipping_address_token'])) {
foreach($customer['addresses'] as $address) {
if($address['address_token'] != $customer['default_shipping_address_token']) {
continue;
}
return [
2024-03-19 00:38:54 +01:00
'shipping_address1' => $address['physical_address']['street_line1'],
'shipping_address2' => $address['physical_address']['street_line2'],
'shipping_city' => $address['physical_address']['locality'],
'shipping_state' => $address['physical_address']['region'],
'shipping_postal_code' => $address['physical_address']['postal_code'],
'shipping_country_id' => '840',
2024-03-18 07:01:00 +01:00
];
}
}
2024-06-14 09:09:44 +02:00
if(isset($customer['addresses'][1])) {
2024-03-18 07:01:00 +01:00
$address = $customer['addresses'][1];
return [
2024-03-19 00:38:54 +01:00
'shipping_address1' => $address['physical_address']['street_line1'],
'shipping_address2' => $address['physical_address']['street_line2'],
'shipping_city' => $address['physical_address']['locality'],
'shipping_state' => $address['physical_address']['region'],
'shipping_postal_code' => $address['physical_address']['postal_code'],
'shipping_country_id' => '840',
'email' => $address['email'],
'phone' => $address['phone'],
2024-03-18 07:01:00 +01:00
];
}
return ['email' => '', 'phone' => ''];
}
}