public BankController(IUnitOfWork <PayDelDbContext> dbContext, IUnitOfWork <FinDbContext> dbFinancial, IOnlinePayment onlinePayment) { _db = dbContext; _dbFinancial = dbFinancial; _onlinePayment = onlinePayment; model = new GateApiReturn <BankPayDto> { Result = new BankPayDto() }; }
public BankController(IUnitOfWork <Main_MadPayDbContext> dbContext, IUnitOfWork <Financial_MadPayDbContext> dbFinancial, IMapper mapper, ILogger <BankController> logger, IOnlinePayment onlinePayment) { _db = dbContext; _dbFinancial = dbFinancial; _mapper = mapper; _logger = logger; _onlinePayment = onlinePayment; model = new GateApiReturn <BankPayDto> { Result = new BankPayDto() }; }
public PayController(IUnitOfWork <PayDelDbContext> dbContext, IUnitOfWork <FinDbContext> dbFinancial, IMapper mapper, ILogger <PayController> logger, IUtilitiess utilities) { _db = dbContext; _dbFinancial = dbFinancial; _mapper = mapper; _logger = logger; _utilities = utilities; errorModel = new GateApiReturn <string> { Status = false, Result = null }; }
public RefundController(IUnitOfWork <Main_MadPayDbContext> dbContext, IUnitOfWork <Financial_MadPayDbContext> dbFinancial, IMapper mapper, ILogger <RefundController> logger, IUtilities utilities, IOnlinePayment onlinePayment) { _db = dbContext; _dbFinancial = dbFinancial; _mapper = mapper; _logger = logger; _utilities = utilities; _onlinePayment = onlinePayment; errorModel = new GateApiReturn <string> { Status = false, Result = null }; }
public VerifyController(IUnitOfWork <PayDelDbContext> dbContext, IUnitOfWork <FinDbContext> dbFinancial, IMapper mapper, ILogger <VerifyController> logger, IUtilitiess utilities, IOnlinePayment onlinePayment, IWalletService walletService) { _db = dbContext; _dbFinancial = dbFinancial; _mapper = mapper; _logger = logger; _utilities = utilities; _onlinePayment = onlinePayment; _walletService = walletService; errorModel = new GateApiReturn <string> { Status = false, Result = null }; }
public static void AddMadInitialize(this IServiceCollection services, int?httpsPort) { services.AddMvcCore(config => { config.ReturnHttpNotAcceptable = true; config.Filters.Add(typeof(RequireHttpsAttribute)); var policy = new AuthorizationPolicyBuilder() .RequireAuthenticatedUser() .Build(); config.Filters.Add(new AuthorizeFilter(policy)); }) .AddApiExplorer() .AddFormatterMappings() .AddDataAnnotations() .AddCors(opt => { opt.AddPolicy("CorsPolicy", builder => builder.WithOrigins("http://localhost:4200") .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials()); }) .AddNewtonsoftJson(opt => { opt.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; }); //Custom ModelState Error services.Configure <ApiBehaviorOptions>(opt => { opt.InvalidModelStateResponseFactory = context => { var strErrorList = new List <string>(); var msErrors = context.ModelState.Where(p => p.Value.Errors.Count > 0); foreach (var msError in msErrors) { foreach (var error in msError.Value.Errors) { strErrorList.Add(error.ErrorMessage); } } var errorModel = new GateApiReturn <string> { Status = false, Messages = strErrorList.ToArray(), Result = null }; return(new BadRequestObjectResult(errorModel)); }; }); // services.AddResponseCaching(); services.AddHsts(opt => { opt.MaxAge = TimeSpan.FromDays(180); opt.IncludeSubDomains = true; opt.Preload = true; }); services.AddHttpsRedirection(opt => { opt.RedirectStatusCode = StatusCodes.Status302Found; }); //services.AddResponseCompression(opt => opt.Providers.Add<GzipCompressionProvider>()); //services.AddRouting( opt => opt.LowercaseUrls = true); //services.AddApiVersioning(opt => //{ // opt.ApiVersionReader = new MediaTypeApiVersionReader(); // opt.AssumeDefaultVersionWhenUnspecified = true; // opt.ReportApiVersions = true; // opt.DefaultApiVersion = new ApiVersion(1,0); // opt.ApiVersionSelector = new CurrentImplementationApiVersionSelector(opt); //}); //services.AddImageResizer(); }
public static void AddPayInitialize(this IServiceCollection services) { services.AddMvc(opt => { //opt.EnableEndpointRouting = false; //opt.ReturnHttpNotAcceptable = true; //opt.SuppressAsyncSuffixInActionNames = false; //opt.SslPort = 4052; var policy = new AuthorizationPolicyBuilder() .RequireAuthenticatedUser().Build(); opt.Filters.Add(new AuthorizeFilter(policy)); //var jsonFormatter = opt.OutputFormatters.OfType<SystemTextJsonOutputFormatter>().Single(); //opt.OutputFormatters.Remove(jsonFormatter); //opt.OutputFormatters.Add(new IonOutputFormatter(jsonFormatter)); //opt.OutputFormatters.Add(new XmlDataContractSerializerOutputFormatter()); //opt.InputFormatters.Add(new XmlSerializerInputFormatter(opt)); }); //services.AddMvcCore(config => //{ // config.ReturnHttpNotAcceptable = true; // config.Filters.Add(typeof(RequireHttpsAttribute)); // var policy = new AuthorizationPolicyBuilder() // .RequireAuthenticatedUser() // .Build(); // config.Filters.Add(new AuthorizeFilter(policy)); //}) //.AddApiExplorer() //.AddFormatterMappings() //.AddDataAnnotations() //.AddCors(opt => //{ // opt.AddPolicy("CorsPolicy", builder => // builder.WithOrigins("http://localhost:4200", "https://localhost:44318") // .AllowAnyMethod() // .AllowAnyHeader() // .AllowCredentials()); //}); //services.AddHsts(opt => //{ // opt.MaxAge = TimeSpan.FromDays(180); // opt.IncludeSubDomains = true; // opt.Preload = true; //}); services.AddCors(opt => opt.AddPolicy("CorsPolicy", builder => builder.WithOrigins("http://localhost:4200").AllowAnyMethod().AllowAnyHeader().AllowCredentials())); //Custom ModelState Error services.Configure <ApiBehaviorOptions>(opt => { opt.InvalidModelStateResponseFactory = context => { var strErrorList = new List <string>(); var msErrors = context.ModelState.Where(p => p.Value.Errors.Count > 0); foreach (var msError in msErrors) { foreach (var error in msError.Value.Errors) { strErrorList.Add(error.ErrorMessage); } } var errorModel = new GateApiReturn <string> { Status = false, Messages = strErrorList.ToArray(), Result = null }; return(new BadRequestObjectResult(errorModel)); }; }); // services.AddResponseCaching(); services.AddResponseCompression(opt => opt.Providers.Add <GzipCompressionProvider>()); services.AddRouting(opt => opt.LowercaseUrls = true); }
public async Task <IActionResult> PaySend(PayRequestDto payRequestDto) { var model = new GateApiReturn <PayResponseDto> { Status = true, Result = new PayResponseDto() }; //Error var gateFromRepo = (await _db._GateRepository.GetAllAsync(p => p.Id == payRequestDto.Api, null, "Wallet")).SingleOrDefault(); if (gateFromRepo == null) { errorModel.Messages.Clear(); errorModel.Messages = new string[] { "Api درگاه معتبر نمیباشد" }; return(BadRequest(errorModel)); } //var userDocuments = await _db.DocumentRepository // .GetManyAsync(p => p.Approve == 1 && p.UserId == gateFromRepo.Wallet.UserId, null, ""); //if (!userDocuments.Any()) //{ // errorModel.Messages.Clear(); // errorModel.Messages = new string[] { "مدارک کاربر صاحب درگاه تکمیل نمیباشد" }; // return BadRequest(errorModel); //} if (!gateFromRepo.IsActive) { errorModel.Messages.Clear(); errorModel.Messages = new string[] { "این درگاه غیر فعال میباشد . درصورت نیاز با پشتیبانی در تماس باید" }; return(BadRequest(errorModel)); } if (gateFromRepo.IsIp) { var currentIp = HttpContext.Connection.RemoteIpAddress.ToString(); //::1 var gateWebsiteIp = await _utilities.GetDomainIpAsync(gateFromRepo.WebsiteUrl); if (currentIp != gateWebsiteIp) { errorModel.Messages.Clear(); errorModel.Messages = new string[] { "آی پی وبسایت درخواست دهنده پرداخت معبتر نمیباشد" }; return(BadRequest(errorModel)); } } //Success var factorToCreate = new Factor() { UserId = gateFromRepo.Wallet.UserId, GateId = gateFromRepo.Id, EnterMoneyWalletId = gateFromRepo.WalletId, UserName = payRequestDto.UserName, Mobile = payRequestDto.Mobile, Email = payRequestDto.Email, FactorNumber = payRequestDto.FactorNumber, Description = payRequestDto.Description, ValidCardNumber = payRequestDto.ValidCardNumber, RedirectUrl = payRequestDto.RedirectUrl, Status = false, Kind = (int)FactorTypeEnums.Factor, Bank = (int)BankEnums.ZarinPal, GiftCode = "", IsGifted = false, Price = payRequestDto.Amount, EndPrice = payRequestDto.Amount, RefBank = "پرداختی انجام نشده است", IsAlreadyVerified = false, GatewayName = "non", Message = "خطای نامشخص" }; await _dbFinancial.FactorRepository.InsertAsync(factorToCreate); if (await _dbFinancial.SaveAcync() > 0) { model.Messages.Clear(); model.Messages = new string[] { "بدون خطا" }; model.Result.Token = factorToCreate.Id; model.Result.RedirectUrl = $"{Request.Scheme ?? ""}://{Request.Host.Value.Replace("api.", "pay.") ?? ""}{Request.PathBase.Value ?? ""}" + "/bank/pay/" + factorToCreate.Id; return(Ok(model)); } else { errorModel.Messages.Clear(); errorModel.Messages = new string[] { "خطا در ثبت فاکتور" }; return(BadRequest(errorModel)); } }
public async Task <IActionResult> VerifySend(VerifyRequestDto verifyRequestDto) { var model = new GateApiReturn <VerifyResponseDto> { Status = true }; //Error var factorFromRepo = await _dbFinancial.FactorRepository.GetByIdAsync(verifyRequestDto.Token); if (factorFromRepo == null) { errorModel.Messages.Clear(); errorModel.Messages = new string[] { "تراکنشی با این مشخصات یافت نشد" }; return(BadRequest(errorModel)); } if (factorFromRepo.DateModified.AddMinutes(20) < DateTime.Now) { errorModel.Messages.Clear(); errorModel.Messages = new string[] { "زمان تایید تراکنش شما گذشته است" }; return(BadRequest(errorModel)); } if (factorFromRepo.IsAlreadyVerified) { errorModel.Messages.Clear(); errorModel.Messages = new string[] { "این تراکنش قبلا بررسی شده است" }; return(BadRequest(errorModel)); } var gateFromRepo = (await _db.GateRepository.GetManyAsync(p => p.Id == verifyRequestDto.Api, null, "Wallet")).SingleOrDefault(); if (gateFromRepo == null) { errorModel.Messages.Clear(); errorModel.Messages = new string[] { "Api درگاه معتبر نمیباشد" }; return(BadRequest(errorModel)); } var userDocuments = await _db.DocumentRepository .GetManyAsync(p => p.Approve == 1 && p.UserId == gateFromRepo.Wallet.UserId, null, ""); if (!userDocuments.Any()) { errorModel.Messages.Clear(); errorModel.Messages = new string[] { "مدارک کاربر صاحب درگاه تکمیل نمیباشد" }; return(BadRequest(errorModel)); } if (!gateFromRepo.IsActive) { errorModel.Messages.Clear(); errorModel.Messages = new string[] { "این درگاه غیر فعال میباشد . درصورت نیاز با پشتیبانی در تماس باید" }; return(BadRequest(errorModel)); } if (gateFromRepo.IsIp) { var currentIp = HttpContext.Connection.RemoteIpAddress.ToString(); //::1 var gateWebsiteIp = await _utilities.GetDomainIpAsync(gateFromRepo.WebsiteUrl); if (currentIp != gateWebsiteIp) { errorModel.Messages.Clear(); errorModel.Messages = new string[] { "آی پی وبسایت درخواست دهنده پرداخت معبتر نمیباشد" }; return(BadRequest(errorModel)); } } //Verify var trackingNumber = Convert.ToInt64(factorFromRepo.RefBank); var verifyResult = await _onlinePayment.VerifyAsync(trackingNumber); if (verifyResult.IsSucceed) { factorFromRepo.Status = true; factorFromRepo.IsAlreadyVerified = true; factorFromRepo.DateModified = DateTime.Now; factorFromRepo.Message = "تراکنش با موفقیت انجام شد"; _dbFinancial.FactorRepository.Update(factorFromRepo); await _dbFinancial.SaveAsync(); await _walletService .IncreaseInventoryAsync(factorFromRepo.EndPrice, factorFromRepo.EnterMoneyWalletId, true); model.Messages.Clear(); model.Messages = new string[] { "تراکنش با موفقیت انجام شد" }; model.Result = new VerifyResponseDto { Amount = factorFromRepo.EndPrice, FactorNumber = factorFromRepo.FactorNumber, RefBank = "MPC-" + factorFromRepo.RefBank, Mobile = factorFromRepo.Mobile, Email = factorFromRepo.Email, Description = factorFromRepo.Description, CardNumber = factorFromRepo.ValidCardNumber }; return(Ok(model)); } else { factorFromRepo.IsAlreadyVerified = true; factorFromRepo.DateModified = DateTime.Now; factorFromRepo.Message = verifyResult.Message; _dbFinancial.FactorRepository.Update(factorFromRepo); await _dbFinancial.SaveAsync(); errorModel.Messages.Clear(); errorModel.Messages = new string[] { verifyResult.Message }; return(BadRequest(errorModel)); } }