From eea4237f322defbff642eb40da8e03190682eb8f Mon Sep 17 00:00:00 2001 From: 4Giedrius <4giedrius@gmail.com> Date: Mon, 19 Jan 2015 15:12:40 +0200 Subject: [PATCH 01/48] Added new Hook - 'onBeforeThemeSettingsSave' --- CHANGELOG.md | 6 ++++++ src/bb-modules/Theme/Controller/Admin.php | 2 ++ 2 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d9402641..1af4b0ae8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +Release 4.14 (2015-02-xx) +------------------------------------------------------------------------------ + +* New event hook: + * onBeforeThemeSettingsSave + Release 4.13 (2015-01-15) ------------------------------------------------------------------------------ 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'); From 54a8a5c8819cf8f8249c7037967ace21cb9f2828 Mon Sep 17 00:00:00 2001 From: Giedrius <4giedrius@gmail.com> Date: Tue, 20 Jan 2015 10:47:23 +0200 Subject: [PATCH 02/48] Vagrant 'require_version' bug fixed --- Vagrantfile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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']}" From 8ad1071b07429392f95f7f2ecf07bdbcb417083a Mon Sep 17 00:00:00 2001 From: Giedrius <4giedrius@gmail.com> Date: Tue, 20 Jan 2015 12:07:14 +0200 Subject: [PATCH 03/48] Unit tests updated --- tests/bb-modules/Theme/Controller/AdminTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) 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); From b2f04a271a3334ed8a8219cfa4565fc2f3a8048e Mon Sep 17 00:00:00 2001 From: Vaidas Lungis Date: Wed, 21 Jan 2015 21:57:16 +0200 Subject: [PATCH 04/48] Change puphpet config hostname value etc/hosts file will be updated correctly with new hostname value when setting up box --- puphpet/config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 77ad45ae1dbcc202358a02f1cc79f0977a9ead5f Mon Sep 17 00:00:00 2001 From: 4Giedrius <4giedrius@gmail.com> Date: Thu, 22 Jan 2015 13:35:26 +0200 Subject: [PATCH 05/48] Issue #231 with hashed password in email after signup fixed --- src/bb-modules/Client/Api/Guest.php | 2 +- src/bb-modules/Client/Service.php | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/bb-modules/Client/Api/Guest.php b/src/bb-modules/Client/Api/Guest.php index feee154c6..a352ee13e 100644 --- a/src/bb-modules/Client/Api/Guest.php +++ b/src/bb-modules/Client/Api/Guest.php @@ -121,7 +121,7 @@ class Guest extends \Api_Abstract 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..5b1319b66 100644 --- a/src/bb-modules/Client/Service.php +++ b/src/bb-modules/Client/Service.php @@ -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; @@ -593,6 +593,5 @@ class Service implements InjectionAwareInterface } return $this->di['auth']->authorizeUser($model, $plainTextPassword); - } } \ No newline at end of file From b2a8ffe6e5dd9314889f9be8d308a88ed34c6c1a Mon Sep 17 00:00:00 2001 From: 4Giedrius <4giedrius@gmail.com> Date: Thu, 22 Jan 2015 14:15:17 +0200 Subject: [PATCH 06/48] Show message if client needs to confirm email #231 --- src/bb-modules/Client/Api/Guest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/bb-modules/Client/Api/Guest.php b/src/bb-modules/Client/Api/Guest.php index a352ee13e..ad77f8e43 100644 --- a/src/bb-modules/Client/Api/Guest.php +++ b/src/bb-modules/Client/Api/Guest.php @@ -119,7 +119,15 @@ 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.'); + } + } + if(isset($data['auto_login']) && $data['auto_login']) { + try { $this->login(array('email'=>$client->email, 'password' => $data['password'])); } catch(\Exception $e) { From dc0cb6a1dae3cc91c91ed1ba93194080025f98b5 Mon Sep 17 00:00:00 2001 From: 4Giedrius <4giedrius@gmail.com> Date: Thu, 22 Jan 2015 16:00:21 +0200 Subject: [PATCH 07/48] Added check if email confirmation is required and if email was confirmed before login. --- src/bb-modules/Client/Service.php | 7 +++ tests/bb-modules/Client/ServiceTest.php | 75 ++++++++++++++++++++++++- 2 files changed, 81 insertions(+), 1 deletion(-) diff --git a/src/bb-modules/Client/Service.php b/src/bb-modules/Client/Service.php index 5b1319b66..4cc440d9a 100644 --- a/src/bb-modules/Client/Service.php +++ b/src/bb-modules/Client/Service.php @@ -592,6 +592,13 @@ class Service implements InjectionAwareInterface return null; } + $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/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 From 8b147f69a6c2790bcfb9e61df722d87fb3ce1337 Mon Sep 17 00:00:00 2001 From: 4Giedrius <4giedrius@gmail.com> Date: Thu, 22 Jan 2015 16:37:38 +0200 Subject: [PATCH 08/48] Trailing comma removed --- src/bb-themes/boxbilling/html/mod_page_login.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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', From 30c9ec44f632977b0d40a7a7bb013ba9edf4b8a5 Mon Sep 17 00:00:00 2001 From: 4Giedrius <4giedrius@gmail.com> Date: Fri, 23 Jan 2015 10:12:07 +0200 Subject: [PATCH 09/48] Added informational message to sent emails list view if mail logging is not enabled #238 #231 --- .../Email/html_admin/mod_email_history.phtml | 10 ++++++++++ 1 file changed, 10 insertions(+) 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' %}
From bb3652e47ac47e481e3e91898b65f316d8f3bce3 Mon Sep 17 00:00:00 2001 From: 4Giedrius <4giedrius@gmail.com> Date: Fri, 23 Jan 2015 10:18:33 +0200 Subject: [PATCH 10/48] Search by admin ID added to activity log --- src/bb-modules/Activity/Service.php | 6 ++++++ 1 file changed, 6 insertions(+) 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'; } From 8dbb38ff73421d10e4e4a8ff27e1eeb02f2103e8 Mon Sep 17 00:00:00 2001 From: 4Giedrius <4giedrius@gmail.com> Date: Fri, 23 Jan 2015 11:16:07 +0200 Subject: [PATCH 11/48] Custom client fields are 1 to 10, not 0 to 10, fixes #230 --- src/bb-modules/Client/html_admin/mod_client_settings.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) %}
From 9180cd09ace888dd796ecb318965be54e63a21d3 Mon Sep 17 00:00:00 2001 From: 4Giedrius <4giedrius@gmail.com> Date: Fri, 23 Jan 2015 11:31:15 +0200 Subject: [PATCH 12/48] Allow to edit company VAT and company number fields for client #230 --- .../Client/html_client/mod_client_profile.phtml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 @@
+
+ +
+ +

