protected function _toHtml() { // echo "<pre>"; // echo "Response\n"; // print_r($_POST);die; // return var_export($_POST, true); include_once "Fondy.cls.php"; $fodny = Mage::getModel('FondyOnPage/FondyOnPage'); $settings = array('merchant_id' => $fodny->getConfigData('merchant'), 'secret_key' => $fodny->getConfigData('secret_key')); try { $validated = FondyForm::isPaymentValid($settings, $_POST); if ($validated === true) { //if ($_POST[]) list($orderId, ) = explode(FondyForm::ORDER_SEPARATOR, $_POST['order_id']); // Payment was successful, so update the order's state, send order email and move to the success page $order = Mage::getModel('sales/order'); $order->loadByIncrementId($orderId); if ($fodny->getConfigData('after_pay_status') == Mage_Sales_Model_Order::STATE_PROCESSING) { $order->setState($fodny->getConfigData('after_pay_status'), true, 'Gateway has authorized the payment.'); } elseif ($fodny->getConfigData('after_pay_status') == Mage_Sales_Model_Order::STATE_HOLDED) { $order->setState($fodny->getConfigData('after_pay_status'), true, 'Gateway has authorized the payment.'); } else { $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, 'Gateway has authorized the payment.'); } $order->sendNewOrderEmail(); $order->setEmailSent(true); $order->save(); Mage::getSingleton('checkout/session')->unsQuoteId(); $url = Mage::getUrl('checkout/onepage/success', array('_secure' => true)); Mage::app()->getFrontController()->getResponse()->setRedirect($url); } else { // case all is valid but order is not approved $url = Mage::getUrl('checkout/onepage/success', array('_secure' => true)); Mage::app()->getFrontController()->getResponse()->setRedirect($url); } } catch (Exception $e) { // There is a problem in the response we got if (Mage::getSingleton('checkout/session')->getLastRealOrderId()) { $order = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId()); if ($order->getId()) { // Flag the order as 'cancelled' and save it $order->cancel()->setState(Mage_Sales_Model_Order::STATE_CANCELED, true, $e->getMessage())->save(); } } $url = Mage::getUrl('checkout/onepage/failure', array('_secure' => true)); Mage::app()->getFrontController()->getResponse()->setRedirect($url); } }
public static function isPaymentValid($oplataSettings, $response) { if ($oplataSettings['merchant_id'] != $response['merchant_id']) { return 'An error has occurred during payment. Merchant data is incorrect.'; } if ($response['order_status'] == FondyForm::ORDER_DECLINED) { Mage::throwException('An error has occurred during payment. Order is declined.'); } $responseSignature = $response['signature']; unset($response['response_signature_string']); unset($response['signature']); if (FondyForm::getSignature($response, $oplataSettings['secret_key']) != $responseSignature) { return 'An error has occurred during payment. Signature is not valid.'; } return true; }
public function getFormFields() { $order_id = $this->getCheckout()->getLastRealOrderId(); $order = Mage::getModel('sales/order')->loadByIncrementId($order_id); $amount = round($order->getGrandTotal() * 100, 2); $customer = Mage::getSingleton('customer/session')->getCustomer(); $checkout = Mage::getSingleton('checkout/session')->getCustomer(); $quote = Mage::getSingleton('checkout/session')->getQuote(); $email = $customer->getEmail(); $email = isset($email) ? $email : $quote->getBillingAddress()->getEmail(); $email = isset($email) ? $email : $order->getCustomerEmail(); $fields = array('order_id' => $order_id . FondyForm::ORDER_SEPARATOR . time(), 'merchant_id' => $this->getConfigData('merchant'), 'order_desc' => 'Order number' . $order_id, 'amount' => $amount, 'currency' => $this->getConfigData('currency'), 'server_callback_url' => $this->getConfigData('back_ref'), 'response_url' => $this->getConfigData('back_ref'), 'lang' => $this->getConfigData('language'), 'sender_email' => $email); $fields['signature'] = FondyForm::getSignature($fields, $this->getConfigData('secret_key')); $params = array('button' => $this->getButton(), 'fields' => $fields); return $params; }
function sendToFondy(&$order) { global $pmpro_currency; global $wpdb; //taxes on initial amount $initial_payment = $order->InitialPayment; $initial_payment_tax = $order->getTaxForPrice($initial_payment); $initial_payment = round((double) $initial_payment + (double) $initial_payment_tax, 2); $fields = array('merchant_data' => 'name=' . $order->billing->name . '=phone=' . $order->billing->phone, 'product_id' => $order->membership_id, 'subscription_callback_url' => admin_url("admin-ajax.php") . "?action=fondy-ins", 'order_id' => $order->code . FondyForm::ORDER_SEPARATOR . time(), 'merchant_id' => pmpro_getOption("fondy_merchantid"), 'order_desc' => substr($order->membership_level->name . " at " . get_bloginfo("name"), 0, 127), 'amount' => round($initial_payment * 100), 'currency' => $pmpro_currency, 'server_callback_url' => admin_url("admin-ajax.php") . "?action=fondy-ins", 'response_url' => admin_url("admin-ajax.php") . "?action=fondy-ins", 'sender_email' => $order->Email, 'required_rectoken' => 'Y', 'subscription' => 'Y'); $last_subscr_order = new MemberOrder(); //print_r ($order); $last = new MemberOrder($last_subscr_order->getLastMemberOrder($order->user_id, $status = 'success', $membership_id = NULL, $gateway = NULL, $gateway_environment = NULL)); if (isset($last->user_id) && isset($last->code)) { $result = $wpdb->get_row("SELECT fondy_token from `{$wpdb->pmpro_membership_orders}` WHERE user_id='" . $last->user_id . "' AND code='" . $last->code . "'"); if (isset($result->fondy_token)) { $fields['rectoken'] = $result->fondy_token; } } $fields['signature'] = FondyForm::getSignature($fields, pmpro_getOption("fondy_securitykey")); //print_r ($last->user_id);die; unset($fields['currency']); $data = 'currency=' . $pmpro_currency . '&'; foreach ($fields as $key => $val) { $data .= $key . "=" . $val . '&'; } $url = 'https://api.fondy.eu/api/checkout/url/'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://api.fondy.eu/api/checkout/url/'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $result = curl_exec($ch); $str = urldecode($result); parse_str($str, $mass); $fondy_url = $mass['checkout_url']; wp_redirect($fondy_url); exit; }
exit(header("Location: /")); } global $SysValue, $link_db; // Определение платежной системы по $_GET['payment'] if (!empty($_REQUEST['payment'])) { if ($_REQUEST['payment'] == 'fondy') { if (empty($_POST)) { $fap = json_decode(file_get_contents("php://input")); $_POST = array(); foreach ($fap as $key => $val) { $_POST[$key] = $val; } } $settings['merchant_id'] = $SysValue['fondy']['fondy_merchant_id']; $settings['secret_key'] = $SysValue['fondy']['fondy_secret_key']; $valid = FondyForm::isPaymentValid($settings, $_POST); if ($valid == true && $_POST['order_status'] == FondyForm::ORDER_APPROVED) { $order_metod = "fondy"; $success_function = true; // Выключаем функцию обновления статуса заказа, операция уже выполнена в result.php $my_crc = "NoN"; $crc = "NoN"; $inv_id = $_GET['inv_id']; } else { WriteLog($valid); } } } function WriteLog($MY_LMI_HASH) { $handle = fopen("../paymentlog.log", "a+");
function pmpro_fondyValidate() { $settings = array('merchant_id' => pmpro_getOption("fondy_merchantid"), 'secret_key' => pmpro_getOption("fondy_securitykey")); $validated = FondyForm::isPaymentValid($settings, $_POST); if ($validated != true) { return $validated; } else { return true; } }
$fields['order_desc'] = "Order:" . $mrh_ouid[0] . $mrh_ouid[1]; $inv_id = $mrh_ouid[0] . "" . $mrh_ouid[1]; $url = ($_SERVER['HTTPS'] ? 'https://' : 'http://') . $_SERVER['HTTP_HOST']; $success_url = "{$url}/success/?inv_id=" . $inv_id . '&payment=fondy'; $fields['server_callback_url'] = $success_url; $fields['response_url'] = $success_url; // вывод HTML страницы с кнопкой для оплаты if ($SysValue['fondy']['fondy_on_page'] == 0) { $fields['amount'] = round($GLOBALS['SysValue']['other']['total'] * 100); //сумма покупки $signature = FondyForm::getSignature($fields, $secret_key); $disp = "\n\t<div align='center'>\n\t<head>\n\t<meta charset='utf-8'>\n\t</head>\n\t\t<form name='tocheckout' method='POST' action='https://api.fondy.eu/api/checkout/redirect/' >\n\t\t\t<input type=hidden name='merchant_id' value='" . $fields['merchant_id'] . "'>\n\t\t\t<input type=hidden name='order_id' value='" . $fields['order_id'] . "'>\n\t\t\t<input type=hidden name='order_desc' value='" . $fields['order_desc'] . "'>\n\t\t\t<input type=hidden name='signature' value='" . $signature . "'>\n\t\t\t<input type=hidden name='amount' value='" . $fields['amount'] . "'>\n\t\t\t<input type=hidden name='lang' value='" . $fields['lang'] . "'>\n\t\t\t<input type=hidden name='currency' value='" . $fields['currency'] . "'>\n\t\t\t<input type=hidden name='response_url' value='" . $fields['response_url'] . "'>\n\t\t\t<input type=hidden name='server_callback_url' value='" . $fields['server_callback_url'] . "'>\n\t\t\t<input type='submit' id='submit_fondy_payment_form' />\n\t<script type='text/javascript'>\n\tdocument.getElementById('submit_fondy_payment_form').click();\n\t</script>\n\t\t</form>\n\t</div>"; } else { $fields['amount'] = $GLOBALS['SysValue']['other']['total']; //сумма покупки $signature = FondyForm::getSignature($fields, $secret_key); $disp = '<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script> <script src="https://api.fondy.eu/static_common/v1/checkout/ipsp.js"></script> <div id="checkout"> <div id="checkout_wrapper"></div> </div> <script> var checkoutStyles = { "html , body" : { "overflow" : "hidden" }, ".col.col-shoplogo" : { "display" : "none" }, ".col.col-language" : { "display" : "none"