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

Use existing PaymentType instead of CardType

This commit is contained in:
Joshua Dwire 2016-04-27 22:13:51 -04:00
parent 1a12cd30d3
commit 1cb2b9dc25
20 changed files with 111 additions and 155 deletions

View File

@ -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 : '<i>Manual entry</i>'; })
->addColumn('payment_type', function ($model) { return $model->payment_type ? $model->payment_type : ($model->account_gateway_id ? '<i>Online payment</i>' : ''); })
->addColumn('payment_type', function ($model) { return ($model->payment_type && !$model->last4) ? $model->payment_type : ($model->account_gateway_id ? '<i>Online payment</i>' : ''); })
->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 '<img height="22" src="'.URL::to('/images/credit_cards/'.$model->card_type_code.'.png').'" alt="'.htmlentities($card_type).'">&nbsp; &bull;&bull;&bull;'.$model->last4.' '.$expiration;
return '<img height="22" src="'.URL::to('/images/credit_cards/'.$code.'.png').'" alt="'.htmlentities($card_type).'">&nbsp; &bull;&bull;&bull;'.$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); })

View File

@ -482,21 +482,6 @@ if (!defined('CONTACT_EMAIL')) {
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');

View File

@ -1201,7 +1201,7 @@ class Account extends Eloquent
public function showTokenCheckbox(&$storage_gateway = null)
{
if (!$this->getTokenGatewayId()) {
if (!($storage_gateway = $this->getTokenGatewayId())) {
return false;
}

View File

@ -1,8 +0,0 @@
<?php namespace App\Models;
use Eloquent;
class CardType extends Eloquent
{
public $timestamps = false;
}

View File

@ -59,11 +59,6 @@ class Payment extends EntityModel
return $this->belongsTo('App\Models\PaymentStatus');
}
public function card_type()
{
return $this->belongsTo('App\Models\CardTypes');
}
public function getRoute()
{
return "/payments/{$this->public_id}/edit";

View File

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

View File

@ -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 '<img height="22" src="'.URL::to('/images/credit_cards/'.$model->card_type_code.'.png').'" alt="'.htmlentities($card_type).'">&nbsp; &bull;&bull;&bull;'.$model->last4.' '.$expiration;
return '<img height="22" src="'.URL::to('/images/credit_cards/'.$code.'.png').'" alt="'.htmlentities($card_type).'">&nbsp; &bull;&bull;&bull;'.$model->last4.' '.$expiration;
}
],
[

View File

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

View File

@ -1,44 +0,0 @@
<?php
use App\Models\CardType;
class CardTypesSeeder extends Seeder
{
public function run()
{
Eloquent::unguard();
$this->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);
}
}
}
}

View File

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

View File

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

View File

@ -0,0 +1,44 @@
<?php
use App\Models\PaymentType;
class PaymentTypesSeeder extends Seeder
{
public function run()
{
Eloquent::unguard();
$paymentTypes = [
array('name' => '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);
}
}
}
}

View File

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

View File

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 6.3 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

View File

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -1192,8 +1192,8 @@ $LANG = array(
'activity_39' => ':user refunded :adjustment of a :payment_amount payment (:payment)',
'card_expiration' => 'Exp:&nbsp: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;

View File

@ -367,7 +367,7 @@
<div class="row" style="padding-top:18px">
<div class="col-md-5">
@if ($client && $account->showTokenCheckbox($storageGateway))
@if ($client && $account->showTokenCheckbox($storageGateway/* will contain gateway id */))
<input id="token_billing" type="checkbox" name="token_billing" {{ $account->selectTokenCheckbox() ? 'CHECKED' : '' }} value="1" style="margin-left:0px; vertical-align:top">
<label for="token_billing" class="checkbox" style="display: inline;">{{ trans('texts.token_billing') }}</label>
<span class="help-block" style="font-size:15px">