From f7b7732f04429057340cd698a76135071f8f3a65 Mon Sep 17 00:00:00 2001 From: = Date: Fri, 20 Aug 2021 22:44:39 +1000 Subject: [PATCH 1/6] Working on importing stripe customers by id --- app/PaymentDrivers/Stripe/ACH.php | 2 +- app/PaymentDrivers/Stripe/ImportCustomers.php | 26 +++++++++++++++++++ .../Stripe/UpdatePaymentMethods.php | 6 +++++ app/PaymentDrivers/StripePaymentDriver.php | 5 ++++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/app/PaymentDrivers/Stripe/ACH.php b/app/PaymentDrivers/Stripe/ACH.php index a17725225b08..5af1cbf05ab2 100644 --- a/app/PaymentDrivers/Stripe/ACH.php +++ b/app/PaymentDrivers/Stripe/ACH.php @@ -61,7 +61,7 @@ class ACH try { $source = Customer::createSource($customer->id, ['source' => $stripe_response->token->id], $this->stripe->stripe_connect_auth); - // $source = $this->stripe->stripe->customers->createSource($customer->id, ['source' => $stripe_response->token->id]); + } catch (InvalidRequestException $e) { throw new PaymentFailed($e->getMessage(), $e->getCode()); } diff --git a/app/PaymentDrivers/Stripe/ImportCustomers.php b/app/PaymentDrivers/Stripe/ImportCustomers.php index 1fae465da08d..2baf26d5bbd5 100644 --- a/app/PaymentDrivers/Stripe/ImportCustomers.php +++ b/app/PaymentDrivers/Stripe/ImportCustomers.php @@ -142,6 +142,32 @@ class ImportCustomers $this->update_payment_methods->updateMethods($customer, $client); } + public function importCustomer($customer_id) + { + + $this->stripe->init(); + + $this->update_payment_methods = new UpdatePaymentMethods($this->stripe); + + if(strlen($this->stripe->company_gateway->getConfigField('account_id')) < 1) + throw new StripeConnectFailure('Stripe Connect has not been configured'); + + $customer = Customer::retrieve($customer_id, $this->stripe_connect_auth); + + if(!$customer) + return; + + foreach($this->stripe->company_gateway->company->clients as $client) + { + if($client->present()->email() == $customer->email) { + + $this->update_payment_methods->updateMethods($customer, $client); + + } + } + + } + public function match() { $this->stripe->init(); diff --git a/app/PaymentDrivers/Stripe/UpdatePaymentMethods.php b/app/PaymentDrivers/Stripe/UpdatePaymentMethods.php index 596356a83148..74d09d4abe26 100644 --- a/app/PaymentDrivers/Stripe/UpdatePaymentMethods.php +++ b/app/PaymentDrivers/Stripe/UpdatePaymentMethods.php @@ -93,6 +93,12 @@ class UpdatePaymentMethods $this->addOrUpdateCard($method, $customer->id, $client, GatewayType::SOFORT); } + //$this->importBankAccounts($customer, $client); + } + + private function importBankAccounts($customer, $client) + { + } // private function addOrUpdateBankAccount($bank_account, $customer_reference, Client $client) diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 0dce16d84d16..7231cebbffc4 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -550,6 +550,11 @@ class StripePaymentDriver extends BaseDriver return (new ImportCustomers($this))->match(); } + public function importCustomer($customer_id) + { + return (new ImportCustomers($this))->importCustomer($customer_id); + } + public function verifyConnect() { return (new Verify($this))->run(); From 71b243bace9a4fefdcc6f1bbbc3322a55ac77569 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 21 Aug 2021 14:01:32 +1000 Subject: [PATCH 2/6] Fixes for client balances --- app/Jobs/Util/ReminderJob.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Jobs/Util/ReminderJob.php b/app/Jobs/Util/ReminderJob.php index e4240b49ac82..b468fb097c48 100644 --- a/app/Jobs/Util/ReminderJob.php +++ b/app/Jobs/Util/ReminderJob.php @@ -184,8 +184,12 @@ class ReminderJob implements ShouldQueue $invoice->fresh(); $invoice->service()->deletePdf(); + /* Refresh the client here to ensure the balance is fresh */ + $client = $invoice->client; + $client = $client->fresh(); + nlog("adjusting client balance and invoice balance by ". ($invoice->balance - $temp_invoice_balance)); - $invoice->client->service()->updateBalance($invoice->balance - $temp_invoice_balance)->save(); + $client->service()->updateBalance($invoice->balance - $temp_invoice_balance)->save(); $invoice->ledger()->updateInvoiceBalance($invoice->balance - $temp_invoice_balance, "Late Fee Adjustment for invoice {$invoice->number}"); return $invoice; From c3f05d5c8c2332050f835664bf9c4ec3bc09b4bb Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 21 Aug 2021 14:57:31 +1000 Subject: [PATCH 3/6] Handle company logo not present failure --- app/Utils/Traits/Uploadable.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/Utils/Traits/Uploadable.php b/app/Utils/Traits/Uploadable.php index f17cce270cd9..7852cbd3a1e0 100644 --- a/app/Utils/Traits/Uploadable.php +++ b/app/Utils/Traits/Uploadable.php @@ -40,5 +40,13 @@ trait Uploadable $entity->save(); } } + else{ + /* Catch Failures */ + $settings = $entity->settings; + $settings->company_logo = ''; + $entity->settings = $settings; + $entity->save(); + } + } } From f315ebd7152e9b9b889ff34bcad7567a4047d815 Mon Sep 17 00:00:00 2001 From: = Date: Sat, 21 Aug 2021 16:24:00 +1000 Subject: [PATCH 4/6] Fixes for tests --- app/Utils/Traits/Uploadable.php | 7 ------- tests/MockAccountData.php | 1 - 2 files changed, 8 deletions(-) diff --git a/app/Utils/Traits/Uploadable.php b/app/Utils/Traits/Uploadable.php index 7852cbd3a1e0..604bab5f5b1b 100644 --- a/app/Utils/Traits/Uploadable.php +++ b/app/Utils/Traits/Uploadable.php @@ -40,13 +40,6 @@ trait Uploadable $entity->save(); } } - else{ - /* Catch Failures */ - $settings = $entity->settings; - $settings->company_logo = ''; - $entity->settings = $settings; - $entity->save(); - } } } diff --git a/tests/MockAccountData.php b/tests/MockAccountData.php index fa078e1146ef..0e566900ad80 100644 --- a/tests/MockAccountData.php +++ b/tests/MockAccountData.php @@ -156,7 +156,6 @@ trait MockAccountData } } - $this->account = Account::factory()->create(); $this->company = Company::factory()->create([ 'account_id' => $this->account->id, From f83590a9dd6d31a822a23c972c42c70c961f5911 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 21 Aug 2021 17:25:37 +1000 Subject: [PATCH 5/6] Fixes for not finding company_logo on import --- app/Jobs/Util/Import.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/Jobs/Util/Import.php b/app/Jobs/Util/Import.php index 79a072f8b7cd..c452fe900ae1 100644 --- a/app/Jobs/Util/Import.php +++ b/app/Jobs/Util/Import.php @@ -403,11 +403,18 @@ class Import implements ShouldQueue $company_repository->save($data, $this->company); if (isset($data['settings']->company_logo) && strlen($data['settings']->company_logo) > 0) { + try { $tempImage = tempnam(sys_get_temp_dir(), basename($data['settings']->company_logo)); copy($data['settings']->company_logo, $tempImage); $this->uploadLogo($tempImage, $this->company, $this->company); } catch (\Exception $e) { + + $settings = $this->company->settings; + $settings->company_logo = ''; + $this->company->settings = $settings; + $this->company->save(); + } } From 3be7b8975aced02a212a04ec62f8e75d9056a10b Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 21 Aug 2021 19:53:20 +1000 Subject: [PATCH 6/6] Minor fixes for import --- VERSION.txt | 2 +- app/Jobs/Util/Import.php | 1 + config/ninja.php | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index 1c26b6f22f62..e230c8396d19 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.2.19 \ No newline at end of file +5.3.0 \ No newline at end of file diff --git a/app/Jobs/Util/Import.php b/app/Jobs/Util/Import.php index c452fe900ae1..664c09afa9b1 100644 --- a/app/Jobs/Util/Import.php +++ b/app/Jobs/Util/Import.php @@ -712,6 +712,7 @@ class Import implements ShouldQueue $modified = $resource; $modified['company_id'] = $this->company->id; $modified['user_id'] = $this->processUserId($resource); + $modified['number'] = $this->checkUniqueConstraint(Vendor::class, 'number', $modified['number']); unset($modified['id']); unset($modified['contacts']); diff --git a/config/ninja.php b/config/ninja.php index 3533b1a7b2f7..e893d61c3b11 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -14,8 +14,8 @@ return [ 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_domain' => env('APP_DOMAIN', 'invoicing.co'), - 'app_version' => '5.2.19', - 'app_tag' => '5.2.19', + 'app_version' => '5.3.0', + 'app_tag' => '5.3.0', 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', ''),