diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d9402641..0868ee482 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,30 @@ +Release 4.14 (2015-02-03) +------------------------------------------------------------------------------ + +* New event hook: + * onBeforeThemeSettingsSave +* New API(client) calls: + * invoice_get_tax_rate + * client_is_taxable + * client_balance_get_total +* Taxes are shown in the cart checkout summary +* Email templates are generated after install +* Footer links fix for Huraga theme +* Only one coupon code name can be created and used; +* Fixed CKEditor issue with canned responses +* Custom payment gateway render error fixed +* Fixed Centova Cast module +* Password hash in email resolved +* Orderbutton module popup improved +* Client email confirmation logic updated +* Variables in email templates list fixed +* Generating email templates just after installing of BoxBilling +* Allow only text in Notification module messages +* Fixed constantly regenerating invoices issue +* Add funds logic updated +* Settings of footer links updated +* Security and performance fixes and updates + Release 4.13 (2015-01-15) ------------------------------------------------------------------------------ diff --git a/Vagrantfile b/Vagrantfile index 67f178920..2545df21c 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -5,7 +5,11 @@ dir = File.dirname(File.expand_path(__FILE__)) configValues = YAML.load_file("#{dir}/puphpet/config.yaml") data = configValues['vagrantfile-local'] -Vagrant.require_version '>= 1.6.0' +begin + Vagrant.require_version ">= 1.6.0" +rescue NoMethodError + raise 'BoxBilling is only supported on Vagrant >= 1.6. Please upgrade.' +end Vagrant.configure('2') do |config| config.vm.box = "#{data['vm']['box']}" diff --git a/puphpet/config.yaml b/puphpet/config.yaml index d8d9e7a17..9f5eb4e3f 100644 --- a/puphpet/config.yaml +++ b/puphpet/config.yaml @@ -3,7 +3,7 @@ vagrantfile-local: vm: box: puphpet/ubuntu1204-x64 box_url: puphpet/ubuntu1204-x64 - hostname: 'boxbilling' + hostname: 'boxbilling.test' memory: '512' cpus: '1' chosen_provider: virtualbox diff --git a/src/bb-modules/Activity/Service.php b/src/bb-modules/Activity/Service.php index 1b88454a7..bf063e5cd 100644 --- a/src/bb-modules/Activity/Service.php +++ b/src/bb-modules/Activity/Service.php @@ -92,6 +92,7 @@ class Service implements InjectionAwareInterface $search = isset($data['search']) ? $data['search'] : NULL; $priority = isset($data['priority']) ? $data['priority'] : NULL; $only_staff = isset($data['only_staff']) ? $data['only_staff'] : NULL; + $admin_id = isset($data['admin_id']) ? $data['admin_id'] : NULL; $only_clients = isset($data['only_clients']) ? $data['only_clients'] : NULL; $no_info = isset($data['no_info']) ? $data['no_info'] : NULL; $no_debug = isset($data['no_debug']) ? $data['no_debug'] : NULL; @@ -115,6 +116,11 @@ class Service implements InjectionAwareInterface $where[] = 'm.admin_id IS NOT NULL'; } + if($admin_id) { + $where[] = 'm.admin_id = :admin_id'; + $params[':admin_id'] = $admin_id; + } + if($only_clients) { $where[] = 'm.client_id IS NOT NULL'; } diff --git a/src/bb-modules/Cart/Service.php b/src/bb-modules/Cart/Service.php index 799259a4c..84ef27301 100644 --- a/src/bb-modules/Cart/Service.php +++ b/src/bb-modules/Cart/Service.php @@ -425,7 +425,7 @@ class Service implements InjectionAwareInterface ) ); - list($order, $invoice_id, $orders) = $this->createFromCart($client, $gateway_id); + list($order, $invoice, $orders) = $this->createFromCart($client, $gateway_id); $this->rm($cart); @@ -450,9 +450,8 @@ class Service implements InjectionAwareInterface ); // invoice may not be created if total is 0 - if ($invoice_id) { - $idata = $this->di['db']->getExistingModelById('Invoice', $invoice_id, 'Invoice not found'); - $result['invoice_hash'] = $idata->hash; + if ($invoice instanceof \Model_Invoice && $invoice->status == \Model_Invoice::STATUS_UNPAID) { + $result['invoice_hash'] = $invoice->hash; } return $result; @@ -460,18 +459,12 @@ class Service implements InjectionAwareInterface public function createFromCart(\Model_Client $client, $gateway_id = null) { - $cart = $this->getSessionCart(); - $cartProducts = $this->di['db']->find('CartProduct', 'cart_id = :cart_id', array(':cart_id' => $cart->id)); - if (count($cartProducts) == 0) { + $cart = $this->getSessionCart(); + $ca = $this->toApiArray($cart); + if (count($ca['items']) == 0) { throw new \Box_Exception('Can not checkout empty cart.'); } - $ca = $this->toApiArray($cart); - - $create_invoice = true; - if ($ca['total'] == 0) { - $create_invoice = false; - } $currency = $this->di['db']->getExistingModelById('Currency', $cart->currency_id, 'Currency not found.'); @@ -521,7 +514,7 @@ class Service implements InjectionAwareInterface $order->updated_at = date('c'); $this->di['db']->store($order); - $orders[] = $order->id; + $orders[] = $order; // mark promo as used if ($cart->promo_id) { @@ -568,44 +561,58 @@ class Service implements InjectionAwareInterface $i++; } - if ($create_invoice) { + if ($ca['total'] > 0) { //crete invoice if order total > 0 $invoiceService = $this->di['mod_service']('Invoice'); - $invoice_id = $invoiceService->prepareInvoice($client, array('client_id' => $client->id, 'items' => $invoice_items, 'gateway_id' => $gateway_id)); - $invoiceModel = $this->di['db']->load('Invoice', $invoice_id); - $invoiceService->approveInvoice($invoiceModel, array('id' => $invoice_id, 'use_credits' => true)); + $invoiceModel = $invoiceService->prepareInvoice($client, array('client_id' => $client->id, 'items' => $invoice_items, 'gateway_id' => $gateway_id)); - foreach ($orders as $oid) { - $o = $this->di['db']->load('ClientOrder', $oid); - $o->unpaid_invoice_id = $invoice_id; - $this->di['db']->store($o); - } + $clientBalanceService = $this->di['mod_service']('Client', 'Balance'); + $balanceAmount = $clientBalanceService->getClientBalance($client); + $useCredits = $balanceAmount >= $ca['total']; - $result = array($master_order, $invoice_id, $orders); - } else { - $result = array($master_order, null, $orders); - } + $invoiceService->approveInvoice($invoiceModel, array('id' => $invoiceModel->id, 'use_credits' => $useCredits)); - //activate orders if product is setup to be activated after order place or order total is $0 - $orderService = $this->di['mod_service']('Order'); - foreach ($orders as $oid) { - - $order = $this->di['db']->load('ClientOrder', $oid); - $oa = $orderService->toApiArray($order, false, $client); - $product = $this->di['db']->getExistingModelById('Product', $oa['product_id']); - if ($product->setup == \Model_ProductTable::SETUP_AFTER_ORDER || ($product->setup == \Model_ProductTable::SETUP_AFTER_PAYMENT && $oa['total'] - $oa['discount'] <= 0)) { - try { - $orderService->activateOrder($order); - } catch (\Exception $e) { - error_log($e->getMessage()); - $status = 'error'; - $notes = 'Order could not be activated after checkout due to error: ' . $e->getMessage(); - $orderService->orderStatusAdd($order, $status, $notes); + if ($invoiceModel->status == \Model_Invoice::STATUS_UNPAID) { + foreach ($orders as $order) { + $order->unpaid_invoice_id = $invoiceModel->id; + $this->di['db']->store($order); } } } - return $result; + //activate orders if product is setup to be activated after order place or order total is $0 + $orderService = $this->di['mod_service']('Order'); + $ids = array(); + foreach ($orders as $order) { + $ids[] = $order->id; + $oa = $orderService->toApiArray($order, false, $client); + $product = $this->di['db']->getExistingModelById('Product', $oa['product_id']); + try { + if ($product->setup == \Model_ProductTable::SETUP_AFTER_ORDER){ + $orderService->activateOrder($order); + } + + if ($ca['total'] <= 0 && $product->setup == \Model_ProductTable::SETUP_AFTER_PAYMENT && $oa['total'] - $oa['discount'] <= 0){ + $orderService->activateOrder($order); + } + + if ($ca['total'] > 0 && $product->setup == \Model_ProductTable::SETUP_AFTER_PAYMENT && $invoiceModel->status == \Model_Invoice::STATUS_PAID ){ + $orderService->activateOrder($order); + } + } + catch (\Exception $e) { + error_log($e->getMessage()); + $status = 'error'; + $notes = 'Order could not be activated after checkout due to error: ' . $e->getMessage(); + $orderService->orderStatusAdd($order, $status, $notes); + } + } + + return array( + $master_order, + isset($invoiceModel) ? $invoiceModel : null, + $ids, + ); } public function usePromo(\Model_Promo $promo) diff --git a/src/bb-modules/Client/Api/Client.php b/src/bb-modules/Client/Api/Client.php index 4558c2b97..f5efa0889 100644 --- a/src/bb-modules/Client/Api/Client.php +++ b/src/bb-modules/Client/Api/Client.php @@ -309,4 +309,19 @@ class Client extends \Api_Abstract return $pager; } + /** + * Get client balance + * @return float + */ + public function balance_get_total() + { + $service = $this->di['mod_service']('Client', 'Balance'); + return $service->getClientBalance($this->identity); + } + + public function is_taxable() + { + return $this->getService()->isClientTaxable($this->identity); + } + } \ No newline at end of file diff --git a/src/bb-modules/Client/Api/Guest.php b/src/bb-modules/Client/Api/Guest.php index feee154c6..47f87afed 100644 --- a/src/bb-modules/Client/Api/Guest.php +++ b/src/bb-modules/Client/Api/Guest.php @@ -119,9 +119,17 @@ class Guest extends \Api_Abstract $client = $service->guestCreateClient($data); + + if (isset($config['require_email_confirmation']) && (int)$config['require_email_confirmation']) { + if (!$client->email_approved) { + throw new \Box_Exception('Account has been created. Please check your mailbox and confirm email address.', null, 7777); + } + } + if(isset($data['auto_login']) && $data['auto_login']) { + try { - $this->login(array('email'=>$client->email, 'password' => $client->pass)); + $this->login(array('email'=>$client->email, 'password' => $data['password'])); } catch(\Exception $e) { error_log($e->getMessage()); } diff --git a/src/bb-modules/Client/Service.php b/src/bb-modules/Client/Service.php index 6a7847aa1..bed70300f 100644 --- a/src/bb-modules/Client/Service.php +++ b/src/bb-modules/Client/Service.php @@ -530,7 +530,7 @@ class Service implements InjectionAwareInterface { $this->di['events_manager']->fire(array('event'=>'onBeforeAdminCreateClient', 'params'=>$data)); $client = $this->createClient($data); - $this->di['events_manager']->fire(array('event'=>'onAfterAdminCreateClient', 'params'=>array('id'=>$client->id, 'password'=>$client->pass))); + $this->di['events_manager']->fire(array('event'=>'onAfterAdminCreateClient', 'params'=>array('id'=>$client->id, 'password'=>$data['password']))); $this->di['logger']->info('Created new client #%s', $client->id); return $client->id; @@ -546,7 +546,7 @@ class Service implements InjectionAwareInterface $data['status'] = \Model_Client::ACTIVE; $client = $this->createClient($data); - $this->di['events_manager']->fire(array('event'=>'onAfterClientSignUp', 'params'=>array('id'=>$client->id, 'password'=>$client->pass))); + $this->di['events_manager']->fire(array('event'=>'onAfterClientSignUp', 'params'=>array('id'=>$client->id, 'password'=>$data['password']))); $this->di['logger']->info('Client #%s signed up', $client->id); return $client; @@ -592,7 +592,13 @@ class Service implements InjectionAwareInterface return null; } - return $this->di['auth']->authorizeUser($model, $plainTextPassword); + $config = $this->di['mod_config']('client'); + if (isset($config['require_email_confirmation']) && (int)$config['require_email_confirmation']) { + if (!$model->email_approved) { + throw new \Box_Exception('Please check your mailbox and confirm email address.'); + } + } + return $this->di['auth']->authorizeUser($model, $plainTextPassword); } } \ No newline at end of file diff --git a/src/bb-modules/Client/html_admin/mod_client_settings.phtml b/src/bb-modules/Client/html_admin/mod_client_settings.phtml index 422c83f73..4e726e559 100644 --- a/src/bb-modules/Client/html_admin/mod_client_settings.phtml +++ b/src/bb-modules/Client/html_admin/mod_client_settings.phtml @@ -86,7 +86,7 @@
- {% for i in 0..10 %} + {% for i in 1..10 %} {% set field_name = 'custom_' ~ i %} {% set custom_field = attribute(params.custom_fields, field_name) %}
diff --git a/src/bb-modules/Client/html_client/mod_client_profile.phtml b/src/bb-modules/Client/html_client/mod_client_profile.phtml index 8a385878f..8e3502712 100644 --- a/src/bb-modules/Client/html_client/mod_client_profile.phtml +++ b/src/bb-modules/Client/html_client/mod_client_profile.phtml @@ -79,6 +79,22 @@
+
+ +
+ +

