protected function setUp()
 {
     $this->_configuration = new Payplug('abc', 'cba', true);
     Payplug::setDefaultConfiguration($this->_configuration);
     $this->_requestMock = $this->getMock('\\Payplug\\Core\\IHttpRequest');
     Core\HttpClient::$REQUEST_HANDLER = $this->_requestMock;
 }
Exemple #2
0
 public function __construct($headers = null, $body = null)
 {
     $config = Payplug::getConfig();
     if (is_null($config)) {
         throw new ParametersNotSetException();
     }
     if (is_null($body)) {
         $body = file_get_contents("php://input");
     }
     if (is_null($headers)) {
         $headers = getallheaders();
     }
     $headers = array_change_key_case($headers, CASE_UPPER);
     $signature = base64_decode($headers['PAYPLUG-SIGNATURE']);
     $publicKey = openssl_pkey_get_public($config->payplugPublicKey);
     $isValid = openssl_verify($body, $signature, $publicKey, OPENSSL_ALGO_SHA1);
     if (!$isValid) {
         throw new InvalidSignatureException();
     }
     $data = json_decode($body, true);
     $this->amount = $data['amount'];
     $this->customData = $data['custom_data'];
     $this->customer = $data['customer'];
     $this->email = $data['email'];
     $this->firstName = $data['first_name'];
     $this->idTransaction = $data['id_transaction'];
     $this->lastName = $data['last_name'];
     $this->order = $data['order'];
     $this->origin = $data['origin'];
     $this->state = $data['state'];
 }
Exemple #3
0
 public static function generateUrl($params)
 {
     $config = Payplug::getConfig();
     $data;
     $signature;
     if (!$config) {
         throw new ParametersNotSetException();
     }
     if (!isset($params['amount'])) {
         throw new MissingRequiredParameterException("Missing required parameter: amount");
     }
     if (!isset($params['currency'])) {
         throw new MissingRequiredParameterException("Missing required parameter: currency");
     }
     if (!isset($params['ipnUrl'])) {
         throw new MissingRequiredParameterException("Missing required parameter: ipnUrl");
     }
     if (!preg_match("/^(http|https):\\/\\//i", $params['ipnUrl'])) {
         throw new MalformedURLException($params['ipnUrl'] . " doesn't starts with 'http://' or 'https://'");
     }
     if ($params['returnUrl'] != null && !preg_match("/^(http|https):\\/\\//i", $params['returnUrl'])) {
         throw new MalformedURLException($params['returnUrl'] . " doesn't starts with 'http://' or 'https://'");
     }
     $url_params = http_build_query(array("amount" => $params['amount'], "currency" => $params['currency'], "custom_data" => $params['customData'], "customer" => $params['customer'], "email" => $params['email'], "first_name" => $params['firstName'], "ipn_url" => $params['ipnUrl'], "last_name" => $params['lastName'], "order" => $params['order'], "origin" => $params['origin'] . " payplug-php" . Payplug::VERSION . " PHP" . phpversion(), "return_url" => $params['returnUrl']));
     $data = urlencode(base64_encode($url_params));
     $privateKey = openssl_pkey_get_private($config->privateKey);
     openssl_sign($url_params, $signature, $privateKey, OPENSSL_ALGO_SHA1);
     $signature = urlencode(base64_encode($signature));
     return $config->paymentBaseUrl . "?data=" . $data . "&sign=" . $signature;
 }
