Esempio n. 1
0
        static PayConfiguration createConfigFromFile(String filename)
        {
            // create/read configuration from a configuration file
            PayConfiguration config = new PayConfiguration(filename);

            return(config);
        }
Esempio n. 2
0
        //protected void grdPaymentMode_RowCommand(object sender, GridViewCommandEventArgs e)
        //{
        //    if (e.CommandName != "Sort")
        //    {
        //        int rowIndex = ((GridViewRow)((Control)e.CommandSource).NamingContainer).RowIndex;
        //        string commandName = e.CommandName;
        //        if (commandName != null)
        //        {
        //            if (!(commandName == "Fall"))
        //            {
        //                if (!(commandName == "Rise"))
        //                {
        //                    return;
        //                }
        //            }
        //            else
        //            {
        //                if (rowIndex != this.grdPaymentMode.Rows.Count)
        //                {
        //                    PaymentModeManage.DescPaymentMode((int)this.grdPaymentMode.DataKeys[rowIndex].Value);
        //                    this.BindData();
        //                }
        //                return;
        //            }
        //            if (rowIndex != 0)
        //            {
        //                PaymentModeManage.AscPaymentMode((int)this.grdPaymentMode.DataKeys[rowIndex].Value);
        //                this.BindData();
        //            }
        //        }
        //    }
        //}

        protected void grdPaymentMode_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#EAFED7';this.style.cursor='pointer';");//#F4F4F4

                //当鼠标移走时还原该行的背景色
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
                if (e.Row.RowIndex % 2 == 0)
                {
                    e.Row.Style.Add(HtmlTextWriterStyle.BackgroundColor, "#F4F4F4");
                }
                else
                {
                    e.Row.Style.Add(HtmlTextWriterStyle.BackgroundColor, "#FFFFFF");
                }
                Label label = (Label)e.Row.FindControl("lblGatawayType");
                if (label != null)
                {
                    GatewayProvider provider = PayConfiguration.GetConfig().Providers[label.Text.ToLower()] as GatewayProvider;
                    if (provider != null)
                    {
                        label.Text = provider.DisplayName;
                    }
                }
            }
        }
Esempio n. 3
0
        private void DoValidate()
        {
            PayConfiguration    config     = PayConfiguration.GetConfig();
            NameValueCollection parameters = new NameValueCollection();

            parameters.Add(this.Page.Request.Form);
            parameters.Add(this.Page.Request.QueryString);
            string tmpGatewayName = this.Page.Request.QueryString[Globals.GATEWAY_KEY];

            if (string.IsNullOrEmpty(tmpGatewayName))
            {
                this.ResponseStatus(true, "gatewaynotfound");
                return;
            }
            this.GatewayName = tmpGatewayName.ToLower();
            GatewayProvider provider = config.Providers[this.GatewayName] as GatewayProvider;

            if (provider == null)
            {
                this.ResponseStatus(true, "gatewaynotfound");
                return;
            }
            this.Notify = NotifyQuery.Instance(provider.NotifyType, parameters);
            if (this.isBackRequest)
            {
                this.Notify.ReturnUrl = Globals.FullPath(string.Format(Globals.PAYMENT_RETURN_URL, this.GatewayName));
            }
            this.RechargeId      = long.Parse(this.Notify.GetOrderId(), CultureInfo.InvariantCulture);
            this.Amount          = this.Notify.GetOrderAmount();
            this.RechargeRequest = PaymentModeManage.GetRechargeRequest(this.RechargeId);
            if (this.RechargeRequest == null)
            {
                this.ResponseStatus(true, "success");
            }
            else
            {
                this.Amount  = this.RechargeRequest.RechargeBlance;
                this.paymode = PaymentModeManage.GetPaymentModeByName(this.RechargeRequest.PaymentGateway);
                if (this.paymode == null)
                {
                    this.ResponseStatus(true, "gatewaynotfound");
                }
                else
                {
                    PayeeInfo payee = new PayeeInfo
                    {
                        EmailAddress  = this.paymode.EmailAddress,
                        Partner       = this.paymode.Partner,
                        Password      = this.paymode.Password,
                        PrimaryKey    = this.paymode.SecretKey,
                        SecondKey     = this.paymode.SecondKey,
                        SellerAccount = this.paymode.MerchantCode
                    };
                    this.Notify.PaidToIntermediary += new NotifyEventHandler(this.notify_PaidToIntermediary);
                    this.Notify.PaidToMerchant     += new NotifyEventHandler(this.notify_PaidToMerchant);
                    this.Notify.NotifyVerifyFaild  += new NotifyEventHandler(this.notify_NotifyVerifyFaild);
                    this.Notify.VerifyNotify(0x7530, payee);
                }
            }
        }
