/** * Returns the HTML code for the Yellowpay payment method. * * @param array $data post data from the user * * @return string HTML code */ function _yellowpay($data = array()) { global $_ARRAYLANG; $objSettings = new \Cx\Modules\Calendar\Controller\CalendarSettings(); $arrCalendarSettings = $objSettings->getYellowpaySettings(); $arrOrder = array('ORDERID' => $data['orderID'], 'AMOUNT' => $data['amount'], 'CURRENCY' => $data['currency'], 'PARAMPLUS' => "section=Calendar&cmd=success&handler=yellowpay"); $arrSettings = array(); $arrSettings['postfinance_shop_id']['value'] = $arrCalendarSettings['paymentYellowpayPspid']; $arrSettings['postfinance_hash_signature_in']['value'] = $arrCalendarSettings['paymentYellowpayShaIn']; $arrSettings['postfinance_authorization_type']['value'] = $arrCalendarSettings['paymentYellowpayAuthorization'] == 0 ? 'SAL' : 'RES'; $arrSettings['postfinance_use_testserver']['value'] = $arrCalendarSettings['paymentTestserver']; $landingPage = \Env::get('em')->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Page')->findOneByModuleCmdLang('Calendar', 'success', FRONTEND_LANG_ID); $yellowpayForm = \Yellowpay::getForm($arrOrder, $_ARRAYLANG['TXT_CALENDAR_START_PAYMENT'], false, $arrSettings, $landingPage); if (_PAYMENT_DEBUG && \Yellowpay::$arrError) { $strError = '<font color="red"><b>' . $_ARRAYLANG['TXT_SHOP_PSP_FAILED_TO_INITIALISE_YELLOWPAY'] . '<br /></b>'; if (_PAYMENT_DEBUG) { $strError .= join('<br />', \Yellowpay::$arrError); //.'<br />'; } return $strError . '</font>'; } return $yellowpayForm; }
/** * Handles any kind of database errors * * Includes updating the payments table (I guess from version 1.2.0(?), * note that this is unconfirmed) to the current structure * @return boolean False. Always. * @throws Cx\Lib\Update_DatabaseException */ static function errorHandler() { // Payment // Fix the Text and Zones tables first \Text::errorHandler(); Zones::errorHandler(); \Yellowpay::errorHandler(); $table_name = DBPREFIX . 'module_shop_payment'; $table_structure = array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'auto_increment' => true, 'primary' => true), 'processor_id' => array('type' => 'INT(10)', 'unsigned' => true, 'default' => '0'), 'fee' => array('type' => 'DECIMAL(9,2)', 'unsigned' => true, 'default' => '0', 'renamefrom' => 'costs'), 'free_from' => array('type' => 'DECIMAL(9,2)', 'unsigned' => true, 'default' => '0', 'renamefrom' => 'costs_free_sum'), 'ord' => array('type' => 'INT(5)', 'unsigned' => true, 'default' => '0', 'renamefrom' => 'sort_order'), 'active' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'default' => '1', 'renamefrom' => 'status')); $table_index = array(); $default_lang_id = \FWLanguage::getDefaultLangId(); if (\Cx\Lib\UpdateUtil::table_exist($table_name)) { if (\Cx\Lib\UpdateUtil::column_exist($table_name, 'name')) { // Migrate all Payment names to the Text table first \Text::deleteByKey('Shop', self::TEXT_NAME); $query = "\n SELECT `id`, `name`\n FROM `{$table_name}`"; $objResult = \Cx\Lib\UpdateUtil::sql($query); if (!$objResult) { throw new \Cx\Lib\Update_DatabaseException("Failed to query Payment names", $query); } while (!$objResult->EOF) { $id = $objResult->fields['id']; $name = $objResult->fields['name']; if (!\Text::replace($id, $default_lang_id, 'Shop', self::TEXT_NAME, $name)) { throw new \Cx\Lib\Update_DatabaseException("Failed to migrate Payment name '{$name}'"); } $objResult->MoveNext(); } } } \Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index); // Update Payments that use obsolete PSPs: // - 05, 'Internal_CreditCard' // - 06, 'Internal_Debit', // Uses 04, Internal \Cx\Lib\UpdateUtil::sql("UPDATE {$table_name}\n SET `processor_id`=4 WHERE `processor_id` IN (5, 6)"); // - 07, 'Saferpay_Mastercard_Multipay_CAR', // - 08, 'Saferpay_Visa_Multipay_CAR', // Uses 01, Saferpay \Cx\Lib\UpdateUtil::sql("UPDATE {$table_name}\n SET `processor_id`=1 WHERE `processor_id` IN (7, 8)"); $table_name = DBPREFIX . 'module_shop_rel_payment'; $table_structure = array('payment_id' => array('type' => 'INT(10)', 'unsigned' => true, 'default' => '0', 'primary' => true), 'zone_id' => array('type' => 'INT(10)', 'unsigned' => true, 'default' => '0', 'primary' => true, 'renamefrom' => 'zones_id')); $table_index = array(); \Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index); // Always return false; }
/** * Display the success page * * @return null */ function showSuccessPage() { $this->_objTpl->setTemplate($this->pageContent, true, true); if ($_REQUEST["handler"] == "yellowpay") { $orderId = \Yellowpay::getOrderId(); $this->getSettings(); if (\Yellowpay::checkin($this->arrSettings["paymentYellowpayShaOut"])) { switch (abs($_REQUEST["result"])) { case 2: // fehler aufgetreten $objRegistration = new \Cx\Modules\Calendar\Controller\CalendarRegistration(null); $objRegistration->delete($orderId); $this->_objTpl->touchBlock("cancelMessage"); break; case 1: // erfolgreich $objRegistration = new \Cx\Modules\Calendar\Controller\CalendarRegistration(null); $objRegistration->get($orderId); $objRegistration->setPaid(1); $this->_objTpl->touchBlock("successMessage"); break; case 0: // abgebrochen $objRegistration = new \Cx\Modules\Calendar\Controller\CalendarRegistration(null); $objRegistration->delete($orderId); $this->_objTpl->touchBlock("cancelMessage"); break; default: \Cx\Core\Csrf\Controller\Csrf::redirect("index.php?section=" . $this->moduleName); break; } } else { \Cx\Core\Csrf\Controller\Csrf::redirect("index.php?section=" . $this->moduleName); return; } } else { \Cx\Core\Csrf\Controller\Csrf::redirect("index.php?section=" . $this->moduleName); return; } }
/** * Evaluate and register the payment result. * If the transaction was successful an email will be sent to the customer and administrator. * * @access private */ private function registerPaymentResult() { global $_ARRAYLANG, $_CONFIG, $objDatabase; $objSettingsYellowpay = new SettingsYellowpay($objDatabase); $arrYellowpay = $objSettingsYellowpay->get(); //evaluate payment result $status = ''; $orderId = \Yellowpay::getOrderId(); $arrTransaction = $this->objTransaction->get(array($orderId)); if (\Yellowpay::checkin($arrYellowpay['sha_out'])) { if (abs($_REQUEST['result']) == 1) { $status = self::CONFIRMED; if ($arrTransaction[0]['status'] == self::WAITING || $arrTransaction[0]['status'] == $status) { $this->arrStatusMessages['ok'][] = $_ARRAYLANG['TXT_CHECKOUT_TRANSACTION_WAS_SUCCESSFUL']; } if ($arrTransaction[0]['status'] == $status) { return; } } else { if ($_REQUEST['result'] == 0 || abs($_REQUEST['result']) == 2) { $status = self::CANCELLED; if ($arrTransaction[0]['status'] == self::WAITING || $arrTransaction[0]['status'] == $status) { $this->arrStatusMessages['error'][] = $_ARRAYLANG['TXT_CHECKOUT_TRANSACTION_WAS_CANCELLED']; } if ($arrTransaction[0]['status'] == $status) { return; } } else { $this->arrStatusMessages['error'][] = $_ARRAYLANG['TXT_CHECKOUT_INVALID_TRANSACTION_STATUS']; return; } } } else { $this->arrStatusMessages['error'][] = $_ARRAYLANG['TXT_CHECKOUT_SECURITY_CHECK_ERROR']; return; } if ($arrTransaction[0]['status'] == self::WAITING) { //update transaction status $this->objTransaction->updateStatus($orderId, $status); //send confirmation email (if the payment was successful) if ($status == self::CONFIRMED) { $arrTransaction = $this->objTransaction->get(array($orderId)); if (!empty($arrTransaction[0])) { //prepare transaction data for output $arrTransaction[0]['time'] = date('j.n.Y G:i:s', $arrTransaction[0]['time']); switch ($arrTransaction[0]['status']) { case self::WAITING: $arrTransaction[0]['status'] = $_ARRAYLANG['TXT_CHECKOUT_STATUS_WAITING']; break; case self::CONFIRMED: $arrTransaction[0]['status'] = $_ARRAYLANG['TXT_CHECKOUT_STATUS_CONFIRMED']; break; case self::CANCELLED: $arrTransaction[0]['status'] = $_ARRAYLANG['TXT_CHECKOUT_STATUS_CANCELLED']; break; } $arrTransaction[0]['invoice_currency'] = $this->arrCurrencies[$arrTransaction[0]['invoice_currency']]; $arrTransaction[0]['invoice_amount'] = number_format($arrTransaction[0]['invoice_amount'], 2, '.', '\''); switch ($arrTransaction[0]['contact_title']) { case self::MISTER: $arrTransaction[0]['contact_title'] = $_ARRAYLANG['TXT_CHECKOUT_CONTACT_TITLE_MISTER']; break; case self::MISS: $arrTransaction[0]['contact_title'] = $_ARRAYLANG['TXT_CHECKOUT_CONTACT_TITLE_MISS']; break; } //get mail templates $objSettingsMail = new SettingsMails($objDatabase); $arrAdminMail = $objSettingsMail->getAdminMail(); $arrCustomerMail = $objSettingsMail->getCustomerMail(); //fill up placeholders in mail templates $arrPlaceholders = array('DOMAIN_URL' => ASCMS_PROTOCOL . '://' . $_CONFIG['domainUrl'] . ASCMS_PATH_OFFSET, 'TRANSACTION_ID' => $arrTransaction[0]['id'], 'TRANSACTION_TIME' => $arrTransaction[0]['time'], 'TRANSACTION_STATUS' => $arrTransaction[0]['status'], 'INVOICE_NUMBER' => $arrTransaction[0]['invoice_number'], 'INVOICE_CURRENCY' => $arrTransaction[0]['invoice_currency'], 'INVOICE_AMOUNT' => $arrTransaction[0]['invoice_amount'], 'CONTACT_TITLE' => $arrTransaction[0]['contact_title'], 'CONTACT_FORENAME' => $arrTransaction[0]['contact_forename'], 'CONTACT_SURNAME' => $arrTransaction[0]['contact_surname'], 'CONTACT_COMPANY' => $arrTransaction[0]['contact_company'], 'CONTACT_STREET' => $arrTransaction[0]['contact_street'], 'CONTACT_POSTCODE' => $arrTransaction[0]['contact_postcode'], 'CONTACT_PLACE' => $arrTransaction[0]['contact_place'], 'CONTACT_COUNTRY' => $arrTransaction[0]['contact_country'], 'CONTACT_PHONE' => $arrTransaction[0]['contact_phone'], 'CONTACT_EMAIL' => $arrTransaction[0]['contact_email']); foreach ($arrPlaceholders as $placeholder => $value) { $arrAdminMail['title'] = str_replace('[[' . $placeholder . ']]', contrexx_raw2xhtml($value), $arrAdminMail['title']); $arrAdminMail['content'] = str_replace('[[' . $placeholder . ']]', contrexx_raw2xhtml($value), $arrAdminMail['content']); $arrCustomerMail['title'] = str_replace('[[' . $placeholder . ']]', contrexx_raw2xhtml($value), $arrCustomerMail['title']); $arrCustomerMail['content'] = str_replace('[[' . $placeholder . ']]', contrexx_raw2xhtml($value), $arrCustomerMail['content']); } //send mail to administrator and customer $this->sendConfirmationMail($_CONFIG['contactFormEmail'], $arrAdminMail); $this->sendConfirmationMail($arrTransaction[0]['contact_email'], $arrCustomerMail); } } exit; } }
static function getOrderId() { if (empty($_REQUEST['handler'])) { //DBG::log("PaymentProcessing::getOrderId(): No handler, fail"); return false; } switch ($_REQUEST['handler']) { case 'saferpay': return \Saferpay::getOrderId(); case 'paypal': return \PayPal::getOrderId(); case 'yellowpay': return \Yellowpay::getOrderId(); case 'payrexx': return \PayrexxProcessor::getOrderId(); // Added 20100222 -- Reto Kohli // Added 20100222 -- Reto Kohli case 'mobilesolutions': //DBG::log("getOrderId(): mobilesolutions"); $order_id = \PostfinanceMobile::getOrderId(); //DBG::log("getOrderId(): mobilesolutions, Order ID $order_id"); return $order_id; // Added 20081117 -- Reto Kohli // Added 20081117 -- Reto Kohli case 'datatrans': return \Datatrans::getOrderId(); // For the remaining types, there's no need to check in, so we // return true and jump over the validation of the order ID // directly to success! // Note: A backup of the order ID is kept in the session // for payment methods that do not return it. This is used // to cancel orders in all cases where false is returned. // For the remaining types, there's no need to check in, so we // return true and jump over the validation of the order ID // directly to success! // Note: A backup of the order ID is kept in the session // for payment methods that do not return it. This is used // to cancel orders in all cases where false is returned. case 'Internal': case 'Internal_CreditCard': case 'Internal_Debit': case 'Internal_LSV': case 'dummy': return isset($_SESSION['shop']['order_id_checkin']) ? $_SESSION['shop']['order_id_checkin'] : false; } // Anything else is wrong. return false; }
function paymentYellowpayVerify() { global $_ARRAYLANG; $result = isset($_REQUEST['result']) ? $_REQUEST['result'] : 0; $order_id = \Yellowpay::getOrderId(); if ($result < 0) { \Cx\Core\Setting\Controller\Setting::init('Egov', 'config'); if (\Yellowpay::checkIn(\Cx\Core\Setting\Controller\Setting::getValue('postfinance_hash_signature_out', 'Egov'))) { // Silently process yellowpay notifications and die(). if (abs($_REQUEST['result']) == 1) { $this->updateOrder($order_id); } } die; } $strReturn = ''; if ($order_id) { $order_id = intval($_REQUEST['order_id']); $product_id = self::GetOrderValue('order_product', $order_id); if (empty($product_id)) { $strReturn = 'alert("' . $_ARRAYLANG['TXT_EGOV_ERROR_PROCESSING_ORDER'] . "\");\n"; } $status = self::GetOrderValue('order_state', $order_id); switch ($status) { case 1: // The payment has been completed. // The direct payment notification (with result == -1) has // successfully caused the order to be updated. // Show an appropriate message, and optionally redirect // the customer. $product_id = self::GetOrderValue('order_product', $order_id); return self::getSuccessMessage($product_id); break; // Not applicable: // Mind that the payment result (cancelled or failed) is not // available outside of the direct payment request from // PostFinance! Thus, this outcome is never encountered. // Not applicable: // Mind that the payment result (cancelled or failed) is not // available outside of the direct payment request from // PostFinance! Thus, this outcome is never encountered. case 0: case 2: default: // Payment failed, or has been cancelled $strReturn = 'alert("' . $_ARRAYLANG['TXT_EGOV_YELLOWPAY_CANCEL'] . "\");\n"; } } return $strReturn . 'document.location.href="' . $_SERVER['PHP_SELF'] . "?section=Egov\";\n"; }
/** * Handles and fixes database related problems * @return boolean False. Always. */ static function errorHandler() { \Yellowpay::errorHandler(); // Also calls \Cx\Core\Setting\Controller\Setting::errorHandler() foreach (array('postfinance_accepted_payment_methods' => 'yellowpay_accepted_payment_methods', 'postfinance_shop_id' => 'yellowpay_shopid', 'postfinance_hash_signature_in' => 'yellowpay_hashseed', 'postfinance_hash_signature_out' => 'yellowpay_hashseed', 'postfinance_authorization_type' => 'yellowpay_authorization', 'postfinance_use_testserver' => 'yellowpay_use_testserver') as $to => $from) { $value = EgovLibrary::GetSettings($from); //DBG::log("EgovLibrary::errorHandler(): Copying from $from, value $value, to $to<br />"); \Cx\Core\Setting\Controller\Setting::set($to, $value); } \Cx\Core\Setting\Controller\Setting::updateAll(); }
/** * Creates and returns the HTML Form for requesting the payment service. * * The parameters in $uriparam are appended to the base index URI. * If empty, this defaults to "section=Shop&cmd=success". * * @access public * @global array $_ARRAYLANG * @param array $arrFields The parameter array * @param string $submitValue The optional label for the submit button * @param boolean $autopost If true, the form is automatically submitted. Defaults to false. * @param array $arrSettings Settings from \Cx\Core\Setting * @param object $landingPage The optional URI parameter string * @return string The HTML form code */ static function getForm($arrFields, $submitValue = 'Send', $autopost = false, $arrSettings = null, $landingPage = null) { global $_ARRAYLANG; if (gettype($landingPage) != 'object' || get_class($landingPage) != 'Cx\\Core\\ContentManager\\Model\\Entity\\Page') { self::$arrError[] = 'No landing page passed.'; } if (($sectionName = $landingPage->getModule()) && !empty($sectionName)) { self::$sectionName = $sectionName; } else { self::$arrError[] = 'Passed landing page is not an application.'; } if (empty($arrSettings)) { $settingDb = \Cx\Core\Setting\Controller\Setting::getArray(self::$sectionName, 'config'); if (!empty($settingDb) && $settingDb['postfinance_active']['value']) { $arrSettings = $settingDb; } else { self::$arrError[] = "Could not load settings."; } } if (empty($arrFields['PSPID'])) { $arrFields['PSPID'] = $arrSettings['postfinance_shop_id']['value']; } if (empty($arrFields['OPERATION'])) { $arrFields['OPERATION'] = $arrSettings['postfinance_authorization_type']['value']; } if (empty($arrFields['LANGUAGE'])) { $arrFields['LANGUAGE'] = strtolower(FWLanguage::getLanguageCodeById(FRONTEND_LANG_ID)) . '_' . strtoupper(FWLanguage::getLanguageCodeById(FRONTEND_LANG_ID)); } $baseUri = Cx\Core\Routing\Url::fromPage($landingPage)->toString() . '?result='; if (empty($arrFields['ACCEPTURL'])) { $arrFields['ACCEPTURL'] = $baseUri . '1'; } if (empty($arrFields['DECLINEURL'])) { $arrFields['DECLINEURL'] = $baseUri . '2'; } if (empty($arrFields['EXCEPTIONURL'])) { $arrFields['EXCEPTIONURL'] = $baseUri . '2'; } if (empty($arrFields['CANCELURL'])) { $arrFields['CANCELURL'] = $baseUri . '0'; } if (empty($arrFields['BACKURL'])) { $arrFields['BACKURL'] = $baseUri . '2'; } if (!self::setFields($arrFields)) { self::$arrError[] = 'Failed to verify keys.'; return false; } $arrFields['SHASIGN'] = self::signature($arrFields, $arrSettings['postfinance_hash_signature_in']['value']); $server = $arrSettings['postfinance_use_testserver']['value'] ? 'test' : 'prod'; $charset = CONTREXX_CHARSET == 'UTF-8' ? '_utf8' : ''; $hiddenFields = ''; foreach ($arrFields as $name => $value) { $hiddenFields .= Html::getHidden($name, $value); } $autoSubmit = !$autopost ? '' : ' <script type="text/javascript"> /* <![CDATA[ */ document.yellowpay.submit(); /* ]]> */ </script> '; $form = $_ARRAYLANG['TXT_ORDER_LINK_PREPARED'] . '<br/><br/>' . '<form name="yellowpay" method="post" action="https://e-payment.postfinance.ch/ncol/' . $server . '/orderstandard' . $charset . '.asp">' . $hiddenFields . '<input type="submit" name="go" value="' . $submitValue . '" />' . '</form>' . $autoSubmit; return $form; }