Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Terms of Service handling to checkout process in sample site #648

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>