Ejemplo n.º 1
0
 function ProcessResult()
 {
     $webhook = new \beGateway\Webhook();
     if (!$webhook->isAuthorized() || !$webhook->isSuccess() || $this->_shopOrder->paid || is_null($order_id = intval(Core_Array::getRequest('order_id'))) || $order_id != $webhook->getTrackingId()) {
         return FALSE;
     }
     $sum = $this->getSumWithCoeff();
     $oShop_Currency = Core_Entity::factory('Shop_Currency')->find($this->_begateway_currency_id);
     /* конвертировать RUR код в RUB */
     $currency = $oShop_Currency->code;
     $currency = $currency == 'RUR' ? 'RUB' : $currency;
     $money = new \beGateway\Money();
     $money->setCurrency($currency);
     $money->setAmount($sum);
     if ($money->getCents() == $webhook->getResponse()->transaction->amount && $currency == $webhook->getResponse()->transaction->currency) {
         $this->shopOrderBeforeAction(clone $this->_shopOrder);
         $result = array("Товар оплачен.", "Атрибуты:", "Номер сайта продавца: " . $this->_shop_id, "Внутренний номер покупки продавца: " . $this->_shopOrder->id, "Сумма платежа: " . $sum, "Валюта платежа: " . $oShop_Currency->code, "UID платежа: " . $webhook->getUid(), "Способ оплаты: " . $webhook->getPaymentMethod(), "Статус платежа: успешно");
         if (isset($webhook->getResponse()->transaction->three_d_secure_verification)) {
             $result[] = "3-D Secure: " . $webhook->getResponse()->transaction->three_d_secure_verification->pa_status;
         }
         $this->_shopOrder->system_information = implode($result, "\n");
         $this->_shopOrder->paid();
         $this->setXSLs();
         $this->send();
         ob_start();
         $this->changedOrder('changeStatusPaid');
         ob_get_clean();
     }
 }
 private function _processWebhook()
 {
     $webhook = new \beGateway\Webhook();
     if ($webhook->isAuthorized() && ($webhook->isSuccess() || $webhook->isFailed())) {
         $Status = $webhook->getStatus();
         $Currency = $webhook->getResponse()->transaction->currency;
         $Amount = new \beGateway\Money();
         $Amount->setCurrency($Currency);
         $Amount->setCents($webhook->getResponse()->transaction->amount);
         $TransId = $webhook->getUid();
         $orderno = $webhook->getTrackingId();
         $cart = new Cart((int) $orderno);
         if (!Validate::isLoadedObject($cart)) {
             Logger::addLog($this->l('Webhook: error to load cart'), 4);
             die($this->l('Critical error to load order cart'));
         }
         $customer = new Customer((int) $cart->id_customer);
         if (!Validate::isLoadedObject($customer)) {
             Logger::addLog($this->l('Webhook: error to load customer details'), 4);
             die($this->l('Critical error to load customer'));
         }
         $shop_ptype = trim(Configuration::get('BEGATEWAY_SHOP_PAYTYPE'));
         $payment_status = $webhook->isSuccess() ? Configuration::get('PS_OS_PAYMENT') : Configuration::get('PS_OS_ERROR');
         $this->be_gateway->validateOrder((int) $orderno, $payment_status, $Amount->getAmount(), $this->be_gateway->displayName, $webhook->getMessage(), array('transaction_id' => $TransId), NULL, false, $customer->secure_key);
         $order_new = empty($this->be_gateway->currentOrder) ? $orderno : $this->be_gateway->currentOrder;
         Db::getInstance()->Execute('
     INSERT INTO ' . _DB_PREFIX_ . 'begateway_transaction (type, id_begateway_customer, id_cart, id_order,
       uid, amount, status, currency, date_add)
       VALUES ("' . $shop_ptype . '", ' . $cart->id_customer . ', ' . $orderno . ', ' . $order_new . ', "' . $TransId . '", ' . $Amount->getAmount() . ', "' . $Status . '", "' . $Currency . '", NOW())');
         die('OK');
     }
 }
Ejemplo n.º 3
0
	public function executeComponent()
	{
		global $APPLICATION;

		try {
      # verify token is valid
			$token = $this->checkToken();

      # locate order and its payment system
      $order_id = $_REQUEST['order_id'];
      $payment_id = $_REQUEST['payment_id'];
      $uid = $_REQUEST['uid'];
      $order = Order::load($order_id);

      if (!$order)
        throw new Exception( Loc::getMessage("COMPONENT_BEGATEWAY_WRONG_ORDER_ID") . $order_id);

      $payment = $order->getPaymentCollection()->getItemById($payment_id);

      if (!$payment)
        throw new Exception( Loc::getMessage("COMPONENT_BEGATEWAY_WRONG_PAYMENT_ID") . $payment_id);

      $arOrder = CSaleOrder::GetByID($order_id);
      CSalePaySystemAction::InitParamArrays($arOrder, $arOrder["ID"], '', array(), $payment->getFieldValues());

      \beGateway\Settings::$shopId = CSalePaySystemAction::GetParamValue("SHOP_ID");
      \beGateway\Settings::$shopKey = CSalePaySystemAction::GetParamValue("SHOP_KEY");
      \beGateway\Settings::$gatewayBase = "https://" . CSalePaySystemAction::GetParamValue("DOMAIN_GATEWAY");
      \beGateway\Settings::$checkoutBase = "https://" . CSalePaySystemAction::GetParamValue("DOMAIN_PAYMENT_PAGE");

			$query = new \beGateway\QueryByToken();
			$query->setToken($token);
			$response = $query->submit()->getResponse();

			if( ! isset( $response->checkout ) )
				throw new Exception( Loc::getMessage("COMPONENT_BEGATEWAY_FAIL_TOKEN_QUERY") );

      # verify token matches uid
			$this->arResult = $response->checkout;
      $type = $this->arResult->transaction_type;

      if (! isset($this->arResult->gateway_response))
        throw new Exception( Loc::getMessage("COMPONENT_BEGATEWAY_NO_TRANS_INFO") );

      if ($this->arResult->gateway_response->$type->uid != $uid)
          throw new Exception( Loc::getMessage("COMPONENT_BEGATEWAY_NO_UID_TOKEN_ACCESS") );

      if ($this->arResult->order->tracking_id != $order_id . ':' . $payment_id)
				throw new Exception( Loc::getMessage("COMPONENT_BEGATEWAY_WRONG_TRACKING_ID") );

      $money = new \beGateway\Money;
      $money->setCents($response->checkout->order->amount);
      $money->setCurrency($response->checkout->order->currency);

			$response->checkout->order->amount = CCurrencyLang::CurrencyFormat( $money->getAmount(), $money->getCurrency() );

      $this->arResult->order->description = $APPLICATION->ConvertCharset($this->arResult->order->description, 'utf-8', SITE_CHARSET);
      $this->arResult->gateway_response->$type->billing_descriptor = $APPLICATION->ConvertCharset($this->arResult->gateway_response->$type->billing_descriptor, SITE_CHARSET, 'utf-8');

			$this->IncludeComponentTemplate();

		} catch(Exception $e) {
			ShowError( $e->getMessage() );
		}
	}
Ejemplo n.º 4
0
\beGateway\Settings::$checkoutBase = "https://" . CSalePaySystemAction::GetParamValue("DOMAIN_PAYMENT_PAGE");

$payment_id = CSalePaySystemAction::GetParamValue("ORDER_PAYMENT_ID");
$order_id = IntVal($GLOBALS["SALE_INPUT_PARAMS"]["ORDER"]["ID"]);

$tracking_id = $order_id . ":" . $payment_id;

set_time_limit(0);

$query = new \beGateway\QueryByTrackingId;
$query->setTrackingId($tracking_id);

$response = $query->submit();

if ($response && $response != 'error') {
  $money = new \beGateway\Money;
  $money->setCurrency($response->getResponse()->transaction->currency);
  $money->setCents($response->getResponse()->transaction->amount);

	if($response->getTrackingId() == $tracking_id) {
		$arOrder = CSaleOrder::GetByID($order_id);
    $message = array();
    $message []= Loc::getMessage("SALE_BEGATEWAY_STATUS_MESSAGE_UID") . ' ' . $response->getUid(). ". " . Loc::getMessage("SALE_BEGATEWAY_STATUS_MESSAGE_TIME") . ' ' . $response->getResponse()->transaction->paid_at;

    if(isset($response->getResponse()->transaction->three_d_secure_verification->pa_status)) {
      $message[] = "3-D Secure: " .$response->getResponse()->transaction->three_d_secure_verification->pa_status;
    }
    $arFields = array(
      "PS_STATUS" => ($response->isSuccess() ? "Y" : "N"),
      "PS_STATUS_DESCRIPTION" => implode("\n",$message),
      "PS_SUM" => $money->getAmount(),
use Bitrix\Main\Localization\Loc;
Loc::loadMessages(__FILE__);
\beGateway\Settings::$shopId = (int) \Bitrix\Main\Config\Option::get($module_id, "shop_id");
\beGateway\Settings::$shopKey = \Bitrix\Main\Config\Option::get($module_id, "shop_key");
\beGateway\Settings::$gatewayBase = "https://" . \Bitrix\Main\Config\Option::get($module_id, "domain_gateway");
\beGateway\Settings::$checkoutBase = "https://" . \Bitrix\Main\Config\Option::get($module_id, "domain_payment_page");
$webhook = new \beGateway\Webhook();
list($site_id, $tracking_id) = explode('_', $webhook->getTrackingId());
$arOrder = CSaleOrder::GetByID($tracking_id);
if ($arOrder && $webhook->isAuthorized()) {
    if ($webhook->isSuccess() && $arOrder["PAYED"] != "Y") {
        CSaleOrder::PayOrder($arOrder["ID"], "Y");
        CSaleOrder::StatusOrder($arOrder["ID"], "P");
        $message = array();
        if (isset($webhook->getResponse()->transaction->three_d_secure_verification)) {
            $message[] = "3-D Secure: " . $webhook->getResponse()->transaction->three_d_secure_verification->pa_status;
        }
        $message[] = $webhook->getResponse()->transaction->description;
        $money = new \beGateway\Money();
        $money->setCurrency($webhook->getResponse()->transaction->currency);
        $money->setCents($webhook->getResponse()->transaction->amount);
        $arFields = array("PS_STATUS" => "Y", "PS_STATUS_MESSAGE" => implode("\n", $message), "PS_SUM" => $money->getAmount(), "PS_CURRENCY" => $webhook->getResponse()->transaction->currency, "PS_RESPONSE_DATE" => date("d.m.Y H:i:s", strtotime($webhook->getResponse()->transaction->created_at)), "PS_STATUS_DESCRIPTION" => json_encode(array($webhook->getUid() => $webhook->getResponse()->transaction->type)));
        \Bitrix\Main\Config\Option::set("main", "~sale_converted_15", "N");
        //Костыль из - за совместимости битрикс с ядром D7
        CSaleOrder::Update($arOrder["ID"], $arFields);
        \Bitrix\Main\Config\Option::set("main", "~sale_converted_15", "Y");
        echo "OK " . $webhook->getUid();
    }
}
$APPLICATION->RestartBuffer();
die;
 public function onBeforeChangeOrderStatusAdmin($args)
 {
     if (!JFolder::exists(JPATH_ROOT . '/components/com_jshopping')) {
         $this->report_error((int) $args[0], JText::_('PLG_JSERIPPAYMENT_JOOMSHOPPING_NOT_FOUND'));
     }
     $config = JFactory::getConfig();
     $db = JFactory::getDBO();
     $query = $db->getQuery(true);
     $query->clear();
     $query->select('os.status_code')->from($db->quoteName('#__jshopping_order_status') . ' AS os')->where($db->quoteName('os.status_id') . ' = ' . (int) $args[1]);
     $db->setQuery($query);
     $new_status = $db->loadResult();
     if ($new_status != 'A') {
         return true;
     }
     $query->clear();
     $query->select('*')->from($db->quoteName('#__jshopping_payment_method') . ' AS pm')->where($db->quoteName('pm.scriptname') . ' = "pm_erip"');
     $db->setQuery($query);
     $payment_details = $db->loadObject();
     if (empty($payment_details) || empty($payment_details->payment_params)) {
         $this->report_error((int) $args[0], JText::_('PLG_JSERIPPAYMENT_ERROR_PAYMENT_DETAILS'));
     }
     $payment_details_explode = explode("\n", $payment_details->payment_params);
     if (empty($payment_details_explode)) {
         $this->report_error((int) $args[0], JText::_('PLG_JSERIPPAYMENT_ERROR_PAYMENT_PARAMS'));
     }
     $payment_format = array();
     foreach ($payment_details_explode as $value) {
         $value_explode = explode("=", $value);
         if (isset($value_explode[1])) {
             $payment_format[$value_explode[0]] = $value_explode[1];
         }
     }
     if (empty($payment_format)) {
         $this->report_error((int) $args[0], JText::_('PLG_JSERIPPAYMENT_ERROR_PAYMENT_PARAMS_EMPTY'));
     }
     $query->clear();
     $query->select('o.*')->from($db->quoteName('#__jshopping_orders') . ' AS o')->where($db->quoteName('o.order_id') . ' = ' . (int) $args[0]);
     $db->setQuery($query);
     $order_details = $db->loadObject();
     if (empty($order_details)) {
         $this->report_error((int) $args[0], JText::_('PLG_JSERIPPAYMENT_ERROR_ORDER_DETAILS'));
     }
     $query->clear();
     $countries = JshopHelpersSelectOptions::getCountrys();
     $_country = JTable::getInstance('country', 'jshop');
     $_country->load($order_details->country);
     $country = $_country->country_code_2;
     $notification_url = JURI::root() . "plugins/system/joomshoppingerip/libraries/callback.php";
     $notification_url = str_replace('carts.local', 'webhook.begateway.com:8443', $notification_url);
     $order_number = ltrim($order_details->order_number, '0');
     $email = $order_details->email;
     if (strlen(trim($email)) == 0) {
         $email = $config->get('mailfrom');
     }
     $money = new \beGateway\Money();
     $money->setAmount($order_details->order_total);
     $money->setCurrency($order_details->currency_code_iso);
     $expired_at = null;
     if (!empty($payment_format['expired_at'])) {
         $expired_at = intval($payment_format['expired_at']);
         $expired_at = date("Y-m-d", ($expired_at + 1) * 24 * 3600 + time()) . "T00:00:00+03:00";
     }
     $post_data = array();
     $post_data["request"]["amount"] = $money->getCents();
     $post_data["request"]["currency"] = $order_details->currency_code_iso;
     $post_data["request"]["description"] = JText::_('PLG_JSERIPPAYMENT_API_CALL_ORDER') . $order_details->order_id;
     $post_data["request"]["email"] = $email;
     $post_data["request"]["ip"] = $_SERVER['REMOTE_ADDR'];
     $post_data["request"]["order_id"] = $order_details->order_id;
     $post_data["request"]["notification_url"] = $notification_url;
     $post_data["request"]["exipred_at"] = $expired_at;
     $post_data["request"]["payment_method"]["type"] = "erip";
     $post_data["request"]["payment_method"]["account_number"] = $order_number;
     $post_data["request"]["payment_method"]["service_no"] = $payment_format['service_no'];
     $post_data["request"]["payment_method"]["service_info"][] = sprintf($payment_format['service_text'], $order_number);
     $post_data["request"]["payment_method"]["receipt"][] = sprintf($payment_format['receipt_text'], $order_number);
     if ($payment_format['customer_data'] == 1) {
         $post_data["request"]["customer"]["first_name"] = $order_details->f_name;
         $post_data["request"]["customer"]["last_name"] = $order_details->l_name;
         $post_data["request"]["customer"]["country"] = $country;
         $post_data["request"]["customer"]["city"] = $order_details->city;
         $post_data["request"]["customer"]["zip"] = $order_details->zip;
         $post_data["request"]["customer"]["address"] = $order_details->street . " " . $order_details->street_nr;
         $post_data["request"]["customer"]["phone"] = $order_details->phone;
     }
     $post_data_format = json_encode($post_data, JSON_NUMERIC_CHECK);
     $this->api_url = strstr($payment_format['api_url'], "http") ? $payment_format['api_url'] : "https://" . $payment_format['api_url'] . "/beyag/payments";
     $response = $this->send_request_via_curl($post_data_format, $payment_format['shop_id'], $payment_format['shop_key']);
     $response_format = json_decode($response);
     if (isset($response_format->errors)) {
         $this->report_error($order_details->order_id, $response_format->message);
     }
     if (isset($response_format->transaction) && isset($response_format->transaction->status) && $response_format->transaction->status == 'pending') {
         JFactory::getApplication()->enqueueMessage(JText::_('PLG_JSERIPPAYMENT_PAYMENT_REQUEST'));
     } else {
         $this->report_error((int) $args[0], JText::_('PLG_JSERIPPAYMENT_ERROR_PAYMENT_REQUEST'));
     }
     try {
         $query = "INSERT INTO #__jshopping_order_history(`order_id`,`order_status_id`,`status_date_added`,`comments`) VALUES ({$order_details->order_id}," . (int) $args[1] . ",now(),'" . $response_format->transaction->uid . "')";
         $db->setQuery($query);
         $db->execute();
         $instruction = JText::sprintf('PLG_JSERIPPAYMENT_EMAIL_INSTRUCTION', $order_details->f_name . " " . $order_details->l_name, $order_details->order_number, $config->get('sitename'), $payment_format['company_name'], $payment_format['tree_path_email'], $payment_format['tree_path_email'], $order_number);
         if (!empty($order_details->email)) {
             $return = JFactory::getMailer()->sendMail($config->get('mailfrom'), $config->get('fromname'), $order_details->email, JText::_('PLG_JSERIPPAYMENT_EMAIL_INSTRUCTION_SUBJECT'), $instruction);
         } elseif (JFactory::getApplication()->isAdmin()) {
             $this->report_error($order_details->order_id, JText::_('PLG_JSERIPPAYMENT_NO_USER_EMAIL'), notice);
         }
     } catch (RuntimeException $e) {
         $this->report_error($order_details->order_id, $e->getMessage());
     }
     return true;
 }