Esempio n. 1
0
 public static QuoteResponse Success(QuoteRequest req, QuoteInfo quoteInfo)
 {
     return new QuoteResponse { Result = "success", QuoteInfo = quoteInfo, OriginRequest = req };
 }
Esempio n. 2
0
        public System.Web.Http.Results.JsonResult<QuoteResponse> RippleQuote(string type)
        {
            var result = default(QuoteResponse);
            var query_params = this.Request.GetQueryNameValuePairs();

            var amount = query_params.SingleOrDefault(item => item.Key.Equals("amount", StringComparison.OrdinalIgnoreCase)).Value;
            var destination = query_params.SingleOrDefault(item => item.Key.Equals("destination", StringComparison.OrdinalIgnoreCase)).Value;
            var address = query_params.SingleOrDefault(item => item.Key.Equals("address", StringComparison.OrdinalIgnoreCase)).Value;
            var alipay_account = query_params.SingleOrDefault(item => item.Key.Equals("alipay_account", StringComparison.OrdinalIgnoreCase)).Value;
            var alipay_username = query_params.SingleOrDefault(item => item.Key.Equals("alipay_username", StringComparison.OrdinalIgnoreCase)).Value;
            var tenpay_account = query_params.SingleOrDefault(item => item.Key.Equals("tenpay_account", StringComparison.OrdinalIgnoreCase)).Value;
            var tenpay_username = query_params.SingleOrDefault(item => item.Key.Equals("tenpay_username", StringComparison.OrdinalIgnoreCase)).Value;
            var bank_account = query_params.SingleOrDefault(item => item.Key.Equals("bank_account", StringComparison.OrdinalIgnoreCase)).Value;
            var bank_username = query_params.SingleOrDefault(item => item.Key.Equals("bank_username", StringComparison.OrdinalIgnoreCase)).Value;
            var bank = query_params.SingleOrDefault(item => item.Key.Equals("bank", StringComparison.OrdinalIgnoreCase)).Value;
            var memo = query_params.SingleOrDefault(item => item.Key.Equals("memo", StringComparison.OrdinalIgnoreCase)).Value.NullSafe().Trim();
            memo = memo.Length > 250 ? memo.Substring(0, 250) : memo;
            var req = new QuoteRequest { Type = type, __dot_use_this_amount = amount, Address = address, Destination = destination, AlipayAccount = alipay_account, TenpayAccount = tenpay_account, Memo = memo };

            type = type.NullSafe().Trim();
            destination = destination.NullSafe().Trim();

            #region 错误处理
            if (!type.ToLower().Equals("quote"))
                result = QuoteResult.NoSupportedType(req, type);
            else if (string.IsNullOrEmpty(destination))
                result = QuoteResult.ErrorDetail(req, "destination is empty");

            #endregion
            else
            {
                var sendAmount = req.Amount.Value + CalcFee(req.Amount.Value);

                //如果用户要做扩展表单直转 to alipay,且支付宝账号不为空
                if (destination.Equals("alipay", StringComparison.OrdinalIgnoreCase) && req.Amount.Value <= maxAcceptAmount && req.Amount.Value >= minAcceptAmount)
                {
                    if (string.IsNullOrEmpty(alipay_account))
                        result = QuoteResult.ErrorDetail(req, "alipay account empty;");
                    else
                    {
                        //创建一个交易
                        var cmd = new CreateThirdPartyPaymentInboundTx(PayWay.Alipay, alipay_account, alipay_username.NullSafe().Trim(), req.Amount.Value, sendAmount, memo);

                        try
                        {
                            IoC.Resolve<ICommandBus>().Send(cmd);
                            var quoteInfo = new QuoteInfo
                            {
                                Type = "quote",
                                Destination = destination,
                                DestinationAddress = GATEWAY_ADDRESS,
                                Domain = GATEWAY_DOMAIN,
                                DestinationTag = Convert.ToInt32(DestinationTagFlg.AlipayRippleForm.ToString("D") + cmd.ResultDestinationTag.ToString()),
                                Amount = req.Amount.Value,
                                Send = new List<RippleAmount> { new RippleAmount(sendAmount, GATEWAY_ADDRESS, req.Amount.Currency) },
                                InvoiceId = cmd.ResultInvoiceID,
                                Source = req.Address
                            };
                            result = QuoteResult.Success(req, quoteInfo);
                        }
                        catch (Exception ex) { Log.Error("在执行Ripple Alipay Quote时报错", ex); }
                    }
                }

                //如果用户要做扩展表单直转 to huodong,
                else if (destination.Equals("huodong", StringComparison.OrdinalIgnoreCase) && req.Amount.Value <= maxAcceptAmount && req.Amount.Value >= minAcceptAmount)
                {
                    if (string.IsNullOrEmpty(alipay_account))
                        result = QuoteResult.ErrorDetail(req, "huodong account empty;");
                    else
                    {
                        var huodongAmount = req.Amount.Value;
                        //创建一个交易
                        var cmd = new CreateThirdPartyPaymentInboundTx(PayWay.Alipay, alipay_account, alipay_username.NullSafe().Trim(), huodongAmount, huodongAmount, "324活动" +
                            (string.IsNullOrEmpty(memo) ? "" : ":" + memo));

                        try
                        {
                            IoC.Resolve<ICommandBus>().Send(cmd);
                            var quoteInfo = new QuoteInfo
                            {
                                Type = "quote",
                                Destination = destination,
                                DestinationAddress = GATEWAY_ADDRESS,
                                Domain = GATEWAY_DOMAIN,
                                DestinationTag = Convert.ToInt32(DestinationTagFlg.AlipayRippleForm.ToString("D") + cmd.ResultDestinationTag.ToString()),
                                Amount = huodongAmount,
                                Send = new List<RippleAmount> { new RippleAmount(huodongAmount, GATEWAY_ADDRESS, req.Amount.Currency) },
                                InvoiceId = cmd.ResultInvoiceID,
                                Source = req.Address
                            };
                            result = QuoteResult.Success(req, quoteInfo);
                        }
                        catch (Exception ex) { Log.Error("在执行Ripple 活动 Quote时报错", ex); }
                    }
                }
                //如果用户要做扩展表单直转 to tenpay
                else if (destination.Equals("tenpay", StringComparison.OrdinalIgnoreCase) && req.Amount.Value <= maxAcceptAmount && req.Amount.Value >= minAcceptAmount)
                {
                    if (string.IsNullOrEmpty(tenpay_account))
                        result = QuoteResult.ErrorDetail(req, "tenpay account empty;");
                    else
                    {
                        var cmd = new CreateThirdPartyPaymentInboundTx(PayWay.Tenpay, tenpay_account, tenpay_username.NullSafe().Trim(), req.Amount.Value, sendAmount, memo);

                        try
                        {
                            IoC.Resolve<ICommandBus>().Send(cmd);

                            var quoteInfo = new QuoteInfo
                            {
                                Type = "quote",
                                Destination = destination,
                                DestinationAddress = GATEWAY_ADDRESS,
                                Domain = GATEWAY_DOMAIN,
                                DestinationTag = Convert.ToInt32(DestinationTagFlg.TenpayRippleForm.ToString("D") + cmd.ResultDestinationTag.ToString()),
                                Amount = req.Amount.Value,
                                Send = new List<RippleAmount> { new RippleAmount(sendAmount, GATEWAY_ADDRESS, req.Amount.Currency) },
                                InvoiceId = cmd.ResultInvoiceID,
                                Source = req.Address
                            };
                            result = QuoteResult.Success(req, quoteInfo);
                        }
                        catch (Exception ex) { Log.Error("在执行Ripple Tenpay Quote时报错", ex); }
                    }
                }
                //如果用户要做扩展表单直转 to bank
                else if (destination.Equals("bank", StringComparison.OrdinalIgnoreCase) && req.Amount.Value <= maxAcceptAmount && req.Amount.Value >= minAcceptAmount)
                {
                    PayWay tobank = default(PayWay);

                    if (string.IsNullOrEmpty(bank_username))
                        result = QuoteResult.ErrorDetail(req, "User name of bank account empty;");
                    else if (string.IsNullOrEmpty(bank_account))
                        result = QuoteResult.ErrorDetail(req, "Bank account empty;");
                    else if (Enum.TryParse<PayWay>(bank, out tobank) && !GetBankList().Contains(tobank))
                    {
                        result = QuoteResult.ErrorDetail(req, "not support this bank.");
                    }
                    else if (tobank == PayWay.OtherBank && string.IsNullOrEmpty(memo))
                    {
                        result = QuoteResult.ErrorDetail(req, "please tell us the bank name in [Comments]");
                    }
                    else
                    {
                        var cmd = new CreateThirdPartyPaymentInboundTx(tobank, bank_account, bank_username, req.Amount.Value, sendAmount, memo.NullSafe().Trim());

                        try
                        {
                            IoC.Resolve<ICommandBus>().Send(cmd);
                            var quoteInfo = new QuoteInfo
                            {
                                Type = "quote",
                                Destination = destination,
                                DestinationAddress = GATEWAY_ADDRESS,
                                Domain = GATEWAY_DOMAIN,
                                Amount = req.Amount.Value,
                                DestinationTag = Convert.ToInt32(DestinationTagFlg.BankRippleForm.ToString("D") + cmd.ResultDestinationTag.ToString()),
                                Send = new List<RippleAmount> { new RippleAmount(sendAmount, GATEWAY_ADDRESS, req.Amount.Currency) },
                                InvoiceId = cmd.ResultInvoiceID,
                                Source = req.Address
                            };
                            result = QuoteResult.Success(req, quoteInfo);
                        }
                        catch (Exception ex)
                        {
                            Log.Error("在执行Ripple Tenpay Quote时报错", ex);
                        }
                    }
                }
                else
                {
                    if (req.Amount.Value < minAcceptAmount)
                        result = QuoteResult.ErrorDetail(req, "amount don't less than  " + minAcceptAmount);
                    else if (req.Amount.Value > maxAcceptAmount)
                        result = QuoteResult.ErrorDetail(req, "amount don't greate than  " + maxAcceptAmount);
                    else
                        result = QuoteResult.ErrorDetail(req, "data invlid");

                }

            }
            return Json(result);
        }