mirror of https://github.com/EasyAbp/EShop.git
14 changed files with 109 additions and 121 deletions
@ -1,13 +0,0 @@ |
|||
using System; |
|||
using Volo.Abp; |
|||
|
|||
namespace EasyAbp.EShop.Payments.Payments |
|||
{ |
|||
public class PaymentAlreadyExistsException : BusinessException |
|||
{ |
|||
public PaymentAlreadyExistsException(Guid orderId) |
|||
: base(message: $"The order {orderId}'s payment is already exists.") |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -1,29 +0,0 @@ |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using EasyAbp.EShop.Orders.Orders.Dtos; |
|||
using EasyAbp.EShop.Payments.Payments.Dtos; |
|||
using EasyAbp.PaymentService.Payments; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace EasyAbp.EShop.Payments.Payments |
|||
{ |
|||
public class BasicPayableCheckProvider : IPayableCheckProvider, ITransientDependency |
|||
{ |
|||
public virtual Task CheckAsync(CreatePaymentDto input, List<OrderDto> orders, CreatePaymentEto createPaymentEto) |
|||
{ |
|||
foreach (var order in orders.Where(order => order.PaymentId.HasValue || order.PaidTime.HasValue)) |
|||
{ |
|||
throw new PaymentAlreadyExistsException(order.Id); |
|||
} |
|||
|
|||
if (orders.Select(order => order.Currency).Distinct().Count() != 1) |
|||
{ |
|||
// Todo: convert to a single currency.
|
|||
throw new MultiCurrencyNotSupportedException(); |
|||
} |
|||
|
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
|
|||
namespace EasyAbp.EShop.Payments.Payments |
|||
{ |
|||
public class BasicPaymentCreationAuthorizationHandler : PaymentCreationAuthorizationHandler |
|||
{ |
|||
|
|||
public BasicPaymentCreationAuthorizationHandler() |
|||
{ |
|||
} |
|||
|
|||
protected override Task HandlePaymentCreationAsync(AuthorizationHandlerContext context, |
|||
PaymentOperationAuthorizationRequirement requirement, PaymentCreationResource resource) |
|||
{ |
|||
if (resource.Orders.Any(order => order.PaymentId.HasValue || order.PaidTime.HasValue)) |
|||
{ |
|||
context.Fail(); |
|||
} |
|||
|
|||
if (resource.Orders.Select(order => order.Currency).Distinct().Count() != 1) |
|||
{ |
|||
// Todo: convert to a single currency.
|
|||
context.Fail(); |
|||
} |
|||
|
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
} |
|||
@ -1,13 +0,0 @@ |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using EasyAbp.EShop.Orders.Orders.Dtos; |
|||
using EasyAbp.EShop.Payments.Payments.Dtos; |
|||
using EasyAbp.PaymentService.Payments; |
|||
|
|||
namespace EasyAbp.EShop.Payments.Payments |
|||
{ |
|||
public interface IPayableCheckProvider |
|||
{ |
|||
Task CheckAsync(CreatePaymentDto input, List<OrderDto> orders, CreatePaymentEto createPaymentEto); |
|||
} |
|||
} |
|||
@ -1,14 +0,0 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using EasyAbp.EShop.Orders.Orders.Dtos; |
|||
using EasyAbp.EShop.Payments.Payments.Dtos; |
|||
using EasyAbp.PaymentService.Payments; |
|||
|
|||
namespace EasyAbp.EShop.Payments.Payments |
|||
{ |
|||
public interface IPayableChecker |
|||
{ |
|||
Task CheckAsync(CreatePaymentDto input, List<OrderDto> orders, CreatePaymentEto createPaymentEto); |
|||
} |
|||
} |
|||
@ -1,12 +0,0 @@ |
|||
using Volo.Abp; |
|||
|
|||
namespace EasyAbp.EShop.Payments.Payments |
|||
{ |
|||
public class MultiCurrencyNotSupportedException : BusinessException |
|||
{ |
|||
public MultiCurrencyNotSupportedException() : base(message: $"The currency of all orders should be the same.") |
|||
{ |
|||
|
|||
} |
|||
} |
|||
} |
|||
@ -1,32 +0,0 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using EasyAbp.EShop.Orders.Orders.Dtos; |
|||
using EasyAbp.EShop.Payments.Payments.Dtos; |
|||
using EasyAbp.PaymentService.Payments; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace EasyAbp.EShop.Payments.Payments |
|||
{ |
|||
public class PayableChecker : IPayableChecker, ITransientDependency |
|||
{ |
|||
private readonly IServiceProvider _serviceProvider; |
|||
|
|||
public PayableChecker(IServiceProvider serviceProvider) |
|||
{ |
|||
_serviceProvider = serviceProvider; |
|||
} |
|||
|
|||
|
|||
public virtual async Task CheckAsync(CreatePaymentDto input, List<OrderDto> orders, CreatePaymentEto createPaymentEto) |
|||
{ |
|||
var providers = _serviceProvider.GetServices<IPayableCheckProvider>(); |
|||
|
|||
foreach (var provider in providers) |
|||
{ |
|||
await provider.CheckAsync(input, orders, createPaymentEto); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
|
|||
namespace EasyAbp.EShop.Payments.Payments |
|||
{ |
|||
public abstract class PaymentCreationAuthorizationHandler : AuthorizationHandler<PaymentOperationAuthorizationRequirement, PaymentCreationResource> |
|||
{ |
|||
protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, PaymentOperationAuthorizationRequirement requirement, |
|||
PaymentCreationResource resource) |
|||
{ |
|||
if (requirement.PaymentOperation != PaymentOperation.Creation) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
await HandlePaymentCreationAsync(context, requirement, resource); |
|||
} |
|||
|
|||
protected abstract Task HandlePaymentCreationAsync(AuthorizationHandlerContext context, |
|||
PaymentOperationAuthorizationRequirement requirement, PaymentCreationResource resource); |
|||
} |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
using System.Collections.Generic; |
|||
using EasyAbp.EShop.Orders.Orders.Dtos; |
|||
using EasyAbp.EShop.Payments.Payments.Dtos; |
|||
using EasyAbp.PaymentService.Payments; |
|||
|
|||
namespace EasyAbp.EShop.Payments.Payments |
|||
{ |
|||
public class PaymentCreationResource |
|||
{ |
|||
public CreatePaymentDto Input { get; set; } |
|||
|
|||
public List<OrderDto> Orders { get; set; } |
|||
|
|||
public CreatePaymentEto CreatePaymentEto { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
using System; |
|||
|
|||
namespace EasyAbp.EShop.Payments.Payments |
|||
{ |
|||
[Flags] |
|||
public enum PaymentOperation |
|||
{ |
|||
Creation = 0 |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
using JetBrains.Annotations; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
|
|||
namespace EasyAbp.EShop.Payments.Payments |
|||
{ |
|||
public class PaymentOperationAuthorizationRequirement : IAuthorizationRequirement |
|||
{ |
|||
public PaymentOperation PaymentOperation { get; } |
|||
|
|||
public PaymentOperationAuthorizationRequirement(PaymentOperation paymentOperation) |
|||
{ |
|||
PaymentOperation = paymentOperation; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue