Example #1
0
        // GET: Payment method fir github

        public ActionResult Payment(string aTranId, string CusProfilId = "")
        {
            CardInfoViewModel cardInfoView = new CardInfoViewModel();

            try
            {
                //cardInfoView.CustomerId = "A001";
                //cardInfoView.email = "*****@*****.**";
                //cardInfoView.customerProfile_Id = "1960547788";
                //cardInfoView.savecard = GetCardInfo(cardInfoView.customerProfile_Id);
                var        requestUrl   = $"{ConfigurationManager.AppSettings["GetPaymentInfoUrl"]}";
                var        urlParameter = $"?aTranId={aTranId}";
                HttpClient client       = new HttpClient();
                client.BaseAddress = new Uri(requestUrl);

                // Add an Accept header for JSON format.
                client.DefaultRequestHeaders.Accept.Add(
                    new MediaTypeWithQualityHeaderValue("application/json"));
                // List data response.
                HttpResponseMessage response = client.GetAsync(urlParameter).Result;  // Blocking call! Program will wait here until a response is received or a timeout occurs.
                if (response.IsSuccessStatusCode)
                {
                    // Parse the response body.
                    var         dataObjects = response.Content.ReadAsStringAsync().Result;
                    PaymentInfo obj         = JsonConvert.DeserializeObject <PaymentInfo>(dataObjects);
                    cardInfoView.reqId = PaymentInfo.SaveRequest(obj);
                    if (obj.StatusCode == "200")
                    {
                        cardInfoView.email = obj.customeremail;
                        cardInfoView.customerProfile_Id     = string.IsNullOrEmpty(obj.CustomerProfileId) ? CusProfilId : obj.CustomerProfileId;//obj.CustomerProfileId == string.Empty? CusProfilId: obj.CustomerProfileId;//"1599538578";
                        cardInfoView.Amount                 = Math.Round(Convert.ToDecimal(obj.amount), 2);
                        cardInfoView.InvoiceNumber          = obj.docType.ToLower() == "order" ? obj.OrderNumber : obj.InvoiceNumber;
                        cardInfoView.ANET_ApiLoginID        = obj.ANET_ApiLoginID;
                        cardInfoView.OderNumber             = obj.OrderNumber;
                        cardInfoView.ANET_ApiTransactionKey = obj.ANET_ApiTransactionKey;
                        cardInfoView.Environment            = obj.env;
                        cardInfoView.aTranId                = obj.tranidkey;
                        cardInfoView.taxAmount              = obj.taxAmount;
                        cardInfoView.shipping               = obj.shipping;
                        cardInfoView.docType                = obj.docType;
                        // billing and shiping info
                        cardInfoView.billingFName         = obj.billingFName;
                        cardInfoView.billingLName         = obj.billingLName;
                        cardInfoView.billingCompany       = obj.billingCompany;
                        cardInfoView.billingAddrLine1     = obj.billingAddrLine1;
                        cardInfoView.billingAddressLine2  = obj.billingAddressLine2;
                        cardInfoView.billingCity          = obj.billingCity;
                        cardInfoView.billingState         = obj.billingState;
                        cardInfoView.billingCountry       = obj.billingCountry;
                        cardInfoView.billingZipCode       = obj.billingZipCode;
                        cardInfoView.billingPhno          = obj.billingPhno;
                        cardInfoView.billingFax           = obj.billingFax;
                        cardInfoView.shippingFName        = obj.shippingFName;
                        cardInfoView.shippingLName        = obj.shippingLName;
                        cardInfoView.shippingCompany      = obj.shippingCompany;
                        cardInfoView.shippingAddrLine1    = obj.shippingAddrLine1;
                        cardInfoView.shippingAddressLine2 = obj.shippingAddressLine2;
                        cardInfoView.shippingCity         = obj.shippingCity;
                        cardInfoView.shippingState        = obj.shippingState;
                        cardInfoView.shippingCountry      = obj.shippingCountry;
                        cardInfoView.shippingZipCode      = obj.shippingZipCode;
                        cardInfoView.shippingPhno         = obj.shippingPhno;
                        cardInfoView.shippingFax          = obj.shippingFax;

                        // billing and shiping info
                        if (!string.IsNullOrEmpty(cardInfoView.customerProfile_Id))
                        {
                            cardInfoView.savecard = _helper.GetCardInfo(cardInfoView.customerProfile_Id, cardInfoView.ANET_ApiLoginID, cardInfoView.ANET_ApiTransactionKey);
                        }
                    }
                    else
                    {
                        return(Json($"Error Geting Customer information: {obj.Message}", JsonRequestBehavior.AllowGet));
                    }
                }
                else
                {
                    //Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
                    return(Json("Error Geting Customer information", JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                string path = $"{System.Web.HttpContext.Current.Server.MapPath("~/Error")}/{Guid.NewGuid().ToString()}.txt";
                FileSave.FileSaveData(path, ex.Message);
            }

            return(View(cardInfoView));
        }