public void FindPaymentIsSuccessful()
        {
            var paymentResponse = new CardPaymentService(serviceConfiguration).CreatePayment(new CreatePaymentRequest
            {
                amount      = 150000,
                description = "Waste Permit",
                return_url  = "https://ag-ea-lp-dev-waste.crm4.dynamics.com/main.aspx?etc=10013&extraqs=formid%3df5880608-0176-460b-97dd-8d840c9d8bd4&id=%7b669F4908-0826-E811-A951-000D3AB3984F%7d&pagetype=entityrecord",
                reference   = "PERMIT 123"
            });

            var response = new CardPaymentService(serviceConfiguration).FindPayment(new FindPaymentRequest
            {
                PaymentId = paymentResponse.payment_id
            });

            pid = response.payment_id;
            Assert.IsNotNull(response);

            response = new CardPaymentService(serviceConfiguration).FindPayment(new FindPaymentRequest
            {
                PaymentId = paymentResponse.payment_id
            });

            Assert.IsNotNull(response);
        }
Example #2
0
            private static async Task <ApiResult <ApiRefundResponse> > BecauseAsync()
            {
                ApiResult = await CardPaymentService.CreatePaymentAsync(CardPaymentRequest);

                CaptureResult = await CardPaymentService.CapturePaymentAsync(ApiResult.Value.Payment.ID.Value, CapturedAmount);

                return(await RefundService.CreateRefundAsync(ApiResult.Value.Payment.ID.Value, RefundRequest));
            }
Example #3
0
 public CardPaymentServiceTests()
 {
     _paymentResultComparer = new PaymentResultComparer();
     _foobarBankClient      = Substitute.For <IFoobarBankClient>();
     _paymentsRepository    = Substitute.For <IPaymentsRepository>();
     _logger             = Substitute.For <ILogger <CardPaymentService> >();
     _cardPaymentService = new CardPaymentService(_logger, _foobarBankClient, _paymentsRepository);
 }
            private static async Task <ApiResult <ApiCardPaymentResponse> > BecauseAsync()
            {
                var initialPaymentResponse = await CardPaymentService.CreatePaymentAsync(CardPaymentInitialRequest);

                CardPaymentRequest.Payment.CreditCardToken.Value =
                    initialPaymentResponse.Value.Payment.CreditCardToken.Value;
                return(await CardPaymentService.CreatePaymentAsync(CardPaymentRequest));
            }
        public void FindPaymentSuccessful()
        {
            var response = new CardPaymentService(serviceConfiguration).FindPayment(new FindPaymentRequest
            {
                PaymentId = pid
            });

            Assert.IsNotNull(response);
        }