Exemple #4
0
function upgrade_module_0_9_7($module)
{
    // Add test status && add hook
    Configuration::deleteByName('PAYPLUG_ORDER_STATE_REFUND');
    Payplug::updateConfiguration('PAYPLUG_SANDBOX', '0');
    $install = new InstallPayplug();
    $install->createOrderState();
    $module->registerHook('header');
    $install->installPayplugLock();
    return true;
    // Return true if success.
}
Exemple #5
0
function upgrade_module_1_1_0($module)
{
    // Update OS PayPlug payment
    if (defined('_PS_OS_ERROR_') || Configuration::get('PS_OS_ERROR')) {
        // If is in configuration (since 1.5)
        if ($os = Configuration::get('PS_OS_ERROR')) {
            $os_payment = $os;
        } else {
            $os_payment = constant('_PS_OS_ERROR_');
        }
        Payplug::updateConfiguration('PAYPLUG_ORDER_STATE_ERROR', (int) $os_payment);
    }
    return true;
    // Return true if success.
}
Exemple #6
0
 public function getContent()
 {
     // if ps version is not available
     if (version_compare(_PS_VERSION_, '1.4', '<')) {
         return;
     }
     // Link base
     if (version_compare(_PS_VERSION_, '1.5', '>')) {
         $this->_link = 'index.php?controller=' . Tools::getValue('controller');
     } else {
         $this->_link = 'index.php?tab=' . Tools::getValue('tab');
     }
     $this->_link .= '&configure=' . $this->name . '&token=' . Tools::getValue('token') . '&tab_module=' . $this->tab . '&module_name=' . $this->name;
     $display_form = true;
     // Check extensions
     $curl_exists = extension_loaded('curl');
     $openssl_exists = extension_loaded('openssl');
     $errors = array();
     // Add msg if extension not exists
     if (!$curl_exists || !$openssl_exists) {
         // cURL not found
         if (!$curl_exists) {
             $errors[] = sprintf($this->l('Connection error: %s library is missing. Please ask your hosting provider to install the %s library on your server, and try configuring the PayPlug module on Prestashop again.'), 'cURL', 'cURL');
         }
         // OpenSSL not found
         if (!$openssl_exists) {
             $errors[] = sprintf($this->l('Connection error: %s library is missing. Please ask your hosting provider to install the %s library on your server, and try configuring the PayPlug module on Prestashop again.'), 'OpenSSL', 'OpenSSL');
         }
     }
     // Check if form was sent
     if (Tools::getValue('payplug_email') && Tools::getValue('payplug_password')) {
         $this->assignForVersion('email', Tools::getValue('payplug_email'));
         // if extensions exist
         if ($curl_exists && $openssl_exists) {
             $sandbox_button = Tools::isSubmit('sandboxButton');
             // Get url to curl
             $url = $sandbox_button ? Payplug::URL_TEST_AUTOCONFIG : Payplug::URL_AUTOCONFIG;
             $curl_version = curl_version();
             $process = curl_init($url);
             curl_setopt($process, CURLOPT_USERPWD, Tools::getValue('payplug_email') . ':' . Tools::getValue('payplug_password'));
             curl_setopt($process, CURLOPT_RETURNTRANSFER, true);
             // CURL const are in uppercase
             curl_setopt($process, CURLOPT_SSL_VERIFYPEER, true);
             # >= 7.26 to 7.28.1 add a notice message for value 1 will be remove
             curl_setopt($process, CURLOPT_SSL_VERIFYHOST, version_compare($curl_version['version'], '7.21', '<') ? true : 2);
             curl_setopt($process, CURLOPT_CAINFO, realpath(dirname(__FILE__) . '/cacert.pem'));
             //work only wiht cURL 7.10+
             $answer = curl_exec($process);
             $error_curl = curl_errno($process);
             curl_close($process);
             // if no error
             if ($error_curl == 0) {
                 $json_answer = Tools::jsonDecode($answer);
                 // if account is just in test mod
                 if ($json_answer->status == 403) {
                     $errors[] = sprintf($this->l('To set up the module in LIVE mode, you first need %s to request your account to be activated %s.'), '<a href="http://support.payplug.fr/customer/portal/articles/1438899-comment-activer-mon-compte-">', '</a>');
                 } else {
                     if ($json_answer->status == 200) {
                         $payplug_install = new InstallPayplug();
                         if (!is_array($json_answer->currencies)) {
                             $currencies = implode(Tools::jsonDecode($json_answer->currencies), ';');
                         } else {
                             $currencies = $json_answer->currencies[0];
                         }
                         $private_key = $json_answer->yourPrivateKey;
                         $public_key = $json_answer->payplugPublicKey;
                         // explode for validator
                         $payplug_install->updateConfig($private_key, $public_key, $json_answer->url, $json_answer->amount_min, $json_answer->amount_max, $currencies, (string) (int) $sandbox_button);
                         $display_form = false;
                         // redirect for update message
                         Tools::redirectAdmin($this->_link . '&conf=4');
                     } else {
                         $errors[] = $this->l('Your email or password is incorrect.');
                     }
                 }
             } else {
                 $errors[] = $error_curl;
             }
         }
     } else {
         if (Tools::getIsset('debug_mode')) {
             self::updateConfiguration('PAYPLUG_DEBUG', !self::getConfiguration('PAYPLUG_DEBUG'));
             Tools::redirectAdmin($this->_link . '&conf=4');
         }
     }
     if (Configuration::get('PAYPLUG_MODULE_KEY') != '' && Configuration::get('PAYPLUG_MODULE_PUBLIC_KEY') != '' && Configuration::get('PAYPLUG_MODULE_URL') != '' && Configuration::get('PAYPLUG_MODULE_MIN_AMOUNT') != '' && Configuration::get('PAYPLUG_MODULE_MAX_AMOUNT') != '' && Configuration::get('PAYPLUG_MODULE_CURRENCIES') != '') {
         $this->assignForVersion(array('moduleInstalled' => true, 'minAmount' => Configuration::get('PAYPLUG_MODULE_MIN_AMOUNT'), 'maxAmount' => Configuration::get('PAYPLUG_MODULE_MAX_AMOUNT'), 'currencies' => Configuration::get('PAYPLUG_MODULE_CURRENCIES'), 'sandboxMode' => Payplug::getConfiguration('PAYPLUG_SANDBOX'), 'debugMode' => Payplug::getConfiguration('PAYPLUG_DEBUG')));
     }
     // Assign datas
     $datas = array('this_path' => $this->_path, 'displayForm' => $display_form, 'errors' => $errors, 'this_link' => $this->_link);
     $this->assignForVersion($datas);
     return $this->display(__FILE__, './views/templates/admin/admin.tpl');
 }
