From 9193484a7df95384e10b0f576bd187feb2a90c61 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 21 May 2021 20:08:48 +1000 Subject: [PATCH] Fixes for migration --- VERSION.txt | 2 +- app/PaymentDrivers/Stripe/ImportCustomers.php | 7 ++ .../Stripe/UpdatePaymentMethods.php | 109 ++++++++++-------- app/PaymentDrivers/StripePaymentDriver.php | 8 +- config/ninja.php | 4 +- ...show_task_end_date_to_companies_tables.php | 32 ----- ...curring_invoice_id_to_activities_table.php | 9 ++ 7 files changed, 81 insertions(+), 90 deletions(-) delete mode 100644 database/migrations/2021_05_06_211039_add_show_task_end_date_to_companies_tables.php diff --git a/VERSION.txt b/VERSION.txt index 77b6d45eba..2abae2150b 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.1.63 \ No newline at end of file +5.1.64 \ No newline at end of file diff --git a/app/PaymentDrivers/Stripe/ImportCustomers.php b/app/PaymentDrivers/Stripe/ImportCustomers.php index 734ba631d9..1dd1de7381 100644 --- a/app/PaymentDrivers/Stripe/ImportCustomers.php +++ b/app/PaymentDrivers/Stripe/ImportCustomers.php @@ -21,6 +21,7 @@ use App\Models\Country; use App\Models\Currency; use App\Models\GatewayType; use App\PaymentDrivers\StripePaymentDriver; +use App\PaymentDrivers\Stripe\UpdatePaymentMethods; use App\Utils\Traits\MakesHash; use Stripe\Customer; use Stripe\PaymentMethod; @@ -32,9 +33,12 @@ class ImportCustomers /** @var StripePaymentDriver */ public $stripe; + public $update_payment_methods; + public function __construct(StripePaymentDriver $stripe) { $this->stripe = $stripe; + } public function run() @@ -42,6 +46,8 @@ class ImportCustomers $this->stripe->init(); + $this->update_payment_methods = new UpdatePaymentMethods($this->stripe); + $customers = Customer::all([], $this->stripe->stripe_connect_auth); foreach($customers as $customer) @@ -123,5 +129,6 @@ class ImportCustomers $contact->email = $customer->email ?: ''; $contact->save(); + $this->update_payment_methods->updateMethods($customer, $client); } } diff --git a/app/PaymentDrivers/Stripe/UpdatePaymentMethods.php b/app/PaymentDrivers/Stripe/UpdatePaymentMethods.php index 79097c2a1d..8d4e975796 100644 --- a/app/PaymentDrivers/Stripe/UpdatePaymentMethods.php +++ b/app/PaymentDrivers/Stripe/UpdatePaymentMethods.php @@ -13,6 +13,7 @@ namespace App\PaymentDrivers\Stripe; use App\Factory\ClientGatewayTokenFactory; +use App\Models\Client; use App\Models\ClientGatewayToken; use App\Models\GatewayType; use App\PaymentDrivers\StripePaymentDriver; @@ -32,90 +33,96 @@ class UpdatePaymentMethods $this->stripe = $stripe; } - public function run() + // public function run() + // { + // $this->stripe->init(); + + // $this->stripe + // ->company_gateway + // ->client_gateway_tokens + // ->each(function ($token){ + + + // // $bank_accounts = Customer::allSources( + // // $token->gateway_customer_reference, + // // ['object' => 'bank_account', 'limit' => 300] + // // ); + + // // foreach($bank_accounts as $bank_account) + // // { + // // $this->addOrUpdateBankAccount($bank_account, $token); + // // } + // // $this->processCustomer($token->gateway_customer_reference); + + // }); + + // } + + private function updateMethods(Customer $customer, Client $client) { - $this->stripe->init(); - - $this->stripe - ->company_gateway - ->client_gateway_tokens - ->each(function ($token){ - $card_methods = PaymentMethod::all([ - 'customer' => $token->gateway_customer_reference, + 'customer' => $customer->id, 'type' => 'card', ], $this->stripe->stripe_connect_auth); foreach($card_methods as $method) { - $this->addOrUpdateCard($method, $token, GatewayType::CREDIT_CARD); + $this->addOrUpdateCard($method, $customer->id, $client,GatewayType::CREDIT_CARD); } $alipay_methods = PaymentMethod::all([ - 'customer' => $token->gateway_customer_reference, + 'customer' => $customer->id, 'type' => 'alipay', ], $this->stripe->stripe_connect_auth); foreach($alipay_methods as $method) { - $this->addOrUpdateCard($method, $token, GatewayType::ALIPAY); + $this->addOrUpdateCard($method, $customer->id, $client,GatewayType::ALIPAY); } $sofort_methods = PaymentMethod::all([ - 'customer' => $token->gateway_customer_reference, + 'customer' => $customer->id, 'type' => 'sofort', ], $this->stripe->stripe_connect_auth); foreach($alipay_methods as $method) { - $this->addOrUpdateCard($method, $token, GatewayType::SOFORT); + $this->addOrUpdateCard($method, $customer->id, $client, GatewayType::SOFORT); } - // $bank_accounts = Customer::allSources( - // $token->gateway_customer_reference, - // ['object' => 'bank_account', 'limit' => 300] - // ); - - // foreach($bank_accounts as $bank_account) - // { - // $this->addOrUpdateBankAccount($bank_account, $token); - // } - - }); - } - private function addOrUpdateBankAccount($bank_account, ClientGatewayToken $token) - { - $token_exists = ClientGatewayToken::where([ - 'gateway_customer_reference' => $token->gateway_customer_reference, - 'token' => $bank_account->id, - ])->exists(); + // private function addOrUpdateBankAccount($bank_account, $customer_reference, Client $client) + // { + // $token_exists = ClientGatewayToken::where([ + // 'gateway_customer_reference' => $customer_reference, + // 'token' => $bank_account->id, + // ])->exists(); - /* Already exists return */ - if($token_exists) - return; + // /* Already exists return */ + // if($token_exists) + // return; - $cgt = ClientGatewayTokenFactory::create($token->company_id); - $cgt->client_id = $token->client_id; - $cgt->token = $bank_account->id; - $cgt->gateway_customer_reference = $token->gateway_customer_reference; - $cgt->company_gateway_id = $token->company_gateway_id; - $cgt->gateway_type_id = GatewayType::BANK_TRANSFER; - $cgt->meta = new \stdClass; - $cgt->routing_number = $bank_account->routing_number; - $cgt->save(); + // $cgt = ClientGatewayTokenFactory::create($client->company_id); + // $cgt->client_id = $client->id; + // $cgt->token = $bank_account->id; + // $cgt->gateway_customer_reference = $customer_reference; + // $cgt->company_gateway_id = $this->stripe->company_gateway->id; + // $cgt->gateway_type_id = GatewayType::BANK_TRANSFER; + // $cgt->meta = new \stdClass; + // $cgt->routing_number = $bank_account->routing_number; + // $cgt->save(); - } + // } - private function addOrUpdateCard(PaymentMethod $method, ClientGatewayToken $token, $type_id) + private function addOrUpdateCard(PaymentMethod $method, $customer_reference, Client $client, $type_id) { $token_exists = ClientGatewayToken::where([ - 'gateway_customer_reference' => $token->gateway_customer_reference, + 'gateway_customer_reference' => $customer_reference, 'token' => $method->id, ])->exists(); @@ -127,11 +134,11 @@ class UpdatePaymentMethods if($method->card->exp_year <= date('Y') && $method->card->exp_month < date('m')) return; - $cgt = ClientGatewayTokenFactory::create($token->company_id); - $cgt->client_id = $token->client_id; + $cgt = ClientGatewayTokenFactory::create($client->company_id); + $cgt->client_id = $client->id; $cgt->token = $method->id; - $cgt->gateway_customer_reference = $token->gateway_customer_reference; - $cgt->company_gateway_id = $token->company_gateway_id; + $cgt->gateway_customer_reference = $customer_reference; + $cgt->company_gateway_id = $this->stripe->company_gateway->id; $cgt->gateway_type_id = $type_id; $cgt->meta = $this->buildPaymentMethodMeta($method, $type_id); $cgt->save(); diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 3c7dad302b..13a0b9cbbb 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -501,10 +501,10 @@ class StripePaymentDriver extends BaseDriver * the respective tokens in the system. * */ - public function updateAllPaymentMethods() - { - return (new UpdatePaymentMethods($this))->run(); - } + // public function updateAllPaymentMethods() + // { + // return (new UpdatePaymentMethods($this))->run(); + // } /** * Imports stripe customers and their payment methods diff --git a/config/ninja.php b/config/ninja.php index d8cf7f5632..af498f8a21 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.1.63', - 'app_tag' => '5.1.63-release', + 'app_version' => '5.1.64', + 'app_tag' => '5.1.64-release', 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', ''), diff --git a/database/migrations/2021_05_06_211039_add_show_task_end_date_to_companies_tables.php b/database/migrations/2021_05_06_211039_add_show_task_end_date_to_companies_tables.php deleted file mode 100644 index 8053de796c..0000000000 --- a/database/migrations/2021_05_06_211039_add_show_task_end_date_to_companies_tables.php +++ /dev/null @@ -1,32 +0,0 @@ -boolean('show_task_end_date')->default(false); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('companies', function (Blueprint $table) { - // - }); - } -} diff --git a/database/migrations/2021_05_10_041528_add_recurring_invoice_id_to_activities_table.php b/database/migrations/2021_05_10_041528_add_recurring_invoice_id_to_activities_table.php index 4ecef8899d..9f5f574caf 100644 --- a/database/migrations/2021_05_10_041528_add_recurring_invoice_id_to_activities_table.php +++ b/database/migrations/2021_05_10_041528_add_recurring_invoice_id_to_activities_table.php @@ -16,6 +16,15 @@ class AddRecurringInvoiceIdToActivitiesTable extends Migration Schema::table('activities', function (Blueprint $table) { $table->unsignedInteger('recurring_invoice_id')->nullable(); }); + + + if (!Schema::hasColumn('companies', 'show_task_end_date')) + { + Schema::table('companies', function (Blueprint $table) { + $table->boolean('show_task_end_date')->default(false); + }); + } + } /**