Esempio n. 4
0
        private bool LogOUT()
        {
            Thread t = new Thread(() =>
            {
                try
                {
                    // create/read configuration from a configuration file
                    PayConfiguration config = createConfigFromFile(mPfad);

                    // start a new session
                    PaySession session = new PaySession();

                    // we define a message listener for events (optional)
                    MyMessageListener msgList = new MyMessageListener(lbl_Status, btn_OK);

                    session.setListener(msgList);

                    // login (this is always the first communication to the EFT)
                    mTerminal = session.login(config);

                    // logout at last
                    session.logout();
                }
                catch (PayException x)
                {
                    // catch all PayExceptions and write to console
                    Console.WriteLine(x.toString());
                }
            });

            t.Start();
            return(true);
        }
Esempio n. 5
0
        static PayConfiguration createConfigManually()
        {
            // create/read configuration manually (without a file)
            PayConfiguration config = new PayConfiguration();

            // set all mandatory fields
            config.setDevice("H5000");
            config.setDeviceConnector("LAN");
            config.setDeviceProtocol("ZVT");
            config.setTerminalID("12345678");
            config.setMerchantPIN("000000");      // Verifone: 000000, Ingenico: 00000, CCV: 000000
            config.setServicePIN("111111");       // Verifone: 111111, Ingenico: 11599, CCV: 003563
            config.setLicenseFile("../../etc/LUIS_ePaymentLicense.dat");

            // mandatory, if networkConnection=ISDN or =ISDNviaSerial
            //config.setNetworkConnection("ISDN");
            //config.setPhoneConnection(datex1, phone1, datex2, phone2, prefix);

            // mandatory, if networkConnection=LAN
            config.setNetworkConnection("LAN");
            config.setLANConnection("213.095.152.80", "5000", "217.111.131.50", "5000"); //cardTech-1: 213.095.152.80:5000, cardTech-2: 217.111.131.50:5000
            config.setLanIPLocal("192.168.1.99");
            config.setLanPortLocal(22000);                                               // Verifone: 22000, Ingenico: 5577
            config.setLanGateway("192.168.1.1");

            // set log4j config file (optional, default = "./LUIS_ePayment.xml")
            config.setLogfile("../../etc/LUIS_ePayment.xml");

            return(config);
        }
Esempio n. 6
0
        private bool ONLine()
        {
            Thread t = new Thread(() =>
            {
                try
                {
                    //--------------
                    // create/read configuration from a configuration file
                    PayConfiguration config = createConfigFromFile(mPfad);

                    // start a new session
                    PaySession session = new PaySession();

                    // we define a message listener for events (optional)
                    MyMessageListener msgList = new MyMessageListener(lbl_Status, btn_OK);

                    session.setListener(msgList);

                    if (!session.isLoggedIn())
                    {
                        // login (this is always the first communication to the EFT)
                        mTerminal = session.login(config);
                    }


                    try
                    {
                        // Now we start a payment of 1 cent

                        // First we create the result object PayMedia
                        PayMedia media = new PayMedia();

                        // Then we start the authorisation of the card

                        short payType = PayTerminal.__Fields.PAY_TYPE_AUTOMATIC;
                        PayTransaction transaction = mTerminal.payment(mBetrag, payType, media);

                        // When we are here, the given card was accepted. We commit the transaction.
                        // If transaction is null, the device doesn't support commit and we are finished.
                        if (transaction != null)
                        {
                            transaction.commit(media);
                        }
                    }
                    finally
                    {
                    }
                }
                catch (PayException x)
                {
                    // catch all PayExceptions and write to console
                    Console.WriteLine(x.toString());
                }
            });

            t.Start();
            return(true);
        }
