mirror of https://github.com/EasyAbp/EShop.git
71 changed files with 4108 additions and 194 deletions
@ -0,0 +1,10 @@ |
|||
using System.Threading.Tasks; |
|||
using EasyAbp.PaymentService.Payments; |
|||
|
|||
namespace EasyAbp.EShop.Orders.Orders |
|||
{ |
|||
public interface IOrderPaymentChecker |
|||
{ |
|||
Task<bool> IsValidPaymentAsync(Order order, PaymentEto paymentEto); |
|||
} |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using EasyAbp.PaymentService.Payments; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace EasyAbp.EShop.Orders.Orders |
|||
{ |
|||
public class OrderPaymentChecker : IOrderPaymentChecker, ITransientDependency |
|||
{ |
|||
public Task<bool> IsValidPaymentAsync(Order order, PaymentEto paymentEto) |
|||
{ |
|||
return Task.FromResult( |
|||
Guid.TryParse(paymentEto.GetProperty<string>("StoreId"), out var paymentStoreId) && |
|||
order.StoreId == paymentStoreId |
|||
); |
|||
} |
|||
} |
|||
} |
|||
@ -1,10 +1,33 @@ |
|||
using System; |
|||
using PaymentServicePaymentDto = EasyAbp.PaymentService.Payments.Dtos.PaymentDto; |
|||
using System.Collections.Generic; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace EasyAbp.EShop.Payments.Payments.Dtos |
|||
{ |
|||
public class PaymentDto : PaymentServicePaymentDto |
|||
public class PaymentDto : ExtensibleFullAuditedEntityDto<Guid> |
|||
{ |
|||
public Guid? StoreId { get; set; } |
|||
|
|||
public Guid UserId { get; set; } |
|||
|
|||
public string PaymentMethod { get; set; } |
|||
|
|||
public string ExternalTradingCode { get; set; } |
|||
|
|||
public string Currency { get; set; } |
|||
|
|||
public decimal OriginalPaymentAmount { get; set; } |
|||
|
|||
public decimal PaymentDiscount { get; set; } |
|||
|
|||
public decimal ActualPaymentAmount { get; set; } |
|||
|
|||
public decimal RefundAmount { get; set; } |
|||
|
|||
public DateTime? CompletionTime { get; set; } |
|||
|
|||
public DateTime? CancelledTime { get; set; } |
|||
|
|||
public List<PaymentItemDto> PaymentItems { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace EasyAbp.EShop.Payments.Payments.Dtos |
|||
{ |
|||
public class PaymentItemDto : FullAuditedEntityDto<Guid> |
|||
{ |
|||
public string ItemType { get; set; } |
|||
|
|||
public Guid ItemKey { get; set; } |
|||
|
|||
public string Currency { get; set; } |
|||
|
|||
public decimal OriginalPaymentAmount { get; set; } |
|||
|
|||
public decimal PaymentDiscount { get; set; } |
|||
|
|||
public decimal ActualPaymentAmount { get; set; } |
|||
|
|||
public decimal RefundAmount { get; set; } |
|||
} |
|||
} |
|||
@ -1,11 +1,26 @@ |
|||
using System; |
|||
using Volo.Abp.Application.Dtos; |
|||
using PaymentServiceRefundDto = EasyAbp.PaymentService.Refunds.Dtos.RefundDto; |
|||
|
|||
namespace EasyAbp.EShop.Payments.Refunds.Dtos |
|||
{ |
|||
public class RefundDto : PaymentServiceRefundDto |
|||
public class RefundDto : FullAuditedEntityDto<Guid> |
|||
{ |
|||
public Guid? StoreId { get; set; } |
|||
|
|||
public Guid PaymentId { get; set; } |
|||
|
|||
public Guid PaymentItemId { get; set; } |
|||
|
|||
public string RefundPaymentMethod { get; set; } |
|||
|
|||
public string ExternalTradingCode { get; set; } |
|||
|
|||
public string Currency { get; set; } |
|||
|
|||
public decimal RefundAmount { get; set; } |
|||
|
|||
public string CustomerRemark { get; set; } |
|||
|
|||
public string StaffRemark { get; set; } |
|||
} |
|||
} |
|||
@ -1,74 +0,0 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using EasyAbp.EShop.Orders.Orders; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Users; |
|||
|
|||
namespace EasyAbp.PaymentService.Payments |
|||
{ |
|||
public class EShopOrderPaymentAuthorizer : IPaymentAuthorizer, ITransientDependency |
|||
{ |
|||
private readonly ICurrentUser _currentUser; |
|||
private readonly IOrderAppService _orderAppService; |
|||
|
|||
public EShopOrderPaymentAuthorizer( |
|||
ICurrentUser currentUser, |
|||
IOrderAppService orderAppService) |
|||
{ |
|||
_currentUser = currentUser; |
|||
_orderAppService = orderAppService; |
|||
} |
|||
|
|||
public virtual async Task<bool> IsPaymentItemAllowedAsync(Payment payment, PaymentItem paymentItem, |
|||
Dictionary<string, object> inputExtraProperties) |
|||
{ |
|||
if (paymentItem.ItemType != "EasyAbpEShopOrder") |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
var order = await _orderAppService.GetAsync(paymentItem.ItemKey); |
|||
|
|||
if (order.CustomerUserId != _currentUser.Id) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
if (order.TotalPrice != paymentItem.OriginalPaymentAmount) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
if (!order.ReducedInventoryAfterPlacingTime.HasValue) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
var inputStoreIdString = inputExtraProperties.GetOrDefault("StoreId") as string; |
|||
|
|||
if (order.StoreId.ToString() != inputStoreIdString) |
|||
{ |
|||
if (inputStoreIdString == null) |
|||
{ |
|||
inputExtraProperties.Add("StoreId", order.StoreId); |
|||
} |
|||
else |
|||
{ |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
if (order.OrderStatus != OrderStatus.Pending) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
// Record the StoreId so EasyAbp.EShop.Payments.Payments.Payment entity can use it.
|
|||
payment.SetProperty("StoreId", order.StoreId); |
|||
|
|||
return true; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
using System; |
|||
using EasyAbp.PaymentService.Payments; |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.Domain.Entities.Auditing; |
|||
|
|||
namespace EasyAbp.EShop.Payments.Payments |
|||
{ |
|||
public class PaymentItem : FullAuditedEntity<Guid>, IPaymentItem |
|||
{ |
|||
#region Base properties
|
|||
|
|||
[NotNull] |
|||
public virtual string ItemType { get; protected set; } |
|||
|
|||
public virtual Guid ItemKey { get; protected set; } |
|||
|
|||
[NotNull] |
|||
public virtual string Currency { get; protected set; } |
|||
|
|||
public virtual decimal OriginalPaymentAmount { get; protected set; } |
|||
|
|||
public virtual decimal PaymentDiscount { get; protected set; } |
|||
|
|||
public virtual decimal ActualPaymentAmount { get; protected set; } |
|||
|
|||
public virtual decimal RefundAmount { get; protected set; } |
|||
|
|||
#endregion
|
|||
|
|||
private PaymentItem() |
|||
{ |
|||
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,50 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using EasyAbp.PaymentService.Payments; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Domain.Entities.Events.Distributed; |
|||
using Volo.Abp.EventBus.Distributed; |
|||
using Volo.Abp.ObjectMapping; |
|||
|
|||
namespace EasyAbp.EShop.Payments.Payments |
|||
{ |
|||
public class PaymentSynchronizer : |
|||
IDistributedEventHandler<EntityUpdatedEto<PaymentEto>>, |
|||
ITransientDependency |
|||
{ |
|||
private readonly IObjectMapper _objectMapper; |
|||
private readonly IPaymentRepository _paymentRepository; |
|||
|
|||
public PaymentSynchronizer( |
|||
IObjectMapper objectMapper, |
|||
IPaymentRepository paymentRepository) |
|||
{ |
|||
_objectMapper = objectMapper; |
|||
_paymentRepository = paymentRepository; |
|||
} |
|||
|
|||
public async Task HandleEventAsync(EntityUpdatedEto<PaymentEto> eventData) |
|||
{ |
|||
var payment = await _paymentRepository.FindAsync(eventData.Entity.Id); |
|||
|
|||
if (payment == null) |
|||
{ |
|||
payment = _objectMapper.Map<PaymentEto, Payment>(eventData.Entity); |
|||
|
|||
if (Guid.TryParse(eventData.Entity.GetProperty<string>("StoreId"), out var storeId)) |
|||
{ |
|||
payment.SetStoreId(storeId); |
|||
} |
|||
|
|||
await _paymentRepository.InsertAsync(payment, true); |
|||
} |
|||
else |
|||
{ |
|||
_objectMapper.Map(eventData.Entity, payment); |
|||
|
|||
await _paymentRepository.UpdateAsync(payment, true); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,29 +0,0 @@ |
|||
using System; |
|||
using EasyAbp.PaymentService.Payments; |
|||
using EasyAbp.PaymentService.Refunds; |
|||
using Volo.Abp.ObjectExtending; |
|||
using Volo.Abp.Threading; |
|||
|
|||
namespace EasyAbp.EShop.Payments.EntityFrameworkCore |
|||
{ |
|||
public static class EShopPaymentsEfCoreEntityExtensionMappings |
|||
{ |
|||
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner(); |
|||
|
|||
public static void Configure() |
|||
{ |
|||
OneTimeRunner.Run(() => |
|||
{ |
|||
ObjectExtensionManager.Instance |
|||
.MapEfCoreProperty<Payment, Guid?>( |
|||
"StoreId" |
|||
); |
|||
|
|||
ObjectExtensionManager.Instance |
|||
.MapEfCoreProperty<Refund, Guid?>( |
|||
"StoreId" |
|||
); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
@ -0,0 +1,143 @@ |
|||
using System; |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
|
|||
namespace EShopSample.Migrations |
|||
{ |
|||
public partial class MadePaymentAndRefundExclusiveTableEntities : Migration |
|||
{ |
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.DropColumn( |
|||
name: "StoreId", |
|||
table: "PaymentServiceRefunds"); |
|||
|
|||
migrationBuilder.DropColumn( |
|||
name: "StoreId", |
|||
table: "PaymentServicePayments"); |
|||
|
|||
migrationBuilder.CreateTable( |
|||
name: "EShopPaymentsPayments", |
|||
columns: table => new |
|||
{ |
|||
Id = table.Column<Guid>(nullable: false), |
|||
ExtraProperties = table.Column<string>(nullable: true), |
|||
ConcurrencyStamp = table.Column<string>(nullable: true), |
|||
CreationTime = table.Column<DateTime>(nullable: false), |
|||
CreatorId = table.Column<Guid>(nullable: true), |
|||
LastModificationTime = table.Column<DateTime>(nullable: true), |
|||
LastModifierId = table.Column<Guid>(nullable: true), |
|||
IsDeleted = table.Column<bool>(nullable: false, defaultValue: false), |
|||
DeleterId = table.Column<Guid>(nullable: true), |
|||
DeletionTime = table.Column<DateTime>(nullable: true), |
|||
TenantId = table.Column<Guid>(nullable: true), |
|||
UserId = table.Column<Guid>(nullable: false), |
|||
PaymentMethod = table.Column<string>(nullable: true), |
|||
PayeeAccount = table.Column<string>(nullable: true), |
|||
ExternalTradingCode = table.Column<string>(nullable: true), |
|||
Currency = table.Column<string>(nullable: true), |
|||
OriginalPaymentAmount = table.Column<decimal>(type: "decimal(18,6)", nullable: false), |
|||
PaymentDiscount = table.Column<decimal>(type: "decimal(18,6)", nullable: false), |
|||
ActualPaymentAmount = table.Column<decimal>(type: "decimal(18,6)", nullable: false), |
|||
RefundAmount = table.Column<decimal>(type: "decimal(18,6)", nullable: false), |
|||
CompletionTime = table.Column<DateTime>(nullable: true), |
|||
CancelledTime = table.Column<DateTime>(nullable: true), |
|||
StoreId = table.Column<Guid>(nullable: true) |
|||
}, |
|||
constraints: table => |
|||
{ |
|||
table.PrimaryKey("PK_EShopPaymentsPayments", x => x.Id); |
|||
}); |
|||
|
|||
migrationBuilder.CreateTable( |
|||
name: "EShopPaymentsRefunds", |
|||
columns: table => new |
|||
{ |
|||
Id = table.Column<Guid>(nullable: false), |
|||
ExtraProperties = table.Column<string>(nullable: true), |
|||
ConcurrencyStamp = table.Column<string>(nullable: true), |
|||
CreationTime = table.Column<DateTime>(nullable: false), |
|||
CreatorId = table.Column<Guid>(nullable: true), |
|||
LastModificationTime = table.Column<DateTime>(nullable: true), |
|||
LastModifierId = table.Column<Guid>(nullable: true), |
|||
IsDeleted = table.Column<bool>(nullable: false, defaultValue: false), |
|||
DeleterId = table.Column<Guid>(nullable: true), |
|||
DeletionTime = table.Column<DateTime>(nullable: true), |
|||
TenantId = table.Column<Guid>(nullable: true), |
|||
PaymentId = table.Column<Guid>(nullable: false), |
|||
PaymentItemId = table.Column<Guid>(nullable: false), |
|||
RefundPaymentMethod = table.Column<string>(nullable: true), |
|||
ExternalTradingCode = table.Column<string>(nullable: true), |
|||
Currency = table.Column<string>(nullable: true), |
|||
RefundAmount = table.Column<decimal>(type: "decimal(18,6)", nullable: false), |
|||
CustomerRemark = table.Column<string>(nullable: true), |
|||
StaffRemark = table.Column<string>(nullable: true), |
|||
StoreId = table.Column<Guid>(nullable: true) |
|||
}, |
|||
constraints: table => |
|||
{ |
|||
table.PrimaryKey("PK_EShopPaymentsRefunds", x => x.Id); |
|||
}); |
|||
|
|||
migrationBuilder.CreateTable( |
|||
name: "EShopPaymentsPaymentItems", |
|||
columns: table => new |
|||
{ |
|||
Id = table.Column<Guid>(nullable: false), |
|||
CreationTime = table.Column<DateTime>(nullable: false), |
|||
CreatorId = table.Column<Guid>(nullable: true), |
|||
LastModificationTime = table.Column<DateTime>(nullable: true), |
|||
LastModifierId = table.Column<Guid>(nullable: true), |
|||
IsDeleted = table.Column<bool>(nullable: false, defaultValue: false), |
|||
DeleterId = table.Column<Guid>(nullable: true), |
|||
DeletionTime = table.Column<DateTime>(nullable: true), |
|||
ItemType = table.Column<string>(nullable: true), |
|||
ItemKey = table.Column<Guid>(nullable: false), |
|||
Currency = table.Column<string>(nullable: true), |
|||
OriginalPaymentAmount = table.Column<decimal>(type: "decimal(18,6)", nullable: false), |
|||
PaymentDiscount = table.Column<decimal>(type: "decimal(18,6)", nullable: false), |
|||
ActualPaymentAmount = table.Column<decimal>(type: "decimal(18,6)", nullable: false), |
|||
RefundAmount = table.Column<decimal>(type: "decimal(18,6)", nullable: false), |
|||
PaymentId = table.Column<Guid>(nullable: true) |
|||
}, |
|||
constraints: table => |
|||
{ |
|||
table.PrimaryKey("PK_EShopPaymentsPaymentItems", x => x.Id); |
|||
table.ForeignKey( |
|||
name: "FK_EShopPaymentsPaymentItems_EShopPaymentsPayments_PaymentId", |
|||
column: x => x.PaymentId, |
|||
principalTable: "EShopPaymentsPayments", |
|||
principalColumn: "Id", |
|||
onDelete: ReferentialAction.Restrict); |
|||
}); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_EShopPaymentsPaymentItems_PaymentId", |
|||
table: "EShopPaymentsPaymentItems", |
|||
column: "PaymentId"); |
|||
} |
|||
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.DropTable( |
|||
name: "EShopPaymentsPaymentItems"); |
|||
|
|||
migrationBuilder.DropTable( |
|||
name: "EShopPaymentsRefunds"); |
|||
|
|||
migrationBuilder.DropTable( |
|||
name: "EShopPaymentsPayments"); |
|||
|
|||
migrationBuilder.AddColumn<Guid>( |
|||
name: "StoreId", |
|||
table: "PaymentServiceRefunds", |
|||
type: "uniqueidentifier", |
|||
nullable: true); |
|||
|
|||
migrationBuilder.AddColumn<Guid>( |
|||
name: "StoreId", |
|||
table: "PaymentServicePayments", |
|||
type: "uniqueidentifier", |
|||
nullable: true); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue