public function after_process() { global $config; if (empty($_POST)) { $fap = json_decode(file_get_contents("php://input")); $_POST = array(); foreach ($fap as $key => $val) { $_POST[$key] = $val; } } list($order_id, ) = explode(fondycsl::ORDER_SEPARATOR, $_POST['order_id']); $payment_method = $this->PaymentMethod->find('first', array('conditions' => array('alias' => $this->module_name))); $order_data = $this->Order->find('first', array('conditions' => array('Order.id' => $order_id))); //print_r ($order_data);die; $fondy_merchant_id = $this->PaymentMethod->PaymentMethodValue->find('first', array('conditions' => array('key' => 'fondy_merchant_id'))); $merchant_id = $fondy_merchant_id['PaymentMethodValue']['value']; $fondy_secret_key = $this->PaymentMethod->PaymentMethodValue->find('first', array('conditions' => array('key' => 'fondy_secret_key'))); $secret_key = $fondy_secret_key['PaymentMethodValue']['value']; $options = array('merchant' => $merchant_id, 'secretkey' => $secret_key); $paymentInfo = fondycsl::isPaymentValid($options, $_POST); if ($order_data) { if ($paymentInfo === true && $_POST['order_status'] == fondycsl::ORDER_APPROVED) { // print_r ($paymentInfo); die; $order_data['Order']['order_status_id'] = $payment_method['PaymentMethod']['order_status_id']; $this->Order->save($order_data); //$this->Session->setFlash($_POST[order_status]); } else { //print_r($_POST);die; $_SESSION['fondy_id'] = $_POST[order_id]; $_SESSION['fondy_desc'] = $_POST[response_description]; $_SESSION['fondy_error'] = $_POST[response_code]; $this->redirect('/page/Fondy' . $config['URL_EXTENSION']); die; } } }
echo 'error'; } } } } else { echo 'Order status already updated'; } } else { // echo 2; list($order_id, ) = explode(fondycsl::ORDER_SEPARATOR, $_POST['order_id']); $order = $simpla->orders->get_order(intval($order_id)); $payment_method = $simpla->payment->get_payment_method($order->payment_method_id); $payment_currency = $simpla->money->get_currency(intval($payment_method->currency_id)); $settings = $simpla->payment->get_payment_settings($payment_method->id); $options = array('merchant' => $settings['fondy_merchantid'], 'secretkey' => $settings['fondy_secret']); $paymentInfo = fondycsl::isPaymentValid($options, $_POST); if (!$order->paid) { if ($_POST['amount'] / 100 >= round($simpla->money->convert($order->total_price, $payment_method->currency_id, false), 2)) { if ($paymentInfo === true) { if ($_POST['order_status'] == fondycsl::ORDER_APPROVED) { // Установим статус оплачен $simpla->orders->update_order(intval($order->id), array('paid' => 1)); // Отправим уведомление на email $simpla->notify->email_order_user(intval($order->id)); $simpla->notify->email_order_admin(intval($order->id)); // Спишем товары $simpla->orders->close(intval($order->id)); $invoice['status'] = $_POST[order_status]; $invoice['transaction'] = $_POST['order_id']; $invoice['system'] = 'fondy'; $invoice['amount'] = $_POST['amount'] / 100 . " " . $_POST['actual_currency'];