Exemple #1
0
    //public void CheckSession()
    //{
    //    if (Session["ActiveClient"] == null)
    //    {
    //        Response.Redirect("~/Default.aspx");
    //    }
    //}

    public string CreatePayPage(Models.PayPageRequest objPayPageRequest)
    {
        return("merchant_email=" + objPayPageRequest.MerchantEmail
               + "&secret_key=" + objPayPageRequest.SecretKey
               + "&currency=" + objPayPageRequest.Currency
               + "&amount=" + objPayPageRequest.Amount
               + "&site_url=" + objPayPageRequest.SiteUrl
               + "&title=" + objPayPageRequest.ProductsPerTitle
               + "&quantity=" + objPayPageRequest.Quantity
               + "&unit_price=" + objPayPageRequest.UnitPrice
               + "&products_per_title=" + objPayPageRequest.ProductsPerTitle
               + "&return_url=" + objPayPageRequest.SiteUrl + "/Receipt.aspx"
               + "&cc_first_name=" + objPayPageRequest.CcFirstNname
               + "&cc_last_name=" + objPayPageRequest.CcLastName
               + "&cc_phone_number=" + objPayPageRequest.CcPhoneNumber
               + "&phone_number=" + objPayPageRequest.CcPhoneNumber
               + "&billing_address=" + objPayPageRequest.BillingAddress
               + "&city=" + objPayPageRequest.City
               + "&state=" + objPayPageRequest.State
               + "&postal_code=" + objPayPageRequest.PostalCode
               + "&country=" + objPayPageRequest.Country
               + "&email=" + objPayPageRequest.Email
               + "&ip_customer=" + System.Net.Dns.GetHostName()
               + "&ip_merchant=100.100.100.100"
               + "&address_shipping=" + objPayPageRequest.AddressShipping
               + "&city_shipping=" + objPayPageRequest.CityShipping
               + "&state_shipping=" + objPayPageRequest.StateShipping
               + "&postal_code_shipping=" + objPayPageRequest.PostalCodeShipping
               + "&country_shipping=" + objPayPageRequest.CountryShipping
               + "&other_charges=0"
               + "&discount=0"
               + "&reference_no=" + GenerateReferenceNumber()
               + "&msg_lang=English"
               + "&cms_with_version=API");
    }
        protected Models.PayPageRequest CreatePayPage()
        {
            if (Helper.PayTabsSession.EmailAddress == null)
            {
                Response.Redirect("~/ClientSettings.aspx");
                return(null);
            }
            else
            {
                var objRequest = new Models.PayPageRequest
                {
                    MerchantEmail      = Helper.PayTabsSession.EmailAddress,
                    SecretKey          = Helper.PayTabsSession.SecretKey,
                    Currency           = ddlCurrency.SelectedValue,
                    Amount             = hdnTotalAmount.Value,
                    SiteUrl            = Helper.PayTabsSession.SiteUrl,
                    Title              = txtProduct.Text,
                    Quantity           = txtQuantity.Text,
                    UnitPrice          = txtPrice.Text,
                    ProductsPerTitle   = txtProduct.Text,
                    ReturnUrl          = Helper.PayTabsSession.SiteUrl + "/Receipt.aspx",
                    CcFirstNname       = txtFirstName.Text,
                    CcLastName         = txtLastName.Text,
                    Phonenumber        = txtPhone.Text,
                    CcPhoneNumber      = txtPhone.Text,
                    BillingAddress     = txtAddress1.Text,
                    City               = txtCity.Text,
                    State              = txtState.Text,
                    PostalCode         = txtZipCode.Text,
                    Country            = ddlCountry.SelectedValue,
                    Email              = txtEmailAddress.Text,
                    AddressShipping    = txtShippingAddress.Text,
                    CityShipping       = txtShippingCity.Text,
                    StateShipping      = txtShippingState.Text,
                    PostalCodeShipping = txtShippingZipCode.Text,
                    CountryShipping    = ddlShippingCountry.SelectedValue,
                    PaymentDate        = DateTime.Now.Date
                };

                return(objRequest);
            }
        }
        protected void btnSave_click(object sender, EventArgs e)
        {
            var objrequest = new Models.PayPageRequest();
            var tmp        = new Models.PayPageResponse();

            try
            {
                var paymentUtility = new Utility();
                objrequest = CreatePayPage();

                //Log to File
                Logger.Info("MakePaymentStep1 - Start", "btnSave_click", objrequest);

                string serviceResponse = paymentUtility.MakeWebServiceCall(Utility.ConstCreatePayPage, paymentUtility.CreatePayPage(objrequest));
                tmp = JsonConvert.DeserializeObject <Models.PayPageResponse>(serviceResponse);

                //Log Response to File
                Logger.Info("MakePaymentStep1 - End", "btnSave_click", tmp);

                if (tmp.response_code != null && tmp.response_code != "4012")
                {
                    lblErrorMessage.Text = paymentUtility.GetPayTabResponseMessage(Utility.PayTabRequestType.CreatePayPage, tmp.response_code, tmp.result);
                }
                else if (tmp.payment_url != "")
                {
                    //Set Payment Active URL to session
//                var activeClient = (Models.Settings)Session["ActiveClient"];
                    Helper.PayTabsSession.CurrentActivePaymentID     = tmp.payment_url;
                    Helper.PayTabsSession.LastPaymentReferenceNumber = tmp.p_id;
                    Helper.PayTabsSession.PageRequestList            = new List <Models.PayPageRequest>();
                    objrequest.PaymentReference = tmp.p_id;

                    var paymentList = new Models.PaymentsList();
                    paymentList.PayPageRequests = new List <Models.PayPageRequest>();
                    if (HttpRuntime.Cache["PAYTABS_PAYMENTS"] != null)
                    {
                        paymentList = HttpRuntime.Cache["PAYTABS_PAYMENTS"] as Models.PaymentsList;

                        //Remove the Old
                        HttpRuntime.Cache.Remove("PAYTABS_PAYMENTS");
                    }

                    paymentList.PayPageRequests.Add(objrequest);

                    HttpRuntime.Cache.Insert("PAYTABS_PAYMENTS", paymentList, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(60));

                    Helper.PayTabsSession.PageRequestList.Add(objrequest);

                    //Redirect to Hosted Page
                    Response.Redirect("~/ClientHost.aspx");
                }
            }
            catch (System.Net.WebException ex)
            {
                //Log Response to File
                Logger.Info("MakePaymentStep1 - Exception", "btnSave_click", ex);

                if (ex.Message.Contains("The remote name could not be resolved"))
                {
                    lblErrorMessage.Text = ex.Message;
                }
            }
            catch (Exception ex)
            {
                //Log Response to File
                Logger.Info("MakePaymentStep1 - Exception", "btnSave_click", ex);
            }
        }