Exemple #1
0
        public async Task <IActionResult> Detail(string slug, string error, string serviceProcessed)
        {
            var response = await _repository.Get <ServicePayPayment>(slug);

            if (!response.IsSuccessful())
            {
                return(response);
            }

            var payment = response.Content as ProcessedServicePayPayment;

            var paymentSubmission = new ServicePayPaymentSubmissionViewModel
            {
                Payment = payment
            };

            if (!string.IsNullOrEmpty(payment?.PaymentAmount))
            {
                paymentSubmission.Amount = payment.PaymentAmount;
            }

            if (!string.IsNullOrEmpty(error) && !string.IsNullOrEmpty(serviceProcessed) && serviceProcessed.ToUpper().Equals("FALSE"))
            {
                ModelState.AddModelError(nameof(ServicePayPaymentSubmissionViewModel.Reference), error);
                ModelState.AddModelError(nameof(ServicePayPaymentSubmissionViewModel.EmailAddress), error);
                ModelState.AddModelError(nameof(ServicePayPaymentSubmissionViewModel.Name), error);
                ModelState.AddModelError(nameof(ServicePayPaymentSubmissionViewModel.Amount), error);
            }

            return(View(paymentSubmission));
        }
        public void Should_ReturnSuccess_WhenValidationIsNone_ForServicePayPayment()
        {
            // Arrange
            var paymentSubmission = new ServicePayPaymentSubmissionViewModel
            {
                Amount  = "10.00",
                Payment = new ProcessedServicePayPayment("paymentTitle",
                                                         "paymentSlug",
                                                         "paymentTeaser",
                                                         "paymentDescription",
                                                         "paymentDetailsText",
                                                         "paymentReference",
                                                         new List <Crumb>(),
                                                         EPaymentReferenceValidation.None,
                                                         "metaDescription",
                                                         "returnUrl",
                                                         "catalogueId",
                                                         "accountReference",
                                                         "paymentDescription",
                                                         new List <Alert>(),
                                                         "12"),
                Reference    = "12345",
                Name         = "name",
                EmailAddress = "*****@*****.**"
            };
            var context = new ValidationContext(paymentSubmission);
            var results = new List <ValidationResult>();

            // Act
            var result = Validator.TryValidateObject(paymentSubmission, context, results, true);

            // Assert
            result.Should().BeTrue();
        }
Exemple #3
0
        public void IsValidShouldReturnValidationResultErrorIfEmailAddressEmpty()
        {
            var model = new ServicePayPaymentSubmissionViewModel
            {
                Reference    = "12346",
                Amount       = "23.52",
                EmailAddress = string.Empty,
                Name         = "Test Name",
                Payment      = _processedPayment
            };

            var context = new ValidationContext(model);
            var results = new List <ValidationResult>();

            var result = Validator.TryValidateObject(model, context, results, true);

            result.Should().Be(false);
        }
Exemple #4
0
        public async Task <IActionResult> Detail(string slug, ServicePayPaymentSubmissionViewModel paymentSubmission)
        {
            var response = await _repository.Get <ServicePayPayment>(slug);

            if (!response.IsSuccessful())
            {
                return(response);
            }

            var payment = response.Content as ProcessedServicePayPayment;

            paymentSubmission.Payment = payment;
            TryValidateModel(paymentSubmission);

            if (!ModelState.IsValid)
            {
                return(View(paymentSubmission));
            }

            var immediateBasketResponse = new CreateImmediateBasketRequest
            {
                CallingAppIdentifier    = _configuration.GetValue <string>("CivicaPayCallingAppIdentifier"),
                CustomerID              = _configuration.GetValue <string>("CivicaPayCustomerID"),
                ApiPassword             = _configuration.GetValue <string>("CivicaPayApiPassword"),
                ReturnURL               = !string.IsNullOrEmpty(payment.ReturnUrl) ? payment.ReturnUrl : $"{Request.Scheme}://{Request.Host}/service-pay-payment/{slug}/result",
                NotifyURL               = string.Empty,
                CallingAppTranReference = paymentSubmission.Reference,
                PaymentItems            = new List <PaymentItem>
                {
                    new PaymentItem
                    {
                        PaymentDetails = new PaymentDetail
                        {
                            CatalogueID             = payment.CatalogueId,
                            AccountReference        = !string.IsNullOrEmpty(payment.AccountReference) ? payment.AccountReference : paymentSubmission.Reference,
                            PaymentAmount           = paymentSubmission.Amount,
                            PaymentNarrative        = $"{payment.PaymentDescription} - {paymentSubmission.Reference}",
                            CallingAppTranReference = paymentSubmission.Reference,
                            Quantity            = "1",
                            ServicePayReference = paymentSubmission.Reference,
                            ServicePayNarrative = $"{payment.PaymentDescription} - Name: {paymentSubmission.Name} - Email: {paymentSubmission.EmailAddress}",
                            EmailAddress        = paymentSubmission.EmailAddress,
                            TelephoneNumber     = "0"
                        },
                        AddressDetails = new AddressDetail
                        {
                            Name = paymentSubmission.Name
                        }
                    }
                }
            };

            var civicaResponse = await _civicaPayGateway.CreateImmediateBasketAsync(immediateBasketResponse);

            if (civicaResponse.StatusCode == HttpStatusCode.BadRequest)
            {
                if (civicaResponse.ResponseContent.ResponseCode == "00001")
                {
                    ModelState.AddModelError("Reference", $"Check {payment.ReferenceLabel.ToLower()} and try again.");
                    return(View(paymentSubmission));
                }

                _logger.LogError($"ServicePayPaymentController:: Unable to create ImmediateBasket:: CivicaPay response code: {civicaResponse.ResponseContent.ResponseCode}, CivicaPay error message - {civicaResponse.ResponseContent.ErrorMessage}");
                return(View("Error", response));
            }

            return(Redirect(_civicaPayGateway.GetPaymentUrl(civicaResponse.ResponseContent.BasketReference, civicaResponse.ResponseContent.BasketToken, paymentSubmission.Reference)));
        }