+
+
+ +
+ +
+ +

+
+
+
From 88ec2fe427f8e9377ac742d26abdd5ef1d14878e Mon Sep 17 00:00:00 2001 From: 4Giedrius <4giedrius@gmail.com> Date: Fri, 23 Jan 2015 12:47:34 +0200 Subject: [PATCH 13/48] Array variables for email template list fixed --- .../Email/html_admin/mod_email_template.phtml | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) 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' %} From 72e07ecfe33ced356b130d7c5fc6846c8ce51a5f Mon Sep 17 00:00:00 2001 From: Vaidas Lungis Date: Thu, 22 Jan 2015 14:29:01 +0200 Subject: [PATCH 14/48] add message to error_log when sending emails in testing application env --- src/bb-modules/Email/Service.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bb-modules/Email/Service.php b/src/bb-modules/Email/Service.php index 51a6ecdc5..0c7508c49 100644 --- a/src/bb-modules/Email/Service.php +++ b/src/bb-modules/Email/Service.php @@ -593,7 +593,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; } From 48b1195820293bde4d84411707adb71701820113 Mon Sep 17 00:00:00 2001 From: Vaidas Lungis Date: Fri, 23 Jan 2015 13:51:59 +0200 Subject: [PATCH 15/48] fix warnings in interkassa unit tests --- .../Payment_Adapter_InterkassaTest.php | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) 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); From a1251d7385c54e5afb0435cc58dd32ccf155ce20 Mon Sep 17 00:00:00 2001 From: Vaidas Lungis Date: Fri, 23 Jan 2015 14:02:52 +0200 Subject: [PATCH 16/48] D R Y when creating email templates --- src/bb-modules/Email/Api/Admin.php | 3 ++- src/bb-modules/Email/Service.php | 17 +++++++---------- tests/bb-modules/Email/Api/Api_AdminTest.php | 7 ++++++- tests/bb-modules/Email/ServiceTest.php | 2 +- 4 files changed, 16 insertions(+), 13 deletions(-) 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 0c7508c49..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'); 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() From c4e413dcc90fc8db7f6d0f36848401c15d884ae1 Mon Sep 17 00:00:00 2001 From: Vaidas Lungis Date: Fri, 23 Jan 2015 16:48:22 +0200 Subject: [PATCH 17/48] add "generate email templates" action after BB install. display_errors turned off. When DI tries to start new session and prints notice of already started session. Then JS call does not get 'ok' message and installation's "finish" step is not reached despite successful install. --- src/install/index.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/install/index.php b/src/install/index.php index 4ef64bbeb..ffcd5fbfb 100644 --- a/src/install/index.php +++ b/src/install/index.php @@ -2,7 +2,7 @@ date_default_timezone_set('UTC'); error_reporting(E_ALL); -ini_set('display_errors', 1); +ini_set('display_errors', 0); ini_set('display_startup_errors', 1); ini_set('log_errors', '1'); ini_set('error_log', dirname(__FILE__) . '/php_error.log'); @@ -32,15 +32,6 @@ set_include_path(implode(PATH_SEPARATOR, array( BB_PATH_LIBRARY, get_include_path(), ))); -spl_autoload_register('bb_autoloader'); - -function bb_autoloader($className) -{ - if(strpos($className, '_') !== false) { - $className = str_replace('_', DIRECTORY_SEPARATOR, $className); - } - require_once $className.'.php'; -} require BB_PATH_VENDOR . '/autoload.php'; @@ -113,6 +104,7 @@ final class Box_Installer } $this->makeInstall($this->session); + $this->generateEmailTemplates(); session_destroy(); print 'ok'; } catch(Exception $e) { @@ -446,6 +438,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'; From c194376ba0cd9beec2581b7630e443f145a013f6 Mon Sep 17 00:00:00 2001 From: 4Giedrius <4giedrius@gmail.com> Date: Mon, 26 Jan 2015 14:26:00 +0200 Subject: [PATCH 18/48] Added message for client if email confirmation is enabled #231 --- src/bb-modules/Client/Api/Guest.php | 2 +- .../Page/html_client/mod_page_signup.phtml | 32 +++++++++++++++---- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/bb-modules/Client/Api/Guest.php b/src/bb-modules/Client/Api/Guest.php index ad77f8e43..47f87afed 100644 --- a/src/bb-modules/Client/Api/Guest.php +++ b/src/bb-modules/Client/Api/Guest.php @@ -122,7 +122,7 @@ class Guest extends \Api_Abstract 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.'); + throw new \Box_Exception('Account has been created. Please check your mailbox and confirm email address.', null, 7777); } } diff --git a/src/bb-modules/Page/html_client/mod_page_signup.phtml b/src/bb-modules/Page/html_client/mod_page_signup.phtml index 40616d477..bde8eef08 100644 --- a/src/bb-modules/Page/html_client/mod_page_signup.phtml +++ b/src/bb-modules/Page/html_client/mod_page_signup.phtml @@ -17,7 +17,12 @@ {% endif %}
+
+
{% set r = guest.client_required %}
@@ -211,13 +216,28 @@ {% block js %} {% endblock %} \ No newline at end of file From d9061bd3f9f0297396464986774b13a8c9ac3191 Mon Sep 17 00:00:00 2001 From: Vaidas Lungis Date: Mon, 26 Jan 2015 17:52:12 +0200 Subject: [PATCH 19/48] increase test fixture's group_id values. old values were mixing with mysql's incremental initial value of table --- tests/fixtures/initial.xml | 12 +++++----- tests/fixtures/mod_cart.xml | 24 +++++++++---------- tests/fixtures/orders.xml | 22 ++++++++--------- tests/fixtures/transactions.xml | 6 ++--- .../bb-modules/mod_order/Api_AdminTest.php | 2 +- 5 files changed, 33 insertions(+), 33 deletions(-) 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..2f90634ed 100644 --- a/tests/fixtures/mod_cart.xml +++ b/tests/fixtures/mod_cart.xml @@ -52,20 +52,20 @@ - - + + - - - - - - + + + + + + - - - - + + + + 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_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'; From 47dff4160ea53ba3d3a9e588faae4d6ffea43f75 Mon Sep 17 00:00:00 2001 From: Vaidas Lungis Date: Tue, 27 Jan 2015 10:10:34 +0200 Subject: [PATCH 20/48] do not activate order addon while invoice is not paid --- src/bb-modules/Cart/Service.php | 33 +++++++++++++++- tests/fixtures/mod_cart.xml | 1 + .../bb-modules/mod_cart/Api_ClientTest.php | 38 +++++++++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/src/bb-modules/Cart/Service.php b/src/bb-modules/Cart/Service.php index 799259a4c..dfae402e2 100644 --- a/src/bb-modules/Cart/Service.php +++ b/src/bb-modules/Cart/Service.php @@ -593,7 +593,7 @@ class Service implements InjectionAwareInterface $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)) { + if ($product->setup == \Model_ProductTable::SETUP_AFTER_ORDER || ($this->canActivateOrder($product, $oa))) { try { $orderService->activateOrder($order); } catch (\Exception $e) { @@ -608,6 +608,37 @@ class Service implements InjectionAwareInterface return $result; } + /** + * Activate order rules: + * - product setup == SETUP_AFTER_PAYMENT + * - order amount must be > 0 + * - group invoice must be paid to activate zero amount and addon order + * + * @param \Model_Product $product + * @param array $orderArray + * @return bool + */ + public function canActivateOrder(\Model_Product $product, array $orderArray) + { + if ($product->setup != \Model_ProductTable::SETUP_AFTER_PAYMENT){ + return false; + } + + if ($orderArray['total'] - $orderArray['discount'] > 0){ + return false; + } + + if ($orderArray['group_master'] == 0 && $orderArray['group_id'] > 0){ + $invoice = $this->di['db']->load('Invoice', $orderArray['unpaid_invoice_id']); + if ($invoice->status != \Model_Invoice::STATUS_PAID){ + return false; + } + + } + + return true; + } + public function usePromo(\Model_Promo $promo) { $promo->used++; diff --git a/tests/fixtures/mod_cart.xml b/tests/fixtures/mod_cart.xml index 2f90634ed..dec4dd9e0 100644 --- a/tests/fixtures/mod_cart.xml +++ b/tests/fixtures/mod_cart.xml @@ -76,6 +76,7 @@ + diff --git a/tests/integration/bb-modules/mod_cart/Api_ClientTest.php b/tests/integration/bb-modules/mod_cart/Api_ClientTest.php index 3ed9afd11..33b35f267 100644 --- a/tests/integration/bb-modules/mod_cart/Api_ClientTest.php +++ b/tests/integration/bb-modules/mod_cart/Api_ClientTest.php @@ -102,4 +102,42 @@ class Box_Mod_Cart_Api_ClientTest extends BBDbApiTestCase $this->assertEquals(9874, $e->getCode()); } } + + /** + * addon activated while order Invoice Unpaid + */ + 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->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); + } } \ No newline at end of file From 95a435456b2ecdd24be63a83418e9ff2db1b1f3d Mon Sep 17 00:00:00 2001 From: Vaidas Lungis Date: Tue, 27 Jan 2015 10:28:27 +0200 Subject: [PATCH 21/48] order models are stored in array, not it ids --- src/bb-modules/Cart/Service.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/bb-modules/Cart/Service.php b/src/bb-modules/Cart/Service.php index dfae402e2..b3c1fcd43 100644 --- a/src/bb-modules/Cart/Service.php +++ b/src/bb-modules/Cart/Service.php @@ -521,7 +521,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) { @@ -575,10 +575,9 @@ class Service implements InjectionAwareInterface $invoiceModel = $this->di['db']->load('Invoice', $invoice_id); $invoiceService->approveInvoice($invoiceModel, array('id' => $invoice_id, 'use_credits' => true)); - foreach ($orders as $oid) { - $o = $this->di['db']->load('ClientOrder', $oid); - $o->unpaid_invoice_id = $invoice_id; - $this->di['db']->store($o); + foreach ($orders as $order) { + $order->unpaid_invoice_id = $invoice_id; + $this->di['db']->store($order); } $result = array($master_order, $invoice_id, $orders); @@ -588,9 +587,8 @@ class Service implements InjectionAwareInterface //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) { + foreach ($orders as $order) { - $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 || ($this->canActivateOrder($product, $oa))) { From 16367a2a5cd466a48ccba09f98a059b8d87f3d27 Mon Sep 17 00:00:00 2001 From: Vaidas Lungis Date: Tue, 27 Jan 2015 10:39:52 +0200 Subject: [PATCH 22/48] remove redundant cart query --- src/bb-modules/Cart/Service.php | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/bb-modules/Cart/Service.php b/src/bb-modules/Cart/Service.php index b3c1fcd43..9270b5c12 100644 --- a/src/bb-modules/Cart/Service.php +++ b/src/bb-modules/Cart/Service.php @@ -460,18 +460,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.'); @@ -568,7 +562,7 @@ 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)); From 62ee45c96fc322e917bbeed1dd9a216ff7c872de Mon Sep 17 00:00:00 2001 From: Vaidas Lungis Date: Tue, 27 Jan 2015 11:09:48 +0200 Subject: [PATCH 23/48] prepareInvoice() will return Model_Invoice object instead of invoice id --- src/bb-modules/Invoice/Api/Admin.php | 3 ++- src/bb-modules/Invoice/Service.php | 2 +- tests/bb-modules/Invoice/Api/AdminTest.php | 6 +++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/bb-modules/Invoice/Api/Admin.php b/src/bb-modules/Invoice/Api/Admin.php index 21f7e295d..b06d7073b 100644 --- a/src/bb-modules/Invoice/Api/Admin.php +++ b/src/bb-modules/Invoice/Api/Admin.php @@ -93,7 +93,8 @@ class Admin extends \Api_Abstract $client = $this->di['db']->getExistingModelById('Client', $data['client_id'], 'Client not found'); - return $this->getService()->prepareInvoice($client, $data); + $invoice = $this->getService()->prepareInvoice($client, $data); + return $invoice->id; } /** diff --git a/src/bb-modules/Invoice/Service.php b/src/bb-modules/Invoice/Service.php index c4bd5f2f0..f2241ceaf 100644 --- a/src/bb-modules/Invoice/Service.php +++ b/src/bb-modules/Invoice/Service.php @@ -493,7 +493,7 @@ class Service implements InjectionAwareInterface } } - return $invoiceId; + return $model; } public function setInvoiceDefaults(\Model_Invoice $model) 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()) From 5789d1b214cbe5bf6ef161d1087b6d7507ddd5f4 Mon Sep 17 00:00:00 2001 From: 4Giedrius <4giedrius@gmail.com> Date: Tue, 27 Jan 2015 11:17:03 +0200 Subject: [PATCH 24/48] Client password fixes --- src/bb-modules/Client/Service.php | 2 +- src/bb-modules/Profile/Service.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bb-modules/Client/Service.php b/src/bb-modules/Client/Service.php index 4cc440d9a..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; 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))); From 6daa231085142ae13f5156b4e5ef32cbab2a2dab Mon Sep 17 00:00:00 2001 From: Vaidas Lungis Date: Tue, 27 Jan 2015 11:34:56 +0200 Subject: [PATCH 25/48] REVERT do not activate order addon while invoice is not paid (reverted from commit 47dff4160ea53ba3d3a9e588faae4d6ffea43f75) --- src/bb-modules/Cart/Service.php | 33 +--------------- tests/fixtures/mod_cart.xml | 1 - .../bb-modules/mod_cart/Api_ClientTest.php | 38 ------------------- 3 files changed, 1 insertion(+), 71 deletions(-) diff --git a/src/bb-modules/Cart/Service.php b/src/bb-modules/Cart/Service.php index 9270b5c12..0b1a8518d 100644 --- a/src/bb-modules/Cart/Service.php +++ b/src/bb-modules/Cart/Service.php @@ -585,7 +585,7 @@ class Service implements InjectionAwareInterface $oa = $orderService->toApiArray($order, false, $client); $product = $this->di['db']->getExistingModelById('Product', $oa['product_id']); - if ($product->setup == \Model_ProductTable::SETUP_AFTER_ORDER || ($this->canActivateOrder($product, $oa))) { + 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) { @@ -600,37 +600,6 @@ class Service implements InjectionAwareInterface return $result; } - /** - * Activate order rules: - * - product setup == SETUP_AFTER_PAYMENT - * - order amount must be > 0 - * - group invoice must be paid to activate zero amount and addon order - * - * @param \Model_Product $product - * @param array $orderArray - * @return bool - */ - public function canActivateOrder(\Model_Product $product, array $orderArray) - { - if ($product->setup != \Model_ProductTable::SETUP_AFTER_PAYMENT){ - return false; - } - - if ($orderArray['total'] - $orderArray['discount'] > 0){ - return false; - } - - if ($orderArray['group_master'] == 0 && $orderArray['group_id'] > 0){ - $invoice = $this->di['db']->load('Invoice', $orderArray['unpaid_invoice_id']); - if ($invoice->status != \Model_Invoice::STATUS_PAID){ - return false; - } - - } - - return true; - } - public function usePromo(\Model_Promo $promo) { $promo->used++; diff --git a/tests/fixtures/mod_cart.xml b/tests/fixtures/mod_cart.xml index dec4dd9e0..2f90634ed 100644 --- a/tests/fixtures/mod_cart.xml +++ b/tests/fixtures/mod_cart.xml @@ -76,7 +76,6 @@ - diff --git a/tests/integration/bb-modules/mod_cart/Api_ClientTest.php b/tests/integration/bb-modules/mod_cart/Api_ClientTest.php index 33b35f267..3ed9afd11 100644 --- a/tests/integration/bb-modules/mod_cart/Api_ClientTest.php +++ b/tests/integration/bb-modules/mod_cart/Api_ClientTest.php @@ -102,42 +102,4 @@ class Box_Mod_Cart_Api_ClientTest extends BBDbApiTestCase $this->assertEquals(9874, $e->getCode()); } } - - /** - * addon activated while order Invoice Unpaid - */ - 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->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); - } } \ No newline at end of file From 9847d83f93879f09fe54f9ee1361d42488e384fc Mon Sep 17 00:00:00 2001 From: Vaidas Lungis Date: Tue, 27 Jan 2015 12:06:55 +0200 Subject: [PATCH 26/48] do not set order unpaid_invoice_id if it was covered from client balance --- src/bb-modules/Cart/Service.php | 15 ++++++++------- tests/fixtures/mod_cart.xml | 1 + 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/bb-modules/Cart/Service.php b/src/bb-modules/Cart/Service.php index 0b1a8518d..32fd335f7 100644 --- a/src/bb-modules/Cart/Service.php +++ b/src/bb-modules/Cart/Service.php @@ -565,16 +565,17 @@ class Service implements InjectionAwareInterface 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)); + $invoiceService->approveInvoice($invoiceModel, array('id' => $invoiceModel->id, 'use_credits' => true)); - foreach ($orders as $order) { - $order->unpaid_invoice_id = $invoice_id; - $this->di['db']->store($order); + if ($invoiceModel->status == \Model_Invoice::STATUS_UNPAID) { + foreach ($orders as $order) { + $order->unpaid_invoice_id = $invoiceModel->id; + $this->di['db']->store($order); + } } - $result = array($master_order, $invoice_id, $orders); + $result = array($master_order, $invoiceModel->id, $orders); } else { $result = array($master_order, null, $orders); } diff --git a/tests/fixtures/mod_cart.xml b/tests/fixtures/mod_cart.xml index 2f90634ed..dec4dd9e0 100644 --- a/tests/fixtures/mod_cart.xml +++ b/tests/fixtures/mod_cart.xml @@ -76,6 +76,7 @@ + From 9c1cab3ffae8010459811f06adc5959f9d65a00f Mon Sep 17 00:00:00 2001 From: Vaidas Lungis Date: Tue, 27 Jan 2015 14:01:55 +0200 Subject: [PATCH 27/48] fix related to 95a435456b2ecdd24be63a83418e9ff2db1b1f3d return array with order ids --- src/bb-modules/Cart/Service.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/bb-modules/Cart/Service.php b/src/bb-modules/Cart/Service.php index 32fd335f7..43c1a3592 100644 --- a/src/bb-modules/Cart/Service.php +++ b/src/bb-modules/Cart/Service.php @@ -582,8 +582,9 @@ class Service implements InjectionAwareInterface //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']); if ($product->setup == \Model_ProductTable::SETUP_AFTER_ORDER || ($product->setup == \Model_ProductTable::SETUP_AFTER_PAYMENT && $oa['total'] - $oa['discount'] <= 0)) { @@ -598,6 +599,7 @@ class Service implements InjectionAwareInterface } } + $result[2] = $ids; return $result; } From 9eafbfd167793a5629b47390d3f9db136f35e2cf Mon Sep 17 00:00:00 2001 From: Vaidas Lungis Date: Tue, 27 Jan 2015 14:36:53 +0200 Subject: [PATCH 28/48] do not activate addon order while master order is not paid --- src/bb-modules/Cart/Service.php | 19 +++++---- .../bb-modules/mod_cart/Api_ClientTest.php | 39 +++++++++++++++++++ 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/src/bb-modules/Cart/Service.php b/src/bb-modules/Cart/Service.php index 43c1a3592..931210a71 100644 --- a/src/bb-modules/Cart/Service.php +++ b/src/bb-modules/Cart/Service.php @@ -587,15 +587,20 @@ class Service implements InjectionAwareInterface $ids[] = $order->id; $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 { + try { + if ($product->setup == \Model_ProductTable::SETUP_AFTER_ORDER){ $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 ($ca['total'] <= 0 && $product->setup == \Model_ProductTable::SETUP_AFTER_PAYMENT && $oa['total'] - $oa['discount'] <= 0){ + $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); } } diff --git a/tests/integration/bb-modules/mod_cart/Api_ClientTest.php b/tests/integration/bb-modules/mod_cart/Api_ClientTest.php index 3ed9afd11..5816e4763 100644 --- a/tests/integration/bb-modules/mod_cart/Api_ClientTest.php +++ b/tests/integration/bb-modules/mod_cart/Api_ClientTest.php @@ -102,4 +102,43 @@ class Box_Mod_Cart_Api_ClientTest extends BBDbApiTestCase $this->assertEquals(9874, $e->getCode()); } } + + /** + * addon activated while order Invoice Unpaid + */ + 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->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); + } + } \ No newline at end of file From f14fe0785b52d4f7b660e3ebd894adc53ed4e822 Mon Sep 17 00:00:00 2001 From: Vaidas Lungis Date: Tue, 27 Jan 2015 14:39:26 +0200 Subject: [PATCH 29/48] unit test fix related 62ee45c96fc322e917bbeed1dd9a216ff7c872de --- tests/bb-modules/Invoice/ServiceTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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() From 1d70b15b5726e723c5269f78192bfc1e824f4565 Mon Sep 17 00:00:00 2001 From: 4Giedrius <4giedrius@gmail.com> Date: Tue, 27 Jan 2015 14:43:41 +0200 Subject: [PATCH 30/48] Admin notification new message logic moved to service class --- src/bb-modules/Notification/Api/Admin.php | 14 +------------- src/bb-modules/Notification/Service.php | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/bb-modules/Notification/Api/Admin.php b/src/bb-modules/Notification/Api/Admin.php index 9383cf8d4..4b8ef57b9 100644 --- a/src/bb-modules/Notification/Api/Admin.php +++ b/src/bb-modules/Notification/Api/Admin.php @@ -68,19 +68,7 @@ class Admin extends \Api_Abstract return false; } - $meta = $this->di['db']->dispense('extension_meta'); - $meta->extension = 'mod_notification'; - $meta->rel_type = 'staff'; - $meta->rel_id = 1; - $meta->meta_key = 'message'; - $meta->meta_value = $data['message']; - $meta->created_at = date('c'); - $meta->updated_at = date('c'); - $id = $this->di['db']->store($meta); - - $this->di['events_manager']->fire(array('event' => 'onAfterAdminNotificationAdd', 'params' => array('id' => $id))); - - return $id; + return $this->getService()->create($data['message']); } /** diff --git a/src/bb-modules/Notification/Service.php b/src/bb-modules/Notification/Service.php index b28b059b2..1ad7c65a3 100644 --- a/src/bb-modules/Notification/Service.php +++ b/src/bb-modules/Notification/Service.php @@ -45,4 +45,21 @@ class Service implements InjectionAwareInterface { return $this->di['db']->toArray($row); } + + public function create($message) + { + $meta = $this->di['db']->dispense('extension_meta'); + $meta->extension = 'mod_notification'; + $meta->rel_type = 'staff'; + $meta->rel_id = 1; + $meta->meta_key = 'message'; + $meta->meta_value = $message; + $meta->created_at = date('c'); + $meta->updated_at = date('c'); + $id = $this->di['db']->store($meta); + + $this->di['events_manager']->fire(array('event' => 'onAfterAdminNotificationAdd', 'params' => array('id' => $id))); + + return $id; + } } \ No newline at end of file From 3c82310d3585af96b7aada52506cb04cfda988a0 Mon Sep 17 00:00:00 2001 From: Vaidas Lungis Date: Tue, 27 Jan 2015 16:29:13 +0200 Subject: [PATCH 31/48] Client\Api\Client balance_get_total() created returns client balance amount --- src/bb-modules/Client/Api/Client.php | 10 +++++++++ tests/bb-modules/Client/Api/ClientTest.php | 25 ++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/bb-modules/Client/Api/Client.php b/src/bb-modules/Client/Api/Client.php index 4558c2b97..20f5cecdc 100644 --- a/src/bb-modules/Client/Api/Client.php +++ b/src/bb-modules/Client/Api/Client.php @@ -309,4 +309,14 @@ 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); + } + } \ No newline at end of file diff --git a/tests/bb-modules/Client/Api/ClientTest.php b/tests/bb-modules/Client/Api/ClientTest.php index 14860d034..e63912588 100644 --- a/tests/bb-modules/Client/Api/ClientTest.php +++ b/tests/bb-modules/Client/Api/ClientTest.php @@ -175,5 +175,30 @@ 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); + + } } \ No newline at end of file From 9612b6cd8205f99dc212b8db07765c14fd63ac66 Mon Sep 17 00:00:00 2001 From: Vaidas Lungis Date: Tue, 27 Jan 2015 16:40:51 +0200 Subject: [PATCH 32/48] cover invoice if client has enought money in balance and activate orders in checkout --- src/bb-modules/Cart/Service.php | 11 ++++- .../bb-modules/mod_cart/Api_ClientTest.php | 45 ++++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/bb-modules/Cart/Service.php b/src/bb-modules/Cart/Service.php index 931210a71..f1dc86d5f 100644 --- a/src/bb-modules/Cart/Service.php +++ b/src/bb-modules/Cart/Service.php @@ -566,7 +566,12 @@ class Service implements InjectionAwareInterface $invoiceService = $this->di['mod_service']('Invoice'); $invoiceModel = $invoiceService->prepareInvoice($client, array('client_id' => $client->id, 'items' => $invoice_items, 'gateway_id' => $gateway_id)); - $invoiceService->approveInvoice($invoiceModel, array('id' => $invoiceModel->id, 'use_credits' => true)); + + $clientBalanceService = $this->di['mod_service']('Client', 'Balance'); + $balanceAmount = $clientBalanceService->getClientBalance($client); + $useCredits = $balanceAmount > $ca['total']; + + $invoiceService->approveInvoice($invoiceModel, array('id' => $invoiceModel->id, 'use_credits' => $useCredits)); if ($invoiceModel->status == \Model_Invoice::STATUS_UNPAID) { foreach ($orders as $order) { @@ -595,6 +600,10 @@ class Service implements InjectionAwareInterface 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()); diff --git a/tests/integration/bb-modules/mod_cart/Api_ClientTest.php b/tests/integration/bb-modules/mod_cart/Api_ClientTest.php index 5816e4763..b3d79402a 100644 --- a/tests/integration/bb-modules/mod_cart/Api_ClientTest.php +++ b/tests/integration/bb-modules/mod_cart/Api_ClientTest.php @@ -104,7 +104,7 @@ class Box_Mod_Cart_Api_ClientTest extends BBDbApiTestCase } /** - * addon activated while order Invoice Unpaid + * checkout cart with product with addon and client has insufficient funds to cover */ public function testAddonActivatedWhileOrderInvoiceUnpaid() { @@ -136,9 +136,52 @@ class Box_Mod_Cart_Api_ClientTest extends BBDbApiTestCase $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 From 88d414360d80d49fd606b082ceebca5076073c34 Mon Sep 17 00:00:00 2001 From: Vaidas Lungis Date: Tue, 27 Jan 2015 16:53:16 +0200 Subject: [PATCH 33/48] Do not show payment gateways when client has enough in account balance --- .../Orderbutton/html_client/mod_orderbutton_checkout.phtml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/bb-modules/Orderbutton/html_client/mod_orderbutton_checkout.phtml b/src/bb-modules/Orderbutton/html_client/mod_orderbutton_checkout.phtml index 03ac9643c..447e4d517 100644 --- a/src/bb-modules/Orderbutton/html_client/mod_orderbutton_checkout.phtml +++ b/src/bb-modules/Orderbutton/html_client/mod_orderbutton_checkout.phtml @@ -154,7 +154,8 @@
- {% 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 %} @@ -168,6 +169,9 @@ {% endif %}
+ {% if enough_in_balance %} +

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