Esempio n. 7
0
        private OpResult GetCompanyPayInfo(int cid, string storeid, int apicode, out string mapCid, bool isCallback = false)
        {
            mapCid = string.Empty;
            var _cid   = cid.ToString();
            var entity = new PayConfiguration();

            if (!isCallback)
            {
                entity = PayConfigurationService.Find(o => o.CompanyId == cid && o.State == 1 && apicode == o.PayType);
            }
            else
            {
                entity = PayConfigurationService.Find(o => o.PaymentMerchantNumber == _cid && o.State == 1 && apicode == o.PayType);
            }
            if (entity != null)
            {
                var storeEntity = new StorePaymentAuthorization();
                if (isCallback)
                {
                    storeEntity = StorePaymentAuthorizationService.Find(o => o.CompanyId == entity.CompanyId && o.MapPaymentStoreId == storeid && o.PayType == apicode && o.State == 1);
                }
                else
                {
                    storeEntity = StorePaymentAuthorizationService.Find(o => o.CompanyId == entity.CompanyId && o.StoreId == storeid && o.PayType == apicode && o.State == 1);
                }
                if (storeEntity != null)
                {
                    //return OpResult.Success(entity.SecurityKey);
                    OpResult result = new OpResult()
                    {
                        Successed = true,
                        Message   = entity.SecurityKey,
                        Data      = storeEntity.MapPaymentStoreId
                    };
                    if (!isCallback)
                    {
                        mapCid = entity.PaymentMerchantNumber;
                    }
                    else
                    {
                        mapCid = entity.CompanyId.ToString();
                    }
                    return(result);
                }
                else
                {
                    return(OpResult.Fail("门店未开通授权支付!"));
                }
            }
            else
            {
                return(OpResult.Fail("商户未开通授权支付!"));
            }
        }
Esempio n. 8
0
        static PayConfiguration createConfigManually()
        {
            // create/read configuration manually (without a file)
            PayConfiguration config = new PayConfiguration();

            // set all mandatory fields
            config.setSharedTerminalIP("192.168.1.100");

            // set log4j config file (optional, default = "./LUIS_ePayment.xml")
            config.setLogfile("../../etc/LUIS_ePayment.xml");

            return(config);
        }
Esempio n. 9
0
        public override void DataBind()
        {
            PayConfiguration config   = PayConfiguration.GetConfig();
            GatewayProvider  provider = null;

            for (int i = 0; i < config.Keys.Count; i++)
            {
                provider = config.Providers[config.Keys[i]] as GatewayProvider;
                this.Items.Add(new ListItem(provider.DisplayName, provider.Name));
            }
            if (this.AllowNull)
            {
                this.Items.Insert(0, new ListItem(this.NullToDisplay, ""));
            }
        }
Esempio n. 10
0
        public virtual void ProcessRequest(HttpContext context)
        {
            //支付ID
            int paymentModeId = Globals.SafeInt(context.Request.QueryString["modeId"], 0);
            //充值金额
            decimal balance = Globals.SafeDecimal(context.Request.QueryString["blance"], 0M);

            //参数 NULL ERROR返回首页
            if ((paymentModeId == 0) || (balance == 0M))
            {
                //Add ErrorLog..
                return;
            }

            T user = GetCurrentUser(context);
            PayConfiguration config      = PayConfiguration.GetConfig();
            PaymentModeInfo  paymentMode = PaymentModeManage.GetPaymentModeById(paymentModeId);
            GatewayProvider  provider    = config.Providers[paymentMode.Gateway.ToLower()] as GatewayProvider;

            //计算支付手续费
            decimal payCharge = paymentMode.CalcPayCharge(balance);

#warning 未支持多币种支付手续费
            //根据多币种货币换算, 计算手续费
            //decimal payCharge = Sales.ScaleMoney(paymentMode.CalcPayCharge(balance));

            if (provider != null)
            {
                RechargeRequestInfo info2 = null;
                info2 = new RechargeRequestInfo
                {
                    TradeDate      = DateTime.Now,
                    RechargeBlance = balance,
                    UserId         = user.UserId,
                    PaymentGateway = paymentMode.Gateway
                };
                info2.RechargeId = PaymentModeManage.AddRechargeBalance(info2);
                if (info2.RechargeId > 0L)
                {
                    PaymentRequest.Instance(
                        provider.RequestType,
                        this.GetPayee(paymentMode),
                        this.GetGateway(paymentMode.Gateway.ToLower()),
                        this.GetTrade(info2, payCharge, user)
                        ).SendRequest();
                }
            }
        }
Esempio n. 11
0
        static PayConfiguration createConfigFromFile(String filename)
        {
            if (File.Exists(filename))
            {
                //für Debug
                //MessageBox.Show("Config-Datei passt");
            }
            else
            {
                MessageBox.Show("Config-Datei fehlt oder falscher Pfad!");
            }

            // create/read configuration from a configuration file
            PayConfiguration config = new PayConfiguration(filename);

            return(config);
        }
Esempio n. 12
0
        public PayProvider(IOptionsSnapshot <PayConfiguration> options, HttpClient httpClient)
        {
            _httpClient = httpClient;
            if (_httpClient == null)
            {
                throw new ArgumentNullException(nameof(_httpClient));
            }

            var configuration = options;

            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            _configuration = configuration.Value;
            if (_configuration == null)
            {
                throw new ArgumentNullException(nameof(_configuration));
            }

            _requestUrl = PayUrls.AuthorizeUrl;
            _verifyUrl  = PayUrls.VerifyUrl;
        }
Esempio n. 13
0
        protected virtual void DoValidate()
        {
            PayConfiguration    config     = PayConfiguration.GetConfig();
            NameValueCollection parameters = new NameValueCollection();

            parameters.Add(this.Page.Request.Form);
            parameters.Add(this.Page.Request.QueryString);
            string tmpGatewayName = this.Page.Request.Params[Globals.GATEWAY_KEY];

            if (string.IsNullOrEmpty(tmpGatewayName))
            {
                this.ResponseStatus(false, "gatewaynotfound");
                return;
            }
            this.GatewayName = tmpGatewayName.ToLower();
            GatewayProvider provider = config.Providers[this.GatewayName] as GatewayProvider;

            if (provider == null)
            {
                this.ResponseStatus(false, "gatewaynotfound");
                return;
            }
            this.Notify = NotifyQuery.Instance(provider.NotifyType, parameters);
            if (this.isBackRequest)
            {
                this.Notify.ReturnUrl = Globals.FullPath(string.Format(Option.ReturnUrl, this.GatewayName));
            }
            this.Amount  = this.Notify.GetOrderAmount();
            this.OrderId = this.Notify.GetOrderId();
            this.Order   = this.GetOrderInfo(this.OrderId);
            if (this.Order == null)
            {
                this.ResponseStatus(false, "ordernotfound");
            }
            else if (this.Order.PaymentStatus == PaymentStatus.Prepaid)
            {
                this.ResponseStatus(true, "success");
            }
            else
            {
                //设置支付网关生成的订单ID
                this.Order.GatewayOrderId = this.Notify.GetGatewayOrderId();

                PaymentModeInfo paymentMode = this.GetPaymentMode(this.Order.PaymentTypeId);
                if (paymentMode == null)
                {
                    this.ResponseStatus(false, "gatewaynotfound");
                }
                else
                {
                    #region 测试模式
                    //DONE: 测试模式埋点
                    if (Globals.IsPaymentTestMode)
                    {
                        string sign = this.Page.Request.Params["sign"];
                        if (string.IsNullOrWhiteSpace(sign))
                        {
                            this.ResponseStatus(false, "<TestMode> no sign");
                        }

                        System.Text.StringBuilder url = new System.Text.StringBuilder(
                            Globals.FullPath(string.Format(Option.ReturnUrl, this.GatewayName)));
                        url.AppendFormat("&out_trade_no={0}", this.OrderId);
                        url.AppendFormat("&total_fee={0}", this.Amount);

                        if (sign != Globals.GetMd5(System.Text.Encoding.UTF8, url.ToString()))
                        {
                            this.ResponseStatus(false, "<TestMode> Unauthorized sign");
                        }

                        //效验通过
                        PaidToSite();
                        return;
                    }
                    #endregion

                    PayeeInfo payee = new PayeeInfo
                    {
                        EmailAddress  = paymentMode.EmailAddress,
                        Partner       = paymentMode.Partner,
                        Password      = paymentMode.Password,
                        PrimaryKey    = paymentMode.SecretKey,
                        SecondKey     = paymentMode.SecondKey,
                        SellerAccount = paymentMode.MerchantCode
                    };

                    GatewayInfo getway = new GatewayInfo
                    {
                        ReturnUrl = Option.ReturnUrl,
                        NotifyUrl = Option.NotifyUrl
                    };
                    this.Notify.NotifyVerifyFaild  += new NotifyEventHandler(this.notify_NotifyVerifyFaild);
                    this.Notify.PaidToIntermediary += new NotifyEventHandler(this.notify_PaidToIntermediary);
                    this.Notify.PaidToMerchant     += new NotifyEventHandler(this.notify_PaidToMerchant);
                    this.Notify.VerifyNotify(0x7530, payee, getway);
                }
            }
        }