Exemple #7
0
                        if (version_compare(_PS_VERSION_, '1.5', '>') && version_compare(_PS_VERSION_, '1.5.2', '<')) {
                            $order_id = Order::getOrderByCartId($cart->id);
                            $order = new Order($order_id);
                            $order_payment = end($order->getOrderPayments());
                            $order_payment->transaction_id = $extra_vars['transaction_id'];
                            $order_payment->update();
                        }
                    }
                    PayplugLock::deleteLock($cart->id);
                }
                Configuration::updateValue('PAYPLUG_CONFIGURATION_OK', true);
            } else {
                echo 'Error : missing or wrong parameters.';
                header($_SERVER['SERVER_PROTOCOL'] . ' 400 Missing or wrong parameters for address', true, 400);
                die;
            }
        } else {
            echo 'Error : missing or wrong parameters.';
            header($_SERVER['SERVER_PROTOCOL'] . ' 400 Missing or wrong parameters for cart', true, 400);
            die;
        }
    } else {
        echo 'Error : missing or wrong parameters.';
        header($_SERVER['SERVER_PROTOCOL'] . ' 400 Missing or wrong parameters', true, 400);
        die;
    }
}
/** Restore display errors configuration */
if (Payplug::getConfiguration('PAYPLUG_DEBUG')) {
    @ini_set('display_errors', $display_errors);
}
 /**
  * Create order
  * @param  string  $key  OS Key
  * @param  boolean $test if os test
  */
 private function createOrderStateSpecifc($key, $test = false)
 {
     // Logo source
     $source = dirname(__FILE__) . '/logo.gif';
     // If is an OS test
     if ($test == true) {
         $key .= '_test';
     }
     // Configuration key
     $key_config = 'PAYPLUG_ORDER_STATE_' . Tools::strtoupper($key);
     // If configuration not exists
     if (!($os = Payplug::getConfiguration($key_config))) {
         // New state
         $order_state = new OrderState();
         // Init state
         $this->initOrderState($order_state, Tools::strtolower($key));
         // Add state
         if ($order_state->add()) {
             // Change
             $destination = _PS_IMG_DIR_ . 'os/' . (int) $order_state->id . '.gif';
             copy($source, $destination);
         }
         // Update configuration
         Payplug::updateConfiguration($key_config, (int) $order_state->id);
     } else {
         // Get status
         $order_state = new OrderState($os);
         // Init status
         $this->initOrderState($order_state, Tools::strtolower($key));
         // Update status
         $order_state->update();
     }
 }
Exemple #9
0
 public static function setConfigFromFile($path)
 {
     self::$parameters = Parameters::loadFromFile($path);
 }
Exemple #10
0
if (!($ps = Tools::getValue('ps')) || $ps != 1) {
    Payplug::redirectForVersion('index.php?controller=order&step=1');
}
if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 || !$payplug->active) {
    Payplug::redirectForVersion('index.php?controller=order&step=1');
}
/**
 * Check that this payment option is still available in case the customer changed his address just before the end of the checkout process
 */
