コード例 #1
0
        /// <summary>
        /// 网关支付
        /// </summary>
        /// <param name="tuple">
        /// Guid为fiiipay用户的id,long为POSMerchantBindRecords的主键
        /// </param>
        public void ShopPaymentRefund(Guid id)
        {
            var record         = new GatewayRefundOrderDAC().GetById(id);
            var order          = new GatewayOrderDAC().GetByOrderId(record.OrderId);
            var cryptoCurrency = new CryptocurrencyDAC().GetById(order.CryptoId);
            var regId          = RedisHelper.StringGet($"FiiiPay:Notice:UserId:{order.UserAccountId}");
            var lang           = RedisHelper.StringGet(REDIS_LANGUAGE_DBINDEX, $"FiiiPay:Language:{order.UserAccountId}") ?? "en";

            string titleKey    = "GatewayOrderPaymentRefundTitle";
            string subTitleKey = "GatewayOrderPaymentRefundSubTitle";

            if (!(_resourcePropertyNames.Contains(titleKey) && _resourcePropertyNames.Contains(subTitleKey)))
            {
                throw new Exception("没有找到资源");
            }
            var title    = ResourceHelper.FiiiPay.GetFormatResource(titleKey, new CultureInfo(lang), cryptoCurrency.Code);
            var subTitle = ResourceHelper.FiiiPay.GetResource(subTitleKey, new CultureInfo(lang));

            string noticeId = "";

            MessagesComponent.AddMessage(order.UserAccountId.Value, UserType.User, record.Id.ToString(), FiiiPayPushType.TYPE_GATEWAY_ORDER_PAYMENT_REFUND, titleKey, subTitleKey, cryptoCurrency.Code, title, subTitle, out noticeId);

            RegPush(FiiiPayPushType.TYPE_GATEWAY_ORDER_PAYMENT_REFUND, new List <string> {
                regId
            }, record.Id, title, subTitle, noticeId);

            LogHelper.Info($"--------{lang}------{title}----------{subTitle}");
        }
コード例 #2
0
        /// <summary>
        /// 支付网关退款成功
        /// </summary>
        /// <param name="id"></param>
        public MessageGatewayPaymentOM MessagePaymentRefund(UserAccount account, Guid id)
        {
            var refundOrder         = new GatewayRefundOrderDAC().GetById(id);
            var order               = new GatewayOrderDAC().GetByOrderId(refundOrder.OrderId);
            var cryptoCurrency      = new CryptocurrencyDAC().GetById(order.CryptoId);
            var currentExchangeRate = GetExchangeRate(account.CountryId, order.FiatCurrency, cryptoCurrency);

            return(new MessageGatewayPaymentOM()
            {
                TradeStatus = 1,
                CryptoCode = cryptoCurrency.Code,
                CurrentExchangeRate = currentExchangeRate,
                FiatCode = order.FiatCurrency,
                IncreaseRate = (currentExchangeRate - order.ExchangeRate) / order.ExchangeRate,
                Markup = order.Markup,
                MerchantName = order.MerchantName,
                MerchantOrderNo = order.OrderNo,
                OrderNo = order.TradeNo,
                PaymentCryptoAmount = order.ActualCryptoAmount,
                PaymentFiatAmount = order.ActualFiatAmount ?? 0m,
                TradeExchangeRate = order.ExchangeRate,
                TradeTime = order.Timestamp.ToUnixTime().ToString(),
                RefundTime = refundOrder.Timestamp.ToUnixTime().ToString()
            });
        }
