Skip to content

Commit 11a05b7

Browse files
Payment transaction
1 parent eb45948 commit 11a05b7

File tree

7 files changed

+1177
-76
lines changed

7 files changed

+1177
-76
lines changed

src/Web/Grand.Web.Admin/Controllers/PaymentTransactionController.cs

Lines changed: 11 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
using Grand.Business.Core.Interfaces.Common.Directory;
55
using Grand.Business.Core.Interfaces.Common.Localization;
66
using Grand.Business.Core.Queries.Checkout.Orders;
7-
using Grand.Domain.Permissions;
87
using Grand.Domain.Payments;
8+
using Grand.Domain.Permissions;
99
using Grand.Infrastructure;
1010
using Grand.SharedKernel;
1111
using Grand.Web.AdminShared.Models.Orders;
@@ -28,7 +28,6 @@ public PaymentTransactionController(
2828
IPaymentTransactionService paymentTransactionService,
2929
IOrderService orderService,
3030
IContextAccessor contextAccessor,
31-
IGroupService groupService,
3231
IDateTimeService dateTimeService,
3332
IMediator mediator,
3433
IEnumTranslationService enumTranslationService)
@@ -37,7 +36,6 @@ public PaymentTransactionController(
3736
_paymentTransactionService = paymentTransactionService;
3837
_orderService = orderService;
3938
_contextAccessor = contextAccessor;
40-
_groupService = groupService;
4139
_dateTimeService = dateTimeService;
4240
_mediator = mediator;
4341
_enumTranslationService = enumTranslationService;
@@ -51,11 +49,10 @@ public PaymentTransactionController(
5149
private readonly IOrderService _orderService;
5250
private readonly ITranslationService _translationService;
5351
private readonly IContextAccessor _contextAccessor;
54-
private readonly IGroupService _groupService;
5552
private readonly IDateTimeService _dateTimeService;
5653
private readonly IMediator _mediator;
5754
private readonly IEnumTranslationService _enumTranslationService;
58-
55+
5956
#endregion Fields
6057

6158
#region Methods
@@ -73,17 +70,14 @@ public IActionResult List()
7370
.ToList()
7471
};
7572
model.PaymentTransactionStatus.Insert(0,
76-
new SelectListItem
77-
{ Text = _translationService.GetResource("Admin.Common.All"), Value = "-1", Selected = true });
73+
new SelectListItem { Text = _translationService.GetResource("Admin.Common.All"), Value = "-1", Selected = true });
7874
return View(model);
7975
}
8076

8177
[PermissionAuthorizeAction(PermissionActionName.List)]
8278
[HttpPost]
8379
public async Task<IActionResult> List(DataSourceRequest command, PaymentTransactionListModel model)
8480
{
85-
if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
86-
model.StoreId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
8781
DateTime? startDateValue = model.StartDate == null
8882
? null
8983
: _dateTimeService.ConvertToUtcTime(model.StartDate.Value, _dateTimeService.CurrentTimeZone);
@@ -161,10 +155,6 @@ public async Task<IActionResult> GoToOrderNumber(PaymentTransactionListModel mod
161155
//not found
162156
return RedirectToAction("List", "PaymentTransaction");
163157

164-
if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer) &&
165-
paymentTransaction.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
166-
return RedirectToAction("List", "PaymentTransaction");
167-
168158
return RedirectToAction("Edit", "PaymentTransaction", new { id = paymentTransaction.Id });
169159
}
170160

@@ -177,10 +167,6 @@ public async Task<IActionResult> Edit(string id)
177167
if (paymentTransaction == null)
178168
return RedirectToAction("List", "PaymentTransaction");
179169

180-
if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer) &&
181-
paymentTransaction.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
182-
return RedirectToAction("List", "PaymentTransaction");
183-
184170
var order = await _orderService.GetOrderByGuid(paymentTransaction.OrderGuid);
185171

