Пример #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
        protected void Page_Load(object sender, EventArgs e)
        {
            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         = "http://example.com";                                   //付款完成通知回傳的網址
                    oPayment.Send.ClientBackURL     = "http://www.ecpay.com.tw/";                             //瀏覽器端返回的廠商網址
                    oPayment.Send.OrderResultURL    = "http://localhost:52413/CheckOutFeedback.aspx";         //瀏覽器端回傳付款結果網址
                    oPayment.Send.MerchantTradeNo   = "TEC" + new Random().Next(1000000, 9999999).ToString(); //廠商的交易編號
                    oPayment.Send.MerchantTradeDate = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");           //廠商的交易時間
                    oPayment.Send.TotalAmount       = Int32.Parse(Session["total_price"].ToString());         //交易總金額
                    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.IgnorePayment     = "";                                                     //不顯示的付款方式
                    oPayment.Send.PlatformID        = "";                                                     //特約合作平台商代號
                    oPayment.Send.CustomField1      = "1234123";
                    oPayment.Send.CustomField2      = "1234";
                    oPayment.Send.CustomField3      = "12";
                    oPayment.Send.CustomField4      = "1";
                    oPayment.Send.EncryptType       = 1;



                    //訂單的商品資料
                    oPayment.Send.Items.Add(new Item()
                    {
                        Name     = Session["product_name"].ToString(),                  //商品名稱
                        Quantity = Int32.Parse(Session["product_quantity"].ToString()), //購買數量
                        Currency = "NTD",                                               //幣別單位
                        Price    = Int32.Parse(Session["product_price"].ToString()),    //商品單價
                        URL      = "http://google.com",                                 //商品的說明網址
                    });


                    /*************************非即時性付款: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());
                }
            }
            catch (Exception ex)
            {
                // 例外錯誤處理。
                enErrors.Add(ex.Message);
            }
            finally
            {
                // 顯示錯誤訊息。
                if (enErrors.Count() > 0)
                {
                    // string szErrorMessage = String.Join("\\r\\n", enErrors);
                }
            }
        }
Пример #4
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);
        }
Пример #5
0
        /// <summary>
        /// 綠界科技付款
        /// </summary>
        /// <param name="orderID">訂單ID</param>
        public static void Payment(int orderID)
        {
            ErrorMessage = "";
            List <string> enErrors = new List <string>();

            try
            {
                using (AllInOne oPayment = new AllInOne())
                {
                    using (ZONYEntities db = new ZONYEntities())
                    {
                        var order = db.Orders.Where(m => m.rowid == orderID).FirstOrDefault();
                        if (order != null)
                        {
                            string str_home_url = ShopContent.GetAppConfigValue("ECPayHomeURL");
                            string str_prod_url = "";
                            string str_order_no = order.order_no;
                            string str_total    = db.OrdersDetail
                                                  .Where(m => m.order_no == str_order_no)
                                                  .Sum(m => m.amount).ToString();

                            /* 服務參數 */
                            //介接服務時,呼叫 API 的方法
                            oPayment.ServiceMethod = HttpMethod.HttpPOST;
                            //要呼叫介接服務的網址
                            //測試環境:https://payment-stage.ecpay.com.tw/Cashier/AioCheckOut/V5
                            //正式環境:https://payment.ecpay.com.tw/Cashier/AioCheckOut/V5
                            oPayment.ServiceURL = ShopContent.GetAppConfigValue("ECPayServiceURL");
                            //ECPay提供的Hash Key Demo = 5294y06JbISpM5x9
                            oPayment.HashKey = ShopContent.GetAppConfigValue("ECPayHashKey");
                            //ECPay提供的Hash IV Demo = v77hoKGq4kWxNNIS
                            oPayment.HashIV = ShopContent.GetAppConfigValue("ECPayHashIV");
                            //ECPay提供的特店編號 Demo = 2000132
                            oPayment.MerchantID = ShopContent.GetAppConfigValue("ECPayMerchantID");

                            /* 基本參數 */
                            //付款完成通知回傳的網址
                            oPayment.Send.ReturnURL = ShopContent.GetAppConfigValue("ECPayReturnURL");
                            //瀏覽器端返回的廠商網址
                            oPayment.Send.ClientBackURL = ShopContent.GetAppConfigValue("ECPayClientBackURL");
                            //瀏覽器端回傳付款結果網址
                            oPayment.Send.OrderResultURL = ShopContent.GetAppConfigValue("ECPayOrderResultURL");
                            //訂單編號前置碼
                            string ECPayOrderCode = ShopContent.GetAppConfigValue("ECPayOrderCode");
                            //廠商的交易編號
                            oPayment.Send.MerchantTradeNo = ECPayOrderCode + new Random().Next(0, 99999).ToString();
                            //廠商的交易時間
                            oPayment.Send.MerchantTradeDate = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                            //交易總金額
                            oPayment.Send.TotalAmount = Decimal.Parse(str_total);
                            //交易描述
                            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.IgnorePayment = "";
                            //特約合作平台商代號
                            oPayment.Send.PlatformID   = "";
                            oPayment.Send.CustomField1 = "";
                            oPayment.Send.CustomField2 = "";
                            oPayment.Send.CustomField3 = "";
                            oPayment.Send.CustomField4 = "";
                            oPayment.Send.EncryptType  = 1;

                            //訂單的商品資料
                            var detail = db.OrdersDetail
                                         .Where(m => m.order_no == str_order_no)
                                         .ToList();
                            if (detail != null && detail.Count() > 0)
                            {
                                foreach (var item in detail)
                                {
                                    str_prod_url = string.Format("{0}/Product/ProductDetail/{1}", str_home_url, item.product_no);
                                    oPayment.Send.Items.Add(new Item()
                                    {
                                        //商品名稱
                                        Name = (item.product_name + item.product_spec),
                                        //商品單價
                                        Price = Decimal.Parse(item.price.ToString()),
                                        //幣別單位
                                        Currency = "新台幣",
                                        //購買數量
                                        Quantity = Int32.Parse(item.qty.ToString()),
                                        //商品的說明網址
                                        URL = str_prod_url
                                    });
                                }
                            }

                            /*************************非即時性付款: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());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // 例外錯誤處理。
                enErrors.Add(ex.Message);
            }
            finally
            {
                // 顯示錯誤訊息。
                if (enErrors.Count() > 0)
                {
                    ErrorMessage = String.Join("\\r\\n", enErrors);
                }
            }
        }
Пример #6
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);
        }
Пример #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
        protected void Page_Load(object sender, EventArgs e)
        {
            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         = "http://example.com";                             //付款完成通知回傳的網址
                    oPayment.Send.ClientBackURL     = "http://www.ecpay.com.tw/";                       //瀏覽器端返回的廠商網址
                    oPayment.Send.OrderResultURL    = "";                                               //瀏覽器端回傳付款結果網址
                    oPayment.Send.MerchantTradeNo   = "ECPay" + new Random().Next(0, 99999).ToString(); //廠商的交易編號
                    oPayment.Send.MerchantTradeDate = DateTime.Now;                                     //廠商的交易時間。
                    oPayment.Send.TotalAmount       = Decimal.Parse("50");                              //交易總金額
                    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.Items.Add(new Item()
                    {
                        Name     = "蘋果",                //商品名稱
                        Price    = Decimal.Parse("50"), //商品單價
                        Currency = "新台幣",               //幣別單位
                        Quantity = Int32.Parse("1"),    //購買數量
                        URL      = "http://google.com", //商品的說明網址
                        Unit     = "顆",                 //商品單位
                        TaxType  = TaxationType.Taxable //商品課稅別
                    });


                    /*************************非即時性付款: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,6";//刷卡分期期數

                    #endregion 分期付款

                    #region 定期定額

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

                    #endregion


                    /********************* 電子發票開立延伸參數 ********************************/
                    oPayment.Send.InvoiceMark              = InvoiceState.Yes;                                               // 指定要開立電子發票
                    oPayment.SendExtend.RelateNumber       = "ECPay" + new Random().Next(0, 99999).ToString();               //廠商自訂編號
                    oPayment.SendExtend.CustomerID         = "A12345678";                                                    //客戶代號
                    oPayment.SendExtend.CustomerIdentifier = "";                                                             //統一編號
                    oPayment.SendExtend.CustomerName       = "商家自訂名稱測試長度商家自訂名稱測試長度商家自訂名稱測試長度商家自訂名稱測試長度商家自訂名稱測試長度商家自訂名稱測試長度"; //客戶名稱
                    oPayment.SendExtend.CustomerAddr       = "客戶地址";                                                         //客戶地址
                    oPayment.SendExtend.CustomerPhone      = "0912345678";                                                   //客戶手機號碼
                    oPayment.SendExtend.CustomerEmail      = "*****@*****.**";                                        //客戶電子郵件
                    oPayment.SendExtend.ClearanceMark      = CustomsClearance.None;                                          //通關方式
                    oPayment.SendExtend.TaxType            = TaxationType.Taxable;                                           //課稅類別
                    oPayment.SendExtend.CarruerType        = InvoiceVehicleType.Member;                                      //載具類別
                    oPayment.SendExtend.CarruerNum         = "";                                                             //載具編號
                    oPayment.SendExtend.Donation           = DonatedInvoice.No;                                              //捐贈註記
                    oPayment.SendExtend.LoveCode           = "";                                                             //愛心碼
                    oPayment.SendExtend.Print              = PrintFlag.No;                                                   //列印註記
                    oPayment.SendExtend.InvoiceRemark      = "";                                                             //備註
                    oPayment.SendExtend.DelayDay           = Int32.Parse("0");                                               //延遲開立天數
                    oPayment.SendExtend.InvType            = TheWordType.General;                                            //字軌類別


                    /* 產生訂單 */
                    enErrors.AddRange(oPayment.CheckOut());
                }
            }
            catch (Exception ex)
            {
                // 例外錯誤處理。
                enErrors.Add(ex.Message);
            }
            finally
            {
                // 顯示錯誤訊息。
                if (enErrors.Count() > 0)
                {
                    // string szErrorMessage = String.Join("\\r\\n", enErrors);
                }
            }
        }
Пример #11
0
        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);
        }