diff --git a/commerce_paybox.module b/commerce_paybox.module index 245cbef..a2f6be3 100644 --- a/commerce_paybox.module +++ b/commerce_paybox.module @@ -5,8 +5,11 @@ * Implements Paybox payment services for use with Drupal Commerce. */ +/** @deprecated Use commerce_paybox_get_available_hosts() */ define('PAYBOX_HOST_MAIN', 'tpeweb.paybox.com'); +/** @deprecated Use commerce_paybox_get_available_hosts() */ define('PAYBOX_HOST_BACKUP', 'tpeweb1.paybox.com'); +/** @deprecated Use commerce_paybox_get_available_hosts() */ define('PAYBOX_HOST_PREPROD', 'preprod-tpeweb.paybox.com'); define('PAYBOX_PATH_SERVICE_CLASSIC', '/cgi/MYchoix_pagepaiement.cgi'); @@ -26,6 +29,20 @@ define('PAYBOX_SANDBOX_URL_RWD', 'https://preprod-tpeweb.paybox.com/cgi/Framepag define('PAYBOX_DIRECT_URL', 'https://ppps.paybox.com/PPPS.php'); define('PAYBOX_DIRECT_SANDBOX_URL', 'https://preprod-ppps.paybox.com/PPPS.php'); +/** + * Returns the list of available hosts. + * + * @param boolean $preprod + * @return array + */ +function commerce_paybox_get_available_hosts($preprod = false) { + $domain = variable_get('commerce_paybox_domain', 'paybox.com'); + if ($preprod) { + return array('preprod-tpeweb.' . $domain); + } + return array('tpeweb.' . $domain, 'tpeweb1.' . $domain); +} + /** * Returns the first available url to send to. * @@ -407,7 +424,7 @@ function commerce_paybox_offsite_redirect_form($form, &$form_state, $order, $pay '#value' => t('Pay with Paybox'), ); - $hosts = $settings['pbx_sandbox'] ? array(PAYBOX_HOST_PREPROD) : array(PAYBOX_HOST_MAIN, PAYBOX_HOST_BACKUP); + $hosts = commerce_paybox_get_available_hosts($settings['pbx_sandbox']); if ($url = commerce_paybox_get_available_url($hosts, $settings['pbx_form_url'])) { $form['#action'] = $url; } diff --git a/includes/commerce_paybox.admin.inc b/includes/commerce_paybox.admin.inc index 7b4461a..6f3299d 100644 --- a/includes/commerce_paybox.admin.inc +++ b/includes/commerce_paybox.admin.inc @@ -101,6 +101,17 @@ function commerce_paybox_settings($form, &$form_state) { '#default_value' => variable_get('commerce_paybox_use_order_number', FALSE), ); + $form['commerce_paybox_domain'] = array( + '#type' => 'select', + '#title' => t('Paybox payment domain'), + '#options' => array( + 'paybox.com' => t('Paybox'), + 'e-transactions.fr' => t('Up2pay E-Transactions'), + ), + '#description' => t('Choose Paybox unless you use a white label service.'), + '#default_value' => variable_get('commerce_paybox_domain', 'paybox.com'), + ); + $paybox_servers = variable_get('commerce_paybox_paybox_servers', array()); $form['commerce_paybox_paybox_servers'] = array( '#type' => 'textarea', diff --git a/tests/commerce_paybox.test b/tests/commerce_paybox.test index bb2a4b4..be7da7f 100644 --- a/tests/commerce_paybox.test +++ b/tests/commerce_paybox.test @@ -87,13 +87,15 @@ class CommercePayboxTestCase extends DrupalWebTestCase { * 99.99% the case! */ function testVerifyServer() { + $hosts = commerce_paybox_get_available_hosts(); $this->assertEqual( - commerce_paybox_get_available_url(array(PAYBOX_HOST_MAIN, PAYBOX_HOST_BACKUP), 'random'), - 'https://' . PAYBOX_HOST_MAIN . PAYBOX_PATH_SERVICE_NEW + commerce_paybox_get_available_url($hosts, 'random'), + 'https://' . $hosts[0] . PAYBOX_PATH_SERVICE_NEW ); + $hosts = commerce_paybox_get_available_hosts(); $this->assertEqual( - commerce_paybox_get_available_url(array(PAYBOX_HOST_PREPROD), 'classic'), - 'https://' . PAYBOX_HOST_PREPROD . PAYBOX_PATH_SERVICE_CLASSIC + commerce_paybox_get_available_url($hosts, 'classic'), + 'https://' . $hosts[0] . PAYBOX_PATH_SERVICE_CLASSIC ); }