Esempio n. 14
0
 /// <summary>
 /// 初始化 <see cref="DevConfiguration"/> 类的新实例。
 /// </summary>
 public DevConfiguration()
 {
     this.PayConfig = new PayConfiguration();
 }
Esempio n. 15
0
        private void DisplayControls()
        {
            if (string.IsNullOrWhiteSpace(this.dropPayInterface.SelectedValue))
            {
                this.HiddenAll();
            }
            else
            {
                if (((this.dropPayInterface.SelectedValue.ToLower() == "cod") ||
                     (this.dropPayInterface.SelectedValue.ToLower() == "advanceaccount")) ||
                    (this.dropPayInterface.SelectedValue.ToLower() == "bank"))
                {
                    chkWap.Enabled = chkWeb.Enabled = true;
                    this.radAllowRecharge.SelectedValue = false;
                    this.radAllowRecharge.Enabled       = false;
                }
                else
                {
                    chkWap.Enabled = chkWeb.Enabled = false;
                    this.radAllowRecharge.SelectedValue = true;
                    this.radAllowRecharge.Enabled       = true;
                }

                chkWeb.Checked = true;
                chkWap.Checked = false;
                if (this.dropPayInterface.SelectedValue.ToLower() == "alipaywap" ||
                    this.dropPayInterface.SelectedValue.ToLower().StartsWith("lakala") ||
                    this.dropPayInterface.SelectedValue.ToLower().StartsWith("cash"))
                {
                    chkWap.Enabled = chkWeb.Enabled = false;
                    chkWeb.Checked = false;
                    chkWap.Checked = true;
                }


                if (this.dropPayInterface.SelectedValue.ToLower().StartsWith("wechat"))
                {
                    this.radAllowRecharge.Enabled       = false;
                    this.radAllowRecharge.SelectedValue = false;
                    chkWap.Enabled = chkWeb.Enabled = true;
                    chkWeb.Checked = true;
                    chkWap.Checked = true;
                }

                GatewayProvider provider = PayConfiguration.GetConfig().Providers[this.dropPayInterface.SelectedValue] as GatewayProvider;
                this.tblrImage.Visible        = provider.Attributes["emailAddress"].ToLower() == "true";
                this.tblrSecretKey.Visible    = provider.Attributes["primaryKey"].ToLower() == "true";
                this.tblrSecondKey.Visible    = provider.Attributes["secondKey"].ToLower() == "true";
                this.tblrPassword.Visible     = provider.Attributes["password"].ToLower() == "true";
                this.tblrPartner.Visible      = provider.Attributes["partner"].ToLower() == "true";
                this.tblrCurrencys.Visible    = false; // provider.SupportedCurrencys.Count > 0;
                this.tblrMerchantCode.Visible = provider.Attributes["sellerAccount"].ToLower() == "true";
                this.tblCharge.Visible        = false; // (provider.Name != "advanceaccount") && !(provider.Name == "bank");
                this.chkCurrencysList.Items.Clear();
                foreach (string str in provider.SupportedCurrencys)
                {
                    if ((provider.Name == "advanceaccount") || (provider.Name == "bank"))
                    {
                        //默认货币 - 人民币
                        string   defaultCurrency = "CNY";
                        ListItem defaultItem     = new ListItem((string)HttpContext.GetGlobalResourceObject("Resources", "Currency_" + defaultCurrency), defaultCurrency);
                        defaultItem.Selected = true;
                        this.chkCurrencysList.Items.Add(defaultItem);
                        continue;
                    }
                    ListItem listItem = new ListItem((string)HttpContext.GetGlobalResourceObject("Resources", "Currency_" + str), str);
                    listItem.Selected = true;
                    this.chkCurrencysList.Items.Add(listItem);
                }

                if ((provider.Attributes["url"] != null) && (provider.Attributes["url"].Trim().Length > 0))
                {
                    if ((provider.Attributes["logo"] != null) && (provider.Attributes["logo"].Trim().Length > 0))
                    {
                        this.hlinkImage.NavigateUrl = provider.Attributes["url"].Replace("^", "&");
                        this.lblimage.Text          = string.Format(CultureInfo.InvariantCulture, "<img src=\"{0}\" border=\"0\" />", new object[] { provider.Attributes["logo"] });
                        this.lblimage.Visible       = true;
                    }
                    else
                    {
                        this.lblimage.Text    = provider.Attributes["url"];
                        this.lblimage.Visible = false;
                    }
                }
                else
                {
                    this.lblimage.Visible = false;
                }
            }
        }
