Skip to content

Commit

Permalink
Merge pull request #40 from pagantis/INT-872
Browse files Browse the repository at this point in the history
Int 872
  • Loading branch information
pgarcess authored Feb 19, 2020
2 parents 7a26868 + 5f16f1e commit 3cd1d2b
Show file tree
Hide file tree
Showing 7 changed files with 2,038 additions and 8 deletions.
1 change: 1 addition & 0 deletions Documentation/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Here you have a complete list of configurations you can change and it's explanat
| PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR | CSS selector with DOM element having the quantity selector value.
| PAGANTIS_FORM_DISPLAY_TYPE | Allow you to select the way to show the payment form in your site
| PAGANTIS_DISPLAY_MIN_AMOUNT | Minimum amount to use the module and show the payment method in the checkout page.
| PAGANTIS_DISPLAY_MAX_AMOUNT | Maximum amount to use the module and show the payment method in the checkout page.
| PAGANTIS_URL_OK | Location where user will be redirected after a successful payment. This string will be concatenated to the base url to build the full url
| PAGANTIS_URL_KO | Location where user will be redirected after a wrong payment. This string will be concatenated to the base url to build the full url
| PAGANTIS_ALLOWED_COUNTRIES | Array of country codes where the method can be used
Expand Down
18 changes: 15 additions & 3 deletions WC_Pagantis.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Pagantis
* Plugin URI: http://www.pagantis.com/
* Description: Financiar con Pagantis
* Version: 8.2.9
* Version: 8.3.0
* Author: Pagantis
*/

Expand Down Expand Up @@ -45,6 +45,7 @@ class WcPagantis
'PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR'=>'a:2:{i:0;s:22:"div.quantity input.qty";i:1;s:18:"div.quantity>input";}',
'PAGANTIS_FORM_DISPLAY_TYPE'=>0,
'PAGANTIS_DISPLAY_MIN_AMOUNT'=>1,
'PAGANTIS_DISPLAY_MAX_AMOUNT'=>0,
'PAGANTIS_URL_OK'=>'',
'PAGANTIS_URL_KO'=>'',
'PAGANTIS_ALLOWED_COUNTRIES' => 'a:3:{i:0;s:2:"es";i:1;s:2:"it";i:2;s:2:"fr";}',
Expand Down Expand Up @@ -238,6 +239,14 @@ public function pagantisActivation()
$wpdb->insert($tableName, array('config' => 'PAGANTIS_SIMULATOR_DECIMAL_SEPARATOR', 'value' => ','), array('%s', '%s'));
}

//Adding new selector < v8.3.0
$tableName = $wpdb->prefix.self::CONFIG_TABLE;
$query = "select * from $tableName where config='PAGANTIS_DISPLAY_MAX_AMOUNT'";
$results = $wpdb->get_results($query, ARRAY_A);
if (count($results) == 0) {
$wpdb->insert($tableName, array('config' => 'PAGANTIS_DISPLAY_MAX_AMOUNT', 'value' => '0'), array('%s', '%s'));
}

$dbConfigs = $wpdb->get_results("select * from $tableName", ARRAY_A);

// Convert a multimple dimension array for SQL insert statements into a simple key/value
Expand Down Expand Up @@ -279,9 +288,12 @@ public function pagantisAddProductSimulator()
$locale = strtolower(strstr(get_locale(), '_', true));
$allowedCountries = unserialize($this->extraConfig['PAGANTIS_ALLOWED_COUNTRIES']);
$allowedCountry = (in_array(strtolower($locale), $allowedCountries));
$minAmount = $this->extraConfig['PAGANTIS_DISPLAY_MIN_AMOUNT'];
$maxAmount = $this->extraConfig['PAGANTIS_DISPLAY_MAX_AMOUNT'];
$totalPrice = $product->get_price();
$validAmount = ($totalPrice>=$minAmount && ($totalPrice<=$maxAmount || $maxAmount=='0'));
if ($cfg['enabled'] !== 'yes' || $cfg['pagantis_public_key'] == '' || $cfg['pagantis_private_key'] == '' ||
$cfg['simulator'] !== 'yes' || $product->get_price() < $this->extraConfig['PAGANTIS_DISPLAY_MIN_AMOUNT'] ||
!$allowedCountry ) {
$cfg['simulator'] !== 'yes' || !$allowedCountry || !$validAmount) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "pagantis/woocommerce",
"description": "Woocommerce module to add Pagantis",
"license": "proprietary",
"type": "module",
"type": "wordpress-plugin",
"keywords": [
"api",
"rest",
Expand Down
17 changes: 14 additions & 3 deletions controllers/paymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,18 @@ public function pagantisReceiptPage($order_id)
->setAssistedSale(false)
->setType(Channel::ONLINE)
;
$orderConfiguration = new Configuration();

$allowedCountries = unserialize($this->extraConfig['PAGANTIS_ALLOWED_COUNTRIES']);
$purchaseCountry =
in_array(strtolower($this->language), $allowedCountries) ? $this->language :
in_array(strtolower($shippingAddress['country']), $allowedCountries) ? $shippingAddress['country'] :
in_array(strtolower($billingAddress['country']), $allowedCountries) ? $billingAddress['country'] : null;

$orderConfiguration = new Configuration();
$orderConfiguration
->setChannel($orderChannel)
->setUrls($orderConfigurationUrls)
->setPurchaseCountry($this->language)
->setPurchaseCountry($purchaseCountry)
;

$orderApiClient = new Order();
Expand Down Expand Up @@ -440,8 +446,12 @@ public function is_available()
$locale = strtolower(strstr(get_locale(), '_', true));
$allowedCountries = unserialize($this->extraConfig['PAGANTIS_ALLOWED_COUNTRIES']);
$allowedCountry = (in_array(strtolower($locale), $allowedCountries));
$minAmount = $this->extraConfig['PAGANTIS_DISPLAY_MIN_AMOUNT'];
$maxAmount = $this->extraConfig['PAGANTIS_DISPLAY_MAX_AMOUNT'];
$totalPrice = (int)$this->get_order_total();
$validAmount = ($totalPrice>=$minAmount && ($totalPrice<=$maxAmount || $maxAmount=='0'));
if ($this->enabled==='yes' && $this->pagantis_public_key!='' && $this->pagantis_private_key!='' &&
(int)$this->get_order_total()>$this->extraConfig['PAGANTIS_DISPLAY_MIN_AMOUNT'] && $allowedCountry) {
$validAmount && $allowedCountry) {
return true;
}

Expand Down Expand Up @@ -498,6 +508,7 @@ public function payment_fields()
'total' => WC()->session->cart_totals['total'],
'enabled' => $this->settings['enabled'],
'min_installments' => $this->extraConfig['PAGANTIS_DISPLAY_MIN_AMOUNT'],
'max_installments' => $this->extraConfig['PAGANTIS_DISPLAY_MAX_AMOUNT'],
'simulator_enabled' => $this->settings['simulator'],
'locale' => $locale,
'country' => $locale,
Expand Down
Loading

0 comments on commit 3cd1d2b

Please sign in to comment.