コード例 #1
0
        public string ProcessPayment()
        {
            List <string> enErrors = new List <string>();
            string        szHtml   = String.Empty;

            try
            {
                using (AllInOne oPayment = new AllInOne())
                {
                    /* 服務參數 */
                    oPayment.ServiceMethod = HttpMethod.HttpPOST;
                    oPayment.ServiceURL    = "https://payment-stage.allpay.com.tw/Cashier/AioCheckOut/V2";
                    oPayment.HashKey       = "5294y06JbISpM5x9";
                    oPayment.HashIV        = "v77hoKGq4kWxNNIS";
                    oPayment.MerchantID    = "2000132";

                    /* 基本參數 */
                    string hostname = this.Request.Url.Authority;
                    oPayment.Send.ReturnURL         = $"http://{hostname}/Pay/AllPayPayment";
                    oPayment.Send.MerchantTradeNo   = DateTime.Now.ToString("yyyyMMddHHmmss");
                    oPayment.Send.MerchantTradeDate = DateTime.Now;
                    oPayment.Send.TotalAmount       = 1;
                    oPayment.Send.TradeDesc         = "測試金流的描述 ABC";
                    oPayment.Send.Items.Add(new Item()
                    {
                        Name       = "iPhone6 Plus"
                        , Price    = 99
                        , Currency = "元"
                        , Quantity = 1
                                     //, Unit = "組"
                                     //, TaxType = TaxationType.Taxable
                    }
                                            );
                    /* 產生訂單 */
                    enErrors.AddRange(oPayment.CheckOut());
                    /* 產生產生訂單 Html Code 的方法 */
                    enErrors.AddRange(oPayment.CheckOutString(ref szHtml));
                }
            }
            catch (Exception ex)
            {
                // 例外錯誤處理。
                enErrors.Add(ex.Message);
            }
            finally
            {
                // 顯示錯誤訊息。
                if (enErrors.Count() > 0)
                {
                    szHtml = String.Join("\\r\\n", enErrors);
                }
            }
            return(szHtml);
        }
コード例 #2
0
    protected void Button2_Click(object sender, EventArgs e)
    {
        id = Request.QueryString["id"];
        List <string> enErrors = new List <string>();

        try
        {
            using (AllInOne oPayment = new AllInOne())
            {
                /* 服務參數 */
                oPayment.ServiceMethod = HttpMethod.HttpPOST;
                oPayment.ServiceURL    = "https://payment-stage.allpay.com.tw/Cashier/AioCheckOut";
                oPayment.HashKey       = "5294y06JbISpM5x9";
                oPayment.HashIV        = "v77hoKGq4kWxNNIS";
                oPayment.MerchantID    = "2000132";
                /* 基本參數 */
                oPayment.Send.ReturnURL = "https://payment-stage.allpay.com.tw/Cashier/AioCheckOut";
                //oPayment.Send.ClientBackURL = "<<您要歐付寶返回按鈕導向的瀏覽器端網址>>";
                //oPayment.Send.OrderResultURL = "<<您要收到付款完成通知的瀏覽器端網址>>";
                oPayment.Send.MerchantTradeNo   = "648513244" + id;
                oPayment.Send.MerchantTradeDate = DateTime.Parse("2016/12/05");
                oPayment.Send.TotalAmount       = Decimal.Parse(price);
                oPayment.Send.TradeDesc         = "很酷";
                oPayment.Send.ChoosePayment     = PaymentMethod.ALL;
                //oPayment.Send.Remark = "<<您要填寫的其他備註>>";
                oPayment.Send.ChooseSubPayment  = PaymentMethodItem.None;
                oPayment.Send.NeedExtraPaidInfo = ExtraPaymentInfo.Yes;
                oPayment.Send.HoldTrade         = HoldTradeType.No;
                oPayment.Send.DeviceSource      = DeviceType.PC;
                oPayment.Send.UseRedeem         = UseRedeemFlag.Yes; //購物金/紅包折抵
                oPayment.Send.IgnorePayment     = "Alipay";          // 例(排除財富通):Tenpay

                // 加入選購商品資料。

                for (int i = 0; i < rows; i++)
                {
                    oPayment.Send.Items.Add(new Item()
                    {
                        Name     = orderdetial_name[i],
                        Price    = Decimal.Parse(orderdetial_price_int[i].ToString()),
                        Currency = "元",
                        Quantity = Int32.Parse(orderdetial_quantity[i]),
                        URL      = " << 產品說明位址 >> "
                    });
                }



                // 當付款方式為 ALL 時,建議增加的參數。
                //oPayment.SendExtend.PaymentInfoURL = "<<您要接收回傳自動櫃員機/超商/條碼付款相關資訊的網址。>> ";
                /* 產生訂單 */
                enErrors.AddRange(oPayment.CheckOut());
                /* 產生產生訂單 Html Code 的方法 */
                string szHtml = String.Empty;
                enErrors.AddRange(oPayment.CheckOutString(ref szHtml));
            }
        }
        catch (Exception ex)
        {
            // 例外錯誤處理。
            enErrors.Add(ex.Message);
        }
        finally
        {
            // 顯示錯誤訊息。
            if (enErrors.Count() > 0)
            {
                string szErrorMessage = String.Join("\\r\\n", enErrors);
            }
        }
    }
