Skip to content

Commit

Permalink
Merge pull request #17 from pagantis/v8.0.1
Browse files Browse the repository at this point in the history
V8.0.1
  • Loading branch information
pgarcess authored May 8, 2019
2 parents 6a78ecb + 3561fee commit 4417de5
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 52 deletions.
15 changes: 9 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
version: 2
jobs:
build:
machine: true
machine:
image: ubuntu-1604:201903-01
working_directory: ~/repo
steps:
- checkout
Expand All @@ -14,13 +15,15 @@ jobs:
- run:
name: Composer Install
command: |
sudo apt install -y python-software-properties
sudo add-apt-repository -y ppa:ondrej/php
find /etc/apt/sources.list.d -type f -name '*.list' -exec sudo apt-get update -o Dir::Etc::sourcelist="{}" ';'
sudo apt install -y php7.2-fpm php7.2-gd php7.2-curl php7.2-mysql php7.2-dev php7.2-cli php7.2-common php7.2-mbstring php7.2-intl php7.2-zip php7.2-bcmath php7.2-dom node
#sudo apt install -y python-software-properties
#sudo add-apt-repository -y ppa:ondrej/php
#sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 6494C6D6997C215E
#sudo rm -rf /etc/apt/sources.list.d/circleci_trusty.list*
#find /etc/apt/sources.list.d -type f -name '*.list' -exec sudo apt-get update -o Dir::Etc::sourcelist="{}" ';'
sudo apt install -y php7.0-fpm php7.0-gd php7.0-curl php7.0-mysql php7.0-dev php7.0-cli php7.0-common php7.0-mbstring php7.0-intl php7.0-bcmath php7.0-zip php7.0-xml nodejs
curl -s https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
composer install
composer install --ignore-platform-reqs
- run:
name: Npm Install
command: |
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM php:7.1-apache
FROM php:7.2-apache

ENV WORDPRESS_VERSION=5.1
ENV WOOCOMMERCE_VERSION=3.5.6
ENV WOOCOMMERCE_VERSION=3.6.2

RUN cd /tmp \
&& curl https://es.wordpress.org/wordpress-$WORDPRESS_VERSION-es_ES.tar.gz -o $WORDPRESS_VERSION-es_ES.tar.gz \
Expand All @@ -25,7 +25,7 @@ RUN buildDeps="libxml2-dev" \
libjpeg62-turbo-dev \
libmcrypt-dev \
--no-install-recommends && rm -rf /var/lib/apt/lists/* \
&& docker-php-ext-install -j$(nproc) pdo_mysql mcrypt soap mysqli pdo mbstring zip \
&& docker-php-ext-install -j$(nproc) pdo_mysql soap mysqli pdo mbstring zip \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false -o APT::AutoRemove::SuggestsImportant=false $buildDeps
Expand Down
4 changes: 2 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ module.exports = function(grunt) {
'cp pagantis.zip pagantis-$(git rev-parse --abbrev-ref HEAD).zip \n'
},
composerProd: {
command: 'composer install --no-dev'
command: 'composer install --no-dev --ignore-platform-reqs'
},
composerDev: {
command: 'composer install'
command: 'composer install --ignore-platform-reqs'
},
},
compress: {
Expand Down
37 changes: 27 additions & 10 deletions WC_Pagantis.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class WcPagantis
'PAGANTIS_TITLE_EXTRA' => 'Pay up to 12 comfortable installments with Pagantis. Completely online and sympathetic request, and the answer is immediate!'
);

/** @var Array $extraConfig */
public $extraConfig;

/**
* WC_Pagantis constructor.
*/
Expand All @@ -53,6 +56,8 @@ public function __construct()

$this->pagantisActivation();

$this->extraConfig = $this->getExtraConfig();

