From 565b26ba2754a2e16bf9a83fffddb1c61cd174f8 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 30 Dec 2015 20:45:52 +0200 Subject: [PATCH] Bug fixes --- .env.example | 1 - app/Http/Controllers/PaymentController.php | 15 ++++++++-- app/Models/Account.php | 32 ++++++++++++++++------ database/seeds/PaymentLibrariesSeeder.php | 1 + resources/views/invoices/history.blade.php | 1 + 5 files changed, 37 insertions(+), 13 deletions(-) diff --git a/.env.example b/.env.example index d103500d8a51..1dc6d99bd419 100644 --- a/.env.example +++ b/.env.example @@ -3,7 +3,6 @@ APP_DEBUG=false APP_URL=http://ninja.dev APP_CIPHER=rijndael-128 APP_KEY=SomeRandomString -APP_TIMEZONE DB_TYPE=mysql DB_STRICT=false diff --git a/app/Http/Controllers/PaymentController.php b/app/Http/Controllers/PaymentController.php index 9e5ab945cf92..3cd7d76d3574 100644 --- a/app/Http/Controllers/PaymentController.php +++ b/app/Http/Controllers/PaymentController.php @@ -495,7 +495,6 @@ class PaymentController extends BaseController if (!$token) { $token = Session::pull('transaction_reference'); } - if (!$token) { return redirect(NINJA_WEB_URL); } @@ -505,7 +504,17 @@ class PaymentController extends BaseController $client = $invoice->client; $account = $client->account; - $accountGateway = $account->getGatewayByType(Session::get($invitation->id . 'payment_type')); + if ($payerId) { + $paymentType = PAYMENT_TYPE_PAYPAL; + } else { + $paymentType = Session::get($invitation->id . 'payment_type'); + } + if (!$paymentType) { + $this->error('No-Payment-Type', false, false); + return Redirect::to($invitation->getLink()); + } + + $accountGateway = $account->getGatewayByType($paymentType); $gateway = $this->paymentService->createGateway($accountGateway); // Check for Dwolla payment error @@ -588,7 +597,7 @@ class PaymentController extends BaseController return Redirect::to('payments'); } - private function error($type, $error, $accountGateway, $exception = false) + private function error($type, $error, $accountGateway = false, $exception = false) { $message = ''; if ($accountGateway && $accountGateway->gateway) { diff --git a/app/Models/Account.php b/app/Models/Account.php index abb4f2e7d169..d3d71f176032 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -207,12 +207,26 @@ class Account extends Eloquent public function getDateTime($date = 'now') { - return new \DateTime($date, new \DateTimeZone($this->getTimezone())); + if ( ! $date) { + return null; + } elseif ( ! $date instanceof \DateTime) { + $date = new \DateTime($date); + } + + $date->setTimeZone(new \DateTimeZone($this->getTimezone())); + + return $date; } public function getCustomDateFormat() { - return $this->date_format ? $this->date_format->format : DEFAULT_DATE_FORMAT; + $format = $this->datetime_format ? $this->datetime_format->format : DEFAULT_DATETIME_FORMAT; + + if ($this->military_time) { + $format = str_replace('g:i a', 'H:i', $format); + } + + return $format; } public function formatMoney($amount, $client = null, $hideSymbol = false) @@ -238,10 +252,10 @@ class Account extends Eloquent public function formatDate($date) { + $date = $this->getDateTime($date); + if ( ! $date) { return null; - } elseif ( ! $date instanceof \DateTime) { - $date = new \DateTime($date); } return $date->format($this->getCustomDateFormat()); @@ -249,10 +263,10 @@ class Account extends Eloquent public function formatDateTime($date) { + $date = $this->getDateTime($date); + if ( ! $date) { return null; - } elseif ( ! $date instanceof \DateTime) { - $date = new \DateTime($date); } return $date->format($this->getCustomDateTimeFormat()); @@ -260,10 +274,10 @@ class Account extends Eloquent public function formatTime($date) { + $date = $this->getDateTime($date); + if ( ! $date) { return null; - } elseif ( ! $date instanceof \DateTime) { - $date = new \DateTime($date); } return $date->format($this->getCustomTimeFormat()); @@ -276,7 +290,7 @@ class Account extends Eloquent public function getCustomDateTimeFormat() { - return $this->datetime_format ? $this->datetime_format->format : DEFAULT_DATETIME_FORMAT; + return $this->getCustomDateFormat() . ' ' . $this->getCustomTimeFormat(); } public function getGatewayByType($type = PAYMENT_TYPE_ANY) diff --git a/database/seeds/PaymentLibrariesSeeder.php b/database/seeds/PaymentLibrariesSeeder.php index c2a66591be6c..b58d9b54d5c2 100644 --- a/database/seeds/PaymentLibrariesSeeder.php +++ b/database/seeds/PaymentLibrariesSeeder.php @@ -120,6 +120,7 @@ class PaymentLibrariesSeeder extends Seeder ['name' => 'Rwandan Franc', 'code' => 'RWF', 'symbol' => 'RF ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Tanzanian Shilling', 'code' => 'TZS', 'symbol' => 'TSh ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Netherlands Antillean Guilder', 'code' => 'ANG', 'symbol' => 'ANG ', 'precision' => '2', 'thousand_separator' => '.', 'decimal_separator' => ','], + ['name' => 'Trinidad and Tobago Dollar', 'code' => 'TTD', 'symbol' => 'TT$', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ]; foreach ($currencies as $currency) { diff --git a/resources/views/invoices/history.blade.php b/resources/views/invoices/history.blade.php index 4746205c5364..2657dabaa6ed 100644 --- a/resources/views/invoices/history.blade.php +++ b/resources/views/invoices/history.blade.php @@ -3,6 +3,7 @@ @section('head') @parent + @include('money_script')