Esempio n. 16
0
        protected void DoValidate()
        {
            PayConfiguration    config     = PayConfiguration.GetConfig();
            NameValueCollection parameters = new NameValueCollection();

            parameters.Add(HttpContext.Current.Request.QueryString);
            parameters.Add(HttpContext.Current.Request.Form);
            string gatewayData = parameters[Globals.GATEWAY_KEY];

            if (string.IsNullOrEmpty(gatewayData))
            {
                Core.Globals.WriteText(new System.Text.StringBuilder(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " gatewaydatanotfound GATEWAYDATA IS NULL"));
                this.ResponseStatus(false, "gatewaydatanotfound");
                return;
            }
            parameters.Remove(Globals.GATEWAY_KEY);

            //获取GetwayData特殊Base64数据
            GetwayDatas = Globals.DecodeData4Url(gatewayData).Split(new[] { '|' }, System.StringSplitOptions.None);
            if (GetwayDatas.Length < 1)
            {
                Core.Globals.WriteText(new System.Text.StringBuilder(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " gatewaydatanotfound GetwayDatas.Length < 1"));
                this.ResponseStatus(false, "gatewaydatanotfound");
                return;
            }
            this.GatewayName = GetwayDatas[0].ToLower();
            GatewayProvider provider = config.Providers[this.GatewayName] as GatewayProvider;

            if (provider == null)
            {
                this.ResponseStatus(false, "gatewaynotfound");
                Core.Globals.WriteText(new System.Text.StringBuilder(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " gatewaydatanotfound PROVIDER IS NULL"));
                return;
            }
            if (string.IsNullOrWhiteSpace(provider.NotifyType))
            {
                this.ResponseStatus(false, "notifytypenotfound");
                Core.Globals.WriteText(new System.Text.StringBuilder(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " gatewaydatanotfound PROVIDER.NOTIFYTYPE IS NULL"));
                return;
            }

            if (provider.UseNotifyMode)     //DONE: 使用差异通知模式 BEN NEW MODE 20131016
            {
                this.Notify = NotifyQuery.Instance(provider.NotifyType, parameters,
                                                   _isNotify ? NotifyMode.Notify : NotifyMode.Callback);
            }
            else                            //回调和通知均使用同一种模式
            {
                this.Notify = NotifyQuery.Instance(provider.NotifyType, parameters);
            }
            if (this._isNotify)
            {
                this.Notify.ReturnUrl = Globals.FullPath(string.Format(Option.ReturnUrl, gatewayData));
            }

            #region 加载企业ID
            if (Components.MvcApplication.IsAutoConn)
            {
                Common.CallContextHelper.SetAutoTag(Common.Globals.SafeLong(GetwayDatas[2], 0));
            }
            #endregion

            #region 测试模式
            if (Globals.IsPaymentTestMode)
            {
                this._orderId = parameters["out_trade_no"];
            }
            #endregion
            else
            {
                this._orderId = this.Notify.GetOrderId();
            }

            this.Order = Option.GetOrderInfo(this._orderId);
            if (this.Order == null)
            {
                Core.Globals.WriteText(new System.Text.StringBuilder(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " GETORDERINFO IS NULL| ORDERID:" + this._orderId));
                this.ResponseStatus(false, "ordernotfound");
                return;
            }

            #region 测试模式
            if (Globals.IsPaymentTestMode)
            {
                this._amount = Globals.SafeDecimal(parameters["total_fee"], -1);
            }
            #endregion
            else
            {
                this._amount = this.Notify.GetOrderAmount() == decimal.Zero
                    ? this.Order.Amount
                    : this.Notify.GetOrderAmount();
            }

            //设置支付网关生成的订单ID
            this.Order.GatewayOrderId = this.Notify.GetGatewayOrderId();
            PaymentMode = this.GetPaymentMode(this.Order.PaymentTypeId);
            if (PaymentMode == null)
            {
                Core.Globals.WriteText(new System.Text.StringBuilder(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " PAYMENTMODE IS NULL| PaymentTypeId:" + this.Order.PaymentTypeId));
                this.ResponseStatus(false, "gatewaynotfound");
                return;
            }

            if (this.Order.PaymentStatus == PaymentStatus.Prepaid)
            {
                this.ResponseStatus(true, "success");
            }
            else
            {
                #region 测试模式
                //DONE: 测试模式埋点
                if (Globals.IsPaymentTestMode)
                {
                    string sign = HttpContext.Current.Request.QueryString["sign"];
                    if (string.IsNullOrWhiteSpace(sign))
                    {
                        this.ResponseStatus(false, "<TestMode> no sign");
                    }

                    System.Text.StringBuilder url = new System.Text.StringBuilder(
                        Globals.FullPath(string.Format(Option.ReturnUrl, gatewayData)));
                    url.AppendFormat("&out_trade_no={0}", this._orderId);
                    url.AppendFormat("&total_fee={0}", this._amount);

                    if (sign != Globals.GetMd5(System.Text.Encoding.UTF8, url.ToString()))
                    {
                        this.ResponseStatus(false, "<TestMode> Unauthorized sign");
                    }

                    //效验通过
                    PaidToSite();
                    return;
                }
                #endregion

                PayeeInfo payee = new PayeeInfo
                {
                    EmailAddress  = PaymentMode.EmailAddress,
                    Partner       = PaymentMode.Partner,
                    Password      = PaymentMode.Password,
                    PrimaryKey    = PaymentMode.SecretKey,
                    SecondKey     = PaymentMode.SecondKey,
                    SellerAccount = PaymentMode.MerchantCode
                };
                GatewayInfo getway = new GatewayInfo
                {
                    Data      = gatewayData,
                    DataList  = GetwayDatas.ToList(),
                    ReturnUrl = Option.ReturnUrl,
                    NotifyUrl = Option.NotifyUrl
                };
                this.Notify.NotifyVerifyFaild  += new NotifyEventHandler(this.notify_NotifyVerifyFaild);
                this.Notify.PaidToIntermediary += new NotifyEventHandler(this.notify_PaidToIntermediary);
                this.Notify.PaidToMerchant     += new NotifyEventHandler(this.notify_PaidToMerchant);

                this.Notify.VerifyNotify(0x7530, payee, getway);
            }
        }