コード例 #3
0
        //網購寫入訂單
        public string webOrder(WebPay payData)
        {
            if (Session[CSession關鍵字.SK_LOGINED_CUSTOMER] != null)
            {
                tCustomer cust = Session[CSession關鍵字.SK_LOGINED_CUSTOMER] as tCustomer;

                MotaiDataEntities dbContext      = new MotaiDataEntities();
                List <tStatu>     StatuList      = dbContext.tStatus.Where(s => s.sCustomerId.Equals(cust.CustomerId)).ToList();
                string            szHtml         = String.Empty;
                string            szErrorMessage = String.Empty;
                List <string>     enErrors       = new List <string>();
                try
                {
                    using (AllInOne oPayment = new AllInOne())
                    {
                        /* 服務參數 */
                        oPayment.ServiceMethod = AllPay.Payment.Integration.HttpMethod.HttpPOST;
                        oPayment.ServiceURL    = "https://payment-stage.opay.tw/Cashier/AioCheckOut/V5";
                        oPayment.HashKey       = "5294y06JbISpM5x9";
                        oPayment.HashIV        = "v77hoKGq4kWxNNIS";
                        oPayment.MerchantID    = "2000132";
                        /* 基本參數 */
                        string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority;
                        if (payData.payType == 2)
                        {
                            oPayment.Send.ReturnURL = baseURI + Url.Action("orderCredit", "Order");
                        }
                        else
                        {
                            oPayment.Send.ReturnURL = baseURI + Url.Action("ATMpayOff", "Order");
                        }
                        oPayment.Send.ClientBackURL = baseURI;
                        //oPayment.Send.OrderResultURL = baseURI;
                        int number = (DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second) * 3;
                        oPayment.Send.MerchantTradeNo   = "MD" + DateTime.Now.Date.ToString("yyyyMMdd") + number.ToString("000000");
                        oPayment.Send.MerchantTradeDate = DateTime.Now;
                        oPayment.Send.TotalAmount       = Decimal.Parse(payData.totalPay);
                        oPayment.Send.TradeDesc         = "感謝購買墨台商品";
                        if (payData.payType == 1)
                        {
                            oPayment.Send.ChoosePayment    = PaymentMethod.ATM;
                            oPayment.SendExtend.ExpireDate = Int32.Parse("3");
                        }
                        else
                        {
                            oPayment.Send.ChoosePayment = PaymentMethod.Credit;
                        }
                        //oPayment.Send.ChoosePayment = PaymentMethod.ALL;
                        oPayment.Send.Remark            = "饒了我吧";
                        oPayment.Send.ChooseSubPayment  = PaymentMethodItem.None;
                        oPayment.Send.NeedExtraPaidInfo = ExtraPaymentInfo.No;
                        oPayment.Send.HoldTrade         = HoldTradeType.No;
                        oPayment.Send.DeviceSource      = DeviceType.PC;
                        oPayment.Send.UseRedeem         = UseRedeemFlag.No; //購物金/紅包折抵
                        oPayment.Send.IgnorePayment     = "";               // 例如財付通:Tenpay
                        // 加入選購商品資料。
                        foreach (var item in StatuList)
                        {
                            tProduct product = dbContext.tProducts.Where(p => p.ProductId.Equals(item.sProductId)).FirstOrDefault();
                            //var chg = JObject.Parse(item.Value.ToString());
                            oPayment.Send.Items.Add(new Item()
                            {
                                Name     = product.pName,
                                Price    = product.pPrice,
                                Currency = "NTD",
                                Quantity = item.sProductQty,
                                URL      = "<< 產品說明位址 >>"
                            });
                        }
                        // 當付款方式為 ALL 時,建議增加的參數。
                        if (payData.payType == 1)
                        {
                            oPayment.SendExtend.PaymentInfoURL = baseURI + Url.Action("orderATM", "Order");
                        }
                        ////攜帶參數
                        //WebOrderModel order = new WebOrderModel();
                        //order.boughtList = StatuList;
                        //order.webpay = payData;
                        //order.customer = cust;
                        //order.payDate = oPayment.Send.MerchantTradeDate;

                        //http.Session[oPayment.Send.MerchantTradeNo] = order;

                        //database產生訂單
                        tOrder newOrder = new tOrder();
                        newOrder.oCustomerId    = cust.CustomerId;
                        newOrder.oEmployeeId    = 19;
                        newOrder.oDate          = DateTime.Now;
                        newOrder.oAddress       = payData.shipAddress;
                        newOrder.oWarehouseName = 1;
                        newOrder.cNote          = oPayment.Send.MerchantTradeNo;
                        dbContext.tOrders.Add(newOrder);
                        dbContext.SaveChanges();
                        tOrder    CreateOrder = dbContext.tOrders.OrderByDescending(o => o.OrderId).FirstOrDefault();
                        tOrderPay pay         = new tOrderPay();
                        pay.oOrderId          = CreateOrder.OrderId;
                        pay.oOrderInstallment = 1;
                        pay.oPayType          = payData.payType;
                        pay.oPayment          = Convert.ToInt32(payData.totalPay);
                        pay.oPayDate          = DateTime.Now;
                        dbContext.tOrderPays.Add(pay);
                        foreach (var item in StatuList)
                        {
                            tOrderDetail orderDetail = new tOrderDetail();
                            orderDetail.oOrderId    = CreateOrder.OrderId;
                            orderDetail.oProductId  = item.sProductId;
                            orderDetail.oProductQty = item.sProductQty;
                            dbContext.tOrderDetails.Add(orderDetail);
                            dbContext.tStatus.Remove(item);
                            dbContext.SaveChanges();
                        }
                        dbContext.SaveChanges();
                        /* 產生訂單 */
                        enErrors.AddRange(oPayment.CheckOut());
                        /* 產生產生訂單 Html Code 的方法 */
                        //string szHtml = String.Empty;
                        enErrors.AddRange(oPayment.CheckOutString(ref szHtml));
                    }
                }
                catch (Exception ex)
                {
                    // 例外錯誤處理。
                    enErrors.Add(ex.Message);
                }
                finally
                {
                    // 顯示錯誤訊息。
                    if (enErrors.Count() > 0)
                    {
                        szErrorMessage = String.Join("\\r\\n", enErrors);
                    }
                }
                if (enErrors.Count() == 0)
                {
                    return(szHtml);
                }
                else
                {
                    return(szErrorMessage);
                }
            }
            return(String.Empty);
        }
