From 2fc0265d067df3768f813a94d666e653276236ae Mon Sep 17 00:00:00 2001 From: Joshua Dwire Date: Fri, 9 Sep 2016 16:47:08 -0400 Subject: [PATCH] Revert change to string ID for gateway types --- app/Http/Controllers/AccountController.php | 2 +- app/Http/routes.php | 10 +++++----- app/Models/GatewayType.php | 2 -- app/Ninja/Datatables/AccountGatewayDatatable.php | 5 +++-- .../2016_09_05_150625_create_gateway_types.php | 15 +++------------ database/seeds/GatewayTypesSeeder.php | 12 ++++++------ 6 files changed, 18 insertions(+), 28 deletions(-) diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 3263a724548a..501df2912044 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -1235,7 +1235,7 @@ class AccountController extends BaseController */ public function savePaymentGatewayLimits() { - $gateway_type_id = Input::get('gateway_type_id'); + $gateway_type_id = intval(Input::get('gateway_type_id')); $gateway_settings = AccountGatewaySettings::scope()->where('gateway_type_id', '=', $gateway_type_id)->first(); if ( ! $gateway_settings) { diff --git a/app/Http/routes.php b/app/Http/routes.php index 4940c8037ca7..6d3d6a23e0c1 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -704,11 +704,11 @@ if (!defined('CONTACT_EMAIL')) { define('PAYMENT_METHOD_STATUS_VERIFICATION_FAILED', 'verification_failed'); define('PAYMENT_METHOD_STATUS_VERIFIED', 'verified'); - define('GATEWAY_TYPE_CREDIT_CARD', 'credit_card'); - define('GATEWAY_TYPE_BANK_TRANSFER', 'bank_transfer'); - define('GATEWAY_TYPE_PAYPAL', 'paypal'); - define('GATEWAY_TYPE_BITCOIN', 'bitcoin'); - define('GATEWAY_TYPE_DWOLLA', 'dwolla'); + define('GATEWAY_TYPE_CREDIT_CARD', 1); + define('GATEWAY_TYPE_BANK_TRANSFER', 2); + define('GATEWAY_TYPE_PAYPAL', 3); + define('GATEWAY_TYPE_BITCOIN', 4); + define('GATEWAY_TYPE_DWOLLA', 5); define('GATEWAY_TYPE_TOKEN', 'token'); define('REMINDER1', 'reminder1'); diff --git a/app/Models/GatewayType.php b/app/Models/GatewayType.php index 6c711d85b304..38fdf48d4eb2 100644 --- a/app/Models/GatewayType.php +++ b/app/Models/GatewayType.php @@ -12,8 +12,6 @@ class GatewayType extends Eloquent */ public $timestamps = false; - public $incrementing = false; - /** * @return mixed */ diff --git a/app/Ninja/Datatables/AccountGatewayDatatable.php b/app/Ninja/Datatables/AccountGatewayDatatable.php index 3b439daa0e6d..700063e6575f 100644 --- a/app/Ninja/Datatables/AccountGatewayDatatable.php +++ b/app/Ninja/Datatables/AccountGatewayDatatable.php @@ -156,14 +156,15 @@ class AccountGatewayDatatable extends EntityDatatable $min = $accountGatewaySettings ? $accountGatewaySettings->min_limit : 0; $max = $accountGatewaySettings ? $accountGatewaySettings->max_limit : 0; - return "javascript:showLimitsModal('{$gatewayType->name}','{$gatewayType->id}',$min,$max)"; + return "javascript:showLimitsModal('{$gatewayType->name}',{$gatewayType->id},$min,$max)"; }, function ($model) use ($gatewayType) { // Only show this action if the given gateway supports this gateway type $accountGateway = AccountGateway::find($model->id); $paymentDriver = $accountGateway->paymentDriver(); + $gatewayTypes = $paymentDriver->gatewayTypes(); - return $paymentDriver->handles($gatewayType->id); + return in_array($gatewayType->id, $gatewayTypes); } ]; } diff --git a/database/migrations/2016_09_05_150625_create_gateway_types.php b/database/migrations/2016_09_05_150625_create_gateway_types.php index cd8e11c7d6ad..1fec411bc9af 100644 --- a/database/migrations/2016_09_05_150625_create_gateway_types.php +++ b/database/migrations/2016_09_05_150625_create_gateway_types.php @@ -12,24 +12,21 @@ class CreateGatewayTypes extends Migration */ public function up() { - Schema::dropIfExists('account_gateway_settings'); Schema::dropIfExists('gateway_types'); - Schema::create('gateway_types', function($t) { - $t->string('id'); + $t->increments('id'); $t->string('name'); - - $t->primary('id'); }); + Schema::dropIfExists('account_gateway_settings'); Schema::create('account_gateway_settings', function($t) { $t->increments('id'); $t->unsignedInteger('account_id'); $t->unsignedInteger('user_id'); - $t->string('gateway_type_id')->nullable(); + $t->unsignedInteger('gateway_type_id')->nullable(); $t->timestamp('updated_at')->nullable(); @@ -42,12 +39,6 @@ class CreateGatewayTypes extends Migration $t->foreign('gateway_type_id')->references('id')->on('gateway_types')->onDelete('cascade'); }); - - Schema::table('payment_types', function($t) - { - $t->string('gateway_type_id')->nullable(); - $t->foreign('gateway_type_id')->references('id')->on('gateway_types')->onDelete('cascade'); - }); } /** * Reverse the migrations. diff --git a/database/seeds/GatewayTypesSeeder.php b/database/seeds/GatewayTypesSeeder.php index 929b3d23cad9..33ae1d2984e3 100644 --- a/database/seeds/GatewayTypesSeeder.php +++ b/database/seeds/GatewayTypesSeeder.php @@ -10,15 +10,15 @@ class GatewayTypesSeeder extends Seeder $gateway_types = [ - ['id' => 'credit_card', 'name' => 'Credit Card'], - ['id' => 'bank_transfer', 'name' => 'Bank Transfer'], - ['id' => 'paypal', 'name' => 'PayPal'], - ['id' => 'bitcoin', 'name' => 'Bitcoin'], - ['id' => 'dwolla', 'name' => 'Dwolla'], + ['name' => 'Credit Card'], + ['name' => 'Bank Transfer'], + ['name' => 'PayPal'], + ['name' => 'Bitcoin'], + ['name' => 'Dwolla'], ]; foreach ($gateway_types as $gateway_type) { - $record = GatewayType::where('id', '=', $gateway_type['id'])->first(); + $record = GatewayType::where('name', '=', $gateway_type['name'])->first(); if (!$record) { GatewayType::create($gateway_type); }