/** * @see waIPayment::payment() */ public function payment($payment_form_data, $order_data, $auto_submit = false) { $order = waOrder::factory($order_data); $hidden_fields = array(); $hidden_fields['eshopId'] = $this->shop_id; $hidden_fields['orderId'] = sprintf($this->template, $this->app_id, $this->merchant_id, $order->id); $hidden_fields['serviceName'] = mb_substr($order->description, 0, 255, "UTF-8"); $hidden_fields['recipientAmount'] = number_format($order->total, 2, ',', ''); $currency = $order->currency; if ($currency == 'RUB') { $currency = 'RUR'; } $hidden_fields['recipientCurrency'] = $currency; $hidden_fields['user_email'] = $order->getContact()->get('email', 'default'); $hidden_fields['language'] = substr($order->getContact()->getLocale(), 0, 2); $transaction_data = array('order_id' => $order->id); $hidden_fields['successUrl'] = $this->getAdapter()->getBackUrl(waAppPayment::URL_SUCCESS, $transaction_data); $hidden_fields['failUrl'] = $this->getAdapter()->getBackUrl(waAppPayment::URL_FAIL, $transaction_data); $hidden_fields['hash'] = $this->getSign($hidden_fields); $view = wa()->getView(); $view->assign('form_url', $this->getEndpointUrl()); $view->assign('hidden_fields', $hidden_fields); $view->assign('auto_submit', $auto_submit); return $view->fetch($this->path . '/templates/payment.html'); }
public function payment($payment_form_data, $order_data, $auto_submit = false) { $order_data = waOrder::factory($order_data); $view = wa()->getView(); $view->assign('order', $order_data); $view->assign('form_url', $this->getEndpointUrl()); $view->assign('order_id', $this->app_id . '_' . $order_data['order_id']); $view->assign('settings', $this->getSettings()); $view->assign('auto_submit', $auto_submit); return $view->fetch($this->path . '/templates/payment.html'); }
public function payment($payment_form_data, $order_data, $auto_submit = false) { $order = waOrder::factory($order_data); $fp_timestamp = time(); $fp_sequence = $order->id; $fp_hash_string = $this->login . "^" . $fp_sequence . "^" . $fp_timestamp . "^" . $order->total . "^" . $order->currency; $form = array('x_login' => $this->login, 'x_test_request' => $this->testmode ? 'TRUE' : 'FALSE', 'x_show_form' => 'PAYMENT_FORM', 'x_fp_sequence' => $fp_sequence, 'x_fp_timestamp' => $fp_timestamp, 'x_fp_hash' => $this->hmac($this->key, $fp_hash_string), 'x_amount' => $order->total, 'x_currency_code' => $order->currency, 'x_first_name' => $order->billing_address['firstname'], 'x_last_name' => $order->billing_address['lastname'], 'x_address' => $order->billing_address['street'], 'x_city' => $order->billing_address['city'], 'x_state' => $order->billing_address['region_name'], 'x_zip' => $order->billing_address['zip'], 'x_country' => $order->billing_address['country_name'], 'x_email' => $order->contact_email, "x_customer_ip" => waRequest::getIp(), 'x_invoice_num' => $order->id_str, 'x_description' => $order->description_en, 'x_ship_to_first_name' => $order->shipping_address['firstname'], 'x_ship_to_last_name' => $order->shipping_address['lastname'], 'x_ship_to_address' => $order->shipping_address['street'], 'x_ship_to_city' => $order->shipping_address['city'], 'x_ship_to_state' => $order->shipping_address['region_name'], 'x_ship_to_zip' => $order->shipping_address['zip'], 'x_ship_to_country' => $order->shipping_address['country_name'], 'x_relay_response' => 'FALSE'); $view = wa()->getView(); $view->assign('form', $form); $view->assign('form_url', $this->getEndpointUrl()); $view->assign('auto_submit', $auto_submit); return $view->fetch($this->path . '/templates/payment.html'); }
public function payment($payment_form_data, $order_data, $auto_submit = false) { $order = waOrder::factory($order_data); $form = array('sid' => $this->sid, 'total' => $order->total, 'cart_order_id' => $order->id, 'card_holder_name' => $order->billing_address['name'], 'street_address' => $order->billing_address['street'], 'city' => $order->billing_address['city'], 'state' => $order->billing_address['region_name'], 'zip' => $order->billing_address['zip'], 'country' => $order->billing_address['country_name'], 'email' => $order->contact_email, 'ship_street_address' => $order->shipping_address['street'], 'ship_city' => $order->shipping_address['city'], 'ship_state' => $order->shipping_address['region_name'], 'ship_zip' => $order->shipping_address['zip'], 'ship_country' => $order->shipping_address['country_name'], 'c_prod' => "ShopScript5 order", 'id_type' => 2); if ($this->demo) { $form['demo'] = 'Y'; } $form['key'] = $this->getSign($form); $view = wa()->getView(); $view->assign('form', $form); $view->assign('form_url', $this->getEndpointUrl()); $view->assign('auto_submit', $auto_submit); return $view->fetch($this->path . '/templates/payment.html'); }
public function payment($payment_form_data, $order_data, $auto_submit = false) { $order_data = waOrder::factory($order_data); if ($order_data['currency_id'] != 'RUB') { return array('type' => 'error', 'data' => _w('Оплата на сайте Яндекс.Денег производится в только в рублях (RUB) и в данный момент невозможна, так как эта валюта не определена в настройках.')); } $view = wa()->getView(); switch ($this->integration_type) { case 'personal': $view->assign('plugin', $this); $view->assign('order', $order_data); $view->assign('return_url', $this->getAdapter()->getBackUrl(waAppPayment::URL_SUCCESS)); $view->assign('label', $this->app_id . '_' . $this->account . '_' . $order_data['order_id']); break; case 'kassa': $hidden_fields = array('scid' => $this->scid, 'ShopID' => $this->ShopID, 'CustomerNumber' => $order_data['customer_contact_id'], 'customerNumber' => $order_data['customer_contact_id'], 'orderNumber' => $this->app_id . '_' . $this->merchant_id . '_' . $order_data['order_id'], 'Sum' => number_format($order_data['amount'], 2, '.', '')); $fields = array(); if ($this->payment_mode) { switch ($this->payment_mode) { case 'customer': $ways = self::settingsPaymentOptions(); $options = array('title' => 'Способ оплаты', 'description' => '', 'options' => array()); foreach ($ways as $way => $name) { if (isset($this->paymentType[$way]) && !empty($this->paymentType[$way])) { $options['options'][$way] = $name; } } if (count($options['options']) == 1) { $hidden_fields['paymentType'] = key($options['options']); } elseif (count($options['options']) > 1) { $options['value'] = key($options['options']); $fields['paymentType'] = waHtmlControl::getControl(waHtmlControl::SELECT, 'paymentType', $options); $auto_submit = false; } break; default: $hidden_fields['paymentType'] = $this->payment_mode; break; } } $view->assign('hidden_fields', $hidden_fields); $view->assign('fields', $fields); $view->assign('form_url', $this->getEndpointUrl()); $view->assign('auto_submit', $auto_submit); break; } $view->assign('integration_type', $this->integration_type); return $view->fetch($this->path . '/templates/payment.html'); }
/** * Generates payment form HTML code. * * Payment form can be displayed during checkout or on order-viewing page. * Form "action" URL can be that of the payment gateway or of the current page (empty URL). * In the latter case, submitted data are passed again to this method for processing, if needed; * e.g., verification, saving, forwarding to payment gateway, etc. * @param array $payment_form_data Array of POST request data received from payment form * (if no "action" URL is specified for the form) * @param waOrder $order_data Object containing all available order-related information * @param bool $auto_submit Whether payment form data must be automatically submitted (useful during checkout) * @return string Payment form HTML * @throws waException */ public function payment($payment_form_data, $order_data, $auto_submit = false) { // using order wrapper class to ensure use of correct data object $order = waOrder::factory($order_data); // verifying order currency support if (!in_array($order->currency, $this->allowedCurrency())) { throw new waException('Unsupported currency'); } // adding all necessary form fields as required by PayPal $hidden_fields = array('cmd' => '_xclick', 'business' => $this->email, 'item_name' => str_replace(array('“', '”', '«', '»'), '"', $order->description), 'item_number' => $this->app_id . '_' . $this->merchant_id . '_' . $order->id, 'no_shipping' => 1, 'amount' => number_format($order->total, 2, '.', ''), 'currency_code' => $order->currency, 'return' => $this->getAdapter()->getBackUrl(waAppPayment::URL_SUCCESS, $order), 'cancel_return' => $this->getAdapter()->getBackUrl(waAppPayment::URL_DECLINE), 'notify_url' => $this->getRelayUrl(), 'charset' => 'utf-8'); $view = wa()->getView(); $view->assign(array('url' => wa()->getRootUrl(), 'hidden_fields' => $hidden_fields, 'form_url' => $this->getEndpointUrl(), 'auto_submit' => $auto_submit, 'plugin' => $this)); // using plugin's own template file to display payment form return $view->fetch($this->path . '/templates/payment.html'); }
/** * Генерирует HTML-код формы оплаты. * * Платежная форма может отображаться во время оформления заказа или на странице просмотра ранее оформленного заказа. * Значение атрибута "action" формы может содержать URL сервера платежной системы либо URL текущей страницы (т. е. быть пустым). * Во втором случае отправленные пользователем платежные данные снова передаются в этот же метод для дальнейшей обработки, если это необходимо, * например, для проверки, сохранения в базу данных, перенаправления на сайт платежной системы и т. д. * @param array $payment_form_data Содержимое POST-запроса, полученное при отправке платежной формы * (если в формы оплаты не указано значение атрибута "action") * @param waOrder $order_data Объект, содержащий всю доступную информацию о заказе * @param bool $auto_submit Флаг, обозначающий, должна ли платежная форма автоматически отправить данные без участия пользователя * (удобно при оформлении заказа) * @return string HTML-код платежной формы * @throws waException */ public function payment($payment_form_data, $order_data, $auto_submit = false) { // заполняем обязательный элемент данных с описанием заказа if (empty($order_data['description'])) { $order_data['description'] = 'Заказ ' . $order_data['order_id']; } // вызываем класс-обертку, чтобы гарантировать использование данных в правильном формате $order = waOrder::factory($order_data); // добавляем в платежную форму поля, требуемые платежной системой WebMoney $hidden_fields = array('LMI_MERCHANT_ID' => $this->LMI_MERCHANT_ID, 'LMI_PAYMENT_AMOUNT' => number_format($order->total, 2, '.', ''), 'LMI_CURRENCY' => strtoupper($order->currency), 'LMI_PAYMENT_NO' => $order_data['order_id'], 'LMI_PAYMENT_DESC' => $order->description, 'LMI_RESULT_URL' => $this->getRelayUrl(), 'wa_app' => $this->app_id, 'wa_merchant_contact_id' => $this->merchant_id); if ($this->LMI_PAYEE_PURSE) { $hidden_fields['LMI_PAYEE_PURSE'] = $this->LMI_PAYEE_PURSE; } if ($this->TESTMODE) { $hidden_fields['LMI_SIM_MODE'] = $this->LMI_SIM_MODE; } if (!empty($order_data['customer_info']['email'])) { $hidden_fields['LMI_PAYER_EMAIL'] = $order_data['customer_info']['email']; } $transaction_data = $this->formalizeData($hidden_fields); // добавляем служебные URL: // URL возврата покупателя после успешного завершения оплаты $hidden_fields['LMI_SUCCESS_URL'] = $this->getAdapter()->getBackUrl(waAppPayment::URL_SUCCESS, $transaction_data); // URL возврата покупателя после неудачной оплаты $hidden_fields['LMI_FAILURE_URL'] = $this->getAdapter()->getBackUrl(waAppPayment::URL_FAIL, $transaction_data); switch ($this->protocol) { case self::PROTOCOL_PAYMASTER: case self::PROTOCOL_WEBMONEY_LEGACY: case self::PROTOCOL_PAYMASTER_COM: case self::PROTOCOL_WEBMONEY_LEGACY_COM: break; case self::PROTOCOL_WEBMONEY: default: unset($hidden_fields['LMI_CURRENCY']); if (strpos(waRequest::getUserAgent(), 'MSIE') !== false) { $hidden_fields['LMI_PAYMENT_DESC'] = $order->description_en; } break; } $view = wa()->getView(); $view->assign('url', wa()->getRootUrl()); $view->assign('hidden_fields', $hidden_fields); $view->assign('form_url', $this->getEndpointUrl()); $view->assign('form_options', $this->getFormOptions()); $view->assign('auto_submit', $auto_submit); // для отображения платежной формы используем собственный шаблон return $view->fetch($this->path . '/templates/payment.html'); }
public function payment($payment_form_data, $order_data, $auto_submit = false) { $order = waOrder::factory($order_data); $description = preg_replace('/[^\\.\\?,\\[]\\(\\):;"@\\%\\s\\w\\d]+/', ' ', $order->description); $description = preg_replace('/[\\s]{2,}/', ' ', $description); if (!in_array($order->currency, $this->allowedCurrency())) { throw new waPaymentException('Invalid currency'); } list(, $lang) = explode("_", wa()->getLocale()); $contact = new waContact(wa()->getUser()->getId()); list($email) = $contact->get('email', 'value'); $redirectUrl = $this->getRelayUrl() . '?&fondy_id=' . $this->fondy_id . '&app_id=' . $this->app_id . '&merchants_id=' . $this->merchant_id; $formFields = array('order_id' => $order_data['order_id'] . self::ORDER_SEPARATOR . time(), 'merchant_id' => $this->fondy_id, 'order_desc' => $description, 'amount' => $this->getAmount($order), 'currency' => $order->currency, 'server_callback_url' => $redirectUrl, 'response_url' => $redirectUrl . '&show_user_response=1', 'lang' => strtolower($lang), 'sender_email' => $email); $formFields['signature'] = $this->getSignature($formFields); $view = wa()->getView(); $view->assign('form_fields', $formFields); $view->assign('form_url', $this->getEndpointUrl()); $view->assign('auto_submit', $auto_submit); return $view->fetch($this->path . '/templates/payment.html'); }
public function payment($payment_form_data, $order_data, $auto_submit = false) { $order = waOrder::factory($order_data); if (!in_array($order->currency_id, $this->allowedCurrency())) { throw new waException('Ошибка оплаты. Валюта не поддерживается'); } $url = $this->getUrl() . 'register.do'; $params = base64_encode(json_encode(array('app_id' => $this->app_id, 'merchant_id' => $this->merchant_id))); $returnUrl = $this->getRelayUrl() . '?params=' . $params; $currency_id = $order->currency_id; $currency = array_search($currency_id, $this->currency); $data = array('userName' => $this->userName, 'password' => $this->password, 'orderNumber' => $order->id . '_' . time(), 'amount' => floor($order->total * 100), 'currency' => $currency, 'returnUrl' => $returnUrl); $response = $this->sendData($url, $data, $this->ssl_version); if (isset($response['errorCode']) && $response['errorCode']) { throw new waPaymentException('Ошибка оплаты. ' . $response['errorMessage']); } $formUrl = $response['formUrl']; $view = wa()->getView(); $view->assign('form_url', $formUrl); $view->assign('auto_submit', $auto_submit); return $view->fetch($this->path . '/templates/payment.html'); }
public function payment($payment_form_data, $order_data, $auto_submit = false) { $order = waOrder::factory($order_data); $hidden_fields = array(); $hidden_fields['ik_am'] = str_replace(',', '.', sprintf('%0.2f', $order->total)); $hidden_fields['ik_pm_no'] = sprintf($this->template, $this->app_id, $this->merchant_id, $order->id); $hidden_fields['ik_desc'] = mb_substr($order->description, 0, 255, "UTF-8"); $hidden_fields['ik_cur'] = $order->currency; if ($this->test) { $hidden_fields['ik_pw_via'] = 'test_interkassa_test_xts'; } $transaction_data = $this->formalizeData($hidden_fields); $hidden_fields['ik_suc_u'] = $this->getAdapter()->getBackUrl(waAppPayment::URL_SUCCESS, $transaction_data); $hidden_fields['ik_fal_u'] = $this->getAdapter()->getBackUrl(waAppPayment::URL_FAIL, $transaction_data); $hidden_fields['ik_pnd_u'] = $hidden_fields['ik_suc_u']; $hidden_fields['ik_ia_u'] = $this->getRelayUrl(); $this->getSign($hidden_fields); $view = wa()->getView(); $view->assign('form_url', $this->getEndpointUrl()); $view->assign('hidden_fields', $hidden_fields); $view->assign('auto_submit', $auto_submit); return $view->fetch($this->path . '/templates/payment.html'); }
public function payment($payment_form_data, $order_data, $auto_submit = false) { $order = waOrder::factory($order_data); $view = wa()->getView(); $view->assign('data', $payment_form_data); $view->assign('order', $order_data); $view->assign('settings', $this->getSettings()); $form = array(); $form['amt'] = number_format($order->total, 2, '.', ''); $form['ccy'] = $order->currency; $form['order'] = sprintf('%s_%s_%s', $this->app_id, $this->merchant_id, $order->id); $form['merchant'] = $this->merchant; $pattern = "@[^\\w\\d" . preg_quote("~@#\$%^-_(){}'`+=[]:;/\\", '@') . "]+@u"; $description = trim(preg_replace('@\\s{2,}@', ' ', preg_replace($pattern, ' ', $order->description))); $form['details'] = mb_substr($description, 0, 130); $form['ext_details'] = mb_substr($description, 0, 250); $form['pay_way'] = 'privat24'; $form['return_url'] = $this->getRelayUrl() . '?customer=1'; $form['server_url'] = $this->getRelayUrl(); $view->assign('form', $form); $view->assign('form_url', $this->getEndpointUrl()); $view->assign('auto_submit', $auto_submit); return $view->fetch($this->path . '/templates/payment.html'); }
public function payment($payment_form_data, $order_data, $auto_submit = false) { $order = waOrder::factory($order_data); if (!in_array($order->currency, $this->allowedCurrency())) { throw new waException('Unsupported currency'); } $customer_phone = ''; if ($this->customer_phone) { $customer_phone = $order->getContactField($this->customer_phone); } $description = htmlentities($order->description_en, ENT_QUOTES, 'utf-8'); $method = $this->gateway; if (!$method) { $method = 'card, liqpay, delayed'; } $customer_url = $this->getAdapter()->getBackUrl(waAppPayment::URL_SUCCESS, array('order_id' => $order->id)); $result_url = $this->getRelayUrl(); $suffix = ''; if ($this->bugfix) { $suffix = sprintf('_%04d', rand(1000, 9999)); } $order_id = $this->order_prefix . $order->id . $suffix; $amount = str_replace(',', '.', round($order->total, 2)); $currency = $order->currency; if ($currency == 'RUB') { $currency = 'RUR'; } $order_id = htmlentities(sprintf('%s.%d_%s', $this->app_id, $this->merchant_id, $order_id), ENT_QUOTES, 'utf-8'); $this->raw_xml = "<request>\n<version>1.2</version>\n<result_url>{$customer_url}</result_url>\n<server_url>{$result_url}</server_url>\n<merchant_id>{$this->getSettings('merchant_id')}</merchant_id>\n<order_id>{$order_id}</order_id>\n<amount>{$amount}</amount>\n<currency>{$currency}</currency>\n<description>{$description}</description>\n<default_phone>{$customer_phone}</default_phone>\n<pay_way>{$method}</pay_way>\n</request>"; $hidden_fields = array('operation_xml' => base64_encode($this->raw_xml), 'signature' => $this->getSignature()); $view = wa()->getView(); $view->assign('hidden_fields', $hidden_fields); $view->assign('form_url', $this->getEndpointUrl()); $view->assign('auto_submit', $auto_submit); return $view->fetch($this->path . '/templates/payment.html'); }
/** * @param array $payment_form_data POST form data * @param waOrder $order_data formalized order data * @param $transaction_type * @return string HTML payment form */ public function payment($payment_form_data, $order_data, $auto_submit = false) { $order = waOrder::factory($order_data); return $this->fetch(array('url' => $this->getUrl(), 'fields' => $this->getFields($order), 'auto_submit' => $auto_submit), '/templates/payment.html'); }
public function payment($payment_form_data, $order_data, $auto_submit = false) { $order = waOrder::factory($order_data); $description = preg_replace('/[^\\.\\?,\\[]\\(\\):;"@\\%\\s\\w\\d]+/', ' ', $order->description); $description = preg_replace('/[\\s]{2,}/', ' ', $description); $form_fields = array(); $form_fields['MrchLogin'] = $this->merchant_login; $form_fields['OutSum'] = number_format($order->total, 2, '.', ''); $form_fields['InvId'] = $order->id; $hash_string = implode(':', $form_fields) . ':' . $this->merchant_pass1; $hash_string .= ':shp_wa_app_id=' . $this->app_id; $hash_string .= ':shp_wa_merchant_id=' . $this->merchant_id; $form_fields['SignatureValue'] = md5($hash_string); $form_fields['Desc'] = mb_substr($description, 0, 100, "UTF-8"); $form_fields['IncCurrLabel'] = $this->gateway_currency; $form_fields['Culture'] = $this->locale; $form_fields['shp_wa_app_id'] = $this->app_id; $form_fields['shp_wa_merchant_id'] = $this->merchant_id; $view = wa()->getView(); $view->assign('form_fields', $form_fields); $view->assign('form_url', $this->getEndpointUrl()); $view->assign('auto_submit', $auto_submit); return $view->fetch($this->path . '/templates/payment.html'); }
/** * * @param string|array $order * @param waPayment * @return waOrder */ public static function getOrderData($order, $payment_plugin = null) { return waOrder::factory($order); }
/** * * formalize order data * @param string|array $order order ID or order data * @param waPayment $payment_plugin * @return waOrder */ public static function getOrderData($order, $payment_plugin = null) { if (!is_array($order)) { $order_id = shopHelper::decodeOrderId($encoded_order_id = $order); if (!$order_id) { $order_id = $encoded_order_id; $encoded_order_id = shopHelper::encodeOrderId($order_id); } $om = new shopOrderModel(); $order = $om->getOrder($order_id); if (!$order) { return null; } $order['id_str'] = $encoded_order_id; } if (!isset($order['id_str'])) { $order['id_str'] = shopHelper::encodeOrderId($order['id']); } if (!isset($order['params'])) { $order_params_model = new shopOrderParamsModel(); $order['params'] = $order_params_model->get($order['id']); } $convert = false; if ($payment_plugin && method_exists($payment_plugin, 'allowedCurrency')) { $currency = $payment_plugin->allowedCurrency(); $total = $order['total']; $currency_id = $order['currency']; if ($currency !== true) { $currency = (array) $currency; if (!in_array($order['currency'], $currency)) { $convert = true; $total = shop_currency($total, $order['currency'], $currency_id = reset($currency), false); } } } else { $currency_id = $order['currency']; $total = $order['total']; } $items = array(); if (!empty($order['items'])) { foreach ($order['items'] as $item) { ifempty($item['price'], 0.0); if ($convert) { $item['price'] = shop_currency($item['price'], $order['currency'], $currency_id, false); } $items[] = array('id' => ifset($item['id']), 'name' => ifset($item['name']), 'sku' => ifset($item['sku_code']), 'description' => '', 'price' => $item['price'], 'quantity' => ifset($item['quantity'], 0), 'total' => $item['price'] * $item['quantity'], 'type' => ifset($item['type'], 'product'), 'product_id' => ifset($item['product_id'])); if (isset($item['weight'])) { $items[count($items) - 1]['weight'] = $item['weight']; } } } $empty_address = array('firstname' => '', 'lastname' => '', 'country' => '', 'region' => '', 'city' => '', 'street' => '', 'zip' => ''); $shipping_address = array_merge($empty_address, shopHelper::getOrderAddress($order['params'], 'shipping')); $billing_address = array_merge($empty_address, shopHelper::getOrderAddress($order['params'], 'billing')); if (!count(array_filter($billing_address, 'strlen'))) { $billing_address = $shipping_address; } ifset($order['shipping'], 0.0); ifset($order['discount'], 0.0); ifset($order['tax'], 0.0); if ($convert) { $order['tax'] = shop_currency($order['tax'], $order['currency'], $currency_id, false); $order['shipping'] = shop_currency($order['shipping'], $order['currency'], $currency_id, false); $order['discount'] = shop_currency($order['discount'], $order['currency'], $currency_id, false); } $order_data = array('id_str' => ifempty($order['id_str'], $order['id']), 'id' => $order['id'], 'contact_id' => $order['contact_id'], 'datetime' => ifempty($order['create_datetime']), 'description' => sprintf(_w('Payment for order %s'), ifempty($order['id_str'], $order['id'])), 'update_datetime' => ifempty($order['update_datetime']), 'paid_datetime' => empty($order['paid_date']) ? null : $order['paid_date'] . ' 00:00:00', 'total' => ifempty($total, $order['total']), 'currency' => ifempty($currency_id, $order['currency']), 'discount' => $order['discount'], 'tax' => $order['tax'], 'payment_name' => ifset($order['params']['payment_name'], ''), 'billing_address' => $billing_address, 'shipping' => $order['shipping'], 'shipping_name' => ifset($order['params']['shipping_name'], ''), 'shipping_address' => $shipping_address, 'items' => $items, 'comment' => ifempty($order['comment'], ''), 'params' => $order['params']); return waOrder::factory($order_data); }
/** * @param array $payment_form_data POST form data * @param waOrder $order_data formalized order data * @param bool $auto_submit * @return string HTML payment form */ public function payment($payment_form_data, $order_data, $auto_submit = false) { $order = waOrder::factory($order_data); return $this->fetch(array('url' => $this->getUrl(), 'params' => $this->getRequestParams($order, true)), '/templates/payment.html'); }
private function restPayment($payment_form_data, $order_data, $auto_submit = false) { $order_data = waOrder::factory($order_data); $transaction_model = new waTransactionModel(); $this->order_id = $order_data->id; $transaction_data = $transaction_model->getByField(array('app_id' => $this->app_id, 'plugin' => $this->id, 'order_id' => $this->order_id), 'id'); ksort($transaction_data); $transaction_data = end($transaction_data); $messages = array(); if (empty($transaction_data)) { if (!empty($payment_form_data['customer_phone'])) { $payment_form_data['customer_phone'] = preg_replace('@\\D+@', '', $payment_form_data['customer_phone']); if (preg_match('@\\d{11}@', $payment_form_data['customer_phone'])) { try { $transaction_data = $this->restAuth($payment_form_data, $order_data); } catch (waPaymentException $ex) { $messages[] = $ex->getMessage(); } } else { $messages[] = 'Неверный номер телефона, используйте только цифры без пробелов и разделителей'; } } } elseif ($transaction_data['state'] == self::STATE_AUTH && empty($payment_form_data['customer_phone'])) { $time = min(time() - strtotime($transaction_data['create_datetime']), time() - strtotime($transaction_data['update_datetime'])) / 3600; if ($time > min($this->lifetime, 2)) { try { $transaction_data = $this->restAuth(array(), $order_data); } catch (waPaymentException $ex) { if ($ex->getCode() == 210) { unset($transaction_data['native_id']); } else { $messages[] = $ex->getMessage(); } } } } if (!empty($transaction_data['native_id'])) { if ($transaction_data['state'] == self::STATE_CAPTURED) { //TODO reload page //wa()->getResponse()->redirect(''); $message = 'Заказ уже оплачен'; } elseif ($transaction_data['state'] == self::STATE_AUTH) { $url = $this->getEndpointUrl('form', array('native_id' => $transaction_data['native_id'])); if ($auto_submit) { wa()->getResponse()->redirect($url); return null; } else { $view = wa()->getView(); $view->assign('form_url', $url); $view->assign('messages', $messages); return $view->fetch($this->path . '/templates/paymentRest.html'); } } elseif (in_array($transaction_data['state'], array(self::STATE_DECLINED, self::STATE_CANCELED))) { $transaction_data_model = new waTransactionDataModel(); $raw_status = $transaction_data_model->getByField(array('transaction_id' => $transaction_data['id'], 'field_id' => 'status')); switch (ifempty($raw_status['value'])) { case 'expired': /** Время жизни счета истекло. Счет не оплачен. **/ $message = sprintf('Время жизни счета истекло. Счет %s не оплачен.', $order_data->id_str); break; case 'unpaid': /** Ошибка при проведении оплаты. Счет не оплачен. **/ $message = sprintf('Ошибка при проведении оплаты. Счет %s не оплачен.', $order_data->id_str); break; case 'rejected': /**Счет отклонен.**/ $message = sprintf('Счет %s отклонен', $order_data->id_str); break; default: $message = sprintf('Неизвестное состояние для счета %s', $order_data->id_str); break; } } else { $message = 'Возможно, заказ уже оплачен'; } return $message; } else { if (!empty($payment_form_data['customer_phone'])) { $mobile_phone = $payment_form_data['customer_phone']; } else { $mobile_phone = preg_replace('/[\\D]+/', '', $order_data->getContactField($this->customer_phone, 'default')); } $view = wa()->getView(); $view->assign('mobile_phone', $mobile_phone); $view->assign('messages', $messages); return $view->fetch($this->path . '/templates/paymentRest.html'); } }