Esempio n. 17
0
        static void Main(string[] args)
        {
            try
            {
                // create/read configuration from a configuration file
                PayConfiguration config = createConfigFromFile("../../etc/zvt.cfg");

                // start a new session
                PaySession session = new PaySession();

                // we define a message listener for events (optional)
                session.setListener(new MyMessageListener());

                // get the software version of LUIS ePayment
                Console.WriteLine("Version=" + session.getVersion());

                // login (this is always the first communication to the EFT)
                PayTerminal terminal = session.login(config);

                try
                {
                    // let's have a look at the settings within the EFT
                    PayResult result = terminal.settings();
                    Console.WriteLine(result.toString());

                    // do some selftest
                    result = terminal.selftest();
                    Console.WriteLine(result.toString());


                    // try to connect the network provider and get the limits for a payment
                    result = terminal.diagnose(PayTerminal.__Fields.DIAGNOSE_EXTENDED);
                    Console.WriteLine(result.toString());


                    // Now we start a payment of 1 cent

                    // First we create the result object PayMedia
                    PayMedia media = new PayMedia();

                    // Then we start the authorisation of the card
                    int            cents       = 1;
                    short          payType     = PayTerminal.__Fields.PAY_TYPE_AUTOMATIC;
                    PayTransaction transaction = terminal.payment(cents, payType, media);
                    Console.WriteLine(media.toString());

                    // When we are here, the given card was accepted. We commit the transaction.
                    // If transaction is null, the device doesn't support commit and we are finished.
                    if (transaction != null)
                    {
                        transaction.commit(media);
                        Console.WriteLine(media.toString());
                    }
                }
                finally
                {
                    // logout at last
                    session.logout();
                }
            }
            catch (PayException x)
            {
                // catch all PayExceptions and write to console
                Console.WriteLine(x.toString());
            }
        }
