public function generalTabHtml() { $api = new PayzenApi(); // new instance of PayzenApi to use static methods $_html = '<fieldset><legend>' . $this->l('BASE SETTINGS') . '</legend>'; // enable / disbale logs $options = array('False' => $this->l('Disabled'), 'True' => $this->l('Enabled')); $_html .= $this->_adminFormSelect($options, Configuration::get('PAYZEN_ENABLE_LOGS'), 'PAYZEN_ENABLE_LOGS', $this->l('Logs'), $this->l('Enable / disbale module logs')); $_html .= '</fieldset><div class="clear"> </div>'; /* * payment gateway access settings */ $_html .= '<fieldset><legend>' . $this->l('PAYMENT GATEWAY ACCESS') . '</legend>'; $_html .= $this->_adminFormText('PAYZEN_SITE_ID', $this->l('Site id'), $this->l('Site id provided by the payment gateway')); $_html .= $this->_adminFormText('PAYZEN_KEY_TEST', $this->l('Test certificate'), $this->l('Certificate provided by the gateway')); $_html .= $this->_adminFormText('PAYZEN_KEY_PROD', $this->l('Production certificate'), $this->l('Certificate provided by the gateway')); // context mode $options = array('TEST' => $this->l('TEST'), 'PRODUCTION' => $this->l('PRODUCTION')); $_html .= $this->_adminFormSelect($options, Configuration::get('PAYZEN_MODE'), 'PAYZEN_MODE', $this->l('Mode'), $this->l('The context mode of this module')); $_html .= $this->_adminFormText('PAYZEN_PLATFORM_URL', $this->l('Gateway URL'), $this->l('URL the client will be redirected to'), 'size="65"'); // check URL display $_html .= '<label>' . $this->l('Check URL to copy in your bank back-office') . '</label>'; $_html .= '<div class="margin-form"><p>'; if (!Shop::isFeatureActive() || Shop::getContext() == Shop::CONTEXT_SHOP) { $_html .= Context::getContext()->shop->getBaseURL() . 'modules/' . $this->_name . '/validation.php'; } else { $_html .= $this->l('Select a shop to view check URL'); } $_html .= '</p></div>'; $_html .= '</fieldset><div class="clear"> </div>'; /* * payment page settings */ $_html .= '<fieldset><legend>' . $this->l('PAYMENT PAGE') . '</legend>'; // supported languages $options = array(); foreach ($api->getSupportedLanguages() as $key => $value) { $options[$key] = $this->l($value); } asort($options); // default language $_html .= $this->_adminFormSelect($options, Configuration::get('PAYZEN_DEFAULT_LANGUAGE'), 'PAYZEN_DEFAULT_LANGUAGE', $this->l('Default language'), $this->l('Default language on the payment page')); // available languages $availLangs = Configuration::get('PAYZEN_AVAILABLE_LANGUAGES'); $selected = $availLangs == '' ? array() : explode(';', $availLangs); $_html .= $this->_adminFormSelect($options, $selected, 'PAYZEN_AVAILABLE_LANGUAGES[]', $this->l('Available languages'), $this->l('Select none to use gateway configuration.'), 'multiple="multiple" size="8"'); // capture delay $_html .= $this->_adminFormText('PAYZEN_DELAY', $this->l('Delay'), $this->l('Delay before banking (in days)')); // validation mode $options = array('' => $this->l('Back-office configuration'), '0' => $this->l('Automatic'), '1' => $this->l('Manual')); $_html .= $this->_adminFormSelect($options, Configuration::get('PAYZEN_VALIDATION_MODE'), 'PAYZEN_VALIDATION_MODE', $this->l('Payment validation'), $this->l('If manual is selected, you will have to confirm payments manually in your bank back-office')); // payment cards $paymentCards = Configuration::get('PAYZEN_PAYMENT_CARDS'); $selected = $paymentCards == '' ? array() : explode(';', $paymentCards); $_html .= $this->_adminFormSelect($api->getSupportedCardTypes(), $selected, 'PAYZEN_PAYMENT_CARDS[]', $this->l('Available payment cards'), $this->l('Select the card types that can be used for the payment.'), 'multiple="multiple" size="7"'); $_html .= '</fieldset><div class="clear"> </div>'; /* * payment page customization settings */ $_html .= '<fieldset><legend>' . $this->l('PAYMENT PAGE CUSTOMIZE') . '</legend>'; // theme configuration $_html .= $this->_adminFormText('PAYZEN_THEME_CONFIG', $this->l('Theme configuration'), $this->l('The theme configuration to customize the payment page (logo, css).'), 'size="65"'); // shop name $_html .= $this->_adminFormText('PAYZEN_SHOP_NAME', $this->l('Shop name'), $this->l('Shop name to display on the payment page. Leave blank to use gateway config.')); // shop URL $_html .= $this->_adminFormText('PAYZEN_SHOP_URL', $this->l('Shop URL'), $this->l('Shop URL to display on the payment page. Leave blank to use gateway config.'), 'size="65"'); $_html .= '</fieldset><div class="clear"> </div>'; /* * selective 3DS settings */ $_html .= '<fieldset><legend>' . $this->l('SELECTIVE 3DS') . '</legend>'; // min amount to activate three ds $_html .= $this->_adminFormText('PAYZEN_3DS_MIN_AMOUNT', $this->l('Minimum amount for which activate 3DS'), $this->l('Requires subscription to Selective 3-D Secure option.')); $_html .= '</fieldset><div class="clear"> </div>'; /* * return to shop settings */ $_html .= '<fieldset><legend>' . $this->l('RETURN TO SHOP') . '</legend>'; // automatic redirection $options = array('False' => $this->l('Disabled'), 'True' => $this->l('Enabled')); $_html .= $this->_adminFormSelect($options, Configuration::get('PAYZEN_REDIRECT_ENABLED'), 'PAYZEN_REDIRECT_ENABLED', $this->l('Automatic redirection'), $this->l('Redirect the client to the shop at the end of the payment process')); // automatic redirection options $_html .= $this->_adminFormText('PAYZEN_REDIRECT_SUCCESS_T', $this->l('Success timeout'), $this->l('Time before the client is redirected after a successful payment')); $_html .= $this->_adminFormText('PAYZEN_REDIRECT_SUCCESS_M', $this->l('Success message'), $this->l('Message displayed before redirection after a successful payment'), 'size="65"'); $_html .= $this->_adminFormText('PAYZEN_REDIRECT_ERROR_T', $this->l('Failure timeout'), $this->l('Time before the client is redirected after a failed payment')); $_html .= $this->_adminFormText('PAYZEN_REDIRECT_ERROR_M', $this->l('Failure message'), $this->l('Message displayed before redirection after a failed payment'), 'size="65"'); // return mode $options = array('GET' => $this->l('GET (parameters in URL)'), 'POST' => $this->l('POST (parameters in a form)')); $_html .= $this->_adminFormSelect($options, Configuration::get('PAYZEN_RETURN_MODE'), 'PAYZEN_RETURN_MODE', $this->l('Return mode'), $this->l('How the client will transmit the payment result')); // payment failed management $options = array(Payzen::ON_FAILURE_RETRY => $this->l('Go back to checkout'), Payzen::ON_FAILURE_SAVE => $this->l('Save order and go back to order history')); $_html .= $this->_adminFormSelect($options, Configuration::get('PAYZEN_FAILURE_MANAGEMENT'), 'PAYZEN_FAILURE_MANAGEMENT', $this->l('Payment failed management'), $this->l('How to deal the client when the payment process failed')); // additional return parameters $_html .= $this->_adminFormText('PAYZEN_RETURN_GET_PARAMS', $this->l('Additional GET parameters'), $this->l('Extra parameters sent in the return URL'), 'size="65"'); $_html .= $this->_adminFormText('PAYZEN_RETURN_POST_PARAMS', $this->l('Additional POST parameters'), $this->l('Extra parameters sent in the return form'), 'size="65"'); $_html .= '</fieldset>'; return $_html; }
/** * 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')); }
/** * Constructor. */ function __construct($encoding = "UTF-8") { // call parent class constructor parent::__construct($encoding); }
/** * Validate and save module admin parameters */ private function _postProcess() { $api = new PayzenApi(); // new instance of PayzenApi for parameters validation // load and validate from request foreach ($this->_getAdminParameters() as $param) { $key = $param['key']; $label = $this->l($param['label'], 'payzenadmindisplay', null); $value = Tools::getValue($key, null); if (in_array($key, $this->_multiLangFields)) { $value = array(); foreach (Language::getLanguages(false) as $language) { $value[$language['id_lang']] = Tools::getValue($key . '_' . $language['id_lang'], ''); } } elseif ($key === 'PAYZEN_MULTI_OPTIONS') { if (!is_array($value) || empty($value)) { $value = array(); } else { $error = false; foreach ($value as $opt => $option) { if (!$option['label'] || !is_numeric($option['count']) || !is_numeric($option['period']) || $option['first'] && (!is_numeric($option['first']) || $option['first'] < 0 || $option['first'] > 100)) { unset($value[$opt]); // not save this option $error = true; } } if ($error) { $this->_errors[] = $this->l('One or more values are invalid for field "Payment options". Only valid lines are saved.'); } } $value = serialize($value); } elseif ($key === 'PAYZEN_AVAILABLE_LANGUAGES' || $key === 'PAYZEN_PAYMENT_CARDS') { $value = is_array($value) && count($value) > 0 ? implode(';', $value) : ''; if ($value == '' && $key === 'PAYZEN_PAYMENT_CARDS') { // empty values for PAYZEN_PAYMENT_CARDS are not allowed $this->_errors[] = $this->l('You must select at least one card type.'); continue; } } elseif ($key === 'PAYZEN_ONEY_SHIP_OPTIONS') { if (!is_array($value) || empty($value)) { $value = array(); } else { foreach ($value as $id => $option) { $carrier = $option['carrier_label'] . ($option['address'] ? ' ' . $option['address'] : ''); if (!preg_match(self::DELIVERY_COMPANY_REGEX, $carrier)) { unset($value[$id]['address']); // not save this option $this->_errors[] = sprintf($this->l('Invalid value "%s" for field "%s".'), $option['carrier_label'] . ' ' . $option['address'], $label); } } } $value = serialize($value); } elseif ($key === 'PAYZEN_ONEY_PROD_CAT') { if (!is_array($value) || empty($value)) { $value = array(); } $value = serialize($value); } elseif ($key === 'PAYZEN_ONEY_ENABLED' && $value == 'True') { $oneyErrors = $this->_validateOney(); if (is_array($oneyErrors) && !empty($oneyErrors)) { $this->_errors = array_merge($this->_errors, $oneyErrors); $value = 'False'; // there is errors, not allow Oney activation } } elseif (in_array($key, $this->_amountFields)) { if (!empty($value) && (!is_numeric($value) || $value < 0)) { $this->_errors[] = sprintf($this->l('Invalid value "%s" for field "%s".'), $value, $label); continue; } } elseif ($key === 'PAYZEN_STD_CARD_DATA_MODE' && $value == '3' && !$this->_checkSsl()) { $value = '1'; $this->_errors[] = $this->l('The card data entry on merchant site cannot be used without enabling SSL.'); } // validate with PayzenApi if (key_exists('name', $param) && isset($param['name']) && !$api->set($param['name'], $value)) { if (empty($value)) { $this->_errors[] = sprintf($this->l('The field "%s" is mandatory.'), $label); } else { $this->_errors[] = sprintf($this->l('Invalid value "%s" for field "%s".'), $value, $label); } continue; } // valid field : try to save into DB if (!Configuration::updateValue($key, $value)) { $this->_errors[] = sprintf($this->l('Problem occured while saving field "%s".'), $label); } else { // temporary variable set to update PrestaShop cache Configuration::set($key, $value); } } }
/** * 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 }
/** * Constructor. */ function PayzenMultiApi($encoding = "UTF-8") { // call parent class constructor parent::PayzenApi($encoding); }