예제 #1
0
        public async Task <IActionResult> Notify([FromBody] PaymentResponse response)
        {
            var movement = await Context.Movements.SingleOrDefaultAsync(x => x.OperationId.Equals(response.OperationId));

            if (movement == null)
            {
                return(BadRequest($"Operation with id: {response.OperationId} does not exist"));
            }
            var transaction = movement.Transaction;

            if (response.IsBadRequest() || response.IsError())
            {
                transaction.Movements.ForEach(x => x.Rollback(ProviderApiFactory, Context).Wait());
            }
            else if (response.IsOk())
            {
                movement.Success();
                Context.Movements.Update(movement);
            }
            await Context.SaveChangesAsync();

            return(Ok());
        }