Ejemplo n.º 1
0
 public AlepayCheckOutResultModel GetRedirectUrl(AlepayOrderModel basicModel)
 {
     return(Anpero.HttpHelper <AlepayCheckOutResultModel> .PostJson(IsTest? "https://alepay-v3-sandbox.nganluong.vn/api/v3/checkout/request-payment" : "https://alepay-v3.nganluong.vn/api/v3/checkout/request-payment", basicModel));
 }
Ejemplo n.º 2
0
        public void ProcessRequest(HttpContext context)
        {
            string rs = "0";

            try
            {
                string op      = context.Request["op"].ToLower();
                string captcha = context.Request["captcha"];
                int    price   = Convert.ToInt32(context.Request["price"].Replace(@".", string.Empty).Replace(@".", string.Empty));
                int    orderId = Convert.ToInt32(context.Request["orderId"].Replace(@",", string.Empty));

                string name       = context.Request["name"];
                string shipingFee = context.Request["shipingFee"];
                string email      = context.Request["email"];
                string phone      = context.Request["phone"];

                Boolean valid = true;

                if (price <= 0 || orderId <= 0)
                {
                    valid = false;
                    rs    = "Tiền thanh toán không hợp lệ";
                }
                if (String.IsNullOrEmpty(captcha) && valid)
                {
                    valid = false;
                    rs    = "Vui lòng click vào ô kiểm tra";
                }
                if (valid)
                {
                    AnperoService   ws       = new AnperoService();
                    int             st       = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["storeID"]);
                    string          TokenKey = System.Configuration.ConfigurationManager.AppSettings["storeTokenKey"];
                    PaymentConfig[] pa       = ws.GetPaymentAPIConfig(st, TokenKey);
                    switch (op.ToUpper())
                    {
                    case "LN":

                        if (pa != null && pa.Length > 0)
                        {
                            for (int i = 0; i < pa.Length; i++)
                            {
                                if (pa[i].Isdefault && pa[i].PaymentCode.ToUpper() == "NL")
                                {
                                    string payment_method    = context.Request["payment_method"];
                                    string str_bankcode      = context.Request["bankcode"];
                                    string order_description = context.Request["detail"];
                                    string DomainName        = HttpContext.Current.Request.Url.Scheme + @"://" + HttpContext.Current.Request.Url.Host;


                                    Anpero.PaymentApi.NganLuong.RequestInfo info = new Anpero.PaymentApi.NganLuong.RequestInfo();
                                    info.Merchant_id       = pa[i].MerchantId.ToString();
                                    info.Merchant_password = pa[i].MerchantPassword;

                                    //info.Merchant_id = "24338";
                                    //info.Merchant_password = "******";

                                    info.Receiver_email = pa[i].Email;

                                    info.cur_code  = "vnd";
                                    info.bank_code = str_bankcode;

                                    info.Order_code        = orderId.ToString();
                                    info.Total_amount      = price.ToString();
                                    info.fee_shipping      = "0";
                                    info.Discount_amount   = "0";
                                    info.order_description = order_description;
                                    info.return_url        = DomainName + "/API/NLCallback";
                                    info.cancel_url        = DomainName + "/API/NLCancel";

                                    info.Buyer_fullname = name;
                                    info.Buyer_email    = email;
                                    info.Buyer_mobile   = phone;

                                    APICheckoutV3 objNLChecout = new APICheckoutV3();
                                    ResponseInfo  result       = objNLChecout.GetUrlCheckout(info, payment_method);

                                    if (result.Error_code == "00")
                                    {
                                        rs = result.Checkout_url;
                                    }
                                    else
                                    {
                                        rs = result.Description + " (" + result.Description + ")";
                                    }
                                }
                            }
                        }
                        break;

                    case "AL2":
                        if (pa != null && pa.Length > 0)
                        {
                            for (int i = 0; i < pa.Length; i++)
                            {
                                if (pa[i].Isdefault && pa[i].PaymentCode.ToUpper() == "AL")
                                {
                                    string order_description = context.Request["detail"];
                                    string DomainName        = HttpContext.Current.Request.Url.Scheme + @"://" + HttpContext.Current.Request.Url.Host;
                                    //DomainName = "https://demo3.anpero.com";

                                    AlepayCheckout client            = new AlepayCheckout();
                                    AlepayInstallmentOrderModel data = new AlepayInstallmentOrderModel();
                                    //AlepayOrderModel data = new AlepayOrderModel();
                                    int month = 0;
                                    int.TryParse(context.Request["month"], out month);
                                    data.paymentMethod = context.Request["paymentMethod"];
                                    if (month != 0)
                                    {
                                        data.month = month;
                                    }
                                    data.bankCode = context.Request["bankCode"];

                                    data.amount           = Convert.ToInt32(price);
                                    data.tokenKey         = pa[i].Token;
                                    data.checkoutType     = 2;
                                    data.returnUrl        = DomainName + "/API/AlepayCallback";
                                    data.orderCode        = orderId.ToString();
                                    data.orderDescription = order_description;
                                    data.cancelUrl        = DomainName + "/API/NLCancel";
                                    data.buyerEmail       = email;
                                    data.buyerName        = name;
                                    data.buyerAddress     = context.Request["Address"];
                                    data.buyerCountry     = "Viet Nam";
                                    data.buyerCity        = "Viet Nam";
                                    data.buyerPhone       = phone;
                                    data.customMerchantId = orderId.ToString();
                                    data.allowDomestic    = false;
                                    data.installment      = true;
                                    AlepayUltil alepayUltil = new AlepayUltil();
                                    data.signature = alepayUltil.GetSignature(data, pa[i].ChecksumKey);
                                    var postData = client.GetRedirectUrl(data);
                                    if (!string.IsNullOrEmpty(postData.code) && Convert.ToInt32(postData.code) == 0)
                                    {
                                        rs = postData.checkoutUrl;
                                    }
                                    else
                                    {
                                        rs = postData.message;
                                    }
                                }
                            }
                        }
                        break;

                    case "AL":
                        if (pa != null && pa.Length > 0)
                        {
                            for (int i = 0; i < pa.Length; i++)
                            {
                                if (pa[i].Isdefault && pa[i].PaymentCode.ToUpper() == "AL")
                                {
                                    string order_description = context.Request["detail"];
                                    string DomainName        = HttpContext.Current.Request.Url.Scheme + @"://" + HttpContext.Current.Request.Url.Host;
                                    //DomainName = "https://demo3.anpero.com";

                                    AlepayCheckout   client = new AlepayCheckout();
                                    AlepayOrderModel data   = new AlepayOrderModel();


                                    data.amount           = Convert.ToInt32(price);
                                    data.tokenKey         = pa[i].Token;
                                    data.checkoutType     = 4;
                                    data.returnUrl        = DomainName + "/API/AlepayCallback";
                                    data.orderCode        = orderId.ToString();
                                    data.orderDescription = order_description;
                                    data.cancelUrl        = DomainName + "/API/NLCancel";
                                    data.buyerEmail       = email;
                                    data.buyerName        = name;
                                    data.buyerAddress     = context.Request["Address"];
                                    data.buyerCountry     = "Viet Nam";
                                    data.buyerCity        = "Viet Nam";
                                    data.buyerPhone       = phone;
                                    data.customMerchantId = orderId.ToString();
                                    data.allowDomestic    = true;
                                    AlepayUltil alepayUltil = new AlepayUltil();
                                    data.signature = alepayUltil.GetSignature(data, pa[i].ChecksumKey);
                                    var postData = client.GetRedirectUrl(data);
                                    if (!string.IsNullOrEmpty(postData.code) && Convert.ToInt32(postData.code) == 0)
                                    {
                                        rs = postData.checkoutUrl;
                                    }
                                    else
                                    {
                                        rs = postData.message;
                                    }
                                }
                            }
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
            }


            context.Response.ContentType = "text/plain";
            context.Response.Write(rs);
        }