Показать сообщение отдельно
Старый 08.01.2012, 21:33   #29   
ЙаТрамвайчег
 
Аватар для RazdoR
 
Сообщений: 748
Регистрация: 22.02.2008

RazdoR вне форума Не в сети
Вот он, родимый))
Это для платрона было сделано. от платрока брали мануал, как xml формировать - и вперед.
Код:
string host = @"http://" + (Request.Url.Host == "localhost" ? Request.Url.Authority : Request.Url.Host);

                PlatronXmlMessage pRequestMsg = new PlatronXmlMessage(PlatronXmlMessage.MessageType.Request);

                pRequestMsg.AddTag("pg_merchant_id", "122"); //*
                pRequestMsg.AddTag("pg_order_id", order.OrderId.ToString());
                pRequestMsg.AddTag("pg_amount", order.AmountToPayRUR.ToString("0.00", _CultureInfoEN_US));
                pRequestMsg.AddTag("pg_currency", "RUR");
                //pRequestMsg.AddTag("pg_check_url", host + "/Platron/Check");
                pRequestMsg.AddTag("pg_result_url", host + "/Platron/Result");
                pRequestMsg.AddTag("pg_refund_url", host + "/Platron/Refund");
                pRequestMsg.AddTag("pg_request_method", "XML");
                pRequestMsg.AddTag("pg_success_url", host + "/Platron/Success");
                pRequestMsg.AddTag("pg_success_url_method", "AUTOPOST");
                pRequestMsg.AddTag("pg_failure_url", host + "/Platron/Failure");
                pRequestMsg.AddTag("pg_failure_url_method", "AUTOPOST");

                pRequestMsg.AddTag("pg_description", String.Format("{0} ({1} мес., {2}: {3})", product.DisplayName, monthsToPay, terminal.DisplayName, licTerminalLogins));
                pRequestMsg.AddTag("pg_user_phone", userProfile.CellPhoneNumber);
                pRequestMsg.AddTag("pg_user_email", membershipUser.Email);
                //pRequestMsg.AddTag("user_test", "Привет, мой малыш!");
                pRequestMsg.AddTag("pg_encoding", "UTF-8");

                string secretKey;
                string[] appSettingsValues = WebConfigurationManager.AppSettings.GetValues("platronSecretKey");

                if (appSettingsValues == null && appSettingsValues.Length == 0)
                    throw new SiteException("Не найден секретный ключ Платрона.");

                secretKey = appSettingsValues[0];


                RequestToPlatron platronRequest = new RequestToPlatron("https://www.platron.ru/init_payment.php");

                pRequestMsg.Sign("init_payment.php", secretKey);

                platronRequest.AddRequestData(pRequestMsg.Xml);

                _DataManager.Transactions.CreateTransaction(
                    order.OrderId, null, "AboutToSendOrderToPlatron", "Ok", "Собираюсь послать Платрону сообщение.", pRequestMsg.Xml);

                ResponseFromPlatron platronResponse = platronRequest.GetResponseFromPlatron();

                if (platronResponse == null)
                    throw new SiteException("Платрон не ответил на запрос генерации заказа.");

                _DataManager.Transactions.CreateTransaction(
                    order.OrderId, null, "PlatronResponseFromOrderSent", "Ok", "От Платрона пришел ответ.", platronResponse.GetContent());

                PlatronXmlMessage pResponseMsg = null;

                try
                {
                    pResponseMsg = new PlatronXmlMessage(platronResponse.GetContent(), PlatronXmlMessage.MessageType.Response);
                }
                catch (Exception ex)
                {
                    throw new SiteException("Ошибка парсинга сообщения от Платрона.", ex);
                }

                if (!pResponseMsg.CheckSign("init_payment.php", secretKey))
                    throw new SiteException(String.Format("[CreateNewOrder] Ошибка проверки подписи сообщения от Платрона. PlatronXmlMessage: '{0}'.", pResponseMsg.Xml));

                if (!pResponseMsg.IsMessageStatusOk())
                    throw new SiteException("Ответ от Платрона пришел со статусом отличным от 'Ok'.");

                string pg_redirect_url = pResponseMsg.FindFirstTagText("pg_redirect_url");

                if (pg_redirect_url == null)
                    throw new SiteException("Ответ от Платрона не содержит ссылки перехода ('pg_redirect_url') на оформление платежа.");

                return Redirect(pg_redirect_url);
            }
            catch (SiteException ex)
            {
                log.Error(ex.Message, ex);
                if (order != null) _DataManager.Orders.AddErrorToOrder(order.OrderId, ex.Message);
                ModelState.AddModelError("", "Ошибка обслуживания платежной системы. Пожалуйста, свяжитесь с нами.");
                //return View("Index", model);
                return View(model);
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex);
                if (order != null) _DataManager.Orders.AddErrorToOrder(order.OrderId, ex.Message);
                ModelState.AddModelError("", "Ошибка обслуживания платежной системы. Пожалуйста, свяжитесь с нами.");
                //return View("Index", model);
                return View(model);
            }
        }

    }
}
Это у меня было взаимодействие с платроном. Ничего никому не передается, кроме того что мы задали. Сделать для робокассы или другой платежной системы - два высших и докторская не нужна.