public async Task <string> GeneratePaymentUrl(string form, string path, string reference, string sessionGuid, PaymentInformation paymentInformation)
        {
            if (string.IsNullOrEmpty(reference))
            {
                throw new PaymentFailureException("CivicaPayProvider::No valid reference");
            }

            var basket = new CreateImmediateBasketRequest
            {
                CallingAppIdentifier    = "Basket",
                CustomerID              = _paymentConfig.CustomerId,
                ApiPassword             = _paymentConfig.ApiPassword,
                ReturnURL               = _environment.EnvironmentName.Equals("local") ? $"https://{_httpContextAccessor.HttpContext.Request.Host}{_environment.EnvironmentName.ToReturnUrlPrefix()}/{form}/{path}/payment-response" : $"https://{_httpContextAccessor.HttpContext.Request.Host}{_environment.EnvironmentName.ToReturnUrlPrefix()}/v2/{form}/{path}/payment-response",
                NotifyURL               = string.Empty,
                CallingAppTranReference = reference,
                PaymentItems            = new List <PaymentItem>
                {
                    new PaymentItem
                    {
                        PaymentDetails = new PaymentDetail
                        {
                            CatalogueID             = paymentInformation.Settings.CatalogueId,
                            AccountReference        = paymentInformation.Settings.AccountReference,
                            PaymentAmount           = paymentInformation.Settings.Amount,
                            Quantity                = "1",
                            PaymentNarrative        = form,
                            CallingAppTranReference = reference,
                            ServicePayItemDesc      = paymentInformation.Settings.Description
                        },
                        AddressDetails = new AddressDetail()
                    }
                }
            };

            var civicaResponse = await _civicaPayGateway.CreateImmediateBasketAsync(basket);

            if (civicaResponse.StatusCode != HttpStatusCode.OK)
            {
                throw new Exception($"CivicaPayProvider::GeneratePaymentUrl, CivicaPay gateway response with a non ok status code {civicaResponse.StatusCode}, HttpResponse: {civicaResponse}");
            }

            return(_civicaPayGateway.GetPaymentUrl(civicaResponse.ResponseContent.BasketReference, civicaResponse.ResponseContent.BasketToken, reference));
        }
Beispiel #2
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)));
        }
        public async Task <IActionResult> Detail(string slug, PaymentSubmission paymentSubmission)
        {
            var response = await _repository.Get <Payment>(slug);

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

            var payment = response.Content as ProcessedPayment;

            paymentSubmission.Payment = payment;

            TryValidateModel(paymentSubmission);

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

            var transactionReference = Guid.NewGuid().ToString();

            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}/payment/{slug}/result",
                NotifyURL               = string.Empty,
                CallingAppTranReference = transactionReference,
                PaymentItems            = new System.Collections.Generic.List <PaymentItem>
                {
                    new PaymentItem
                    {
                        PaymentDetails = new PaymentDetail
                        {
                            CatalogueID             = payment.CatalogueId,
                            AccountReference        = !string.IsNullOrEmpty(payment.AccountReference) ? payment.AccountReference : paymentSubmission.Reference,
                            PaymentAmount           = paymentSubmission.Amount.ToString(),
                            PaymentNarrative        = $"{payment.PaymentDescription} - {paymentSubmission.Reference}",
                            CallingAppTranReference = transactionReference,
                            Quantity = "1"
                        },
                        AddressDetails = new AddressDetail()
                    }
                }
            };

            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));
                }
                return(View("Error", response));
            }

            return(Redirect(_civicaPayGateway.GetPaymentUrl(civicaResponse.ResponseContent.BasketReference, civicaResponse.ResponseContent.BasketToken, transactionReference)));
        }
Beispiel #4
0
        public async Task <HttpResponse <CreateImmediateBasketResponse> > CreateImmediateBasketAsync(CreateImmediateBasketRequest request)
        {
            var response = await PostAsync <CreateImmediateBasketResponse>($"{ApiRoot}/BasketApi/CreateImmediatePaymentBasket", request);

            if (response.ResponseContent.ResponseCode != "00000")
            {
                response.StatusCode = HttpStatusCode.BadRequest;
            }

            return(response);
        }