/** * Create an instance * @since version 1.0.2 * @access public * @return instance of self */ public static function getInstance() { if (!self::$instance) { self::$instance = new self(); } return self::$instance; }
/** * Handler when cart/icepay_result is callback * * @return string */ public function runPageCartResult() { $logger = \Icepay_Api_Logger::getInstance(); $logger->enableLogging()->setLoggingLevel(\Icepay_Api_Logger::LEVEL_ERRORS_AND_TRANSACTION)->logToFunction("logWrapper", "log"); $config = \Drupal::config("uc_icepay.settings"); /* postback */ if ($_SERVER['REQUEST_METHOD'] == 'POST') { $icepay = \Icepay_Project_Helper::getInstance()->postback(); $icepay->setMerchantID($config->get("merchant_id"))->setSecretCode($config->get("secret_code"))->doIPCheck(true); if ($config->get("ipcheck") && $config->get("ipcheck_list") != '') { $ipRanges = explode(",", $config->get("ipcheck_list")); foreach ($ipRanges as $ipRange) { $ip = explode("-", $ipRange); $icepay->setIPRange($ip[0], $ip[1]); } } if ($icepay->validate()) { $data = $icepay->GetPostback(); $orderID = $data->reference; $order = uc_order_load($orderID); if (!$order) { return t("Order not exists"); } $firstPostback = Database::getConnection()->select('uc_payment_icepay', 'i')->fields('i', array('transaction_id'))->condition('transaction_id', $data->transactionID, '=')->execute()->fetchAssoc(); $paymentDetails = IcepayApi::getPaymentDetailsByOrderId($orderID); if ($icepay->canUpdateStatus($paymentDetails->icepay_status)) { $order->icepay_status = $data->status; $order->transaction_id = $data->transactionID; IcepayApi::enterPayment($order); // updating order status, this one is deprecated //uc_order_update_status($orderID, IcepayApi::getUbercartStatusCode($data->status)); // updating order status, using direct save into order $order->setStatusId(IcepayApi::getUbercartStatusCode($data->status))->save(); } // adding new comment order uc_order_comment_save($orderID, 1, t($data->statusCode), 'order', IcepayApi::getUbercartStatusCode($data->status), true); // need to save into order payment if postback from Icepay is confirming payment received // @see Drupal/uc_payment/Form/OrderPaymentsForm::submitForm() if (strtoupper($data->status) == "OK" || strtoupper($data->status) == "REFUND") { $orderTotal = $order->getTotal(); // when refund, means order total is requested back if (strtoupper($data->status) == "REFUND") { $orderTotal *= -1; } uc_payment_enter($orderID, $paymentDetails->payment_method, $orderTotal, \Drupal::currentUser()->id(), '', $data->statusCode, REQUEST_TIME); } // best to record this into watch log // https://drupalize.me/blog/201510/how-log-messages-drupal-8 \Drupal::logger('uc_icepay')->info('Icepay Postback :: ' . $data->statusCode); // need to send notification due to order status update if (isset($firstPostback['transaction_id'])) { // this rules invoke to send order status update by email is deprecated //rules_invoke_event('uc_order_status_email_update', $order); } } else { if ($icepay->isVersionCheck()) { $dump = array("module" => sprintf(t("Version %s using PHP API 2 version %s"), ICEPAY_VERSION, Icepay_Project_Helper::getInstance()->getReleaseVersion()), "notice" => "Checksum validation passed!"); if ($icepay->validateVersion()) { $name = "uc_cart"; $path = drupal_get_path('module', $name) . '/' . $name . '.info'; $data = drupal_parse_info_file($path); $dump["additional"] = array("Drupal" => VERSION, "Ubercart" => $data["version"]); } else { $dump["notice"] = "Checksum failed! Merchant ID and Secret code probably incorrect."; } var_dump($dump); exit; } } return t("Postback script functions properly"); } else { $icepay = \Icepay_Project_Helper::getInstance()->result(); $icepay->setMerchantID($config->get("merchant_id"))->setSecretCode($config->get("secret_code")); if (!$icepay->validate()) { $data = $icepay->getResultData(); //$output = $data->statusCode; //return $output; drupal_set_message($data->statusCode, 'error'); $response = new RedirectResponse(\Drupal::url('uc_cart.checkout')); $response->send(); } else { $data = $icepay->getResultData(); if ($data->status == 'ERR') { //$output = $data->statusCode; //return $output; drupal_set_message($data->statusCode, 'error'); return new RedirectResponse(\Drupal::url('uc_cart.checkout')); } $order = uc_order_load($data->reference); if (!$order) { return t("Order with id :orderId not exist", array(":orderId" => $data->reference)); } $session = \Drupal::service('session'); if (!$session->get('cart_order')) { drupal_set_message(t("Cart is currently empty."), 'error'); return new RedirectResponse(\Drupal::url('uc_cart.checkout')); } //$order->icepay_status = \ICEPAY_STATUSCODE::SUCCESS; $order->icepay_status = $data->status; $order->transaction_id = $data->transactionID; IcepayApi::enterPayment($order); // update order status $order->setStatusId(IcepayApi::getUbercartStatusCode($data->status))->save(); $_SESSION['uc_checkout'][$session->get('cart_order')]['do_complete'] = TRUE; // $response = new RedirectResponse(Url::fromRoute('uc_cart.checkout_complete')->toString()); // $response->send(); return new RedirectResponse(\Drupal::url('uc_cart.checkout_complete')); } } }