/** * returns API response array() */ public static function restApi($action = null, $data = null) { try { $hipay = new HiPay_Tpp(); HipayLogger::addLog($hipay->l('API call initiated', 'hipay'), HipayLogger::APICALL, 'Action : ' . $action . ' - Data : ' . Tools::jsonEncode($data)); if ($action == null) { Tools::redirect('index.php?controller=order&xer=6'); } if ($data == null) { Tools::redirect('index.php?controller=order&xer=7'); } define('API_ENDPOINT', HipayClass::getAPIURL()); define('API_USERNAME', HipayClass::getAPIUsername()); define('API_PASSWORD', HipayClass::getAPIPassword()); $credentials = API_USERNAME . ':' . API_PASSWORD; $resource = API_ENDPOINT . $action; // create a new cURL resource $curl = curl_init(); // set appropriate options $options = array(CURLOPT_URL => $resource, CURLOPT_USERPWD => $credentials, CURLOPT_HTTPHEADER => array('Accept: application/json'), CURLOPT_RETURNTRANSFER => true, CURLOPT_FAILONERROR => false, CURLOPT_HEADER => false, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $data, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false); foreach ($options as $option => $value) { curl_setopt($curl, $option, $value); } $result = curl_exec($curl); $status = (int) curl_getinfo($curl, CURLINFO_HTTP_CODE); $response = Tools::jsonDecode($result); // execute the given cURL session if (false === $result) { $errorCurl = curl_error($curl); throw new Exception('Curl error: ' . $errorCurl); } if (floor($status / 100) != 2) { throw new Exception('Hipay message: ' . $response->message, $response->code); } curl_close($curl); HipayLogger::addLog($hipay->l('API call success', 'hipay'), HipayLogger::APICALL, 'Appel vers API avec success : ' . Tools::jsonEncode($response)); return $response; } catch (Exception $e) { HipayLogger::addLog($hipay->l('API call error', 'hipay'), HipayLogger::ERROR, $e->getMessage()); return $e; } }
/** * returns API response array() */ public static function restMaintenanceApi($transaction_reference = null, $data = null) { try { $hipay = new HiPay_Tpp(); HipayLogger::addLog($hipay->l('API Refund call initiated', 'hipay'), HipayLogger::APICALL, 'Transaction_reference : ' . $transaction_reference . ' - Data : ' . Tools::jsonEncode($data)); if ($transaction_reference == null) { return 'Error - No transaction reference'; } if ($data == null) { return 'Error - No data'; } define('API_ENDPOINT', HipayClass::getAPIURL()); define('API_USERNAME', HipayClass::getAPIUsername()); define('API_PASSWORD', HipayClass::getAPIPassword()); $credentials = API_USERNAME . ':' . API_PASSWORD; $resource = API_ENDPOINT . 'maintenance/transaction/' . $transaction_reference; // create a new cURL resource $curl = curl_init(); // set appropriate options $options = array(CURLOPT_URL => $resource, CURLOPT_USERPWD => $credentials, CURLOPT_HTTPHEADER => array('Accept: application/json'), CURLOPT_RETURNTRANSFER => true, CURLOPT_FAILONERROR => false, CURLOPT_HEADER => false, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $data, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false); foreach ($options as $option => $value) { curl_setopt($curl, $option, $value); } $result = curl_exec($curl); $status = (int) curl_getinfo($curl, CURLINFO_HTTP_CODE); $response = Tools::jsonDecode($result); // execute the given cURL session if (false === $result) { throw new Exception(curl_error($curl)); } if (floor($status / 100) != 2) { throw new Exception('Err Msg : ' . $response->message . ', Err Desc : ' . $response->description . ', Err Code : ' . $response->code); } curl_close($curl); HipayLogger::addLog($hipay->l('API call success', 'hipay'), HipayLogger::APICALL, 'Appel vers API avec success : ' . mysql_real_escape_string(Tools::jsonEncode($response))); return $response; } catch (Exception $e) { HipayLogger::addLog($hipay->l('API call error', 'hipay'), HipayLogger::ERROR, mysql_real_escape_string($e->getMessage())); return false; } }
* International Registered Trademark & Property of Profileo */ require_once dirname(__FILE__) . '/../../../config/config.inc.php'; $str_ps_version = (int) str_replace('.', '', _PS_VERSION_); if ($str_ps_version < 1600) { // version 1.5 or 1.4 include_once dirname(__FILE__) . '/../../../init.php'; } else { // Version 1.6 or above include_once dirname(__FILE__) . '/../../../init.php'; } include_once dirname(__FILE__) . '/hipay_tpp.php'; try { $hipay = new HiPay_Tpp(); $content = Tools::jsonEncode($_POST); // Insert into order_history $log_state = $_POST['state'] ? $_POST['state'] : 'error'; // Sets to error if nothing is found $log_status = $_POST['status'] ? $_POST['status'] : 'error'; // Sets to error if nothing is found HipayLogger::addLog($hipay->l('Callback recieved', 'hipay'), HipayLogger::NOTICE, 'Callback recieved - cid : ' . (int) $_POST['order']['id'] . ' - state : ' . $log_state . ' - status : ' . $log_status . ' - content : ' . mysql_real_escape_string($content)); $sql_insert = "INSERT INTO `" . _DB_PREFIX_ . "hipay_callbacks` (`callback`) VALUES ('" . mysql_real_escape_string(pSQL($content)) . "');"; $insert = Db::getInstance()->execute($sql_insert); if ($insert) { echo 'Callback captured'; } else { echo 'Callback failed to be captured'; } } catch (Exception $e) { echo 'Callback failed : ' . $e->getMessage(); }
public static function createTables() { return HipayLogger::createLogTable() && HipayLogger::createTransactionTable() && HipayLogger::createTokenTable() && HipayLogger::createTokenTempTable() && HipayLogger::createCallbacksTable() && HipayLogger::createCartSentTable(); }
function hipayResetOrderStatus($cart = null) { echo '-fnROS'; if ($_POST['status'] == '117' || $_POST['status'] == '118') { $cart = new Cart((int) $_POST['order']->id); if ($cart->orderExists()) { $orderState = _PS_OS_PAYMENT_; if ($_POST['captured_amount'] < $_POST['authorized_amount']) { $orderState = Configuration::get('HIPAY_PARTIALLY_CAPTURED') ? Configuration::get('HIPAY_PARTIALLY_CAPTURED') : HipayClass::getConfiguration('HIPAY_PARTIALLY_CAPTURED'); } // FORCE INVOICE CREATION IF OrderState = _PS_OS_PAYMENT_ if ($orderState == _PS_OS_PAYMENT_) { $order_id = retrieveOrderId($cart->id); // Retrieve order id $order = new Order((int) $order_id); // Recreate order $newOS = new OrderState((int) $orderState, $order->id_lang); // Emulate the order state _PS_OS_PAYMENT_ // Uf the order state allows invoice and there is no invoice number, then generate the invoice if ($newOS->invoice and !$order->invoice_number) { $order->setInvoice(); } } } } // New modification for status challenged // Second check for status 112 -> 117 -> 118 if ($_POST['status'] == '117') { if ((bool) $order->getHistory($context->language->id, Configuration::get('HIPAY_CHALLENGED'))) { $cart = new Cart((int) $_POST['order']->id); if ($cart->orderExists()) { $orderState = _PS_OS_PAYMENT_; } if ($_POST['captured_amount'] < $_POST['authorized_amount']) { $orderState = Configuration::get('HIPAY_PARTIALLY_CAPTURED') ? Configuration::get('HIPAY_PARTIALLY_CAPTURED') : HipayClass::getConfiguration('HIPAY_PARTIALLY_CAPTURED'); } // FORCE INVOICE CREATION IF OrderState = _PS_OS_PAYMENT_ if ($orderState == _PS_OS_PAYMENT_) { $order_id = retrieveOrderId($cart->id); // Retrieve order id $order = new Order((int) $order_id); // Recreate order $newOS = new OrderState((int) $orderState, $order->id_lang); // Emulate the order state _PS_OS_PAYMENT_ // Uf the order state allows invoice and there is no invoice number, then generate the invoice if ($newOS->invoice and !$order->invoice_number) { $order->setInvoice(); } } } } // Update to minimize risk of simultaneous calls for status 116 and 117 if ($_POST['status'] == '116') { usleep(500000); // 0.5sec echo '/116'; // If order exists for cart $cart = new Cart((int) $_POST['order']->id); if ($cart->orderExists()) { echo '/C_OK' . $GLOBALS['_HIPAY_CALLBACK_ORDER_ID_']; $context = Context::getContext(); // Retrieve Order ID $order_id = retrieveOrderId($cart->id); $order = new Order((int) $order_id); echo '/' . (int) $order_id; // If current state is paiement accepted or capture partielle // then skip the process if ((bool) $order->getHistory($context->language->id, _PS_OS_PAYMENT_)) { echo '/' . (int) _PS_OS_PAYMENT_ . '_U'; // Update orders $sql_update = "UPDATE `" . _DB_PREFIX_ . "orders`\r\n SET `current_state` = '" . _PS_OS_PAYMENT_ . "'\r\n WHERE `id_order`='" . (int) $order_id . "'"; Db::getInstance()->execute($sql_update); // Insert into order_history $sql_insert = "INSERT INTO `" . _DB_PREFIX_ . "order_history` (`id_employee`, `id_order`, `id_order_state`, `date_add`)\r\n VALUES ('0', '" . (int) $order_id . "', '" . _PS_OS_PAYMENT_ . "', now());"; Db::getInstance()->execute($sql_insert); } if ((bool) $order->getHistory($context->language->id, Configuration::get('HIPAY_PARTIALLY_CAPTURED'))) { echo '/' . (int) Configuration::get('HIPAY_PARTIALLY_CAPTURED') . '_U'; // Update orders $sql_update = "UPDATE `" . _DB_PREFIX_ . "orders`\r\n SET `current_state` = '" . Configuration::get('HIPAY_PARTIALLY_CAPTURED') . "'\r\n WHERE `id_order`='" . (int) $order_id . "'"; Db::getInstance()->execute($sql_update); // Insert into order_history $sql_insert = "INSERT INTO `" . _DB_PREFIX_ . "order_history` (`id_employee`, `id_order`, `id_order_state`, `date_add`)\r\n VALUES ('0', '" . (int) $order_id . "', '" . Configuration::get('HIPAY_PARTIALLY_CAPTURED') . "', now());"; Db::getInstance()->execute($sql_insert); } HipayLogger::addLog($hipay->l('Callback process', 'hipay'), HipayLogger::NOTICE, 'hipayResetOrderStatus status 116 cart already ok - cid : ' . (int) $_POST['order']->id); die; } else { echo '/C_KO' . $GLOBALS['_HIPAY_CALLBACK_ORDER_ID_']; } } HipayLogger::addLog($hipay->l('Callback process', 'hipay'), HipayLogger::NOTICE, 'hipayResetOrderStatus ended - cid : ' . (int) $_POST['order']->id); die; }
private function _postProcess() { if (Tools::getValue('btnLocalCardsubmit')) { $localPayments = array(); foreach ($_POST as $key => $value) { if ($this->startsWith($key, 'local_card_selection_')) { $localPayments[] = $value; } } Configuration::updateValue('HIPAY_LOCAL_PAYMENTS', Tools::jsonEncode($localPayments)); $currencyCards = array(); foreach ($_POST as $key => $value) { if ($this->startsWith($key, 'currency_card_selection_')) { $currencyCards[] = $value; } } Configuration::updateValue('HIPAY_CURRENCY_CARDS', Tools::jsonEncode($currencyCards)); } if (Tools::isSubmit('btnSubmit')) { Configuration::updateValue('HIPAY_API_USERNAME', Tools::getValue('HIPAY_API_USERNAME')); Configuration::updateValue('HIPAY_API_PASSWORD', Tools::getValue('HIPAY_API_PASSWORD')); Configuration::updateValue('HIPAY_TEST_API_USERNAME', Tools::getValue('HIPAY_TEST_API_USERNAME')); Configuration::updateValue('HIPAY_TEST_API_PASSWORD', Tools::getValue('HIPAY_TEST_API_PASSWORD')); Configuration::updateValue('HIPAY_TEST_MODE', Tools::getValue('HIPAY_TEST_MODE')); Configuration::updateValue('HIPAY_THREEDSECURE', Tools::getValue('HIPAY_THREEDSECURE')); // Modification to save the amount of 3D Secure $str = Tools::getValue('HIPAY_THREEDSECURE_AMOUNT'); $str = str_replace(",", ".", $str); Configuration::updateValue('HIPAY_THREEDSECURE_AMOUNT', $str); Configuration::updateValue('HIPAY_MANUALCAPTURE', Tools::getValue('HIPAY_MANUALCAPTURE')); Configuration::updateValue('HIPAY_MEMORIZE', Tools::getValue('HIPAY_MEMORIZE')); Configuration::updateValue('HIPAY_PAYMENT_MODE', Tools::getValue('HIPAY_PAYMENT_MODE')); Configuration::updateValue('HIPAY_CHALLENGE_URL', Tools::getValue('HIPAY_CHALLENGE_URL')); Configuration::updateValue('HIPAY_CSS_URL', Tools::getValue('HIPAY_CSS_URL')); Configuration::updateValue('HIPAY_TEMPLATE_MODE', Tools::getValue('HIPAY_TEMPLATE_MODE')); Configuration::updateValue('HIPAY_SELECTOR_MODE', Tools::getValue('HIPAY_SELECTOR_MODE')); Configuration::updateValue('HIPAY_IFRAME_WIDTH', Tools::getValue('HIPAY_IFRAME_WIDTH')); Configuration::updateValue('HIPAY_IFRAME_HEIGHT', Tools::getValue('HIPAY_IFRAME_HEIGHT')); // Processing cards $card_arr = array(); if (Tools::getValue('card_selection_visa')) { $card_arr[0] = Tools::getValue('card_selection_visa'); } if (Tools::getValue('card_selection_mastercard')) { $card_arr[1] = Tools::getValue('card_selection_mastercard'); } if (Tools::getValue('card_selection_maestro')) { $card_arr[2] = Tools::getValue('card_selection_maestro'); } if (Tools::getValue('card_selection_cb')) { $card_arr[3] = Tools::getValue('card_selection_cb'); } if (Tools::getValue('card_selection_american-express')) { $card_arr[5] = Tools::getValue('card_selection_american-express'); } if (Tools::getValue('card_selection_bcmc')) { $card_arr[4] = Tools::getValue('card_selection_bcmc'); } $card_str = implode(',', $card_arr); Configuration::updateValue('HIPAY_ALLOWED_CARDS', $card_str); } HipayLogger::addLog($this->l('Hipay BO updated'), HipayLogger::NOTICE, 'The HiPay backoffice params have been updated'); $this->_html .= $this->displayConfirmation($this->l('Settings updated')); }
public static function saveToken($cardtoken = null, $cart = null) { $customer_id = $cart->id_customer; $token = $cardtoken->token; $brand = $cardtoken->brand; $pan = $cardtoken->pan; $card_holder = $cardtoken->card_holder; $card_expiry_month = $cardtoken->card_expiry_month; $card_expiry_year = $cardtoken->card_expiry_year; $issuer = $cardtoken->issuer; $country = $cardtoken->country; $sql = "SELECT * FROM `" . _DB_PREFIX_ . "hipay_tokens`\r\n WHERE `customer_id`='" . $customer_id . "'\r\n AND `token`='" . $token . "'"; HipayLogger::addLog('SQL', HipayLogger::APICALL, $sql); $result = Db::getInstance()->getRow($sql); if ($result['id']) { return true; // 'Already exists record for order_id'; } else { // 'insert in DB'; $sql_insert = "INSERT INTO `" . _DB_PREFIX_ . "hipay_tokens` (`customer_id`, `token`, `brand`, `pan`, `card_holder`, `card_expiry_month`, `card_expiry_year`, `issuer`, `country`)\r\n VALUES('" . $customer_id . "', '" . $token . "', '" . $brand . "', '" . $pan . "', '" . $card_holder . "', '" . $card_expiry_month . "', '" . $card_expiry_year . "', '" . $issuer . "', '" . $country . "')"; return Db::getInstance()->execute($sql_insert); } }
function createOrderByHipay($order_exist, $callback_arr, $hipay, $cart, $statut, $order = false) { $bool = false; //LOG HipayLog('--------------- Début createOrderByHipay'); if (!$order_exist) { //LOG HipayLog('--------------- pas de commande existante'); // init message pour création de commande $message = $hipay->l('HiPay - Callback initiated') . "<br>"; $message .= ' - ' . $hipay->l('Transaction_reference : ') . $callback_arr['transaction_reference'] . "<br>"; $message .= ' - ' . $hipay->l('State : ') . $callback_arr['state'] . "<br>"; $message .= ' - ' . $hipay->l('Status : ') . $callback_arr['status'] . "<br>"; $message .= ' - ' . $hipay->l('Message : ') . $callback_arr['message'] . "<br>"; $message .= ' - ' . $hipay->l('Amount : ') . $callback_arr['authorized_amount'] . "<br>"; $message = strip_tags($message, '<br>'); //LOG 2 HipayLog('--------------- MESSAGE = ' . $message); // init order_payement $orderPayment = array('transaction_id' => $callback_arr['transaction_reference'], 'card_number' => $callback_arr['payment_method']['pan'], 'card_brand' => $callback_arr['payment_method']['brand'], 'card_expiration' => $callback_arr['payment_method']['card_expiry_month'] . '/' . $callback_arr['payment_method']['card_expiry_year'], 'card_holder' => $callback_arr['payment_method']['card_holder']); // création de la commande sur le statut authorized // car pas de commande $tmpshop = new Shop((int) $cart->id_shop); //LOG HipayLog('--------------- SHOP Id = ' . $cart->id_shop); HipayLog('--------------- Début validateOrder '); try { $hipay->validateOrder($cart->id, $statut, (double) $callback_arr['authorized_amount'], $hipay->displayName . ' via ' . ucfirst($callback_arr['payment_product']), $message, $orderPayment, NULL, false, $cart->secure_key, $tmpshop); } catch (Exception $e) { // on catch mais on continue le traitement HipayLog($e->getCode() . ' : ' . $e->getMessage()); } HipayLog('--------------- Fin validateOrder '); // init order for message HIPAY_CAPTURE $id_order = $hipay->currentOrder; // LOG HipayLog('--------------- ID Current Order = ' . $id_order); // Init / MAJ de la ligne message HIPAY_CAPTURE addHipayCaptureMessage($callback_arr, $id_order); $new_order = new order($id_order); // MAJ ligne transaction pour le status 116 if ($callback_arr['status'] == HIPAY_STATUS_AUTHORIZED) { // LOG HipayLog('--------------- STATUS 116 début update order payment'); $sql = "UPDATE `" . _DB_PREFIX_ . "order_payment` SET \n\t\t\t\t\t\t`amount` = '" . $callback_arr['captured_amount'] . "'\n WHERE `order_reference`='" . $new_order->reference . "'"; Db::getInstance()->execute($sql); // LOG HipayLog('--------------- STATUS 116 fin update order payment'); } // transaction table Hipay $sql = "\n \t\tINSERT INTO `" . _DB_PREFIX_ . "hipay_transactions`\n (`cart_id`,`order_id`,`customer_id`,`transaction_reference`,`device_id`,`ip_address`,`ip_country`,`token`) VALUES \n ('" . (int) $cart->id . "',\n \t'" . (int) $id_order . "',\n \t'" . (int) $new_order->id_customer . "',\n \t'" . pSQL($callback_arr['transaction_reference']) . "',\n \t'',\n \t'" . pSQL($callback_arr['ip_address']) . "',\n \t'" . pSQL($callback_arr['ip_country']) . "',\n \t'" . pSQL($callback_arr['payment_method']['token']) . "');"; // LOG HipayLog('--------------- TABLE HIPAY = ' . $sql); if (!Db::getInstance()->execute($sql)) { //LOG HipayLog('Insert table HiPay en erreur'); return false; } // Check if card is either an Americain-express, CB, Mastercard et Visa card. if ($callback_arr['payment_product'] == 'american-express' || $callback_arr['payment_product'] == 'cb' || $callback_arr['payment_product'] == 'visa' || $callback_arr['payment_product'] == 'mastercard') { // Memorize new card only if card used can be "recurring" // LOG $customer_id = $new_order->id_customer; $token = $callback_arr['payment_method']['token']; $brand = $callback_arr['payment_method']['brand']; $pan = $callback_arr['payment_method']['pan']; $card_holder = $callback_arr['payment_method']['card_holder']; $card_expiry_month = $callback_arr['payment_method']['card_expiry_month']; $card_expiry_year = $callback_arr['payment_method']['card_expiry_year']; $issuer = $callback_arr['payment_method']['issuer']; $country = $callback_arr['payment_method']['country']; $sql = "SELECT * FROM `" . _DB_PREFIX_ . "hipay_tokens`\n\t WHERE `customer_id`='" . (int) $customer_id . "'\n\t AND `token`='" . pSQL($token) . "'"; HipayLogger::addLog('SQL', HipayLogger::APICALL, $sql); $result = Db::getInstance()->getRow($sql); if (!$result['id']) { // LOG HipayLog('--------------- Enregistrement nouveau Token'); // 'insert in DB'; $sql_insert = "INSERT INTO `" . _DB_PREFIX_ . "hipay_tokens` (`customer_id`, `token`, `brand`, `pan`, `card_holder`, `card_expiry_month`, `card_expiry_year`, `issuer`, `country`)\n\t VALUES('" . (int) $customer_id . "', '" . pSQL($token) . "', '" . pSQL($brand) . "', '" . pSQL($pan) . "', '" . pSQL($card_holder) . "', '" . pSQL($card_expiry_month) . "', '" . pSQL($card_expiry_year) . "', '" . pSQL($issuer) . "', '" . pSQL($country) . "')"; Db::getInstance()->execute($sql_insert); } } //LOG HipayLog('--------------- currentOrder = ' . $hipay->currentOrder); $bool = true; } else { if ($order_exist && $callback_arr['status'] == HIPAY_STATUS_AUTHORIZED) { // prepare message for this status HIPAY_STATUS_AUTHORIZED $message = $hipay->l('HiPay - Callback initiated') . "<br>"; $message .= ' - ' . $hipay->l('Transaction_reference : ') . $callback_arr['transaction_reference'] . "<br>"; $message .= ' - ' . $hipay->l('State : ') . $callback_arr['state'] . "<br>"; $message .= ' - ' . $hipay->l('Status : ') . $callback_arr['status'] . "<br>"; $message .= ' - ' . $hipay->l('Message : ') . $callback_arr['message'] . "<br>"; $message .= ' - ' . $hipay->l('Amount : ') . $callback_arr['authorized_amount'] . "<br>"; $message = strip_tags($message, '<br>'); // LOG HipayLog('--------------- MSG : ' . $message); // prepare payment for this status HIPAY_STATUS_AUTHORIZED $amount = $callback_arr['captured_amount']; // Set refund to negative $payment_method = 'HiPay Fullservice via ' . (string) ucwords($callback_arr['payment_product']); $payment_transaction_id = $callback_arr['transaction_reference']; $currency = new Currency($order->id_currency); $payment_date = date("Y-m-d H:i:s"); $order_invoice = null; if ($order && Validate::isLoadedObject($order)) { // Add order payment if ($order->addOrderPayment($amount, $payment_method, $payment_transaction_id, $currency, $payment_date, $order_invoice)) { // LOG HipayLog('--------------- Order payment add with success'); // Add message for this status $msg = new Message(); if (Validate::isCleanHtml($message)) { $msg->message = $message; $msg->id_order = (int) $order->id; $msg->private = 1; $msg->add(); // LOG HipayLog('--------------- MSG register with success'); $bool = true; } } } else { HipayLogger::addLog($hipay->l('Bad Callback Error', 'hipay'), HipayLogger::ERROR, 'Error, order exist but the object order not loaded'); HipayLog('--------------- Error, order exist but the object order not loaded'); } } } return $bool; }
public static function createToken($cardNumber = null, $cardHolder = null, $cardExpiryMonth = null, $cardExpiryYear = null, $cardSecurityCode = null, $firstname = null, $lastname = null, $paymentproductswitcher = null) { try { $hipay = new HiPay_Tpp(); HipayLogger::addLog($hipay->l('Token Create call initiated', 'hipay'), HipayLogger::APICALL, 'Action : Create Token'); define('API_ENDPOINT_TOKEN', HipayClass::getAPITokenURL()); define('API_USERNAME_TOKEN', HipayClass::getAPIUsername()); define('API_PASSWORD_TOKEN', HipayClass::getAPIPassword()); $credentials_token = API_USERNAME_TOKEN . ':' . API_PASSWORD_TOKEN; $resource_token = API_ENDPOINT_TOKEN . 'create'; // Multi_use : only boolean // 0 = Generate a single-use token // 1 = Generate a multi-use token (default) $multi_use = 1; if ($paymentproductswitcher == 'american-express') { $data_token = array('card_number' => $cardNumber, 'card_expiry_month' => $cardExpiryMonth, 'card_expiry_year' => $cardExpiryYear, 'firstname' => $firstname, 'lastname' => $lastname, 'cvc' => $cardSecurityCode, 'multi_use' => $multi_use); } elseif ($paymentproductswitcher == 'bcmc') { $data_token = array('card_number' => $cardNumber, 'card_expiry_month' => $cardExpiryMonth, 'card_expiry_year' => $cardExpiryYear, 'card_holder' => $cardHolder, 'multi_use' => $multi_use); } else { $data_token = array('card_number' => $cardNumber, 'card_expiry_month' => $cardExpiryMonth, 'card_expiry_year' => $cardExpiryYear, 'card_holder' => $cardHolder, 'cvc' => $cardSecurityCode, 'multi_use' => $multi_use); } // create a new cURL resource $curl_token = curl_init(); // set appropriate options $options_token = array(CURLOPT_URL => $resource_token, CURLOPT_USERPWD => $credentials_token, CURLOPT_HTTPHEADER => array('Accept: application/json'), CURLOPT_RETURNTRANSFER => true, CURLOPT_FAILONERROR => false, CURLOPT_HEADER => false, CURLOPT_POST => true, CURLOPT_POSTFIELDS => http_build_query($data_token), CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false); foreach ($options_token as $option => $value) { curl_setopt($curl_token, $option, $value); } $result_token = curl_exec($curl_token); $status_token = (int) curl_getinfo($curl_token, CURLINFO_HTTP_CODE); $response_token = Tools::jsonDecode($result_token); // p($credentials_token); // p($resource_token); // p($data_token); // p($status_token); // p($response_token); // execute the given cURL session if (false === $result_token) { throw new Exception(curl_error($curl_token)); } if (floor($status_token / 100) != 2) { throw new Exception($status_token); } curl_close($curl_token); HipayLogger::addLog($hipay->l('Token Create call success', 'hipay'), HipayLogger::APICALL, 'Creation token avec success'); return $response_token; } catch (Exception $e) { HipayLogger::addLog($hipay->l('Token Create call status error', 'hipay'), HipayLogger::ERROR, mysql_real_escape_string($e->getMessage())); return $e->getMessage(); } }