load_plugin_textdomain('pagantis', false, basename(dirname(__FILE__)).'/languages');
add_filter('woocommerce_payment_gateways', array($this, 'addPagantisGateway'));
add_filter('woocommerce_available_payment_gateways', array($this, 'pagantisFilterGateways'), 9999);
Expand Down Expand Up @@ -92,7 +97,7 @@ public function pagantisActivation()
$sql = "CREATE TABLE IF NOT EXISTS $tableName (
id int NOT NULL AUTO_INCREMENT,
config varchar(60) NOT NULL,
value varchar(100) NOT NULL,
value varchar(1000) NOT NULL,
UNIQUE KEY id(id)) $charset_collate";

require_once(ABSPATH.'wp-admin/includes/upgrade.php');
Expand All @@ -113,10 +118,6 @@ public function pagantisActivation()
}
}

foreach (array_merge($this->defaultConfigs, $simpleDbConfigs) as $key => $value) {
putenv($key . '=' . $value);
}

//Current plugin config: pagantis_public_key => New field --- public_key => Old field
$settings = get_option('woocommerce_pagantis_settings');

Expand All @@ -142,17 +143,17 @@ public function pagantisAddProductSimulator()

$cfg = get_option('woocommerce_pagantis_settings');
if ($cfg['enabled'] !== 'yes' || $cfg['pagantis_public_key'] == '' || $cfg['pagantis_private_key'] == '' ||
$cfg['simulator'] !== 'yes' || $product->price < getenv('PAGANTIS_DISPLAY_MIN_AMOUNT') ) {
$cfg['simulator'] !== 'yes' || $product->price < $this->extraConfig['PAGANTIS_DISPLAY_MIN_AMOUNT'] ) {
return;
}

$template_fields = array(
'total' => is_numeric($product->price) ? $product->price : 0,
'public_key' => $cfg['pagantis_public_key'],
'simulator_type' => getenv('PAGANTIS_SIMULATOR_DISPLAY_TYPE'),
'positionSelector' => getenv('PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR'),
'quantitySelector' => getenv('PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR'),
'priceSelector' => getenv('PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR'),
'simulator_type' => $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_TYPE'],
'positionSelector' => $this->extraConfig['PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR'],
'quantitySelector' => $this->extraConfig['PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR'],
'priceSelector' => $this->extraConfig['PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR'],
'totalAmount' => is_numeric($product->price) ? $product->price : 0
);
wc_get_template('product_simulator.php', $template_fields, '', $this->template_path);
Expand Down Expand Up @@ -351,6 +352,22 @@ public function pagantisRegisterEndpoint()
true
);
}

/**
* @return array
*/
private function getExtraConfig()
{
global $wpdb;
$tableName = $wpdb->prefix.self::CONFIG_TABLE;
$response = array();
$dbResult = $wpdb->get_results("select config, value from $tableName", ARRAY_A);
foreach ($dbResult as $value) {
$response[$value['config']] = $value['value'];
}

return $response;
}
}

/**
Expand Down
50 changes: 37 additions & 13 deletions controllers/paymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

define('__ROOT__', dirname(dirname(__FILE__)));


class WcPagantisGateway extends WC_Payment_Gateway
{
const METHOD_ID = "pagantis";
Expand All @@ -22,6 +23,11 @@ class WcPagantisGateway extends WC_Payment_Gateway

const NOT_CONFIRMED = 'No se ha podido confirmar el pago';

const CONFIG_TABLE = 'pagantis_config';

/** @var Array $extraConfig */
public $extraConfig;

/**
* WcPagantisGateway constructor.
*/
Expand All @@ -32,7 +38,7 @@ public function __construct()
$this->icon = esc_url(plugins_url('../assets/images/logo.png', __FILE__));
$this->has_fields = true;
$this->method_title = ucfirst($this->id);
$this->title = getenv('PAGANTIS_TITLE');
$this->title = $this->extraConfig['PAGANTIS_TITLE'];

//Useful vars
$this->template_path = plugin_dir_path(__FILE__) . '../templates/';
Expand All @@ -44,8 +50,10 @@ public function __construct()
$this->form_fields = include(plugin_dir_path(__FILE__).'../includes/settings-pagantis.php');//Panel options
$this->init_settings();