コード例 #3
0
        /// <summary>
        /// 支付网关发起退款
        /// </summary>
        /// <param name="tradeId"></param>
        public void GatewayRefund(string tradeId)
        {
            //获取订单详情
            var orderDetail = new GatewayOrderDAC().GetByTradeNo(tradeId);

            if (orderDetail == null)
            {
                throw new Exception("Have no record of this order:tradeId=" + tradeId);
            }
            if (orderDetail.Status != GatewayOrderStatus.Completed)
            {
                throw new Exception($"The status of this order {tradeId} is not completed");
            }

            var uwComponent = new UserWalletComponent();
            var userWallet  = uwComponent.GetUserWallet(orderDetail.UserAccountId.Value, orderDetail.CryptoId);
            var goDAC       = new GatewayOrderDAC();
            var rgoDAC      = new GatewayRefundOrderDAC();
            var uwDAC       = new UserWalletDAC();
            var uwsDAC      = new UserWalletStatementDAC();

            using (var scope = new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Required, new TimeSpan(0, 0, 1, 30)))
            {
                orderDetail.Status = GatewayOrderStatus.Refunded;
                goDAC.Update(orderDetail);

                uwDAC.Increase(userWallet.Id, orderDetail.ActualCryptoAmount);
                uwsDAC.Insert(new UserWalletStatement
                {
                    WalletId      = userWallet.Id,
                    Action        = UserWalletStatementAction.TansferIn,
                    Amount        = orderDetail.ActualCryptoAmount,
                    Balance       = userWallet.Balance + orderDetail.ActualCryptoAmount,
                    FrozenAmount  = 0,
                    FrozenBalance = userWallet.FrozenBalance,
                    Timestamp     = DateTime.UtcNow
                });
                rgoDAC.Insert(new GatewayRefundOrder
                {
                    Id        = Guid.NewGuid(),
                    OrderId   = orderDetail.Id,
                    Timestamp = DateTime.UtcNow,
                    Status    = RefundStatus.Completed
                });

                scope.Complete();
            }
        }
コード例 #4
0
ファイル: PaymentProcess.cs プロジェクト: BryceStory/BS.FPApp
        public void Refund(string message)
        {
            var orderModel = JsonConvert.DeserializeObject <MallPaymentOrder>(message);

            var userWalletDac      = new UserWalletDAC();
            var walletStatementDac = new UserWalletStatementDAC();
            var gatewayOrderDac    = new GatewayOrderDAC();
            var mallDac            = new MallPaymentOrderDAC();
            var refundDac          = new GatewayRefundOrderDAC();

            var gatewayOrder = gatewayOrderDac.GetByTradeNo(orderModel.TradeNo);

            if (gatewayOrder.Status == GatewayOrderStatus.Pending)
            {
                _log.Error("Order message " + message + " not payment.");
                return;
            }
            if (gatewayOrder.Status == GatewayOrderStatus.Refunded)
            {
                _log.Info("Order message " + message + " has refund.");
                return;
            }

            var fiiiWallet = userWalletDac.GetByCryptoCode(orderModel.UserAccountId, "FIII");

            try
            {
                var id            = Guid.NewGuid();
                var refundTradeNo = NumberGenerator.GenerateUnixOrderNo();
                using (var scope = new TransactionScope())
                {
                    mallDac.UpdateStatus(orderModel.Id, (byte)OrderStatus.Refunded);
                    mallDac.UpdateRefundTradeNo(orderModel.Id, refundTradeNo);

                    gatewayOrderDac.UpdateStatus(gatewayOrder.Id, (byte)OrderStatus.Refunded);

                    userWalletDac.Increase(fiiiWallet.Id, gatewayOrder.CryptoAmount);
                    walletStatementDac.Insert(new UserWalletStatement
                    {
                        WalletId      = fiiiWallet.Id,
                        Action        = UserWalletStatementAction.Refund,
                        Amount        = orderModel.CryptoAmount,
                        Balance       = fiiiWallet.Balance + gatewayOrder.CryptoAmount,
                        FrozenAmount  = 0,
                        FrozenBalance = fiiiWallet.FrozenBalance,
                        Timestamp     = DateTime.UtcNow
                    });

                    refundDac.Insert(new GatewayRefundOrder
                    {
                        Id            = id,
                        OrderId       = gatewayOrder.Id,
                        Remark        = "",
                        Status        = RefundStatus.Completed,
                        Timestamp     = DateTime.UtcNow,
                        RefundTradeNo = refundTradeNo
                    });

                    scope.Complete();
                }

                RabbitMQSender.SendMessage("ShopPaymentRefund", id);
                SendNotificationMessage(TradeType.Refund, orderModel.Id, orderModel.OrderId, refundTradeNo, "success");
            }
            catch (Exception exception)
            {
                _log.Error("Refund error, exception : " + exception.Message);

                //SendNotificationMessage(TradeType.Refund, orderModel.Id, orderModel.OrderId, string.Empty, "error");
            }
        }