/** * Return the paid amount converted from cents (or currency equivalent) to a decimal value * @return float */ function getFloatAmount() { $currency = $this->api->findCurrencyByNumCode($this->get('currency')); return $currency->convertAmountToFloat($this->get('amount')); }
/** * Prepare data and redirect to PayZen payment platform * * @param string $order_number * @param object $orderData * @param string $return_context the session id * @param string $html the form to display * @param bool $new_status false if it should not be changed, otherwise new staus * @return NULL */ function plgVmConfirmedOrder($cart, $order) { if (!($method = $this->getVmPluginMethod($order['details']['BT']->virtuemart_paymentmethod_id))) { return NULL; // Another method was selected, do nothing } if (!$this->selectedThisElement($method->payment_element)) { return FALSE; } $this->_debug = $method->debug; // enable debug $session = JFactory::getSession(); $return_context = $session->getId(); $this->logInfo('plgVmOnConfirmedOrderGetPaymentForm -- order number: ' . $order['details']['BT']->order_number, 'message'); if (!class_exists('PayzenApi')) { require JPATH_VMPAYMENTPLUGIN_PAYZEN . DS . 'payzen' . DS . 'payzen_api.php'; } $api = new PayzenApi('UTF-8'); // set config parameters $paramNames = array('platform_url', 'key_test', 'key_prod', 'capture_delay', 'ctx_mode', 'site_id', 'validation_mode', 'redirect_enabled', 'redirect_success_timeout', 'redirect_success_message', 'redirect_error_timeout', 'redirect_error_message', 'return_mode'); foreach ($paramNames as $name) { $api->set($name, $method->{$name}); } // Set urls $url_return = JROUTE::_(JURI::root() . 'index.php?option=com_virtuemart&view=pluginresponse&task=pluginresponsereceived'); $uri = JURI::getInstance($url_return); //$uri->setVar('pelement', $this->payment_element); $uri->setVar('pm', $order['details']['BT']->virtuemart_paymentmethod_id); $uri->setVar('Itemid', JRequest::getInt('Itemid')); $api->set('url_return', $uri->toString()); $url_cancel = JROUTE::_(JURI::root() . 'index.php?option=com_virtuemart&view=pluginresponse&task=pluginUserPaymentCancel'); $uri = JURI::getInstance($url_cancel); $uri->setVar('on', $order['details']['BT']->order_number); $uri->setVar('pm', $order['details']['BT']->virtuemart_paymentmethod_id); $uri->setVar('Itemid', JRequest::getInt('Itemid')); $api->set('url_cancel', $uri->toString()); // Set the language code $lang = JFactory::getLanguage(); $lang->load('plg_vmpayment_' . $this->_name, JPATH_ADMINISTRATOR); $tag = substr($lang->get('tag'), 0, 2); $language = in_array($tag, $api->getSupportedLanguages()) ? $tag : ($method->language ? $method->language : 'fr'); $api->set('language', $language); // Set currency if (!class_exists('VirtueMartModelCurrency')) { require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'currency.php'; } $currencyModel = new VirtueMartModelCurrency(); $currencyObj = $currencyModel->getCurrency($cart->pricesCurrency); $currency = $api->findCurrencyByNumCode($currencyObj->currency_numeric_code); if ($currency == NULL) { $this->logInfo('plgVmOnConfirmedOrderGetPaymentForm -- Could not find currency numeric code for currency : ' . $currencyObj->currency_numeric_code, 'error'); vmInfo(JText::_('VMPAYMENT_' . $this->_name . '_CURRENCY_NOT_SUPPORTED')); return NULL; } $api->set('currency', $currency->num); // payment_cards may be one value or array $cards = $method->payment_cards; $cards = !is_array($cards) ? $cards : (in_array("", $cards) ? "" : implode(";", $cards)); $api->set('payment_cards', $cards); // available_languages may be one value or array $available_languages = $method->available_languages; $available_languages = !is_array($available_languages) ? $available_languages : (in_array("", $available_languages) ? "" : implode(";", $available_languages)); $api->set('available_languages', $available_languages); $api->set('contrib', 'VirtueMart2.0.8_1.3c/' . vmVersion::$RELEASE); // Set customer info // $usr = JFactory::getUser(); $usrBT = $order['details']['BT']; $usrST = isset($order['details']['ST']) ? $order['details']['ST'] : $order['details']['BT']; $api->set('cust_email', $usrBT->email); // $api->set('cust_id', ''); $api->set('cust_title', @$usrBT->title); $api->set('cust_first_name', $usrBT->first_name); $api->set('cust_last_name', $usrBT->last_name); $api->set('cust_address', $usrBT->address_1 . ' ' . $usrBT->address_2); $api->set('cust_zip', $usrBT->zip); $api->set('cust_city', $usrBT->city); $api->set('cust_state', @ShopFunctions::getStateByID($usrBT->virtuemart_state_id)); $api->set('cust_country', @ShopFunctions::getCountryByID($usrBT->virtuemart_country_id, 'country_2_code')); $api->set('cust_phone', $usrBT->phone_1); $api->set('cust_cell_phone', $usrBT->phone_2); $api->set('ship_to_first_name', $usrST->first_name); $api->set('ship_to_last_name', $usrST->last_name); $api->set('ship_to_city', $usrST->city); $api->set('ship_to_street', $usrST->address_1); $api->set('ship_to_street2', $usrST->address_2); $api->set('ship_to_state', @ShopFunctions::getStateByID($usrST->virtuemart_state_id)); $api->set('ship_to_country', @ShopFunctions::getCountryByID($usrST->virtuemart_country_id, 'country_2_code')); $api->set('ship_to_phone_num', $usrST->phone_1); $api->set('ship_to_zip', $usrST->zip); // Set order_id $api->set('order_id', $order['details']['BT']->order_number); // Set the amount to pay $exchangeRate = $currencyObj->currency_exchange_rate; if ($exchangeRate == 0) { $this->logInfo('plgVmOnConfirmedOrderGetPaymentForm -- Exchange rate for currency ' . $currencyObj->currency_numeric_code . ' must not be null.', 'warn'); if ($method->ctx_mode == 'TEST') { vmInfo(JText::_('VMPAYMENT_' . $this->_name . '_EXCHANGE_RATE_NULL')); return NULL; } else { // not consider exchange rate $exchangeRate = 1; } } $amount = $order['details']['BT']->order_total * $exchangeRate; $api->set('amount', $currency->convertAmountToInteger($amount)); // 3DS activation according to amount $threeds_mpi = null; if ($method->threeds_min_amount != '' && $amount < $method->threeds_min_amount) { $threeds_mpi = '2'; } $api->set('threeds_mpi', $threeds_mpi); // Prepare data that should be stored in the database $dbValues['order_number'] = $order['details']['BT']->order_number; $dbValues['payment_name'] = $this->renderPluginName($method, $order); $dbValues['virtuemart_paymentmethod_id'] = $cart->virtuemart_paymentmethod_id; $dbValues[$this->_name . '_custom'] = $return_context; $this->storePSPluginInternalData($dbValues); $this->logInfo('plgVmOnConfirmedOrderGetPaymentForm -- payment data saved to table ' . $this->_tablename, 'message'); // echo the redirect form $form = '<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><title>Redirection</title></head><body><div style="margin: auto; text-align: center;">'; $form .= '<p>' . JText::_('VMPAYMENT_' . $this->_name . '_PLEASE_WAIT') . '</p>'; $form .= '<p>' . JText::_('VMPAYMENT_' . $this->_name . '_CLICK_BUTTON_IF_NOT_REDIRECTED') . '</p>'; $form .= '<form action="' . $api->platformUrl . '" method="POST" name="vm_' . $this->_name . '_form" >'; $form .= '<input type="image" name="submit" src="' . JURI::base(TRUE) . '/images/stories/virtuemart/payment/' . $this->_name . '.png" alt="' . JText::_('VMPAYMENT_' . $this->_name . '_BTN_ALT') . '" title="' . JText::_('VMPAYMENT_PAYZEN_BTN_ALT') . '"/>'; $form .= $api->getRequestFieldsHtml(); $form .= '</form></div>'; $form .= '<script type="text/javascript">document.forms[0].submit();</script></body></html>'; $this->logInfo('plgVmOnConfirmedOrderGetPaymentForm -- user redirected to ' . $this->_name, 'message'); echo $form; $cart->_confirmDone = FALSE; $cart->_dataValidated = FALSE; $cart->setCartIntoSession(); die; // not save order, not send mail, do redirect }