mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Switch to string-based ID for gateway types; associate gateway type with payment type
This commit is contained in:
parent
30fcf0e363
commit
3c4ad52463
@ -1235,7 +1235,7 @@ class AccountController extends BaseController
|
||||
*/
|
||||
public function savePaymentGatewayLimits()
|
||||
{
|
||||
$gateway_type_id = intval(Input::get('gateway_type_id'));
|
||||
$gateway_type_id = Input::get('gateway_type_id');
|
||||
$gateway_settings = AccountGatewaySettings::scope()->where('gateway_type_id', '=', $gateway_type_id)->first();
|
||||
|
||||
if ( ! $gateway_settings) {
|
||||
|
@ -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', 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_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_TOKEN', 'token');
|
||||
|
||||
define('REMINDER1', 'reminder1');
|
||||
|
@ -12,6 +12,8 @@ class GatewayType extends Eloquent
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
public $incrementing = false;
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
|
@ -156,15 +156,14 @@ 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 in_array($gatewayType->id, $gatewayTypes);
|
||||
return $paymentDriver->handles($gatewayType->id);
|
||||
}
|
||||
];
|
||||
}
|
||||
|
@ -12,21 +12,24 @@ class CreateGatewayTypes extends Migration
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::dropIfExists('account_gateway_settings');
|
||||
Schema::dropIfExists('gateway_types');
|
||||
|
||||
Schema::create('gateway_types', function($t)
|
||||
{
|
||||
$t->increments('id');
|
||||
$t->string('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->unsignedInteger('gateway_type_id')->nullable();
|
||||
$t->string('gateway_type_id')->nullable();
|
||||
|
||||
$t->timestamp('updated_at')->nullable();
|
||||
|
||||
@ -39,6 +42,12 @@ 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.
|
||||
|
@ -10,15 +10,15 @@ class GatewayTypesSeeder extends Seeder
|
||||
|
||||
|
||||
$gateway_types = [
|
||||
['name' => 'Credit Card'],
|
||||
['name' => 'Bank Transfer'],
|
||||
['name' => 'PayPal'],
|
||||
['name' => 'Bitcoin'],
|
||||
['name' => 'Dwolla'],
|
||||
['id' => 'credit_card', 'name' => 'Credit Card'],
|
||||
['id' => 'bank_transfer', 'name' => 'Bank Transfer'],
|
||||
['id' => 'paypal', 'name' => 'PayPal'],
|
||||
['id' => 'bitcoin', 'name' => 'Bitcoin'],
|
||||
['id' => 'dwolla', 'name' => 'Dwolla'],
|
||||
];
|
||||
|
||||
foreach ($gateway_types as $gateway_type) {
|
||||
$record = GatewayType::where('name', '=', $gateway_type['name'])->first();
|
||||
$record = GatewayType::where('id', '=', $gateway_type['id'])->first();
|
||||
if (!$record) {
|
||||
GatewayType::create($gateway_type);
|
||||
}
|
||||
|
@ -10,32 +10,39 @@ class PaymentTypesSeeder extends Seeder
|
||||
|
||||
$paymentTypes = [
|
||||
array('name' => 'Apply Credit'),
|
||||
array('name' => 'Bank Transfer'),
|
||||
array('name' => 'Bank Transfer', 'gateway_type_id' => GATEWAY_TYPE_BANK_TRANSFER),
|
||||
array('name' => 'Cash'),
|
||||
array('name' => 'Debit'),
|
||||
array('name' => 'ACH'),
|
||||
array('name' => 'Visa Card'),
|
||||
array('name' => 'MasterCard'),
|
||||
array('name' => 'American Express'),
|
||||
array('name' => 'Discover Card'),
|
||||
array('name' => 'Diners Card'),
|
||||
array('name' => 'EuroCard'),
|
||||
array('name' => 'Nova'),
|
||||
array('name' => 'Credit Card Other'),
|
||||
array('name' => 'PayPal'),
|
||||
array('name' => 'Debit', 'gateway_type_id' => GATEWAY_TYPE_CREDIT_CARD),
|
||||
array('name' => 'ACH', 'gateway_type_id' => GATEWAY_TYPE_BANK_TRANSFER),
|
||||
array('name' => 'Visa Card', 'gateway_type_id' => GATEWAY_TYPE_CREDIT_CARD),
|
||||
array('name' => 'MasterCard', 'gateway_type_id' => GATEWAY_TYPE_CREDIT_CARD),
|
||||
array('name' => 'American Express', 'gateway_type_id' => GATEWAY_TYPE_CREDIT_CARD),
|
||||
array('name' => 'Discover Card', 'gateway_type_id' => GATEWAY_TYPE_CREDIT_CARD),
|
||||
array('name' => 'Diners Card', 'gateway_type_id' => GATEWAY_TYPE_CREDIT_CARD),
|
||||
array('name' => 'EuroCard', 'gateway_type_id' => GATEWAY_TYPE_CREDIT_CARD),
|
||||
array('name' => 'Nova', 'gateway_type_id' => GATEWAY_TYPE_CREDIT_CARD),
|
||||
array('name' => 'Credit Card Other', 'gateway_type_id' => GATEWAY_TYPE_CREDIT_CARD),
|
||||
array('name' => 'PayPal', 'gateway_type_id' => GATEWAY_TYPE_PAYPAL),
|
||||
array('name' => 'Google Wallet'),
|
||||
array('name' => 'Check'),
|
||||
array('name' => 'Carte Blanche'),
|
||||
array('name' => 'UnionPay'),
|
||||
array('name' => 'JCB'),
|
||||
array('name' => 'Laser'),
|
||||
array('name' => 'Maestro'),
|
||||
array('name' => 'Solo'),
|
||||
array('name' => 'Switch'),
|
||||
array('name' => 'Carte Blanche', 'gateway_type_id' => GATEWAY_TYPE_CREDIT_CARD),
|
||||
array('name' => 'UnionPay', 'gateway_type_id' => GATEWAY_TYPE_CREDIT_CARD),
|
||||
array('name' => 'JCB', 'gateway_type_id' => GATEWAY_TYPE_CREDIT_CARD),
|
||||
array('name' => 'Laser', 'gateway_type_id' => GATEWAY_TYPE_CREDIT_CARD),
|
||||
array('name' => 'Maestro', 'gateway_type_id' => GATEWAY_TYPE_CREDIT_CARD),
|
||||
array('name' => 'Solo', 'gateway_type_id' => GATEWAY_TYPE_CREDIT_CARD),
|
||||
array('name' => 'Switch', 'gateway_type_id' => GATEWAY_TYPE_CREDIT_CARD),
|
||||
];
|
||||
|
||||
foreach ($paymentTypes as $paymentType) {
|
||||
if (!DB::table('payment_types')->where('name', '=', $paymentType['name'])->get()) {
|
||||
$record = PaymentType::where('name', '=', $paymentType['name'])->first();
|
||||
|
||||
if ( $record) {
|
||||
$record->name = $paymentType['name'];
|
||||
$record->gateway_type_id = ! empty($paymentType['gateway_type_id']) ? $paymentType['gateway_type_id'] : null;
|
||||
|
||||
$record->save();
|
||||
} else {
|
||||
PaymentType::create($paymentType);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user