예제 #1
0
        public void Perform()
        {
            var enteredValue = string.Empty;
            var methodValue  = 0;
            var account      = new Account();

            Console.WriteLine("Please choose one of following Payment Methods");
            var methods = Enum.GetValues(typeof(PaymentMethod));

            foreach (PaymentMethod method in methods)
            {
                Console.WriteLine($"{(int)method} {method}");
            }
            while (string.IsNullOrWhiteSpace(enteredValue))
            {
                try
                {
                    enteredValue = Console.ReadLine();
                    methodValue  = Convert.ToInt32(enteredValue);
                    SetAccount((PaymentMethod)methodValue, ref account);
                }
                catch (System.FormatException ex)
                {
                    Console.WriteLine("The entered value is not correct format ! Please enter another one.", ex);
                    enteredValue = string.Empty;
                }
            }
            var paymentParams = new PaymentParam {
                Account = account
            };
            var paymentMethod    = PaymentChooser.GetPaymentMethod((PaymentMethod)methodValue, paymentParams);
            var paymentProcessor = new PaymentProcessor(paymentMethod);

            paymentProcessor.Create();
        }
예제 #2
0
        public string GetPayParams(PaymentParam param)
        {
            var total     = param.Total.ToString("N");
            var currency  = Enum.GetName(typeof(PaypalCurrency), param.Currency);
            var payParams = new
            {
                intent        = "sale",
                redirect_urls = new
                {
                    return_url = param.ReturnUrl,
                    cancel_url = param.CancelUrl,
                },
                payer = new
                {
                    payment_method = "paypal"
                },
                transactions = new dynamic[]
                {
                    new
                    {
                        amount = new
                        {
                            total    = total,
                            currency = currency
                        },
                        description = param.Description,
                        custom      = param.Code,
                        item_list   = new
                        {
                            items = new dynamic[]
                            {
                                new
                                {
                                    name = param.Name,
                                    //description = param.Name,
                                    quantity = "1",
                                    price    = total,
                                    //tax = "0.01",
                                    //sku = "1",
                                    currency = currency
                                }
                            }
                        }
                    }
                }
            };
            var json = new JavaScriptSerializer().Serialize(payParams);

            return(json);
        }
예제 #3
0
        public IActionResult Notify(int platformId = 2)
        {
            var onlinePay = GetOnlinePay(platformId);

            if (onlinePay == null)
            {
                return(StatusCode(404));
            }
            var param  = new PaymentParam(Request.Query);
            var result = onlinePay.HandleNotify(param);

            if (!result)
            {
                Logger.LogError(1, "{onlinePay} Notify 处理失败 支付单({payId}) 支付平台交易号{payNo} {message}", onlinePay.Name, result.Data.PayId, result.Data.PayNo, result.Message);
            }
            return(Content(result.Data.Output));
        }
예제 #4
0
        public IActionResult Callback(int platformId = 2)
        {
            var onlinePay = GetOnlinePay(platformId);

            if (onlinePay == null)
            {
                return(StatusCode(404));
            }
            var param  = new PaymentParam(Request.Query);
            var result = onlinePay.HandleNotify(param);

            if (!result)
            {
                Logger.LogError(1, "{onlinePay} Callback 处理失败 支付单({payId}) 支付平台交易号{payNo} {message}", onlinePay.Name, result.Data.PayId, result.Data.PayNo, result.Message);
            }
            return(Redirect("/pay/result/" + result.Data.PayId));//跳转到结果页面统一处理
        }
