Plugin Directory

Changeset 2501160


Ignore:
Timestamp:
03/22/2021 04:07:00 PM (5 years ago)
Author:
paybox
Message:

v0.9.9.9.2
3DSv2

Location:
paybox-woocommerce-gateway/trunk
Files:
1 added
14 edited

Legend:

Unmodified
Added
Removed
  • paybox-woocommerce-gateway/trunk/class/wc-paybox-abstract-gateway.php

    r2294678 r2501160  
    11<?php
    22
    3 abstract class WC_Paybox_Abstract_Gateway extends WC_Payment_Gateway {
    4 
     3/**
     4 * Paybox - Payment Gateway class.
     5 *
     6 * Extended by individual payment gateways to handle payments.
     7 *
     8 * @class   WC_Paybox_Abstract_Gateway
     9 * @extends WC_Payment_Gateway
     10 */
     11abstract class WC_Paybox_Abstract_Gateway extends WC_Payment_Gateway
     12{
    513    protected $_config;
    614    protected $_paybox;
    715    private $logger;
    816
    9     public function __construct() {
     17    public function __construct()
     18    {
    1019        // Logger for debug if needed
    1120        if (WC()->debug === 'yes') {
     
    1322        }
    1423
    15 
    1624        $this->method_description = '<center><img src="' . plugins_url('images/logo.png', plugin_basename(dirname(__FILE__))) . '"/></center>';
    1725
     
    2331        $this->_paybox = new WC_Paybox($this->_config);
    2432
    25 //        $this->title = $this->_config->getTitle();
    26 //        $this->description = $this->_config->getDescription();
    27 
    28         $this->title = apply_filters('title',$this->_config->getTitle());
    29         $this->description = apply_filters('description',$this->_config->getDescription());
    30         $this->icon = apply_filters( WC_PAYBOX_PLUGIN, plugin_dir_url(__DIR__).'images/')
    31                 .apply_filters('icon',$this->_config->getIcon());
     33        // $this->title = $this->_config->getTitle();
     34        // $this->description = $this->_config->getDescription();
     35
     36        $this->title = apply_filters('title', $this->_config->getTitle());
     37        $this->description = apply_filters('description', $this->_config->getDescription());
     38        $this->icon = apply_filters(WC_PAYBOX_PLUGIN, plugin_dir_url(__DIR__) . 'images/') . apply_filters('icon', $this->_config->getIcon());
    3239
    3340        // Actions
     
    4350     * @return void
    4451     */
    45     public function process_admin_options() {
     52    public function process_admin_options()
     53    {
    4654        $crypto = new PayboxEncrypt();
    4755        if (!isset($_POST['crypted'])) {
    48             if (isset($_POST["woocommerce_paybox_std_hmackey"]))
     56            if (isset($_POST["woocommerce_paybox_std_hmackey"])) {
    4957                $_POST["woocommerce_paybox_std_hmackey"] = $crypto->encrypt($_POST["woocommerce_paybox_std_hmackey"]);
    50             else
     58            } else {
    5159                $_POST["woocommerce_paybox_3x_hmackey"] = $crypto->encrypt($_POST["woocommerce_paybox_3x_hmackey"]);
     60            }
    5261            $_POST['crypted'] = true;
    5362        }
     
    5564    }
    5665
    57     public function admin_options() {
    58 
     66    public function admin_options()
     67    {
    5968        $crypt = new PayboxEncrypt();
    6069        $this->settings['hmackey'] = $crypt->decrypt($this->settings['hmackey']);
     
    6675     * Initialise Gateway Settings Form Fields
    6776     */
    68     public function init_form_fields() {
     77    public function init_form_fields()
     78    {
    6979        $defaults = new WC_Paybox_Config(array(), $this->defaultTitle, $this->defaultDesc);
    7080        $defaults = $defaults->getDefaults();
     
    8292            'default' => __($defaults['title'], WC_PAYBOX_PLUGIN),
    8393        );
    84         $allFiles = scandir( plugin_dir_path( __DIR__ ) .'images/');   
    85         $fileList = array();
    86         foreach($allFiles as $id=>$file){
    87             if (in_array( explode(".",$file)[1], array('png','jpg','gif','svg'))){
    88                
    89                 $fileList[$file]=$file;
    90             }
    91         }
     94        $allFiles = scandir(plugin_dir_path(__DIR__) . 'images/');
     95        $fileList = array();
     96        foreach ($allFiles as $id => $file) {
     97            if (in_array(explode(".", $file)[1], array('png', 'jpg', 'gif', 'svg'))) {
     98                $fileList[$file]=$file;
     99            }
     100        }
    92101        $this->form_fields['icon'] = array(
    93102            'title' => __('Icon file', WC_PAYBOX_PLUGIN),
    94103            'type' => 'select',
    95             'description' => __('Icon file to be displayed to customers. file are located in: ', WC_PAYBOX_PLUGIN).apply_filters( WC_PAYBOX_PLUGIN, ''.plugin_dir_url(__DIR__).'images/'),
     104            'description' => __('Icon file to be displayed to customers. file are located in: ', WC_PAYBOX_PLUGIN) . apply_filters(WC_PAYBOX_PLUGIN, '' . plugin_dir_url(__DIR__) . 'images/'),
    96105            'default' => __($defaults['icon'], WC_PAYBOX_PLUGIN),
    97             'options' => $fileList,
     106            'options' => $fileList,
    98107        );
    99108        $this->form_fields['description'] = array(
     
    126135            'default' => $defaults['amount']
    127136        );
    128         $this->form_fields['3ds'] = array(
    129             'title' => __('3D Secure', WC_PAYBOX_PLUGIN),
    130             'type' => 'title',
    131         );
    132         $this->form_fields['3ds_enabled'] = array(
    133             'title' => __('Enable/Disable', WC_PAYBOX_PLUGIN),
    134             'type' => 'select',
    135             'label' => __('Enable 3D Secure', WC_PAYBOX_PLUGIN),
    136             'description' => __('You can enable 3D Secure for all orders or depending on following conditions', WC_PAYBOX_PLUGIN),
    137             'default' => $defaults['3ds_enabled'],
    138             'options' => array(
    139                 'never' => __('Disabled', WC_PAYBOX_PLUGIN),
    140                 'always' => __('Enabled', WC_PAYBOX_PLUGIN),
    141                 'conditional' => __('Conditional', WC_PAYBOX_PLUGIN),
    142             ),
    143         );
    144         $this->form_fields['3ds_amount'] = array(
    145             'title' => __('Minimal amount', WC_PAYBOX_PLUGIN),
    146             'type' => 'text',
    147             'description' => __('Enable 3D Secure for order with amount greater or equals to this amount (empty to ignore this condition)', WC_PAYBOX_PLUGIN),
    148             'default' => $defaults['3ds_amount']
    149         );
    150137        $this->form_fields['paybox_account'] = array(
    151138            'title' => __('Paybox account', WC_PAYBOX_PLUGIN),
     
    191178        );
    192179        $this->form_fields['ips'] = array(
    193             'title' => __('Allowed IPs ', WC_PAYBOX_PLUGIN),
     180            'title' => __('Allowed IPs', WC_PAYBOX_PLUGIN),
    194181            'type' => 'text',
    195182            'description' => __('A coma separated list of Paybox IPs.', WC_PAYBOX_PLUGIN),
     
    210197     * @return bool
    211198     */
    212     public function is_available() {
     199    public function is_available()
     200    {
    213201        if (!parent::is_available()) {
    214202            return false;
     
    219207        }
    220208        $total = WC()->cart->total;
     209
    221210        return $total >= $minimal;
    222211    }
     
    228217     * @return array TODO
    229218     */
    230     public function process_payment($orderId) {
     219    public function process_payment($orderId)
     220    {
    231221        $order = new WC_Order($orderId);
    232222
     
    240230    }
    241231
    242     public function receipt_page($orderId) {
     232    public function receipt_page($orderId)
     233    {
    243234        $order = new WC_Order($orderId);
    244235
     
    265256        } catch (Exception $e) {
    266257            echo "<p>" . $e->getMessage() . "</p>";
    267             echo "<form><center><button onClick='history.go(-1);return true;'>" . __('Back...', WC_ETRANSACTIONS_PLUGIN) . "</center></button></form>";
     258            echo "<form><center><button onClick='history.go(-1);return true;'>" . __('Back...', WC_PAYBOX_PLUGIN) . "</center></button></form>";
    268259            exit;
    269260        }
     
    271262        ?>
    272263        <form id="pbxep_form" method="post" action="<?php echo esc_url($url); ?>" enctype="application/x-www-form-urlencoded">
    273             <?php if ($debug): ?>
     264            <?php if ($debug) : ?>
    274265                <p>
    275266                    <?php echo __('This is a debug view. Click continue to be redirected to Paybox payment page.', WC_PAYBOX_PLUGIN); ?>
    276267                </p>
    277             <?php else: ?>
     268            <?php else : ?>
    278269                <p>
    279270                    <?php echo __('You will be redirected to the Paybox payment page. If not, please use the button bellow.', WC_PAYBOX_PLUGIN); ?>
     
    288279            <?php
    289280            $type = $debug ? 'text' : 'hidden';
    290             foreach ($params as $name => $value):
     281            foreach ($params as $name => $value) {
    291282                $name = esc_attr($name);
    292283                $value = esc_attr($value);
    293                 if ($debug):
     284                if ($debug) {
    294285                    echo '<p><label for="' . $name . '">' . $name . '</label>';
    295                 endif;
     286                }
    296287                echo '<input type="' . $type . '" id="' . $name . '" name="' . $name . '" value="' . $value . '" />';
    297                 if ($debug):
     288                if ($debug) {
    298289                    echo '</p>';
    299                 endif;
    300             endforeach;
     290                }
     291            }
    301292            ?>
    302293        </form>
     
    304295    }
    305296
    306     public function api_call() {
     297    public function api_call()
     298    {
    307299        if (!isset($_GET['status'])) {
    308300            header('Status: 404 Not found', true, 404);
     
    333325    }
    334326
    335     public function on_payment_failed() {
     327    public function on_payment_failed()
     328    {
    336329        try {
    337330            $params = $this->_paybox->getParams();
     
    344337                $message = __('Payment refused by Paybox', WC_PAYBOX_PLUGIN);
    345338                $this->_paybox->addCartErrorMessage($message);
    346                  $order->update_status('failed', $message);             
     339                $order->update_status('failed', $message);
    347340            }
    348341        } catch (Exception $e) {
     
    353346    }
    354347
    355     public function on_payment_canceled() {
     348    public function on_payment_canceled()
     349    {
    356350        try {
    357351            $params = $this->_paybox->getParams();
     
    363357                $message = __('Payment canceled', WC_PAYBOX_PLUGIN);
    364358                $this->_paybox->addCartErrorMessage($message);
    365                 $order->update_status('failed', $message);             
     359                $order->update_status('failed', $message);
    366360            }
    367361        } catch (Exception $e) {
     
    372366    }
    373367
    374     public function on_payment_succeed() {
     368    public function on_payment_succeed()
     369    {
    375370        try {
    376371            $params = $this->_paybox->getParams();
     
    391386    }
    392387
    393     public function on_ipn() {
    394        global $wpdb;
     388    public function on_ipn()
     389    {
     390        global $wpdb;
    395391
    396392        try {
    397 
    398393            $params = $this->_paybox->getParams();
    399394
    400395            if ($params === false) {
    401                 return;
     396                return;
    402397            }
    403398
     
    405400
    406401            // IP not allowed
    407             /*              $allowedIps = $this->_config->getAllowedIps();
    408               $currentIp = $this->_paybox->getClientIp();
    409               if (!in_array($currentIp, $allowedIps)) {
    410               $message = __('IPN call from %s not allowed.', WC_PAYBOX_PLUGIN);
    411               $message = sprintf($message, $currentIp);
    412               $this->_paybox->addOrderNote($order, $message);
    413               throw new Exception($message);
    414               }
    415               //removed by JC: no need for IP checking anymore.
    416              */
     402            /*
     403            $allowedIps = $this->_config->getAllowedIps();
     404            $currentIp = $this->_paybox->getClientIp();
     405            if (!in_array($currentIp, $allowedIps)) {
     406                $message = __('IPN call from %s not allowed.', WC_PAYBOX_PLUGIN);
     407                $message = sprintf($message, $currentIp);
     408                $this->_paybox->addOrderNote($order, $message);
     409                throw new Exception($message);
     410            }
     411            // removed by JC: no need for IP checking anymore.
     412            */
    417413            // Check required parameters
    418414            $requiredParams = array('amount', 'transaction', 'error', 'reference', 'sign', 'date', 'time');
     
    421417                    $message = sprintf(__('Missing %s parameter in Paybox call', WC_PAYBOX_PLUGIN), $requiredParam);
    422418                    $this->_paybox->addOrderNote($order, $message);
    423                    throw new Exception($message);
     419                    throw new Exception($message);
    424420                }
    425421            }
     
    427423            // Payment success
    428424            if ($params['error'] == '00000') {
    429            
    430425                switch ($this->type) {
    431426                    case 'standard':
     
    437432                    case 'threetime':
    438433                        $sql = 'select distinct type from ' . $wpdb->prefix . 'wc_paybox_payment where order_id = ' . $order->get_id();
    439                         $done = $wpdb->get_col($sql);
     434                        $done = $wpdb->get_col($sql);
    440435                        if (!in_array('first_payment', $done)) {
    441436                            $this->_paybox->addOrderNote($order, __('Payment was authorized and captured by Paybox.', WC_PAYBOX_PLUGIN));
    442437                            $order->payment_complete($params['transaction']);
    443438                            $this->_paybox->addOrderPayment($order, 'first_payment', $params);
    444                         } else if (!in_array('second_payment', $done)) {
     439                        } elseif (!in_array('second_payment', $done)) {
    445440                            $this->_paybox->addOrderNote($order, __('Second payment was captured by Paybox.', WC_PAYBOX_PLUGIN));
    446441                            $this->_paybox->addOrderPayment($order, 'second_payment', $params);
    447                         } else if (!in_array('third_payment', $done)) {
     442                        } elseif (!in_array('third_payment', $done)) {
    448443                            $this->_paybox->addOrderNote($order, __('Third payment was captured by Paybox.', WC_PAYBOX_PLUGIN));
    449444                            $this->_paybox->addOrderPayment($order, 'third_payment', $params);
     
    454449                        }
    455450                        break;
    456 
    457451                    default:
    458452                        $message = __('Unexpected type %s', WC_PAYBOX_PLUGIN);
     
    461455                        throw new Exception($message);
    462456                }
    463             }
    464 
    465             // Payment refused
    466             else {
     457            } else {
     458                // Payment refused
    467459                $message = __('Payment was refused by Paybox (%s).', WC_PAYBOX_PLUGIN);
    468460                $error = $this->_paybox->toErrorMessage($params['error']);
    469461                $message = sprintf($message, $error);
    470                 $this->_paybox->addOrderPayment($order, 'failed_payment', $params);
     462                $this->_paybox->addOrderPayment($order, 'failed_payment', $params);
    471463                $this->_paybox->addOrderNote($order, $message);
    472464            }
    473465        } catch (Exception $e) {
    474             if (WC()->debug === 'yes') {
    475                 $this->logger->add("paybox", $e->getMessage());
    476             }
    477         }
    478     }
    479 
    480     public function redirectToCheckout() {
     466            if (WC()->debug === 'yes') {
     467                $this->logger->add("paybox", $e->getMessage());
     468            }
     469        }
     470    }
     471
     472    public function redirectToCheckout()
     473    {
    481474        wp_redirect(WC()->cart->get_cart_url());
    482475        die();
    483476    }
    484    
    485     public function checkCrypto(){
    486         $crypt = new PayboxEncrypt();
     477
     478    public function checkCrypto()
     479    {
     480        $crypt = new PayboxEncrypt();
    487481        return $crypt->decrypt($this->settings['hmackey']);
    488     }
    489    
    490     public abstract function showDetails($orderId);
    491    
    492 
     482    }
     483
     484    abstract public function showDetails($orderId);
    493485}
  • paybox-woocommerce-gateway/trunk/class/wc-paybox-config.php

    r2240593 r2501160  
    11<?php
    22
    3 class WC_Paybox_Config {
    4     private $_values;
    5     private $_defaults = array(
    6         '3ds_enabled' => 'always',
    7         'icon' => 'cbvisamcecb.png',
    8         '3ds_amount' => '',
    9         'amount' => '',
    10         'debug' => 'no',
    11         'delay' => 0,
    12         'environment' => 'TEST',
    13         'hmackey' => '0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF',
    14         'identifier' => 3262411,
    15         'ips' => '194.2.122.158,195.25.7.166,195.101.99.76',
    16         'rank' => 77,
    17         'site' => 1999888,
    18     );
     3/**
     4 * Paybox - Configuration class.
     5 *
     6 * @class   WC_Paybox_Config
     7 */
     8class WC_Paybox_Config
     9{
     10    private $_values;
     11    private $_defaults = array(
     12        'icon' => 'cbvisamcecb.png',
     13        'amount' => '',
     14        'debug' => 'no',
     15        'delay' => 0,
     16        'environment' => 'TEST',
     17        'hmackey' => '0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF',
     18        'identifier' => 3262411,
     19        'ips' => '194.2.122.158,195.25.7.166,195.101.99.76',
     20        'rank' => 77,
     21        'site' => 1999888,
     22    );
    1923
    20     public function __construct(array $values, $defaultTitle, $defaultDesc) {
    21         $this->_values = $values;
    22         $this->_defaults['title'] = $defaultTitle;
    23         $this->_defaults['description'] = $defaultDesc;
    24     }
     24    public function __construct(array $values, $defaultTitle, $defaultDesc)
     25    {
     26        $this->_values = $values;
     27        $this->_defaults['title'] = $defaultTitle;
     28        $this->_defaults['description'] = $defaultDesc;
     29    }
    2530
    26     protected function _getOption($name) {
    27         if (isset($this->_values[$name])) {
    28             return $this->_values[$name];
    29         }
    30         if (isset($this->_defaults[$name])) {
    31             return $this->_defaults[$name];
    32         }
    33         return null;
    34     }
     31    protected function _getOption($name)
     32    {
     33        if (isset($this->_values[$name])) {
     34            return $this->_values[$name];
     35        }
     36        if (isset($this->_defaults[$name])) {
     37            return $this->_defaults[$name];
     38        }
     39        return null;
     40    }
    3541
    36     public function get3DSEnabled() {
    37         return $this->_getOption('3ds_enabled');
    38     }
     42    public function getAmount()
     43    {
     44        $value = $this->_getOption('amount');
     45        return empty($value) ? null : floatval($value);
     46    }
    3947
    40     public function get3DSAmount() {
    41         $value = $this->_getOption('3ds_amount');
    42         return empty($value) ? null : floatval($value);
    43     }
     48    public function getAllowedIps()
     49    {
     50        return explode(',', $this->_getOption('ips'));
     51    }
    4452
    45     public function getAmount() {
    46         $value = $this->_getOption('amount');
    47         return empty($value) ? null : floatval($value);
    48     }
     53    public function getDefaults()
     54    {
     55        return $this->_defaults;
     56    }
    4957
    50     public function getAllowedIps() {
    51         return explode(',', $this->_getOption('ips'));
    52     }
     58    public function getDelay()
     59    {
     60        return (int)$this->_getOption('delay');
     61    }
    5362
    54     public function getDefaults() {
    55         return $this->_defaults;
    56     }
     63    public function getDescription()
     64    {
     65            return $this->_getOption('description');
     66    }
    5767
    58     public function getDelay() {
    59         return (int)$this->_getOption('delay');
    60     }
     68    public function getHmacAlgo()
     69    {
     70        return 'SHA512';
     71    }
    6172
    62     public function getDescription() {
    63             return $this->_getOption('description');
    64     }
     73    public function getHmacKey()
     74    {
     75        $crypto = new PayboxEncrypt();
     76        return $crypto->decrypt($this->_values['hmackey']);
     77    }
    6578
    66     public function getHmacAlgo() {
    67         return 'SHA512';
    68     }
     79    public function getIdentifier()
     80    {
     81        return $this->_getOption('identifier');
     82    }
    6983
    70     public function getHmacKey() {
    71         $crypto = new PayboxEncrypt();
    72         return $crypto->decrypt($this->_values['hmackey']);
    73     }
     84    public function getRank()
     85    {
     86        return $this->_getOption('rank');
     87    }
    7488
    75     public function getIdentifier() {
    76         return $this->_getOption('identifier');
    77     }
     89    public function getSite()
     90    {
     91        return $this->_getOption('site');
     92    }
    7893
    79     public function getRank() {
    80         return $this->_getOption('rank');
    81     }
     94    public function getSystemProductionUrls()
     95    {
     96        return array(
     97            'https://tpeweb.paybox.com/php/',
     98            'https://tpeweb1.paybox.com/php/',
     99        );
     100    }
    82101
    83     public function getSite() {
    84         return $this->_getOption('site');
    85     }
     102    public function getSystemTestUrls()
     103    {
     104        return array(
     105            'https://preprod-tpeweb.paybox.com/php/'
     106        );
     107    }
    86108
    87     public function getSystemProductionUrls() {
    88         return array(
    89             'https://tpeweb.paybox.com/php/',
    90             'https://tpeweb1.paybox.com/php/',
    91         );
    92     }
     109    public function getSystemUrls()
     110    {
     111        if ($this->isProduction()) {
     112            return $this->getSystemProductionUrls();
     113        }
     114        return $this->getSystemTestUrls();
     115    }
    93116
    94     public function getSystemTestUrls() {
    95         return array(
    96             'https://preprod-tpeweb.paybox.com/php/'
    97         );
    98     }
     117    public function getTitle()
     118    {
     119        return $this->_getOption('title');
     120    }
    99121
    100     public function getSystemUrls() {
    101         if ($this->isProduction()) {
    102             return $this->getSystemProductionUrls();
    103         }
    104         return $this->getSystemTestUrls();
    105     }
     122    public function getIcon()
     123    {
     124        return $this->_getOption('icon');
     125    }
    106126
    107     public function getTitle() {
    108         return $this->_getOption('title');
    109     }
     127    public function isDebug()
     128    {
     129        return $this->_getOption('debug') === 'yes';
     130    }
    110131
    111     public function getIcon() {
    112         return $this->_getOption('icon');
    113     }
    114 
    115     public function isDebug() {
    116         return $this->_getOption('debug') === 'yes';
    117     }
    118 
    119     public function isProduction() {
    120         return $this->_getOption('environment') === 'PRODUCTION';
    121     }
     132    public function isProduction()
     133    {
     134        return $this->_getOption('environment') === 'PRODUCTION';
     135    }
    122136}
  • paybox-woocommerce-gateway/trunk/class/wc-paybox-encrypt.php

    r2294678 r2501160  
    99 * Software License (OSL-3.0) that is available through the world-wide-web
    1010 * at the following URI: http://opensource.org/licenses/OSL-3.0. If
    11  * you did not receive a copy of the OSL-3.0 license and are unable 
     11 * you did not receive a copy of the OSL-3.0 license and are unable
    1212 * to obtain it through the web, please send a note to
    1313 * [email protected] so we can mail you a copy immediately.
     
    2020 * */
    2121
    22 class PayboxEncrypt {
    23     /*IV generation */
    24     private function _MakeIv($key){
    25         if(function_exists('openssl_cipher_iv_length')){
    26             //openssl
    27             $len =  openssl_cipher_iv_length ( 'AES-128-CBC' );
    28             $strong_crypto = true;
    29             $iv = openssl_random_pseudo_bytes($len, $strong_crypto);
    30         }else{
    31             //mcrypt
    32             $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
    33             $size = mcrypt_enc_get_iv_size($td);
    34             $iv = mcrypt_create_iv($size, MCRYPT_RAND);
    35         }
    36         return bin2hex($iv);
     22class PayboxEncrypt
     23{
     24    /*IV generation */
     25    private function _MakeIv($key)
     26    {
     27        if (function_exists('openssl_cipher_iv_length')) {
     28            //openssl
     29            $len =  openssl_cipher_iv_length('AES-128-CBC');
     30            $strong_crypto = true;
     31            $iv = openssl_random_pseudo_bytes($len, $strong_crypto);
     32        } else {
     33            //mcrypt
     34            $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
     35            $size = mcrypt_enc_get_iv_size($td);
     36            $iv = mcrypt_create_iv($size, MCRYPT_RAND);
     37        }
    3738
    38     }
    39     /*
    40      * You can change this method
    41      if you want to change the way the key is generated.
    42      */
    43     public function generateKey(){
    44         // generate key, write to KEY_FILE_PATH
    45         $key = openssl_random_pseudo_bytes(16);
    46         if(file_exists(WC_PAYBOX_KEY_PATH))unlink(WC_PAYBOX_KEY_PATH);
    47         $key = bin2hex($key);
    48         $iv = $this->_MakeIv($key);
    49         return file_put_contents(WC_PAYBOX_KEY_PATH,"<?php" . $key.$iv);
    50     }
    51     /**
    52      * @return string Key used for encryption
    53      */
    54      private function _getKey()
    55     {
    56         //check whether key on KEY_FILE_PATH exists, if not generate it.
    57         $ok = true;
    58         if(!file_exists(WC_PAYBOX_KEY_PATH)){
    59             $ok = $this->generateKey();
    60             $_POST['KEY_ERROR'] = __("For some reason, the key has just been generated. please reenter the HMAC key to crypt it.");
    61         }
    62         if($ok!==false){
    63             $key = file_get_contents(WC_PAYBOX_KEY_PATH);
    64             $key = substr($key,5,32);
    65             return $key;
    66         }
    67     }
    68     /**
    69      * @return string Key used for encryption
    70      */
    71      private function _getIv()
    72     {
    73         //check whether key on KEY_FILE_PATH exists, if not generate it.
    74         if(!file_exists(WC_PAYBOX_KEY_PATH)){
    75             $this->generateKey();
    76             $_POST['KEY_ERROR'] = __("For some reason, the key has just been generated. please reenter the HMAC key to crypt it.");
    77         }else{
    78             $iv = file_get_contents(WC_PAYBOX_KEY_PATH);
    79             $iv = substr($iv,37,16);
    80             return $iv;
    81         }
    82     }
    83     private function _crypt($key,$iv,$data){
    84             if(function_exists('openssl_encrypt')){
    85                 //openssl
    86                 $result = openssl_encrypt($data, 'aes-128-cbc', $key, OPENSSL_RAW_DATA , $iv);
    87             }else{
    88                 // Prepare mcrypt
    89                 $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
    90                 mcrypt_generic_init($td, $key, $iv);
    91                 // Encrypt
    92                 $result =  mcrypt_generic($td, $data);
    93             }
    94             // Encode (to avoid data loose when saved to database or
    95             // any storage that does not support null chars)
    96             return base64_encode($result);
    97     }
    98     /**
    99      * Encrypt $data using AES
    100      * @param string $data The data to encrypt
    101      * @return string The result of encryption
    102      */
    103     public function encrypt($data)
    104     {
    105         if (empty($data)) {
    106             return '';
    107         }
    108         // First encode data to base64 (see end of descrypt)
    109         $data = base64_encode($data);
     39        return bin2hex($iv);
     40    }
    11041
     42    /*
     43     * You can change this method
     44     if you want to change the way the key is generated.
     45     */
     46    public function generateKey()
     47    {
     48        // generate key, write to KEY_FILE_PATH
     49        $key = openssl_random_pseudo_bytes(16);
     50        if (file_exists(WC_PAYBOX_KEY_PATH)) {
     51            unlink(WC_PAYBOX_KEY_PATH);
     52        }
     53        $key = bin2hex($key);
     54        $iv = $this->_MakeIv($key);
    11155
    112         // Prepare key
    113         $key = $this->_getKey();
    114         $key = substr($key, 0, 24);
    115         while (strlen($key) < 24) {
    116             $key .= substr($key, 0, 24 - strlen($key));
    117         }
    118         // Init vector
    119         $iv = $this->_getIv();
     56        return file_put_contents(WC_PAYBOX_KEY_PATH, "<?php" . $key . $iv);
     57    }
     58    /**
     59     * @return string Key used for encryption
     60     */
     61    private function _getKey()
     62    {
     63        //check whether key on KEY_FILE_PATH exists, if not generate it.
     64        $ok = true;
     65        if (!file_exists(WC_PAYBOX_KEY_PATH)) {
     66            $ok = $this->generateKey();
     67            $_POST['KEY_ERROR'] = __("For some reason, the key has just been generated. please reenter the HMAC key to crypt it.");
     68        }
     69        if ($ok!==false) {
     70            $key = file_get_contents(WC_PAYBOX_KEY_PATH);
     71            $key = substr($key, 5, 32);
     72            return $key;
     73        }
     74    }
     75    /**
     76     * @return string Key used for encryption
     77     */
     78    private function _getIv()
     79    {
     80        //check whether key on KEY_FILE_PATH exists, if not generate it.
     81        if (!file_exists(WC_PAYBOX_KEY_PATH)) {
     82            $this->generateKey();
     83            $_POST['KEY_ERROR'] = __("For some reason, the key has just been generated. please reenter the HMAC key to crypt it.");
     84        } else {
     85            $iv = file_get_contents(WC_PAYBOX_KEY_PATH);
     86            $iv = substr($iv, 37, 16);
     87            return $iv;
     88        }
     89    }
    12090
    121         return $this->_crypt($key,$iv,$data);
    122        
    123     }
    124     private function _decrypt($key,$iv,$data){
    125         if(function_exists('openssl_decrypt')){
    126             //openssl
    127             $result = openssl_decrypt($data, 'aes-128-cbc', $key, OPENSSL_RAW_DATA , $iv);
    128             if(!$result && function_exists('mcrypt_module_open')){
    129                 $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
    130                 mcrypt_generic_init($td, $key, $iv);
    131                 // Decrypt
    132                 $result = mdecrypt_generic($td, $data);
    133             }
    134             if(!$result) show_message(new WP_Error("","","ATTENTION:le module ne peut plus afficher la clef HMAC, veuillez l'initiailiser de nouveau."));
    135         }else{
    136             // Prepare mcrypt
    137             $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
    138             mcrypt_generic_init($td, $key, $iv);
    139             // Decrypt
    140             $result = mdecrypt_generic($td, $data);
    141         }
    142         // Decode data
    143         return base64_decode($result);     
    144     }
    145     /**
    146      * Decrypt $data using 3DES
    147      * @param string $data The data to decrypt
    148      * @return string The result of decryption
    149      * @see PAYBOX_Epayment_Helper_Encrypt::_getKey()
    150      */
    151     public function decrypt($data)
    152     {
    153         if (empty($data)) {
    154             return '';
    155         }
     91    private function _crypt($key, $iv, $data)
     92    {
     93        if (function_exists('openssl_encrypt')) {
     94            //openssl
     95            $result = openssl_encrypt($data, 'aes-128-cbc', $key, OPENSSL_RAW_DATA, $iv);
     96        } else {
     97            // Prepare mcrypt
     98            $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
     99            mcrypt_generic_init($td, $key, $iv);
     100            // Encrypt
     101            $result =  mcrypt_generic($td, $data);
     102        }
    156103
    157         // First decode encrypted message (see end of encrypt)
    158         $data = base64_decode($data);
     104        // Encode (to avoid data loose when saved to database or
     105        // any storage that does not support null chars)
     106        return base64_encode($result);
     107    }
    159108
     109    /**
     110     * Encrypt $data using AES
     111     * @param string $data The data to encrypt
     112     * @return string The result of encryption
     113     */
     114    public function encrypt($data)
     115    {
     116        if (empty($data)) {
     117            return '';
     118        }
     119        // First encode data to base64 (see end of descrypt)
     120        $data = base64_encode($data);
    160121
    161         // Prepare key
    162         $key = $this->_getKey();
    163         $key = substr($key, 0, 24);
    164         while (strlen($key) < 24) {
    165             $key .= substr($key, 0, 24 - strlen($key));
    166         }
    167         // Init vector
    168         $iv = $this->_getIv();
    169         $result = $this->_decrypt($key,$iv,$data);
    170         // Remove any null char (data is base64 encoded so no data loose)
    171         $result = rtrim($result, "\0");
     122        // Prepare key
     123        $key = $this->_getKey();
     124        $key = substr($key, 0, 24);
     125        while (strlen($key) < 24) {
     126            $key .= substr($key, 0, 24 - strlen($key));
     127        }
     128        // Init vector
     129        $iv = $this->_getIv();
    172130
     131        return $this->_crypt($key, $iv, $data);
     132    }
    173133
    174         return $result;
    175     }
     134    private function _decrypt($key, $iv, $data)
     135    {
     136        if (function_exists('openssl_decrypt')) {
     137            //openssl
     138            $result = openssl_decrypt($data, 'aes-128-cbc', $key, OPENSSL_RAW_DATA, $iv);
     139            if (!$result && function_exists('mcrypt_module_open')) {
     140                $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
     141                mcrypt_generic_init($td, $key, $iv);
     142                // Decrypt
     143                $result = mdecrypt_generic($td, $data);
     144            }
     145            if (!$result) {
     146                show_message(new WP_Error("", "", "ATTENTION:le module ne peut plus afficher la clef HMAC, veuillez l'initiailiser de nouveau."));
     147            }
     148        } else {
     149            // Prepare mcrypt
     150            $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
     151            mcrypt_generic_init($td, $key, $iv);
     152            // Decrypt
     153            $result = mdecrypt_generic($td, $data);
     154        }
     155
     156        // Decode data
     157        return base64_decode($result);
     158    }
     159
     160    /**
     161     * Decrypt $data using 3DES
     162     * @param string $data The data to decrypt
     163     * @return string The result of decryption
     164     * @see PAYBOX_Epayment_Helper_Encrypt::_getKey()
     165     */
     166    public function decrypt($data)
     167    {
     168        if (empty($data)) {
     169            return '';
     170        }
     171
     172        // First decode encrypted message (see end of encrypt)
     173        $data = base64_decode($data);
     174
     175        // Prepare key
     176        $key = $this->_getKey();
     177        $key = substr($key, 0, 24);
     178        while (strlen($key) < 24) {
     179            $key .= substr($key, 0, 24 - strlen($key));
     180        }
     181        // Init vector
     182        $iv = $this->_getIv();
     183        $result = $this->_decrypt($key, $iv, $data);
     184        // Remove any null char (data is base64 encoded so no data loose)
     185        $result = rtrim($result, "\0");
     186
     187        return $result;
     188    }
    176189}
  • paybox-woocommerce-gateway/trunk/class/wc-paybox-iso4217currency.php

    r1256571 r2501160  
    11<?php
    22
    3 class WC_Paybox_Iso4217Currency {
     3/**
     4 * Paybox - ISO 4217 Currency class.
     5 *
     6 * @class   WC_Paybox_Iso4217Currency
     7 */
     8class WC_Paybox_Iso4217Currency
     9{
     10    private static $_mapping = array(
     11        'AED' => '784',
     12        'AFN' => '971',
     13        'ALL' => '008',
     14        'AMD' => '051',
     15        'ANG' => '532',
     16        'AOA' => '973',
     17        'ARS' => '032',
     18        'AUD' => '036',
     19        'AWG' => '533',
     20        'AZN' => '944',
     21        'BAM' => '977',
     22        'BBD' => '052',
     23        'BDT' => '050',
     24        'BGN' => '975',
     25        'BHD' => '048',
     26        'BIF' => '108',
     27        'BMD' => '060',
     28        'BND' => '096',
     29        'BOB' => '068',
     30        'BOV' => '984',
     31        'BRL' => '986',
     32        'BSD' => '044',
     33        'BTN' => '064',
     34        'BWP' => '072',
     35        'BYR' => '974',
     36        'BZD' => '084',
     37        'CAD' => '124',
     38        'CDF' => '976',
     39        'CHE' => '947',
     40        'CHF' => '756',
     41        'CHW' => '948',
     42        'CLF' => '990',
     43        'CLP' => '152',
     44        'CNY' => '156',
     45        'COP' => '170',
     46        'COU' => '970',
     47        'CRC' => '188',
     48        'CUC' => '931',
     49        'CUP' => '192',
     50        'CVE' => '132',
     51        'CZK' => '203',
     52        'DJF' => '262',
     53        'DKK' => '208',
     54        'DOP' => '214',
     55        'DZD' => '012',
     56        'EEK' => '233',
     57        'EGP' => '818',
     58        'ERN' => '232',
     59        'ETB' => '230',
     60        'EUR' => '978',
     61        'FJD' => '242',
     62        'FKP' => '238',
     63        'GBP' => '826',
     64        'GEL' => '981',
     65        'GHS' => '936',
     66        'GIP' => '292',
     67        'GMD' => '270',
     68        'GNF' => '324',
     69        'GTQ' => '320',
     70        'GYD' => '328',
     71        'HKD' => '344',
     72        'HNL' => '340',
     73        'HRK' => '191',
     74        'HTG' => '332',
     75        'HUF' => '348',
     76        'IDR' => '360',
     77        'ILS' => '376',
     78        'INR' => '356',
     79        'IQD' => '368',
     80        'IRR' => '364',
     81        'ISK' => '352',
     82        'JMD' => '388',
     83        'JOD' => '400',
     84        'JPY' => '392',
     85        'KES' => '404',
     86        'KGS' => '417',
     87        'KHR' => '116',
     88        'KMF' => '174',
     89        'KPW' => '408',
     90        'KRW' => '410',
     91        'KWD' => '414',
     92        'KYD' => '136',
     93        'KZT' => '398',
     94        'LAK' => '418',
     95        'LBP' => '422',
     96        'LKR' => '144',
     97        'LRD' => '430',
     98        'LSL' => '426',
     99        'LTL' => '440',
     100        'LVL' => '428',
     101        'LYD' => '434',
     102        'MAD' => '504',
     103        'MDL' => '498',
     104        'MGA' => '969',
     105        'MKD' => '807',
     106        'MMK' => '104',
     107        'MNT' => '496',
     108        'MOP' => '446',
     109        'MRO' => '478',
     110        'MUR' => '480',
     111        'MVR' => '462',
     112        'MWK' => '454',
     113        'MXN' => '484',
     114        'MXV' => '979',
     115        'MYR' => '458',
     116        'MZN' => '943',
     117        'NAD' => '516',
     118        'NGN' => '566',
     119        'NIO' => '558',
     120        'NOK' => '578',
     121        'NPR' => '524',
     122        'NZD' => '554',
     123        'OMR' => '512',
     124        'PAB' => '590',
     125        'PEN' => '604',
     126        'PGK' => '598',
     127        'PHP' => '608',
     128        'PKR' => '586',
     129        'PLN' => '985',
     130        'PYG' => '600',
     131        'QAR' => '634',
     132        'RON' => '946',
     133        'RSD' => '941',
     134        'RUB' => '643',
     135        'RWF' => '646',
     136        'SAR' => '682',
     137        'SBD' => '090',
     138        'SCR' => '690',
     139        'SDG' => '938',
     140        'SEK' => '752',
     141        'SGD' => '702',
     142        'SHP' => '654',
     143        'SLL' => '694',
     144        'SOS' => '706',
     145        'SRD' => '968',
     146        'STD' => '678',
     147        'SYP' => '760',
     148        'SZL' => '748',
     149        'THB' => '764',
     150        'TJS' => '972',
     151        'TMT' => '934',
     152        'TND' => '788',
     153        'TOP' => '776',
     154        'TRY' => '949',
     155        'TTD' => '780',
     156        'TWD' => '901',
     157        'TZS' => '834',
     158        'UAH' => '980',
     159        'UGX' => '800',
     160        'USD' => '840',
     161        'USN' => '997',
     162        'USS' => '998',
     163        'UYU' => '858',
     164        'UZS' => '860',
     165        'VEF' => '937',
     166        'VND' => '704',
     167        'VUV' => '548',
     168        'WST' => '882',
     169        'XAF' => '950',
     170        'XAG' => '961',
     171        'XAU' => '959',
     172        'XBA' => '955',
     173        'XBB' => '956',
     174        'XBC' => '957',
     175        'XBD' => '958',
     176        'XCD' => '951',
     177        'XDR' => '960',
     178        'XOF' => '952',
     179        'XPD' => '964',
     180        'XPF' => '953',
     181        'XPT' => '962',
     182        'XTS' => '963',
     183        'XXX' => '999',
     184        'YER' => '886',
     185        'ZAR' => '710',
     186        'ZMK' => '894',
     187        'ZWL' => '932',
     188    );
    4189
    5     private static $_mapping = array(
    6         'AED' => '784',
    7         'AFN' => '971',
    8         'ALL' => '008',
    9         'AMD' => '051',
    10         'ANG' => '532',
    11         'AOA' => '973',
    12         'ARS' => '032',
    13         'AUD' => '036',
    14         'AWG' => '533',
    15         'AZN' => '944',
    16         'BAM' => '977',
    17         'BBD' => '052',
    18         'BDT' => '050',
    19         'BGN' => '975',
    20         'BHD' => '048',
    21         'BIF' => '108',
    22         'BMD' => '060',
    23         'BND' => '096',
    24         'BOB' => '068',
    25         'BOV' => '984',
    26         'BRL' => '986',
    27         'BSD' => '044',
    28         'BTN' => '064',
    29         'BWP' => '072',
    30         'BYR' => '974',
    31         'BZD' => '084',
    32         'CAD' => '124',
    33         'CDF' => '976',
    34         'CHE' => '947',
    35         'CHF' => '756',
    36         'CHW' => '948',
    37         'CLF' => '990',
    38         'CLP' => '152',
    39         'CNY' => '156',
    40         'COP' => '170',
    41         'COU' => '970',
    42         'CRC' => '188',
    43         'CUC' => '931',
    44         'CUP' => '192',
    45         'CVE' => '132',
    46         'CZK' => '203',
    47         'DJF' => '262',
    48         'DKK' => '208',
    49         'DOP' => '214',
    50         'DZD' => '012',
    51         'EEK' => '233',
    52         'EGP' => '818',
    53         'ERN' => '232',
    54         'ETB' => '230',
    55         'EUR' => '978',
    56         'FJD' => '242',
    57         'FKP' => '238',
    58         'GBP' => '826',
    59         'GEL' => '981',
    60         'GHS' => '936',
    61         'GIP' => '292',
    62         'GMD' => '270',
    63         'GNF' => '324',
    64         'GTQ' => '320',
    65         'GYD' => '328',
    66         'HKD' => '344',
    67         'HNL' => '340',
    68         'HRK' => '191',
    69         'HTG' => '332',
    70         'HUF' => '348',
    71         'IDR' => '360',
    72         'ILS' => '376',
    73         'INR' => '356',
    74         'IQD' => '368',
    75         'IRR' => '364',
    76         'ISK' => '352',
    77         'JMD' => '388',
    78         'JOD' => '400',
    79         'JPY' => '392',
    80         'KES' => '404',
    81         'KGS' => '417',
    82         'KHR' => '116',
    83         'KMF' => '174',
    84         'KPW' => '408',
    85         'KRW' => '410',
    86         'KWD' => '414',
    87         'KYD' => '136',
    88         'KZT' => '398',
    89         'LAK' => '418',
    90         'LBP' => '422',
    91         'LKR' => '144',
    92         'LRD' => '430',
    93         'LSL' => '426',
    94         'LTL' => '440',
    95         'LVL' => '428',
    96         'LYD' => '434',
    97         'MAD' => '504',
    98         'MDL' => '498',
    99         'MGA' => '969',
    100         'MKD' => '807',
    101         'MMK' => '104',
    102         'MNT' => '496',
    103         'MOP' => '446',
    104         'MRO' => '478',
    105         'MUR' => '480',
    106         'MVR' => '462',
    107         'MWK' => '454',
    108         'MXN' => '484',
    109         'MXV' => '979',
    110         'MYR' => '458',
    111         'MZN' => '943',
    112         'NAD' => '516',
    113         'NGN' => '566',
    114         'NIO' => '558',
    115         'NOK' => '578',
    116         'NPR' => '524',
    117         'NZD' => '554',
    118         'OMR' => '512',
    119         'PAB' => '590',
    120         'PEN' => '604',
    121         'PGK' => '598',
    122         'PHP' => '608',
    123         'PKR' => '586',
    124         'PLN' => '985',
    125         'PYG' => '600',
    126         'QAR' => '634',
    127         'RON' => '946',
    128         'RSD' => '941',
    129         'RUB' => '643',
    130         'RWF' => '646',
    131         'SAR' => '682',
    132         'SBD' => '090',
    133         'SCR' => '690',
    134         'SDG' => '938',
    135         'SEK' => '752',
    136         'SGD' => '702',
    137         'SHP' => '654',
    138         'SLL' => '694',
    139         'SOS' => '706',
    140         'SRD' => '968',
    141         'STD' => '678',
    142         'SYP' => '760',
    143         'SZL' => '748',
    144         'THB' => '764',
    145         'TJS' => '972',
    146         'TMT' => '934',
    147         'TND' => '788',
    148         'TOP' => '776',
    149         'TRY' => '949',
    150         'TTD' => '780',
    151         'TWD' => '901',
    152         'TZS' => '834',
    153         'UAH' => '980',
    154         'UGX' => '800',
    155         'USD' => '840',
    156         'USN' => '997',
    157         'USS' => '998',
    158         'UYU' => '858',
    159         'UZS' => '860',
    160         'VEF' => '937',
    161         'VND' => '704',
    162         'VUV' => '548',
    163         'WST' => '882',
    164         'XAF' => '950',
    165         'XAG' => '961',
    166         'XAU' => '959',
    167         'XBA' => '955',
    168         'XBB' => '956',
    169         'XBC' => '957',
    170         'XBD' => '958',
    171         'XCD' => '951',
    172         'XDR' => '960',
    173         'XOF' => '952',
    174         'XPD' => '964',
    175         'XPF' => '953',
    176         'XPT' => '962',
    177         'XTS' => '963',
    178         'XXX' => '999',
    179         'YER' => '886',
    180         'ZAR' => '710',
    181         'ZMK' => '894',
    182         'ZWL' => '932',
    183     );
    184 
    185     public static function getIsoCode($code, $default = null) {
    186         if (isset(WC_Paybox_Iso4217Currency::$_mapping[$code])) {
    187             return WC_Paybox_Iso4217Currency::$_mapping[$code];
    188         }
    189         return $default;
    190     }
     190    public static function getIsoCode($code, $default = null)
     191    {
     192        if (isset(WC_Paybox_Iso4217Currency::$_mapping[$code])) {
     193            return WC_Paybox_Iso4217Currency::$_mapping[$code];
     194        }
     195        return $default;
     196    }
    191197}
  • paybox-woocommerce-gateway/trunk/class/wc-paybox-standard-gateway.php

    r2294678 r2501160  
    11<?php
    22
    3 class WC_PbxStdGw extends WC_Paybox_Abstract_Gateway {
    4     protected $defaultTitle = 'Paybox payment';
    5     protected $defaultDesc = 'xxxx';
    6     protected $type = 'standard';
     3/**
     4 * Paybox - Individual Payment Gateway class.
     5 *
     6 * @class   WC_PbxStdGw
     7 * @extends WC_Paybox_Abstract_Gateway
     8 */
     9class WC_PbxStdGw extends WC_Paybox_Abstract_Gateway
     10{
     11    protected $defaultTitle = 'Paybox payment';
     12    protected $defaultDesc = 'xxxx';
     13    protected $type = 'standard';
    714
    8     public function __construct() {
    9         // Some properties
    10         $this->id = 'paybox_std';
    11         $this->method_title = __('Paybox', WC_PAYBOX_PLUGIN);
    12         $this->has_fields = false;
    13         $this->icon = 'cbvisamcecb.png';
     15    public function __construct()
     16    {
     17        // Some properties
     18        $this->id = 'paybox_std';
     19        $this->method_title = __('Paybox', WC_PAYBOX_PLUGIN);
     20        $this->has_fields = false;
     21        $this->icon = 'cbvisamcecb.png';
    1422
    15         parent::__construct();
    16     }
    17     private function _showDetailRow($label, $value) {
    18         return '<strong>'.$label.'</strong> '.__($value, WC_PAYBOX_PLUGIN);
    19     }
     23        parent::__construct();
     24    }
    2025
    21     public function showDetails($order) {
    22         $orderId = $order->get_id();
    23         $payment = $this->_paybox->getOrderPayments($orderId, 'capture');
     26    private function _showDetailRow($label, $value)
     27    {
     28        return '<strong>'.$label.'</strong> '.__($value, WC_PAYBOX_PLUGIN);
     29    }
    2430
    25         if (!empty($payment)) {
    26             $data = unserialize($payment->data);
    27             $rows = array();
    28             $rows[] = $this->_showDetailRow(__('Reference:', WC_PAYBOX_PLUGIN), $data['reference']);
    29             if (isset($data['ip'])) {
    30                 $rows[] = $this->_showDetailRow(__('Country of IP:', WC_PAYBOX_PLUGIN), $data['ip']);
    31             }
    32             $rows[] = $this->_showDetailRow(__('Processing date:', WC_PAYBOX_PLUGIN), preg_replace('/^([0-9]{2})([0-9]{2})([0-9]{4})$/', '$1/$2/$3', $data['date'])." - ".$data['time']);
    33             if (isset($data['firstNumbers']) && isset($data['lastNumbers'])) {
    34                 $rows[] = $this->_showDetailRow(__('Card numbers:', WC_PAYBOX_PLUGIN), $data['firstNumbers'].'...'.$data['lastNumbers']);
    35             }
    36             if (isset($data['validity'])) {
    37                 $rows[] = $this->_showDetailRow(__('Validity date:', WC_PAYBOX_PLUGIN), preg_replace('/^([0-9]{2})([0-9]{2})$/', '$2/$1', $data['validity']));
    38             }
    39             $rows[] = $this->_showDetailRow(__('Transaction:', WC_PAYBOX_PLUGIN), $data['transaction']);
    40             $rows[] = $this->_showDetailRow(__('Call:', WC_PAYBOX_PLUGIN), $data['call']);
    41             $rows[] = $this->_showDetailRow(__('Authorization:', WC_PAYBOX_PLUGIN), $data['authorization']);
     31    public function showDetails($order)
     32    {
     33        $orderId = $order->get_id();
     34        $payment = $this->_paybox->getOrderPayments($orderId, 'capture');
    4235
    43             echo '<h4>'.__('Payment information', WC_PAYBOX_PLUGIN).'</h4>';
    44             echo '<p>'.implode('<br/>', $rows).'</p>';
    45         }
    46     }
     36        if (empty($payment)) {
     37            return;
     38        }
    4739
     40        $data = unserialize($payment->data);
     41        $rows = array();
     42        $rows[] = $this->_showDetailRow(__('Reference:', WC_PAYBOX_PLUGIN), $data['reference']);
     43        if (isset($data['ip'])) {
     44            $rows[] = $this->_showDetailRow(__('Country of IP:', WC_PAYBOX_PLUGIN), $data['ip']);
     45        }
     46        $rows[] = $this->_showDetailRow(__('Processing date:', WC_PAYBOX_PLUGIN), preg_replace('/^([0-9]{2})([0-9]{2})([0-9]{4})$/', '$1/$2/$3', $data['date'])." - ".$data['time']);
     47        if (isset($data['firstNumbers']) && isset($data['lastNumbers'])) {
     48            $rows[] = $this->_showDetailRow(__('Card numbers:', WC_PAYBOX_PLUGIN), $data['firstNumbers'].'...'.$data['lastNumbers']);
     49        }
     50        if (isset($data['validity'])) {
     51            $rows[] = $this->_showDetailRow(__('Validity date:', WC_PAYBOX_PLUGIN), preg_replace('/^([0-9]{2})([0-9]{2})$/', '$2/$1', $data['validity']));
     52        }
     53
     54        // 3DS Version
     55        if (!empty($data['3ds']) && $data['3ds'] == 'Y') {
     56            $cc_3dsVersion = '1.0.0';
     57            if (!empty($data['3dsVersion'])) {
     58                $cc_3dsVersion = str_replace('3DSv', '', trim($data['3dsVersion']));
     59            }
     60            $rows[] = $this->_showDetailRow(__('3DS version:', WC_PAYBOX_PLUGIN), $cc_3dsVersion);
     61        }
     62
     63        $rows[] = $this->_showDetailRow(__('Transaction:', WC_PAYBOX_PLUGIN), $data['transaction']);
     64        $rows[] = $this->_showDetailRow(__('Call:', WC_PAYBOX_PLUGIN), $data['call']);
     65        $rows[] = $this->_showDetailRow(__('Authorization:', WC_PAYBOX_PLUGIN), $data['authorization']);
     66
     67        echo '<h4>'.__('Payment information', WC_PAYBOX_PLUGIN).'</h4>';
     68        echo '<p>'.implode('<br/>', $rows).'</p>';
     69    }
    4870}
  • paybox-woocommerce-gateway/trunk/class/wc-paybox-threetime-gateway.php

    r2298639 r2501160  
    11<?php
    22
    3 class WC_Pbx3xGw extends WC_Paybox_Abstract_Gateway {
    4     protected $defaultTitle = 'Paybox 3 times payment';
    5     protected $defaultDesc = 'xxxx';
    6     protected $type = 'threetime';
     3/**
     4 * Paybox 3 times - Payment Gateway class.
     5 *
     6 * Extended by individual payment gateways to handle payments.
     7 *
     8 * @class   WC_Pbx3xGw
     9 * @extends WC_Paybox_Abstract_Gateway
     10 */
     11class WC_Pbx3xGw extends WC_Paybox_Abstract_Gateway
     12{
     13    protected $defaultTitle = 'Paybox 3 times payment';
     14    protected $defaultDesc = 'xxxx';
     15    protected $type = 'threetime';
    716
    8     public function __construct() {
    9         // Some properties
    10         $this->id = 'paybox_3x';
    11         $this->method_title = __('Paybox 3 times', WC_PAYBOX_PLUGIN);
    12         $this->has_fields = false;
    13         $this->icon = '3xcbvisamcecb.png';
     17    public function __construct()
     18    {
     19        // Some properties
     20        $this->id = 'paybox_3x';
     21        $this->method_title = __('Paybox 3 times', WC_PAYBOX_PLUGIN);
     22        $this->has_fields = false;
     23        $this->icon = '3xcbvisamcecb.png';
    1424
    15         parent::__construct();
    16     }
     25        parent::__construct();
     26    }
    1727
    18     private function _showDetailRow($label, $value) {
    19         return '<strong>'.$label.'</strong> '.$value;
    20     }
     28    private function _showDetailRow($label, $value)
     29    {
     30        return '<strong>'.$label.'</strong> '.$value;
     31    }
    2132
    22     /**
    23      * Check If The Gateway Is Available For Use
    24      *
    25      * @access public
    26      * @return bool
    27      */
     33    /**
     34     * Check If The Gateway Is Available For Use
     35     *
     36     * @access public
     37     * @return bool
     38     */
     39    public function showDetails($order)
     40    {
     41        $orderId = $order->get_id();
     42        $payment = $this->_paybox->getOrderPayments($orderId, 'first_payment');
    2843
    29     public function showDetails($order) {
    30         $orderId = $order->get_id();
    31         $payment = $this->_paybox->getOrderPayments($orderId, 'first_payment');
    32         if (!empty($payment)) {
    33             $data = unserialize($payment->data);
    34             $payment = $this->_paybox->getOrderPayments($orderId, 'second_payment');
    35             if (!empty($payment)) {
    36                 $second = unserialize($payment->data);
    37             }
    38             $payment = $this->_paybox->getOrderPayments($orderId, 'third_payment');
    39             if (!empty($payment)) {
    40                 $third = unserialize($payment->data);
    41             }
     44        if (empty($payment)) {
     45            return;
     46        }
    4247
    43             $rows = array();
    44             $rows[] = $this->_showDetailRow(__('Reference:', WC_PAYBOX_PLUGIN), $data['reference']);
    45             if (isset($data['ip'])) {
    46                 $rows[] = $this->_showDetailRow(__('Country of IP:', WC_PAYBOX_PLUGIN), $data['ip']);
    47             }
    48             $rows[] = $this->_showDetailRow(__('Processing date:', WC_PAYBOX_PLUGIN), preg_replace('/^([0-9]{2})([0-9]{2})([0-9]{4})$/', '$1/$2/$3', $data['date'])." - ".$data['time']);
    49             if (isset($data['firstNumbers']) && isset($data['lastNumbers'])) {
    50                 $rows[] = $this->_showDetailRow(__('Card numbers:', WC_PAYBOX_PLUGIN), $data['firstNumbers'].'...'.$data['lastNumbers']);
    51             }
    52             if (isset($data['validity'])) {
    53                 $rows[] = $this->_showDetailRow(__('Validity date:', WC_PAYBOX_PLUGIN), preg_replace('/^([0-9]{2})([0-9]{2})$/', '$2/$1', $data['validity']));
    54             }
     48        $data = unserialize($payment->data);
     49        $payment = $this->_paybox->getOrderPayments($orderId, 'second_payment');
     50        if (!empty($payment)) {
     51            $second = unserialize($payment->data);
     52        }
     53        $payment = $this->_paybox->getOrderPayments($orderId, 'third_payment');
     54        if (!empty($payment)) {
     55            $third = unserialize($payment->data);
     56        }
    5557
    56             $date = preg_replace('/^([0-9]{2})([0-9]{2})([0-9]{4})$/', '$1/$2/$3', $data['date']);
    57             $value = sprintf('%s (%s)', $data['amount'] / 100.0, $date);
    58             $rows[] = $this->_showDetailRow(__('First debit:'), $value);
     58        $rows = array();
     59        $rows[] = $this->_showDetailRow(__('Reference:', WC_PAYBOX_PLUGIN), $data['reference']);
     60        if (isset($data['ip'])) {
     61            $rows[] = $this->_showDetailRow(__('Country of IP:', WC_PAYBOX_PLUGIN), $data['ip']);
     62        }
     63        $rows[] = $this->_showDetailRow(__('Processing date:', WC_PAYBOX_PLUGIN), preg_replace('/^([0-9]{2})([0-9]{2})([0-9]{4})$/', '$1/$2/$3', $data['date'])." - ".$data['time']);
     64        if (isset($data['firstNumbers']) && isset($data['lastNumbers'])) {
     65            $rows[] = $this->_showDetailRow(__('Card numbers:', WC_PAYBOX_PLUGIN), $data['firstNumbers'].'...'.$data['lastNumbers']);
     66        }
     67        if (isset($data['validity'])) {
     68            $rows[] = $this->_showDetailRow(__('Validity date:', WC_PAYBOX_PLUGIN), preg_replace('/^([0-9]{2})([0-9]{2})$/', '$2/$1', $data['validity']));
     69        }
    5970
    60             if (isset($second)) {
    61                 $date = preg_replace('/^([0-9]{2})([0-9]{2})([0-9]{4})$/', '$1/$2/$3', $second['date']);
    62                 $value = sprintf('%s (%s)', $second['amount'] / 100.0, $date);
    63             }
    64             else {
    65                 $value = __('Not achieved', WC_PAYBOX_PLUGIN);
    66             }
    67             $rows[] = $this->_showDetailRow(__('Second debit:'), $value);
     71        // 3DS Version
     72        if (!empty($data['3ds']) && $data['3ds'] == 'Y') {
     73            $cc_3dsVersion = '1.0.0';
     74            if (!empty($data['3dsVersion'])) {
     75                $cc_3dsVersion = str_replace('3DSv', '', trim($data['3dsVersion']));
     76            }
     77            $rows[] = $this->_showDetailRow(__('3DS version:', WC_PAYBOX_PLUGIN), $cc_3dsVersion);
     78        }
    6879
    69             if (isset($third)) {
    70                 $date = preg_replace('/^([0-9]{2})([0-9]{2})([0-9]{4})$/', '$1/$2/$3', $third['date']);
    71                 $value = sprintf('%s (%s)', $third['amount'] / 100.0, $date);
    72             }
    73             else {
    74                 $value = __('Not achieved', WC_PAYBOX_PLUGIN);
    75             }
    76             $rows[] = $this->_showDetailRow(__('Third debit:'), $value);
     80        $date = preg_replace('/^([0-9]{2})([0-9]{2})([0-9]{4})$/', '$1/$2/$3', $data['date']);
     81        $value = sprintf('%s (%s)', $data['amount'] / 100.0, $date);
     82        $rows[] = $this->_showDetailRow(__('First debit:'), $value);
    7783
    78             $rows[] = $this->_showDetailRow(__('Transaction:', WC_PAYBOX_PLUGIN), $data['transaction']);
    79             $rows[] = $this->_showDetailRow(__('Call:', WC_PAYBOX_PLUGIN), $data['call']);
    80             $rows[] = $this->_showDetailRow(__('Authorization:', WC_PAYBOX_PLUGIN), $data['authorization']);
     84        if (isset($second)) {
     85            $date = preg_replace('/^([0-9]{2})([0-9]{2})([0-9]{4})$/', '$1/$2/$3', $second['date']);
     86            $value = sprintf('%s (%s)', $second['amount'] / 100.0, $date);
     87        } else {
     88            $value = __('Not achieved', WC_PAYBOX_PLUGIN);
     89        }
     90        $rows[] = $this->_showDetailRow(__('Second debit:'), $value);
    8191
    82             echo '<h4>'.__('Payment information', WC_PAYBOX_PLUGIN).'</h4>';
    83             echo '<p>'.implode('<br/>', $rows).'</p>';
    84         }
    85     }
     92        if (isset($third)) {
     93            $date = preg_replace('/^([0-9]{2})([0-9]{2})([0-9]{4})$/', '$1/$2/$3', $third['date']);
     94            $value = sprintf('%s (%s)', $third['amount'] / 100.0, $date);
     95        } else {
     96            $value = __('Not achieved', WC_PAYBOX_PLUGIN);
     97        }
     98        $rows[] = $this->_showDetailRow(__('Third debit:'), $value);
     99
     100        $rows[] = $this->_showDetailRow(__('Transaction:', WC_PAYBOX_PLUGIN), $data['transaction']);
     101        $rows[] = $this->_showDetailRow(__('Call:', WC_PAYBOX_PLUGIN), $data['call']);
     102        $rows[] = $this->_showDetailRow(__('Authorization:', WC_PAYBOX_PLUGIN), $data['authorization']);
     103
     104        echo '<h4>'.__('Payment information', WC_PAYBOX_PLUGIN).'</h4>';
     105        echo '<p>'.implode('<br/>', $rows).'</p>';
     106    }
    86107}
    87 class WC_Paybox_Threetime_GateWay extends WC_Pbx3xGw{   
    88     public function receipt_page($orderId){
    89         return;
    90     }
     108
     109class WC_Paybox_Threetime_GateWay extends WC_Pbx3xGw
     110{
     111    public function receipt_page($orderId)
     112    {
     113        return;
     114    }
    91115}
  • paybox-woocommerce-gateway/trunk/class/wc-paybox.php

    r2294684 r2501160  
    11<?php
    22
    3 class WC_Paybox {
    4     private $_config;
    5     private $_currencyDecimals = array(
     3/**
     4 * Paybox - Main class.
     5 *
     6 * @class   WC_Paybox
     7 */
     8class WC_Paybox
     9{
     10    private $_config;
     11    private $_currencyDecimals = array(
    612        '008' => 2,
    713        '012' => 2,
     
    174180        '997' => 2,
    175181        '998' => 2,
    176     );
    177 
    178     private $_errorCode = array(
    179         '00000' => 'Successful operation',
    180         '00001' => 'Payment system not available',
    181         '00003' => 'Paybor error',
    182         '00004' => 'Card number or invalid cryptogram',
    183         '00006' => 'Access denied or invalid identification',
    184         '00008' => 'Invalid validity date',
    185         '00009' => 'Subscription creation failed',
    186         '00010' => 'Unknown currency',
    187         '00011' => 'Invalid amount',
    188         '00015' => 'Payment already done',
    189         '00016' => 'Existing subscriber',
    190         '00021' => 'Unauthorized card',
    191         '00029' => 'Invalid card',
    192         '00030' => 'Timeout',
    193         '00033' => 'Unauthorized IP country',
    194         '00040' => 'No 3D Secure',
    195     );
    196 
    197     private $_resultMapping = array(
    198         'M' => 'amount',
    199         'R' => 'reference',
    200         'T' => 'call',
    201         'A' => 'authorization',
    202         'B' => 'subscription',
    203         'C' => 'cardType',
    204         'D' => 'validity',
    205         'E' => 'error',
    206         'F' => '3ds',
    207         'G' => '3dsWarranty',
    208         'H' => 'imprint',
    209         'I' => 'ip',
    210         'J' => 'lastNumbers',
    211         'K' => 'sign',
    212         'N' => 'firstNumbers',
    213         'O' => '3dsInlistment',
    214         'o' => 'celetemType',
    215         'P' => 'paymentType',
    216         'Q' => 'time',
    217         'S' => 'transaction',
    218         'U' => 'subscriptionData',
    219         'W' => 'date',
    220         'Y' => 'country',
    221         'Z' => 'paymentIndex',
    222     );
    223 
    224     public function __construct(WC_Paybox_Config $config) {
    225         $this->_config = $config;
    226     }
    227 
    228     public function addCartErrorMessage($message) {
    229         wc_add_notice($message, 'error');
    230     }
    231 
    232     public function addOrderNote(WC_Order $order, $message) {
    233         $order->add_order_note($message);
    234     }
    235 
    236     public function addOrderPayment(WC_Order $order, $type, array $data) {
    237         global $wpdb;
    238         $wpdb->insert($wpdb->prefix.'wc_paybox_payment', array(
    239             'order_id' => $order->get_id(),
    240             'type' => $type,
    241             'data' => serialize($data),
    242         ));
    243     }
    244    
    245 
    246     /**
    247      * @params WC_Order $order Order
    248      * @params string $type Type of payment (standard or threetime)
    249      * @params array $additionalParams Additional parameters
    250      */
    251     public function buildSystemParams(WC_Order $order, $type, array $additionalParams = array()) {
    252         global $wpdb;
    253 
    254         // Parameters
    255         $values = array();
    256 
    257         // Merchant information
    258         $values['PBX_SITE'] = $this->_config->getSite();
    259         $values['PBX_RANG'] = $this->_config->getRank();
    260         $values['PBX_IDENTIFIANT'] = $this->_config->getIdentifier();
    261 
    262         // Order information
    263         $values['PBX_PORTEUR'] = $this->getBillingEmail($order);
    264         $values['PBX_DEVISE'] = $this->getCurrency();
    265         $values['PBX_CMD'] = $order->get_id().' - '.$this->getBillingName($order);
    266 
    267         // Amount
    268         $orderAmount = floatval($order->get_total());
    269         $amountScale = $this->_currencyDecimals[$values['PBX_DEVISE']];
    270         $amountScale = pow(10, $amountScale);
    271         switch ($type) {
    272             case 'standard':
    273                 $delay = $this->_config->getDelay();
    274                 if ($delay > 0) {
    275                     if ($delay > 7) {
    276                         $delay = 7;
    277                     }
    278                     $values['PBX_DIFF'] = sprintf('%02d', $delay);
    279                 }
    280                 $values['PBX_TOTAL'] = sprintf('%03d', round($orderAmount * $amountScale));
    281                 break;
    282 
    283             case 'threetime':
    284                 // Compute each payment amount
    285                 $step = round($orderAmount * $amountScale / 3);
    286                 $firstStep = ($orderAmount * $amountScale) - 2 * $step;
    287                 $values['PBX_TOTAL'] = sprintf('%03d', $firstStep);
    288                 $values['PBX_2MONT1'] = sprintf('%03d', $step);
    289                 $values['PBX_2MONT2'] = sprintf('%03d', $step);
    290 
    291                 // Payment dates
    292                 $now = new DateTime();
    293                 $now->modify('1 month');
    294                 $values['PBX_DATE1'] = $now->format('d/m/Y');
    295                 $now->modify('1 month');
    296                 $values['PBX_DATE2'] = $now->format('d/m/Y');
    297 
    298                 // Force validity date of card
    299                 $values['PBX_DATEVALMAX'] = $now->format('ym');
    300                 break;
    301 
    302             default:
    303                 $message  = __('Unexpected type %s', WC_PAYBOX_PLUGIN);
    304                 $message = sprintf($message, $type);
    305                 throw new Exception($message);
    306         }
    307 
    308         // 3D Secure
    309         switch ($this->_config->get3DSEnabled()) {
    310             case 'never':
    311                 $enable3ds = false;
    312                 break;
    313             case null:
    314             case 'always':
    315                 $enable3ds = true;
    316                 break;
    317             case 'conditional':
    318                 $tdsAmount = $this->_config->get3DSAmount();
    319                 $enable3ds = empty($tdsAmount) || ($orderAmount >= $tdsAmount);
    320                 break;
    321             default:
    322                 $message  = __('Unexpected 3-D Secure status %s', WC_PAYBOX_PLUGIN);
    323                 $message = sprintf($message, $this->_config->get3DSEnabled());
    324                 throw new Exception($message);
    325         }
    326         // Enable is the default behaviour
    327         if (!$enable3ds) {
    328             $values['PBX_3DS'] = 'N';
    329         }
    330         // Paybox => Magento
    331         $values['PBX_RETOUR'] = 'M:M;R:R;T:T;A:A;B:B;C:C;D:D;E:E;F:F;G:G;I:I;J:J;N:N;O:O;P:P;Q:Q;S:S;W:W;Y:Y;K:K';
    332         $values['PBX_RUF1'] = 'POST';
    333 
    334         // Choose correct language
    335         $lang = get_locale();
    336         if (!empty($lang)) {
    337             $lang = preg_replace('#_.*$#', '', $lang);
    338         }
    339         $languages = $this->getLanguages();
    340         if (!array_key_exists($lang, $languages)) {
    341             $lang = 'default';
    342         }
    343         $values['PBX_LANGUE'] = $languages[$lang];
    344 
    345         // Choose page format depending on browser/devise
    346         if ($this->isMobile()) {
    347             $values['PBX_SOURCE'] = 'XHTMl';
    348         }
    349 
    350         // Misc.
    351         $values['PBX_TIME'] = date('c');
    352         $values['PBX_HASH'] = strtoupper($this->_config->getHmacAlgo());
    353 
    354         // Adding additionnal informations
    355         $values = array_merge($values, $additionalParams);
    356 
    357         // Sort parameters for simpler debug
    358         ksort($values);
    359 
    360         // Sign values
    361         $sign = $this->signValues($values);
    362 
    363         // Hash HMAC
    364         $values['PBX_HMAC'] = $sign;
    365 
    366         return $values;
    367     }
    368 
    369     public function convertParams(array $params) {
    370         $result = array();
    371         foreach ($this->_resultMapping as $param => $key) {
    372             if (isset($params[$param]))
    373                 $result[$key] = utf8_encode($params[$param]);
    374         }
    375 
    376         return $result;
    377     }
    378 
    379     public function getBillingEmail(WC_Order $order) {
    380         return $order->get_billing_email();
    381     }
    382 
    383     public function getBillingName(WC_Order $order) {
    384         $name = $order->get_billing_first_name().' '.$order->get_billing_last_name();
    385         $name = remove_accents($name);
    386         $name = trim(preg_replace('/[^-. a-zA-Z0-9]/', '', $name));
    387         return $name;
    388     }
    389    
    390    
    391    
    392     public function getClientIp() {
    393         $ipaddress = '';
    394         if ($_SERVER['HTTP_CLIENT_IP'])
    395             $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
    396         else if($_SERVER['HTTP_X_FORWARDED_FOR'])
    397             $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
    398         else if($_SERVER['HTTP_X_FORWARDED'])
    399             $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
    400         else if($_SERVER['HTTP_FORWARDED_FOR'])
    401             $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
    402         else if($_SERVER['HTTP_FORWARDED'])
    403             $ipaddress = $_SERVER['HTTP_FORWARDED'];
    404         else if($_SERVER['REMOTE_ADDR'])
    405             $ipaddress = $_SERVER['REMOTE_ADDR'];
    406         else
    407             $ipaddress = 'UNKNOWN';
    408        
    409         return $ipaddress;
    410     }
    411 
    412     public function getCurrency() {
    413         return WC_Paybox_Iso4217Currency::getIsoCode(get_woocommerce_currency());
    414     }
    415 
    416     public function getLanguages() {
    417         return array(
    418             'fr' => 'FRA',
    419             'es' => 'ESP',
    420             'it' => 'ITA',
    421             'de' => 'DEU',
    422             'nl' => 'NLD',
    423             'sv' => 'SWE',
    424             'pt' => 'PRT',
    425             'default' => 'GBR',
    426         );
    427     }
    428 
    429     public function getOrderPayments($orderId, $type) {
    430         global $wpdb;
    431         $sql = 'select * from '.$wpdb->prefix.'wc_paybox_payment where order_id = %d and type = %s';
    432         $sql = $wpdb->prepare($sql, $orderId, $type);
    433         return $wpdb->get_row($sql);
    434     }
    435 
    436     public function getParams() {
    437         // Retrieves data
    438         $data = file_get_contents('php://input');
     182    );
     183
     184    private $_errorCode = array(
     185        '00000' => 'Successful operation',
     186        '00001' => 'Payment system not available',
     187        '00003' => 'Paybor error',
     188        '00004' => 'Card number or invalid cryptogram',
     189        '00006' => 'Access denied or invalid identification',
     190        '00008' => 'Invalid validity date',
     191        '00009' => 'Subscription creation failed',
     192        '00010' => 'Unknown currency',
     193        '00011' => 'Invalid amount',
     194        '00015' => 'Payment already done',
     195        '00016' => 'Existing subscriber',
     196        '00021' => 'Unauthorized card',
     197        '00029' => 'Invalid card',
     198        '00030' => 'Timeout',
     199        '00033' => 'Unauthorized IP country',
     200        '00040' => 'No 3D Secure',
     201    );
     202
     203    private $_resultMapping = array(
     204        'M' => 'amount',
     205        'R' => 'reference',
     206        'T' => 'call',
     207        'A' => 'authorization',
     208        'B' => 'subscription',
     209        'C' => 'cardType',
     210        'D' => 'validity',
     211        'E' => 'error',
     212        'F' => '3ds',
     213        'G' => '3dsWarranty',
     214        'H' => 'imprint',
     215        'I' => 'ip',
     216        'J' => 'lastNumbers',
     217        'K' => 'sign',
     218        'N' => 'firstNumbers',
     219        'O' => '3dsInlistment',
     220        'o' => 'celetemType',
     221        'P' => 'paymentType',
     222        'Q' => 'time',
     223        'S' => 'transaction',
     224        'U' => 'subscriptionData',
     225        'W' => 'date',
     226        'Y' => 'country',
     227        'Z' => 'paymentIndex',
     228        'v' => '3dsVersion',
     229    );
     230
     231    public function __construct(WC_Paybox_Config $config)
     232    {
     233        $this->_config = $config;
     234    }
     235
     236    public function addCartErrorMessage($message)
     237    {
     238        wc_add_notice($message, 'error');
     239    }
     240
     241    public function addOrderNote(WC_Order $order, $message)
     242    {
     243        $order->add_order_note($message);
     244    }
     245
     246    public function addOrderPayment(WC_Order $order, $type, array $data)
     247    {
     248        global $wpdb;
     249        $wpdb->insert($wpdb->prefix.'wc_paybox_payment', array(
     250            'order_id' => $order->get_id(),
     251            'type' => $type,
     252            'data' => serialize($data),
     253        ));
     254    }
     255
     256    /**
     257     * @params WC_Order $order Order
     258     * @params string $type Type of payment (standard or threetime)
     259     * @params array $additionalParams Additional parameters
     260     */
     261    public function buildSystemParams(WC_Order $order, $type, array $additionalParams = array())
     262    {
     263        global $wpdb;
     264
     265        // Parameters
     266        $values = array();
     267
     268        // Merchant information
     269        $values['PBX_SITE'] = $this->_config->getSite();
     270        $values['PBX_RANG'] = $this->_config->getRank();
     271        $values['PBX_IDENTIFIANT'] = $this->_config->getIdentifier();
     272        $values['PBX_VERSION'] = WC_PAYBOX_PLUGIN . "-" . WC_PAYBOX_VERSION . "_WP" . get_bloginfo('version') . "_WC" . WC()->version;
     273
     274        // Order information
     275        $values['PBX_PORTEUR'] = $this->getBillingEmail($order);
     276        $values['PBX_DEVISE'] = $this->getCurrency();
     277        $values['PBX_CMD'] = $order->get_id().' - '.$this->getBillingName($order);
     278
     279        // Amount
     280        $orderAmount = floatval($order->get_total());
     281        $amountScale = $this->_currencyDecimals[$values['PBX_DEVISE']];
     282        $amountScale = pow(10, $amountScale);
     283        switch ($type) {
     284            case 'standard':
     285                $delay = $this->_config->getDelay();
     286                if ($delay > 0) {
     287                    if ($delay > 7) {
     288                        $delay = 7;
     289                    }
     290                    $values['PBX_DIFF'] = sprintf('%02d', $delay);
     291                }
     292                $values['PBX_TOTAL'] = sprintf('%03d', round($orderAmount * $amountScale));
     293                break;
     294
     295            case 'threetime':
     296                // Compute each payment amount
     297                $step = round($orderAmount * $amountScale / 3);
     298                $firstStep = ($orderAmount * $amountScale) - 2 * $step;
     299                $values['PBX_TOTAL'] = sprintf('%03d', $firstStep);
     300                $values['PBX_2MONT1'] = sprintf('%03d', $step);
     301                $values['PBX_2MONT2'] = sprintf('%03d', $step);
     302
     303                // Payment dates
     304                $now = new DateTime();
     305                $now->modify('1 month');
     306                $values['PBX_DATE1'] = $now->format('d/m/Y');
     307                $now->modify('1 month');
     308                $values['PBX_DATE2'] = $now->format('d/m/Y');
     309
     310                // Force validity date of card
     311                $values['PBX_DATEVALMAX'] = $now->format('ym');
     312                break;
     313
     314            default:
     315                $message  = __('Unexpected type %s', WC_PAYBOX_PLUGIN);
     316                $message = sprintf($message, $type);
     317                throw new Exception($message);
     318        }
     319
     320        // Paybox => Magento
     321        $values['PBX_RETOUR'] = 'M:M;R:R;T:T;A:A;B:B;C:C;D:D;E:E;F:F;G:G;I:I;J:J;N:N;O:O;P:P;Q:Q;S:S;W:W;Y:Y;v:v;K:K';
     322        $values['PBX_RUF1'] = 'POST';
     323
     324        // 3DSv2 parameters
     325        $values['PBX_SHOPPINGCART'] = $this->getXmlShoppingCartInformation($order);
     326        $values['PBX_BILLING'] = $this->getXmlBillingInformation($order);
     327
     328        // Choose correct language
     329        $lang = get_locale();
     330        if (!empty($lang)) {
     331            $lang = preg_replace('#_.*$#', '', $lang);
     332        }
     333        $languages = $this->getLanguages();
     334        if (!array_key_exists($lang, $languages)) {
     335            $lang = 'default';
     336        }
     337        $values['PBX_LANGUE'] = $languages[$lang];
     338
     339        // Choose page format depending on browser/devise
     340        if ($this->isMobile()) {
     341            $values['PBX_SOURCE'] = 'XHTMl';
     342        }
     343
     344        // Misc.
     345        $values['PBX_TIME'] = date('c');
     346        $values['PBX_HASH'] = strtoupper($this->_config->getHmacAlgo());
     347
     348        // Adding additionnal informations
     349        $values = array_merge($values, $additionalParams);
     350
     351        // Sort parameters for simpler debug
     352        ksort($values);
     353
     354        // Sign values
     355        $sign = $this->signValues($values);
     356
     357        // Hash HMAC
     358        $values['PBX_HMAC'] = $sign;
     359
     360        return $values;
     361    }
     362
     363    public function convertParams(array $params)
     364    {
     365        $result = array();
     366        foreach ($this->_resultMapping as $param => $key) {
     367            if (isset($params[$param])) {
     368                $result[$key] = utf8_encode($params[$param]);
     369            }
     370        }
     371
     372        return $result;
     373    }
     374
     375    public function getBillingEmail(WC_Order $order)
     376    {
     377        return $order->get_billing_email();
     378    }
     379
     380    public function getBillingName(WC_Order $order)
     381    {
     382        $name = $order->get_billing_first_name().' '.$order->get_billing_last_name();
     383        $name = remove_accents($name);
     384        $name = trim(preg_replace('/[^-. a-zA-Z0-9]/', '', $name));
     385        return $name;
     386    }
     387
     388    /**
     389     * Format a value to respect specific rules
     390     *
     391     * @param string $value
     392     * @param string $type
     393     * @param int $maxLength
     394     * @return string
     395     */
     396    protected function formatTextValue($value, $type, $maxLength = null)
     397    {
     398        /*
     399        AN : Alphanumerical without special characters
     400        ANP : Alphanumerical with spaces and special characters
     401        ANS : Alphanumerical with special characters
     402        N : Numerical only
     403        A : Alphabetic only
     404        */
     405
     406        switch ($type) {
     407            default:
     408            case 'AN':
     409                $value = remove_accents($value);
     410                break;
     411            case 'ANP':
     412                $value = remove_accents($value);
     413                $value = preg_replace('/[^-. a-zA-Z0-9]/', '', $value);
     414                break;
     415            case 'ANS':
     416                break;
     417            case 'N':
     418                $value = preg_replace('/[^0-9.]/', '', $value);
     419                break;
     420            case 'A':
     421                $value = remove_accents($value);
     422                $value = preg_replace('/[^A-Za-z]/', '', $value);
     423                break;
     424        }
     425        // Remove carriage return characters
     426        $value = trim(preg_replace("/\r|\n/", '', $value));
     427
     428        // Cut the string when needed
     429        if (!empty($maxLength) && is_numeric($maxLength) && $maxLength > 0) {
     430            if (function_exists('mb_strlen')) {
     431                if (mb_strlen($value) > $maxLength) {
     432                    $value = mb_substr($value, 0, $maxLength);
     433                }
     434            } elseif (strlen($value) > $maxLength) {
     435                $value = substr($value, 0, $maxLength);
     436            }
     437        }
     438
     439        return $value;
     440    }
     441
     442    /**
     443     * Import XML content as string and use DOMDocument / SimpleXML to validate, if available
     444     *
     445     * @param string $xml
     446     * @return string
     447     */
     448    protected function exportToXml($xml)
     449    {
     450        if (class_exists('DOMDocument')) {
     451            $doc = new DOMDocument();
     452            $doc->loadXML($xml);
     453            $xml = $doc->saveXML();
     454        } elseif (function_exists('simplexml_load_string')) {
     455            $xml = simplexml_load_string($xml)->asXml();
     456        }
     457
     458        $xml = trim(preg_replace('/(\s*)(' . preg_quote('<?xml version="1.0" encoding="utf-8"?>') . ')(\s*)/', '$2', $xml));
     459        $xml = trim(preg_replace("/\r|\n/", '', $xml));
     460
     461        return $xml;
     462    }
     463
     464    /**
     465     * Generate XML value for PBX_BILLING parameter
     466     *
     467     * @param WC_Order $order
     468     * @return string
     469     */
     470    public function getXmlBillingInformation(WC_Order $order)
     471    {
     472        $firstName = $this->formatTextValue($order->get_billing_first_name(), 'ANP', 30);
     473        $lastName = $this->formatTextValue($order->get_billing_last_name(), 'ANP', 30);
     474        $addressLine1 = $this->formatTextValue($order->get_billing_address_1(), 'ANS', 50);
     475        $addressLine2 = $this->formatTextValue($order->get_billing_address_2(), 'ANS', 50);
     476        $zipCode = $this->formatTextValue($order->get_billing_postcode(), 'ANS', 16);
     477        $city = $this->formatTextValue($order->get_billing_city(), 'ANS', 50);
     478        $countryCode = (int)WC_Paybox_Iso3166_Country::getNumericCode($order->get_billing_country());
     479
     480        $xml = sprintf(
     481            '<?xml version="1.0" encoding="utf-8"?><Billing><Address><FirstName>%s</FirstName><LastName>%s</LastName><Address1>%s</Address1><Address2>%s</Address2><ZipCode>%s</ZipCode><City>%s</City><CountryCode>%d</CountryCode></Address></Billing>',
     482            $firstName,
     483            $lastName,
     484            $addressLine1,
     485            $addressLine2,
     486            $zipCode,
     487            $city,
     488            $countryCode
     489        );
     490
     491        return $this->exportToXml($xml);
     492    }
     493
     494    /**
     495     * Generate XML value for PBX_SHOPPINGCART parameter
     496     *
     497     * @param WC_Order $order
     498     * @return string
     499     */
     500    public function getXmlShoppingCartInformation(WC_Order $order)
     501    {
     502        $totalQuantity = 0;
     503        foreach ($order->get_items() as $item) {
     504            $totalQuantity += (int)$item->get_quantity();
     505        }
     506        // totalQuantity must be less or equal than 99
     507        $totalQuantity = min($totalQuantity, 99);
     508
     509        return sprintf('<?xml version="1.0" encoding="utf-8"?><shoppingcart><total><totalQuantity>%d</totalQuantity></total></shoppingcart>', $totalQuantity);
     510    }
     511
     512    public function getClientIp()
     513    {
     514        $ipaddress = '';
     515        if ($_SERVER['HTTP_CLIENT_IP']) {
     516            $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
     517        } elseif ($_SERVER['HTTP_X_FORWARDED_FOR']) {
     518            $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
     519        } elseif ($_SERVER['HTTP_X_FORWARDED']) {
     520            $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
     521        } elseif ($_SERVER['HTTP_FORWARDED_FOR']) {
     522            $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
     523        } elseif ($_SERVER['HTTP_FORWARDED']) {
     524            $ipaddress = $_SERVER['HTTP_FORWARDED'];
     525        } elseif ($_SERVER['REMOTE_ADDR']) {
     526            $ipaddress = $_SERVER['REMOTE_ADDR'];
     527        } else {
     528            $ipaddress = 'UNKNOWN';
     529        }
     530
     531        return $ipaddress;
     532    }
     533
     534    public function getCurrency()
     535    {
     536        return WC_Paybox_Iso4217Currency::getIsoCode(get_woocommerce_currency());
     537    }
     538
     539    public function getLanguages()
     540    {
     541        return array(
     542            'fr' => 'FRA',
     543            'es' => 'ESP',
     544            'it' => 'ITA',
     545            'de' => 'DEU',
     546            'nl' => 'NLD',
     547            'sv' => 'SWE',
     548            'pt' => 'PRT',
     549            'default' => 'GBR',
     550        );
     551    }
     552
     553    public function getOrderPayments($orderId, $type)
     554    {
     555        global $wpdb;
     556        $sql = 'select * from '.$wpdb->prefix.'wc_paybox_payment where order_id = %d and type = %s';
     557        $sql = $wpdb->prepare($sql, $orderId, $type);
     558
     559        return $wpdb->get_row($sql);
     560    }
     561
     562    public function getParams()
     563    {
     564        // Retrieves data
     565        $data = file_get_contents('php://input');
    439566        if (empty($data)) {
    440567            $data = $_SERVER['QUERY_STRING'];
    441568        }
    442569        if (empty($data)) {
    443             $message = 'An unexpected error in Paybox call has occured: no parameters.';
    444             throw new Exception(__($message, WC_PAYBOX_PLUGIN));
    445         }
    446 
    447         // Extract signature
    448         $matches = array();
    449         if (!preg_match('#^(.*)&K=(.*)$#', $data, $matches)) {
    450             $message = 'An unexpected error in Paybox call has occured: missing signature.';
    451             throw new Exception(__($message, WC_PAYBOX_PLUGIN));
    452         }
    453 
    454         // /*Check signature*/
    455         $signature = base64_decode(urldecode($matches[2]));
    456         $pubkey = file_get_contents(dirname(__FILE__).'/pubkey.pem');
    457         $res = (boolean) openssl_verify($matches[1], $signature, $pubkey);
    458 
    459         if (!$res) {
    460             if (preg_match('#^s=i&(.*)&K=(.*)$#', $data, $matches)) {
    461                 $signature = base64_decode(urldecode($matches[2]));
    462                 $res = (boolean) openssl_verify($matches[1], $signature, $pubkey);
    463             }
    464 
    465             if (!$res) {
    466                 $message = 'An unexpected error in Paybox call has occured: invalid signature.';
    467                 throw new Exception(__($message, WC_PAYBOX_PLUGIN));
    468             }
    469         }
    470 
    471         $rawParams = array();
    472         parse_str($data, $rawParams);
    473 
    474         // Decrypt params
    475         $params = $this->convertParams($rawParams);
    476         if (empty($params)) {
    477             $message = 'An unexpected error in Paybox call has occured: no parameters.';
    478             throw new Exception(__($message, WC_PAYBOX_PLUGIN));
    479         }
    480         return $params;
    481     }
    482 
    483     public function getSystemUrl() {
    484         $urls = $this->_config->getSystemUrls();
    485         if (empty($urls)) {
    486             $message = 'Missing URL for Paybox system in configuration';
    487             throw new Exception(__($message, WC_PAYBOX_PLUGIN));
    488         }
    489 
    490         // look for valid peer
    491         $error = null;
    492         foreach ($urls as $url) {
    493             $testUrl = preg_replace('#^([a-zA-Z0-9]+://[^/]+)(/.*)?$#', '\1/load.html', $url);
    494 
    495             $connectParams = array(
    496                 'timeout' => 5,
    497                 'redirection' => 0,
    498                 'user-agent' => 'Woocommerce Paybox module',
    499                 'httpversion' => '2',
    500             );
    501             try {
    502                 $response = wp_remote_get($testUrl, $connectParams);
    503                 if (is_array($response) && ($response['response']['code'] == 200)) {
    504                     if (preg_match('#<div id="server_status" style="text-align:center;">OK</div>#', $response['body']) == 1) {
    505                         return $url;
    506                     }
    507                 }
    508             }
    509             catch (Exception $e) {
    510                 $error = $e;
    511             }
    512         }
    513 
    514         // Here, there's a problem
    515         throw new Exception(__('Paybox not available. Please try again later.'));
    516     }
    517 
    518     public function isMobile() {
    519         // From http://detectmobilebrowsers.com/, regexp of 09/09/2013
    520         global $_SERVER;
    521         $userAgent = $_SERVER['HTTP_USER_AGENT'];
    522         if (preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$userAgent)) {
    523             return true;
    524         }
    525         if (preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i', substr($userAgent, 0, 4))) {
    526             return true;
    527         }
    528         return false;
    529     }
    530 
    531     public function signValues(array $values) {
    532         // Serialize values
    533         $params = array();
    534         foreach ($values as $name => $value) {
    535             $params[] = $name.'='.$value;
    536         }
    537         $query = implode('&', $params);
    538 
    539         // Prepare key
    540         $key = pack('H*', $this->_config->getHmacKey());
    541 
    542         // Sign values
    543         $sign = hash_hmac($this->_config->getHmacAlgo(), $query, $key);
    544         if ($sign === false) {
    545             $errorMsg = 'Unable to create hmac signature. Maybe a wrong configuration.';
    546             throw new Exception(__($errorMsg, WC_PAYBOX_PLUGIN));
    547         }
    548 
    549         return strtoupper($sign);
    550     }
     570            $message = 'An unexpected error in Paybox call has occured: no parameters.';
     571            throw new Exception(__($message, WC_PAYBOX_PLUGIN));
     572        }
     573
     574        // Extract signature
     575        $matches = array();
     576        if (!preg_match('#^(.*)&K=(.*)$#', $data, $matches)) {
     577            $message = 'An unexpected error in Paybox call has occured: missing signature.';
     578            throw new Exception(__($message, WC_PAYBOX_PLUGIN));
     579        }
     580
     581        // /*Check signature*/
     582        $signature = base64_decode(urldecode($matches[2]));
     583        $pubkey = file_get_contents(dirname(__FILE__).'/pubkey.pem');
     584        $res = (boolean) openssl_verify($matches[1], $signature, $pubkey);
     585
     586        if (!$res) {
     587            if (preg_match('#^s=i&(.*)&K=(.*)$#', $data, $matches)) {
     588                $signature = base64_decode(urldecode($matches[2]));
     589                $res = (boolean) openssl_verify($matches[1], $signature, $pubkey);
     590            }
     591
     592            if (!$res) {
     593                $message = 'An unexpected error in Paybox call has occured: invalid signature.';
     594                throw new Exception(__($message, WC_PAYBOX_PLUGIN));
     595            }
     596        }
     597
     598        $rawParams = array();
     599        parse_str($data, $rawParams);
     600
     601        // Decrypt params
     602        $params = $this->convertParams($rawParams);
     603        if (empty($params)) {
     604            $message = 'An unexpected error in Paybox call has occured: no parameters.';
     605            throw new Exception(__($message, WC_PAYBOX_PLUGIN));
     606        }
     607
     608        return $params;
     609    }
     610
     611    public function getSystemUrl()
     612    {
     613        $urls = $this->_config->getSystemUrls();
     614        if (empty($urls)) {
     615            $message = 'Missing URL for Paybox system in configuration';
     616            throw new Exception(__($message, WC_PAYBOX_PLUGIN));
     617        }
     618
     619        // look for valid peer
     620        $error = null;
     621        foreach ($urls as $url) {
     622            $testUrl = preg_replace('#^([a-zA-Z0-9]+://[^/]+)(/.*)?$#', '\1/load.html', $url);
     623
     624            $connectParams = array(
     625                'timeout' => 5,
     626                'redirection' => 0,
     627                'user-agent' => 'Woocommerce Paybox module',
     628                'httpversion' => '2',
     629            );
     630            try {
     631                $response = wp_remote_get($testUrl, $connectParams);
     632                if (is_array($response) && ($response['response']['code'] == 200)) {
     633                    if (preg_match('#<div id="server_status" style="text-align:center;">OK</div>#', $response['body']) == 1) {
     634                        return $url;
     635                    }
     636                }
     637            } catch (Exception $e) {
     638                $error = $e;
     639            }
     640        }
     641
     642        // Here, there's a problem
     643        throw new Exception(__('Paybox not available. Please try again later.'));
     644    }
     645
     646    public function isMobile()
     647    {
     648        // From http://detectmobilebrowsers.com/, regexp of 09/09/2013
     649        global $_SERVER;
     650
     651        $userAgent = $_SERVER['HTTP_USER_AGENT'];
     652        if (preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i', $userAgent)) {
     653            return true;
     654        }
     655        if (preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i', substr($userAgent, 0, 4))) {
     656            return true;
     657        }
     658
     659        return false;
     660    }
     661
     662    public function signValues(array $values)
     663    {
     664        // Serialize values
     665        $params = array();
     666        foreach ($values as $name => $value) {
     667            $params[] = $name.'='.$value;
     668        }
     669        $query = implode('&', $params);
     670
     671        // Prepare key
     672        $key = pack('H*', $this->_config->getHmacKey());
     673
     674        // Sign values
     675        $sign = hash_hmac($this->_config->getHmacAlgo(), $query, $key);
     676        if ($sign === false) {
     677            $errorMsg = 'Unable to create hmac signature. Maybe a wrong configuration.';
     678            throw new Exception(__($errorMsg, WC_PAYBOX_PLUGIN));
     679        }
     680
     681        return strtoupper($sign);
     682    }
    551683
    552684    public function toErrorMessage($code)
    553     {
     685    {
    554686        if (isset($this->_errorCode[$code])) {
    555687            return $this->_errorCode[$code];
     
    559691    }
    560692
    561     /**
    562      * Load order from the $token
    563      * @param string $token Token (@see tokenizeOrder)
    564      * @return Mage_Sales_Model_Order
    565      */
    566     public function untokenizeOrder($token) {
    567         $parts = explode(' - ', $token, 2);
    568         if (count($parts) < 2) {
    569             $message = 'Invalid decrypted token "%s"';
    570             throw new Exception(sprintf(__($message, WC_PAYBOX_PLUGIN), $token));
    571         }
    572 
    573         // Retrieves order
    574         $order = new WC_Order($parts[0]);
    575         $temp_id=$order->get_id();
    576         if (empty($temp_id)) {
    577             $message = 'Not existing order id from decrypted token "%s"';
    578             throw new Exception(sprintf(__($message, WC_PAYBOX_PLUGIN), $token));
    579         }
    580 
    581         $name = $this->getBillingName($order);
    582         if (($name != utf8_decode($parts[1])) && ($name != $parts[1])) {
    583             $message = 'Consistency error on descrypted token "%s"';
    584             throw new Exception(sprintf(__($message, WC_PAYBOX_PLUGIN), $token));
    585         }
    586 
    587         return $order;
    588     }
     693    /**
     694     * Load order from the $token
     695     * @param string $token Token (@see tokenizeOrder)
     696     * @return Mage_Sales_Model_Order
     697     */
     698    public function untokenizeOrder($token)
     699    {
     700        $parts = explode(' - ', $token, 2);
     701        if (count($parts) < 2) {
     702            $message = 'Invalid decrypted token "%s"';
     703            throw new Exception(sprintf(__($message, WC_PAYBOX_PLUGIN), $token));
     704        }
     705
     706        // Retrieves order
     707        $order = new WC_Order($parts[0]);
     708        $temp_id=$order->get_id();
     709        if (empty($temp_id)) {
     710            $message = 'Not existing order id from decrypted token "%s"';
     711            throw new Exception(sprintf(__($message, WC_PAYBOX_PLUGIN), $token));
     712        }
     713
     714        $name = $this->getBillingName($order);
     715        if (($name != utf8_decode($parts[1])) && ($name != $parts[1])) {
     716            $message = 'Consistency error on descrypted token "%s"';
     717            throw new Exception(sprintf(__($message, WC_PAYBOX_PLUGIN), $token));
     718        }
     719
     720        return $order;
     721    }
    589722}
  • paybox-woocommerce-gateway/trunk/lang/woocommerce-paybox-fr_FR.po

    r2240593 r2501160  
    11msgid ""
    22msgstr ""
    3 "Project-Id-Version: Woocommerce Paybox plugin\n"
    4 "POT-Creation-Date: 2020-02-06 14:16+0100\n"
    5 "PO-Revision-Date: 2020-02-07 17:19+0100\n"
     3"Project-Id-Version: WooCommerce Paybox Payment plugin\n"
     4"POT-Creation-Date: 2020-10-09 17:28+0200\n"
     5"PO-Revision-Date: 2020-10-09 17:34+0200\n"
    66"Last-Translator: Jérôme Cintas <jerome.cintas@verifonecom>\n"
    77"Language-Team: BM Services <[email protected]>\n"
    8 "Language: fr\n"
     8"Language: fr_FR\n"
    99"MIME-Version: 1.0\n"
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "X-Generator: Poedit 2.3\n"
     12"X-Generator: Poedit 2.4.1\n"
    1313"X-Poedit-Basepath: ..\n"
    1414"Plural-Forms: nplurals=2; plural=(n > 1);\n"
     15"X-Poedit-Flags-xgettext: --add-comments=translators:\n"
     16"X-Poedit-WPHeader: woocommerce-paybox.php\n"
    1517"X-Poedit-SourceCharset: UTF-8\n"
    16 "X-Poedit-KeywordsList: __;__e\n"
     18"X-Poedit-KeywordsList: __;_e;_n:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;esc_attr__;"
     19"esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;_n_noop:1,2;"
     20"_nx_noop:3c,1,2;__ngettext_noop:1,2\n"
    1721"X-Poedit-SearchPath-0: .\n"
    18 
    19 #: class/wc-paybox-abstract-gateway.php:68
    20 #: class/wc-paybox-abstract-gateway.php:113
     22"X-Poedit-SearchPathExcluded-0: *.min.js\n"
     23
     24#: class/wc-paybox-abstract-gateway.php:83
    2125msgid "Enable/Disable"
    2226msgstr "Actif/Inactif"
    2327
    24 #: class/wc-paybox-abstract-gateway.php:70
     28#: class/wc-paybox-abstract-gateway.php:85
    2529msgid "Enable Paybox Payment"
    2630msgstr "Activer le paiement par Paybox"
    2731
    28 #: class/wc-paybox-abstract-gateway.php:74
     32#: class/wc-paybox-abstract-gateway.php:89
    2933msgid "Title"
    3034msgstr "Titre"
    3135
    32 #: class/wc-paybox-abstract-gateway.php:76
     36#: class/wc-paybox-abstract-gateway.php:91
    3337msgid "This controls the title which the user sees during checkout."
    3438msgstr "Titre visible par le client lors d'une commande."
    3539
    36 #: class/wc-paybox-abstract-gateway.php:80
     40#: class/wc-paybox-abstract-gateway.php:102
     41msgid "Icon file"
     42msgstr "Fichier icône"
     43
     44#: class/wc-paybox-abstract-gateway.php:104
     45msgid "Icon file to be displayed to customers. file are located in: "
     46msgstr ""
     47"Fichier d’icône à afficher au client. les fichiers sont dans le répertoire: "
     48
     49#: class/wc-paybox-abstract-gateway.php:109
    3750msgid "Description"
    3851msgstr "Description"
    3952
    40 #: class/wc-paybox-abstract-gateway.php:82
     53#: class/wc-paybox-abstract-gateway.php:111
    4154msgid "Payment method description that the customer will see on your checkout."
    4255msgstr ""
     
    4457"commande."
    4558
    46 #: class/wc-paybox-abstract-gateway.php:87
     59#: class/wc-paybox-abstract-gateway.php:116
    4760msgid "Delay"
    4861msgstr "Délai"
    4962
    50 #: class/wc-paybox-abstract-gateway.php:90
     63#: class/wc-paybox-abstract-gateway.php:119
    5164msgid "Immediate"
    5265msgstr "Immédiat"
    5366
    54 #: class/wc-paybox-abstract-gateway.php:91
     67#: class/wc-paybox-abstract-gateway.php:120
    5568msgid "1 day"
    5669msgstr "1 jour"
    5770
    58 #: class/wc-paybox-abstract-gateway.php:92
     71#: class/wc-paybox-abstract-gateway.php:121
    5972msgid "2 days"
    6073msgstr "2 jours"
    6174
    62 #: class/wc-paybox-abstract-gateway.php:93
     75#: class/wc-paybox-abstract-gateway.php:122
    6376msgid "3 days"
    6477msgstr "3 jours"
    6578
    66 #: class/wc-paybox-abstract-gateway.php:94
     79#: class/wc-paybox-abstract-gateway.php:123
    6780msgid "4 days"
    6881msgstr "4 jours"
    6982
    70 #: class/wc-paybox-abstract-gateway.php:95
     83#: class/wc-paybox-abstract-gateway.php:124
    7184msgid "5 days"
    7285msgstr "5 jours"
    7386
    74 #: class/wc-paybox-abstract-gateway.php:96
     87#: class/wc-paybox-abstract-gateway.php:125
    7588msgid "6 days"
    7689msgstr "6 jours"
    7790
    78 #: class/wc-paybox-abstract-gateway.php:97
     91#: class/wc-paybox-abstract-gateway.php:126
    7992msgid "7 days"
    8093msgstr "7 jours"
    8194
    82 #: class/wc-paybox-abstract-gateway.php:103
    83 #: class/wc-paybox-abstract-gateway.php:125
     95#: class/wc-paybox-abstract-gateway.php:132
    8496msgid "Minimal amount"
    8597msgstr "Montant minimal"
    8698
    87 #: class/wc-paybox-abstract-gateway.php:105
     99#: class/wc-paybox-abstract-gateway.php:134
    88100msgid ""
    89101"Enable this payment method for order with amount greater or equals to this "
    90102"amount (empty to ignore this condition)"
    91103msgstr ""
    92 "Activer 3D Secure pour les commandes dont le montant est supérieur ou égal "
    93 "au montant suivant (laissez vide pour ne pas activer cette condition)"
    94 
    95 #: class/wc-paybox-abstract-gateway.php:109
     104"Activer ce moyen de paiement pour les commandes dont le montant est "
     105"supérieur ou égal au montant suivant (laissez vide pour ne pas activer cette "
     106"condition)"
     107
     108#: class/wc-paybox-abstract-gateway.php:138
    96109msgid "3D Secure"
    97110msgstr "3D Secure"
    98111
    99 #: class/wc-paybox-abstract-gateway.php:115
    100 msgid "Enable 3D Secure"
    101 msgstr "Activer 3D Secure"
    102 
    103 #: class/wc-paybox-abstract-gateway.php:116
    104 msgid ""
    105 "You can enable 3D Secure for all orders or depending on following conditions"
    106 msgstr ""
    107 "Vous pouvez activer  3D Secure pour toutes les commandes ou en fonction des "
    108 "conditions suivantes"
    109 
    110 #: class/wc-paybox-abstract-gateway.php:119
    111 msgid "Disabled"
    112 msgstr "Inactif"
    113 
    114 #: class/wc-paybox-abstract-gateway.php:120
    115 msgid "Enabled"
    116 msgstr "Actif"
    117 
    118 #: class/wc-paybox-abstract-gateway.php:121
    119 msgid "Conditional"
    120 msgstr "Sélectif"
    121 
    122 #: class/wc-paybox-abstract-gateway.php:127
    123 msgid ""
    124 "Enable 3D Secure for order with amount greater or equals to this amount "
    125 "(empty to ignore this condition)"
    126 msgstr ""
    127 "Activer 3D Secure pour les commandes dont le montant est supérieur ou égal "
    128 "au montant suivant"
    129 
    130 #: class/wc-paybox-abstract-gateway.php:131
     112#: class/wc-paybox-abstract-gateway.php:142
     113msgid "Version"
     114msgstr "Version"
     115
     116#: class/wc-paybox-abstract-gateway.php:152
    131117msgid "Paybox account"
    132118msgstr "Compte Paybox"
    133119
    134 #: class/wc-paybox-abstract-gateway.php:135
     120#: class/wc-paybox-abstract-gateway.php:156
    135121msgid "Site number"
    136122msgstr "Numéro du site"
    137123
    138 #: class/wc-paybox-abstract-gateway.php:137
     124#: class/wc-paybox-abstract-gateway.php:158
    139125msgid "Site number provided by Paybox."
    140126msgstr "Le numéro du site vous est fourni par Paybox."
    141127
    142 #: class/wc-paybox-abstract-gateway.php:141
     128#: class/wc-paybox-abstract-gateway.php:162
    143129msgid "Rank number"
    144130msgstr "Rang"
    145131
    146 #: class/wc-paybox-abstract-gateway.php:143
     132#: class/wc-paybox-abstract-gateway.php:164
    147133msgid "Rank number provided by Paybox (two last digits)."
    148134msgstr "Numéro de rang fourni par Paybox (deux derniers chiffres)."
    149135
    150 #: class/wc-paybox-abstract-gateway.php:147
     136#: class/wc-paybox-abstract-gateway.php:168
    151137msgid "Login"
    152138msgstr "Identifiant"
    153139
    154 #: class/wc-paybox-abstract-gateway.php:149
     140#: class/wc-paybox-abstract-gateway.php:170
    155141msgid "Internal login provided by Paybox."
    156142msgstr "Votre identifiant vous est fourni par Paybox."
    157143
    158 #: class/wc-paybox-abstract-gateway.php:153
     144#: class/wc-paybox-abstract-gateway.php:174
    159145msgid "HMAC"
    160146msgstr "HMAC"
    161147
    162 #: class/wc-paybox-abstract-gateway.php:155
     148#: class/wc-paybox-abstract-gateway.php:176
    163149msgid "Secrete HMAC key to create using the Paybox interface."
    164150msgstr "Clé secrète HMAC à générer puis activer dans votre Back-Office Paybox."
    165151
    166 #: class/wc-paybox-abstract-gateway.php:159
     152#: class/wc-paybox-abstract-gateway.php:180
    167153msgid "Environment"
    168154msgstr "Environnement"
    169155
    170 #: class/wc-paybox-abstract-gateway.php:161
     156#: class/wc-paybox-abstract-gateway.php:182
    171157msgid "In test mode your payments will not be sent to the bank."
    172158msgstr "En mode test, vos paiements ne seront pas envoyé à la banque."
    173159
    174 #: class/wc-paybox-abstract-gateway.php:163
     160#: class/wc-paybox-abstract-gateway.php:184
    175161msgid "Production"
    176162msgstr "Production"
    177163
    178 #: class/wc-paybox-abstract-gateway.php:164
     164#: class/wc-paybox-abstract-gateway.php:185
    179165msgid "Test"
    180166msgstr "Test"
    181167
    182 #: class/wc-paybox-abstract-gateway.php:169
     168#: class/wc-paybox-abstract-gateway.php:190
    183169msgid "Technical settings"
    184170msgstr "Configuration technique"
    185171
    186 #: class/wc-paybox-abstract-gateway.php:173
    187 msgid "Allowed IPs "
    188 msgstr "Adresses IP autorisées "
    189 
    190 #: class/wc-paybox-abstract-gateway.php:175
     172#: class/wc-paybox-abstract-gateway.php:194
     173msgid "Allowed IPs"
     174msgstr "Adresses IP autorisées"
     175
     176#: class/wc-paybox-abstract-gateway.php:196
    191177msgid "A coma separated list of Paybox IPs."
    192178msgstr ""
     
    194180"réception des Notifications Instantanées de Paiement."
    195181
    196 #: class/wc-paybox-abstract-gateway.php:179
     182#: class/wc-paybox-abstract-gateway.php:200
    197183msgid "Debug"
    198184msgstr "Debug"
    199185
    200 #: class/wc-paybox-abstract-gateway.php:181
     186#: class/wc-paybox-abstract-gateway.php:202
    201187msgid "Enable some debugging information"
    202188msgstr "Activer les informations de debuggage"
    203189
    204 #: class/wc-paybox-abstract-gateway.php:213
     190#: class/wc-paybox-abstract-gateway.php:237
    205191msgid "Customer is redirected to Paybox payment page"
    206192msgstr "Le client est redirigé vers la pages de paiement paybox"
    207193
    208 #: class/wc-paybox-abstract-gateway.php:247
     194#: class/wc-paybox-abstract-gateway.php:272
    209195msgid "Back..."
    210196msgstr "Retour..."
    211197
    212 #: class/wc-paybox-abstract-gateway.php:255
     198#: class/wc-paybox-abstract-gateway.php:280
    213199msgid ""
    214200"This is a debug view. Click continue to be redirected to Paybox payment page."
     
    217203"la page de paiement Paybox."
    218204
    219 #: class/wc-paybox-abstract-gateway.php:259
     205#: class/wc-paybox-abstract-gateway.php:284
    220206msgid ""
    221207"You will be redirected to the Paybox payment page. If not, please use the "
     
    225211"cas, merci d'utiliser le bouton ci dessous."
    226212
    227 #: class/wc-paybox-abstract-gateway.php:267
     213#: class/wc-paybox-abstract-gateway.php:292
    228214msgid "Continue..."
    229215msgstr "Continuer..."
    230216
    231 #: class/wc-paybox-abstract-gateway.php:321
    232 #: class/wc-paybox-abstract-gateway.php:357
     217#: class/wc-paybox-abstract-gateway.php:348
     218#: class/wc-paybox-abstract-gateway.php:388
    233219msgid "Customer is back from Paybox payment page."
    234220msgstr "Le client revient de la page de paiement Paybox."
    235221
    236 #: class/wc-paybox-abstract-gateway.php:322
    237 #: class/wc-paybox-abstract-gateway.php:324
     222#: class/wc-paybox-abstract-gateway.php:349
     223#: class/wc-paybox-abstract-gateway.php:351
    238224msgid "Payment refused by Paybox"
    239225msgstr "Le paiement a été refusé par Paybox"
    240226
    241 #: class/wc-paybox-abstract-gateway.php:340
     227#: class/wc-paybox-abstract-gateway.php:369
    242228msgid "Payment was canceled by user on Paybox payment page."
    243229msgstr "Le paiement a été annulé par le client sur la page de paiement Paybox."
    244230
    245 #: class/wc-paybox-abstract-gateway.php:342
     231#: class/wc-paybox-abstract-gateway.php:371
    246232msgid "Payment canceled"
    247233msgstr "Le paiement a été annulé"
    248234
    249 #: class/wc-paybox-abstract-gateway.php:399
     235#: class/wc-paybox-abstract-gateway.php:431
    250236#, php-format
    251237msgid "Missing %s parameter in Paybox call"
    252 msgstr "Le paramêtre %s manque dans l'appel Paybox"
    253 
    254 #: class/wc-paybox-abstract-gateway.php:410
    255 #: class/wc-paybox-abstract-gateway.php:419
     238msgstr "Le paramètre %s manque dans l'appel Paybox"
     239
     240#: class/wc-paybox-abstract-gateway.php:441
     241#: class/wc-paybox-abstract-gateway.php:450
    256242msgid "Payment was authorized and captured by Paybox."
    257243msgstr "Paiement autorisé et capturé par Paybox."
    258244
    259 #: class/wc-paybox-abstract-gateway.php:423
     245#: class/wc-paybox-abstract-gateway.php:454
    260246msgid "Second payment was captured by Paybox."
    261247msgstr "Deuxième paiement capturé par Paybox."
    262248
    263 #: class/wc-paybox-abstract-gateway.php:426
     249#: class/wc-paybox-abstract-gateway.php:457
    264250msgid "Third payment was captured by Paybox."
    265251msgstr "Troisième paiement capturé par Paybox."
    266252
    267 #: class/wc-paybox-abstract-gateway.php:429
     253#: class/wc-paybox-abstract-gateway.php:460
    268254msgid "Invalid three-time payment status"
    269255msgstr "Statut du paiement en trois fois non valide"
    270256
    271 #: class/wc-paybox-abstract-gateway.php:436 class/wc-paybox.php:303
     257#: class/wc-paybox-abstract-gateway.php:466 class/wc-paybox.php:314
    272258#, php-format
    273259msgid "Unexpected type %s"
    274260msgstr "Type %s inattendu"
    275261
    276 #: class/wc-paybox-abstract-gateway.php:445
     262#: class/wc-paybox-abstract-gateway.php:473
    277263#, php-format
    278264msgid "Payment was refused by Paybox (%s)."
    279265msgstr "Paiement refusé par Paybox (%s)."
    280266
    281 #: class/wc-paybox-encrypt.php:61 class/wc-paybox-encrypt.php:76
     267#: class/wc-paybox-encrypt.php:67 class/wc-paybox-encrypt.php:83
    282268msgid ""
    283269"For some reason, the key has just been generated. please reenter the HMAC "
     
    287273"clé HMAC pour qu'elle soit cryptée."
    288274
    289 #: class/wc-paybox-standard-gateway.php:11
     275#: class/wc-paybox-standard-gateway.php:19
    290276msgid "Paybox"
    291277msgstr "Paybox"
    292278
    293 #: class/wc-paybox-standard-gateway.php:29
    294 #: class/wc-paybox-threetime-gateway.php:55
     279#: class/wc-paybox-standard-gateway.php:42
     280#: class/wc-paybox-threetime-gateway.php:59
    295281msgid "Reference:"
    296 msgstr "Référence/"
    297 
    298 #: class/wc-paybox-standard-gateway.php:31
    299 #: class/wc-paybox-threetime-gateway.php:57
     282msgstr "Référence:"
     283
     284#: class/wc-paybox-standard-gateway.php:44
     285#: class/wc-paybox-threetime-gateway.php:61
    300286msgid "Country of IP:"
    301287msgstr "Pays de l'IP:"
    302288
    303 #: class/wc-paybox-standard-gateway.php:33
    304 #: class/wc-paybox-threetime-gateway.php:59
     289#: class/wc-paybox-standard-gateway.php:46
     290#: class/wc-paybox-threetime-gateway.php:63
    305291msgid "Processing date:"
    306292msgstr "Date de traitement:"
    307293
    308 #: class/wc-paybox-standard-gateway.php:35
    309 #: class/wc-paybox-threetime-gateway.php:61
     294#: class/wc-paybox-standard-gateway.php:48
     295#: class/wc-paybox-threetime-gateway.php:65
    310296msgid "Card numbers:"
    311297msgstr "Numéros de la carte:"
    312298
    313 #: class/wc-paybox-standard-gateway.php:38
    314 #: class/wc-paybox-threetime-gateway.php:64
     299#: class/wc-paybox-standard-gateway.php:51
     300#: class/wc-paybox-threetime-gateway.php:68
    315301msgid "Validity date:"
    316302msgstr "Date de validité:"
    317303
    318 #: class/wc-paybox-standard-gateway.php:40
    319 #: class/wc-paybox-threetime-gateway.php:89
     304#: class/wc-paybox-standard-gateway.php:60
     305#: class/wc-paybox-threetime-gateway.php:77
     306msgid "3DS version:"
     307msgstr "Version 3DS:"
     308
     309#: class/wc-paybox-standard-gateway.php:63
     310#: class/wc-paybox-threetime-gateway.php:100
    320311msgid "Transaction:"
    321312msgstr "Transaction:"
    322313
    323 #: class/wc-paybox-standard-gateway.php:41
    324 #: class/wc-paybox-threetime-gateway.php:90
     314#: class/wc-paybox-standard-gateway.php:64
     315#: class/wc-paybox-threetime-gateway.php:101
    325316msgid "Call:"
    326317msgstr "Appel:"
    327318
    328 #: class/wc-paybox-standard-gateway.php:42
    329 #: class/wc-paybox-threetime-gateway.php:91
     319#: class/wc-paybox-standard-gateway.php:65
     320#: class/wc-paybox-threetime-gateway.php:102
    330321msgid "Authorization:"
    331322msgstr "Autorisation:"
    332323
    333 #: class/wc-paybox-standard-gateway.php:44
    334 #: class/wc-paybox-threetime-gateway.php:93
     324#: class/wc-paybox-standard-gateway.php:67
     325#: class/wc-paybox-threetime-gateway.php:104
    335326msgid "Payment information"
    336327msgstr "Informations sur le paiement"
    337328
    338 #: class/wc-paybox-threetime-gateway.php:11
     329#: class/wc-paybox-threetime-gateway.php:21
    339330msgid "Paybox 3 times"
    340331msgstr "Paybox paiement en trois fois"
    341332
    342 #: class/wc-paybox-threetime-gateway.php:69
     333#: class/wc-paybox-threetime-gateway.php:82
    343334msgid "First debit:"
    344335msgstr "Premier paiement:"
    345336
    346 #: class/wc-paybox-threetime-gateway.php:76
    347 #: class/wc-paybox-threetime-gateway.php:85
     337#: class/wc-paybox-threetime-gateway.php:88
     338#: class/wc-paybox-threetime-gateway.php:96
    348339msgid "Not achieved"
    349340msgstr "Non traité"
    350341
    351 #: class/wc-paybox-threetime-gateway.php:78
     342#: class/wc-paybox-threetime-gateway.php:90
    352343msgid "Second debit:"
    353344msgstr "Seconde échéance:"
    354345
    355 #: class/wc-paybox-threetime-gateway.php:87
     346#: class/wc-paybox-threetime-gateway.php:98
    356347msgid "Third debit:"
    357348msgstr "Troisième échéance:"
    358349
    359 #: class/wc-paybox.php:322
    360 #, php-format
    361 msgid "Unexpected 3-D Secure status %s"
    362 msgstr "Statut 3-D Secure inattendu: %s"
    363 
    364 #: class/wc-paybox.php:519
     350#: class/wc-paybox.php:644
    365351msgid "Paybox not available. Please try again later."
    366352msgstr "Paybox n'est pas disponible. Merci d'essayer plus tard."
    367353
    368 #: woocommerce-paybox.php:122
     354#: woocommerce-paybox.php:40
     355msgid "WooCommerce must be activated"
     356msgstr "WooCommerce doit être activé"
     357
     358#: woocommerce-paybox.php:129
    369359msgid "HMAC key cannot be decrypted please re-enter or reinitialise it."
    370360msgstr ""
     
    372362"HMAC, la régénérer si besoin."
    373363
    374 #~ msgid "IPN call from %s not allowed."
    375 #~ msgstr "Appel IPN depuis %s non autorisé."
    376 
    377 #~ msgid "Rank number provided by Paybox."
    378 #~ msgstr "Le rang de votre site vous est fourni par Paybox"
    379 
    380 #~ msgid "Unexpected 3D Secure status %s"
    381 #~ msgstr "Satut 3D Secure %s inattendu"
    382 
    383 #~ msgid "Depending on following conditions (and)"
    384 #~ msgstr "Suivant les conditions ci-dessous (et)"
    385 
    386 #~ msgid "Depending on following conditions (or)"
    387 #~ msgstr "Suivant les conditions ci-dessous (ou)"
    388 
    389 #~ msgid "Maximal order count"
    390 #~ msgstr "Nombre maximal de commande"
    391 
    392 #~ msgid ""
    393 #~ "Enable 3D Secure for customer with less than this number of orders (empty "
    394 #~ "to ignore this condition)"
    395 #~ msgstr ""
    396 #~ "Activer 3D Secure pour les clients ayant passé moins de  for customer "
    397 #~ "with less than this number of orders (laisser vide pour ignorer cette "
    398 #~ "condition)"
    399 
    400 #~ msgid "TODO"
    401 #~ msgstr "TODO"
     364#: woocommerce-paybox.php:134
     365msgid "Woocommerce is not active !"
     366msgstr "WooCommerce n’est pas activé !"
     367
     368#. Plugin Name of the plugin/theme
     369msgid "WooCommerce Paybox Payment plugin"
     370msgstr "Le client est redirigé vers la page de paiement Paybox"
     371
     372#. Description of the plugin/theme
     373msgid "Paybox gateway payment plugins for WooCommerce"
     374msgstr "Extension Paybox - passerelle de paiement pour WooCommerce"
     375
     376#. Author of the plugin/theme
     377msgid "Paybox Verifone"
     378msgstr "Paybox Verifone"
     379
     380#. Author URI of the plugin/theme
     381msgid "http://www.paybox.com"
     382msgstr ""
  • paybox-woocommerce-gateway/trunk/readme.txt

    r2298641 r2501160  
    44Tags: Payment Gateway, Orders, woocommerce, e-commerce, payment, Paybox
    55Requires at least: 3.0.1
    6 Tested up to: 5.4.1
    7 Stable tag: 0.9.9
     6Tested up to: 5.7
     7Stable tag: 0.9.9.2
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
    1010WC requires at least: 2.6
    11 WC tested up to: 4.0.1
     11WC tested up to: 5.1.0
    1212This plugin is a Paybox payment gateway for WooCommerce 3.x
    1313
     
    2323it adds payment information to the orders details and changes the status of orders (upon reception of an IPN, see below.) and adds payment means on the checkout page.
    2424
    25 This plugin takes information from the order and creates a form containing the details of the payment to be made, including parameters configured in the admin panel of the module that identify the mechant. 
     25This plugin takes information from the order and creates a form containing the details of the payment to be made, including parameters configured in the admin panel of the module that identify the mechant.
    2626
    2727The plugin checks for availability of the Paybox platform, through a call to our servers.
     
    5151= My orders are not validated, even though the payment went through ? =
    5252
    53 The oder paid with Paybox is only validated upon rectpion of a positive Instant Payment Notification (IPN) this IPN is authenticated with the filter on the IP address, if the IP is somewhow changed, the plugin will give a 500 HTTP error. 
    54 Avoid Maintenance mode, or allow Paybox IP to go through (194.2.122.158,195.25.7.166,195.101.99.76). If the WordPress Installation is in maintenance mode, the Paybox server will not be able to contact it. 
     53The oder paid with Paybox is only validated upon rectpion of a positive Instant Payment Notification (IPN) this IPN is authenticated with the filter on the IP address, if the IP is somewhow changed, the plugin will give a 500 HTTP error.
     54Avoid Maintenance mode, or allow Paybox IP to go through (194.2.122.158,195.25.7.166,195.101.99.76). If the WordPress Installation is in maintenance mode, the Paybox server will not be able to contact it.
    5555
    5656= Something is not working for me, how can i get help ? =
     
    6868
    6969== Changelog ==
     70= 0.9.9.2 =
     71Force 3DSv2 for all cards
     72
     73= 0.9.9.1 =
     74Add 3DSv2 support
     75
    7076= 0.9.9 =
    7177Fix 3 times payment not displayed
     
    8187
    8288= 0.9.8.6 =
    83 Correcting 3x payments IPN 
     89Correcting 3x payments IPN
    8490
    8591= 0.9.8.5 =
     
    117123
    118124= 0.9.6.7 =
    119 Changed: 
    120 only rely on the $_SERVER data to check for the IP address: 
     125Changed:
     126only rely on the $_SERVER data to check for the IP address:
    121127this solves the non reception of the IPN  (error 500)
    122128
    123129= 0.9.6.6 =
    124 Second release: 
    125 Fixed: 
     130Second release:
     131Fixed:
    126132-Missing table now created ok.
    127 -"Syntax error: Unexpected token < " message when checking out, 
     133-"Syntax error: Unexpected token < " message when checking out,
    128134-Use of deprecated functions to get pages url: now we use endpoints.
    129135
  • paybox-woocommerce-gateway/trunk/woocommerce-paybox.php

    r2298639 r2501160  
    33 * Plugin Name: WooCommerce Paybox Payment plugin
    44 * Description: Paybox gateway payment plugins for WooCommerce
    5  * Version: 0.9.9
     5 * Version: 0.9.9.2
    66 * Author: Paybox Verifone
    77 * Author URI: http://www.paybox.com
    88 * Text Domain: woocommerce-paybox
    9  * 
     9 *
    1010 * @package WordPress
    1111 * @since 0.9.0
    1212 */
     13
    1314// Ensure not called directly
    1415if (!defined('ABSPATH')) {
    15     exit;
     16    exit;
    1617}
    1718
    18 function isWoocommerceActive(){
    19         // Makes sure the plugin is defined before trying to use it
    20         if ( !class_exists( 'WC_Payment_Gateway' ) ) {
    21             return false;
    22         }
    23         return true;
     19function isWoocommerceActive()
     20{
     21    // Makes sure the plugin is defined before trying to use it
     22    if (!class_exists('WC_Payment_Gateway')) {
     23        return false;
     24    }
     25    return true;
    2426}
    2527
    26 
    2728// Ensure WooCommerce is active
    28 
    29 
    3029define('WC_PAYBOX_PLUGIN', 'woocommerce-paybox');
    31 define('WC_PAYBOX_VERSION', '0.9.9');
     30define('WC_PAYBOX_VERSION', '0.9.9.2');
    3231define('WC_PAYBOX_KEY_PATH', ABSPATH . '/kek.php');
    3332
     33function woocommerce_paybox_installation()
     34{
     35    global $wpdb;
     36    $installed_ver = get_option("WC_PAYBOX_PLUGIN.'_version'");
    3437
    35 function woocommerce_paybox_installation() {
    36     global $wpdb;
    37     $installed_ver = get_option( "WC_PAYBOX_PLUGIN.'_version'" );
    38    
    39     include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
    40     if(!isWoocommerceActive()) {
    41         _e('WooCommerce must be activated', WC_PAYBOX_PLUGIN);
    42         die();
    43     }
     38    include_once(ABSPATH . 'wp-admin/includes/plugin.php');
     39    if (!isWoocommerceActive()) {
     40        _e('WooCommerce must be activated', WC_PAYBOX_PLUGIN);
     41        die();
     42    }
    4443
    45     if ( $installed_ver != WC_PAYBOX_VERSION ) {
    46         $tableName = $wpdb->prefix.'wc_paybox_payment';
    47         $sql = "CREATE TABLE $tableName (
    48             id int not null auto_increment,
    49             order_id bigint not null,
    50             type enum('capture', 'first_payment', 'second_payment', 'third_payment') not null,
    51             data varchar(2048) not null,
    52             KEY order_id (order_id),
    53             PRIMARY KEY  (id))";
     44    if ($installed_ver != WC_PAYBOX_VERSION) {
     45        $tableName = $wpdb->prefix.'wc_paybox_payment';
     46        $sql = "CREATE TABLE $tableName (
     47            id int not null auto_increment,
     48            order_id bigint not null,
     49            type enum('capture', 'first_payment', 'second_payment', 'third_payment') not null,
     50            data varchar(2048) not null,
     51            KEY order_id (order_id),
     52            PRIMARY KEY  (id))";
    5453
    55         require_once(ABSPATH.'wp-admin/includes/upgrade.php');
     54        require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    5655
    57         dbDelta( $sql );
     56        dbDelta($sql);
    5857
    59         update_option(WC_PAYBOX_PLUGIN.'_version', WC_PAYBOX_VERSION);
    60     }
    61    
     58        update_option(WC_PAYBOX_PLUGIN . '_version', WC_PAYBOX_VERSION);
     59    }
    6260}
    63 function woocommerce_paybox_initialization() {
    64     if(!isWoocommerceActive()){
    65         return ("Woocommerce not Active") ;
    66     }
    67     $class = 'WC_Paybox_Abstract_Gateway';
    6861
    69     if (!class_exists($class)) {
    70         require_once(dirname(__FILE__).'/class/wc-paybox-config.php');
    71         require_once(dirname(__FILE__).'/class/wc-paybox-iso4217currency.php');
    72         require_once(dirname(__FILE__).'/class/wc-paybox.php');
    73         require_once(dirname(__FILE__).'/class/wc-paybox-abstract-gateway.php');
    74         require_once(dirname(__FILE__).'/class/wc-paybox-standard-gateway.php');
    75         require_once(dirname(__FILE__).'/class/wc-paybox-threetime-gateway.php');
    76         require_once(dirname(__FILE__).'/class/wc-paybox-encrypt.php');
    77     }
     62function woocommerce_paybox_initialization()
     63{
     64    if (!isWoocommerceActive()) {
     65        return "Woocommerce not Active";
     66    }
     67    $class = 'WC_Paybox_Abstract_Gateway';
    7868
    79     load_plugin_textdomain(WC_PAYBOX_PLUGIN, false, dirname(plugin_basename(__FILE__)).'/lang/');
     69    if (!class_exists($class)) {
     70        require_once(dirname(__FILE__).'/class/wc-paybox-config.php');
     71        require_once(dirname(__FILE__).'/class/wc-paybox-iso4217currency.php');
     72        require_once(dirname(__FILE__).'/class/wc-paybox-iso3166-country.php');
     73        require_once(dirname(__FILE__).'/class/wc-paybox.php');
     74        require_once(dirname(__FILE__).'/class/wc-paybox-abstract-gateway.php');
     75        require_once(dirname(__FILE__).'/class/wc-paybox-standard-gateway.php');
     76        require_once(dirname(__FILE__).'/class/wc-paybox-threetime-gateway.php');
     77        require_once(dirname(__FILE__).'/class/wc-paybox-encrypt.php');
     78    }
    8079
    81     $crypto = new PayboxEncrypt();
    82     if(!file_exists(WC_PAYBOX_KEY_PATH))$crypto->generateKey();
    83    
    84     if ( get_site_option( WC_PAYBOX_PLUGIN.'_version' ) != WC_PAYBOX_VERSION ) {
     80    load_plugin_textdomain(WC_PAYBOX_PLUGIN, false, dirname(plugin_basename(__FILE__)).'/lang/');
     81
     82    $crypto = new PayboxEncrypt();
     83    if (!file_exists(WC_PAYBOX_KEY_PATH)) {
     84        $crypto->generateKey();
     85    }
     86
     87    if (get_site_option(WC_PAYBOX_PLUGIN . '_version') != WC_PAYBOX_VERSION) {
    8588        woocommerce_paybox_installation();
    8689    }
    8790}
    8891
    89 function woocommerce_paybox_register(array $methods) {
    90     $methods[] = 'WC_PbxStdGw';
    91     $methods[] = 'WC_Pbx3xGw';
    92     $methods[] = 'WC_Paybox_Threetime_Gateway';
    93     return $methods;
     92function woocommerce_paybox_register(array $methods)
     93{
     94    $methods[] = 'WC_PbxStdGw';
     95    $methods[] = 'WC_Pbx3xGw';
     96    $methods[] = 'WC_Paybox_Threetime_Gateway';
     97    return $methods;
    9498}
    9599
     
    98102add_filter('woocommerce_payment_gateways', 'woocommerce_paybox_register');
    99103
    100 function woocommerce_paybox_show_details(WC_Order $order) {
    101     $method = get_post_meta($order->get_id(), '_payment_method', true);
    102     switch ($method) {
    103         case 'paybox_std':
    104             $method = new WC_PbxStdGw();
    105             $method->showDetails($order);
    106             break;
    107         case 'paybox_3x':
    108             $method = new WC_Pbx3xGw();
    109             $method->showDetails($order);
    110             break;
    111     }
     104function woocommerce_paybox_show_details(WC_Order $order)
     105{
     106    $method = get_post_meta($order->get_id(), '_payment_method', true);
     107    switch ($method) {
     108        case 'paybox_std':
     109            $method = new WC_PbxStdGw();
     110            $method->showDetails($order);
     111            break;
     112        case 'paybox_3x':
     113            $method = new WC_Pbx3xGw();
     114            $method->showDetails($order);
     115            break;
     116    }
    112117}
    113118
    114119add_action('woocommerce_admin_order_data_after_billing_address', 'woocommerce_paybox_show_details');
    115120
    116 
    117 function Pbx_hmac_admin_notice(){
    118    
    119     if(isWoocommerceActive()){
    120         $temp = new WC_PbxStdGw();
    121         $plugin_data = get_plugin_data( __FILE__ );
    122         $plugin_name = $plugin_data['Name'];
    123         if ( !$temp->checkCrypto() ) {
    124         echo "<div class='notice notice-error  is-dismissible'>
    125               <p><strong>/!\ Attention ! plugin ".$plugin_name." : </strong>".__('HMAC key cannot be decrypted please re-enter or reinitialise it.', WC_PAYBOX_PLUGIN)."</p>
    126              </div>";
    127         }
    128     }else{
    129         echo "<div class='notice notice-error  is-dismissible'>
    130               <p><strong>/!\ Attention ! plugin Paybox : </strong>".__('Woocommerce is not active !.', 'woocommerce-paybox')."</p>
    131              </div>";
    132        
    133     }
    134 
     121function Pbx_hmac_admin_notice()
     122{
     123    if (isWoocommerceActive()) {
     124        $temp = new WC_PbxStdGw();
     125        $plugin_data = get_plugin_data(__FILE__);
     126        $plugin_name = $plugin_data['Name'];
     127        if (!$temp->checkCrypto()) {
     128            echo "<div class='notice notice-error  is-dismissible'>
     129                <p><strong>/!\ Attention ! plugin ".$plugin_name." : </strong>".__('HMAC key cannot be decrypted please re-enter or reinitialise it.', WC_PAYBOX_PLUGIN)."</p>
     130                </div>";
     131        }
     132    } else {
     133        echo "<div class='notice notice-error  is-dismissible'>
     134              <p><strong>/!\ Attention ! plugin Paybox : </strong>".__('Woocommerce is not active !', 'woocommerce-paybox')."</p>
     135             </div>";
     136    }
    135137}
    136138add_action('admin_notices', 'Pbx_hmac_admin_notice');
Note: See TracChangeset for help on using the changeset viewer.