示例#1
0
文件: hipay.php 项目: jprotin/hipay
 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;
 }
示例#2
0
 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($this->context->customer->email);
     $paymentParams->setUrlCancel(Tools::getShopDomainSsl(true) . __PS_BASE_URI__ . 'order.php?step=3');
     $paymentParams->setUrlNok(Tools::getShopDomainSsl(true) . __PS_BASE_URI__ . 'order-confirmation.php?id_cart=' . (int) $cart->id . '&amp;id_module=' . (int) $this->id . '&amp;secure_key=' . $customer->secure_key);
     $paymentParams->setUrlOk(Tools::getShopDomainSsl(true) . __PS_BASE_URI__ . 'order-confirmation.php?id_cart=' . (int) $cart->id . '&amp;id_module=' . (int) $this->id . '&amp;secure_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')));
     $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 {
         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';
     }
 }
示例#3
0
文件: hipay.php 项目: grlf/eyedock
 public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result)
 {
     require_once dirname(__FILE__) . '/mapi/mapi_package.php';
     $OrderTitle = 'Order on ' . $this->getDi()->config->get('site_title');
     $OrderInfo = $invoice->getLineDescription();
     $OrderCategory = $this->getConfig('order_category');
     $params = new HIPAY_MAPI_PaymentParams();
     $params->setLogin($this->getConfig('account_id'), $this->getConfig('merchant_password'));
     $params->setAccounts($this->getConfig('account_id'));
     $params->setLocale('en_GB');
     // The payment interface will be in International French by default
     $params->setRating('ALL');
     // '+16' - The order content is intended for people at least 16 years old.
     $params->setMedia('WEB');
     // The interface will be the Web interface
     if (!$invoice->rebill_times) {
         $params->setPaymentMethod(HIPAY_MAPI_METHOD_SIMPLE);
     } else {
         $params->setPaymentMethod(HIPAY_MAPI_METHOD_MULTI);
     }
     // It is a Recurring payment
     $params->setCaptureDay(HIPAY_MAPI_CAPTURE_IMMEDIATE);
     // The capture take place immediately
     $params->setCurrency($invoice->currency);
     $params->setIdForMerchant('aMember invoice #' . $invoice->public_id);
     // The merchant-selected identifier for this order
     $params->setMerchantDatas('invoice_id', $invoice->public_id);
     //Data element of type key=value declared and will be returned to the merchant after the payment in the notification data feed [C].
     $site_id = $this->invoice->getItem(0)->getBillingPlanData('hipay_site_id');
     if (!$site_id) {
         $site_id = $this->getConfig('site_id');
     }
     // use default value
     $params->setMerchantSiteId($site_id);
     // This order relates to the web site which the merchant declared in the Hipay platform.
     $params->setURLOk($this->getReturnUrl());
     // If the payment is accepted, the user will be redirected to this page
     $params->setUrlNok($this->getCancelUrl());
     // If the payment is refused, the user will be redirected to this page
     $params->setUrlCancel($this->getCancelUrl());
     // If the user cancels the payment, he will be redirected to this page
     $params->setUrlAck($this->getPluginUrl('ipn'));
     // The merchant's site will be notified of the result of the payment by a call to the script
     $t = $params->check();
     if (!$t) {
         throw new Am_Exception_Paysystem_TransactionInvalid('An error occurred while creating the paymentParams object');
     }
     if ($invoice->tax_rate && $invoice->tax_title) {
         $tax = new HIPAY_MAPI_Tax();
         $tax->setTaxName($invoice->tax_title);
         $percentage = true;
         //$invoice->tax_type == 1;
         $tax->setTaxVal($invoice->tax_rate, $percentage);
         $t = $tax->check();
         if (!$t) {
             throw new Am_Exception_Paysystem_TransactionInvalid('An error occurred while creating a tax object');
         }
     }
     $item1 = new HIPAY_MAPI_Product();
     $item1->setName($invoice->getItem(0)->item_title);
     $item1->setCategory($OrderCategory);
     $item1->setquantity(1);
     $item1->setPrice($invoice->first_total);
     if (isset($tax)) {
         $item1->setTax(array($tax));
     }
     //$item1->setInfo('Simmons, Dan – ISBN 0575076380');
     //$item1->setRef('JV005');
     $t = $item1->check();
     if (!$t) {
         throw new Am_Exception_Paysystem_TransactionInvalid('An error occurred while creating a product object');
     }
     $order = new HIPAY_MAPI_Order();
     $order->setOrderTitle($OrderTitle);
     // Order title and information
     $order->setOrderInfo($OrderInfo);
     $order->setOrderCategory($OrderCategory);
     // The order category is 3 (Books)
     if ($invoice->hasShipping()) {
         $order->setShipping($invoice->first_shipping, isset($tax) ? array($tax) : array());
     }
     // The shipping costs are 1.50 Euros excluding taxes, and $tax1 is applied
     //$order->setInsurance(2,array($tax3,$tax1)); // The insurance costs are 2 Euros excluding taxes, and $tax1 and $tax3 are applied
     //$order->setFixedCost(2.25,array($tax3)); // The fixed costs are 2.25 Euros excluding taxes, and $tax3 is applied to this amount
     //$order->setAffiliate(array($aff1,$aff2)); // This order has two affiliates, $aff1 and $aff2
     $t = $order->check();
     if (!$t) {
         throw new Am_Exception_Paysystem_TransactionInvalid('An error occurred while creating a product object');
     }
     if (!$invoice->rebill_times) {
         try {
             $payment = new HIPAY_MAPI_SimplePayment($params, $order, array($item1));
         } catch (Exception $e) {
             throw new Am_Exception_Paysystem_TransactionInvalid($e->getMessage());
         }
     } else {
         // First payment: The payment will be made in 1 hour, in the amount of 5 Euros, excluding taxes plus tax $tax1.
         $ins1 = new HIPAY_MAPI_Installment();
         if ($invoice->first_total > 0) {
             $price = $invoice->first_total;
             $paymentDelay = '0H';
         } else {
             $price = $invoice->second_total;
             $paymentDelay = $this->getPeriod($invoice->first_period);
         }
         $ins1->setPrice($price);
         if (isset($tax)) {
             $ins1->setTax(array($tax));
         }
         $ins1->setFirst(true, $paymentDelay);
         $t = $ins1->check();
         if (!$t) {
             throw new Am_Exception_Paysystem_TransactionInvalid('An error occurred while creating an instalment object');
         }
         // Subsequent payments: The payments will be made every 30 days in the amount of 12.5 Euros excluding taxes, plus tax of $tax2.0.
         $ins2 = new HIPAY_MAPI_Installment();
         $ins2->setPrice($invoice->second_total);
         if (isset($tax)) {
             $ins2->setTax(array($tax));
         }
         $paymentDelay = $this->getPeriod($invoice->second_period);
         $ins2->setFirst(false, $paymentDelay);
         $t = $ins2->check();
         if (!$t) {
             throw new Am_Exception_Paysystem_TransactionInvalid('An error occurred while creating an instalment object');
         }
         // Initial order
         $orderins1 = new HIPAY_MAPI_Order();
         $orderins1->setOrderTitle($OrderTitle);
         // Title and information on this payment
         $orderins1->setOrderInfo($OrderInfo);
         //1 free hour
         $orderins1->setOrderCategory($OrderCategory);
         // The order category is 3 (Books)
         $t = $orderins1->check();
         if (!$t) {
             throw new Am_Exception_Paysystem_TransactionInvalid('An error occurred while creating an order object');
         }
         // Subsequent orders
         $orderins2 = new HIPAY_MAPI_Order();
         $orderins2->setOrderTitle($OrderTitle);
         // Title and information on this payment
         $orderins2->setOrderInfo($OrderInfo);
         //only 12 euros 50 monthly !
         $orderins2->setOrderCategory($OrderCategory);
         // The order category is 3 (Books)
         $t = $orderins2->check();
         if (!$t) {
             throw new Am_Exception_Paysystem_TransactionInvalid('An error occurred while creating an order object');
         }
         try {
             $payment = new HIPAY_MAPI_MultiplePayment($params, $orderins1, $ins1, $orderins2, $ins2);
         } catch (Exception $e) {
             throw new Am_Exception_Paysystem_TransactionInvalid($e->getMessage());
         }
     }
     $xmlTx = $payment->getXML();
     $output = HIPAY_MAPI_SEND_XML::sendXML($xmlTx, $this->getConfig('testing') ? self::TEST_URL : self::URL);
     $r = HIPAY_MAPI_COMM_XML::analyzeResponseXML($output, $url, $err_msg);
     if ($r === true && !$err_msg) {
         // The internet user is sent to the URL indicated by the Hipay platform
         $a = new Am_Paysystem_Action_Redirect($url);
         $result->setAction($a);
     } else {
         throw new Am_Exception_Paysystem_TransactionInvalid($err_msg);
     }
 }