Exemplo n.º 1
0
        public async Task <object> Process(PaymentModel.Payment payment)
        {
            if (_paypalSettings == null)
            {
                throw new NullReferenceException("Paypal settings cannot be null.");
            }

            var env            = new SandboxEnvironment(_paypalSettings.ClientId, _paypalSettings.ClientSecret);
            var client         = new PayPalHttpClient(env);
            var paymentDetails = new PaymentMapper(payment).GetPaymentDetails();
            var request        = new PaymentCreateRequest();

            request.RequestBody(paymentDetails);

            try
            {
                var response = await client.Execute(request);

                var result = response.Result <PayPal.v1.Payments.Payment>();
                var json   = JsonConvert.SerializeObject(result);
                return(result);
            }
            catch (Exception ex)
            {
                return(ex);
            }
        }
Exemplo n.º 2
0
        public void Init()
        {
            _apiPayment = new ApiModel.Payment
            {
                CardDetails = new ApiModel.CardDetails
                {
                    CardFirstname   = "Firstname",
                    CardLastname    = "Lastname",
                    CardNumber      = "1234567894567896",
                    Cvv             = "123",
                    ExpiryDateMonth = 10,
                    ExpiryDateYear  = 2025,
                    Type            = "mastercard"
                },
                Created   = DateTime.Now,
                Details   = "Payment Test",
                PaymentId = Guid.NewGuid(),
                Price     = new ApiModel.Price
                {
                    Amount   = 100,
                    Currency = "EUR"
                },
                ProductId   = "123ABC_TEST1",
                ProductName = "Product Test",
                UserId      = Guid.NewGuid()
            };

            _filter = new ApiModel.PaymentsFilter
            {
                UserId    = _apiPayment.UserId.ToString(),
                StartDate = DateTime.Now.AddDays(-1),
                EndDate   = DateTime.Now.AddDays(1)
            };

            _repoPayment = new PaymentApiToRepo().MapToDestination(_apiPayment);
            var payments = new List <RepoModel.Payment> {
                _repoPayment
            };

            var logFactory = LoggerFactory.Create(builder => builder.AddConsole());

            _log = logFactory.CreateLogger <AllPaymentsActionProvider>();

            //Mock
            _mockRepo = new Mock <IPaymentRepository>();
            _mockRepo.Setup(r => r.GetMongoQueryable()).Returns(payments.AsQueryable());
            _mockValManager = new Mock <IValidatorManager <AllPaymentsValidator, CoreModel.PaymentsFilter> >();
            _mockValManager.Setup(m => m.GetValidatorsResult(It.IsAny <CoreModel.PaymentsFilter>()))
            .Returns(Task.FromResult(It.IsAny <IEnumerable <Func <Result> > >()));
            _mockVaService = new Mock <IValidationService>();
            _mockVaService.Setup(v => v.ProcessValidation(_mockValManager.Object, It.IsAny <CoreModel.PaymentsFilter>()))
            .Returns(Task.FromResult((object)payments));
        }
Exemplo n.º 3
0
 public PaymentMapper(payment_gateway_repository.Model.Payment payment)
 {
     _payment = payment;
 }
Exemplo n.º 4
0
        public void Init()
        {
            _userId     = new Guid("3fa85f64-5717-4562-b3fc-2c963f66afa6");
            _apiPayment = new ApiModel.Payment
            {
                CardDetails = new ApiModel.CardDetails
                {
                    CardFirstname   = "Firstname",
                    CardLastname    = "Lastname",
                    CardNumber      = "1234567894567896",
                    Cvv             = "123",
                    ExpiryDateMonth = 10,
                    ExpiryDateYear  = 2025,
                    Type            = "mastercard"
                },
                Created   = DateTime.Now,
                Details   = "Payment Test",
                PaymentId = Guid.NewGuid(),
                Price     = new ApiModel.Price
                {
                    Amount   = 100,
                    Currency = "EUR"
                },
                ProductId   = "123ABC_TEST1",
                ProductName = "Product Test",
                UserId      = _userId
            };
            _payments = new List <ApiModel.Payment> {
                _apiPayment
            };
            _repoPayment = new PaymentApiToRepo().MapToDestination(_apiPayment);

            var logFactory = LoggerFactory.Create(builder => builder.AddConsole());

            _log = logFactory.CreateLogger <PaymentController>();

            //Mock
            _mockActService = new Mock <IActionService>();
            _mockActService.Setup(s => s.ProcessAction <ProcessPaymentAction>(It.IsAny <ApiModel.Payment>()))
            .Returns((ApiModel.Payment p) =>
            {
                if (p == null)
                {
                    return(Task.FromResult <object>(null));
                }

                //Simulates an exception
                if (p.ProductName == "Exception")
                {
                    throw new NullReferenceException("Test Throw Null Exception from ProcessPaymentAction. Parameter cannot be null.");
                }

                //Simulates an error
                if (p.CardDetails == null)
                {
                    return(Task.FromResult <object>(new Result
                    {
                        ErrorCode = ErrorCode.PaymentFailed,
                        StatusCode = StatusCode.Failed,
                        StatusDetail = "Test Invalid Card Details"
                    }));
                }

                return(Task.FromResult <object>(_repoPayment));
            });
        }
