From 24a071c0f3eb952a5072926e8bee115cacb45b71 Mon Sep 17 00:00:00 2001 From: aggepagge Date: Sun, 22 Jun 2014 21:08:52 +0200 Subject: [PATCH] added functionallity to company/payments page --- app/controllers/AccountController.php | 14 +- app/controllers/PaymentController.php | 9 +- .../seeds/SecurePaymentFormSeeder.php | 235 ++++++++++++------ app/libraries/utils.php | 36 --- app/models/AccountGateway.php | 14 ++ app/routes.php | 20 +- app/views/accounts/payments.blade.php | 17 ++ .../Test-AmericanExpress-Icon.png | Bin .../{ => credit_cards}/Test-Diners-Icon.png | Bin .../{ => credit_cards}/Test-Discover-Icon.png | Bin .../Test-MasterCard-Icon.png | Bin .../{ => credit_cards}/Test-Visa-Icon.png | Bin 12 files changed, 215 insertions(+), 130 deletions(-) rename public/images/{ => credit_cards}/Test-AmericanExpress-Icon.png (100%) rename public/images/{ => credit_cards}/Test-Diners-Icon.png (100%) rename public/images/{ => credit_cards}/Test-Discover-Icon.png (100%) rename public/images/{ => credit_cards}/Test-MasterCard-Icon.png (100%) rename public/images/{ => credit_cards}/Test-Visa-Icon.png (100%) diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php index 1e90afc3f953..81733907d8f0 100755 --- a/app/controllers/AccountController.php +++ b/app/controllers/AccountController.php @@ -107,9 +107,9 @@ class AccountController extends \BaseController { { $accountGateway = $account->account_gateways[0]; $config = $accountGateway->config; - + $configFields = json_decode($config); - + foreach($configFields as $configField => $value) { $configFields->$configField = str_repeat('*', strlen($value)); @@ -132,6 +132,13 @@ class AccountController extends \BaseController { ); $recommendedGatewayArray[$recommendedGateway->name] = $arrayItem; } + + $creditCardsArray = unserialize(CREDIT_CARDS); + $creditCards = []; + foreach($creditCardsArray as $card => $name) + { + $creditCards[$name['text']] = ['value' => $card, 'data-imageUrl' => asset($name['card'])]; + } $otherItem = array( 'value' => 1000000, @@ -140,7 +147,7 @@ class AccountController extends \BaseController { 'data-siteUrl' => '' ); $recommendedGatewayArray['Other Options'] = $otherItem; - + $data = [ 'account' => $account, 'accountGateway' => $accountGateway, @@ -153,6 +160,7 @@ class AccountController extends \BaseController { ->orderBy('name') ->get(), 'recommendedGateways' => $recommendedGatewayArray, + 'creditCardTypes' => $creditCards, ]; foreach ($data['gateways'] as $gateway) diff --git a/app/controllers/PaymentController.php b/app/controllers/PaymentController.php index e3efb2fd31da..9eb2c133fcaf 100755 --- a/app/controllers/PaymentController.php +++ b/app/controllers/PaymentController.php @@ -229,8 +229,6 @@ class PaymentController extends \BaseController } } - - /** HÄR SKALL DET HÄMTAS UT BILDER!!!!! **/ public function show_payment($invitationKey) { // For PayPal Express we redirect straight to their site @@ -252,12 +250,11 @@ class PaymentController extends \BaseController $invitation = Invitation::with('invoice.invoice_items', 'invoice.client.currency', 'invoice.client.account.account_gateways.gateway')->where('invitation_key', '=', $invitationKey)->firstOrFail(); $invoice = $invitation->invoice; - $client = $invoice->client; + $client = $invoice->client; + $accountGateway = $invoice->client->account->account_gateways[0]; $gateway = $invoice->client->account->account_gateways[0]->gateway; $paymentLibrary = $gateway->paymentlibrary; - - $mask = $invoice->client->account->account_gateways[0]->accepted_credit_cards; - $acceptedCreditCardTypes = Utils::getCreditcardTypes($mask); + $acceptedCreditCardTypes = $accountGateway->getCreditcardTypes(); $data = [ 'showBreadcrumbs' => false, diff --git a/app/database/seeds/SecurePaymentFormSeeder.php b/app/database/seeds/SecurePaymentFormSeeder.php index 72514949adeb..77bbe1ba6cf2 100644 --- a/app/database/seeds/SecurePaymentFormSeeder.php +++ b/app/database/seeds/SecurePaymentFormSeeder.php @@ -6,7 +6,6 @@ **/ class SecurePaymentFormSeeder extends Seeder { - public function run() { Eloquent::unguard(); @@ -28,83 +27,161 @@ class SecurePaymentFormSeeder extends Seeder DB::unprepared($statement); - $firstName = 'Oscar'; - $lastName = 'Thompson'; - - $user = AccountGateway::create(array( - 'account_id' => 1, - 'user_id' => 1, - 'gateway_id' => 4, - 'config' => 'bla bla bla bla bla bla bla', - 'public_id' => 1, - 'accepted_credit_cards' => 18 - )); - - $client = Client::create(array( - 'user_id' => 1, - 'account_id' => 1, - 'currency_id' => 1, - 'name' => $firstName.' '.$lastName, - 'address1' => '2119 Howe Course', - 'address2' => '2118 Howe Course', - 'city' => 'West Chazport', - 'state' => 'Utah', - 'postal_code' => '31572', - 'country_id' => 752, - 'work_phone' => '012-345678', - 'private_notes' => 'bla bla bla bla bla bla bla', - 'balance' => 10.4, - 'paid_to_date' => 10.2, - 'website' => 'awebsite.com', - 'industry_id' => 8, - 'is_deleted' => 0, - 'payment_terms' => 2, - 'public_id' => 1, - 'custom_value1' => $firstName, - 'custom_value2' => $firstName - )); - - $contact = Contact::create(array( - 'account_id' => 1, - 'user_id' => 1, - 'client_id' => 1, - 'is_primary' => 0, - 'send_invoice' => 0, - 'first_name' => $firstName, - 'last_name' => $lastName, - 'email' => 'an@email.com', - 'phone' => '012-345678', - 'public_id' => 1 - )); - - $invoice = Invoice::create(array( - 'client_id' => 1, - 'user_id' => 1, - 'account_id' => 1, - 'invoice_number' => 1, - 'discount' => 0.4, - 'po_number' => $firstName, - 'terms' => 'bla bla bla bla bla bla bla', - 'public_notes' => 'bla bla bla bla bla bla bla', - 'is_deleted' => 0, - 'is_recurring' => 0, - 'frequency_id' => 1, - 'tax_name' => 'moms', - 'tax_rate' => 33.0, - 'amount' => 10.0, - 'balance' => 8.0, - 'public_id' => 1, - 'is_quote' => 0 - )); - - $invitation = Invitation::create(array( - 'account_id' => 1, - 'user_id' => 1, - 'contact_id' => 1, - 'invoice_id' => 1, - 'invitation_key' => 'aaabbb', - 'transaction_reference' => 'bla bla bla bla bla bla bla', - 'public_id' => 1 - )); + //$firstName = 'Oscar'; +// $lastName = 'Thompson'; +// $firstName_2 = 'Philip'; +// $lastName_2 = 'Jonsson'; +// +// $user = AccountGateway::create(array( +// 'account_id' => 1, +// 'user_id' => 1, +// 'gateway_id' => 4, +// 'config' => '{"bla":"vla","bli":"cla"}', +// 'public_id' => 1, +// 'accepted_credit_cards' => 8 +// )); +// +// $user2 = AccountGateway::create(array( +// 'account_id' => 2, +// 'user_id' => 2, +// 'gateway_id' => 5, +// 'config' => '{"bla":"vla","bli":"cla"}', +// 'public_id' => 2, +// 'accepted_credit_cards' => 7 +// )); +// +// $client = Client::create(array( +// 'user_id' => 1, +// 'account_id' => 1, +// 'currency_id' => 1, +// 'name' => $firstName.' '.$lastName, +// 'address1' => '2119 Howe Course', +// 'address2' => '2118 Howe Course', +// 'city' => 'West Chazport', +// 'state' => 'Utah', +// 'postal_code' => '31572', +// 'country_id' => 752, +// 'work_phone' => '012-345678', +// 'private_notes' => 'bla bla bla bla bla bla bla', +// 'balance' => 10.4, +// 'paid_to_date' => 10.2, +// 'website' => 'awebsite.com', +// 'industry_id' => 8, +// 'is_deleted' => 0, +// 'payment_terms' => 2, +// 'public_id' => 1, +// 'custom_value1' => $firstName, +// 'custom_value2' => $firstName +// )); +// +// $client2 = Client::create(array( +// 'user_id' => 2, +// 'account_id' => 2, +// 'currency_id' => 1, +// 'name' => $firstName_2.' '.$lastName_2, +// 'address1' => '1118 Muma Road', +// 'address2' => '1118 Muma Road', +// 'city' => 'New Orleans', +// 'state' => 'Arizona', +// 'postal_code' => '31572', +// 'country_id' => 752, +// 'work_phone' => '012-345678', +// 'private_notes' => 'bla bla bla bla bla bla bla', +// 'balance' => 10.4, +// 'paid_to_date' => 10.2, +// 'website' => 'bodosite.com', +// 'industry_id' => 8, +// 'is_deleted' => 0, +// 'payment_terms' => 2, +// 'public_id' => 1, +// 'custom_value1' => $firstName_2, +// 'custom_value2' => $firstName_2 +// )); +// +// $contact = Contact::create(array( +// 'account_id' => 1, +// 'user_id' => 1, +// 'client_id' => 1, +// 'is_primary' => 0, +// 'send_invoice' => 0, +// 'first_name' => $firstName, +// 'last_name' => $lastName, +// 'email' => 'an@email.com', +// 'phone' => '012-345678', +// 'public_id' => 1 +// )); +// +// $contact2 = Contact::create(array( +// 'account_id' => 2, +// 'user_id' => 2, +// 'client_id' => 2, +// 'is_primary' => 0, +// 'send_invoice' => 0, +// 'first_name' => $firstName_2, +// 'last_name' => $lastName_2, +// 'email' => 'the@email.com', +// 'phone' => '012-345678', +// 'public_id' => 2 +// )); +// +// $invoice = Invoice::create(array( +// 'client_id' => 1, +// 'user_id' => 1, +// 'account_id' => 1, +// 'invoice_number' => 1, +// 'discount' => 0.4, +// 'po_number' => $firstName, +// 'terms' => 'bla bla bla bla bla bla bla', +// 'public_notes' => 'bla bla bla bla bla bla bla', +// 'is_deleted' => 0, +// 'is_recurring' => 0, +// 'frequency_id' => 1, +// 'tax_name' => 'moms', +// 'tax_rate' => 33.0, +// 'amount' => 10.0, +// 'balance' => 8.0, +// 'public_id' => 1, +// 'is_quote' => 0 +// )); +// +// $invoice2 = Invoice::create(array( +// 'client_id' => 2, +// 'user_id' => 2, +// 'account_id' => 2, +// 'invoice_number' => 2, +// 'discount' => 0.4, +// 'po_number' => $firstName_2, +// 'terms' => 'bla bla bla bla bla bla bla', +// 'public_notes' => 'bla bla bla bla bla bla bla', +// 'is_deleted' => 0, +// 'is_recurring' => 0, +// 'frequency_id' => 1, +// 'tax_name' => 'moms', +// 'tax_rate' => 33.0, +// 'amount' => 10.0, +// 'balance' => 8.0, +// 'public_id' => 2, +// 'is_quote' => 0 +// )); +// +// $invitation = Invitation::create(array( +// 'account_id' => 1, +// 'user_id' => 1, +// 'contact_id' => 1, +// 'invoice_id' => 1, +// 'invitation_key' => 'aaabbb', +// 'transaction_reference' => 'bla bla bla bla bla bla bla', +// 'public_id' => 1 +// )); +// +// $invitation2 = Invitation::create(array( +// 'account_id' => 2, +// 'user_id' => 2, +// 'contact_id' => 2, +// 'invoice_id' => 2, +// 'invitation_key' => 'cccddd', +// 'transaction_reference' => 'bla bla bla bla bla bla bla', +// 'public_id' => 2 +// )); } } \ No newline at end of file diff --git a/app/libraries/utils.php b/app/libraries/utils.php index ef3df1b14eac..7ad83368f3c7 100755 --- a/app/libraries/utils.php +++ b/app/libraries/utils.php @@ -441,40 +441,4 @@ class Utils return $message; } - - public static function getCreditcardTypes($mask) - { - $arrayOfImages = []; - - $flags = [ - CREDIT_CARD_VISA => ['card' => 'Visa', 'text' => 'Visa'], - CREDIT_CARD_MASTER_CARD => ['card' => 'MasterCard', 'text' => 'Master Card'], - CREDIT_CARD_AMERICAN_EXPRESS => ['card' => 'AmericanExpress', 'text' => 'American Express'], - CREDIT_CARD_DINERS => ['card' => 'Diners', 'text' => 'Diners'], - CREDIT_CARD_DISCOVER => ['card' => 'Discover', 'text' => 'Discover'] - ]; - - foreach ($flags as $card => $name) - { - if (($mask & $card) == $card) - $arrayOfImages[] = ['source' => asset('images/Test-'.$name['card'].'-Icon.png'), 'alt' => $name['text']]; - } - - //if($mask & CREDIT_CARD_VISA) -// array_push($arrayOfImages, ['source' => asset('images/Test-Visa-Icon.png'), 'alt' => 'Visa']); -// -// if($mask & CREDIT_CARD_MASTER_CARD) -// array_push($arrayOfImages, ['source' => asset('images/Test-MasterCard-Icon.png'), 'alt' => 'Master Card']); -// -// if($mask & CREDIT_CARD_AMERICAN_EXPRESS) -// array_push($arrayOfImages, ['source' => asset('images/Test-AmericanExpress-Icon.png'), 'alt' => 'American Express']); -// -// if($mask & CREDIT_CARD_DINERS) -// array_push($arrayOfImages, ['source' => asset('images/Test-Diners-Icon.png'), 'alt' => 'Diners']); -// -// if($mask & CREDIT_CARD_DISCOVER) -// array_push($arrayOfImages, ['source' => asset('images/Test-Discover-Icon.png'), 'alt' => 'Discover']); - - return $arrayOfImages; - } } \ No newline at end of file diff --git a/app/models/AccountGateway.php b/app/models/AccountGateway.php index f62861f2f6b1..fb178fc1a1b8 100755 --- a/app/models/AccountGateway.php +++ b/app/models/AccountGateway.php @@ -6,4 +6,18 @@ class AccountGateway extends EntityModel { return $this->belongsTo('Gateway'); } + + public function getCreditcardTypes() + { + $flags = unserialize(CREDIT_CARDS); + $arrayOfImages = []; + + foreach ($flags as $card => $name) + { + if (($this->accepted_credit_cards & $card) == $card) + $arrayOfImages[] = ['source' => asset($name['card']), 'alt' => $name['text']]; + } + + return $arrayOfImages; + } } \ No newline at end of file diff --git a/app/routes.php b/app/routes.php index d78b0114cd8f..1c4f83ef072b 100755 --- a/app/routes.php +++ b/app/routes.php @@ -229,12 +229,20 @@ define('GATEWAY_GOOGLE', 33); define('GATEWAY_QUICKBOOKS', 35); */ -/** TEST VALUES FOR THE CREDIT CARDS **/ -define('CREDIT_CARD_VISA', 1); -define('CREDIT_CARD_MASTER_CARD', 2); -define('CREDIT_CARD_AMERICAN_EXPRESS', 4); -define('CREDIT_CARD_DINERS', 8); -define('CREDIT_CARD_DISCOVER', 16); +/** + * TEST VALUES FOR THE CREDIT CARDS + * NUMBER IS FOR THE BINARY COUNT FOR WHICH IMAGES TO DISPLAY + * card IS FOR CARD IMAGE AND text IS FOR CARD NAME (TO ADD TO alt FOR IMAGE) +**/ +$creditCards = [ + 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'], + 8 => ['card' => 'images/credit_cards/Test-Diners-Icon.png', 'text' => 'Diners'], + 16 => ['card' => 'images/credit_cards/Test-Discover-Icon.png', 'text' => 'Discover'] + ]; + +define('CREDIT_CARDS', serialize($creditCards)); HTML::macro('nav_link', function($url, $text, $url2 = '', $extra = '') { diff --git a/app/views/accounts/payments.blade.php b/app/views/accounts/payments.blade.php index 6fdaf446fd50..329624dbba11 100755 --- a/app/views/accounts/payments.blade.php +++ b/app/views/accounts/payments.blade.php @@ -19,6 +19,16 @@ @endif @endforeach @endif + + +
+ {{ Former::radios('creditCardTypes_id') + ->label('Accepted Credit Cards') + ->radios($creditCardTypes) + ->class('creditcard-types') + }} +
{{ Former::radios('recommendedGateway_id')->label('Recommended Gateways') @@ -104,6 +114,13 @@ $(this).after('
'); $(this).parent().children().last().after('Create an account'); }); + + // TODO: THIS IS JUST TO SHOW THE IMAGES, STYLE IS SET INLINE STYLE + $('.creditcard-types').each(function(){ + var contents = $(this).parent().contents(); + contents[contents.length - 1].nodeValue = ''; + $(this).after('
'); + }); setFieldsShown(); diff --git a/public/images/Test-AmericanExpress-Icon.png b/public/images/credit_cards/Test-AmericanExpress-Icon.png similarity index 100% rename from public/images/Test-AmericanExpress-Icon.png rename to public/images/credit_cards/Test-AmericanExpress-Icon.png diff --git a/public/images/Test-Diners-Icon.png b/public/images/credit_cards/Test-Diners-Icon.png similarity index 100% rename from public/images/Test-Diners-Icon.png rename to public/images/credit_cards/Test-Diners-Icon.png diff --git a/public/images/Test-Discover-Icon.png b/public/images/credit_cards/Test-Discover-Icon.png similarity index 100% rename from public/images/Test-Discover-Icon.png rename to public/images/credit_cards/Test-Discover-Icon.png diff --git a/public/images/Test-MasterCard-Icon.png b/public/images/credit_cards/Test-MasterCard-Icon.png similarity index 100% rename from public/images/Test-MasterCard-Icon.png rename to public/images/credit_cards/Test-MasterCard-Icon.png diff --git a/public/images/Test-Visa-Icon.png b/public/images/credit_cards/Test-Visa-Icon.png similarity index 100% rename from public/images/Test-Visa-Icon.png rename to public/images/credit_cards/Test-Visa-Icon.png