public CommonApiResponse After3Ds(Submit3Ds submit3Ds, [FromServices] SessionManagerService sessionManager, [FromServices] OperationManagerService operationManager, [FromServices] PaymentSystemContext dbContext) { var merchant = (Merchant)HttpContext.Items["Merchant"]; var operation3ds = dbContext.Operation3ds.Include(x => x.Operation).FirstOrDefault(x => x.LocalMd == submit3Ds.MD); if (operation3ds == null || operation3ds.Operation.OperationStatus != OperationStatus.AdditionalAuth) { return new DebitResponse { Error = new ApiError(InnerError.CommonError) } } ; var session = dbContext.Session.Include(x => x.Operation).First(x => x.Id == operation3ds.Operation.SessionId); if (session.MerchantId != merchant.Id) { return new DebitResponse { Error = new ApiError(InnerError.CommonError) } } ; var possibility = operationManager.CheckPaymentPossibility(session, operation3ds.Operation); if (possibility != PaymentPossibility.PaymentAllowed) { return new DebitResponse { Error = new ApiError(InnerError.CommonError) } } ; var result = operationManager.Deposit(session, operation3ds, submit3Ds); return(new DebitResponse { Status = result.OperationStatus }); } } }
public ContentResult Pay(string Id, [FromServices] SessionManagerService sessionManager, [FromServices] OperationManagerService operationManager, [FromServices] FormManagerService formManager, [FromServices] PaymentSystemContext dbContext, [FromServices] FormDataCryptService cryptService) { try { var session = sessionManager.Get(Id); if (session.SessionType != SessionType.OneStep && session.SessionType != SessionType.TwoStep) { return(base.Content(formManager.GetErrorForm())); } var result = operationManager.CheckPaymentPossibility(session); var dictionary = new Dictionary <string, string>(); switch (result) { case PaymentPossibility.LimitExceeded: case PaymentPossibility.SessionExpired: return(base.Content(formManager.GetErrorForm())); case PaymentPossibility.AlreadyPaid: return(base.Content(formManager.GetSuccessForm())); default: var generationTime = DateTime.UtcNow; session.LastFormGenerationTime = generationTime; session.TryCount++; dbContext.SaveChanges(); var formSign = new FormSign { GenerationTime = generationTime, SessionId = session.Id }; dictionary.Add("sessionId", session.ExternalId); dictionary.Add("code", cryptService.Crypt(formSign)); return(base.Content(formManager.GetPaymentForm(dictionary))); } } catch (Exception) { return(base.Content(formManager.GetErrorForm())); } }
public ContentResult Pay([FromForm] SubmitPay submitPay, [FromServices] OperationManagerService operationManager, [FromServices] FormManagerService formManager, [FromServices] PaymentSystemContext dbContext, [FromServices] FormDataCryptService cryptService) { if (string.IsNullOrEmpty(submitPay.ExternalId) || string.IsNullOrEmpty(submitPay.Code)) { return(base.Content(formManager.GetErrorForm())); } var formCrypt = cryptService.DeCrypt(submitPay.Code); var session = dbContext.Session.Include(x => x.Merchant).FirstOrDefault(x => x.Id == formCrypt.SessionId); if (session == null || session.ExternalId != submitPay.ExternalId || session.ExpireTime != formCrypt.GenerationTime) { return(base.Content(formManager.GetErrorForm())); } var paymentData = new PaymentData(submitPay.Pan, submitPay.Year, submitPay.Month, submitPay.Cvv); var result = operationManager.Deposit(session.Merchant, session, paymentData); switch (result.OperationStatus) { case OperationStatus.AdditionalAuth: return(base.Content(formManager.Get3DsForm(result.AdditionalAuth))); case OperationStatus.Pending: return(base.Content(formManager.GetPendingForm())); case OperationStatus.Success: return(base.Content(formManager.GetSuccessForm())); case OperationStatus.Redirected: return(base.Content(formManager.GetRedirectForm(result.RedirectedUrl))); case OperationStatus.Error: return(session.CanTryToPayAnotherTime ? base.Content(formManager.GetRedirectForm("/form/v1/pay")) : base.Content(formManager.GetErrorForm())); default: return(base.Content(formManager.GetErrorForm())); } }
public ContentResult From3Ds([FromForm] Submit3Ds submit3Ds, [FromServices] OperationManagerService operationManager, [FromServices] FormManagerService formManager, [FromServices] PaymentSystemContext dbContext) { var operation3ds = dbContext.Operation3ds.Include(x => x.Operation).FirstOrDefault(x => x.LocalMd == submit3Ds.MD); if (operation3ds == null || operation3ds.Operation.OperationStatus != OperationStatus.AdditionalAuth) { return(base.Content(formManager.GetErrorForm())); } var session = dbContext.Session.Include(x => x.Operation).First(x => x.Id == operation3ds.Operation.SessionId); var possibility = operationManager.CheckPaymentPossibility(session, operation3ds.Operation); if (possibility != PaymentPossibility.PaymentAllowed) { return(base.Content(formManager.GetErrorForm())); } var result = operationManager.Deposit(session, operation3ds, submit3Ds); switch (result.OperationStatus) { case OperationStatus.Pending: return(base.Content(formManager.GetPendingForm())); case OperationStatus.Success: return(base.Content(formManager.GetSuccessForm())); case OperationStatus.Redirected: return(base.Content(formManager.GetRedirectForm(result.RedirectedUrl))); case OperationStatus.Error: return(session.CanTryToPayAnotherTime ? base.Content(formManager.GetRedirectForm("/form/v1/pay")) : base.Content(formManager.GetErrorForm())); default: return(base.Content(formManager.GetErrorForm())); } }
public CommonApiResponse Hold(DebitRequest request, [FromServices] SessionManagerService sessionManager, [FromServices] OperationManagerService operationManager) { var merchant = (Merchant)HttpContext.Items["Merchant"]; var session = sessionManager.Create(merchant, new SessionCreateRequest { Amount = request.Amount, Currency = request.Currency, OrderDescription = request.OrderDescription, OrderId = request.OrderId, SessionType = SessionType.TwoStep }); var paymentData = new PaymentData(request.Pan, request.Year, request.Month, request.Cvv); var result = operationManager.Hold(merchant, session, paymentData); return(new DebitResponse { Status = result.OperationStatus, Auth = result.AdditionalAuth }); }
public CommonApiResponse Hold(ChargeRequest request, [FromServices] SessionManagerService sessionManager, [FromServices] OperationManagerService operationManager) { var merchant = (Merchant)HttpContext.Items["Merchant"]; var session = sessionManager.GetByOrderId(merchant, request.OrderId); if (session == null) { return new CommonApiResponse { Error = new ApiError(InnerError.SessionNotFound) } } ; var result = operationManager.Charge(merchant, session, null, request.Amount); return(new DebitResponse { Status = result.OperationStatus, Auth = result.AdditionalAuth }); } }