186172
var model = new PaymentTransactionModel {
@@ -207,17 +193,12 @@ public async Task<IActionResult> Edit(string id)
207193
//payment method buttons
208194
//model.CanCancelOrder = await _mediator.Send(new CanCancelOrderQuery() { Order = order });
209195
CanCapture = await _mediator.Send(new CanCaptureQuery { PaymentTransaction = paymentTransaction }),
210-
CanMarkAsPaid = await _mediator.Send(new CanMarkPaymentTransactionAsPaidQuery
211-
{ PaymentTransaction = paymentTransaction }),
196+
CanMarkAsPaid = await _mediator.Send(new CanMarkPaymentTransactionAsPaidQuery { PaymentTransaction = paymentTransaction }),
212197
CanRefund = await _mediator.Send(new CanRefundQuery { PaymentTransaction = paymentTransaction }),
213-
CanRefundOffline = await _mediator.Send(new CanRefundOfflineQuery
214-
{ PaymentTransaction = paymentTransaction }),
215-
CanPartiallyRefund = await _mediator.Send(new CanPartiallyRefundQuery
216-
{ PaymentTransaction = paymentTransaction, AmountToRefund = 0 }),
217-
CanPartiallyRefundOffline = await _mediator.Send(new CanPartiallyRefundOfflineQuery
218-
{ PaymentTransaction = paymentTransaction, AmountToRefund = 0 }),
219-
CanPartiallyPaidOffline = await _mediator.Send(new CanPartiallyPaidOfflineQuery
220-
{ PaymentTransaction = paymentTransaction, AmountToPaid = 0 }),
198+
CanRefundOffline = await _mediator.Send(new CanRefundOfflineQuery { PaymentTransaction = paymentTransaction }),
199+
CanPartiallyRefund = await _mediator.Send(new CanPartiallyRefundQuery { PaymentTransaction = paymentTransaction, AmountToRefund = 0 }),
200+
CanPartiallyRefundOffline = await _mediator.Send(new CanPartiallyRefundOfflineQuery { PaymentTransaction = paymentTransaction, AmountToRefund = 0 }),
201+
CanPartiallyPaidOffline = await _mediator.Send(new CanPartiallyPaidOfflineQuery { PaymentTransaction = paymentTransaction, AmountToPaid = 0 }),
221202
CanVoid = await _mediator.Send(new CanVoidQuery { PaymentTransaction = paymentTransaction }),
222203
CanVoidOffline = await _mediator.Send(new CanVoidOfflineQuery { PaymentTransaction = paymentTransaction }),
223204
MaxAmountToRefund = paymentTransaction.TransactionAmount - paymentTransaction.RefundedAmount,
@@ -236,10 +217,6 @@ public async Task<IActionResult> CapturePaymentTransaction(string id)
236217
if (paymentTransaction == null)
237218
return RedirectToAction("List", "PaymentTransaction");
238219

239-
if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer) &&
240-
paymentTransaction.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
241-
return RedirectToAction("List", "PaymentTransaction");
242-
243220
try
244221
{
245222
var errors = await _mediator.Send(new CaptureCommand { PaymentTransaction = paymentTransaction });
@@ -265,10 +242,6 @@ public async Task<IActionResult> MarkPaymentTransactionAsPaid(string id)
265242
if (paymentTransaction == null)
266243
return RedirectToAction("List", "PaymentTransaction");
267244

268-
if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer) &&
269-
paymentTransaction.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
270-
return RedirectToAction("List", "PaymentTransaction");
271-
272245
try
273246
{
274247
await _mediator.Send(new MarkAsPaidCommand { PaymentTransaction = paymentTransaction });
@@ -290,10 +263,6 @@ public async Task<IActionResult> RefundPaymentTransaction(string id)
290263
if (paymentTransaction == null)
291264
return RedirectToAction("List", "PaymentTransaction");
292265

293-
if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer) &&
294-
paymentTransaction.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
295-
return RedirectToAction("List", "PaymentTransaction");
296-
297266
try
298267
{
299268
var errors = await _mediator.Send(new RefundCommand { PaymentTransaction = paymentTransaction });
@@ -318,10 +287,6 @@ public async Task<IActionResult> RefundPaymentTransactionOffline(string id)
318287
if (paymentTransaction == null)
319288
return RedirectToAction("List", "PaymentTransaction");
320289

321-
if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer) &&
322-
paymentTransaction.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
323-
return RedirectToAction("List", "PaymentTransaction");
324-
325290
try
326291
{
327292
await _mediator.Send(new RefundOfflineCommand { PaymentTransaction = paymentTransaction });
@@ -343,10 +308,6 @@ public async Task<IActionResult> VoidPaymentTransaction(string id)
343308
if (paymentTransaction == null)
344309
return RedirectToAction("List", "PaymentTransaction");
345310

346-
if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer) &&
347-
paymentTransaction.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
348-
return RedirectToAction("List", "PaymentTransaction");
349-
350311
try
351312
{
352313
var errors = await _mediator.Send(new VoidCommand { PaymentTransaction = paymentTransaction });
@@ -371,10 +332,6 @@ public async Task<IActionResult> VoidPaymentTransactionOffline(string id)
371332
if (paymentTransaction == null)
372333
return RedirectToAction("List", "PaymentTransaction");
373334

374-
if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer) &&
375-
paymentTransaction.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
376-
return RedirectToAction("List", "PaymentTransaction");
377-
378335
try
379336
{
380337
await _mediator.Send(new VoidOfflineCommand { PaymentTransaction = paymentTransaction });
@@ -395,10 +352,6 @@ public async Task<IActionResult> PartiallyRefundPopup(string id, bool online)
395352
if (paymentTransaction == null)
396353
return RedirectToAction("List", "PaymentTransaction");
397354

398-
if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer) &&
399-
paymentTransaction.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
400-
return RedirectToAction("List", "PaymentTransaction");
401-
402355
var model = new PaymentTransactionModel {
403356
Id = paymentTransaction.Id,
404357
MaxAmountToRefund = paymentTransaction.TransactionAmount - paymentTransaction.RefundedAmount,
@@ -416,10 +369,6 @@ public async Task<IActionResult> PartiallyRefundPopup(string id, bool online, Pa
416369
if (paymentTransaction == null)
417370
return RedirectToAction("List", "PaymentTransaction");
418371

419-
if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer) &&
420-
paymentTransaction.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
421-
return RedirectToAction("List", "PaymentTransaction");
422-
423372
try
424373
{
425374
var amountToRefund = model.AmountToRefund;
@@ -432,11 +381,9 @@ public async Task<IActionResult> PartiallyRefundPopup(string id, bool online, Pa
432381

433382
var errors = new List<string>();
434383
if (online)
435-
errors = (await _mediator.Send(new PartiallyRefundCommand
436-
{ PaymentTransaction = paymentTransaction, AmountToRefund = amountToRefund })).ToList();
384+
errors = (await _mediator.Send(new PartiallyRefundCommand { PaymentTransaction = paymentTransaction, AmountToRefund = amountToRefund })).ToList();
437385
else
438-
await _mediator.Send(new PartiallyRefundOfflineCommand
439-
{ PaymentTransaction = paymentTransaction, AmountToRefund = amountToRefund });
386+
await _mediator.Send(new PartiallyRefundOfflineCommand { PaymentTransaction = paymentTransaction, AmountToRefund = amountToRefund });
440387

441388
if (errors.Count == 0)
442389
{
@@ -466,10 +413,6 @@ public async Task<IActionResult> PartiallyPaidPopup(string id, bool online)
466413
if (paymentTransaction == null)
467414
return RedirectToAction("List", "PaymentTransaction");
468415

469-
if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer) &&
470-
paymentTransaction.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
471-
return RedirectToAction("List", "PaymentTransaction");
472-
473416
var model = new PaymentTransactionModel {
474417
Id = paymentTransaction.Id,
475418
MaxAmountToPaid = paymentTransaction.TransactionAmount - paymentTransaction.PaidAmount,
@@ -487,10 +430,6 @@ public async Task<IActionResult> PartiallyPaidPopup(string id, bool online, Paym
487430
if (paymentTransaction == null)
488431
return RedirectToAction("List", "PaymentTransaction");
489432

490-
if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer) &&
491-
paymentTransaction.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
492-
return RedirectToAction("List", "PaymentTransaction");
493-
494433
try
495434
{
496435
var amountToPaid = model.AmountToPaid;
@@ -501,8 +440,7 @@ public async Task<IActionResult> PartiallyPaidPopup(string id, bool online, Paym
501440
if (amountToPaid > maxAmountToPaid)
502441
amountToPaid = maxAmountToPaid;
503442

504-
await _mediator.Send(new PartiallyPaidOfflineCommand
505-
{ PaymentTransaction = paymentTransaction, AmountToPaid = amountToPaid });
443+
await _mediator.Send(new PartiallyPaidOfflineCommand { PaymentTransaction = paymentTransaction, AmountToPaid = amountToPaid });
506444

507445
ViewBag.RefreshPage = true;
508446
return View(model);
@@ -523,9 +461,6 @@ public async Task<IActionResult> Delete(string id)
523461
if (paymentTransaction == null)
524462
return RedirectToAction("List");
525463

526-
if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer) &&
527-
paymentTransaction.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
528-
return RedirectToAction("List", "MerchandiseReturn");
529464
if (ModelState.IsValid)
530465
{
531466
await _paymentTransactionService.DeletePaymentTransaction(paymentTransaction);

0 commit comments

Comments
 (0)