示例#1
0
        public ActionResult AlepayCallback(string transactionCode, string errorCode, string cancel)
        {
            AnperoService ws = new AnperoService();

            PaymentConfig[] pc = ws.GetPaymentAPIConfig(StoreID, TokenKey);
            if (pc != null && pc.Length > 0)
            {
                for (int i = 0; i < pc.Length; i++)
                {
                    if (pc[i].Name.ToUpper() == "AL")
                    {
                        AlepayCheckout checkout          = new AlepayCheckout();
                        var            transactionDetail = checkout.GetTransactionDetail(transactionCode, pc[i].Token, pc[i].ChecksumKey);
                        if (Convert.ToInt32(transactionDetail.code) == 0)
                        {
                            //ResponseCheckOrder result = objNLChecout.GetTransactionDetail(info);
                            string rs = "Giao dịch Thành công, đơn hàng của quý khách đang được xử lý nhanh chóng";
                            rs += "<br>";
                            rs += "Trạng thái: " + transactionDetail.reason;
                            rs += "<br>";
                            rs += "Số tiền thanh toán: " + Anpero.StringHelpper.ConVertToMoneyFormatInt(transactionDetail.amount);
                            rs += "<br>";

                            rs += "Phí thanh toán: " + Anpero.StringHelpper.ConVertToMoneyFormatInt((int)transactionDetail.payerFee);
                            rs += "<br>";
                            rs += "Mã giao dịch Alepay: " + transactionDetail.transactionCode;
                            rs += "<br>";
                            rs += "Mã đơn hàng: " + transactionDetail.orderCode;
                            rs += "<br>";
                            rs += "Tên người thanh toán: " + transactionDetail.buyerName;
                            rs += "<br>";
                            rs += "Số điện thoại: " + transactionDetail.buyerPhone;
                            rs += "<br>";
                            rs += "Chu kỳ trả góp: " + transactionDetail.month;
                            rs += "<br>";
                            rs += "Tên ngân hàng trả góp: " + transactionDetail.bankName;


                            //update and add cash book
                            ws.UpdateOrderStatus(StoreID, TokenKey, Convert.ToInt32(transactionDetail.orderCode), Convert.ToInt32(transactionDetail.amount), "Alepay (Mã giao dịch " + transactionDetail.transactionCode + ")<br />" + rs);
                            ViewBag.Msg = rs;
                        }
                    }
                }
            }

            return(View("Index"));
        }
示例#2
0
        public InstallmentModel GetInstallmentInfo(double amount)
        {
            AnperoService ws = new AnperoService();

            PaymentConfig[] pc = ws.GetPaymentAPIConfig(StoreID, TokenKey);

            if (pc != null && pc.Length > 0)
            {
                for (int i = 0; i < pc.Length; i++)
                {
                    if (pc[i].Name.ToUpper() == "AL")
                    {
                        AlepayCheckout checkout = new AlepayCheckout();
                        return(checkout.GetInstallmentInfo(amount, pc[i].Token, pc[i].ChecksumKey));
                    }
                }
            }
            return(null);
        }
        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);
        }