Skip to content

Commit

Permalink
Add Cart model to the TokensController
Browse files Browse the repository at this point in the history
This change includes the Cart model in the TokensController and the TokenViewModel. Consequently, it modifies the Index.cshtml, adding conditionality to the 'Checkout with token' link based on cart content. Unused code in CheckOutController.cs has also been cleaned up.
  • Loading branch information
lounge committed Feb 9, 2024
1 parent ec2eea6 commit aaabe5a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,6 @@ public async Task<IPaymentOrderResponse> CreatePaymentOrder(bool generatePayment
return await CreatePaymentOrder(generatePaymentToken, generateRecurrenceToken, generateUnscheduledToken, null, null);
}

// public async Task<IPaymentOrderResponse> CreatePaymentOrder(bool generatePaymentToken, bool generateRecurrenceToken, bool generateUnscheduledToken, string paymentToken)
// {
// return await CreatePaymentOrder(generatePaymentToken, generateRecurrenceToken, generateUnscheduledToken, null, paymentToken);
// }

public async Task<IPaymentOrderResponse> CreatePaymentOrder(bool generatePaymentToken, bool generateRecurrenceToken, bool generateUnscheduledToken,
Uri paymentUrl, string paymentToken)
{
Expand Down Expand Up @@ -231,7 +226,6 @@ public async Task<IPaymentOrderResponse> CreatePaymentOrder(bool generatePayment

if (!string.IsNullOrWhiteSpace(paymentToken))
{
// paymentOrderRequest.Payer.PayerReference = null;
paymentOrderRequest.GeneratePaymentToken = false;
paymentOrderRequest.PaymentToken ??= paymentToken;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

using Sample.AspNetCore.Models;
using Sample.AspNetCore.Models.ViewModels;

using SwedbankPay.Sdk;
Expand All @@ -17,12 +18,15 @@ public class TokensController : Controller
{
private readonly ISwedbankPayClient _swedbankPayClient;
private readonly ILogger<TokensController> _logger;
private readonly Cart _cart;

public TokensController(ISwedbankPayClient swedbankPayClient,
ILogger<TokensController> logger)
ILogger<TokensController> logger,
Cart cart)
{
_swedbankPayClient = swedbankPayClient;
_logger = logger;
_cart = cart;
}


Expand Down Expand Up @@ -107,6 +111,7 @@ private async Task<TokenViewModel> GetViewModel()
viewModel.PayerReference = tokenResponse?.PayerReference;
viewModel.Tokens = tokenResponse?.Tokens;
viewModel.OperationList = tokenResponse?.Operations;
viewModel.Cart = _cart;
}
catch (Exception)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ public class TokenViewModel
{
public string Id { get;set; }
public string PayerReference { get;set; }


public Cart Cart { get; set; }
public IUserTokenOperations OperationList { get; set; }

public List<IUserToken> Tokens { get; set; }

}
21 changes: 12 additions & 9 deletions src/Samples/Sample.AspNetCore/Views/Tokens/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@model Sample.AspNetCore.Models.ViewModels.TokenViewModel

@{
ViewData["Title"] = "Tokens";
Layout = "~/Views/Shared/_Layout.cshtml";
Expand Down Expand Up @@ -68,14 +67,18 @@
asp-route-tokenId=@token.Token>
Delete Token
</a>

<a class="btn btn-primary"
data-automation="button-checkout-with-token"
asp-route-paymentToken="@token.Token"
asp-action="LoadPaymentMenu"
asp-controller="CheckOut">
Checkout with token
</a>

@if (Model.Cart.CartLines.Any())
{
<a class="btn btn-primary"
data-automation="button-checkout-with-token"
asp-route-paymentToken="@token.Token"
asp-action="LoadPaymentMenu"
asp-controller="CheckOut">
Checkout with token
</a>
}

</td>
</tr>
}
Expand Down

0 comments on commit aaabe5a

Please sign in to comment.