Skip to content

Commit 3f389c8

Browse files
authored
#1085. An error occurs when paying for an order (#1086)
1 parent 7fb6d40 commit 3f389c8

21 files changed

Lines changed: 80 additions & 41 deletions

File tree

src/Modules/SimplCommerce.Module.PaymentBraintree/Areas/PaymentBraintree/Components/BraintreeLandingViewComponent.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ public async Task<IViewComponentResult> InvokeAsync(Guid checkoutId)
5757
{
5858
ClientToken = await _braintreeConfiguration.GetClientToken(),
5959
Amount = zeroDecimalAmount,
60-
ISOCurrencyCode = regionInfo.ISOCurrencySymbol
60+
ISOCurrencyCode = regionInfo.ISOCurrencySymbol,
61+
CheckoutId = checkoutId,
6162
};
6263

6364
return View(this.GetViewPath(), model);

src/Modules/SimplCommerce.Module.PaymentBraintree/Areas/PaymentBraintree/Controllers/BraintreeController.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,17 @@ public BraintreeController(
4949
}
5050

5151
[HttpPost]
52-
public async Task<IActionResult> Charge(string nonce)
52+
public async Task<IActionResult> Charge(string nonce, Guid checkoutId)
5353
{
5454
var gateway = await _braintreeConfiguration.BraintreeGateway();
5555

5656
var curentUser = await _workContext.GetCurrentUser();
57-
//TODO: pass checkout Id here
58-
var cart = await _checkoutService.GetCheckoutDetails(Guid.NewGuid());
57+
58+
var cart = await _checkoutService.GetCheckoutDetails(checkoutId);
5959
if(cart == null)
6060
{
6161
return NotFound();
6262
}
63-
var checkoutId = Guid.NewGuid();
6463
var orderCreateResult = await _orderService.CreateOrder(checkoutId, PaymentProviderHelper.BraintreeProviderId, 0, OrderStatus.PendingPayment);
6564

6665
if (!orderCreateResult.Success)
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace SimplCommerce.Module.PaymentBraintree.Areas.PaymentBraintree.ViewModels
1+
using System;
2+
3+
namespace SimplCommerce.Module.PaymentBraintree.Areas.PaymentBraintree.ViewModels
24
{
35
public class BraintreeCheckoutForm
46
{
@@ -7,5 +9,7 @@ public class BraintreeCheckoutForm
79
public decimal Amount { get; set; }
810

911
public string ISOCurrencyCode { get; set; }
12+
13+
public Guid CheckoutId { get; set; }
1014
}
1115
}

src/Modules/SimplCommerce.Module.PaymentBraintree/Areas/PaymentBraintree/Views/Shared/Components/BraintreeLanding/Default.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
var request = $.ajax({
4646
type: 'POST',
4747
url: '@Url.Action("Charge", "Braintree", new { Area = "PaymentBraintree" })',
48-
data: { nonce: payload.nonce }
48+
data: { nonce: payload.nonce, checkoutId: "@Model.CheckoutId" }
4949
})
5050
.done(function (data) {
5151
window.location = "/checkout/success?orderId="+ data.orderId;

src/Modules/SimplCommerce.Module.PaymentMomo/Areas/PaymentMomo/Components/MomoLandingViewComponent.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Threading.Tasks;
1+
using System;
2+
using System.Threading.Tasks;
23
using Microsoft.AspNetCore.Mvc;
34
using Microsoft.EntityFrameworkCore;
45
using Newtonsoft.Json;
@@ -19,13 +20,14 @@ public MomoLandingViewComponent(IRepositoryWithTypedId<PaymentProvider, string>
1920
_paymentProviderRepository = paymentProviderRepository;
2021
}
2122

22-
public async Task<IViewComponentResult> InvokeAsync()
23+
public async Task<IViewComponentResult> InvokeAsync(Guid checkoutId)
2324
{
2425
var momoProvider = await _paymentProviderRepository.Query().FirstOrDefaultAsync(x => x.Id == PaymentProviderHelper.MomoPaymentProviderId);
2526
var momoSetting = JsonConvert.DeserializeObject<MomoPaymentConfigForm>(momoProvider.AdditionalSettings);
2627

2728
var model = new MomoCheckoutForm();
2829
model.PaymentFee = momoSetting.PaymentFee;
30+
model.CheckoutId = checkoutId;
2931

3032
return View(this.GetViewPath(), model);
3133
}

src/Modules/SimplCommerce.Module.PaymentMomo/Areas/PaymentMomo/Controllers/MomoPaymentController.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,17 @@ public MomoPaymentController(
5454
_setting = new Lazy<MomoPaymentConfigForm>(GetSetting());
5555
}
5656

57-
public async Task<IActionResult> MomoCheckout()
57+
[HttpPost]
58+
public async Task<IActionResult> MomoCheckout(Guid checkoutId)
5859
{
5960
var currentUser = await _workContext.GetCurrentUser();
60-
//TODO: pass checkout Id here
61-
var cart = await _checkoutService.GetCheckoutDetails(Guid.Empty);
61+
62+
var cart = await _checkoutService.GetCheckoutDetails(checkoutId);
6263
if (cart == null)
6364
{
6465
return NotFound();
6566
}
6667

67-
var checkoutId = Guid.NewGuid();
6868
var orderCreateResult = await _orderService.CreateOrder(checkoutId, "MomoPayment", 0, OrderStatus.PendingPayment);
6969

7070
if (!orderCreateResult.Success)

src/Modules/SimplCommerce.Module.PaymentMomo/Areas/PaymentMomo/Views/Shared/Components/MomoLanding/Default.cshtml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
<label>Momo payment</label>
1+
@model SimplCommerce.Module.PaymentMomo.ViewModels.MomoCheckoutForm
2+
3+
<label>Momo payment</label>
24
<form asp-area="PaymentMomo" asp-controller="MomoPayment" asp-action="MomoCheckout" method="POST" id="checkout-payment" class="form-horizontal">
35
<div class="form-group">
46
<div class="col-md-12">
7+
<input type="hidden" value="@Model.CheckoutId" name="checkoutId" />
58
<button type="submit" class="btn btn-order">@Localizer["Momo payment"]</button>
69
</div>
710
</div>
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
namespace SimplCommerce.Module.PaymentMomo.ViewModels
1+
using System;
2+
3+
namespace SimplCommerce.Module.PaymentMomo.ViewModels
24
{
35
public class MomoCheckoutForm
46
{
57
public decimal PaymentFee { get; set; }
8+
9+
public Guid CheckoutId { get; set; }
610
}
711
}

src/Modules/SimplCommerce.Module.PaymentNganLuong/Areas/PaymentNganLuong/Components/NganLuongLandingViewComponent.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Threading.Tasks;
1+
using System;
2+
using System.Threading.Tasks;
23
using Microsoft.AspNetCore.Mvc;
34
using Microsoft.EntityFrameworkCore;
45
using Newtonsoft.Json;
@@ -19,12 +20,12 @@ public NganLuongLandingViewComponent(IRepositoryWithTypedId<PaymentProvider, str
1920
_paymentProviderRepository = paymentProviderRepository;
2021
}
2122

22-
public async Task<IViewComponentResult> InvokeAsync()
23+
public async Task<IViewComponentResult> InvokeAsync(Guid checkoutId)
2324
{
2425
var nganLuongProvider = await _paymentProviderRepository.Query().FirstOrDefaultAsync(x => x.Id == PaymentProviderHelper.NganLuongPaymentProviderId);
2526
var nganLuongSetting = JsonConvert.DeserializeObject<NganLuongConfigForm>(nganLuongProvider.AdditionalSettings);
2627

27-
return View(this.GetViewPath());
28+
return View(this.GetViewPath(), checkoutId);
2829
}
2930
}
3031
}

src/Modules/SimplCommerce.Module.PaymentNganLuong/Areas/PaymentNganLuong/Controllers/NganLuongController.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,16 @@ public IActionResult PaymentMethods()
6060
}
6161

6262
[HttpPost]
63-
public async Task<IActionResult> SubmitPayment(string paymentOption, string bankCode)
63+
public async Task<IActionResult> SubmitPayment(string paymentOption, string bankCode, Guid checkoutId)
6464
{
6565
var currentUser = await _workContext.GetCurrentUser();
66-
//TODO: pass checkout Id here
67-
var cart = await _checkoutService.GetCheckoutDetails(Guid.Empty);
66+
67+
var cart = await _checkoutService.GetCheckoutDetails(checkoutId);
6868
if (cart == null)
6969
{
7070
return NotFound();
7171
}
7272

73-
var checkoutId = Guid.NewGuid();
7473
var orderCreateResult = await _orderService.CreateOrder(checkoutId, "NganLuong", 0, OrderStatus.PendingPayment);
7574

7675
if (!orderCreateResult.Success)

0 commit comments

Comments
 (0)