Esempio n. 1
0
 public static string GetPaymentXML(PayooOrder payooOrder)
 {
     try
     {
         if (payooOrder == null)
         {
             throw new Exception("Parameter is not set.");
         }
         if (string.IsNullOrEmpty(payooOrder.ValidityTime))
         {
             return(string.Format(_XML_Temp, payooOrder.Session, payooOrder.BusinessUsername, payooOrder.ShopID, payooOrder.ShopTitle,
                                  payooOrder.ShopDomain, payooOrder.ShopBackUrl, payooOrder.OrderNo, payooOrder.OrderCashAmount, payooOrder.StartShippingDate,
                                  payooOrder.ShippingDays, payooOrder.OrderDescription, payooOrder.NotifyUrl,
                                  payooOrder.CustomerName, payooOrder.CustomerPhone, payooOrder.CustomerAddress, payooOrder.CustomerCity, payooOrder.CustomerEmail));
         }
         return(string.Format(_XML, payooOrder.Session, payooOrder.BusinessUsername, payooOrder.ShopID, payooOrder.ShopTitle,
                              payooOrder.ShopDomain, payooOrder.ShopBackUrl, payooOrder.OrderNo, payooOrder.OrderCashAmount, payooOrder.StartShippingDate,
                              payooOrder.ShippingDays, payooOrder.OrderDescription, payooOrder.NotifyUrl, payooOrder.ValidityTime,
                              payooOrder.CustomerName, payooOrder.CustomerPhone, payooOrder.CustomerAddress, payooOrder.CustomerCity, payooOrder.CustomerEmail));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        private CreateOrderResponse ExecuteCreatePayooPreOrderRequest(PayooOrder payooOrder, string checksum, out string message)
        {
            try
            {
                var client  = new RestClient(_paymentMethodConfiguration.ApiPayooCheckout);
                var request = new RestRequest(Method.POST);
                request.AddHeader("content-type", "multipart/form-data");
                request.AddParameter("data", payooOrder.Xml);
                request.AddParameter("checksum", checksum);
                request.AddParameter("refer", payooOrder.ShopDomain);
                IRestResponse response = client.Execute(request);
                message = $"Excute request to create Payoo Preorder with status {response.StatusCode}";

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    JavaScriptSerializer objJson = new JavaScriptSerializer();
                    return(objJson.Deserialize <CreateOrderResponse>(response.Content));
                }

                return(null);
            }
            catch (Exception e)
            {
                message = e.Message;
                _logger.Error(e);
                return(null);
            }
        }
        private PayooOrder CreatePayooOrder(IOrderGroup orderGroup, IPayment payment)
        {
            var orderNumberID = _orderNumberGenerator.GenerateOrderNumber(orderGroup);

            var order = new PayooOrder();

            order.Session           = orderNumberID;
            order.BusinessUsername  = _paymentMethodConfiguration.BusinessUsername;
            order.OrderCashAmount   = (long)payment.Amount;
            order.OrderNo           = orderNumberID;
            order.ShippingDays      = 1;
            order.ShopBackUrl       = $"{HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority)}{_cmsPaymentPropertyService.GetPayooPaymentProcessingPage()}";
            order.ShopDomain        = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority);
            order.ShopID            = long.Parse(_paymentMethodConfiguration.ShopID);
            order.ShopTitle         = _paymentMethodConfiguration.ShopTitle;
            order.StartShippingDate = DateTime.Now.ToString("dd/MM/yyyy");
            order.NotifyUrl         = string.Empty;
            order.ValidityTime      = DateTime.Now.AddDays(1).ToString("yyyyMMddHHmmss");

            var customer = CustomerContext.Current.GetContactById(orderGroup.CustomerId);

            order.CustomerName    = customer.FullName ?? $"{customer.FirstName} {customer.MiddleName} {customer.LastName}";
            order.CustomerPhone   = string.Empty;
            order.CustomerEmail   = customer.Email;
            order.CustomerAddress = customer.PreferredShippingAddress?.Line1;
            order.CustomerCity    = customer.PreferredShippingAddress?.City;

            order.OrderDescription = HttpUtility.UrlEncode(OrderDescriptionHTMLFactory.CreateOrderDescription(orderGroup));
            order.Xml = PaymentXMLFactory.GetPaymentXML(order);
            return(order);
        }
        private string CreatePayooChecksum(PayooOrder payooOrder)
        {
            var checksumKey = _paymentMethodConfiguration.ChecksumKey;

            return(Utilities.EncryptSHA512($"{checksumKey}{payooOrder.Xml}"));
        }
        //Thanh toán với Payoo
        protected string btnPaynow_Click(string orderId, string TenDuAn, int SoTien, int NgayChuyenTien, EntityDauTu item)
        {
            EntityPhanThuong phanthuong;
            if (item.IdPhanthuong.GetValueOrDefault() == 0)
            {
                phanthuong = new EntityPhanThuong();
                phanthuong.NoiDung = "Bạn không nhận phần thưởng";
            }
            else
            {
                phanthuong = db.EntityPhanThuongs.Where(p => p.Id == item.IdPhanthuong).First();

            }
            PayooOrder order = new PayooOrder();
            order.Session = orderId;
            order.BusinessUsername = ConfigurationManager.AppSettings["BusinessUsername"];
            order.OrderCashAmount = SoTien;
            order.OrderNo = orderId;
            order.ShippingDays = short.Parse(NgayChuyenTien.ToString());
            order.ShopBackUrl = ConfigurationManager.AppSettings["ShopBackUrl"];
            order.ShopDomain = ConfigurationManager.AppSettings["ShopDomain"];
            order.ShopID = long.Parse(ConfigurationManager.AppSettings["ShopID"]);
            order.ShopTitle = ConfigurationManager.AppSettings["ShopTitle"];
            order.StartShippingDate = DateTime.Now.ToString("dd/MM/yyyy");
            order.NotifyUrl = ConfigurationManager.AppSettings["NotifyUrl"];
            //You can do

            string OrderHtml = "<table width='100%' border='1' cellspacing='0'><thead><tr><td width='30%' align='center'><b>Dự án bạn đã đầu tư</b></td><td width='45%' align='center'><b>Phần thưởng</b></td><td width='25%' align='center'><b>Số tiền</b></td></tr></thead><tbody>";
            OrderHtml += "<tr><td align='center'>" + TenDuAn + "</td><td align='center'>" + phanthuong.NoiDung + "</td><td align='right'>" + String.Format("{0:0,0 VNĐ}", SoTien) + "</td></tr>";
            //OrderHtml += "<tr><td align='left'>Chi phí thuế</td><td align='right'>50,000</td><td align='right'>50,000</td></tr>";
            OrderHtml += "<tr><td align='right' colspan='2'><b>Tổng tiền:</b></td><td align='right'>" + String.Format("{0:0,0 VNĐ}", SoTien) + "</tr>";
            OrderHtml += "<tr><td align='left' colspan='3'>Một vài lưu ý khác: </td></tr></tbody></table>";
            order.OrderDescription = HttpUtility.UrlEncode(OrderHtml);

            //order.OrderDescription = HttpUtility.UrlEncode("<table width='100%' border='1' cellspacing='0'><thead><tr><td width='45%' align='center'><b>Tên dự án</b></td><td width='30%' align='center'><b>Số tiền đầu tư</b></td><td width='25%' align='center'><b>Thành tiền</b></td></tr></thead><tbody><tr><td align='left'>Dự án chuồn chuồn giấy</td><td align='right'>500,000</td><td align='right'>500,000</td></tr><tr><td align='left'>Chi phí thuế</td><td align='right'>50,000</td><td align='right'>50,000</td></tr><tr><td align='right' colspan='2'><b>Tổng tiền:</b></td><td align='right'>550,000</td></tr><tr><td align='left' colspan='3'>Một vài lưu ý khác</td></tr></tbody></table>");

            string Checksum = string.Empty;

            //Su dung checksum ko ma hoa du lieu
            //string ChecksumKey = ConfigurationManager.AppSettings["ChecksumKey"];
            //string XML = PaymentXMLFactory.GetPaymentXML(order);
            //Checksum = SHA1encode.hash(ChecksumKey + XML);

            //khong su dung checksum, co ma hoa du lieu
            string XML = PaymentXMLFactory.GetPaymentXML(order, Server.MapPath(@"..\App_Data\Certificates\biz_pkcs12.p12"), "alpe", Server.MapPath(@"..\App_Data\Certificates\payoo_public_cert.pem"));

            return RedirectToProvider(ConfigurationManager.AppSettings["PayooCheckout"], XML, Checksum);
        }