Exemplo n.º 5
0
        public void Init()
        {
            _apiUser = new ApiModel.User
            {
                FirstName = "Firstname",
                LastName  = "Lastname",
                UserId    = Guid.NewGuid(),
                UserLogin = new ApiModel.UserLogin
                {
                    Username = "******",
                    Password = "******"
                }
            };
            new UserApiToRepo().MapToDestination(_apiUser);

            _apiPayment = new ApiModel.Payment
            {
                CardDetails = new ApiModel.CardDetails
                {
                    CardFirstname   = "Firstname",
                    CardLastname    = "Lastname",
                    CardNumber      = "1234567894567896",
                    Cvv             = "123",
                    ExpiryDateMonth = 10,
                    ExpiryDateYear  = 2025,
                    Type            = "mastercard"
                },
                Created   = DateTime.Now,
                Details   = "Payment Test",
                PaymentId = Guid.NewGuid(),
                Price     = new ApiModel.Price
                {
                    Amount   = 100,
                    Currency = "EUR"
                },
                ProductId   = "123ABC_TEST1",
                ProductName = "Product Test",
                UserId      = Guid.NewGuid()
            };
            _repoPayment = new PaymentApiToRepo().MapToDestination(_apiPayment);

            var logFactory = LoggerFactory.Create(builder => builder.AddConsole());

            _log = logFactory.CreateLogger <ProcessPaymentAction>();

            //Mock
            _mockRepoTrue = new Mock <IPaymentRepository>();
            _mockRepoTrue.Setup(r => r.AddItemAsync(It.IsAny <RepoModel.Payment>())).Returns(Task.FromResult(true));
            _mockRepoFalse = new Mock <IPaymentRepository>();
            _mockRepoFalse.Setup(r => r.AddItemAsync(It.IsAny <RepoModel.Payment>())).Returns(Task.FromResult(false));
            _mockValManager = new Mock <IValidatorManager <PaymentValidator, RepoModel.Payment> >();
            _mockValManager.Setup(m => m.GetValidatorsResult(It.IsAny <RepoModel.Payment>()))
            .Returns(Task.FromResult(It.IsAny <IEnumerable <Func <Result> > >()));
            _mockValService = new Mock <IValidationService>();
            _mockValService.Setup(v => v.ProcessValidation(_mockValManager.Object, It.IsAny <RepoModel.Payment>()))
            .Returns(Task.FromResult((object)_repoPayment));
            _mockBankProcessorObj = new Mock <IBankProcessor>();
            _mockBankProcessorObj.Setup(b => b.Process(It.IsAny <RepoModel.Payment>()))
            .Returns(Task.FromResult((object)_repoPayment));
            _mockBankProcessorEx = new Mock <IBankProcessor>();
            _mockBankProcessorEx.Setup(b => b.Process(It.IsAny <RepoModel.Payment>()))
            .Returns(Task.FromResult((object)new Exception("Test return exception.")));
        }
Exemplo n.º 6
0
        public void Init()
        {
            _filter = new ApiModel.PaymentsFilter
            {
                UserId = "97190759-1638-42fa-abb7-1ac97111978d"
            };

            _userId      = new Guid("3fa85f64-5717-4562-b3fc-2c963f66afa6");
            _repoPayment = new RepoModel.Payment
            {
                CardDetails = new RepoModel.CardDetails
                {
                    CardFirstname   = "Firstname",
                    CardLastname    = "Lastname",
                    CardNumber      = "1234567894567896",
                    Cvv             = "123",
                    ExpiryDateMonth = 10,
                    ExpiryDateYear  = 2025,
                    Type            = "mastercard"
                },
                Created   = DateTime.Now,
                Details   = "Payment Test",
                PaymentId = Guid.NewGuid(),
                Price     = new RepoModel.Price
                {
                    Amount   = 100,
                    Currency = "EUR"
                },
                ProductId   = "123ABC_TEST1",
                ProductName = "Product Test",
                UserId      = _userId
            };
            _apiPayment   = new PaymentRepoToApi().MapToDestination(_repoPayment);
            _repoPayments = new List <RepoModel.Payment> {
                _repoPayment
            };
            _apiPayments = new PaymentsRepoToApi().MapToDestination(_repoPayments).ToList();

            var logFactory = LoggerFactory.Create(builder => builder.AddConsole());

            _log = logFactory.CreateLogger <PaymentController>();

            //Mock
            _mockActService = new Mock <IActionService>();
            _mockActService.Setup(s => s.ProcessAction <AllPaymentsActionProvider>(It.IsAny <ApiModel.PaymentsFilter>()))
            .Returns((ApiModel.PaymentsFilter filter) =>
            {
                if (filter == null)
                {
                    return(Task.FromResult <object>(null));
                }

                //Simulates an exception
                if (filter.ProductName == "Exception")
                {
                    throw new NullReferenceException("Test Throw Null Exception from AllPaymentsActionProvider. Parameter cannot be null.");
                }

                //Simulates an invalid user
                if (filter.UserId.Length < 36 || filter.UserId.Length > 36)
                {
                    return(Task.FromResult <object>(new Result
                    {
                        ErrorCode = ErrorCode.NoAuthorized,
                        StatusCode = StatusCode.Failed,
                        StatusDetail = "Test Invalid User ID"
                    }));
                }

                return(Task.FromResult <object>(_repoPayments));
            });
        }