From 3d16a2c5b19f2b0db3ebdfbf8bf58a6c2f9a6909 Mon Sep 17 00:00:00 2001 From: Daniel Sundqvist Date: Mon, 25 Nov 2024 08:55:53 +0100 Subject: [PATCH] Add Terms of Service handling to checkout process Introduced IHttpContextAccessor to CheckOutController for dynamically generating Terms of Service URL. Created a new TermsController with an associated view to display payment terms. Enhanced SwedbankPayCheckout view to open terms in a new tab. --- .../Controllers/CheckOutController.cs | 9 +++++++++ .../Controllers/TermsController.cs | 11 +++++++++++ .../Views/Checkout/_SwedbankPayCheckout.cshtml | 1 + .../Sample.AspNetCore/Views/Terms/Index.cshtml | 13 +++++++++++++ 4 files changed, 34 insertions(+) create mode 100644 src/Samples/Sample.AspNetCore/Controllers/TermsController.cs create mode 100644 src/Samples/Sample.AspNetCore/Views/Terms/Index.cshtml diff --git a/src/Samples/Sample.AspNetCore/Controllers/CheckOutController.cs b/src/Samples/Sample.AspNetCore/Controllers/CheckOutController.cs index 97147e2645..0621ebae76 100644 --- a/src/Samples/Sample.AspNetCore/Controllers/CheckOutController.cs +++ b/src/Samples/Sample.AspNetCore/Controllers/CheckOutController.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -25,6 +26,7 @@ namespace Sample.AspNetCore.Controllers; public class CheckOutController : Controller { private readonly Cart _cartService; + private readonly IHttpContextAccessor _httpContextAccessor; private readonly ILogger _logger; private readonly StoreDbContext _context; private readonly PayeeInfoConfig _payeeInfoOptions; @@ -36,6 +38,7 @@ public class CheckOutController : Controller public CheckOutController(IOptionsSnapshot payeeInfoOptionsAccessor, IOptionsSnapshot urlsAccessor, Cart cart, + IHttpContextAccessor httpContextAccessor, ILogger logger, StoreDbContext storeDbContext, ISwedbankPayClient payClient, @@ -44,6 +47,7 @@ public CheckOutController(IOptionsSnapshot payeeInfoOptionsAcce _payeeInfoOptions = payeeInfoOptionsAccessor.Value; _urls = urlsAccessor.Value; _cartService = cart; + _httpContextAccessor = httpContextAccessor; _logger = logger; _context = storeDbContext; _swedbankPayClient = payClient; @@ -148,6 +152,11 @@ public async Task CreatePaymentOrder(bool? generatePaymen LogoUrl = _urls.LogoUrl, CancelUrl = _urls.CancelUrl }; + + if (_httpContextAccessor.HttpContext != null){ + var httpContextRequest = _httpContextAccessor.HttpContext.Request; + urls.TermsOfServiceUrl = new Uri($"{httpContextRequest.Scheme}://{httpContextRequest.Host.Value}/terms", UriKind.Absolute); + } var paymentOrderRequest = new PaymentOrderRequest( generateRecurrenceToken.HasValue && generateRecurrenceToken.Value || generateUnscheduledToken.HasValue && generateUnscheduledToken.Value diff --git a/src/Samples/Sample.AspNetCore/Controllers/TermsController.cs b/src/Samples/Sample.AspNetCore/Controllers/TermsController.cs new file mode 100644 index 0000000000..3c90663e02 --- /dev/null +++ b/src/Samples/Sample.AspNetCore/Controllers/TermsController.cs @@ -0,0 +1,11 @@ +using Microsoft.AspNetCore.Mvc; + +namespace Sample.AspNetCore.Controllers; + +public class TermsController : Controller +{ + public IActionResult Index() + { + return View(); + } +} \ No newline at end of file diff --git a/src/Samples/Sample.AspNetCore/Views/Checkout/_SwedbankPayCheckout.cshtml b/src/Samples/Sample.AspNetCore/Views/Checkout/_SwedbankPayCheckout.cshtml index f5b8416979..573e9112d2 100644 --- a/src/Samples/Sample.AspNetCore/Views/Checkout/_SwedbankPayCheckout.cshtml +++ b/src/Samples/Sample.AspNetCore/Views/Checkout/_SwedbankPayCheckout.cshtml @@ -68,6 +68,7 @@ function onTermsOfServiceRequested(obj){ console.log("Terms of service requested event:"); console.log(obj) + window.open(obj.termsOfServiceUrl, '_blank'); } function onEventNotification(obj){ diff --git a/src/Samples/Sample.AspNetCore/Views/Terms/Index.cshtml b/src/Samples/Sample.AspNetCore/Views/Terms/Index.cshtml new file mode 100644 index 0000000000..9e58410741 --- /dev/null +++ b/src/Samples/Sample.AspNetCore/Views/Terms/Index.cshtml @@ -0,0 +1,13 @@ +

Terms of Payment

+ +

By making a payment, you agree to the following terms and conditions:

+ +
    +
  • All payments are non-refundable unless otherwise stated.
  • +
  • Payments must be made in full before the delivery of any goods or services.
  • +
  • We accept the following payment methods: credit card, debit card, and PayPal.
  • +
  • Any disputes regarding payments must be reported within 30 days of the transaction date.
  • +
  • We reserve the right to change our payment terms at any time without prior notice.
  • +
+ +

If you have any questions or concerns about our payment terms, please contact our support team.

\ No newline at end of file