コード例 #4
0
        public string ProcessPayment(order orderdetail)
        {
            List <string> enErrors = new List <string>();
            decimal       x        = 0;
            var           y        = 0;
            string        szHtml   = String.Empty;

            try
            {
                using (AllInOne oPayment = new AllInOne())
                {
                    /* 服務參數 */
                    oPayment.ServiceMethod = HttpMethod.HttpPOST;
                    oPayment.ServiceURL    = "https://payment-stage.allpay.com.tw/Cashier/AioCheckOut/V2";
                    oPayment.HashKey       = "5294y06JbISpM5x9";
                    oPayment.HashIV        = "v77hoKGq4kWxNNIS";
                    oPayment.MerchantID    = "2000132";

                    /* 基本參數 */
                    string hostname = this.Request.Url.Authority;
                    oPayment.Send.ReturnURL         = $"http://{hostname}/AllPayPayment/CallBack";
                    oPayment.Send.MerchantTradeNo   = DateTime.Now.ToString("yyyyMMddHHmmss");
                    oPayment.Send.MerchantTradeDate = DateTime.Now;
                    //oPayment.Send.TotalAmount = 1;
                    oPayment.Send.TradeDesc = "測試金流的描述 ABC";
                    var details = orderdetail.order_detail.Select(a => a).ToList();
                    foreach (var item in details)
                    {
                        oPayment.Send.Items.Add(new Item
                        {
                            Name     = item.productname,
                            Price    = item.total_price,
                            Quantity = item.quiantity
                        });
                        y  = item.quiantity;
                        x += item.total_price;
                    }
                    oPayment.Send.TotalAmount = x * y;
                    //oPayment.Send.Items.Add(new Item
                    //{
                    //    Name = $"向{orderdetail.sell_id}下定的東西",

                    //});



                    /* 產生訂單 */
                    enErrors.AddRange(oPayment.CheckOut());
                    /* 產生產生訂單 Html Code 的方法 */
                    enErrors.AddRange(oPayment.CheckOutString(ref szHtml));
                }
            }
            catch (Exception ex)
            {
                // 例外錯誤處理。
                enErrors.Add(ex.Message);
            }
            finally
            {
                // 顯示錯誤訊息。
                if (enErrors.Count() > 0)
                {
                    szHtml = String.Join("\\r\\n", enErrors);
                }
                orderdetail.status = "完成交易";
            }
            return(szHtml);
        }
コード例 #5
0
ファイル: STPay.cs プロジェクト: PuwuFR/ecpay_sample
        private string CheckOut(PaymentMethod pm, string returnUrl, string ShopUrl, string TransactionId, int Amt)
        {
            List <string> enErrors = new List <string>();

            try
            {
                using (AllInOne oPayment = new AllInOne())
                {
                    /* 服務參數 */
                    oPayment.ServiceMethod = HttpMethod.HttpPOST;                  //介接服務時,呼叫 API 的方法
                    oPayment.ServiceURL    = PaymentConfig.ECpayConfig.ServiceURL; //要呼叫介接服務的網址
                    oPayment.HashKey       = PaymentConfig.ECpayConfig.HashKey;    //ECPay提供的Hash Key
                    oPayment.HashIV        = PaymentConfig.ECpayConfig.HashIV;     //ECPay提供的Hash IV
                    oPayment.MerchantID    = PaymentConfig.ECpayConfig.MerchantID; //ECPay提供的特店編號

                    /* 基本參數 */
                    oPayment.Send.ReturnURL         = returnUrl;                     //付款完成通知回傳的網址
                    oPayment.Send.ClientBackURL     = ShopUrl;                       //瀏覽器端返回的廠商網址
                    oPayment.Send.OrderResultURL    = "";                            //瀏覽器端回傳付款結果網址
                    oPayment.Send.MerchantTradeNo   = TransactionId;                 //廠商的交易編號
                    oPayment.Send.MerchantTradeDate = DateTime.Now;                  //廠商的交易時間
                    oPayment.Send.TotalAmount       = Decimal.Parse(Amt.ToString()); //交易總金額
                    oPayment.Send.TradeDesc         = "交易描述";                        //交易描述
                    oPayment.Send.ChoosePayment     = pm;                            //使用的付款方式
                    oPayment.Send.Remark            = "";                            //備註欄位
                    oPayment.Send.ChooseSubPayment  = PaymentMethodItem.None;        //使用的付款子項目
                    oPayment.Send.NeedExtraPaidInfo = ExtraPaymentInfo.Yes;          //是否需要額外的付款資訊
                    oPayment.Send.DeviceSource      = DeviceType.PC;                 //來源裝置
                    oPayment.Send.IgnorePayment     = "";                            //不顯示的付款方式
                    oPayment.Send.PlatformID        = "";                            //特約合作平台商代號
                    oPayment.Send.HoldTradeAMT      = HoldTradeType.Yes;
                    oPayment.Send.CustomField1      = "";
                    oPayment.Send.CustomField2      = "";
                    oPayment.Send.CustomField3      = "";
                    oPayment.Send.CustomField4      = "";
                    oPayment.Send.EncryptType       = 1;

                    //訂單的商品資料
                    oPayment.Send.Items.Add(new Item()
                    {
                        Name     = "網路購物",                        //商品名稱
                        Price    = Decimal.Parse(Amt.ToString()), //商品單價
                        Currency = "新台幣",                         //幣別單位
                        Quantity = Int32.Parse("1"),              //購買數量
                        URL      = ShopUrl,                       //商品的說明網址
                    });

                    /*************************非即時性付款:ATM、CVS 額外功能參數**************/

                    #region ATM 額外功能參數

                    //oPayment.SendExtend.ExpireDate = 3;//允許繳費的有效天數
                    //oPayment.SendExtend.PaymentInfoURL = "";//伺服器端回傳付款相關資訊
                    //oPayment.SendExtend.ClientRedirectURL = "";//Client 端回傳付款相關資訊

                    #endregion


                    #region CVS 額外功能參數

                    //oPayment.SendExtend.StoreExpireDate = 3; //超商繳費截止時間 CVS:以分鐘為單位 BARCODE:以天為單位
                    //oPayment.SendExtend.Desc_1 = "test1";//交易描述 1
                    //oPayment.SendExtend.Desc_2 = "test2";//交易描述 2
                    //oPayment.SendExtend.Desc_3 = "test3";//交易描述 3
                    //oPayment.SendExtend.Desc_4 = "";//交易描述 4
                    //oPayment.SendExtend.PaymentInfoURL = "";//伺服器端回傳付款相關資訊
                    //oPayment.SendExtend.ClientRedirectURL = "";///Client 端回傳付款相關資訊

                    #endregion

                    /***************************信用卡額外功能參數***************************/

                    #region Credit 功能參數

                    //oPayment.SendExtend.BindingCard = BindingCardType.No; //記憶卡號
                    //oPayment.SendExtend.MerchantMemberID = ""; //記憶卡號識別碼
                    //oPayment.SendExtend.Language = ""; //語系設定

                    #endregion Credit 功能參數

                    #region 一次付清

                    //oPayment.SendExtend.Redeem = false;   //是否使用紅利折抵
                    //oPayment.SendExtend.UnionPay = true; //是否為銀聯卡交易

                    #endregion

                    #region 分期付款

                    //oPayment.SendExtend.CreditInstallment = "3,6";//刷卡分期期數

                    #endregion 分期付款

                    #region 定期定額

                    //oPayment.SendExtend.PeriodAmount = 1000;//每次授權金額
                    //oPayment.SendExtend.PeriodType = PeriodType.Day;//週期種類
                    //oPayment.SendExtend.Frequency = 1;//執行頻率
                    //oPayment.SendExtend.ExecTimes = 2;//執行次數
                    //oPayment.SendExtend.PeriodReturnURL = "";//伺服器端回傳定期定額的執行結果網址。

                    #endregion

                    /* 產生訂單 */

                    string html = string.Empty;

                    /* 產生訂單 */
                    enErrors.AddRange(oPayment.CheckOutString(ref html));

                    return(html);
                }
            }
            catch (Exception ex)
            {
                // 例外錯誤處理。
                enErrors.Add(ex.Message);
            }
            finally
            {
                // 顯示錯誤訊息。
                if (enErrors.Count() > 0)
                {
                    // string szErrorMessage = String.Join("\\r\\n", enErrors);
                }
            }
            return(null);
        }
コード例 #6
0
        public ActionResult Payment(int?id)
        {
            var o = db.Orders.Find(id);

            string        test     = "test";
            List <string> enErrors = new List <string>();

            try
            {
                using (AllInOne oPayment = new AllInOne())
                {
                    /* 服務參數 */
                    oPayment.ServiceMethod = HttpMethod.HttpPOST;                                         //介接服務時,呼叫 API 的方法
                    oPayment.ServiceURL    = "https://payment-stage.ecpay.com.tw/Cashier/AioCheckOut/V5"; //要呼叫介接服務的網址
                    oPayment.HashKey       = "5294y06JbISpM5x9";                                          //ECPay提供的Hash Key
                    oPayment.HashIV        = "v77hoKGq4kWxNNIS";                                          //ECPay提供的Hash IV
                    oPayment.MerchantID    = "2000132";                                                   //ECPay提供的特店編號

                    /* 基本參數 */
                    oPayment.Send.ReturnURL         = "https://dotrabackend.azurewebsites.net/Orders/GetPaymentResult"; //付款完成通知回傳的網址
                    oPayment.Send.ClientBackURL     = "https://dotrawebsite.azurewebsites.net/";                        //瀏覽器端返回的廠商網址
                    oPayment.Send.OrderResultURL    = "https://dotrawebsite.azurewebsites.net/Order/GetResult";         //瀏覽器端回傳付款結果網址
                    oPayment.Send.MerchantTradeNo   = "Dotra" + new Random().Next(0, 99999).ToString();                 //廠商的交易編號
                    oPayment.Send.MerchantTradeDate = DateTime.Now;                                                     //廠商的交易時間
                    oPayment.Send.TotalAmount       = Convert.ToInt32(o.OrderDetails.Sum(y => y.SubTotal));             //交易總金額
                    oPayment.Send.TradeDesc         = "交易描述";                                                           //交易描述
                    oPayment.Send.ChoosePayment     = (PaymentMethod)o.PaymentID;                                       //使用的付款方式
                    oPayment.Send.Remark            = "";                                                               //備註欄位
                    oPayment.Send.ChooseSubPayment  = PaymentMethodItem.None;                                           //使用的付款子項目
                    oPayment.Send.NeedExtraPaidInfo = ExtraPaymentInfo.Yes;                                             //是否需要額外的付款資訊
                    oPayment.Send.DeviceSource      = DeviceType.PC;                                                    //來源裝置
                    oPayment.Send.IgnorePayment     = "";                                                               //不顯示的付款方式
                    oPayment.Send.PlatformID        = "";                                                               //特約合作平台商代號
                    oPayment.Send.CustomField1      = id.ToString();
                    oPayment.Send.CustomField2      = "";
                    oPayment.Send.CustomField3      = "";
                    oPayment.Send.CustomField4      = "";
                    oPayment.Send.EncryptType       = 1;


                    foreach (var item in o.OrderDetails)
                    {
                        oPayment.Send.Items.Add(new Item()
                        {
                            Name     = item.Product.ProductName,                      //商品名稱
                            Price    = item.Product.SalesPrice,                       //商品單價
                            Currency = "新台幣",                                         //幣別單位
                            Quantity = item.Quantity,                                 //購買數量
                            URL      = "https://dotrawebsite.azurewebsites.net/Shop", //商品的說明網址
                        });
                    }
                    //訂單的商品資料


                    /*************************非即時性付款:ATM、CVS 額外功能參數**************/

                    #region ATM 額外功能參數

                    //oPayment.SendExtend.ExpireDate = 3;//允許繳費的有效天數
                    //oPayment.SendExtend.PaymentInfoURL = "";//伺服器端回傳付款相關資訊
                    //oPayment.SendExtend.ClientRedirectURL = "";//Client 端回傳付款相關資訊

                    #endregion


                    #region CVS 額外功能參數

                    //oPayment.SendExtend.StoreExpireDate = 3; //超商繳費截止時間 CVS:以分鐘為單位 BARCODE:以天為單位
                    //oPayment.SendExtend.Desc_1 = "test1";//交易描述 1
                    //oPayment.SendExtend.Desc_2 = "test2";//交易描述 2
                    //oPayment.SendExtend.Desc_3 = "test3";//交易描述 3
                    //oPayment.SendExtend.Desc_4 = "";//交易描述 4
                    //oPayment.SendExtend.PaymentInfoURL = "";//伺服器端回傳付款相關資訊
                    //oPayment.SendExtend.ClientRedirectURL = "";///Client 端回傳付款相關資訊

                    #endregion

                    /***************************信用卡額外功能參數***************************/

                    #region Credit 功能參數

                    //oPayment.SendExtend.BindingCard = BindingCardType.No; //記憶卡號
                    //oPayment.SendExtend.MerchantMemberID = ""; //記憶卡號識別碼
                    //oPayment.SendExtend.Language = ""; //語系設定

                    #endregion Credit 功能參數

                    #region 一次付清

                    //oPayment.SendExtend.Redeem = false;   //是否使用紅利折抵
                    //oPayment.SendExtend.UnionPay = true; //是否為銀聯卡交易

                    #endregion

                    #region 分期付款

                    //oPayment.SendExtend.CreditInstallment = "3,6";//刷卡分期期數

                    #endregion 分期付款

                    #region 定期定額

                    //oPayment.SendExtend.PeriodAmount = 1000;//每次授權金額
                    //oPayment.SendExtend.PeriodType = PeriodType.Day;//週期種類
                    //oPayment.SendExtend.Frequency = 1;//執行頻率
                    //oPayment.SendExtend.ExecTimes = 2;//執行次數
                    //oPayment.SendExtend.PeriodReturnURL = "";//伺服器端回傳定期定額的執行結果網址。

                    #endregion

                    /* 產生訂單 */
                    enErrors.AddRange(oPayment.CheckOutString(ref test));
                }
            }
            catch (Exception ex)
            {
                // 例外錯誤處理。
                enErrors.Add(ex.Message);
            }
            finally
            {
                // 顯示錯誤訊息。
                if (enErrors.Count() > 0)
                {
                    // string szErrorMessage = String.Join("\\r\\n", enErrors);
                }
            }
            return(Content(test));
        }
コード例 #7
0
        public string CheckOut(string payment_method)
        {
            var user = Session[CDictionary.welcome] as CMember;
            SingleApartmentEntities db = new SingleApartmentEntities();

            ViewBag.MemberID = user.fMemberId;
            CUser theUser = new CUser()
            {
                tMember = db.tMember.Where(r => r.fMemberId == user.fMemberId).FirstOrDefault()
            };
            List <CAddtoSessionView> list = Session[CDictionary.PRODUCTS_IN_CART] as List <CAddtoSessionView>;
            string orderID = "";

            if (list != null && list.Count != 0)
            {
                orderID = theUser.MakeOrder(list);
                if (orderID != "發生錯誤,請稍後再試!")
                {
                    Session[CDictionary.PRODUCTS_IN_CART] = null;
                }
            }
            List <COrderDetailsViewModel> orderlist = theUser.SearchProductInCart(list);
            int TotalPrice = 0;

            foreach (var item in orderlist)
            {
                TotalPrice += (item.ProductPrice == null ? 0 : (int)item.ProductPrice) * item.Quantity;
            }
            if (payment_method == "歐付寶")
            {
                List <string> enErrors = new List <string>();
                try
                {
                    using (AllInOne oPayment = new AllInOne())
                    {
                        var order1       = new Order();
                        var orderdetails = orderlist.Where(p => p.OrderID == order1.OrderID);
                        int?total        = TotalPrice;

                        /* 服務參數 */
                        oPayment.ServiceMethod = AllPay.Payment.Integration.HttpMethod.HttpPOST;
                        oPayment.ServiceURL    = "https://payment-stage.opay.tw/Cashier/AioCheckOut/V5";
                        oPayment.HashKey       = "5294y06JbISpM5x9";
                        oPayment.HashIV        = "v77hoKGq4kWxNNIS";
                        oPayment.MerchantID    = "2000132";
                        /* 基本參數 */
                        oPayment.Send.ReturnURL     = "http://localhost:1080/Member/Home";
                        oPayment.Send.ClientBackURL = "http://localhost:1080/Product/OrderList";
                        //oPayment.Send.OrderResultURL = "<<您要收到付款完成通知的瀏覽器端網址>>";
                        oPayment.Send.MerchantTradeNo   = string.Format("{0:00000}", (new Random()).Next(100000));
                        oPayment.Send.MerchantTradeDate = DateTime.Now;
                        oPayment.Send.TotalAmount       = (decimal)total;
                        oPayment.Send.TradeDesc         = "感謝您的購買";
                        //oPayment.Send.ChoosePayment = PaymentMethod.ALL;
                        //oPayment.Send.Remark = "<<您要填寫的其他備註>>";
                        oPayment.Send.ChooseSubPayment  = PaymentMethodItem.None;
                        oPayment.Send.NeedExtraPaidInfo = ExtraPaymentInfo.Yes;
                        oPayment.Send.HoldTrade         = HoldTradeType.No;
                        oPayment.Send.DeviceSource      = DeviceType.PC;
                        //oPayment.Send.UseRedeem = UseRedeemFlag.Yes; //購物金/紅包折抵
                        //oPayment.Send.IgnorePayment = "<<您不要顯示的付款方式>>"; // 例如財付通:Tenpay
                        //                                                      // 加入選購商品資料。

                        foreach (var item in orderlist)
                        {
                            oPayment.Send.Items.Add(new Item()
                            {
                                Name = item.ProductName,

                                Price = (decimal)item.ProductPrice,

                                Currency = "元",

                                Quantity = item.Quantity
                            });
                        }
                        // 當付款方式為 ALL 時,建議增加的參數。
                        //oPayment.SendExtend.PaymentInfoURL = "<<您要接收回傳自動櫃員機/超商/條碼付款相關資訊的網址。>> ";

                        /* 產生訂單 */
                        enErrors.AddRange(oPayment.CheckOut());
                        /* 產生產生訂單 Html Code 的方法 */
                        string szHtml = String.Empty;
                        enErrors.AddRange(oPayment.CheckOutString(ref szHtml));
                        return(szHtml);
                    }
                }
                catch (Exception ex)
                {
                    // 例外錯誤處理。
                    enErrors.Add(ex.Message);
                    return(ex.Message);
                }
                finally
                {
                    // 顯示錯誤訊息。
                    if (enErrors.Count() > 0)
                    {
                        string szErrorMessage = String.Join("\\r\\n", enErrors);
                    }
                }
            }
            else if (payment_method == "綠界科技")
            {
                List <string> enErrors = new List <string>();
                try
                {
                    using (ECPay.Payment.Integration.AllInOne oPayment = new ECPay.Payment.Integration.AllInOne())
                    {
                        /* 服務參數 */
                        oPayment.ServiceMethod = ECPay.Payment.Integration.HttpMethod.HttpPOST;               //介接服務時,呼叫 API 的方法
                        oPayment.ServiceURL    = "https://payment-stage.ecpay.com.tw/Cashier/AioCheckOut/V5"; //要呼叫介接服務的網址
                        oPayment.HashKey       = "5294y06JbISpM5x9";                                          //ECPay提供的Hash Key
                        oPayment.HashIV        = "v77hoKGq4kWxNNIS";                                          //ECPay提供的Hash IV
                        oPayment.MerchantID    = "2000132";                                                   //ECPay提供的特店編號

                        /* 基本參數 */
                        oPayment.Send.ReturnURL     = "http://localhost:1080/Product/MakeOrderIntoDB";
                        oPayment.Send.ClientBackURL = "http://localhost:1080/Product/OrderList";
                        //oPayment.Send.ReturnURL = "http://example.com";//付款完成通知回傳的網址
                        //oPayment.Send.ClientBackURL = "http://www.ecpay.com.tw/";//瀏覽器端返回的廠商網址
                        oPayment.Send.OrderResultURL    = "http://localhost:1080/Product/MakeOrderIntoDB"; //瀏覽器端回傳付款結果網址
                        oPayment.Send.MerchantTradeNo   = "WoJuApartment000" + orderID.ToString();         //廠商的交易編號
                        oPayment.Send.MerchantTradeDate = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");;   //廠商的交易時間
                        oPayment.Send.TotalAmount       = (decimal)TotalPrice;                             //交易總金額
                        oPayment.Send.TradeDesc         = "感謝您的購買^^";                                      //交易描述
                        //oPayment.Send.ChoosePayment = PaymentMethod.ALL;//使用的付款方式
                        oPayment.Send.Remark = "窩居公寓-測試訂單";                                                //備註欄位
                        //oPayment.Send.ChooseSubPayment = PaymentMethodItem.None;//使用的付款子項目
                        //oPayment.Send.NeedExtraPaidInfo = ExtraPaymentInfo.Yes;//是否需要額外的付款資訊
                        //oPayment.Send.DeviceSource = DeviceType.PC;//來源裝置
                        oPayment.Send.CustomField1 = user.fMemberId.ToString();;
                        oPayment.Send.CustomField2 = orderID;
                        //訂單的商品資料
                        foreach (var item in orderlist)
                        {
                            oPayment.Send.Items.Add(new ECPay.Payment.Integration.Item()
                            {
                                Name     = item.ProductName,
                                Price    = (decimal)item.ProductPrice,
                                Currency = "元",
                                Quantity = item.Quantity
                            });
                        }

                        /*************************非即時性付款:ATM、CVS 額外功能參數**************/

                        #region ATM 額外功能參數

                        //oPayment.SendExtend.ExpireDate = 3;//允許繳費的有效天數
                        //oPayment.SendExtend.PaymentInfoURL = "";//伺服器端回傳付款相關資訊
                        //oPayment.SendExtend.ClientRedirectURL = "";//Client 端回傳付款相關資訊

                        #endregion
                        #region CVS 額外功能參數

                        //oPayment.SendExtend.StoreExpireDate = 3; //超商繳費截止時間 CVS:以分鐘為單位 BARCODE:以天為單位
                        //oPayment.SendExtend.Desc_1 = "test1";//交易描述 1
                        //oPayment.SendExtend.Desc_2 = "test2";//交易描述 2
                        //oPayment.SendExtend.Desc_3 = "test3";//交易描述 3
                        //oPayment.SendExtend.Desc_4 = "";//交易描述 4
                        //oPayment.SendExtend.PaymentInfoURL = "";//伺服器端回傳付款相關資訊
                        //oPayment.SendExtend.ClientRedirectURL = "";///Client 端回傳付款相關資訊

                        #endregion

                        /***************************信用卡額外功能參數***************************/

                        #region Credit 功能參數

                        //oPayment.SendExtend.BindingCard = BindingCardType.No; //記憶卡號
                        //oPayment.SendExtend.MerchantMemberID = ""; //記憶卡號識別碼
                        //oPayment.SendExtend.Language = ""; //語系設定

                        #endregion Credit 功能參數
                        #region 一次付清

                        //oPayment.SendExtend.Redeem = false;   //是否使用紅利折抵
                        //oPayment.SendExtend.UnionPay = true; //是否為銀聯卡交易

                        #endregion
                        #region 分期付款

                        //oPayment.SendExtend.CreditInstallment = "3,6";//刷卡分期期數

                        #endregion 分期付款
                        #region 定期定額

                        //oPayment.SendExtend.PeriodAmount = 1000;//每次授權金額
                        //oPayment.SendExtend.PeriodType = PeriodType.Day;//週期種類
                        //oPayment.SendExtend.Frequency = 1;//執行頻率
                        //oPayment.SendExtend.ExecTimes = 2;//執行次數
                        //oPayment.SendExtend.PeriodReturnURL = "";//伺服器端回傳定期定額的執行結果網址。

                        #endregion

                        /* 產生訂單 */
                        enErrors.AddRange(oPayment.CheckOut());
                        /* 產生產生訂單 Html Code 的方法 */
                        string szHtml = String.Empty;
                        enErrors.AddRange(oPayment.CheckOutString(ref szHtml));
                        return(szHtml);
                    }
                }
                catch (Exception ex)
                {
                    // 例外錯誤處理。
                    enErrors.Add(ex.Message);
                    return(ex.Message);
                }
                finally
                {
                    // 顯示錯誤訊息。
                    if (enErrors.Count() > 0)
                    {
                        string szErrorMessage = String.Join("\\r\\n", enErrors);
                    }
                }
            }
            else
            {
                return("其他");
            }
        }
コード例 #8
0
        /// <summary>
        /// 連接到綠界結帳頁面,並於客製化欄位放入orderId及memberId
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="member"></param>
        /// <returns></returns>
        public string ConnectECPay(int orderId, MemberViewModel member)
        {
            var           session     = HttpContext.Current.Session;
            List <string> enErrors    = new List <string>();
            string        html        = string.Empty;
            var           cartSession = ((CartItemListViewModel)session["Cart"]);
            PayViewModel  readyToPay  = QueryByPlanId(cartSession);
            var           TotalAmount = (Convert.ToInt32(readyToPay.TotalAccount)).ToString();

            try
            {
                using (AllInOne oPayment = new AllInOne())
                {
                    /* 服務參數 */
                    oPayment.ServiceMethod = HttpMethod.HttpPOST;                                         //介接服務時,呼叫 API 的方法
                    oPayment.ServiceURL    = "https://payment-stage.ecpay.com.tw/Cashier/AioCheckOut/V5"; //要呼叫介接服務的網址
                    oPayment.HashKey       = "5294y06JbISpM5x9";                                          //ECPay提供的Hash Key
                    oPayment.HashIV        = "v77hoKGq4kWxNNIS";                                          //ECPay提供的Hash IV
                    oPayment.MerchantID    = "2000132";                                                   //ECPay提供的特店編號

                    /* 基本參數 */
                    oPayment.Send.ReturnURL         = "https://mycarplanwebsite.azurewebsites.net/Pay/CheckECPayFeedBack"; //付款完成通知回傳的網址
                    oPayment.Send.ClientBackURL     = "https://mycarplanwebsite.azurewebsites.net/Home/Index";             //瀏覽器端返回的廠商網址
                    oPayment.Send.OrderResultURL    = "https://mycarplanwebsite.azurewebsites.net/pay/Result";             //瀏覽器端回傳付款結果網址
                    oPayment.Send.MerchantTradeNo   = "ECPay" + new Random().Next(0, 99999).ToString();                    //廠商的交易編號
                    oPayment.Send.MerchantTradeDate = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");                        //廠商的交易時間
                    oPayment.Send.TotalAmount       = Decimal.Parse(TotalAmount);
                    oPayment.Send.TradeDesc         = "交易描述";                                                              //交易描述
                    oPayment.Send.ChoosePayment     = PaymentMethod.ALL;                                                   //使用的付款方式
                    oPayment.Send.Remark            = "";                                                                  //備註欄位
                    oPayment.Send.ChooseSubPayment  = PaymentMethodItem.None;                                              //使用的付款子項目
                    oPayment.Send.NeedExtraPaidInfo = ExtraPaymentInfo.No;                                                 //是否需要額外的付款資訊
                    oPayment.Send.DeviceSource      = DeviceType.PC;                                                       //來源裝置
                    oPayment.Send.IgnorePayment     = "";                                                                  //不顯示的付款方式
                    oPayment.Send.PlatformID        = "";                                                                  //特約合作平台商代號
                    oPayment.Send.HoldTradeAMT      = HoldTradeType.Yes;
                    oPayment.Send.CustomField1      = orderId.ToString();
                    oPayment.Send.CustomField2      = member.MemberId.ToString();
                    oPayment.Send.CustomField3      = "";
                    oPayment.Send.CustomField4      = "";
                    oPayment.Send.EncryptType       = 1;

                    foreach (var order in readyToPay.CartItems)
                    {
                        //訂單的商品資料
                        oPayment.Send.Items.Add(new Item()
                        {
                            Name     = order.PlanTitle,                 //商品名稱
                            Price    = order.PlanPrice,                 //商品單價
                            Currency = "新台幣",                           //幣別單位
                            Quantity = order.Quantity,                  //購買數量
                            Unit     = "件",
                            URL      = $"/ProjectDetail/Index/{order}", //商品的說明網址
                        });
                    }



                    //            /*************************非即時性付款:ATM、CVS 額外功能參數**************/

                    //            #region ATM 額外功能參數

                    //            //oPayment.SendExtend.ExpireDate = 3;//允許繳費的有效天數
                    //            //oPayment.SendExtend.PaymentInfoURL = "";//伺服器端回傳付款相關資訊
                    //            //oPayment.SendExtend.ClientRedirectURL = "";//Client 端回傳付款相關資訊

                    //            #endregion


                    //            #region CVS 額外功能參數

                    //            //oPayment.SendExtend.StoreExpireDate = 3; //超商繳費截止時間 CVS:以分鐘為單位 BARCODE:以天為單位
                    //            //oPayment.SendExtend.Desc_1 = "test1";//交易描述 1
                    //            //oPayment.SendExtend.Desc_2 = "test2";//交易描述 2
                    //            //oPayment.SendExtend.Desc_3 = "test3";//交易描述 3
                    //            //oPayment.SendExtend.Desc_4 = "";//交易描述 4
                    //            //oPayment.SendExtend.PaymentInfoURL = "";//伺服器端回傳付款相關資訊
                    //            //oPayment.SendExtend.ClientRedirectURL = "";///Client 端回傳付款相關資訊

                    //            #endregion

                    //            /***************************信用卡額外功能參數***************************/

                    //            #region Credit 功能參數

                    //            //oPayment.SendExtend.BindingCard = BindingCardType.No; //記憶卡號
                    //            //oPayment.SendExtend.MerchantMemberID = ""; //記憶卡號識別碼
                    //            //oPayment.SendExtend.Language = "ENG"; //語系設定

                    //            #endregion Credit 功能參數

                    //            #region 一次付清

                    //            //oPayment.SendExtend.Redeem = false;   //是否使用紅利折抵
                    //            //oPayment.SendExtend.UnionPay = true; //是否為銀聯卡交易

                    //            #endregion

                    //            #region 分期付款

                    //            //oPayment.SendExtend.CreditInstallment = 3;//刷卡分期期數

                    //            #endregion 分期付款

                    //            #region 定期定額

                    //            //oPayment.SendExtend.PeriodAmount = 1000;//每次授權金額
                    //            //oPayment.SendExtend.PeriodType = PeriodType.Day;//週期種類
                    //            //oPayment.SendExtend.Frequency = 1;//執行頻率
                    //            //oPayment.SendExtend.ExecTimes = 2;//執行次數
                    //            //oPayment.SendExtend.PeriodReturnURL = "";//伺服器端回傳定期定額的執行結果網址。

                    //            #endregion


                    /* 產生訂單 */
                    enErrors.AddRange(oPayment.CheckOut());
                    oPayment.CheckOutString(ref html);
                }
            }
            catch (Exception ex)
            {
                // 例外錯誤處理。
                enErrors.Add(ex.Message);
            }
            finally
            {
                // 顯示錯誤訊息。
                if (enErrors.Count() > 0)
                {
                    // string szErrorMessage = String.Join("\\r\\n", enErrors);
                }
            }
            return(html);
        }
