Skip to content

Commit

Permalink
Add Terms of Service handling to checkout process (#648)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zunkas authored Nov 25, 2024
1 parent 84ced1f commit 73dc5bb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,6 +26,7 @@ namespace Sample.AspNetCore.Controllers;
public class CheckOutController : Controller
{
private readonly Cart _cartService;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly ILogger<CheckOutController> _logger;
private readonly StoreDbContext _context;
private readonly PayeeInfoConfig _payeeInfoOptions;
Expand All @@ -36,6 +38,7 @@ public class CheckOutController : Controller
public CheckOutController(IOptionsSnapshot<PayeeInfoConfig> payeeInfoOptionsAccessor,
IOptionsSnapshot<UrlsOptions> urlsAccessor,
Cart cart,
IHttpContextAccessor httpContextAccessor,
ILogger<CheckOutController> logger,
StoreDbContext storeDbContext,
ISwedbankPayClient payClient,
Expand All @@ -44,6 +47,7 @@ public CheckOutController(IOptionsSnapshot<PayeeInfoConfig> payeeInfoOptionsAcce
_payeeInfoOptions = payeeInfoOptionsAccessor.Value;
_urls = urlsAccessor.Value;
_cartService = cart;
_httpContextAccessor = httpContextAccessor;
_logger = logger;
_context = storeDbContext;
_swedbankPayClient = payClient;
Expand Down Expand Up @@ -148,6 +152,11 @@ public async Task<IPaymentOrderResponse> 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
Expand Down
11 changes: 11 additions & 0 deletions src/Samples/Sample.AspNetCore/Controllers/TermsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Microsoft.AspNetCore.Mvc;

namespace Sample.AspNetCore.Controllers;

public class TermsController : Controller
{
public IActionResult Index()
{
return View();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
13 changes: 13 additions & 0 deletions src/Samples/Sample.AspNetCore/Views/Terms/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<h1>Terms of Payment</h1>

<p>By making a payment, you agree to the following terms and conditions:</p>

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

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

0 comments on commit 73dc5bb

Please sign in to comment.