From 0b0f0759f1b83fd63bed155f26e0e8e117bd2352 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 8 Sep 2019 20:39:13 +1000 Subject: [PATCH] Working on Gateways --- app/DataMapper/ClientSettings.php | 1 - app/DataMapper/CompanySettings.php | 4 +- app/Models/Client.php | 10 +++- app/Models/ClientGatewayToken.php | 42 +++++++++++++++++ app/Models/CompanyGateway.php | 29 ++++++++---- app/Models/CompanyGatewaySetting.php | 39 ++++++++++++++++ .../2014_10_13_000000_create_users_table.php | 46 +++++++++++++++++-- 7 files changed, 153 insertions(+), 18 deletions(-) create mode 100644 app/Models/ClientGatewayToken.php create mode 100644 app/Models/CompanyGatewaySetting.php diff --git a/app/DataMapper/ClientSettings.php b/app/DataMapper/ClientSettings.php index 55348aeb271b..aafe44213761 100644 --- a/app/DataMapper/ClientSettings.php +++ b/app/DataMapper/ClientSettings.php @@ -82,7 +82,6 @@ class ClientSettings extends BaseSettings public $recurring_invoice_number_prefix; public $counter_padding; - public $default_gateway; /** * Settings which which are unique to client settings diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index e8f208c427c5..11bfa5c33797 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -111,8 +111,6 @@ class CompanySettings extends BaseSettings public $reset_counter_date; public $counter_padding; - public $default_gateway; - public $design; /** * Cast object values and return entire class @@ -168,7 +166,7 @@ class CompanySettings extends BaseSettings 'client_number_prefix' => '', 'auto_archive_invoice' => 'FALSE', 'design' => 'views/pdf/design1.blade.php', - + 'translations' => (object) [], ]; } diff --git a/app/Models/Client.php b/app/Models/Client.php index 32a71af21443..1c1011c17772 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -92,6 +92,11 @@ class Client extends BaseModel 'settings' => 'object' ]; + public function gateway_tokens() + { + return $this->hasMany(ClientGatewayToken::class); + } + public function contacts() { return $this->hasMany(ClientContact::class)->orderBy('is_primary', 'desc'); @@ -147,7 +152,10 @@ class Client extends BaseModel return $this->morphMany(Document::class, 'documentable'); } - + public function getPaymentMethods() + { + + } } diff --git a/app/Models/ClientGatewayToken.php b/app/Models/ClientGatewayToken.php new file mode 100644 index 000000000000..b72d3b83b3e4 --- /dev/null +++ b/app/Models/ClientGatewayToken.php @@ -0,0 +1,42 @@ +hasOne(Client::class); + } + + public function gateway() + { + return $this->hasOne(CompanyGateway::class); + } + + public function company() + { + return $this->hasOne(Company::class); + } + + public function user() + { + return $this->hasOne(User::class); + } + +} \ No newline at end of file diff --git a/app/Models/CompanyGateway.php b/app/Models/CompanyGateway.php index 3bfbaece968b..1ba12aa23587 100644 --- a/app/Models/CompanyGateway.php +++ b/app/Models/CompanyGateway.php @@ -16,10 +16,9 @@ use App\Models\Gateway; use App\Models\GatewayType; use Illuminate\Database\Eloquent\Model; -class CompanyGateway extends Model +class CompanyGateway extends BaseModel { - public static $creditCards = - [ + public static $credit_cards = [ 1 => ['card' => 'images/credit_cards/Test-Visa-Icon.png', 'text' => 'Visa'], 2 => ['card' => 'images/credit_cards/Test-MasterCard-Icon.png', 'text' => 'Master Card'], 4 => ['card' => 'images/credit_cards/Test-AmericanExpress-Icon.png', 'text' => 'American Express'], @@ -63,12 +62,22 @@ class CompanyGateway extends Model } } + public function getConfigAttribute() + { + return decrypt($this->config); + } + + public function setConfigAttribute($value) + { + $this->attributes['config'] = encrypt(json_encode($value)); + } + /** * @return bool */ public function getAchEnabled() { - return ! empty($this->getConfigField('enableAch')); + return ! empty($this->config('enableAch')); } /** @@ -76,7 +85,7 @@ class CompanyGateway extends Model */ public function getApplePayEnabled() { - return ! empty($this->getConfigField('enableApplePay')); + return ! empty($this->config('enableApplePay')); } /** @@ -84,7 +93,7 @@ class CompanyGateway extends Model */ public function getAlipayEnabled() { - return ! empty($this->getConfigField('enableAlipay')); + return ! empty($this->config('enableAlipay')); } /** @@ -92,7 +101,7 @@ class CompanyGateway extends Model */ public function getSofortEnabled() { - return ! empty($this->getConfigField('enableSofort')); + return ! empty($this->config('enableSofort')); } /** @@ -100,7 +109,7 @@ class CompanyGateway extends Model */ public function getSepaEnabled() { - return ! empty($this->getConfigField('enableSepa')); + return ! empty($this->config('enableSepa')); } /** @@ -108,7 +117,7 @@ class CompanyGateway extends Model */ public function getBitcoinEnabled() { - return ! empty($this->getConfigField('enableBitcoin')); + return ! empty($this->config('enableBitcoin')); } /** @@ -116,6 +125,6 @@ class CompanyGateway extends Model */ public function getPayPalEnabled() { - return ! empty($this->getConfigField('enablePayPal')); + return ! empty($this->config('enablePayPal')); } } diff --git a/app/Models/CompanyGatewaySetting.php b/app/Models/CompanyGatewaySetting.php new file mode 100644 index 000000000000..ec3fd8d0e4b4 --- /dev/null +++ b/app/Models/CompanyGatewaySetting.php @@ -0,0 +1,39 @@ +belongsTo(Company::class); + } + + public function user() + { + return $this->belongsTo(User::class); + } + + public function company_gateway() + { + return $this->belongsTo(CompanyGateway::class); + } +} diff --git a/database/migrations/2014_10_13_000000_create_users_table.php b/database/migrations/2014_10_13_000000_create_users_table.php index a9a90b6f37f6..2974378084c9 100644 --- a/database/migrations/2014_10_13_000000_create_users_table.php +++ b/database/migrations/2014_10_13_000000_create_users_table.php @@ -351,9 +351,13 @@ class CreateUsersTable extends Migration $table->unsignedInteger('company_id')->unique(); $table->unsignedInteger('user_id'); $table->unsignedInteger('gateway_id'); + $table->unsignedInteger('accepted_credit_cards'); + $table->boolean('require_cvv')->default(true); $table->boolean('show_address')->default(true)->nullable(); - $table->boolean('update_address')->default(true)->nullable(); + $table->boolean('show_shipping_address')->default(true)->nullable(); + $table->boolean('update_details')->default(false)->nullable(); $table->text('config'); + $table->unsignedInteger('sort_id')->default(0); $table->timestamps(6); $table->softDeletes(); @@ -683,7 +687,7 @@ class CreateUsersTable extends Migration $t->unsignedInteger('client_contact_id')->nullable(); $t->unsignedInteger('invitation_id')->nullable(); $t->unsignedInteger('user_id')->nullable(); - $t->unsignedInteger('account_gateway_id')->nullable(); + $t->unsignedInteger('company_gateway_id')->nullable(); $t->unsignedInteger('payment_type_id')->nullable(); $t->unsignedInteger('status_id')->index(); @@ -700,7 +704,7 @@ class CreateUsersTable extends Migration $t->foreign('company_id')->references('id')->on('companies')->onDelete('cascade'); $t->foreign('client_id')->references('id')->on('clients')->onDelete('cascade'); $t->foreign('client_contact_id')->references('id')->on('client_contacts')->onDelete('cascade'); - $t->foreign('account_gateway_id')->references('id')->on('account_gateways')->onDelete('cascade'); + $t->foreign('company_gateway_id')->references('id')->on('company_gateways')->onDelete('cascade'); $t->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); ; $t->foreign('payment_type_id')->references('id')->on('payment_types'); @@ -885,6 +889,42 @@ class CreateUsersTable extends Migration $table->string('alias'); $table->string('name'); }); + + + Schema::create('client_gateway_tokens', function ($table){ + $table->increments('id'); + $table->unsignedInteger('company_id'); + $table->unsignedInteger('client_id')->nullable(); + $table->text('token'); + $table->unsignedInteger('company_gateway_id'); + $table->boolean('is_default'); + $table->timestamps(6); + $table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade'); + $table->foreign('client_id')->references('id')->on('clients')->onDelete('cascade'); + }); + + + Schema::create('company_gateway_settings', function ($table){ + $table->increments('id'); + $table->unsignedInteger('company_id'); + $table->unsignedInteger('company_gateway_id')->nullable(); + $table->unsignedInteger('gateway_type_id')->nullable(); + $table->unsignedInteger('user_id')->nullable(); + $table->decimal('min_limit', 13, 2)->nullable(); + $table->decimal('max_limit', 13, 2)->nullable(); + $table->decimal('fee_amount', 13, 2)->nullable(); + $table->decimal('fee_percent', 13, 2)->nullable(); + $table->decimal('fee_tax_name1', 13, 2)->nullable(); + $table->decimal('fee_tax_name2', 13, 2)->nullable(); + $table->decimal('fee_tax_rate1', 13, 2)->nullable(); + $table->decimal('fee_tax_rate2', 13, 2)->nullable(); + $table->unsignedInteger('fee_cap')->default(0); + $table->boolean('adjust_fee_percent'); + + $table->timestamps(6); + $table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade'); + $table->foreign('company_gateway_id')->references('id')->on('company_gateways')->onDelete('cascade'); + }); } /**