Ejemplo n.º 1
0
        public IActionResponse <string> Verify(PaymentGateway gateway, Transaction model, object responseGateway = null)
        {
            if (model.OrderId != 0)
            {
                if (_transactionBusiness.GetTotalPayedPrice(model.OrderId) == 0)
                {
                    _orderBusiness.UpdateStatus(model.OrderId);
                }
                else
                {
                    _orderBusiness.UpdateStatus(model.OrderId, OrderStatus.DeliveryFiles);
                }
            }

            model.IsSuccess  = true;
            model.TrackingId = "123";
            model.Status     = "1";
            _transactionBusiness.Update(model);

            _observerManager.Value.Notify(ConcreteKey.Success_Payment, new ObserverMessage
            {
                SmsContent = string.Format(LocalMessage.Transaction_Add_Sms, (HttpContext.Current.User as ICurrentUserPrincipal).FullName, model.OrderId),
                BotContent = string.Format(LocalMessage.Transaction_Add_Bot, (HttpContext.Current.User as ICurrentUserPrincipal).FullName,
                                           model.OrderId, gateway.BankName.GetLocalizeDescription(),
                                           model.Price.ToString("0,0"),
                                           model.TrackingId),
                Key    = nameof(Transaction),
                UserId = (HttpContext.Current.User as ICurrentUserPrincipal).UserId,
            });
            return(new ActionResponse <string>
            {
                IsSuccessful = true,
                Message = "عملیات پرداخت با موفقیت انجام شد",
                Result = model.TrackingId.ToString()
            });
        }