Esempio n. 18
0
        public virtual void ProcessRequest(HttpContext context)
        {
            //Safe
            if (!VerifySendPayment(context))
            {
                return;
            }

            //订单ID字符串
            string orderIdStr = string.Empty;

            //获取全部订单ID
            string[] orderIds = OrderProcessor.GetQueryString4OrderIds(context.Request, out orderIdStr);

            //订单ID NULL ERROR返回首页
            if (orderIds == null || orderIds.Length < 1)
            {
                //Add ErrorLog..
                HttpContext.Current.Response.Redirect("~/");
                return;
            }

            //合并支付 订单支付信息以第一份订单为主
            T orderInfo = Option.GetOrderInfo(orderIds[0]);

            if (orderInfo == null)
            {
                return;
            }

            //计算订单支付金额
            decimal totalMoney = this.GetOrderTotalMoney(orderIds, orderInfo);

            if (totalMoney < 0)
            {
                return;
            }

            if (orderInfo.PaymentStatus != PaymentStatus.NotYet)
            {
                //订单已支付
                context.Response.Write(
                    HttpContext.GetGlobalResourceObject("Resources", "IDS_ErrorMessage_SentPayment").ToString());
                return;
            }

            PaymentModeInfo paymentMode = GetPaymentMode(orderInfo);

            if (paymentMode == null || string.IsNullOrWhiteSpace(paymentMode.Gateway))
            {
                //订单历史的支付方式不存在
                context.Response.Write(
                    HttpContext.GetGlobalResourceObject("Resources", "IDS_ErrorMessage_NoPayment").ToString());
                return;
            }

            string getwayName = paymentMode.Gateway.ToLower();

            //获取支付网关
            GatewayProvider provider =
                PayConfiguration.GetConfig().Providers[getwayName] as GatewayProvider;

            if (provider == null)
            {
                return;
            }

            //支付网关
            GatewayInfo gatewayInfo = this.GetGateway(getwayName);

            //交易信息
            TradeInfo tradeInfo = this.GetTrade(orderIdStr, totalMoney, orderInfo);

            #region 测试模式
            //DONE: 测试模式埋点
            if (Globals.IsPaymentTestMode && !Globals.ExcludeGateway.Contains(getwayName.ToLower()))
            {
                System.Text.StringBuilder url = new System.Text.StringBuilder(gatewayInfo.ReturnUrl);
                url.AppendFormat("&out_trade_no={0}", tradeInfo.OrderId);
                url.AppendFormat("&total_fee={0}", tradeInfo.TotalMoney);
                url.AppendFormat("&sign={0}", Globals.GetMd5(System.Text.Encoding.UTF8, url.ToString()));
                HttpContext.Current.Response.Redirect(
                    gatewayInfo.ReturnUrl.Contains("?")
                        ? url.ToString()
                        : url.ToString().Replace("&out_trade_no", "?out_trade_no"), true);
                return;
            }
            #endregion

            #region 发送支付请求
            //发送支付请求
            PaymentRequest paymentRequest = PaymentRequest.Instance(
                provider.RequestType,
                this.GetPayee(paymentMode),
                gatewayInfo,
                tradeInfo
                );
            if (paymentRequest == null)
            {
                return;
            }
            paymentRequest.SendRequest();
            #endregion
        }