+ {% endif %}
From bcacd3175830f4724d6ff6d2e682d013d2fb4a5b Mon Sep 17 00:00:00 2001 From: Vaidas Lungis Date: Tue, 27 Jan 2015 16:57:56 +0200 Subject: [PATCH 34/48] update $result array --- src/bb-modules/Cart/Service.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/bb-modules/Cart/Service.php b/src/bb-modules/Cart/Service.php index f1dc86d5f..8b79483c5 100644 --- a/src/bb-modules/Cart/Service.php +++ b/src/bb-modules/Cart/Service.php @@ -579,10 +579,6 @@ class Service implements InjectionAwareInterface $this->di['db']->store($order); } } - - $result = array($master_order, $invoiceModel->id, $orders); - } else { - $result = array($master_order, null, $orders); } //activate orders if product is setup to be activated after order place or order total is $0 @@ -613,8 +609,11 @@ class Service implements InjectionAwareInterface } } - $result[2] = $ids; - return $result; + return array( + $master_order, + isset($invoiceModel) ? $invoiceModel->id : null, + $ids, + ); } public function usePromo(\Model_Promo $promo) From f2bd35b9ce8e6ee0b8f332a3844554f669f71792 Mon Sep 17 00:00:00 2001 From: 4Giedrius <4giedrius@gmail.com> Date: Tue, 27 Jan 2015 17:25:49 +0200 Subject: [PATCH 35/48] Profile service test fixed --- tests/bb-modules/Profile/ServiceTest.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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); } From 1211851d3acc050c11c2f835a9302af739b65fa5 Mon Sep 17 00:00:00 2001 From: Vaidas Lungis Date: Tue, 27 Jan 2015 17:30:13 +0200 Subject: [PATCH 36/48] update logical operator for balance compare. --- src/bb-modules/Cart/Service.php | 11 +++++------ .../html_client/mod_orderbutton_checkout.phtml | 2 +- tests/bb-modules/Cart/ServiceTest.php | 3 --- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/bb-modules/Cart/Service.php b/src/bb-modules/Cart/Service.php index 8b79483c5..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; @@ -569,7 +568,7 @@ class Service implements InjectionAwareInterface $clientBalanceService = $this->di['mod_service']('Client', 'Balance'); $balanceAmount = $clientBalanceService->getClientBalance($client); - $useCredits = $balanceAmount > $ca['total']; + $useCredits = $balanceAmount >= $ca['total']; $invoiceService->approveInvoice($invoiceModel, array('id' => $invoiceModel->id, 'use_credits' => $useCredits)); @@ -611,7 +610,7 @@ class Service implements InjectionAwareInterface return array( $master_order, - isset($invoiceModel) ? $invoiceModel->id : null, + isset($invoiceModel) ? $invoiceModel : null, $ids, ); } diff --git a/src/bb-modules/Orderbutton/html_client/mod_orderbutton_checkout.phtml b/src/bb-modules/Orderbutton/html_client/mod_orderbutton_checkout.phtml index 447e4d517..900e2f7cb 100644 --- a/src/bb-modules/Orderbutton/html_client/mod_orderbutton_checkout.phtml +++ b/src/bb-modules/Orderbutton/html_client/mod_orderbutton_checkout.phtml @@ -154,7 +154,7 @@
- {% set enough_in_balance = client.client_balance_get_total > 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 %} 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)); From 6e4246ab5ac4982a8a8d3a0030cba2ff4cbcb799 Mon Sep 17 00:00:00 2001 From: Vaidas Lungis Date: Wed, 28 Jan 2015 11:27:11 +0200 Subject: [PATCH 37/48] update checkout page in boxbilling theme do not show payment gateways if there is enough in client balance --- src/bb-themes/boxbilling/html/mod_cart_index.phtml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/bb-themes/boxbilling/html/mod_cart_index.phtml b/src/bb-themes/boxbilling/html/mod_cart_index.phtml index 99eb5d628..c70322d90 100644 --- a/src/bb-themes/boxbilling/html/mod_cart_index.phtml +++ b/src/bb-themes/boxbilling/html/mod_cart_index.phtml @@ -89,7 +89,8 @@

