bebeboutik/modules/paybox/direct_paiement.php

102 lines
3.3 KiB
PHP
Raw Normal View History

2016-07-15 17:49:13 +02:00
<?php
require_once(dirname(__FILE__).'/../../config/config.inc.php');
require_once(dirname(__FILE__).'/../../init.php');
require_once(dirname(__FILE__).'/paybox.php');
global $cart, $smarty;
$module = new Paybox();
$controller->preProcess();
if (!$cookie->isLogged())
Tools::redirect('authentication.php');
2016-07-18 11:45:18 +02:00
$id_paybox_card = Tools::getValue('id_paybox_card', false);
if ($id_paybox_card) {
$paybox_card = Db::getInstance()->getRow('
2016-07-15 17:49:13 +02:00
SELECT *
FROM `ps_paybox_customer_agreement`
2016-07-18 11:45:18 +02:00
WHERE `id_customer` = '.(int)$cart->id_customer.'
AND `id_paybox_card` = '.(int)$id_paybox_card.'
2016-07-15 17:49:13 +02:00
');
2016-07-18 12:46:58 +02:00
if(empty($paybox_card) || (int)$paybox_card['id_customer']!=(int)$cart->id_customer) {
2016-07-18 11:45:18 +02:00
Tools::redirect('order.php?step=3&cgv=1&paybox_error=1');
2016-07-15 17:49:13 +02:00
}
2016-08-24 17:48:50 +02:00
} else {
Tools::redirect('order.php?step=3&cgv=1&paybox_error=1');
2016-07-15 17:49:13 +02:00
}
2016-08-24 17:48:50 +02:00
2016-07-15 17:49:13 +02:00
include(dirname(__FILE__).'/../../header.php');
if(Configuration::get('PBX_DEMO_MODE') == 0) {
$curl = curl_init('https://preprod-ppps.paybox.com/PPPS.php');
} else {
//$curl = curl_init('https://ppps.paybox.com/PPPS.php');
}
2016-08-24 17:48:50 +02:00
2016-07-15 17:49:13 +02:00
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_COOKIESESSION, true);
$pbx_site = trim(Configuration::get('PBX_SITE'));
$pbx_rang = trim(Configuration::get('PBX_RANG'));
$pbx_id = trim(Configuration::get('PBX_ID'));
$num_question = Configuration::get('NUM_QUESTION_PAYBOX') + 1;
Configuration::updateValue('NUM_QUESTION_PAYBOX', $num_question);
2016-08-24 17:48:50 +02:00
$montant = (int)sprintf('%010d', number_format(Tools::convertPrice($cart->getOrderTotal(), null, false), 2, '.', '') * 100);
$devise = 978;
$numbers = urldecode($paybox_card['handle']);
$dateval = $paybox_card['date'];
$customer = new Customer((int)$cart->id_customer);
2016-09-08 14:51:03 +02:00
$refabonne = $customer->email;
2016-07-15 17:49:13 +02:00
$postfields = array(
'VERSION' => '00104',
'TYPE' => '00053',
'SITE' => $pbx_site,
'RANG' => $pbx_rang,
'CLE' => 'EFNLJKFB',
'NUMQUESTION' => $num_question,
'MONTANT' => $montant,
'DEVISE' => $devise,
'REFERENCE' => (int)$cart->id,
2016-07-18 12:46:58 +02:00
'REFABONNE' => $refabonne,
2016-07-18 11:45:18 +02:00
'PORTEUR' => $numbers,
'DATEVAL' => $dateval,
'ACTIVITE' => '027',
/*'CVV' => Configuration::get('PBX_DEMO_MODE') == 0 ?'123':$cvv,*/
2016-07-15 17:49:13 +02:00
'DATEQ' => date('dmYHis')
);
2016-08-24 17:48:50 +02:00
2016-07-15 17:49:13 +02:00
$trame = http_build_query($postfields, '', '&');
2016-09-08 14:51:03 +02:00
mail('marion@antadis.com', '[BBB] Envoi trame paiement direct', $trame);
echo '<pre>';var_dump($trame);echo '</pre>';
2016-08-24 17:48:50 +02:00
2016-07-15 17:49:13 +02:00
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($curl, CURLOPT_POSTFIELDS, $trame);
$response = curl_exec($curl);
curl_close($curl);
2016-09-08 14:51:03 +02:00
echo '<pre>';var_dump($response);echo '</pre>';die();
2016-07-15 17:49:13 +02:00
$data = explode('&', $response);
$code_reponse = explode('CODEREPONSE=', $data[6]);
2016-09-08 14:51:03 +02:00
mail('marion@antadis.com', '[BBB] Paiement direct reponse globale', $data);
2016-07-15 17:49:13 +02:00
// payment success
if (Configuration::get('PBX_DEMO_MODE') == 0) {
2016-07-18 11:45:18 +02:00
if ($code_reponse[1] == "00000" || $code_reponse[0] == "00000") {
2016-07-15 17:49:13 +02:00
return true;
}
} else {
if ($code_reponse[1] == "00000" || $code_reponse[0] == "00000") {
return true;
} else {
2016-09-08 14:51:03 +02:00
mail('marion@antadis.com', '[BBB] Soucis paiement direct reponse globale', json_encode($response));
2016-07-15 17:49:13 +02:00
return false;
}
}