コード例 #9
0
        public ActionResult SendToOpay(string OrderKey = "", string JsonString = "")
        {
            // 將 JsonString 轉回購物車
            Cart currentCart = JsonConvert.DeserializeObject <Cart>(JsonString);

            List <string> enErrors = new List <string>();
            string        szHtml   = string.Empty;

            try
            {
                using (AllInOne oPayment = new AllInOne())
                {
                    string MyApiDomain = ConfigurationManager.AppSettings["MyApiDomain"];

                    /* 服務參數 */
                    oPayment.ServiceMethod = HttpMethod.HttpPOST;
                    oPayment.ServiceURL    = ConfigurationManager.AppSettings["ServiceURL"];
                    oPayment.HashKey       = ConfigurationManager.AppSettings["HashKey"];
                    oPayment.HashIV        = ConfigurationManager.AppSettings["HashIV"];
                    oPayment.MerchantID    = ConfigurationManager.AppSettings["MerchantID"];

                    /* 基本參數 */
                    string hostname = Request.Url.Authority;
                    oPayment.Send.ReturnURL         = $"{MyApiDomain}/Home/GetPayResult/?OrderKey={OrderKey}";
                    oPayment.Send.OrderResultURL    = $"{MyApiDomain}/Home/GetPayResult/?OrderKey={OrderKey}";
                    oPayment.Send.MerchantTradeNo   = DateTime.Now.ToString("yyyyMMddHHmmss");
                    oPayment.Send.MerchantTradeDate = DateTime.Now;
                    oPayment.Send.TotalAmount       = currentCart.TotalAmount;
                    oPayment.Send.TradeDesc         = "串接測試";

                    foreach (var cartItem in currentCart)
                    {
                        oPayment.Send.Items.Add(new Item()
                        {
                            Name     = cartItem.Name,
                            Price    = cartItem.Price,
                            Currency = "元",
                            Quantity = cartItem.Quantity
                        });
                    }

                    /* 產生歐付寶的訂單 */
                    enErrors.AddRange(oPayment.CheckOut());

                    /* 產生 Html Code */
                    enErrors.AddRange(oPayment.CheckOutString(ref szHtml));
                }
            }
            catch (Exception ex)
            {
                enErrors.Add(ex.Message);
            }
            finally
            {
                if (enErrors.Count() > 0)
                {
                    szHtml = string.Join("\\r\\n", enErrors);
                }
            }
            return(Content(szHtml));
        }
