public function __construct() { $this->currencyCode = SCurrenciesQuery::create()->filterByIsDefault(true)->findOne()->getCode(); $this->settings = $this->cms_base->get_settings(); parent::__construct(); }
public function processPayment() { $PSystem_ID = $_GET['PSystem_ID']; $order_key = $this->order->getKey(); $order_id = $this->order->getId(); $paymentMethod = $this->paymentMethod->getId(); $CurrencyId = $this->paymentMethod->getCurrencyId(); $data = $this->loadSettings(); $MerchantGuid = $data['MerchantGuid']; $MerchantSecretKey = $data['MerchantSecretKey']; $currencies = SCurrenciesQuery::create()->find(); foreach ($currencies as $c) { $this->currencies[$c->getId()] = $c; } $currency = $this->currencies[$CurrencyId]; $currency_Code = $currency->code; $currency_Rate = $currency->getRate(); $TotalPrice = 0; $PSystem_ID = isset($PSystem_ID) ? $PSystem_ID : $this->getPSI(); $send_data['SelectedPaySystemId'] = $PSystem_ID; $db = \CI::$APP->db; $db->where('shop_orders_products.order_id', $order_id); $db->join('shop_products', 'shop_orders_products.product_id=shop_products.id', 'left outer'); $Products = $db->get('shop_orders_products')->result_array(); foreach ($Products as $orderProduct) { $product_item = array(); $product_item['ImageUrl'] = productImageUrl($orderProduct['mainModImage']); $product_item['ProductItemsNum'] = number_format($orderProduct['quantity'], 2, '.', ''); $product_item['ProductName'] = $orderProduct['product_name']; $product_item['ProductPrice'] = number_format($orderProduct['price'] * $currency_Rate, 2, '.', ''); $product_item['ProductId'] = $orderProduct['product_id']; $send_data['Products'][] = $product_item; $TotalPrice += $product_item['ProductPrice'] * $product_item['ProductItemsNum']; $product_count += $product_item['ProductItemsNum']; } $TotalPrice = number_format($TotalPrice, 2, '.', ''); $product_count = number_format($product_count, 2, '.', ''); //Инициализация if ($PSystem_ID && !$_GET['back']) { if ($user_id = $this->order->getUserId()) { $profile = SUserProfileQuery::create()->filterById($user_id)->findone(); } else { $user_id = 1; } $send_data['PaymentDetails']['MerchantInternalPaymentId'] = $order_id; $send_data['PaymentDetails']['MerchantInternalUserId'] = $user_id; $send_data['PaymentDetails']['EMail'] = $this->order->user_email; $send_data['PaymentDetails']['PhoneNumber'] = $profile->getPhone(); $send_data['PaymentDetails']['Description'] = "Оплата заказа {$order_id}"; $send_data['PaymentDetails']['DeliveryType'] = $this->order->getSDeliveryMethods()->getName(); $send_data['PaymentDetails']['CustomMerchantInfo'] = ''; $send_data['PaymentDetails']['StatusUrl'] = shop_url("cart/view/{$order_key}?back=1&pm={$paymentMethod}"); $send_data['PaymentDetails']['ReturnUrl'] = shop_url("cart/view/{$order_key}?back=1"); $send_data['PaymentDetails']['BuyerLastname'] = ''; $send_data['PaymentDetails']['BuyerFirstname'] = $this->order->user_full_name; $send_data['PaymentDetails']['BuyerPatronymic'] = ''; $send_data['PaymentDetails']['BuyerStreet'] = $profile->getAddress(); $send_data['PaymentDetails']['BuyerCity'] = ''; $send_data['PaymentDetails']['BuyerZone'] = ''; $send_data['PaymentDetails']['BuyerZip'] = ''; $send_data['PaymentDetails']['BuyerCountry'] = ''; $send_data['PaymentDetails']['DeliveryLastname'] = ''; $send_data['PaymentDetails']['DeliveryFirstname'] = $this->order->user_full_name; $send_data['PaymentDetails']['DeliveryPatronymic'] = ''; $send_data['PaymentDetails']['DeliveryStreet'] = $profile->getAddress(); $send_data['PaymentDetails']['DeliveryCity'] = ''; $send_data['PaymentDetails']['DeliveryZone'] = ''; $send_data['PaymentDetails']['DeliveryZip'] = ''; $send_data['PaymentDetails']['DeliveryCountry'] = ''; $signature_s = $MerchantGuid . $TotalPrice . $product_count . $send_data['PaymentDetails']['MerchantInternalUserId'] . $send_data['PaymentDetails']['MerchantInternalPaymentId'] . $PSystem_ID . $data['MerchantSecretKey']; if (stristr($currency_Code, 'R') === 0) { $currency_Code = 'RUB'; } elseif (stristr($currency_Code, 'UA') === 0) { $currency_Code = 'UAH'; } elseif (stristr($currency_Code, 'US') === 0) { $currency_Code = 'USD'; } elseif (stristr($currency_Code, 'E') === 0) { $currency_Code = 'EUR'; } $send_data['Signature'] = md5($signature_s); $send_data['MerchantGuid'] = $MerchantGuid; $send_data['Currency'] = $currency_Code; $res = $this->Treasurer_Request($this->URL_CreatePayment, $send_data); $data = json_decode($res, 1); $ErrorCode = $data['ErrorCode']; $ExternalForm = $data['ExternalForm']; if ($ErrorCode) { die("ErrorCode={$ErrorCode}"); } $ExternalForm = base64_decode($ExternalForm); die($ExternalForm); } else { //CallBack оплаты $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : file_get_contents('php://input'); $req_data = json_decode($HTTP_RAW_POST_DATA, 1); $MerchantInternalPaymentId = abs(intval($req_data['MerchantInternalPaymentId'])); $Signature = strtoupper($req_data['Signature']); $Sum = $req_data['Sum']; $ErrorCode = $req_data['ErrorCode']; $MerchantInternalUserId = $req_data['MerchantInternalUserId']; $CustomMerchantInfo = $req_data['CustomMerchantInfo']; if (!$MerchantInternalPaymentId) { return false; } if ($ErrorCode) { return false; } $Sum = number_format($Sum, 2, '.', ''); //857.00 => 857 WTF!!! $signature_true = strtoupper(md5($ErrorCode . $order_id . $MerchantInternalUserId . $Sum . $CustomMerchantInfo . $MerchantSecretKey)); if ($Signature != $signature_true) { return false; } if ($this->order->getPaid() == true) { return ERROR_ORDER_PAID_BEFORE; } $this->setOrderPaid(); die("OK{$order_id}"); } }