+
+
+ +
+ +
+ +

+
+
+
diff --git a/src/bb-modules/Email/Api/Admin.php b/src/bb-modules/Email/Api/Admin.php index c647844c6..e1514f913 100644 --- a/src/bb-modules/Email/Api/Admin.php +++ b/src/bb-modules/Email/Api/Admin.php @@ -264,7 +264,8 @@ class Admin extends \Api_Abstract $enabled = isset($data['enabled']) ? $data['enabled'] : 0; $category = isset($data['category']) ? $data['category'] : NULL; - return $this->getService()->templateCreate($data['action_code'], $data['subject'], $data['content'], $enabled, $category); + $templateModel = $this->getService()->templateCreate($data['action_code'], $data['subject'], $data['content'], $enabled, $category); + return $templateModel->id; } /** diff --git a/src/bb-modules/Email/Service.php b/src/bb-modules/Email/Service.php index 51a6ecdc5..36fc77eca 100644 --- a/src/bb-modules/Email/Service.php +++ b/src/bb-modules/Email/Service.php @@ -489,7 +489,7 @@ class Service implements \Box\InjectionAwareInterface $this->di['logger']->info('Added new email template #%s', $modelId); - return $modelId; + return $model; } public function templateBatchGenerate() @@ -516,15 +516,12 @@ class Service implements \Box\InjectionAwareInterface continue; } - list($s, $c, $desc, $enabled, $mod) = $this->_getDefaults(array('code' => $code)); - $t = $this->di['db']->dispense('EmailTemplate'); - $t->enabled = $enabled; - $t->action_code = $code; - $t->category = $mod; - $t->subject = $s; - $t->content = $c; - $t->description = $desc; - $this->di['db']->store($t); + list($subject, $content, $desc, $enabled, $mod) = $this->_getDefaults(array('code' => $code)); + $t = $this->templateCreate($code, $subject, $content, $enabled, $mod); + if ($desc) { + $t->description = $desc; + $this->di['db']->store($t); + } } $this->di['logger']->info('Generated email templates for installed extensions'); @@ -593,7 +590,7 @@ class Service implements \Box\InjectionAwareInterface $mail->addTo($queue->to, $queue->to_name); if (APPLICATION_ENV != 'production') { - //if(BB_DEBUG) error_log('Skip email sending'); + error_log('Skip email sending. Application ENV: '.APPLICATION_ENV); return true; } diff --git a/src/bb-modules/Email/html_admin/mod_email_history.phtml b/src/bb-modules/Email/html_admin/mod_email_history.phtml index b0dc8a35e..6d59cf8f5 100644 --- a/src/bb-modules/Email/html_admin/mod_email_history.phtml +++ b/src/bb-modules/Email/html_admin/mod_email_history.phtml @@ -4,6 +4,16 @@ {% set active_menu = 'activity' %} {% block content %} + +{% set config = admin.extension_config_get({"ext":"mod_email"}) %} +{% if config.log_enabled is not defined or config.log_enabled != 1 %} +
+

{% trans 'INFORMATION' %}: {% trans 'Email logging is not enabled. If you want to log sent mails to database, enable it in' %} + {% trans 'email settings.' %} +

+
+{% endif %} +
{% trans 'Email history' %}
diff --git a/src/bb-modules/Email/html_admin/mod_email_template.phtml b/src/bb-modules/Email/html_admin/mod_email_template.phtml index ec62c47b8..9614be2ed 100644 --- a/src/bb-modules/Email/html_admin/mod_email_template.phtml +++ b/src/bb-modules/Email/html_admin/mod_email_template.phtml @@ -102,14 +102,29 @@ {% for k,var in template.vars %} - {% if var|keys|length > 0 %} - {% for subkey,subvalue in var %} - - - {{ '{{' }} {{ k }}.{{subkey}} {{ '}}' }} - {{ subvalue }} - - {% endfor %} + {% if var is iterable %} + {% for subkey,subvalue in var %} + {% if subvalue is iterable %} + {% for subsubkey,subsubvalue in var %} + {% if subsubvalue is not iterable %} + + {{ '{{' }} {{ k }}.{{subkey}}.{{subsubkey}}{{ '}}' }} + {{ subsubvalue }} + + {% else %} + + {{ '{{' }} {{ k }}.{{subkey}}.{{subsubkey}}{{ '}}' }} + Array [ ] + + {% endif %} + {% endfor %} + {% else %} + + {{ '{{' }} {{ k }}.{{subkey}} {{ '}}' }} + {{ subvalue }} + + {% endif %} + {% endfor %} {% else %} {{ '{{' }} {{ k }} {{ '}}' }} @@ -117,7 +132,7 @@ {% endif %} - {% else %} + {% else %} {% trans 'This template does not receive any parameters' %} diff --git a/src/bb-modules/Embed/html_client/mod_embed_contact.phtml b/src/bb-modules/Embed/html_client/mod_embed_contact.phtml index fcb0fad11..c35e62f01 100644 --- a/src/bb-modules/Embed/html_client/mod_embed_contact.phtml +++ b/src/bb-modules/Embed/html_client/mod_embed_contact.phtml @@ -60,7 +60,7 @@ {% if guest.extension_is_on({"mod":"spamchecker"}) %} {% set rc = guest.spamchecker_recaptcha %} {% if rc.enabled %} - {% set server = "http://www.google.com/recaptcha/api" %} + {% set server = "https://www.google.com/recaptcha/api" %} {% endblock %} \ No newline at end of file diff --git a/src/bb-modules/Profile/Service.php b/src/bb-modules/Profile/Service.php index d2034238f..9b6af70a5 100644 --- a/src/bb-modules/Profile/Service.php +++ b/src/bb-modules/Profile/Service.php @@ -287,7 +287,7 @@ class Service implements InjectionAwareInterface $this->di['validator']->isPasswordStrong($password); - $client->pass = $password; + $client->pass = $this->di['password']->hashIt($password); $this->di['db']->store($client); $this->di['events_manager']->fire(array('event' => 'onAfterClientProfilePasswordChange', 'params' => array('id' => $client->id))); diff --git a/src/bb-modules/Theme/Controller/Admin.php b/src/bb-modules/Theme/Controller/Admin.php index 6369d22d4..39dfe8771 100644 --- a/src/bb-modules/Theme/Controller/Admin.php +++ b/src/bb-modules/Theme/Controller/Admin.php @@ -47,6 +47,8 @@ class Admin implements \Box\InjectionAwareInterface */ public function save_theme_settings(\Box_App $app, $theme) { + $this->di['events_manager']->fire(array('event' => 'onBeforeThemeSettingsSave', 'params' => $_POST)); + $api = $app->getApiAdmin(); $mod = $this->di['mod']('theme'); diff --git a/src/bb-themes/boxbilling/html/mod_cart_index.phtml b/src/bb-themes/boxbilling/html/mod_cart_index.phtml index 99eb5d628..7f5861afd 100644 --- a/src/bb-themes/boxbilling/html/mod_cart_index.phtml +++ b/src/bb-themes/boxbilling/html/mod_cart_index.phtml @@ -86,10 +86,20 @@
+ {% set tax_amount = 0 %} + {% if client.client_is_taxable %} + {% set tax_rate = client.invoice_get_tax_rate %} + {% set tax_amount = cart.total * tax_rate / 100 %} + +

{% trans 'VAT'%} ({{ tax_rate }}%) :

+ +
{{ tax_amount | money_convert }}
+ {% endif %}

{% trans 'Total:' %}

-
{{ cart.total | money_convert }}
+
{{ (cart.total + tax_amount) | money_convert }}
- {% if cart.total %} + {% set enough_in_balance = client.client_balance_get_total >= cart.total %} + {% if cart.total and not enough_in_balance %}
{% for gtw in guest.invoice_gateways %} {% if cart.currency.code in gtw.accepted_currencies %} @@ -103,6 +113,9 @@ {% endif %}
+ {% if enough_in_balance %} +

{% trans 'Total amount will be deducted from account balance' %}

+ {% endif %}
diff --git a/src/bb-themes/boxbilling/html/mod_page_login.phtml b/src/bb-themes/boxbilling/html/mod_page_login.phtml index b1c229c2c..4de1ea950 100644 --- a/src/bb-themes/boxbilling/html/mod_page_login.phtml +++ b/src/bb-themes/boxbilling/html/mod_page_login.phtml @@ -234,7 +234,7 @@ $(function() { //login after registration var login_details = { email: $('#reg-email').val(), - password: $('#reg-password').val(), + password: $('#reg-password').val() }; bb.post( 'guest/client/login', diff --git a/src/bb-themes/huraga/config/settings.html b/src/bb-themes/huraga/config/settings.html index 4fef58ae0..9e07b2730 100644 --- a/src/bb-themes/huraga/config/settings.html +++ b/src/bb-themes/huraga/config/settings.html @@ -269,27 +269,27 @@ - + - + - + - + - +
-> ->
-> ->
-> ->
-> ->
-> ->
diff --git a/src/bb-themes/huraga/html/layout_default.phtml b/src/bb-themes/huraga/html/layout_default.phtml index 5dd699ece..475f37c13 100644 --- a/src/bb-themes/huraga/html/layout_default.phtml +++ b/src/bb-themes/huraga/html/layout_default.phtml @@ -172,27 +172,48 @@
    {% if settings.footer_link_1_enabled %}
  • + {% if 'http://' in settings.footer_link_1_page or 'https://' in settings.footer_link_1_page%} + {{ settings.footer_link_1_title }} + {% else %} {{ settings.footer_link_1_title }} + {% endif %}
  • {% endif %} {% if settings.footer_link_2_enabled %}
  • - {{ settings.footer_link_2_title }} + {% if 'http://' in settings.footer_link_2_page or 'https://' in settings.footer_link_2_page%} + {{ settings.footer_link_2_title }} + {% else %} + {{ settings.footer_link_2_title }} + {% endif %}
  • {% endif %} {% if settings.footer_link_3_enabled %}
  • + {% if 'http://' in settings.footer_link_3_page or 'https://' in settings.footer_link_3_page%} + {{ settings.footer_link_3_title }} + {% else %} {{ settings.footer_link_3_title }} + + {%endif %}
  • {% endif %} {% if settings.footer_link_4_enabled %}
  • + {% if 'http://' in settings.footer_link_4_page or 'https://' in settings.footer_link_4_page%} + {{ settings.footer_link_4_title }} + {% else %} {{ settings.footer_link_4_title }} + {% endif %}
  • {% endif %} {% if settings.footer_link_5_enabled %}
  • + {% if 'http://' in settings.footer_link_5_page or 'https://' in settings.footer_link_5_page%} + {{ settings.footer_link_5_title }} + {% else %} {{ settings.footer_link_5_title }} + {% endif %}
  • {% endif %} diff --git a/src/install/index.php b/src/install/index.php index 4ef64bbeb..6a046c94f 100644 --- a/src/install/index.php +++ b/src/install/index.php @@ -1,13 +1,23 @@ makeInstall($this->session); + $this->generateEmailTemplates(); session_destroy(); print 'ok'; } catch(Exception $e) { @@ -446,6 +448,16 @@ final class Box_Installer throw new Exception('License Key is not valid'); } } + + private function generateEmailTemplates() + { + define('BB_PATH_MODS', BB_PATH_ROOT . '/bb-modules'); + + $emailService = new \Box\Mod\Email\Service(); + $di = $di = include BB_PATH_ROOT . '/bb-di.php'; + $emailService->setDi($di); + return $emailService->templateBatchGenerate(); + } } $action = isset($_GET['a']) ? $_GET['a'] : 'index'; diff --git a/tests/bb-library/Payment/Adapter/Payment_Adapter_InterkassaTest.php b/tests/bb-library/Payment/Adapter/Payment_Adapter_InterkassaTest.php index b89903586..dabacf9c7 100644 --- a/tests/bb-library/Payment/Adapter/Payment_Adapter_InterkassaTest.php +++ b/tests/bb-library/Payment/Adapter/Payment_Adapter_InterkassaTest.php @@ -150,7 +150,12 @@ class Payment_Adapter_InterkassaTest extends PHPUnit_Framework_TestCase { ->getMock(); $adapterMock->expects($this->atLeastOnce()) ->method('getParam') - ->withConsecutive('notify_url', 'return_url', 'return_url', 'cancel_url'); + ->withConsecutive( + array('ik_co_id'), + array('notify_url'), + array('return_url'), + array('return_url'), + array('cancel_url')); $paymentInvoiceMock = $this->getMockBuilder('Payment_Invoice') ->getMock(); @@ -234,7 +239,9 @@ class Payment_Adapter_InterkassaTest extends PHPUnit_Framework_TestCase { $adapterMock->expects($this->atLeastOnce()) ->method('getParam') - ->withConsecutive('ik_co_id', 'ik_secret_key') + ->withConsecutive( + array('ik_co_id'), + array('ik_secret_key')) ->willReturnOnConsecutiveCalls($shop_id, $secret_key); $data = array( @@ -265,7 +272,9 @@ class Payment_Adapter_InterkassaTest extends PHPUnit_Framework_TestCase { $adapterMock->expects($this->atLeastOnce()) ->method('getParam') - ->withConsecutive('ik_co_id', 'ik_secret_key') + ->withConsecutive( + array('ik_co_id'), + array('ik_secret_key')) ->willReturnOnConsecutiveCalls($shop_id, $secret_key); $data = array( @@ -291,7 +300,11 @@ class Payment_Adapter_InterkassaTest extends PHPUnit_Framework_TestCase { $adapterMock->expects($this->atLeastOnce()) ->method('getParam') - ->withConsecutive('ik_co_id', 'ik_secret_key', 'test_mode', 'ik_secret_key_test') + ->withConsecutive( + array('ik_co_id'), + array('ik_secret_key'), + array('test_mode'), + array('ik_secret_key_test')) ->willReturnOnConsecutiveCalls($shop_id, $secret_key, true, $secret_key); $data = array( @@ -355,7 +368,10 @@ class Payment_Adapter_InterkassaTest extends PHPUnit_Framework_TestCase { $dbMock->expects($this->atLeastOnce()) ->method('load') - ->withConsecutive('Transaction', 'Invoice', 'Client') + ->withConsecutive( + array('Transaction'), + array('Invoice'), + array('Client')) ->willReturnOnConsecutiveCalls($transactionModel, $invoiceModel, $clientModel); $dbMock->expects($this->atLeastOnce()) @@ -389,14 +405,18 @@ class Payment_Adapter_InterkassaTest extends PHPUnit_Framework_TestCase { $api_admin = new \Api_Handler($adminModel); $transaction_id = 1; + $invoice_id = 22; $data = array( 'post' => array( - 'ik_x_iid' => 1, + 'ik_x_iid' => $invoice_id, 'ik_trn_id' => 2, 'ik_inv_st' => 'success', 'ik_am' => 1.00, 'ik_cur' => 'USD', ), + 'get'=> array( + 'bb_invoice_id' => $invoice_id + ) ); $gateway_id = 1; $adapterMock->processTransaction($api_admin, $transaction_id, $data, $gateway_id); diff --git a/tests/bb-modules/Cart/ServiceTest.php b/tests/bb-modules/Cart/ServiceTest.php index a3124f10a..871167b16 100644 --- a/tests/bb-modules/Cart/ServiceTest.php +++ b/tests/bb-modules/Cart/ServiceTest.php @@ -678,9 +678,6 @@ class ServiceTest extends \PHPUnit_Framework_TestCase $promo->loadBean(new \RedBeanPHP\OODBBean()); $dbMock = $this->getMockBuilder('Box_Database')->getMock(); - $dbMock->expects($this->atLeastOnce()) - ->method('getExistingModelById') - ->will($this->returnValue($invoice)); $dbMock->expects($this->atLeastOnce()) ->method('load') ->will($this->returnValue($promo)); diff --git a/tests/bb-modules/Client/Api/ClientTest.php b/tests/bb-modules/Client/Api/ClientTest.php index 14860d034..09d26e1f3 100644 --- a/tests/bb-modules/Client/Api/ClientTest.php +++ b/tests/bb-modules/Client/Api/ClientTest.php @@ -175,5 +175,52 @@ class ClientTest extends \PHPUnit_Framework_TestCase { $result = $api->update($data); $this->assertTrue($result); } + + public function testbalance_get_total() + { + $balanceAmount = 0.00; + $model = new \Model_Client(); + $model->loadBean(new \RedBeanPHP\OODBBean()); + + $serviceMock = $this->getMockBuilder('\Box\Mod\Client\ServiceBalance')->getMock(); + $serviceMock->expects($this->atLeastOnce()) + ->method('getClientBalance') + ->will($this->returnValue($balanceAmount)); + + $di = new \Box_Di(); + $di['mod_service'] = $di->protect(function ($name, $sub) use($serviceMock) {return $serviceMock;}); + + $api = new \Box\Mod\Client\Api\Client(); + $api->setDi($di); + $api->setIdentity($model); + + $result = $api->balance_get_total(); + + $this->assertInternalType('float', $result); + $this->assertEquals($balanceAmount, $result); + + } + + public function testis_taxable() + { + $clientIsTaxable = true; + + $serviceMock = $this->getMockBuilder('\Box\Mod\Client\Service')->getMock(); + $serviceMock->expects($this->atLeastOnce()) + ->method('isClientTaxable') + ->willReturn($clientIsTaxable); + + $client = new \Model_Client(); + $client->loadBean(new \RedBeanPHP\OODBBean()); + + $api = new \Box\Mod\Client\Api\Client(); + $api->setService($serviceMock); + $api->setIdentity($client); + + $result = $api->is_taxable(); + $this->assertInternalType('bool', $result); + $this->assertEquals($clientIsTaxable, $result); + + } } \ No newline at end of file diff --git a/tests/bb-modules/Client/ServiceTest.php b/tests/bb-modules/Client/ServiceTest.php index 553300562..105e21726 100644 --- a/tests/bb-modules/Client/ServiceTest.php +++ b/tests/bb-modules/Client/ServiceTest.php @@ -1039,7 +1039,9 @@ class ServiceTest extends \PHPUnit_Framework_TestCase { $di = new \Box_Di(); $di['db'] = $dbMock; $di['auth'] = $authMock; - + $di['mod_config'] = $di->protect(function ($name) use($di) { + return array ('require_email_confirmation' => false); + }); $service = new \Box\Mod\Client\Service(); $service->setDi($di); @@ -1047,5 +1049,76 @@ class ServiceTest extends \PHPUnit_Framework_TestCase { $this->assertInstanceOf('\Model_Client', $result); } + /** + * @expectedException \Box_Exception + */ + public function testauthorizeClientEmailRequiredNotConfirmed() + { + $email = 'example@boxbilling.vm'; + $password = '123456'; + + $clientModel = new \Model_Client(); + $clientModel->loadBean(new \RedBeanPHP\OODBBean()); + + $dbMock = $this->getMockBuilder('\Box_Database')->getMock(); + $dbMock->expects($this->atLeastOnce()) + ->method('findOne') + ->with('Client') + ->willReturn($clientModel); + + $authMock = $this->getMockBuilder('\Box_Authorization')->disableOriginalConstructor()->getMock(); + $authMock->expects($this->never()) + ->method('authorizeUser') + ->with($clientModel, $password) + ->willReturn($clientModel); + + $di = new \Box_Di(); + $di['db'] = $dbMock; + $di['auth'] = $authMock; + $di['mod_config'] = $di->protect(function ($name) use ($di) { + return array('require_email_confirmation' => true); + }); + $service = new \Box\Mod\Client\Service(); + $service->setDi($di); + + $result = $service->authorizeClient($email, $password); + $this->assertInstanceOf('\Model_Client', $result); + } + + + public function testauthorizeClientEmailRequiredConfirmed() + { + $email = 'example@boxbilling.vm'; + $password = '123456'; + + $clientModel = new \Model_Client(); + $clientModel->loadBean(new \RedBeanPHP\OODBBean()); + $clientModel->email_approved = 1; + + $dbMock = $this->getMockBuilder('\Box_Database')->getMock(); + $dbMock->expects($this->atLeastOnce()) + ->method('findOne') + ->with('Client') + ->willReturn($clientModel); + + $authMock = $this->getMockBuilder('\Box_Authorization')->disableOriginalConstructor()->getMock(); + $authMock->expects($this->any()) + ->method('authorizeUser') + ->with($clientModel, $password) + ->willReturn($clientModel); + + $di = new \Box_Di(); + $di['db'] = $dbMock; + $di['auth'] = $authMock; + $di['mod_config'] = $di->protect(function ($name) use ($di) { + return array('require_email_confirmation' => true); + }); + $service = new \Box\Mod\Client\Service(); + $service->setDi($di); + + $result = $service->authorizeClient($email, $password); + $this->assertInstanceOf('\Model_Client', $result); + } + } \ No newline at end of file diff --git a/tests/bb-modules/Email/Api/Api_AdminTest.php b/tests/bb-modules/Email/Api/Api_AdminTest.php index 62e1c9326..2a3feed32 100644 --- a/tests/bb-modules/Email/Api/Api_AdminTest.php +++ b/tests/bb-modules/Email/Api/Api_AdminTest.php @@ -411,6 +411,11 @@ class AdminTest extends \PHPUnit_Framework_TestCase $adminApi = new \Box\Mod\Email\Api\Admin(); $modelId = rand(1, 100); + + $templateModel = new \Model_EmailTemplate(); + $templateModel->loadBean(new \RedBeanPHP\OODBBean()); + $templateModel->id = $modelId; + $data = array( 'action_code' => 'Action_code', 'subject' => 'Subject', @@ -420,7 +425,7 @@ class AdminTest extends \PHPUnit_Framework_TestCase $emailService = $this->getMockBuilder('Box\Mod\Email\Service')->setMethods(array('templateCreate'))->getMock(); $emailService->expects($this->atLeastOnce()) ->method('templateCreate') - ->will($this->returnValue($modelId)); + ->will($this->returnValue($templateModel)); $adminApi->setService($emailService); $result = $adminApi->template_create($data); diff --git a/tests/bb-modules/Email/ServiceTest.php b/tests/bb-modules/Email/ServiceTest.php index 0b0c41531..a7297eea0 100644 --- a/tests/bb-modules/Email/ServiceTest.php +++ b/tests/bb-modules/Email/ServiceTest.php @@ -874,7 +874,7 @@ class ServiceTest extends \PHPUnit_Framework_TestCase $result = $service->templateCreate($data['action_code'], $data['subject'], $data['content'], 1, $data['category']); - $this->assertEquals($id, $result); + $this->assertEquals($emailTemplateModel, $result); } public function testBatchTemplateGenerateProvider() diff --git a/tests/bb-modules/Invoice/Api/AdminTest.php b/tests/bb-modules/Invoice/Api/AdminTest.php index aaee5f655..69dfcbc5c 100644 --- a/tests/bb-modules/Invoice/Api/AdminTest.php +++ b/tests/bb-modules/Invoice/Api/AdminTest.php @@ -117,10 +117,14 @@ class AdminTest extends \PHPUnit_Framework_TestCase { ); $newInvoiceId = 1; + $invoiceModel = new \Model_Invoice(); + $invoiceModel->loadBean(new \RedBeanPHP\OODBBean()); + $invoiceModel->id = $newInvoiceId; + $serviceMock = $this->getMockBuilder('\Box\Mod\Invoice\Service')->getMock(); $serviceMock->expects($this->atLeastOnce()) ->method('prepareInvoice') - ->will($this->returnValue($newInvoiceId)); + ->will($this->returnValue($invoiceModel)); $validatorMock = $this->getMockBuilder('\Box_Validate')->getMock(); $validatorMock->expects($this->atLeastOnce()) diff --git a/tests/bb-modules/Invoice/Api/ClientTest.php b/tests/bb-modules/Invoice/Api/ClientTest.php index c21151ea4..fdd5aad9f 100644 --- a/tests/bb-modules/Invoice/Api/ClientTest.php +++ b/tests/bb-modules/Invoice/Api/ClientTest.php @@ -367,6 +367,33 @@ class ClientTest extends \PHPUnit_Framework_TestCase { $this->assertInternalType('array', $result); } + public function testget_tax_rate() + { + $client = new \Model_Client(); + $client->loadBean(new \RedBeanPHP\OODBBean()); + + $taxRate = 20; + + $invoiceTaxService = $this->getMockBuilder('\Box\Mod\Invoice\ServiceTax') + ->getMock(); + $invoiceTaxService->expects($this->atLeastOnce()) + ->method('getTaxRateForClient') + ->willReturn($taxRate); + + + $di = new \Box_Di(); + $di['mod_service'] = $di->protect(function ($service, $sub) use($invoiceTaxService){ + if ($service == 'Invoice' && $sub == 'Tax'){ + return $invoiceTaxService; + } + }); + $this->api->setDi($di); + $this->api->setIdentity($client); + + $result = $this->api->get_tax_rate(); + $this->assertEquals($taxRate, $result); + } + } diff --git a/tests/bb-modules/Invoice/ServiceTest.php b/tests/bb-modules/Invoice/ServiceTest.php index 490bf7e90..00e5994f7 100644 --- a/tests/bb-modules/Invoice/ServiceTest.php +++ b/tests/bb-modules/Invoice/ServiceTest.php @@ -628,8 +628,7 @@ class ServiceTest extends \PHPUnit_Framework_TestCase $serviceMock->setDi($di); $result = $serviceMock->prepareInvoice($clientModel, $data); - $this->assertInternalType('int', $result); - $this->assertEquals($newRecordId, $result); + $this->assertInstanceOf('Model_Invoice', $result); } public function testsetInvoiceDefaults() diff --git a/tests/bb-modules/Profile/ServiceTest.php b/tests/bb-modules/Profile/ServiceTest.php index 71608aada..f9a95dd0d 100644 --- a/tests/bb-modules/Profile/ServiceTest.php +++ b/tests/bb-modules/Profile/ServiceTest.php @@ -362,18 +362,27 @@ class ServiceTest extends \PHPUnit_Framework_TestCase $validatorMock = $this->getMockBuilder('\Box_Validate')->getMock(); $validatorMock->expects($this->atLeastOnce())->method('isPasswordStrong'); + $password = 'new password'; + + $passwordMock = $this->getMockBuilder('\Box_Password')->getMock(); + $passwordMock->expects($this->atLeastOnce()) + ->method('hashIt') + ->with($password); + + $di = new \Box_Di(); $di['logger'] = new \Box_Log(); $di['events_manager'] = $emMock; $di['db'] = $dbMock; $di['validator'] = $validatorMock; + $di['password'] = $passwordMock; $model = new \Model_Client(); $model->loadBean(new \RedBeanPHP\OODBBean()); $service = new Service(); $service->setDi($di); - $result = $service->changeClientPassword($model, 'new password'); + $result = $service->changeClientPassword($model, $password); $this->assertTrue($result); } diff --git a/tests/bb-modules/Theme/Controller/AdminTest.php b/tests/bb-modules/Theme/Controller/AdminTest.php index 8fb29f928..89187337e 100644 --- a/tests/bb-modules/Theme/Controller/AdminTest.php +++ b/tests/bb-modules/Theme/Controller/AdminTest.php @@ -122,6 +122,9 @@ class AdminTest extends \PHPUnit_Framework_TestCase { ->method('getService') ->willReturn($themeServiceMock); + $eventMock = $this->getMockBuilder('\Box_EventManager')->getMock(); + $eventMock->expects($this->atLeastOnce())->method('fire'); + $di = new \Box_Di(); $di['mod'] = $di->protect(function ($name) use($modMock){ if ($name == 'theme') @@ -129,6 +132,7 @@ class AdminTest extends \PHPUnit_Framework_TestCase { return $modMock; } }); + $di['events_manager'] = $eventMock; $controller = new \Box\Mod\Theme\Controller\Admin(); $controller->setDi($di); @@ -174,6 +178,9 @@ class AdminTest extends \PHPUnit_Framework_TestCase { ->method('getService') ->willReturn($themeServiceMock); + $eventMock = $this->getMockBuilder('\Box_EventManager')->getMock(); + $eventMock->expects($this->atLeastOnce())->method('fire'); + $di = new \Box_Di(); $di['mod'] = $di->protect(function ($name) use($modMock){ if ($name == 'theme') @@ -181,6 +188,7 @@ class AdminTest extends \PHPUnit_Framework_TestCase { return $modMock; } }); + $di['events_manager'] = $eventMock; $controller = new \Box\Mod\Theme\Controller\Admin(); $controller->setDi($di); diff --git a/tests/fixtures/initial.xml b/tests/fixtures/initial.xml index 00dcffe04..e8212c9db 100644 --- a/tests/fixtures/initial.xml +++ b/tests/fixtures/initial.xml @@ -7,12 +7,12 @@ - - - - - - + + + + + + diff --git a/tests/fixtures/mod_cart.xml b/tests/fixtures/mod_cart.xml index 8e669fd44..dec4dd9e0 100644 --- a/tests/fixtures/mod_cart.xml +++ b/tests/fixtures/mod_cart.xml @@ -52,20 +52,20 @@ - - + + - - - - - - + + + + + + - - - - + + + + @@ -76,6 +76,7 @@ + diff --git a/tests/fixtures/orders.xml b/tests/fixtures/orders.xml index 59b0a99f1..eed9dcf26 100644 --- a/tests/fixtures/orders.xml +++ b/tests/fixtures/orders.xml @@ -50,18 +50,18 @@ - - - - - - + + + + + + - - - - - + + + + + diff --git a/tests/fixtures/transactions.xml b/tests/fixtures/transactions.xml index 426285822..117fe3f43 100644 --- a/tests/fixtures/transactions.xml +++ b/tests/fixtures/transactions.xml @@ -8,9 +8,9 @@ - - - + + + diff --git a/tests/integration/bb-modules/mod_cart/Api_ClientTest.php b/tests/integration/bb-modules/mod_cart/Api_ClientTest.php index 3ed9afd11..b3d79402a 100644 --- a/tests/integration/bb-modules/mod_cart/Api_ClientTest.php +++ b/tests/integration/bb-modules/mod_cart/Api_ClientTest.php @@ -102,4 +102,86 @@ class Box_Mod_Cart_Api_ClientTest extends BBDbApiTestCase $this->assertEquals(9874, $e->getCode()); } } + + /** + * checkout cart with product with addon and client has insufficient funds to cover + */ + public function testAddonActivatedWhileOrderInvoiceUnpaid() + { + + $this->api_guest->cart_reset(); + $data = array( + 'id' => 11, + 'period' => '6M', + 'domain' => array( + 'action' => "register", + 'owndomain_sld' =>"", + 'owndomain_tld' =>".com", + 'register_sld' =>"newdomainregister", + 'register_tld' =>".com", + 'register_years' => "1", + ), + 'multiple' => 1, + + ); + $this->api_guest->cart_add_item($data); + $this->api_client->cart_checkout(); + + $masterOrder = $this->di['db']->findOne('ClientOrder', 'group_master = 1 ORDER BY id desc'); + $addonOrder = $this->di['db']->findOne('ClientOrder', 'group_id = ? and group_master = 0', array($masterOrder->group_id)); + + $invoiceModel = $this->di['db']->load('Invoice', $masterOrder->unpaid_invoice_id); + + $this->assertInstanceOf('Model_ClientOrder', $masterOrder); + $this->assertInstanceOf('Model_ClientOrder', $addonOrder); + $this->assertInstanceOf('Model_Invoice', $invoiceModel); + + $this->assertNotNull($masterOrder->unpaid_invoice_id); + $this->assertEquals(Model_ClientOrder::STATUS_PENDING_SETUP, $masterOrder->status); + $this->assertEquals(Model_ClientOrder::STATUS_PENDING_SETUP, $addonOrder->status); + $this->assertEquals(Model_Invoice::STATUS_UNPAID, $invoiceModel->status); + } + + + /** + * checkout cart with product with addon and client has sufficient funds to cover + */ + public function testOrderWithAddonCoverFromAccountBalance() + { + $this->api_guest->cart_reset(); + $data = array( + 'id' => 11, + 'period' => '6M', + 'domain' => array( + 'action' => "register", + 'owndomain_sld' =>"", + 'owndomain_tld' =>".com", + 'register_sld' =>"newdomainregister2", + 'register_tld' =>".com", + 'register_years' => "1", + ), + 'multiple' => 1, + + ); + + $this->api_admin->client_balance_add_funds(array('id' => 1, 'amount' => 100, 'description' => 'Added from PHPUnit')); + $this->api_guest->cart_add_item($data); + $this->api_client->cart_checkout(); + + $masterOrder = $this->di['db']->findOne('ClientOrder', 'group_master = 1 ORDER BY id desc'); + $addonOrder = $this->di['db']->findOne('ClientOrder', 'group_id = ? and group_master = 0', array($masterOrder->group_id)); + + $invoiceItemModel = $this->di['db']->findOne('InvoiceItem', "type = 'order' and rel_id = ?", array($masterOrder->id)); + $invoiceModel = $this->di['db']->load('Invoice', $invoiceItemModel->invoice_id); + + $this->assertInstanceOf('Model_ClientOrder', $masterOrder); + $this->assertInstanceOf('Model_ClientOrder', $addonOrder); + $this->assertInstanceOf('Model_Invoice', $invoiceModel); + + $this->assertNull($masterOrder->unpaid_invoice_id); + $this->assertEquals(Model_ClientOrder::STATUS_ACTIVE, $masterOrder->status); + $this->assertEquals(Model_ClientOrder::STATUS_ACTIVE, $addonOrder->status); + $this->assertEquals(Model_Invoice::STATUS_PAID, $invoiceModel->status); + } + } \ No newline at end of file diff --git a/tests/integration/bb-modules/mod_order/Api_AdminTest.php b/tests/integration/bb-modules/mod_order/Api_AdminTest.php index 60960fb88..8ad4487bb 100644 --- a/tests/integration/bb-modules/mod_order/Api_AdminTest.php +++ b/tests/integration/bb-modules/mod_order/Api_AdminTest.php @@ -210,7 +210,7 @@ class Api_Admin_OrderTest extends BBDbApiTestCase $data['client_id'] = 1; $data['product_id'] = $pid; $data['period'] = '1M'; - $data['group_id'] = 2; + $data['group_id'] = 200; // $data['currency'] = 'EUR'; // $data['invoice_option'] = 'issue-invoice'; $data['invoice_option'] = 'no-invoice';