コード例 #10
0
ファイル: AllPay.cs プロジェクト: aobichen/MyAnything
        public string PayOfOrder(AllPayModel pay)
        {
            List <string> enErrors = new List <string>();

            using (AllInOne oPayment = new AllInOne())
            {
                /* 服務參數 */
                oPayment.ServiceMethod = HttpMethod.HttpPOST;
                oPayment.ServiceURL    = ServiceURL;
                oPayment.HashKey       = HashKey;
                oPayment.HashIV        = HashIV;

                oPayment.MerchantID = MerchantID;
                /* 基本參數 */
                //您要收到付款完成通知的伺服器端網址
                oPayment.Send.ReturnURL = string.IsNullOrEmpty(pay.ReturnURL) ? ReturnURL : pay.ReturnURL;
                //oPayment.Send.ClientBackURL = "https://developers.allpay.com.tw/AioMock/MerchantClientBackUrl";
                //您要歐付寶返回按鈕導向的瀏覽器端網址
                oPayment.Send.ClientBackURL = pay.ClientBackURL;
                //您要收到付款完成通知的瀏覽器端網址>
                oPayment.Send.OrderResultURL = pay.OrderResultURL;
                //oPayment.Send.OrderResultURL = ReturnURL;

                oPayment.Send.MerchantTradeNo   = pay.MerchantTradeNo;
                oPayment.Send.MerchantTradeDate = DateTime.Now;
                oPayment.Send.TotalAmount       = pay.TotalAmount;
                oPayment.Send.TradeDesc         = pay.TradeDesc;
                oPayment.Send.ChoosePayment     = PaymentMethod.ALL;
                oPayment.Send.Remark            = pay.Remark;
                oPayment.Send.ChooseSubPayment  = PaymentMethodItem.None;
                oPayment.Send.NeedExtraPaidInfo = ExtraPaymentInfo.Yes;
                oPayment.Send.HoldTrade         = HoldTradeType.No;
                oPayment.Send.DeviceSource      = DeviceType.PC;
                oPayment.Send.IgnorePayment     = "Tenpay";

                // 加入選購商品資料。
                foreach (var item in pay.Items)
                {
                    oPayment.Send.Items.Add(new Item()
                    {
                        Name = item.Name, Price = item.Price, Currency = item.Currency, Quantity = item.Quantity, URL = item.URL
                    });
                }


                /* Credit 分期延伸參數 */

                oPayment.SendExtend.CreditInstallment = pay.CreditInstallment;
                oPayment.SendExtend.InstallmentAmount = pay.InstallmentAmount;
                //是否使用紅利折抵
                oPayment.SendExtend.Redeem = false;
                //是否使用銀聯卡
                oPayment.SendExtend.UnionPay = false;
                /* 產生訂單 */
                enErrors.AddRange(oPayment.CheckOut());
                /* 產生產生訂單 Html Code 的方法 */
                string szHtml = String.Empty;
                enErrors.AddRange(oPayment.CheckOutString(ref szHtml));
                HtmlCode = szHtml;
            }

            return(HtmlCode);
        }