Ejemplo n.º 2
0
        public IActionResponse <string> Verify(PaymentGateway gateway, Transaction model, object responseGateway = null)
        {
            try
            {
                var deserializeCheckingResponse = new PasargadCheckResponse();
                if (responseGateway == null)
                {
                    return new ActionResponse <string>
                           {
                               IsSuccessful = false,
                               Message      = "عملیات پرداخت از سمت درگاه تایید نشد، لطفا مجددا عملیات پرداخت را تکرار نمایید",
                           }
                }
                ;
                #region Checking
                using (HttpClient chkHttp = new HttpClient())
                {
                    var checkingSerilizedModel = JsonConvert.SerializeObject(new
                    {
                        InvoiceNumber          = model.TransactionId.ToString(),
                        InvoiceDate            = model.InsertDateSh,
                        TerminalCode           = int.Parse(gateway.Username),
                        MerchantCode           = int.Parse(gateway.Password),
                        TransactionReferenceID = (string)responseGateway
                    });

                    var checkingContent = new StringContent(checkingSerilizedModel, Encoding.UTF8, "application/json");
                    var chkResponse     = chkHttp.PostAsync("https://pep.shaparak.ir/Api/v1/Payment/CheckTransactionResult", checkingContent).Result;
                    //FileLoger.Info("deserializeCheckingResponse : " + Encoding.UTF8.GetString(chkResponse.Content.ReadAsByteArrayAsync().Result));
                    deserializeCheckingResponse = JsonConvert.DeserializeObject <PasargadCheckResponse>(Encoding.UTF8.GetString(chkResponse.Content.ReadAsByteArrayAsync().Result));
                }
                #endregion
                if (deserializeCheckingResponse.IsSuccess)
                {
                    var deserializeResponse = new PasargadVerifyResponse();
                    using (HttpClient verifyHttp = new HttpClient())
                    {
                        var verifyModel = new
                        {
                            InvoiceNumber = model.TransactionId.ToString(),
                            InvoiceDate   = model.InsertDateSh,
                            TerminalCode  = int.Parse(gateway.Username),
                            MerchantCode  = int.Parse(gateway.Password),
                            deserializeCheckingResponse.Amount,
                            TimeStamp = CreateTimeSpan(DateTime.Now)
                        };
                        var verifyContent  = new StringContent(JsonConvert.SerializeObject(verifyModel), Encoding.UTF8, "application/json");
                        var requestMessage = new HttpRequestMessage
                        {
                            RequestUri = new Uri("https://pep.shaparak.ir/Api/v1/Payment/VerifyPayment"),
                            Method     = HttpMethod.Post,
                            Content    = verifyContent
                        };
                        var data = JsonConvert.SerializeObject(verifyModel);
                        requestMessage.Headers.Add("Sign", GetSign(data));
                        verifyHttp.DefaultRequestHeaders.Accept.Add(new
                                                                    MediaTypeWithQualityHeaderValue("application/json"));
                        var response = verifyHttp.SendAsync(requestMessage).Result;
                        //FileLoger.Info("verifyResponse : " + Encoding.UTF8.GetString(response.Content.ReadAsByteArrayAsync().Result));
                        deserializeResponse = JsonConvert.DeserializeObject <PasargadVerifyResponse>(Encoding.UTF8.GetString(response.Content.ReadAsByteArrayAsync().Result));
                    }
                    if (deserializeResponse.IsSuccess)
                    {
                        model.IsSuccess  = true;
                        model.TrackingId = responseGateway.ToString();
                        model.Status     = "1";
                        if (model.OrderId != 0)
                        {
                            if (_transactionBusiness.GetTotalPayedPrice(model.OrderId) == 0)
                            {
                                _orderBusiness.UpdateStatus(model.OrderId);
                            }
                            else
                            {
                                _orderBusiness.UpdateStatus(model.OrderId, OrderStatus.DeliveryFiles);
                            }
                        }

                        _transactionBusiness.Update(model);

                        _observerManager.Value.Notify(ConcreteKey.Success_Payment, new ObserverMessage
                        {
                            SmsContent = string.Format(_smsTemplateBusiness.Value.GetText(MessagingType.Sms, ConcreteKey.Success_Payment), model.OrderId, model.Price.ToString("N0") + LocalMessage.MoneyCurrency),
                            //string.Format(LocalMessage.Transaction_Add_Sms, (HttpContext.Current.User as ICurrentUserPrincipal).FullName, model.OrderId),
                            BotContent = string.Format(_smsTemplateBusiness.Value.GetText(MessagingType.RoboTele, ConcreteKey.Success_Payment), (HttpContext.Current.User as ICurrentUserPrincipal).FullName,
                                                       model.OrderId, gateway.BankName.GetLocalizeDescription(),
                                                       model.Price.ToString("0,0"),
                                                       model.TrackingId),
                            //string.Format(LocalMessage.Transaction_Add_Bot, (HttpContext.Current.User as ICurrentUserPrincipal).FullName,
                            //                        model.OrderId, gateway.BankName.GetLocalizeDescription(),
                            //                        model.Price.ToString("0,0"),
                            //                        model.TrackingId),
                            Key    = nameof(Transaction),
                            UserId = (HttpContext.Current.User as ICurrentUserPrincipal).UserId,
                        });
                        return(new ActionResponse <string>
                        {
                            IsSuccessful = true,
                            Message = "عملیات پرداخت با موفقیت انجام شد",
                            Result = model.TrackingId.ToString()
                        });
                    }
                    //----------
                }
                model.IsSuccess = false;
                model.Status    = "-1";
                _transactionBusiness.Update(model);
                return(new ActionResponse <string>
                {
                    IsSuccessful = false,
                    Message = "عملیات پرداخت از سمت درگاه تایید نشد، لطفا مجددا عملیات پرداخت را تکرار نمایید",
                    Result = model.TrackingId.ToString()
                });
            }
            catch (Exception e)
            {
                FileLoger.Error(e);
                return(new ActionResponse <string>
                {
                    IsSuccessful = false,
                    Message = "عملیات پرداخت از سمت درگاه تایید نشد، لطفا مجددا عملیات پرداخت را تکرار نمایید",
                    Result = model.TrackingId.ToString()
                });
            }
        }