36 changed files with 560 additions and 282 deletions
@ -0,0 +1,17 @@ |
|||||
|
using JetBrains.Annotations; |
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace EShopOnAbp.PublicWeb.PaymentMethods; |
||||
|
|
||||
|
public class PaymentMethodUiOptions |
||||
|
{ |
||||
|
[NotNull] |
||||
|
public Dictionary<string, string> Icons { get; } = new(); |
||||
|
|
||||
|
public string DefaultIcon { get; set; } = "fa-credit-card demo"; |
||||
|
|
||||
|
public void ConfigureIcon(string paymentMethod, string iconCss) |
||||
|
{ |
||||
|
Icons[paymentMethod] = iconCss; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,43 @@ |
|||||
|
using EShopOnAbp.PaymentService.PaymentMethods; |
||||
|
using EShopOnAbp.PublicWeb.PaymentMethods; |
||||
|
using Microsoft.Extensions.Options; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
|
||||
|
namespace EShopOnAbp.PublicWeb.ServiceProviders; |
||||
|
|
||||
|
public class PaymentMethodProvider : ITransientDependency |
||||
|
{ |
||||
|
protected IPaymentMethodAppService PaymentMethodAppService { get; } |
||||
|
|
||||
|
private readonly PaymentMethodUiOptions _options; |
||||
|
|
||||
|
public PaymentMethodProvider( |
||||
|
IPaymentMethodAppService paymentMethodAppService, |
||||
|
IOptions<PaymentMethodUiOptions> options) |
||||
|
{ |
||||
|
PaymentMethodAppService = paymentMethodAppService; |
||||
|
_options = options.Value; |
||||
|
} |
||||
|
|
||||
|
public async Task<List<PaymentMethodViewModel>> GetPaymentMethodsAsync() |
||||
|
{ |
||||
|
var paymentMethods = await PaymentMethodAppService.GetListAsync(); |
||||
|
|
||||
|
return paymentMethods.Select((pm, i) => new PaymentMethodViewModel |
||||
|
{ |
||||
|
Name = pm.Name, |
||||
|
IsDefault = i == 0, |
||||
|
IconCss = _options.Icons.GetOrDefault(pm.Name)?? _options.DefaultIcon |
||||
|
}).ToList(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public class PaymentMethodViewModel |
||||
|
{ |
||||
|
public string Name { get; set; } |
||||
|
public string IconCss { get; set; } |
||||
|
public bool IsDefault { get; set; } |
||||
|
} |
||||
@ -1,24 +0,0 @@ |
|||||
using System.Collections.Generic; |
|
||||
using Volo.Abp.DependencyInjection; |
|
||||
|
|
||||
namespace EShopOnAbp.PublicWeb.ServiceProviders; |
|
||||
|
|
||||
public class PaymentTypeProvider : ITransientDependency |
|
||||
{ |
|
||||
public List<PaymentType> GetPaymentTypes() |
|
||||
{ |
|
||||
return new List<PaymentType> |
|
||||
{ |
|
||||
new() { Type = "demo", Name = "Demo", IconCss = "fa-credit-card demo", IsDefault = true}, |
|
||||
new() { Type = "paypal", Name = "Paypal", IconCss = "fa-cc-paypal paypal"} |
|
||||
}; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
public class PaymentType |
|
||||
{ |
|
||||
public string Type { get; set; } |
|
||||
public string Name { get; set; } |
|
||||
public string IconCss { get; set; } |
|
||||
public bool IsDefault { get; set; } = false; |
|
||||
} |
|
||||
@ -1,46 +0,0 @@ |
|||||
using System; |
|
||||
using System.Collections.Generic; |
|
||||
using System.Linq; |
|
||||
using Volo.Abp; |
|
||||
|
|
||||
namespace EShopOnAbp.OrderingService.Orders; |
|
||||
|
|
||||
public class PaymentType : Enumeration |
|
||||
{ |
|
||||
public static PaymentType Demo = new PaymentType(0, nameof(Demo).ToLowerInvariant()); |
|
||||
public static PaymentType Paypal = new PaymentType(1, nameof(Paypal).ToLowerInvariant()); |
|
||||
|
|
||||
public PaymentType(int id, string name) : base(id, name) |
|
||||
{ |
|
||||
} |
|
||||
|
|
||||
public static IEnumerable<PaymentType> List() => |
|
||||
new[] {Demo, Paypal}; |
|
||||
|
|
||||
public static PaymentType FromName(string name) |
|
||||
{ |
|
||||
var state = List() |
|
||||
.SingleOrDefault(s => String.Equals(s.Name, name, StringComparison.CurrentCultureIgnoreCase)); |
|
||||
|
|
||||
if (state == null) |
|
||||
{ |
|
||||
throw new BusinessException(OrderingServiceErrorCodes.PaymentTypeNotFound) |
|
||||
.WithData("PaymentType", String.Join(",", List().Select(s => s.Name))); |
|
||||
} |
|
||||
|
|
||||
return state; |
|
||||
} |
|
||||
|
|
||||
public static PaymentType From(int id) |
|
||||
{ |
|
||||
var state = List().SingleOrDefault(s => s.Id == id); |
|
||||
|
|
||||
if (state == null) |
|
||||
{ |
|
||||
throw new BusinessException(OrderingServiceErrorCodes.PaymentTypeNotFound) |
|
||||
.WithData("PaymentType", String.Join(",", List().Select(s => s.Name))); |
|
||||
} |
|
||||
|
|
||||
return state; |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,206 @@ |
|||||
|
// <auto-generated />
|
||||
|
using System; |
||||
|
using EShopOnAbp.OrderingService.EntityFrameworkCore; |
||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
using Microsoft.EntityFrameworkCore.Infrastructure; |
||||
|
using Microsoft.EntityFrameworkCore.Migrations; |
||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; |
||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; |
||||
|
using Volo.Abp.EntityFrameworkCore; |
||||
|
|
||||
|
#nullable disable |
||||
|
|
||||
|
namespace EShopOnAbp.OrderingService.Migrations |
||||
|
{ |
||||
|
[DbContext(typeof(OrderingServiceDbContext))] |
||||
|
[Migration("20220118084223_Removed_PaymentType")] |
||||
|
partial class Removed_PaymentType |
||||
|
{ |
||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder) |
||||
|
{ |
||||
|
#pragma warning disable 612, 618
|
||||
|
modelBuilder |
||||
|
.HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.PostgreSql) |
||||
|
.HasAnnotation("ProductVersion", "6.0.0") |
||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63); |
||||
|
|
||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); |
||||
|
|
||||
|
modelBuilder.Entity("EShopOnAbp.OrderingService.Orders.Order", b => |
||||
|
{ |
||||
|
b.Property<Guid>("Id") |
||||
|
.HasColumnType("uuid"); |
||||
|
|
||||
|
b.Property<string>("ConcurrencyStamp") |
||||
|
.IsConcurrencyToken() |
||||
|
.HasMaxLength(40) |
||||
|
.HasColumnType("character varying(40)") |
||||
|
.HasColumnName("ConcurrencyStamp"); |
||||
|
|
||||
|
b.Property<string>("ExtraProperties") |
||||
|
.HasColumnType("text") |
||||
|
.HasColumnName("ExtraProperties"); |
||||
|
|
||||
|
b.Property<DateTime>("OrderDate") |
||||
|
.HasColumnType("timestamp with time zone"); |
||||
|
|
||||
|
b.Property<int>("OrderNo") |
||||
|
.HasColumnType("integer"); |
||||
|
|
||||
|
b.Property<string>("PaymentMethod") |
||||
|
.HasColumnType("text"); |
||||
|
|
||||
|
b.Property<Guid?>("PaymentRequestId") |
||||
|
.HasColumnType("uuid"); |
||||
|
|
||||
|
b.Property<string>("PaymentStatus") |
||||
|
.HasMaxLength(256) |
||||
|
.HasColumnType("character varying(256)"); |
||||
|
|
||||
|
b.Property<int>("_orderStatusId") |
||||
|
.HasColumnType("integer") |
||||
|
.HasColumnName("OrderStatusId"); |
||||
|
|
||||
|
b.HasKey("Id"); |
||||
|
|
||||
|
b.HasIndex("_orderStatusId"); |
||||
|
|
||||
|
b.ToTable("Orders", (string)null); |
||||
|
}); |
||||
|
|
||||
|
modelBuilder.Entity("EShopOnAbp.OrderingService.Orders.OrderItem", b => |
||||
|
{ |
||||
|
b.Property<Guid>("Id") |
||||
|
.HasColumnType("uuid"); |
||||
|
|
||||
|
b.Property<decimal>("Discount") |
||||
|
.HasColumnType("numeric"); |
||||
|
|
||||
|
b.Property<Guid>("OrderId") |
||||
|
.HasColumnType("uuid"); |
||||
|
|
||||
|
b.Property<string>("PictureUrl") |
||||
|
.HasColumnType("text"); |
||||
|
|
||||
|
b.Property<string>("ProductCode") |
||||
|
.IsRequired() |
||||
|
.HasColumnType("text"); |
||||
|
|
||||
|
b.Property<Guid>("ProductId") |
||||
|
.HasColumnType("uuid"); |
||||
|
|
||||
|
b.Property<string>("ProductName") |
||||
|
.IsRequired() |
||||
|
.HasColumnType("text"); |
||||
|
|
||||
|
b.Property<decimal>("UnitPrice") |
||||
|
.HasColumnType("numeric"); |
||||
|
|
||||
|
b.Property<int>("Units") |
||||
|
.HasColumnType("integer"); |
||||
|
|
||||
|
b.HasKey("Id"); |
||||
|
|
||||
|
b.HasIndex("OrderId"); |
||||
|
|
||||
|
b.ToTable("OrderItems", (string)null); |
||||
|
}); |
||||
|
|
||||
|
modelBuilder.Entity("EShopOnAbp.OrderingService.Orders.OrderStatus", b => |
||||
|
{ |
||||
|
b.Property<int>("Id") |
||||
|
.HasColumnType("integer") |
||||
|
.HasDefaultValue(1); |
||||
|
|
||||
|
b.Property<string>("Name") |
||||
|
.IsRequired() |
||||
|
.HasMaxLength(256) |
||||
|
.HasColumnType("character varying(256)"); |
||||
|
|
||||
|
b.HasKey("Id"); |
||||
|
|
||||
|
b.ToTable("OrderStatus", (string)null); |
||||
|
}); |
||||
|
|
||||
|
modelBuilder.Entity("EShopOnAbp.OrderingService.Orders.Order", b => |
||||
|
{ |
||||
|
b.HasOne("EShopOnAbp.OrderingService.Orders.OrderStatus", "OrderStatus") |
||||
|
.WithMany() |
||||
|
.HasForeignKey("_orderStatusId") |
||||
|
.OnDelete(DeleteBehavior.Cascade) |
||||
|
.IsRequired(); |
||||
|
|
||||
|
b.OwnsOne("EShopOnAbp.OrderingService.Orders.Address", "Address", b1 => |
||||
|
{ |
||||
|
b1.Property<Guid>("OrderId") |
||||
|
.HasColumnType("uuid"); |
||||
|
|
||||
|
b1.Property<string>("City") |
||||
|
.HasColumnType("text"); |
||||
|
|
||||
|
b1.Property<string>("Country") |
||||
|
.HasColumnType("text"); |
||||
|
|
||||
|
b1.Property<string>("Description") |
||||
|
.HasColumnType("text"); |
||||
|
|
||||
|
b1.Property<string>("Street") |
||||
|
.HasColumnType("text"); |
||||
|
|
||||
|
b1.Property<string>("ZipCode") |
||||
|
.HasColumnType("text"); |
||||
|
|
||||
|
b1.HasKey("OrderId"); |
||||
|
|
||||
|
b1.ToTable("Orders"); |
||||
|
|
||||
|
b1.WithOwner() |
||||
|
.HasForeignKey("OrderId"); |
||||
|
}); |
||||
|
|
||||
|
b.OwnsOne("EShopOnAbp.OrderingService.Orders.Buyer", "Buyer", b1 => |
||||
|
{ |
||||
|
b1.Property<Guid>("OrderId") |
||||
|
.HasColumnType("uuid"); |
||||
|
|
||||
|
b1.Property<string>("Email") |
||||
|
.HasColumnType("text"); |
||||
|
|
||||
|
b1.Property<Guid?>("Id") |
||||
|
.HasColumnType("uuid"); |
||||
|
|
||||
|
b1.Property<string>("Name") |
||||
|
.HasColumnType("text"); |
||||
|
|
||||
|
b1.HasKey("OrderId"); |
||||
|
|
||||
|
b1.ToTable("Orders"); |
||||
|
|
||||
|
b1.WithOwner() |
||||
|
.HasForeignKey("OrderId"); |
||||
|
}); |
||||
|
|
||||
|
b.Navigation("Address"); |
||||
|
|
||||
|
b.Navigation("Buyer"); |
||||
|
|
||||
|
b.Navigation("OrderStatus"); |
||||
|
}); |
||||
|
|
||||
|
modelBuilder.Entity("EShopOnAbp.OrderingService.Orders.OrderItem", b => |
||||
|
{ |
||||
|
b.HasOne("EShopOnAbp.OrderingService.Orders.Order", null) |
||||
|
.WithMany("OrderItems") |
||||
|
.HasForeignKey("OrderId") |
||||
|
.OnDelete(DeleteBehavior.Cascade) |
||||
|
.IsRequired(); |
||||
|
}); |
||||
|
|
||||
|
modelBuilder.Entity("EShopOnAbp.OrderingService.Orders.Order", b => |
||||
|
{ |
||||
|
b.Navigation("OrderItems"); |
||||
|
}); |
||||
|
#pragma warning restore 612, 618
|
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,72 @@ |
|||||
|
using Microsoft.EntityFrameworkCore.Migrations; |
||||
|
|
||||
|
#nullable disable |
||||
|
|
||||
|
namespace EShopOnAbp.OrderingService.Migrations |
||||
|
{ |
||||
|
public partial class Removed_PaymentType : Migration |
||||
|
{ |
||||
|
protected override void Up(MigrationBuilder migrationBuilder) |
||||
|
{ |
||||
|
migrationBuilder.DropForeignKey( |
||||
|
name: "FK_Orders_PaymentTypes_PaymentTypeId", |
||||
|
table: "Orders"); |
||||
|
|
||||
|
migrationBuilder.DropTable( |
||||
|
name: "PaymentTypes"); |
||||
|
|
||||
|
migrationBuilder.DropIndex( |
||||
|
name: "IX_Orders_PaymentTypeId", |
||||
|
table: "Orders"); |
||||
|
|
||||
|
migrationBuilder.DropColumn( |
||||
|
name: "PaymentTypeId", |
||||
|
table: "Orders"); |
||||
|
|
||||
|
migrationBuilder.AddColumn<string>( |
||||
|
name: "PaymentMethod", |
||||
|
table: "Orders", |
||||
|
type: "text", |
||||
|
nullable: true); |
||||
|
} |
||||
|
|
||||
|
protected override void Down(MigrationBuilder migrationBuilder) |
||||
|
{ |
||||
|
migrationBuilder.DropColumn( |
||||
|
name: "PaymentMethod", |
||||
|
table: "Orders"); |
||||
|
|
||||
|
migrationBuilder.AddColumn<int>( |
||||
|
name: "PaymentTypeId", |
||||
|
table: "Orders", |
||||
|
type: "integer", |
||||
|
nullable: false, |
||||
|
defaultValue: 0); |
||||
|
|
||||
|
migrationBuilder.CreateTable( |
||||
|
name: "PaymentTypes", |
||||
|
columns: table => new |
||||
|
{ |
||||
|
Id = table.Column<int>(type: "integer", nullable: false, defaultValue: 1), |
||||
|
Name = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false) |
||||
|
}, |
||||
|
constraints: table => |
||||
|
{ |
||||
|
table.PrimaryKey("PK_PaymentTypes", x => x.Id); |
||||
|
}); |
||||
|
|
||||
|
migrationBuilder.CreateIndex( |
||||
|
name: "IX_Orders_PaymentTypeId", |
||||
|
table: "Orders", |
||||
|
column: "PaymentTypeId"); |
||||
|
|
||||
|
migrationBuilder.AddForeignKey( |
||||
|
name: "FK_Orders_PaymentTypes_PaymentTypeId", |
||||
|
table: "Orders", |
||||
|
column: "PaymentTypeId", |
||||
|
principalTable: "PaymentTypes", |
||||
|
principalColumn: "Id", |
||||
|
onDelete: ReferentialAction.Cascade); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,23 @@ |
|||||
|
// This file is automatically generated by ABP framework to use MVC Controllers from CSharp
|
||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Application.Dtos; |
||||
|
using Volo.Abp.Http.Client; |
||||
|
using Volo.Abp.Http.Modeling; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.Http.Client.ClientProxying; |
||||
|
using EShopOnAbp.PaymentService.PaymentMethods; |
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
// ReSharper disable once CheckNamespace
|
||||
|
namespace EShopOnAbp.PaymentService.Controllers.ClientProxies; |
||||
|
|
||||
|
[Dependency(ReplaceServices = true)] |
||||
|
[ExposeServices(typeof(IPaymentMethodAppService), typeof(PaymentMethodClientProxy))] |
||||
|
public partial class PaymentMethodClientProxy : ClientProxyBase<IPaymentMethodAppService>, IPaymentMethodAppService |
||||
|
{ |
||||
|
public virtual async Task<List<PaymentMethodDto>> GetListAsync() |
||||
|
{ |
||||
|
return await RequestAsync<List<PaymentMethodDto>>(nameof(GetListAsync)); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,7 @@ |
|||||
|
// This file is part of PaymentMethodClientProxy, you can customize it here
|
||||
|
// ReSharper disable once CheckNamespace
|
||||
|
namespace EShopOnAbp.PaymentService.Controllers.ClientProxies; |
||||
|
|
||||
|
public partial class PaymentMethodClientProxy |
||||
|
{ |
||||
|
} |
||||
Loading…
Reference in new issue