if (!Payplug::moduleIsActive()) {
    die($payplug->l('This payment method is not available.', 'validation'));
}
$customer = new Customer((int) $cart->id_customer);
if (!Validate::isLoadedObject($customer)) {
    Payplug::redirectForVersion('index.php?controller=order&step=1');
}
$total = (double) $cart->getOrderTotal(true, Cart::BOTH);
PayplugLock::check($cart->id);
$order_id = Order::getOrderByCartId($cart->id);
if (!$order_id) {
    PayplugLock::addLock($cart->id);
    /** Get the right order status following module configuration (Sandbox or not) */
    $order_state = Payplug::getOsConfiguration('waiting');
    $payplug->validateOrder($cart->id, $order_state, $total, $payplug->displayName, false, array(), (int) $currency->id, false, $customer->secure_key);
    PayplugLock::deleteLock($cart->id);
    $order_id = $payplug->currentOrder;
}
/** Change variable name, because $link is already instanciated */
$link_redirect = $order_confirmation_url . 'id_cart=' . $cart->id . '&id_module=' . $payplug->id . '&id_order=' . $order_id . '&key=' . $customer->secure_key;
Payplug::redirectForVersion($link_redirect);
Exemple #11
0
 public function testCanSetDefaultConfiguration()
 {
     $configuration = Payplug::setSecretKey('abc');
     Payplug::setDefaultConfiguration($configuration);
     $this->assertEquals($configuration, Payplug::getDefaultConfiguration());
 }
Exemple #12
0
}
/**
 *  Check amount
 */
$amount = $context->cart->getOrderTotal(true, Cart::BOTH) * 100;
if ($amount < Configuration::get('PAYPLUG_MODULE_MIN_AMOUNT') * 100 || $amount > Configuration::get('PAYPLUG_MODULE_MAX_AMOUNT') * 100) {
    return false;
}
/**
 *  Parameters for payment url
 */
$url_payment = Configuration::get('PAYPLUG_MODULE_URL');
if (Tools::getShopProtocol() == 'https://') {
    $baseurl = _PS_BASE_URL_SSL_;
} else {
    $baseurl = _PS_BASE_URL_;
}
$base_return_url = $baseurl . __PS_BASE_URI__ . 'modules/payplug/controllers/front/validation.php';
if (version_compare(_PS_VERSION_, '1.5', '<')) {
    $customer = new Customer($context->cookie->id_customer);
} else {
    $customer = $context->customer;
}
$params = array('amount' => $amount, 'custom_data' => $context->cart->id, 'origin' => 'Prestashop ' . _PS_VERSION_ . ' module ' . $payplug->version, 'currency' => $result_currency['iso_code'], 'ipn_url' => $baseurl . __PS_BASE_URI__ . 'modules/payplug/ipn.php', 'cancel_url' => $base_return_url . '?ps=2&cartid=' . $context->cart->id, 'return_url' => $base_return_url . '?ps=1&cartid=' . $context->cart->id, 'email' => $customer->email, 'firstname' => $customer->firstname, 'lastname' => $customer->lastname, 'order' => $context->cart->id, 'customer' => $customer->id);
$url_params = http_build_query($params);
$privatekey = Configuration::get('PAYPLUG_MODULE_KEY');
openssl_sign($url_params, $signature, $privatekey, $signature_alg = OPENSSL_ALGO_SHA1);
$url_param_base_encode = base64_encode($url_params);
$signature = base64_encode($signature);
Payplug::redirectForVersion($url_payment . '?data=' . urlencode($url_param_base_encode) . '&sign=' . urlencode($signature));
Exemple #13
0
 function onPaymentConfigurationSave(&$element)
 {
     $app = JFactory::getApplication();
     if (empty($element->payment_params->email)) {
         $app->enqueueMessage(JText::sprintf('ENTER_INFO_REGISTER_IF_NEEDED', 'PayPlug', JText::_('HIKA_EMAIL'), 'PayPlug', 'http://www.payplug.fr'));
     } elseif (empty($element->payment_params->password)) {
         $app->enqueueMessage(JText::sprintf('ENTER_INFO_REGISTER_IF_NEEDED', 'PayPlug', JText::_('HIKA_PASSWORD'), 'PayPlug', 'http://www.payplug.fr'));
     } else {
         require_once dirname(__FILE__) . '/lib/payplug.php';
         try {
             $parameters = Payplug::loadParameters($element->payment_params->email, $element->payment_params->password);
             $parameters->saveInFile(HIKASHOP_MEDIA . "payplug_parameters.json");
         } catch (Exception $e) {
             $app->enqueueMessage($e->getMessage());
         }
     }
     return true;
 }