Exemplo n.º 1
0
        /// <summary>
        /// Generates the XML required for a GenerateRequest call
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        private string GenerateRequestXml(RequestInput input)
        {
            StringWriter sw = new StringWriter();

            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent = true;
            settings.NewLineOnAttributes = false;
            settings.OmitXmlDeclaration  = true;

            using (XmlWriter writer = XmlWriter.Create(sw, settings))
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("GenerateRequest");
                writer.WriteElementString("PxPayUserId", _PxPayUserId);
                writer.WriteElementString("PxPayKey", _PxPayKey);

                PropertyInfo[] properties = input.GetType().GetProperties();

                foreach (PropertyInfo prop in properties)
                {
                    if (prop.CanWrite)
                    {
                        string val = (string)prop.GetValue(input, null);

                        if (val != null || val != string.Empty)
                        {
                            writer.WriteElementString(prop.Name, val);
                        }
                    }
                }
                writer.WriteEndElement();
                writer.WriteEndDocument();
                writer.Flush();
            }

            return(sw.ToString());
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public RequestOutput GenerateRequest(RequestInput input)
        {
            RequestOutput result = new RequestOutput(SubmitXml(GenerateRequestXml(input)));

            return(result);
        }
Exemplo n.º 3
0
        public override string RedirectForPayment(OrderData orderData)
        {
            orderData.OrderStatus = "020";
            orderData.PurchaseInfo.SetXmlProperty("genxml/paymenterror", "");
            orderData.PurchaseInfo.Lang = Utils.GetCurrentCulture();
            orderData.SavePurchaseData();
            try
            {
                var settings = ProviderUtils.GetProviderSettings("NBrightPxPaypayment");

                string PxPayUserId = settings.GetXmlProperty("genxml/textbox/pxpayuserid");
                string PxPayKey    = settings.GetXmlProperty("genxml/textbox/pxpaykey");

                PxPay WS = new PxPay(PxPayUserId, PxPayKey);

                RequestInput input = new RequestInput();

                var appliedtotal = orderData.PurchaseInfo.GetXmlPropertyDouble("genxml/appliedtotal");
                var alreadypaid  = orderData.PurchaseInfo.GetXmlPropertyDouble("genxml/alreadypaid");

                var orderTotal = (appliedtotal - alreadypaid).ToString("0.00");

                var param = new string[3];
                param[0] = "orderid=" + orderData.PurchaseInfo.ItemID.ToString("");
                param[1] = "status=1";
                var returnUrl = Globals.NavigateURL(StoreSettings.Current.PaymentTabId, "", param);
                param[1] = "status=0";
                var returnCancelUrl = Globals.NavigateURL(StoreSettings.Current.PaymentTabId, "", param);

                input.AmountInput       = orderTotal;
                input.CurrencyInput     = settings.GetXmlProperty("genxml/textbox/currencycode");
                input.MerchantReference = settings.GetXmlProperty("genxml/textbox/merchantref");
                input.TxnType           = "Purchase";
                input.UrlFail           = returnUrl;
                input.UrlSuccess        = returnCancelUrl;

                input.TxnId = Guid.NewGuid().ToString().Substring(0, 16);
                orderData.PurchaseInfo.SetXmlProperty("genxml/txnid", input.TxnId);
                orderData.Save();

                RequestOutput output = WS.GenerateRequest(input);

                if (output.valid == "1" && output.URI != null)
                {
                    // Redirect user to payment page
                    return(output.Url);
                }
                else
                {
                    // rollback transaction
                    orderData.PurchaseInfo.SetXmlProperty("genxml/paymenterror", "<div>PAYMENT RETURN ERROR: </div><div>" + output + "</div>");
                    orderData.PaymentFail();
                    return(Globals.NavigateURL(StoreSettings.Current.PaymentTabId, "", param));
                }
            }
            catch (Exception ex)
            {
                // rollback transaction
                orderData.PurchaseInfo.SetXmlProperty("genxml/paymenterror", "<div>PAYMENT EXCEPTION: </div><div>" + ex + "</div>");
                orderData.PaymentFail();

                var param = new string[3];
                param[0] = "orderid=" + orderData.PurchaseInfo.ItemID.ToString("");
                param[1] = "status=0";
                return(Globals.NavigateURL(StoreSettings.Current.PaymentTabId, "", param));
            }
        }