diff --git a/app/Http/Controllers/PublicClientController.php b/app/Http/Controllers/PublicClientController.php
index a68c1568e487..28391cf7140e 100644
--- a/app/Http/Controllers/PublicClientController.php
+++ b/app/Http/Controllers/PublicClientController.php
@@ -305,7 +305,7 @@ class PublicClientController extends BaseController
public function paymentIndex()
{
- if (!$invitation = $this->getInGvitation()) {
+ if (!$invitation = $this->getInvitation()) {
return $this->returnError();
}
$account = $invitation->account;
@@ -340,12 +340,13 @@ class PublicClientController extends BaseController
return Datatable::query($payments)
->addColumn('invoice_number', function ($model) { return $model->invitation_key ? link_to('/view/'.$model->invitation_key, $model->invoice_number)->toHtml() : $model->invoice_number; })
->addColumn('transaction_reference', function ($model) { return $model->transaction_reference ? $model->transaction_reference : 'Manual entry'; })
- ->addColumn('payment_type', function ($model) { return $model->payment_type ? $model->payment_type : ($model->account_gateway_id ? 'Online payment' : ''); })
+ ->addColumn('payment_type', function ($model) { return ($model->payment_type && !$model->last4) ? $model->payment_type : ($model->account_gateway_id ? 'Online payment' : ''); })
->addColumn('payment_source', function ($model) {
- if (!$model->card_type_code) return '';
- $card_type = trans("texts.card_" . $model->card_type_code);
+ if (!$model->last4) return '';
+ $code = str_replace(' ', '', strtolower($model->payment_type));
+ $card_type = trans("texts.card_" . $code);
$expiration = trans('texts.card_expiration', array('expires'=>Utils::fromSqlDate($model->expiration, false)->format('m/y')));
- return ' •••'.$model->last4.' '.$expiration;
+ return '
•••'.$model->last4.' '.$expiration;
})
->addColumn('amount', function ($model) { return Utils::formatMoney($model->amount, $model->currency_id, $model->country_id); })
->addColumn('payment_date', function ($model) { return Utils::dateToString($model->payment_date); })
diff --git a/app/Http/routes.php b/app/Http/routes.php
index 0676b44b7931..7c3759aa8ef4 100644
--- a/app/Http/routes.php
+++ b/app/Http/routes.php
@@ -481,22 +481,7 @@ if (!defined('CONTACT_EMAIL')) {
define('PAYMENT_STATUS_COMPLETED', 3);
define('PAYMENT_STATUS_PARTIALLY_REFUNDED', 4);
define('PAYMENT_STATUS_REFUNDED', 5);
-
- define('CARD_UNKNOWN', 0);
- define('CARD_AMERICAN_EXPRESS', 1);
- define('CARD_CARTE_BLANCHE', 2);
- define('CARD_UNIONPAY', 3);
- define('CARD_DINERS_CLUB', 4);
- define('CARD_DISCOVER', 5);
- define('CARD_JCB', 6);
- define('CARD_LASER', 7);
- define('CARD_MAESTRO', 8);
- define('CARD_MASTERCARD', 9);
- define('CARD_SOLO', 10);
- define('CARD_SWITCH', 11);
- define('CARD_VISA', 12);
- define('PAYMENT_TYPE_CREDIT', 1);
define('CUSTOM_DESIGN', 11);
define('FREQUENCY_WEEKLY', 1);
@@ -629,6 +614,23 @@ if (!defined('CONTACT_EMAIL')) {
define('TOKEN_BILLING_OPT_OUT', 3);
define('TOKEN_BILLING_ALWAYS', 4);
+ define('PAYMENT_TYPE_CREDIT', 1);
+ define('PAYMENT_TYPE_VISA', 6);
+ define('PAYMENT_TYPE_MASTERCARD', 7);
+ define('PAYMENT_TYPE_AMERICAN_EXPRESS', 8);
+ define('PAYMENT_TYPE_DISCOVER', 9);
+ define('PAYMENT_TYPE_DINERS', 10);
+ define('PAYMENT_TYPE_EUROCARD', 11);
+ define('PAYMENT_TYPE_NOVA', 12);
+ define('PAYMENT_TYPE_CREDIT_CARD_OTHER', 13);
+ define('PAYMENT_TYPE_CARTE_BLANCHE', 17);
+ define('PAYMENT_TYPE_UNIONPAY', 18);
+ define('PAYMENT_TYPE_JCB', 19);
+ define('PAYMENT_TYPE_LASER', 20);
+ define('PAYMENT_TYPE_MAESTRO', 21);
+ define('PAYMENT_TYPE_SOLO', 22);
+ define('PAYMENT_TYPE_SWITCH', 23);
+
define('PAYMENT_TYPE_PAYPAL', 'PAYMENT_TYPE_PAYPAL');
define('PAYMENT_TYPE_CREDIT_CARD', 'PAYMENT_TYPE_CREDIT_CARD');
define('PAYMENT_TYPE_DIRECT_DEBIT', 'PAYMENT_TYPE_DIRECT_DEBIT');
diff --git a/app/Models/Account.php b/app/Models/Account.php
index 85391557ab17..44b49d44e1fe 100644
--- a/app/Models/Account.php
+++ b/app/Models/Account.php
@@ -1201,7 +1201,7 @@ class Account extends Eloquent
public function showTokenCheckbox(&$storage_gateway = null)
{
- if (!$this->getTokenGatewayId()) {
+ if (!($storage_gateway = $this->getTokenGatewayId())) {
return false;
}
diff --git a/app/Models/CardType.php b/app/Models/CardType.php
deleted file mode 100644
index 6eee490c1260..000000000000
--- a/app/Models/CardType.php
+++ /dev/null
@@ -1,8 +0,0 @@
-belongsTo('App\Models\PaymentStatus');
- }
-
- public function card_type()
- {
- return $this->belongsTo('App\Models\CardTypes');
}
public function getRoute()
diff --git a/app/Ninja/Repositories/PaymentRepository.php b/app/Ninja/Repositories/PaymentRepository.php
index 4f9a3fc49291..c1c8d3e851dd 100644
--- a/app/Ninja/Repositories/PaymentRepository.php
+++ b/app/Ninja/Repositories/PaymentRepository.php
@@ -23,7 +23,6 @@ class PaymentRepository extends BaseRepository
->join('invoices', 'invoices.id', '=', 'payments.invoice_id')
->join('contacts', 'contacts.client_id', '=', 'clients.id')
->join('payment_statuses', 'payment_statuses.id', '=', 'payments.payment_status_id')
- ->leftJoin('card_types', 'card_types.id', '=', 'payments.card_type_id')
->leftJoin('payment_types', 'payment_types.id', '=', 'payments.payment_type_id')
->leftJoin('account_gateways', 'account_gateways.id', '=', 'payments.account_gateway_id')
->leftJoin('gateways', 'gateways.id', '=', 'account_gateways.gateway_id')
@@ -60,8 +59,7 @@ class PaymentRepository extends BaseRepository
'invoices.is_deleted as invoice_is_deleted',
'gateways.name as gateway_name',
'gateways.id as gateway_id',
- 'payment_statuses.name as payment_status_name',
- 'card_types.code as card_type_code'
+ 'payment_statuses.name as payment_status_name'
);
if (!\Session::get('show_trash:payment')) {
@@ -89,7 +87,6 @@ class PaymentRepository extends BaseRepository
->join('invoices', 'invoices.id', '=', 'payments.invoice_id')
->join('contacts', 'contacts.client_id', '=', 'clients.id')
->join('payment_statuses', 'payment_statuses.id', '=', 'payments.payment_status_id')
- ->leftJoin('card_types', 'card_types.id', '=', 'payments.card_type_id')
->leftJoin('invitations', function ($join) {
$join->on('invitations.invoice_id', '=', 'invoices.id')
->on('invitations.contact_id', '=', 'contacts.id');
@@ -121,8 +118,7 @@ class PaymentRepository extends BaseRepository
'payments.expiration',
'payments.last4',
'payments.payment_status_id',
- 'payment_statuses.name as payment_status_name',
- 'card_types.code as card_type_code'
+ 'payment_statuses.name as payment_status_name'
);
if ($filter) {
diff --git a/app/Services/PaymentService.php b/app/Services/PaymentService.php
index 6bd0a5b03001..6bfcf2e12559 100644
--- a/app/Services/PaymentService.php
+++ b/app/Services/PaymentService.php
@@ -260,7 +260,7 @@ class PaymentService extends BaseService
}
$payment->expiration = $year . '-' . $card->expiryMonth . '-00';
- $payment->card_type_id = $this->detectCardType($card->number);
+ $payment->payment_type_id = $this->detectCardType($card->number);
}
if ($accountGateway->gateway_id == GATEWAY_STRIPE) {
@@ -273,18 +273,18 @@ class PaymentService extends BaseService
$payment->last4 = $card['last4'];
$payment->expiration = $card['exp_year'] . '-' . $card['exp_month'] . '-00';
$stripe_card_types = array(
- 'Visa' => CARD_VISA,
- 'American Express' => CARD_AMERICAN_EXPRESS,
- 'MasterCard' => CARD_MASTERCARD,
- 'Discover' => CARD_DISCOVER,
- 'JCB' => CARD_JCB,
- 'Diners Club' => CARD_DINERS_CLUB,
+ 'Visa' => PAYMENT_TYPE_VISA,
+ 'American Express' => PAYMENT_TYPE_AMERICAN_EXPRESS,
+ 'MasterCard' => PAYMENT_TYPE_MASTERCARD,
+ 'Discover' => PAYMENT_TYPE_DISCOVER,
+ 'JCB' => PAYMENT_TYPE_JCB,
+ 'Diners Club' => PAYMENT_TYPE_DINERS,
);
if (!empty($stripe_card_types[$card['brand']])) {
- $payment->card_type_id = $stripe_card_types[$card['brand']];
+ $payment->payment_type_id = $stripe_card_types[$card['brand']];
} else {
- $payment->card_type_id = CARD_UNKNOWN;
+ $payment->payment_type_id = PAYMENT_TYPE_CREDIT_CARD_OTHER;
}
}
} elseif ($accountGateway->gateway_id == GATEWAY_BRAINTREE) {
@@ -293,24 +293,24 @@ class PaymentService extends BaseService
$payment->expiration = $card->expirationYear . '-' . $card->expirationMonth . '-00';
$braintree_card_types = array(
- 'Visa' => CARD_VISA,
- 'American Express' => CARD_AMERICAN_EXPRESS,
- 'MasterCard' => CARD_MASTERCARD,
- 'Discover' => CARD_DISCOVER,
- 'JCB' => CARD_JCB,
- 'Diners Club' => CARD_DINERS_CLUB,
- 'Carte Blanche' => CARD_CARTE_BLANCHE,
- 'China UnionPay' => CARD_UNIONPAY,
- 'Laser' => CARD_LASER,
- 'Maestro' => CARD_MAESTRO,
- 'Solo' => CARD_SOLO,
- 'Switch' => CARD_SWITCH,
+ 'Visa' => PAYMENT_TYPE_VISA,
+ 'American Express' => PAYMENT_TYPE_AMERICAN_EXPRESS,
+ 'MasterCard' => PAYMENT_TYPE_MASTERCARD,
+ 'Discover' => PAYMENT_TYPE_DISCOVER,
+ 'JCB' => PAYMENT_TYPE_JCB,
+ 'Diners Club' => PAYMENT_TYPE_DINERS,
+ 'Carte Blanche' => PAYMENT_TYPE_CARTE_BLANCHE,
+ 'China UnionPay' => PAYMENT_TYPE_UNIONPAY,
+ 'Laser' => PAYMENT_TYPE_LASER,
+ 'Maestro' => PAYMENT_TYPE_MAESTRO,
+ 'Solo' => PAYMENT_TYPE_SOLO,
+ 'Switch' => PAYMENT_TYPE_SWITCH,
);
if (!empty($braintree_card_types[$card->cardType])) {
- $payment->card_type_id = $braintree_card_types[$card->cardType];
+ $payment->payment_type_id = $braintree_card_types[$card->cardType];
} else {
- $payment->card_type_id = CARD_UNKNOWN;
+ $payment->payment_type_id = PAYMENT_TYPE_CREDIT_CARD_OTHER;
}
}
@@ -379,19 +379,19 @@ class PaymentService extends BaseService
private function detectCardType($number)
{
if (preg_match('/^3[47][0-9]{13}$/',$number)) {
- return CARD_AMERICAN_EXPRESS;
+ return PAYMENT_TYPE_AMERICAN_EXPRESS;
} elseif (preg_match('/^3(?:0[0-5]|[68][0-9])[0-9]{11}$/',$number)) {
- return CARD_DINERS_CLUB;
+ return PAYMENT_TYPE_DINERS;
} elseif (preg_match('/^6(?:011|5[0-9][0-9])[0-9]{12}$/',$number)) {
- return CARD_DISCOVER;
+ return PAYMENT_TYPE_DISCOVER;
} elseif (preg_match('/^(?:2131|1800|35\d{3})\d{11}$/',$number)) {
- return CARD_JCB;
+ return PAYMENT_TYPE_JCB;
} elseif (preg_match('/^5[1-5][0-9]{14}$/',$number)) {
- return CARD_MASTERCARD;
+ return PAYMENT_TYPE_MASTERCARD;
} elseif (preg_match('/^4[0-9]{12}(?:[0-9]{3})?$/',$number)) {
- return CARD_VISA;
+ return PAYMENT_TYPE_VISA;
}
- return CARD_UNKNOWN;
+ return PAYMENT_TYPE_CREDIT_CARD_OTHER;
}
public function completePurchase($gateway, $accountGateway, $details, $token)
@@ -488,16 +488,17 @@ class PaymentService extends BaseService
[
'payment_type',
function ($model) {
- return $model->payment_type ? $model->payment_type : ($model->account_gateway_id ? $model->gateway_name : '');
+ return ($model->payment_type && !$model->last4) ? $model->payment_type : ($model->account_gateway_id ? $model->gateway_name : '');
}
],
[
'source',
function ($model) {
- if (!$model->card_type_code) return '';
- $card_type = trans("texts.card_" . $model->card_type_code);
+ if (!$model->last4) return '';
+ $code = str_replace(' ', '', strtolower($model->payment_type));
+ $card_type = trans("texts.card_" . $code);
$expiration = trans('texts.card_expiration', array('expires'=>Utils::fromSqlDate($model->expiration, false)->format('m/y')));
- return '
•••'.$model->last4.' '.$expiration;
+ return '
•••'.$model->last4.' '.$expiration;
}
],
[
diff --git a/database/migrations/2016_04_23_182223_payments_changes.php b/database/migrations/2016_04_23_182223_payments_changes.php
index fc887b3bb88f..c99512cfabf9 100644
--- a/database/migrations/2016_04_23_182223_payments_changes.php
+++ b/database/migrations/2016_04_23_182223_payments_changes.php
@@ -13,7 +13,6 @@ class PaymentsChanges extends Migration
public function up()
{
Schema::dropIfExists('payment_statuses');
- Schema::dropIfExists('card_types');
Schema::create('payment_statuses', function($table)
{
@@ -21,15 +20,7 @@ class PaymentsChanges extends Migration
$table->string('name');
});
- Schema::create('card_types', function($table)
- {
- $table->increments('id');
- $table->string('name');
- $table->string('code');
- });
-
(new \PaymentStatusSeeder())->run();
- (new \CardTypesSeeder())->run();
Schema::table('payments', function($table)
{
@@ -40,8 +31,6 @@ class PaymentsChanges extends Migration
$table->unsignedInteger('routing_number')->nullable();
$table->smallInteger('last4')->unsigned()->nullable();
$table->date('expiration')->nullable();
- $table->unsignedInteger('card_type_id')->nullable();
- $table->foreign('card_type_id')->references('id')->on('card_types');
});
}
@@ -61,11 +50,8 @@ class PaymentsChanges extends Migration
$table->dropColumn('routing_number');
$table->dropColumn('last4');
$table->dropColumn('expiration');
- $table->dropForeign('card_type_id_foreign');
- $table->dropColumn('card_type_id');
});
Schema::dropIfExists('payment_statuses');
- Schema::dropIfExists('card_types');
}
}
diff --git a/database/seeds/CardTypesSeeder.php b/database/seeds/CardTypesSeeder.php
deleted file mode 100644
index e5d70b9ed585..000000000000
--- a/database/seeds/CardTypesSeeder.php
+++ /dev/null
@@ -1,44 +0,0 @@
-createPaymentSourceTypes();
-
- Eloquent::reguard();
- }
-
- private function createPaymentSourceTypes()
- {
- $statuses = [
- ['id' => '0', 'name' => 'Unknown', 'code'=>'unknown']
- ['id' => '1', 'name' => 'American Express', 'code'=>'amex'],
- ['id' => '2', 'name' => 'Carte Blanche', 'code'=>'carteblanche'],
- ['id' => '3', 'name' => 'China UnionPay', 'code'=>'unionpay'],
- ['id' => '4', 'name' => 'Diners Club', 'code'=>'diners'],
- ['id' => '5', 'name' => 'Discover', 'code'=>'discover'],
- ['id' => '6', 'name' => 'JCB', 'code'=>'jcb'],
- ['id' => '7', 'name' => 'Laser', 'code'=>'laser'],
- ['id' => '8', 'name' => 'Maestro', 'code'=>'maestro'],
- ['id' => '9', 'name' => 'MasterCard', 'code'=>'mastercard'],
- ['id' => '10', 'name' => 'Solo', 'code'=>'solo'],
- ['id' => '11', 'name' => 'Switch', 'code'=>'switch'],
- ['id' => '12', 'name' => 'Visa', 'code'=>'visa'],
- ];
-
- foreach ($statuses as $status) {
- $record = CardType::find($status['id']);
- if ($record) {
- $record->name = $status['name'];
- $record->save();
- } else {
- CardType::create($status);
- }
- }
- }
-}
diff --git a/database/seeds/ConstantsSeeder.php b/database/seeds/ConstantsSeeder.php
index e02741684318..863ba5c71f10 100644
--- a/database/seeds/ConstantsSeeder.php
+++ b/database/seeds/ConstantsSeeder.php
@@ -20,23 +20,6 @@ class ConstantsSeeder extends Seeder
public function run()
{
- PaymentType::create(array('name' => 'Apply Credit'));
- PaymentType::create(array('name' => 'Bank Transfer'));
- PaymentType::create(array('name' => 'Cash'));
- PaymentType::create(array('name' => 'Debit'));
- PaymentType::create(array('name' => 'ACH'));
- PaymentType::create(array('name' => 'Visa Card'));
- PaymentType::create(array('name' => 'MasterCard'));
- PaymentType::create(array('name' => 'American Express'));
- PaymentType::create(array('name' => 'Discover Card'));
- PaymentType::create(array('name' => 'Diners Card'));
- PaymentType::create(array('name' => 'EuroCard'));
- PaymentType::create(array('name' => 'Nova'));
- PaymentType::create(array('name' => 'Credit Card Other'));
- PaymentType::create(array('name' => 'PayPal'));
- PaymentType::create(array('name' => 'Google Wallet'));
- PaymentType::create(array('name' => 'Check'));
-
Theme::create(array('name' => 'amelia'));
Theme::create(array('name' => 'cerulean'));
Theme::create(array('name' => 'cosmo'));
diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php
index 20bdbe7f0cc1..6117c22e007a 100644
--- a/database/seeds/DatabaseSeeder.php
+++ b/database/seeds/DatabaseSeeder.php
@@ -20,10 +20,10 @@ class DatabaseSeeder extends Seeder
$this->call('BanksSeeder');
$this->call('InvoiceStatusSeeder');
$this->call('PaymentStatusSeeder');
- $this->call('CardTypesSeeder');
$this->call('CurrenciesSeeder');
$this->call('DateFormatsSeeder');
$this->call('InvoiceDesignsSeeder');
$this->call('PaymentTermsSeeder');
+ $this->call('PaymentTypesSeeder');
}
}
diff --git a/database/seeds/PaymentTypesSeeder.php b/database/seeds/PaymentTypesSeeder.php
new file mode 100644
index 000000000000..6ded62284583
--- /dev/null
+++ b/database/seeds/PaymentTypesSeeder.php
@@ -0,0 +1,44 @@
+ 'Apply Credit'),
+ array('name' => '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' => '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'),
+ ];
+
+ foreach ($paymentTypes as $paymentType) {
+ if (!DB::table('payment_types')->where('name', '=', $paymentType['name'])->get()) {
+ PaymentType::create($paymentType);
+ }
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/database/seeds/UpdateSeeder.php b/database/seeds/UpdateSeeder.php
index dffb2dbe26b7..5cd784a1ec8d 100644
--- a/database/seeds/UpdateSeeder.php
+++ b/database/seeds/UpdateSeeder.php
@@ -16,10 +16,10 @@ class UpdateSeeder extends Seeder
$this->call('BanksSeeder');
$this->call('InvoiceStatusSeeder');
$this->call('PaymentStatusSeeder');
- $this->call('CardTypesSeeder');
$this->call('CurrenciesSeeder');
$this->call('DateFormatsSeeder');
$this->call('InvoiceDesignsSeeder');
$this->call('PaymentTermsSeeder');
+ $this->call('PaymentTypesSeeder');
}
}
diff --git a/public/images/credit_cards/amex.png b/public/images/credit_cards/americanexpress.png
similarity index 100%
rename from public/images/credit_cards/amex.png
rename to public/images/credit_cards/americanexpress.png
diff --git a/public/images/credit_cards/unknown.png b/public/images/credit_cards/creditcardother.png
similarity index 100%
rename from public/images/credit_cards/unknown.png
rename to public/images/credit_cards/creditcardother.png
diff --git a/public/images/credit_cards/diners.png b/public/images/credit_cards/dinerscard.png
similarity index 100%
rename from public/images/credit_cards/diners.png
rename to public/images/credit_cards/dinerscard.png
diff --git a/public/images/credit_cards/discover.png b/public/images/credit_cards/discovercard.png
similarity index 100%
rename from public/images/credit_cards/discover.png
rename to public/images/credit_cards/discovercard.png
diff --git a/public/images/credit_cards/visa.png b/public/images/credit_cards/visacard.png
similarity index 100%
rename from public/images/credit_cards/visa.png
rename to public/images/credit_cards/visacard.png
diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php
index 769732589921..f96dd990b818 100644
--- a/resources/lang/en/texts.php
+++ b/resources/lang/en/texts.php
@@ -1192,8 +1192,8 @@ $LANG = array(
'activity_39' => ':user refunded :adjustment of a :payment_amount payment (:payment)',
'card_expiration' => 'Exp: :expires',
- 'card_unknown' => 'Unknown',
- 'card_amex' => 'American Express',
+ 'card_creditcardother' => 'Unknown',
+ 'card_americanexpress' => 'American Express',
'card_carteblanche' => 'Carte Blanche',
'card_unionpay' => 'UnionPay',
'card_diners' => 'Diners Club',
@@ -1204,7 +1204,7 @@ $LANG = array(
'card_mastercard' => 'MasterCard',
'card_solo' => 'Solo',
'card_switch' => 'Switch',
- 'card_visa' => 'Visa',
+ 'card_visacard' => 'Visa',
);
return $LANG;
diff --git a/resources/views/payments/payment.blade.php b/resources/views/payments/payment.blade.php
index fe612670050c..d11c09416e83 100644
--- a/resources/views/payments/payment.blade.php
+++ b/resources/views/payments/payment.blade.php
@@ -367,7 +367,7 @@