Example #6
0
        public bool Pay(double amount, string accountName)
        {
            if (!CardPaymentService.Pay(amount, accountName, out var amountDue))
            {
                Loggingservice.Add($"Not enough balance, missing: {amountDue}");
                return(false);
            }

            return(true);
        }
        public void CardPayment_InValidPayments(Card card, BankAccount bankAccount, TransactionStatus resulTransactionStatus)
        {
            var fakeCardRepository        = new FakeCardRepository();
            var fakeBankAccountRepository = new FakeBankAccountRepository();
            var inMemPaymentRepository    = new InMemoryPaymentRepository();
            var service = new CardPaymentService(fakeCardRepository, fakeBankAccountRepository, inMemPaymentRepository);
            CardPaymentResponse response = service.DoPayment(new CardPaymentRequest(requestId1, card, bankAccount));

            Assert.Equal(resulTransactionStatus, response.TransactionStatus);
        }
        public async Task ValidCardPaymentReturnsSuccess()
        {
            var transactionServiceMock = new Mock <ITransactionService>();
            var bankServiceMock        = new Mock <IBankService>();
            var modelConverter         = new ModelConverter(new MaskingService());
            var loggerMock             = new Mock <ILogger <CardPaymentService> >();

            var cardPaymentService = new CardPaymentService(transactionServiceMock.Object, bankServiceMock.Object, modelConverter, loggerMock.Object);
            var cardPaymentRequest = ModelDataHelper.GetValidCardPaymentRequest();
            var merchant           = ModelDataHelper.GetTestMerchant();

            var cardPaymentContext = modelConverter.CreateCardPaymentContext(cardPaymentRequest, merchant);

            var transaction = new Transaction()
            {
                TransactionId     = Guid.NewGuid().ToString(),
                CardDetail        = cardPaymentContext.CardDetail,
                Amount            = cardPaymentContext.Amount,
                MerchantId        = merchant.Id,
                MerchantReference = cardPaymentContext.MerchantReference,
                RequestedOn       = DateTime.UtcNow
            };

            transactionServiceMock.Setup(x => x.InitialiseTransactionAsync(It.IsAny <CardPaymentContext>())).ReturnsAsync(transaction);

            var bankResponse = new BankResponse()
            {
                Id      = "BNK_111",
                Status  = BankResponseStatus.Success,
                Details = "Authorised"
            };

            bankServiceMock.Setup(x => x.ExecuteAsync(It.IsAny <BankCardRequest>())).ReturnsAsync(bankResponse);

            var updatedTransaction = transaction;

            updatedTransaction.BankDetails   = bankResponse.Details;
            updatedTransaction.BankReference = bankResponse.Id;
            updatedTransaction.Status        = TransactionStatus.Fulfilled;
            updatedTransaction.ProcessedOn   = DateTime.UtcNow;

            transactionServiceMock.Setup(x => x.UpdateTransactionAsync(transaction.TransactionId, bankResponse)).ReturnsAsync(updatedTransaction);

            var response = await cardPaymentService.ProcessAsync(cardPaymentRequest, merchant);

            response.Should().NotBeNull();
            response.Amount.Should().Be(cardPaymentRequest.Amount);
            response.Currency.Should().Be(cardPaymentRequest.CurrencyCode);
            response.Success.Should().BeTrue();
            response.Status.Should().Be("fulfilled");
            response.BankReference.Should().Be(bankResponse.Id);
        }
        public void CreatePaymentIsSuccessful()
        {
            CardPaymentService service = new CardPaymentService(serviceConfiguration);

            var response = service.CreatePayment(new CreatePaymentRequest
            {
                amount      = 100,
                description = "Test1",
                return_url  = "https://defra/",
                reference   = "MSTEST1"
            });

            Assert.IsNotNull(response);
        }
        public void FindPaymentSuccessfulGovPayOffline()
        {
            var config = serviceConfiguration;

            config.TargetUrl  = "https://test.invaliddomaindoesnotexisteverever.com/";
            config.TargetHost = "test.invaliddomaindoesnotexisteverever.com";

            var response = new CardPaymentService(config).FindPayment(new FindPaymentRequest
            {
                PaymentId = pid
            });

            Assert.IsNotNull(response.state.status = "error");
        }
        public void CardPayment_DoublePayment()
        {
            // arrange
            var fakeCardRepository        = new FakeCardRepository();
            var fakeBankAccountRepository = new FakeBankAccountRepository();
            var inMemPaymentRepository    = new InMemoryPaymentRepository();
            // act
            var service = new CardPaymentService(fakeCardRepository, fakeBankAccountRepository, inMemPaymentRepository);
            CardPaymentResponse response = service.DoPayment(new CardPaymentRequest(requestId1, FakeCardRepository.GenerateCard_JohnDoe(), FakeBankAccountRepository.GenerateBankAccount_Amazon()));

            service = new CardPaymentService(new FakeCardRepository(), new FakeBankAccountRepository(), inMemPaymentRepository);
            // act-assert
            Assert.Throws <RequestAlreadyProcessedException>(() => service.DoPayment(new CardPaymentRequest(requestId1, FakeCardRepository.GenerateCard_JohnDoe(), FakeBankAccountRepository.GenerateBankAccount_Amazon())));
        }
        /// <summary>
        /// Executes the WorkFlow.
        /// </summary>
        /// <param name="crmWorkflowContext">The <see cref="WorkFlowActivityBase.LocalWorkflowContext"/> which contains the
        /// <param name="executionContext" > <see cref="CodeActivityContext"/>
        /// </param>
        /// <remarks>
        /// For improved performance, Microsoft Dynamics 365 caches WorkFlow instances.
        /// The WorkFlow's Execute method should be written to be stateless as the constructor
        /// is not called for every invocation of the WorkFlow. Also, multiple system threads
        /// could execute the WorkFlow at the same time. All per invocation state information
        /// is stored in the context. This means that you should not use global variables in WorkFlows.
        /// </remarks>
        public override void ExecuteCRMWorkFlowActivity(CodeActivityContext executionContext, LocalWorkflowContext crmWorkflowContext)
        {
            var tracingService = executionContext.GetExtension <ITracingService>();

            tracingService.Trace("CreatePayment starting...");

            try
            {
                // 1. Validation
                ValidateNotNull(crmWorkflowContext);

                // 2. Prepare API Request
                tracingService.Trace("Calling PrepareCardPaymentRequest...");
                CreatePaymentRequest apiRequest = this.PrepareCardPaymentRequest(executionContext);

                // 2. Retrieve Configuration
                tracingService.Trace("Calling RetrieveCardPaymentServiceConfiguration...");
                RestServiceConfiguration cardServiceConfiguration = this.RetrieveCardPaymentServiceConfiguration(executionContext, ConfigurationPrefix.Get(executionContext));

                // 3. Set-up the Api Service
                tracingService.Trace("Instantiating CardPaymentService...");
                CardPaymentService cardPaymentService = new CardPaymentService(cardServiceConfiguration);

                // 4. Call the API
                tracingService.Trace("Calling GovPay CreatePayment with amount='{0}', description='{1}', reference='{2}', returnUrl='{3}'", apiRequest.amount, apiRequest.description, apiRequest.reference, apiRequest.return_url);
                CreatePaymentResponse apiResponse = cardPaymentService.CreatePayment(apiRequest);

                // TODO Log request and Response

                // 5. Return the response
                if (apiResponse != null && apiResponse.error_message != null)
                {
                    tracingService.Trace("Error message: {0}", apiResponse.error_message);
                }
                tracingService.Trace("Calling PrepareOutputParameters...");
                this.PrepareOutputParameters(executionContext, apiResponse, tracingService);
            }
            catch (Exception ex)
            {
                // Todo: Log the Error
                tracingService.Trace("Exception: " + ex);
                throw ex;
            }
        }
        public void CreatePaymentGovPayOffline()
        {
            var config = serviceConfiguration;

            config.TargetUrl  = "https://test.invaliddomaindoesnotexisteverever.com/";
            config.TargetHost = "test.invaliddomaindoesnotexisteverever.com";

            CardPaymentService service = new CardPaymentService(serviceConfiguration);

            var response = service.CreatePayment(new CreatePaymentRequest
            {
                amount      = 100,
                description = "Test1",
                return_url  = "https://defra/",
                reference   = "MSTEST1"
            });

            Assert.IsNotNull(response.state.status = "error");
        }
        /// <summary>
        /// Executes the WorkFlow.
        /// </summary>
        /// <param name="crmWorkflowContext">The <see cref="WorkFlowActivityBase.LocalWorkflowContext"/> which contains the
        /// <param name="executionContext" > <see cref="CodeActivityContext"/>
        /// </param>
        /// <remarks>
        /// For improved performance, Microsoft Dynamics 365 caches WorkFlow instances.
        /// The WorkFlow's Execute method should be written to be stateless as the constructor
        /// is not called for every invocation of the WorkFlow. Also, multiple system threads
        /// could execute the WorkFlow at the same time. All per invocation state information
        /// is stored in the context. This means that you should not use global variables in WorkFlows.
        /// </remarks>
        public override void ExecuteCRMWorkFlowActivity(CodeActivityContext executionContext, LocalWorkflowContext crmWorkflowContext)
        {
            var tracingService = executionContext.GetExtension <ITracingService>();

            tracingService.Trace("FindPayment starting...");

            try
            {
                // 1. Validation
                ValidateNotNull(crmWorkflowContext);

                // 2. Prepare API Request
                tracingService.Trace("Calling PrepareFindPaymentRequest...");
                FindPaymentRequest apiRequest = this.PrepareFindPaymentRequest(executionContext, crmWorkflowContext, tracingService);

                // 3. Retrieve Configuration
                tracingService.Trace("Calling RetrieveCardPaymentServiceConfiguration...");
                RestServiceConfiguration cardServiceConfiguration = this.RetrieveCardPaymentServiceConfiguration(executionContext, ConfigurationPrefix.Get(executionContext));

                // 4. Set-up the Api Service
                tracingService.Trace("Instantiating CardPaymentService...");
                CardPaymentService cardPaymentService = new CardPaymentService(cardServiceConfiguration);

                // 5. Call the API
                tracingService.Trace("Calling GovPay FindPayment...");
                FindPaymentResponse apiResponse = cardPaymentService.FindPayment(apiRequest);

                // 6. Return the response
                tracingService.Trace("Calling PrepareOutputParameters...");
                this.PrepareOutputParameters(executionContext, apiResponse, tracingService);
            }
            catch (Exception ex)
            {
                // Todo: Log the Error
                tracingService.Trace("Exception: " + ex);
                throw ex;
            }
        }
Example #15
0
 public double GetAccountBalance(string accountName)
 {
     return(CardPaymentService.GetAccountBalance(accountName));
 }
 public void Init()
 {
     _cardService = SampleFactory.CreateSampleCardPaymentService();
     _auth        = SampleFactory.CreateSampleCustomAuthorization("noException");
 }
            private static async Task <ApiResult <ApiCardPaymentResponse> > BecauseAsync()
            {
                ApiResult = await CardPaymentService.CreatePaymentAsync(CardPaymentRequest);

                return(await CardPaymentService.CancelPaymentAsync(ApiResult.Value.Payment.ID.Value));
            }
 public void SetUp()
 {
     _cardPaymentService = SampleFactory.CreateSampleCardPaymentService();
 }