1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-29 04:37:11 +02:00

Merge branch 'v5-develop' into v5-stable

This commit is contained in:
David Bomba 2021-05-21 20:08:55 +10:00
commit 7b07784f0c
7 changed files with 81 additions and 90 deletions

View File

@ -1 +1 @@
5.1.63
5.1.64

View File

@ -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);
}
}

View File

@ -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();

View File

@ -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

View File

@ -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', ''),

View File

@ -1,32 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddShowTaskEndDateToCompaniesTables extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('companies', function (Blueprint $table) {
$table->boolean('show_task_end_date')->default(false);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('companies', function (Blueprint $table) {
//
});
}
}

View File

@ -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);
});
}
}
/**