Browse Source

Added payment type to buyer

pull/53/head
Galip Tolga Erdem 4 years ago
parent
commit
7fb9831a1b
  1. 1
      services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Localization/OrderingService/en.json
  2. 1
      services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Localization/OrderingService/tr.json
  3. 1
      services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/OrderingServiceErrorCodes.cs
  4. 15
      services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/Buyer.cs
  5. 47
      services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/PaymentType.cs

1
services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Localization/OrderingService/en.json

@ -4,6 +4,7 @@
"MyAccount": "My account",
"SamplePageMessage": "A sample page for the OrderingService module",
"Ordering:00001": "Possible values for Order status: {0}",
"Ordering:00011": "Possible values for Payment types: {0}",
"Ordering:00002": "Invalid number of units",
"Ordering:00003": "Invalid discount",
"Ordering:00004": "The total of order item is lower than applied discount"

1
services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Localization/OrderingService/tr.json

@ -4,6 +4,7 @@
"MyAccount": "Hesabım",
"SamplePageMessage": "OrderingService modulünden örnek bir sayfa",
"Ordering:00001": "Muhtemel Sipariş durum değerleri: {0}",
"Ordering:00011": "Muhtemel Ödeme türleri: {0}",
"Ordering:00002": "Ürün adedi negatif olamaz",
"Ordering:00003": "Geçersiz indirim",
"Ordering:00004": "Ürünlerin toplam bedeli, uygulanan indirimden daha az olamaz"

1
services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/OrderingServiceErrorCodes.cs

@ -3,6 +3,7 @@
public static class OrderingServiceErrorCodes
{
public const string OrderingStatusNotFound = "Ordering:00001";
public const string PaymentTypeNotFound = "Ordering:00011";
public const string InvalidUnits = "Ordering:00002";
public const string InvalidDiscount = "Ordering:00003";
public const string InvalidTotalForDiscount = "Ordering:00004";

15
services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/Buyer.cs

@ -7,18 +7,23 @@ namespace EShopOnAbp.OrderingService.Buyers;
public class Buyer : AggregateRoot<Guid>
{
public string UserName { get; private set; }
private int _paymentTypeId;
public string Name { get; private set; }
public string PaymentId { get; private set; }
public string Email { get; private set; }
public PaymentType PaymentType { get; private set; }
private Buyer()
{
}
public Buyer(Guid id, [NotNull] string userName, [NotNull] string name, [NotNull] string paymentId) : base(id)
public Buyer(Guid id,
[NotNull] string userName,
[NotNull] string name,
[NotNull] string email,
PaymentType paymentType) : base(id)
{
UserName = Check.NotNullOrEmpty(userName, nameof(userName));
_paymentTypeId = PaymentType.FromName(paymentType.Name).Id;
Name = Check.NotNullOrEmpty(name, nameof(name));
PaymentId = Check.NotNullOrEmpty(paymentId, nameof(paymentId));
Email = Check.NotNullOrEmpty(email, nameof(email));
}
}

47
services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/PaymentType.cs

@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Volo.Abp;
namespace EShopOnAbp.OrderingService.Buyers;
public class PaymentType : Enumeration
{
public static PaymentType Paypal = new PaymentType(1, nameof(Paypal).ToLowerInvariant());
public static PaymentType Visa = new PaymentType(1, nameof(Visa).ToLowerInvariant());
public static PaymentType MasterCard = new PaymentType(1, nameof(MasterCard).ToLowerInvariant());
public PaymentType(int id, string name) : base(id, name)
{
}
public static IEnumerable<PaymentType> List() =>
new[] {Paypal, Visa, Visa, MasterCard};
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;
}
}
Loading…
Cancel
Save