public function payment() { if (!$this->active) { return; } global $cart; $id_currency = (int) $this->getModuleCurrency($cart); // If the currency is forced to a different one than the current one, then the cart must be updated if ($cart->id_currency != $id_currency) { if (Db::getInstance()->execute('UPDATE ' . _DB_PREFIX_ . 'cart SET id_currency = ' . (int) $id_currency . ' WHERE id_cart = ' . (int) $cart->id)) { $cart->id_currency = $id_currency; } } $currency = new Currency($id_currency); $language = new Language($cart->id_lang); $customer = new Customer($cart->id_customer); require_once dirname(__FILE__) . '/mapi/mapi_package.php'; $hipayAccount = Configuration::get('HIPAY_ACCOUNT_' . $currency->iso_code); $hipayPassword = Configuration::get('HIPAY_PASSWORD_' . $currency->iso_code); $hipaySiteId = Configuration::get('HIPAY_SITEID_' . $currency->iso_code); $hipaycategory = Configuration::get('HIPAY_CATEGORY_' . $currency->iso_code); $paymentParams = new HIPAY_MAPI_PaymentParams(); $paymentParams->setLogin($hipayAccount, $hipayPassword); $paymentParams->setAccounts($hipayAccount, $hipayAccount); // EN_us is not a standard format, but that's what Hipay uses if (isset($language->language_code)) { $paymentParams->setLocale($this->formatLanguageCode($language->language_code)); } else { $paymentParams->setLocale(Tools::strtolower($language->iso_code) . '_' . Tools::strtoupper($language->iso_code)); } $paymentParams->setMedia('WEB'); $paymentParams->setRating(Configuration::get('HIPAY_RATING')); $paymentParams->setPaymentMethod(HIPAY_MAPI_METHOD_SIMPLE); $paymentParams->setCaptureDay(HIPAY_MAPI_CAPTURE_IMMEDIATE); $paymentParams->setCurrency(Tools::strtoupper($currency->iso_code)); $paymentParams->setIdForMerchant($cart->id); $paymentParams->setMerchantSiteId($hipaySiteId); $paymentParams->setIssuerAccountLogin(Context::getContext()->customer->email); if (version_compare(_PS_VERSION_, '1.5.0.0', '<')) { $paymentParams->setUrlCancel(Tools::getShopDomainSsl(true) . __PS_BASE_URI__ . 'order.php?step=3'); $paymentParams->setUrlNok(Tools::getShopDomainSsl(true) . __PS_BASE_URI__ . 'order.php?step=3&hipay_error=1'); $paymentParams->setUrlOk(Tools::getShopDomainSsl(true) . __PS_BASE_URI__ . 'order-confirmation.php?id_cart=' . (int) $cart->id . '&id_module=' . (int) $this->id . '&key=' . $customer->secure_key); $paymentParams->setUrlAck(Tools::getShopDomainSsl(true) . __PS_BASE_URI__ . 'modules/' . $this->name . '/validation.php?token=' . Tools::encrypt($cart->id . $cart->secure_key . Configuration::get('HIPAY_SALT'))); # # Patch transfert du logo vers la page de paiement # Le 16/11/2015 par Johan PROTIN (jprotin at hipay dot com) # if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') { // Si le site utilise le protocol HTTPS alors on envoit l'URL avec HTTPS $logo_url = Tools::getShopDomainSsl(true) . _PS_IMG_ . Configuration::get('PS_LOGO'); $paymentParams->setLogoUrl($logo_url); } # ------------------------------------------------ } else { $paymentParams->setUrlCancel(Context::getContext()->link->getPageLink('order', null, null, array('step' => 3))); $paymentParams->setUrlNok(Context::getContext()->link->getPageLink('order', null, null, array('step' => 3, 'hipay_error' => 1))); $paymentParams->setUrlOk(Context::getContext()->link->getPageLink('order-confirmation', null, null, array('id_cart' => (int) $cart->id, 'id_module' => (int) $this->id, 'key' => $customer->secure_key))); $paymentParams->setUrlAck(Context::getContext()->link->getModuleLink('hipay', 'validation', array('token' => Tools::encrypt($cart->id . $cart->secure_key . Configuration::get('HIPAY_SALT'))))); # # Patch transfert du logo vers la page de paiement # Le 16/11/2015 par Johan PROTIN (jprotin at hipay dot com) # if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') { // Si le site utilise le protocol HTTPS alors on envoit l'URL avec HTTPS $logo_url = $this->context->link->getMediaLink(_PS_IMG_ . Configuration::get('PS_LOGO')); $paymentParams->setLogoUrl($logo_url); } # ------------------------------------------------ } $paymentParams->setBackgroundColor('#FFFFFF'); if (!$paymentParams->check()) { return $this->l('[Hipay] Error: cannot create PaymentParams'); } $item = new HIPAY_MAPI_Product(); $item->setName($this->l('Cart')); $item->setInfo(''); $item->setquantity(1); $item->setRef($cart->id); $item->setCategory($hipaycategory); $item->setPrice($cart->getOrderTotal()); try { if (!$item->check()) { return $this->l('[Hipay] Error: cannot create "Cart" Product'); } } catch (Exception $e) { return $this->l('[Hipay] Error: cannot create "Cart" Product'); } $items = array($item); $order = new HIPAY_MAPI_Order(); $order->setOrderTitle($this->l('Order total')); $order->setOrderCategory($hipaycategory); if (!$order->check()) { return $this->l('[Hipay] Error: cannot create Order'); } try { $commande = new HIPAY_MAPI_SimplePayment($paymentParams, $order, $items); } catch (Exception $e) { return $this->l('[Hipay] Error:') . ' ' . $e->getMessage(); } $xmlTx = $commande->getXML(); $output = HIPAY_MAPI_SEND_XML::sendXML($xmlTx); $reply = HIPAY_MAPI_COMM_XML::analyzeResponseXML($output, $url, $err_msg, $err_keyword, $err_value, $err_code); if ($reply === true) { Tools::redirectLink($url); } else { if (version_compare(_PS_VERSION_, '1.5.0.0', '<')) { global $smarty; include dirname(__FILE__) . '/../../header.php'; $smarty->assign('errors', array('[Hipay] ' . strval($err_msg) . ' (' . $output . ')')); $_SERVER['HTTP_REFERER'] = Tools::getShopDomainSsl(true) . __PS_BASE_URI__ . 'order.php?step=3'; $smarty->display(_PS_THEME_DIR_ . 'errors.tpl'); include dirname(__FILE__) . '/../../footer.php'; } else { Context::getContext()->controller->errors[] = '[Hipay] ' . strval($err_msg) . ' (' . $output . ')'; $_SERVER['HTTP_REFERER'] = Context::getContext()->link->getPageLink('order', true, null, array('step' => 3)); } } return $reply; }
/** * Erzeugt die Basisparameter für den Bezahlvorgang * * @param HIPAY_MAPI_PaymentParams $params * @param string token */ protected function setupParams(Mage_Sales_Model_Order $order, $token) { $websiteId = Mage::app()->getStore()->getStoreId(); //Mage::app()->getStore()->getWebsiteId(); $accountId = Mage::getStoreConfig('hipay/accountsettings/accountid', $websiteId); $merchantPassword = Mage::getStoreConfig('hipay/accountsettings/merchantpassword', $websiteId); $merchantSiteId = Mage::getStoreConfig('hipay/accountsettings/merchantsiteid', $websiteId); //$accountCurrency = Mage::getStoreConfig('hipay/accountsettings/accountcurrency'); $orderCurrency = $order->getOrderCurrency()->getData("currency_code"); $ageClassification = Mage::getStoreConfig('hipay/accountsettings/ageclassification', $websiteId); $notificationEmail = Mage::getStoreConfig('hipay/accountsettings/notificationemail', $websiteId); $logoUrl = Mage::getStoreConfig('hipay/extendedaccountsettings/logourl', $websiteId); $itemAccountId = Mage::getStoreConfig('hipay/extendedaccountsettings/itemaccountid', $websiteId); $taxAccountId = ""; //Mage::getStoreConfig('hipay/extendedaccountsettings/taxaccountid'); $insuranceAccountId = ""; //Mage::getStoreConfig('hipay/extendedaccountsettings/insuranceaccountid'); $fixcostAccountId = ""; //Mage::getStoreConfig('hipay/extendedaccountsettings/fixcostaccountid'); $shippingAccountId = Mage::getStoreConfig('hipay/extendedaccountsettings/shippingaccountid', $websiteId); $itemAccountId = empty($itemAccountId) ? $accountId : $itemAccountId; $taxAccountId = empty($taxAccountId) ? $itemAccountId : $taxAccountId; $insuranceAccountId = empty($insuranceAccountId) ? $itemAccountId : $insuranceAccountId; $fixcostAccountId = empty($fixcostAccountId) ? $itemAccountId : $fixcostAccountId; $shippingAccountId = empty($shippingAccountId) ? $itemAccountId : $shippingAccountId; $nomLog = 'hipay-wallet-payment-' . date('Ymd') . '.log'; Mage::log('############################', null, $nomLog); Mage::log('websiteId = ' . $websiteId, null, $nomLog); Mage::log('accountId = ' . $accountId, null, $nomLog); Mage::log('merchantPassword = '******'merchantSiteId = ' . $merchantSiteId, null, $nomLog); Mage::log('orderCurrency = ' . $orderCurrency, null, $nomLog); Mage::log('ageClassification = ' . $ageClassification, null, $nomLog); Mage::log('notificationEmail = ' . $notificationEmail, null, $nomLog); Mage::log('logoUrl = ' . $logoUrl, null, $nomLog); Mage::log('itemAccountId = ' . $itemAccountId, null, $nomLog); Mage::log('shippingAccountId = ' . $shippingAccountId, null, $nomLog); $params = new HIPAY_MAPI_PaymentParams(); //The Hipay platform connection parameters. This is not the information used to connect to your Hipay //account, but the specific login and password used to connect to the payment platform. //The login is the ID of the hipay merchant account receiving the payment, and the password is //the « merchant password » set within your Hipay account (site info). $params->setLogin($accountId, $merchantPassword); // The amounts will be credited to the defined accounts $params->setAccounts($itemAccountId, $taxAccountId, $insuranceAccountId, $fixcostAccountId, $shippingAccountId); // The payment interface will be in German by default $params->setDefaultLang('de_DE'); // The interface will be the Web interface $params->setMedia('WEB'); //The order content is intended for people at least (ALL, 12+, 16+, 18+) years old. $params->setRating($ageClassification); // This is a single payment $params->setPaymentMethod(HIPAY_MAPI_METHOD_SIMPLE); // The capture take place immediately (HIPAY_MAPI_CAPTURE_IMMEDIATE), manually (HIPAY_MAPI_CAPTURE_MANUAL) // or delayed (0-7 -> number of days before capture) $params->setCaptureDay(HIPAY_MAPI_CAPTURE_IMMEDIATE); // The amounts are expressed in Euros, this has to be the same currency as the merchant's account. $params->setCurrency($orderCurrency); // The merchant-selected identifier for this order $params->setIdForMerchant($order->getRealOrderId()); // Two data elements of type key=value are declared and will be returned to the merchant after the payment in the // notification data feed [C]. // $params->setMerchantDatas('id_client','2000'); // $params->setMerchantDatas('credit','10'); // This order relates to the web site which the merchant declared in the Hipay platform. $params->setMerchantSiteId($merchantSiteId); // Set buyer email $params->setIssuerAccountLogin($order->getCustomerEmail()); // If the payment is accepted, the user will be redirected to this page $urlOk = Mage::getUrl('hipay/mapi/success/'); // creates URL 'http://www.mywebsite.com/hipay/mapi/success/' $params->setURLOk($urlOk . $token); // add security-token // If the payment is refused, the user will be redirected to this page $urlNok = Mage::getUrl('hipay/mapi/failed'); // creates URL 'http://www.mywebsite.com/hipay/mapi/failed/' $params->setUrlNok($urlNok . $token); // add security-token // If the user cancels the payment, he will be redirected to this page $urlCancel = Mage::getUrl('hipay/mapi/cancel'); // creates URL 'http://www.mywebsite.com/hipay/mapi/failed/' $params->setUrlCancel($urlCancel . $token); // add security-token // The email address used to send the notifications, on top of the http notifications. $params->setEmailAck($notificationEmail); // The merchant's site will be notified of the result of the payment by a call to the script // "listen_hipay_notification.php" $urlAck = Mage::getUrl('hipay/mapi/notification'); // creates URL 'http://www.mywebsite.com/hipay/mapi/notfication' $params->setUrlAck($urlAck); // The background color of the interface will be #FFFFFF (default color recommended) $params->setBackgroundColor('#FFFFFF'); //The merchant’s logo URL, this logo will be displayed on the payment pages. $params->setLogoUrl($logoUrl); if (!$params->check()) { $errorTxt = "Hipay: An error occurred while creating the HIPAY_MAPI_PaymentParams object"; Mage::log($errorTxt); return null; } return $params; }