id = 'payanyway'; $this->method_title = 'Монета | PayAnyWay'; $this->method_description = 'PayAnyWay - универсальный платежный агрегатор для интернет-магазинов и сервисов'; $this->icon = plugin_dir_url(dirname(__FILE__)) . 'payanyway/assets/images/payanyway.png'; $this->has_fields = false; // Load the settings $this->init_form_fields(); $this->init_settings(); // Define user set variables $this->MNT_ID = (int)$this->get_option('MNT_ID'); $this->MNT_DATAINTEGRITY_CODE = $this->get_option('MNT_DATAINTEGRITY_CODE'); $this->MNT_TEST_MODE = 0; $this->demo_mode = $this->get_option('demo_mode'); $this->title = $this->get_option('title'); $this->iniframe = $this->get_option('iniframe'); $this->debug = $this->get_option('debug'); $this->description = $this->get_option('description'); $this->instructions = $this->get_option('instructions'); // Logs if ($this->debug === 'yes') { $this->logger = wc_get_logger(); } // Actions add_action('woocommerce_receipt_payanyway', array($this, 'receipt_page')); // Save options add_action('woocommerce_update_options_payment_gateways_payanyway', array($this, 'process_admin_options')); // Payment listener/API hook add_action('woocommerce_api_wc_payanyway', array($this, 'check_assistant_response')); if (!$this->is_valid_for_use()) { $this->enabled = false; } } /** * Check if this gateway is enabled and available in the user's country */ function is_valid_for_use() { if (!in_array(get_option('woocommerce_currency'), array('RUB'))) { return false; } return true; } /** * Admin Panel Options * - Options for bits like 'title' and availability on a country-by-country basis * * @since 0.1 **/ public function admin_options() { if ($this->is_valid_for_use()) { $this->generate_settings_html(); } else { ?>

:

form_fields = include 'includes/settings/settings-paw.php'; } /** * Дополнительная информация в форме выбора способа оплаты **/ function payment_fields() { echo $this->get_description(); if (isset($_GET['pay_for_order']) && !empty($_GET['key'])) { $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); $this->receipt_page($order->get_id()); } } /** * Process the payment and return the result **/ function process_payment($order_id) { /** @var WC_Order $order */ $order = new WC_Order($order_id); return array( 'result' => 'success', 'redirect' => add_query_arg( 'order-pay', $order->get_id(), add_query_arg( 'key', $order->get_order_key(), $order->get_checkout_payment_url() ) ), ); } private function getPaymentObject($productName) { if (false !== mb_stripos($productName, 'акциз')) { $itemPaymentObject = 'excise'; } elseif (false !== mb_stripos($productName, 'работ')) { $itemPaymentObject = 'job'; } elseif (false !== mb_stripos($productName, 'услуг')) { $itemPaymentObject = 'service'; } elseif (false !== mb_stripos($productName, 'ставк')) { $itemPaymentObject = 'gambling_bet'; } elseif (false !== mb_stripos($productName, 'выигрыш')) { $itemPaymentObject = 'gambling_prize'; } elseif (false !== mb_stripos($productName, 'лотере')) { $itemPaymentObject = 'lottery'; } elseif (false !== mb_stripos($productName, 'приз')) { $itemPaymentObject = 'lottery_prize'; } elseif (false !== mb_stripos($productName, 'интеллект')) { $itemPaymentObject = 'intellectual_activity'; } elseif (false !== mb_stripos($productName, 'взнос')) { $itemPaymentObject = 'payment'; } elseif (false !== mb_stripos($productName, 'агент')) { $itemPaymentObject = 'agent_commission'; } else { $itemPaymentObject = 'commodity'; } return $itemPaymentObject; } /** * @param string $data * @return string */ private function getVatTag($data) { $vatList = array( 'none' => '1105', 'vat0' => '1104', 'vat5' => '1108', 'vat105' => '1110', 'vat7' => '1109', 'vat107' => '1111', 'vat10' => '1103', 'vat110' => '1107', 'vat20' => '1102', 'vat120' => '1106', 'vat22' => '1113', 'vat122' => '1114', ); return isset($vatList[$data]) ? $vatList[$data] : '1105'; } /** * @param int|null $rate * @return string */ private function convertVatIdByRate($rate) { if ($rate === null) { return 'none'; } $vatMap = array( 0 => 'vat0', 5 => 'vat5', 7 => 'vat7', 10 => 'vat10', 20 => 'vat20', 22 => 'vat22', ); return isset($vatMap[$rate]) ? $vatMap[$rate] : 'vat' . $rate; } private function getPaymentMethod($productName) { if (false !== mb_stripos($productName, 'аванс')) { $itemPaymentMethod = 'advance'; } elseif (false !== mb_stripos($productName, 'кредит')) { $itemPaymentMethod = 'credit'; } else { $itemPaymentMethod = 'full_prepayment'; } return $itemPaymentMethod; } /** * Форма оплаты **/ function receipt_page($order_id) { $order = new WC_Order($order_id); $amount = $this->formatPrice($order->get_total()); $test_mode = $this->MNT_TEST_MODE; $in_iframe = ($this->iniframe === 'yes') ? 1 : 0; $currency = get_woocommerce_currency(); if ($currency === 'RUR') $currency = 'RUB'; $transactionId = $this->createTransactionId($order_id); $subscriberId = $this->getSubscriberId($order); $signature = md5( $this->MNT_ID . $transactionId . $amount . $currency . $subscriberId . $test_mode . $this->MNT_DATAINTEGRITY_CODE ); $wcKey = (isset($_GET['key'])) ? $_GET['key'] : ''; $args = array( 'MNT_ID' => $this->MNT_ID, 'MNT_TRANSACTION_ID' => $transactionId, 'MNT_AMOUNT' => $amount, 'MNT_CURRENCY_CODE' => $currency, 'MNT_TEST_MODE' => $test_mode, 'MNT_DESCRIPTION' => $this->getDescription($order), 'MNT_SUBSCRIBER_ID' => $subscriberId, 'MNT_SIGNATURE' => $signature, 'MNT_SUCCESS_URL' => get_site_url() . "/?wc-api=wc_payanyway&payanyway=success&key={$wcKey}&order_id={$order_id}", 'MNT_FAIL_URL' => get_site_url() . "/?wc-api=wc_payanyway&payanyway=fail", 'MNT_RETURN_URL' => get_site_url() . '/checkout/', 'MNT_CMS' => $this->getCmsModuleVersion(), ); $form_fields = array(); foreach ($args as $key => $value) { $form_fields[] = ''; } wp_enqueue_style('paw_css_main', plugin_dir_url(__FILE__) . 'assets/css/paw-main.css', '', ''); $demoMode = ($this->demo_mode === 'yes') ? 1 : 0; $this->logger && $this->logger->info('Create payment processed', array( 'source' => self::MODULE_NAME, 'form_data' => $args, )); if ($in_iframe) { $assistantEndpoint = $demoMode ? self::DEMO_IFRAME_ENDPOINT : self::PROD_IFRAME_ENDPOINT; $form_html = '