Exemplo n.º 1
0
 public static void AddPaymentDetails(string transactionId, PaymentDetails paymentDetails)
 {
     Dictionary<string, PaymentDetails> paymentHash = null;
     if (HttpContext.Current.Session[WebConstants.Session.PAYMENT_DETAILS] == null)
     {
         HttpContext.Current.Session[WebConstants.Session.PAYMENT_DETAILS] = new Dictionary<string, PaymentDetails>();
     }
     paymentHash = (Dictionary<string, PaymentDetails>)HttpContext.Current.Session[WebConstants.Session.PAYMENT_DETAILS];
     if (paymentHash.ContainsKey(transactionId))
     {
         paymentHash[transactionId] = paymentDetails;
     }
     else
     {
         paymentHash.Add(transactionId, paymentDetails);
     }
     HttpContext.Current.Session[WebConstants.Session.PAYMENT_DETAILS] = paymentHash;
 }
        protected void btnContinue_Click(object sender, ImageClickEventArgs e)
        {
            string url = AppSettings[WebConstants.Config.CYBER_SOURCE_URL];
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
            string proxy = null;
            //clear it from session to keep the session as min as possible
            if (Request[WebConstants.Request.TRANSACTION_ID] != null)
            {
                SessionFactory.RemovePaymentDetails(Request[WebConstants.Request.TRANSACTION_ID]);
            }
            string transactionUId = InsertTransaction();
            if (transactionUId != null)
            {
                PaymentDetails paymentDetails = new PaymentDetails();
                paymentDetails.CardNumber = txtCardNumber.Text;
                paymentDetails.CardType = lstCardType.SelectedValue;
                paymentDetails.Country = txtBillingCountry.Text;
                paymentDetails.County = txtBillingCounty.Text;
                paymentDetails.ExpiryMonth = txtExpiryMonth.SelectedValue;
                paymentDetails.ExpiryYear = txtExpiryYear.SelectedValue;
                paymentDetails.FirstName = txtFirstName.Text;
                paymentDetails.LastName = txtLastName.Text;
                paymentDetails.PostCode = txtBillingZipCode.Text;
                paymentDetails.SecurityCode = txtSecurityCode.Text;
                paymentDetails.StartMonth = txtStartMonth.SelectedValue;
                paymentDetails.StartYear = txtStartYear.SelectedValue;
                paymentDetails.Street = txtBillingStreet.Text;
                paymentDetails.Telephone = txtTelephone.Text;
                paymentDetails.Town = txtBillingTown.Text;
                SessionFactory.AddPaymentDetails(transactionUId, paymentDetails);

                string data = "amount=" + Server.UrlEncode(Request["amount"]);
                data += "&orderNumber=" + Server.UrlEncode(transactionUId);
                data += "&currency=" + Server.UrlEncode(Request["currency"]);
                data += "&orderPage_timestamp=" + Server.UrlEncode(Request["orderPage_timestamp"]);
                data += "&merchantID=" + Server.UrlEncode(Request["merchantID"]);
                data += "&orderPage_transactionType=" + Server.UrlEncode(Request["orderPage_transactionType"]);
                data += "&orderPage_version=" + Server.UrlEncode(Request["orderPage_version"]);
                data += "&orderPage_serialNumber=" + Server.UrlEncode(Request["orderPage_serialNumber"]);
                data += "&orderPage_signaturePublic=" + Server.UrlEncode(Request["orderPage_signaturePublic"]);
                data += "&billTo_city=" + Server.UrlEncode(txtBillingCounty.Text);
                data += "&billTo_country=" + Server.UrlEncode(txtBillingCountry.Text);
                data += "&billTo_firstName=" + Server.UrlEncode(txtFirstName.Text);
                data += "&billTo_lastName=" + Server.UrlEncode(txtLastName.Text);
                data += "&billTo_street1=" + Server.UrlEncode(txtBillingStreet.Text);
                data += "&billTo_street2=" + Server.UrlEncode(txtBillingTown.Text);
                data += "&billTo_phoneNumber=" + Server.UrlEncode(txtTelephone.Text);
                data += "&billTo_postalCode=" + Server.UrlEncode(txtBillingZipCode.Text);
                data += "&card_accountNumber=" + Server.UrlEncode(txtCardNumber.Text);
                data += "&card_cardType=" + Server.UrlEncode(lstCardType.Text);
                data += "&card_cvNumber=" + Server.UrlEncode(txtSecurityCode.Text);
                data += "&card_expirationMonth=" + Server.UrlEncode(txtExpiryMonth.Text);
                data += "&card_expirationYear=" + Server.UrlEncode(txtExpiryYear.Text);
                data += "&card_startMonth=" + Server.UrlEncode(txtStartMonth.Text);
                data += "&card_startYear=" + Server.UrlEncode(txtStartYear.Text);
                data += "&orderPage_requestToken=" + Server.UrlEncode(System.Guid.NewGuid().ToString());

                data += "&recurringSubscriptionInfo_amount=" + Server.UrlEncode(Request["recurringSubscriptionInfo_amount"]);
                data += "&recurringSubscriptionInfo_numberOfPayments=" + Server.UrlEncode(Request["recurringSubscriptionInfo_numberOfPayments"]);
                data += "&recurringSubscriptionInfo_frequency=" + Server.UrlEncode(Request["recurringSubscriptionInfo_frequency"]);
                data += "&recurringSubscriptionInfo_automaticRenew=" + Server.UrlEncode(Request["recurringSubscriptionInfo_automaticRenew"]);
                data += "&recurringSubscriptionInfo_startDate=" + Server.UrlEncode(Request["recurringSubscriptionInfo_startDate"]);
                data += "&recurringSubscriptionInfo_signaturePublic=" + Server.UrlEncode(Request["recurringSubscriptionInfo_signaturePublic"]);

                byte[] buffer = Encoding.UTF8.GetBytes(data);
                try
                {
                    req.Method = "POST";
                    req.ContentType = "application/x-www-form-urlencoded";
                    req.ContentLength = buffer.Length;
                    req.Proxy = new WebProxy(proxy, true);
                    req.CookieContainer = new CookieContainer();

                    Stream reqst = req.GetRequestStream();
                    reqst.Write(buffer, 0, buffer.Length);

                    reqst.Flush();
                    reqst.Close();
                }
                catch (Exception ex)
                {

                    ex.StackTrace.ToString();
                }

                HttpWebResponse res = (HttpWebResponse)req.GetResponse();

                Stream resst = res.GetResponseStream();
                StreamReader sr = new StreamReader(resst);
                string response = sr.ReadToEnd();
                //Response.Write(response);
            }
        }