$this->settings['ok_url'] = (getenv('PAGANTIS_URL_OK')!='')?getenv('PAGANTIS_URL_OK'):$this->generateOkUrl();
$this->settings['ko_url'] = (getenv('PAGANTIS_URL_KO')!='')?getenv('PAGANTIS_URL_KO'):$this->generateKoUrl();
$this->extraConfig = $this->getExtraConfig();

$this->settings['ok_url'] = ($this->extraConfig['PAGANTIS_URL_OK']!='')?$this->extraConfig['PAGANTIS_URL_OK']:$this->generateOkUrl();
$this->settings['ko_url'] = ($this->extraConfig['PAGANTIS_URL_KO']!='')?$this->extraConfig['PAGANTIS_URL_KO']:$this->generateKoUrl();
foreach ($this->settings as $setting_key => $setting_value) {
$this->$setting_key = $setting_value;
}
Expand Down Expand Up @@ -112,13 +120,13 @@ public function pagantisCheckFields()
} elseif (!in_array(get_woocommerce_currency(), $this->allowed_currencies)) {
$error_string = __(' only can be used in Euros', 'pagantis');
$this->settings['enabled'] = 'no';
} elseif (getenv('PAGANTIS_SIMULATOR_MAX_INSTALLMENTS')<'2'
|| getenv('PAGANTIS_SIMULATOR_MAX_INSTALLMENTS')>'12') {
} elseif ($this->extraConfig['PAGANTIS_SIMULATOR_MAX_INSTALLMENTS']<'2'
|| $this->extraConfig['PAGANTIS_SIMULATOR_MAX_INSTALLMENTS']>'12') {
$error_string = __(' only can be payed from 2 to 12 installments', 'pagantis');
} elseif (getenv('PAGANTIS_SIMULATOR_START_INSTALLMENTS')<'2'
|| getenv('PAGANTIS_SIMULATOR_START_INSTALLMENTS')>'12') {
} elseif ($this->extraConfig['PAGANTIS_SIMULATOR_START_INSTALLMENTS']<'2'
|| $this->extraConfig['PAGANTIS_SIMULATOR_START_INSTALLMENTS']>'12') {
$error_string = __(' only can be payed from 2 to 12 installments', 'pagantis');
} elseif (getenv('PAGANTIS_DISPLAY_MIN_AMOUNT')<0) {
} elseif ($this->extraConfig['PAGANTIS_DISPLAY_MIN_AMOUNT']<0) {
$error_string = __(' can not have a minimum amount less than 0', 'pagantis');
}

Expand Down Expand Up @@ -282,7 +290,7 @@ public function pagantisReceiptPage($order_id)