{% trans 'Total:' %}

{{ cart.total | 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 +104,9 @@ {% endif %}
+ {% if enough_in_balance %} +

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

+ {% endif %}
From e80128e3aabea9b15e470d11c6164e8677406ff1 Mon Sep 17 00:00:00 2001 From: Vaidas Lungis Date: Mon, 26 Jan 2015 17:52:12 +0200 Subject: [PATCH 38/48] increase test fixture's group_id values. old values were mixing with mysql's incremental initial value of table --- tests/fixtures/initial.xml | 12 +++++----- tests/fixtures/mod_cart.xml | 24 +++++++++---------- tests/fixtures/orders.xml | 22 ++++++++--------- tests/fixtures/transactions.xml | 6 ++--- .../bb-modules/mod_order/Api_AdminTest.php | 2 +- 5 files changed, 33 insertions(+), 33 deletions(-) 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..2f90634ed 100644 --- a/tests/fixtures/mod_cart.xml +++ b/tests/fixtures/mod_cart.xml @@ -52,20 +52,20 @@ - - + + - - - - - - + + + + + + - - - - + + + + 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_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'; From ecd84c57969f855461ec619d3df350da29114787 Mon Sep 17 00:00:00 2001 From: 4Giedrius <4giedrius@gmail.com> Date: Wed, 28 Jan 2015 13:22:40 +0200 Subject: [PATCH 39/48] Footer links fix for huraga theme --- src/bb-themes/huraga/config/settings.html | 10 ++++---- .../huraga/html/layout_default.phtml | 23 ++++++++++++++++++- 2 files changed, 27 insertions(+), 6 deletions(-) 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 %} From 7b5b94a8d86545b52e25651fec1deb17a5c67bf4 Mon Sep 17 00:00:00 2001 From: Vaidas Lungis Date: Thu, 29 Jan 2015 10:00:45 +0200 Subject: [PATCH 40/48] add new client api calls: client_is_taxable and invoice_get_tax_rate --- src/bb-modules/Client/Api/Client.php | 5 ++++ src/bb-modules/Invoice/Api/Client.php | 6 +++++ tests/bb-modules/Client/Api/ClientTest.php | 22 +++++++++++++++++ tests/bb-modules/Invoice/Api/ClientTest.php | 27 +++++++++++++++++++++ 4 files changed, 60 insertions(+) diff --git a/src/bb-modules/Client/Api/Client.php b/src/bb-modules/Client/Api/Client.php index 20f5cecdc..f5efa0889 100644 --- a/src/bb-modules/Client/Api/Client.php +++ b/src/bb-modules/Client/Api/Client.php @@ -319,4 +319,9 @@ class Client extends \Api_Abstract 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/Invoice/Api/Client.php b/src/bb-modules/Invoice/Api/Client.php index 1031cf9f2..d0c4c6348 100644 --- a/src/bb-modules/Invoice/Api/Client.php +++ b/src/bb-modules/Invoice/Api/Client.php @@ -195,4 +195,10 @@ class Client extends \Api_Abstract return $pager; } + + public function get_tax_rate() + { + $service = $this->di['mod_service']('Invoice', 'Tax'); + return $service->getTaxRateForClient($this->identity); + } } \ No newline at end of file diff --git a/tests/bb-modules/Client/Api/ClientTest.php b/tests/bb-modules/Client/Api/ClientTest.php index e63912588..09d26e1f3 100644 --- a/tests/bb-modules/Client/Api/ClientTest.php +++ b/tests/bb-modules/Client/Api/ClientTest.php @@ -200,5 +200,27 @@ class ClientTest extends \PHPUnit_Framework_TestCase { $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/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); + } + } From a11b08c9e42d280db299f55e665489b666e60cf4 Mon Sep 17 00:00:00 2001 From: Vaidas Lungis Date: Thu, 29 Jan 2015 10:38:57 +0200 Subject: [PATCH 41/48] add tax row at checkout summary --- .../html_client/mod_orderbutton_checkout.phtml | 11 ++++++++++- src/bb-themes/boxbilling/html/mod_cart_index.phtml | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/bb-modules/Orderbutton/html_client/mod_orderbutton_checkout.phtml b/src/bb-modules/Orderbutton/html_client/mod_orderbutton_checkout.phtml index 900e2f7cb..13d92c014 100644 --- a/src/bb-modules/Orderbutton/html_client/mod_orderbutton_checkout.phtml +++ b/src/bb-modules/Orderbutton/html_client/mod_orderbutton_checkout.phtml @@ -145,9 +145,18 @@ {% endif %} + {% 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 }} diff --git a/src/bb-themes/boxbilling/html/mod_cart_index.phtml b/src/bb-themes/boxbilling/html/mod_cart_index.phtml index c70322d90..7f5861afd 100644 --- a/src/bb-themes/boxbilling/html/mod_cart_index.phtml +++ b/src/bb-themes/boxbilling/html/mod_cart_index.phtml @@ -86,8 +86,17 @@
    + {% 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 }}
    {% set enough_in_balance = client.client_balance_get_total >= cart.total %} {% if cart.total and not enough_in_balance %} From 6f65771b5bf676fec33b15a9c179859da4a51cdb Mon Sep 17 00:00:00 2001 From: Vaidas Lungis Date: Thu, 29 Jan 2015 10:39:31 +0200 Subject: [PATCH 42/48] add minus sign before discount price --- .../Orderbutton/html_client/mod_orderbutton_checkout.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bb-modules/Orderbutton/html_client/mod_orderbutton_checkout.phtml b/src/bb-modules/Orderbutton/html_client/mod_orderbutton_checkout.phtml index 13d92c014..0ca4442b3 100644 --- a/src/bb-modules/Orderbutton/html_client/mod_orderbutton_checkout.phtml +++ b/src/bb-modules/Orderbutton/html_client/mod_orderbutton_checkout.phtml @@ -141,7 +141,7 @@ {% trans 'Discount:' %} - {{ cart.discount | money_convert }} + - {{ cart.discount | money_convert }} {% endif %} From 6602e57ca6d78dffab1c3149df70d8db9b39c244 Mon Sep 17 00:00:00 2001 From: 4Giedrius <4giedrius@gmail.com> Date: Mon, 2 Feb 2015 17:00:45 +0200 Subject: [PATCH 43/48] Escape notification message before saving it to DB --- src/bb-modules/Notification/Api/Admin.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/bb-modules/Notification/Api/Admin.php b/src/bb-modules/Notification/Api/Admin.php index 4b8ef57b9..78d2fbda6 100644 --- a/src/bb-modules/Notification/Api/Admin.php +++ b/src/bb-modules/Notification/Api/Admin.php @@ -68,7 +68,9 @@ class Admin extends \Api_Abstract return false; } - return $this->getService()->create($data['message']); + $message = htmlspecialchars($data['message'], ENT_QUOTES, 'UTF-8'); + + return $this->getService()->create($message); } /** From 71bd95fe3a4e7b76b40aa5b7713e494982952d48 Mon Sep 17 00:00:00 2001 From: Vaidas Lungis Date: Tue, 3 Feb 2015 09:43:23 +0200 Subject: [PATCH 44/48] update secure protocol check issue #246 --- src/install/index.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/install/index.php b/src/install/index.php index ffcd5fbfb..6a046c94f 100644 --- a/src/install/index.php +++ b/src/install/index.php @@ -1,4 +1,14 @@ Date: Tue, 3 Feb 2015 15:46:57 +0200 Subject: [PATCH 45/48] add document ready to orderbutton js --- .../html_client/mod_orderbutton_js.phtml | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/bb-modules/Orderbutton/html_client/mod_orderbutton_js.phtml b/src/bb-modules/Orderbutton/html_client/mod_orderbutton_js.phtml index e1aa53f09..28c2d6c2a 100644 --- a/src/bb-modules/Orderbutton/html_client/mod_orderbutton_js.phtml +++ b/src/bb-modules/Orderbutton/html_client/mod_orderbutton_js.phtml @@ -107,18 +107,19 @@ function popup(){ $('#popup-iframe').show(); } } - -if (typeof jQuery === "undefined") { - (function(d, script) { - script = d.createElement('script'); - script.type = 'text/javascript'; - script.async = true; - script.onload = function(){ - show_popup(); - }; - script.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'; - d.getElementsByTagName('head')[0].appendChild(script); - }(document)); -}else{ - show_popup(); -}; +$( document ).ready(function() { + if (typeof jQuery === "undefined") { + (function(d, script) { + script = d.createElement('script'); + script.type = 'text/javascript'; + script.async = true; + script.onload = function(){ + show_popup(); + }; + script.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'; + d.getElementsByTagName('head')[0].appendChild(script); + }(document)); + }else{ + show_popup(); + }; +}); \ No newline at end of file From e6d13e99dfa6c5ef443052318651b754cd2a9689 Mon Sep 17 00:00:00 2001 From: Vaidas Lungis Date: Tue, 3 Feb 2015 16:12:22 +0200 Subject: [PATCH 46/48] change http protocol to https for external resources resource loading issues when ssl is used. --- src/bb-modules/Embed/html_client/mod_embed_contact.phtml | 2 +- src/bb-modules/Orderbutton/html_client/mod_orderbutton_js.phtml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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" %}