예제 #5
0
        /// <summary>
        /// 保存订单商品
        /// </summary>
        /// <param name="billid"></param>
        /// <param name="goodsDT"></param>
        /// <param name="paymentParam"></param>
        /// <returns></returns>
        private bool saveOrderGoods(string billid, DataTable goodsDT, PaymentParam paymentParam)
        {
            string insql = "insert into t_order_goods(merchantOrderId,barCode,skuUnitPrice,quantity," +
                           " goodsName,sendType,skubillname,supplyPrice,purchasePrice) " +
                           " values('" + billid + "','" + goodsDT.Rows[0]["barcode"].ToString() + "'," + goodsDT.Rows[0]["price"].ToString() + "," + paymentParam.inputNum + "," +
                           " '" + goodsDT.Rows[0]["goodsname"].ToString() + "','XXC','" + goodsDT.Rows[0]["goodsname"].ToString() + "',0,0)";

            if (DatabaseOperationWeb.ExecuteDML(insql))
            {
                //setGoodsNum(billid, goodsDT.Rows[0]["barcode"].ToString(),Convert.ToInt32( paymentParam.inputNum));
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #6
0
 /// <summary>
 /// 保存订单
 /// </summary>
 /// <param name="openId"></param>
 /// <param name="billid"></param>
 /// <param name="paymentParam"></param>
 /// <returns></returns>
 public bool saveOrder(string openId, string billid, PaymentParam paymentParam)
 {
     try
     {
         Util      util    = new Util();
         string[]  addrSts = util.getAddr(paymentParam.inputAddress);//获取地址编码
         string    sql     = "select * from t_goods_list where id =" + paymentParam.goodsId;
         DataTable dt      = DatabaseOperationWeb.ExecuteSelectDS(sql, "t_goods_list").Tables[0];
         if (dt.Rows.Count > 0)
         {
             string    sql1  = "select wcode from t_goods_warehouse where barcode = '" + dt.Rows[0]["barcode"].ToString() + "' and suppliercode ='*****@*****.**'  ";
             DataTable dt1   = DatabaseOperationWeb.ExecuteSelectDS(sql1, "t_goods_list").Tables[0];
             string    wcode = "";
             if (dt1.Rows.Count > 0)
             {
                 wcode = dt1.Rows[0]["wcode"].ToString();
             }
             double total = Convert.ToDouble(dt.Rows[0]["price"]) * Convert.ToDouble(paymentParam.inputNum);
             string insql = "insert into t_order_list(warehouseCode,customerCode,parentOrderId,merchantOrderId,tradeTime," +
                            "tradeAmount,goodsTotalAmount,consigneeName,consigneeMobile," +
                            "addrCountry,addrProvince,addrCity,addrDistrict," +
                            "addrDetail,zipCode,idType,idNumber," +
                            "idFountImgUrl,idBackImgUrl,status,purchaserCode," +
                            "apitype,fqID,sendapi,orderType) " +
                            "values('" + wcode + "','" + openId + "','" + billid + "','" + billid + "','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'," +
                            "" + total + "," + total + ",'" + paymentParam.inputName + "','" + paymentParam.inputPhone + "'," +
                            "'中国','" + addrSts[0] + "','" + addrSts[1] + "','" + addrSts[2] + "'," +
                            "'" + addrSts[3] + "','000000','1','" + paymentParam.inputIdCard + "'," +
                            "'','',0,'" + paymentParam.shop + "'," +
                            "'XXC','','XXC','" + paymentParam.radio + "')";
             if (DatabaseOperationWeb.ExecuteDML(insql))
             {
                 if (saveOrderGoods(billid, dt, paymentParam))
                 {
                     return(true);
                 }
             }
         }
         return(false);
     }
     catch (Exception)
     {
         return(false);
     }
 }
예제 #7
0
        //private void setGoodsNum(string orderid, string tm, int num)
        //{
        //    string sql = "update t_ck_goods_warehouse set goodsnum=goodsnum-" + num + " where barcode = '" + tm;//+ "' and wcode= '" + wcode + "' ";
        //    if (DatabaseOperation.ExecuteDML(sql))
        //    {
        //        setGoodsNumLog(orderid, tm, num, "扣除库存");
        //    }
        //}

        //private void setGoodsNumLog(string orderid, string tm, int num, string state)
        //{
        //    string sql = "insert into t_log_goodsnum (createtime,wcode,orderid,tm,goodsnum,state) values(now(),'" + "" + "','" + orderid + "','" + tm + "'," + num + ",'" + state + "')";
        //    DatabaseOperation.ExecuteDML(sql);
        //}

        /// <summary>
        /// 获取订单总金额
        /// </summary>
        /// <param name="paymentParam"></param>
        /// <returns></returns>
        public int getOrderTotalPrice(PaymentParam paymentParam)
        {
            try
            {
                string    sql = "select price from t_goods_list where id =" + paymentParam.goodsId;
                DataTable dt  = DatabaseOperationWeb.ExecuteSelectDS(sql, "t_goods_list").Tables[0];
                if (dt.Rows.Count > 0)
                {
                    double total = Convert.ToDouble(dt.Rows[0]["price"]) * Convert.ToDouble(paymentParam.inputNum);
                    return(Convert.ToInt32(total * 100));
                }
                return(0);
            }
            catch (Exception)
            {
                return(0);
            }
        }
예제 #8
0
        public static Payment GetPaymentMethod(PaymentMethod method, PaymentParam param = null)
        {
            switch (method)
            {
            case PaymentMethod.Cash:
                return(new Cash());

            case PaymentMethod.ZaloPay:
                return(new ZaloPay());

            case PaymentMethod.Momo:
                return(new Momo());

            case PaymentMethod.InternetBanking:
                return(new InternetBanking());

            case PaymentMethod.MasterCard:
                return(new MasterCard(param.Account));

            default:
                return(new Cash());
            }
        }
예제 #9
0
        /// <summary>
        /// 保存订单商品
        /// </summary>
        /// <param name="billid"></param>
        /// <param name="goodsDT"></param>
        /// <param name="paymentParam"></param>
        /// <returns></returns>
        private bool saveOrderGoods(string billid, DataTable goodsDT, PaymentParam paymentParam)
        {
            string    sql  = "select offer from t_goods_offer where barcode = '" + goodsDT.Rows[0]["barcode"].ToString() + "' and usercode ='O2O' ";
            DataTable dt   = DatabaseOperationWeb.ExecuteSelectDS(sql, "t_goods_list").Tables[0];
            string    sql1 = "select inprice from t_goods_warehouse where barcode = '" + goodsDT.Rows[0]["barcode"].ToString() + "' and suppliercode ='*****@*****.**'  ";
            DataTable dt1  = DatabaseOperationWeb.ExecuteSelectDS(sql1, "t_goods_list").Tables[0];

            string insql = "insert into t_order_goods(merchantOrderId,barCode,slt,skuUnitPrice,quantity," +
                           " goodsName,sendType,skubillname,supplyPrice,purchasePrice) " +
                           " values('" + billid + "','" + goodsDT.Rows[0]["barcode"].ToString() + "','" + goodsDT.Rows[0]["slt"].ToString() +
                           "'," + goodsDT.Rows[0]["price"].ToString() + "," + paymentParam.inputNum + "," +
                           " '" + goodsDT.Rows[0]["goodsname"].ToString() + "','XXC','" + goodsDT.Rows[0]["goodsname"].ToString() +
                           "'," + dt.Rows[0][0].ToString() + "," + dt1.Rows[0][0].ToString() + ")";

            if (DatabaseOperationWeb.ExecuteDML(insql))
            {
                //setGoodsNum(billid, goodsDT.Rows[0]["barcode"].ToString(),Convert.ToInt32( paymentParam.inputNum));
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #10
0
        public ActionResult Payment(PaymentParam model)
        {
            try
            {
                HttpCookie          reqCookies = Request.Cookies["MemberLoginCookie"];
                ResponseMemberLogin login      = JsonConvert.DeserializeObject <ResponseMemberLogin>(reqCookies.Value.ToString().UrlDecode());
                if (login == null || login.ID == 0)
                {
                    return(Json(new PaymentResult {
                        Status = -1, Uri = ""
                    }));
                }

                double reduce = 0;

                var tour = _tourBusiness.GetDetail(model.TourID);
                if (tour != null && tour.ID != 0)
                {
                    var steps = _stepBusiness.GetAll(tour.ID);

                    if (model.PCode != "")
                    {
                        var promotion = _promotionBusiness.ApplyPromotion(model.PCode);
                        if (promotion != null && promotion.ID != 0)
                        {
                            if (promotion.TourApply == "" || promotion.TourApply == null)
                            {
                                if (promotion.Type == 1)
                                {
                                    reduce = promotion.AmountReduced;
                                }
                                else
                                {
                                    reduce = (tour.Price * promotion.PercentReduced) / 100;
                                }
                            }
                            else
                            {
                                if (promotion.TourApply.Contains(tour.ID.ToString()))
                                {
                                    if (promotion.Type == 1)
                                    {
                                        reduce = promotion.AmountReduced;
                                    }
                                    else
                                    {
                                        reduce = (tour.Price * promotion.PercentReduced) / 100;
                                    }
                                }
                            }
                        }
                    }

                    OrderView order = new OrderView();
                    order.Amount     = tour.Price - reduce;
                    order.Code       = $"{DateTime.Now.ToString("ddMMyy")}{RandomUtils.RandomString(6, 8, true, true, false)}";
                    order.Date       = DateTime.Now;
                    order.IsPayment  = false;
                    order.Member     = login.ID;
                    order.MemberName = login.Name;
                    order.Price      = tour.Price;
                    order.Reduce     = reduce;
                    order.Status     = 0;
                    order.Step       = 0;
                    order.Tour       = tour.ID;
                    if (_orderBusiness.Add(order))
                    {
                        _orderBusiness.Save();

                        long oID = _orderBusiness.GetID(order.Code);

                        if (steps != null && steps.Count() > 0 && oID != 0)
                        {
                            int max   = steps.Count();
                            int count = 1;
                            foreach (var item in steps)
                            {
                                OrderDetailView detail = new OrderDetailView();
                                detail.IsAccomplish = false;
                                if (count == max)
                                {
                                    detail.IsLastStep = true;
                                }
                                else
                                {
                                    detail.IsLastStep = false;
                                }
                                detail.OrderID  = oID;
                                detail.Rank     = count;
                                detail.StepID   = item.ID;
                                detail.StepName = item.Name;
                                if (_orderDetailBusiness.Add(detail))
                                {
                                    _orderDetailBusiness.Save();
                                }

                                count++;
                            }
                        }

                        if (model.TypePay == 0)
                        {
                            string uri = CreateRequestPaymentPort(order.Amount.ToString(), order.Code, login.ID.ToString());
                            return(Json(new PaymentResult {
                                Status = 1, Uri = uri
                            }));
                        }
                        if (model.TypePay == 1)
                        {
                            string uri = CreateRequestPaymentPortGlobal(order.Amount.ToString(), order.Code, login.ID.ToString());
                            return(Json(new PaymentResult {
                                Status = 1, Uri = uri
                            }));
                        }
                    }
                }
                return(Json(new PaymentResult {
                    Status = -1, Uri = ""
                }));
            }
            catch (Exception)
            {
                return(Json(new PaymentResult {
                    Status = -1, Uri = ""
                }));
            }
        }
예제 #11
0
        public PaymentResult Pay(PaymentParam param)
        {
            var json = GetPayParams(param);

            return(Pay(json));
        }
예제 #12
0
        public ActionResult Payment(PaymentParam model)
        {
            try
            {
                HttpCookie          reqCookies = Request.Cookies["MemberLoginCookie"];
                ResponseMemberLogin login      = JsonConvert.DeserializeObject <ResponseMemberLogin>(reqCookies.Value.ToString().UrlDecode());
                if (login == null || login.ID == 0)
                {
                    return(Json(new PaymentResult {
                        Status = -1, Uri = ""
                    }));
                }

                double reduce = 0;

                var doctor = _doctorBusiness.GetByID(model.DoctorID);

                if (doctor != null && doctor.ID != 0)
                {
                    if (model.PCode != "")
                    {
                        var promotion = _promotionBusiness.ApplyPromotion(model.PCode);
                        if (promotion != null && promotion.ID != 0)
                        {
                            if (promotion.DoctorApply == "" || promotion.DoctorApply == null)
                            {
                                if (promotion.Type == 1)
                                {
                                    reduce = promotion.AmountReduced;
                                }
                                else
                                {
                                    reduce = (doctor.Price * promotion.PercentReduced) / 100;
                                }
                            }
                            else
                            {
                                if (promotion.DoctorApply.Contains(doctor.ID.ToString()))
                                {
                                    if (promotion.Type == 1)
                                    {
                                        reduce = promotion.AmountReduced;
                                    }
                                    else
                                    {
                                        reduce = (doctor.Price * promotion.PercentReduced) / 100;
                                    }
                                }
                            }
                        }
                    }

                    AppoinmentView appoinment = new AppoinmentView();
                    appoinment.Amount    = doctor.Price - reduce;
                    appoinment.Code      = $"{DateTime.Now.ToString("ddMMyy")}{RandomUtils.RandomString(6, 8, true, true, false)}";
                    appoinment.Date      = model.Date;
                    appoinment.Doctor    = doctor.ID;
                    appoinment.IsPayment = false;
                    appoinment.Patient   = login.ID;
                    appoinment.Price     = doctor.Price;
                    appoinment.Reduce    = reduce;
                    appoinment.Status    = 0;
                    appoinment.Time      = model.Time;

                    if (_appoinmentBusiness.Add(appoinment))
                    {
                        _appoinmentBusiness.Save();
                        if (model.TypePay == 1)
                        {
                            string uri = CreateRequestPaymentPort((appoinment.Amount * 100).ToString(), appoinment.Code, login.ID.ToString());
                            return(Json(new PaymentResult {
                                Status = 1, Uri = uri
                            }));
                        }
                        if (model.TypePay == 2)
                        {
                            string uri = CreateRequestPaymentPortGlobal((appoinment.Amount * 100).ToString(), appoinment.Code, login.ID.ToString());
                            return(Json(new PaymentResult {
                                Status = 1, Uri = uri
                            }));
                        }
                    }
                }
                return(Json(new PaymentResult {
                    Status = -1, Uri = ""
                }));
            }
            catch (Exception)
            {
                return(Json(new PaymentResult {
                    Status = -1, Uri = ""
                }));
            }
        }
예제 #13
0
        public ActionResult Payment(PaymentParam model)
        {
            try
            {
                if (model != null)
                {
                    if (Request.Cookies["MemberLoginCookie"] == null)
                    {
                        return(Json(new PaymentResult {
                            Status = -1, Uri = ""
                        }));
                    }
                    HttpCookie          reqCookies = Request.Cookies["MemberLoginCookie"];
                    ResponseMemberLogin login      = JsonConvert.DeserializeObject <ResponseMemberLogin>(reqCookies.Value.ToString().UrlDecode());
                    if (login == null || login.ID == 0)
                    {
                        return(Json(new PaymentResult {
                            Status = -1, Uri = ""
                        }));
                    }
                    if (Session["ListShoppingCart"] == null)
                    {
                        return(Json(new PaymentResult {
                            Status = -1, Uri = ""
                        }));
                    }
                    List <Cart> carts = (List <Cart>)Session["ListShoppingCart"];
                    if (carts == null || carts.Count() <= 0)
                    {
                        return(Json(new PaymentResult {
                            Status = -1, Uri = ""
                        }));
                    }

                    List <string> codes  = new List <string>();
                    List <string> id     = new List <string>();
                    double        amount = 0;


                    string Code = "";
                    Code += RandomUtils.RandomString(7, 9, true, true, false);
                    if (_orderBusiness.CheckExistsCode(Code))
                    {
                        Code = RandomUtils.RandomString(7, 9, true, true, false);
                    }
                    Code = Code.ToUpperCase(true);
                    OrderView order = new OrderView();
                    order.Amount  = carts.Sum(x => x.Total);
                    order.Code    = Code;
                    order.Date    = DateTime.Now;
                    order.Member  = login.ID;
                    order.Receipt = model.ReceiptID;
                    //order.Reduce=carts.Sum(x=>x.re)
                    order.StatusOrder   = 0;
                    order.StatusPayment = 0;
                    order.Total         = carts.Sum(x => x.Total);
                    order.TypePayment   = model.TypePay;
                    if (_orderBusiness.Add(order))
                    {
                        _orderBusiness.Save();

                        foreach (var d in carts)
                        {
                            OrderDetailView detail = new OrderDetailView();
                            detail.Code    = Code;
                            detail.Price   = d.Price;
                            detail.Product = d.ID;
                            detail.Qty     = d.Qty;
                            detail.Reduce  = 0;
                            detail.Total   = d.Total;
                            if (_orderDetailBusiness.Add(detail))
                            {
                                _orderDetailBusiness.Save();
                            }
                        }
                    }
                    amount = order.Amount;

                    Session["ListShoppingCart"] = null;
                    if (model.TypePay == 2)
                    {
                        return(Json(new PaymentResult {
                            Status = 1, Uri = $"/xac-nhan-dat-hang.html?code={Code}"
                        }));
                    }
                    if (model.TypePay == 0)
                    {
                        string uri = CreateRequestPaymentPort((amount * 100).ToString(), Code, login.Name);
                        return(Json(new PaymentResult {
                            Status = 1, Uri = uri
                        }));
                    }
                    if (model.TypePay == 1)
                    {
                        string uri = CreateRequestPaymentPortGlobal((amount * 100).ToString(), Code, login.Name);
                        return(Json(new PaymentResult {
                            Status = 1, Uri = uri
                        }));
                    }
                }
                return(Json(new PaymentResult {
                    Status = -1, Uri = ""
                }));
            }
            catch (Exception)
            {
                return(Json(new PaymentResult {
                    Status = -1, Uri = ""
                }));
            }
        }