if ($url=="") {
throw new Exception(_("No ha sido posible obtener una respuesta de Pagantis"));
} elseif (getenv('PAGANTIS_FORM_DISPLAY_TYPE')=='0') {
} elseif ($this->extraConfig['PAGANTIS_FORM_DISPLAY_TYPE']=='0') {
wp_redirect($url);
exit;
} else {
Expand Down Expand Up @@ -369,7 +377,7 @@ public function pagantisCompleteStatus($status, $order_id, $order)
public function is_available()
{
if ($this->enabled==='yes' && $this->pagantis_public_key!='' && $this->pagantis_private_key!='' &&
(int)$this->get_order_total()>getenv('PAGANTIS_DISPLAY_MIN_AMOUNT')) {
(int)$this->get_order_total()>$this->extraConfig['PAGANTIS_DISPLAY_MIN_AMOUNT']) {
return true;
}

Expand All @@ -382,7 +390,7 @@ public function is_available()
*/
public function get_title()
{
return getenv('PAGANTIS_TITLE');
return $this->extraConfig['PAGANTIS_TITLE'];
}

/**
Expand Down Expand Up @@ -420,8 +428,8 @@ public function payment_fields()
'public_key' => $this->pagantis_public_key,
'total' => WC()->session->cart_totals['total'],
'enabled' => $this->settings['enabled'],
'min_installments' => getenv('PAGANTIS_DISPLAY_MIN_AMOUNT'),
'message' => __(getenv('PAGANTIS_TITLE_EXTRA'))
'min_installments' => $this->extraConfig['PAGANTIS_DISPLAY_MIN_AMOUNT'],
'message' => __($this->extraConfig['PAGANTIS_TITLE_EXTRA'])
);
wc_get_template('checkout_description.php', $template_fields, '', $this->template_path);
}
Expand Down Expand Up @@ -674,4 +682,20 @@ private function checkDbTable()
dbDelta($sql);
}
}

/**
* @return array
*/
private function getExtraConfig()
{
global $wpdb;
$tableName = $wpdb->prefix.self::CONFIG_TABLE;
$response = array();
$dbResult = $wpdb->get_results("select config, value from $tableName", ARRAY_A);
foreach ($dbResult as $value) {
$response[$value['config']] = $value['value'];
}

return $response;
}
}
2 changes: 1 addition & 1 deletion generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ docker-compose exec woocommerce-test curl -s https://getcomposer.org/installer |
docker-compose exec woocommerce-test ./composer.phar install

# Time to boot and install woocommerce
sleep 10
sleep 80
set -e

# Run test
Expand Down
4 changes: 2 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Contributors: pgarcess
Tags: WooCommerce, Payment Gateway, Pagantis, pagantis payment gateway, gateway for woocommerce, Card payment woocommerce, woocommerce financing
Requires at least: 2.0.1.3
Tested up to: 5.1.0
WC tested up to: 3.5.6
Tested up to: 5.2.0
WC tested up to: 3.6.2
Stable tag: trunk
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Expand Down
6 changes: 3 additions & 3 deletions templates/product_simulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@

function loadSimulator()
{
var positionSelector = '<? echo $positionSelector;?>';
var positionSelector = '<?php echo $positionSelector;?>';
if (positionSelector === 'default') {
positionSelector = '.PagantisSimulator';
}

var priceSelector = '<? echo $priceSelector;?>';
var priceSelector = '<?php echo $priceSelector;?>';
if (priceSelector === 'default') {
priceSelector = 'div.summary.entry-summary span.woocommerce-Price-amount.amount';
}

var quantitySelector = '<? echo $quantitySelector;?>';
var quantitySelector = '<?php echo $quantitySelector;?>';
if (quantitySelector === 'default') {
quantitySelector = 'div.quantity>input';
}
Expand Down
6 changes: 3 additions & 3 deletions test/selenium/PagantisWoocommerceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ abstract class PagantisWoocommerceTest extends TestCase

const BACKOFFICE_FOLDER = '/wp-admin';

const LANG = '';

/**
* @var array
*/
Expand All @@ -45,9 +47,7 @@ abstract class PagantisWoocommerceTest extends TestCase
'defaultMinIns' => 3,
'defaultMaxIns' => 12,
'defaultSimulatorOpt' => 6,
'confirmationMsg'=>'Pedido recibido',
'checkoutDescription'=> 'Pay up to 12 comfortable installments with Pagantis',
'enter' => 'Haz clic aquí para acceder'
'checkoutDescription'=> 'Pay up to 12 comfortable installments with Pagantis'
);


Expand Down
5 changes: 3 additions & 2 deletions test/selenium/buy/AbstractBuy.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,9 @@ public function verifyOrderInformation()
$this->waitUntil($condition);
$actualString = $this->webDriver->findElement($messageElementSearch)->getText();
$this->assertNotEmpty($actualString, "PR45");
$this->assertNotEmpty($this->configuration['confirmationMsg'], "PR45");
$compareString = (strstr($actualString, $this->configuration['confirmationMsg'])) === false ? false : true;
$confString = (PagantisWoocommerceTest::LANG == 'EN') ? "Order received" : "Pedido recibido";
$this->assertNotEmpty($confString, "PR45");
$compareString = (strstr($actualString, $confString)) === false ? false : true;
$this->assertTrue($compareString, $actualString." PR45");

$menuSearch = WebDriverBy::cssSelector("li.woocommerce-order-overview__total > strong > span.woocommerce-Price-amount");
Expand Down
Loading

0 comments on commit 4417de5

Please sign in to comment.