diff --git a/client/MAVN.Service.SmartVouchers.Client/Models/Responses/Enums/RedeemVoucherErrorCodes.cs b/client/MAVN.Service.SmartVouchers.Client/Models/Responses/Enums/RedeemVoucherErrorCodes.cs
index 0457cbd..b1786ec 100644
--- a/client/MAVN.Service.SmartVouchers.Client/Models/Responses/Enums/RedeemVoucherErrorCodes.cs
+++ b/client/MAVN.Service.SmartVouchers.Client/Models/Responses/Enums/RedeemVoucherErrorCodes.cs
@@ -15,5 +15,9 @@ public enum RedeemVoucherErrorCodes
VoucherCampaignNotFound,
/// Voucher campaign not active
VoucherCampaignNotActive,
+ /// The passed seller id does not have a linked partner id
+ SellerCustomerIsNotALinkedPartner,
+ /// The passed seller id does not match the voucher issuer id
+ SellerCustomerIsNotTheVoucherIssuer,
}
}
diff --git a/settings.yaml b/settings.yaml
index 5dc9cde..f544cc3 100644
--- a/settings.yaml
+++ b/settings.yaml
@@ -76,3 +76,6 @@ MonitoringServiceClient:
PaymentManagementServiceClient:
ServiceUrl:
settings-key: PaymentManagementServiceUrl
+PartnerManagementServiceClient:
+ ServiceUrl:
+ settings-key: PartnerManagementServiceUrl
\ No newline at end of file
diff --git a/src/MAVN.Job.SmartVouchers/Modules/ServiceModule.cs b/src/MAVN.Job.SmartVouchers/Modules/ServiceModule.cs
index 5e55ce6..60fa5ee 100644
--- a/src/MAVN.Job.SmartVouchers/Modules/ServiceModule.cs
+++ b/src/MAVN.Job.SmartVouchers/Modules/ServiceModule.cs
@@ -5,6 +5,7 @@
using Lykke.SettingsReader;
using MAVN.Job.SmartVouchers.Services;
using MAVN.Job.SmartVouchers.Settings;
+using MAVN.Service.PartnerManagement.Client;
using MAVN.Service.PaymentManagement.Client;
using MAVN.Service.SmartVouchers.Domain.Services;
using MAVN.Service.SmartVouchers.DomainServices;
@@ -43,6 +44,7 @@ protected override void Load(ContainerBuilder builder)
.SingleInstance();
builder.RegisterPaymentManagementClient(_settings.PaymentManagementServiceClient, null);
+ builder.RegisterPartnerManagementClient(_settings.PartnerManagementServiceClient, null);
}
}
}
diff --git a/src/MAVN.Job.SmartVouchers/Settings/AppSettings.cs b/src/MAVN.Job.SmartVouchers/Settings/AppSettings.cs
index 1455a3f..779f6c0 100644
--- a/src/MAVN.Job.SmartVouchers/Settings/AppSettings.cs
+++ b/src/MAVN.Job.SmartVouchers/Settings/AppSettings.cs
@@ -1,5 +1,6 @@
using Lykke.Sdk.Settings;
using MAVN.Job.SmartVouchers.Settings.JobSettings;
+using MAVN.Service.PartnerManagement.Client;
using MAVN.Service.PaymentManagement.Client;
namespace MAVN.Job.SmartVouchers.Settings
@@ -9,5 +10,7 @@ public class AppSettings : BaseAppSettings
public SmartVouchersJobSettings SmartVouchersJob { get; set; }
public PaymentManagementServiceClientSettings PaymentManagementServiceClient { get; set; }
+
+ public PartnerManagementServiceClientSettings PartnerManagementServiceClient { get; set; }
}
}
diff --git a/src/MAVN.Service.SmartVouchers.Domain/Enums/RedeemVoucherError.cs b/src/MAVN.Service.SmartVouchers.Domain/Enums/RedeemVoucherError.cs
index 0eb6153..bf3d6b6 100644
--- a/src/MAVN.Service.SmartVouchers.Domain/Enums/RedeemVoucherError.cs
+++ b/src/MAVN.Service.SmartVouchers.Domain/Enums/RedeemVoucherError.cs
@@ -7,5 +7,7 @@ public enum RedeemVoucherError
WrongValidationCode,
VoucherCampaignNotFound,
VoucherCampaignNotActive,
+ SellerCustomerIsNotALinkedPartner,
+ SellerCustomerIsNotTheVoucherIssuer,
}
}
diff --git a/src/MAVN.Service.SmartVouchers.DomainServices/MAVN.Service.SmartVouchers.DomainServices.csproj b/src/MAVN.Service.SmartVouchers.DomainServices/MAVN.Service.SmartVouchers.DomainServices.csproj
index 9cfb9b9..adfbdc3 100644
--- a/src/MAVN.Service.SmartVouchers.DomainServices/MAVN.Service.SmartVouchers.DomainServices.csproj
+++ b/src/MAVN.Service.SmartVouchers.DomainServices/MAVN.Service.SmartVouchers.DomainServices.csproj
@@ -6,6 +6,7 @@
+
diff --git a/src/MAVN.Service.SmartVouchers.DomainServices/VouchersService.cs b/src/MAVN.Service.SmartVouchers.DomainServices/VouchersService.cs
index 53ee1eb..3ae2ed0 100644
--- a/src/MAVN.Service.SmartVouchers.DomainServices/VouchersService.cs
+++ b/src/MAVN.Service.SmartVouchers.DomainServices/VouchersService.cs
@@ -6,6 +6,7 @@
using Common.Log;
using Lykke.Common.Log;
using Lykke.RabbitMqBroker.Publisher;
+using MAVN.Service.PartnerManagement.Client;
using MAVN.Service.PaymentManagement.Client;
using MAVN.Service.PaymentManagement.Client.Models.Requests;
using MAVN.Service.PaymentManagement.Client.Models.Responses;
@@ -24,6 +25,7 @@ public class VouchersService : IVouchersService
private const string PendingPaymentStatus = "pending";
private readonly IPaymentManagementClient _paymentManagementClient;
+ private readonly IPartnerManagementClient _partnerManagementClient;
private readonly IVouchersRepository _vouchersRepository;
private readonly ICampaignsRepository _campaignsRepository;
private readonly IPaymentRequestsRepository _paymentRequestsRepository;
@@ -35,6 +37,7 @@ public class VouchersService : IVouchersService
public VouchersService(
IPaymentManagementClient paymentManagementClient,
+ IPartnerManagementClient partnerManagementClient,
IVouchersRepository vouchersRepository,
ICampaignsRepository campaignsRepository,
IPaymentRequestsRepository paymentRequestsRepository,
@@ -45,6 +48,7 @@ public VouchersService(
TimeSpan lockTimeOut)
{
_paymentManagementClient = paymentManagementClient;
+ _partnerManagementClient = partnerManagementClient;
_vouchersRepository = vouchersRepository;
_campaignsRepository = campaignsRepository;
_paymentRequestsRepository = paymentRequestsRepository;
@@ -247,6 +251,17 @@ public async Task RedeemVoucherAsync(string voucherShortCode
if (!IsCampaignStateValid(campaign) || !IsCampaignDateValid(campaign))
return RedeemVoucherError.VoucherCampaignNotActive;
+ if (sellerCustomerId.HasValue)
+ {
+ var linkedPartner = await _partnerManagementClient.Linking.GetLinkedPartnerAsync(sellerCustomerId.Value);
+
+ if (!linkedPartner.HasValue)
+ return RedeemVoucherError.SellerCustomerIsNotALinkedPartner;
+
+ if(linkedPartner.Value != campaign.PartnerId)
+ return RedeemVoucherError.SellerCustomerIsNotTheVoucherIssuer;
+ }
+
voucher.Status = VoucherStatus.Used;
voucher.RedemptionDate = DateTime.UtcNow;
voucher.SellerId = sellerCustomerId;
diff --git a/src/MAVN.Service.SmartVouchers.MsSqlRepositories/Repositories/CampaignsRepository.cs b/src/MAVN.Service.SmartVouchers.MsSqlRepositories/Repositories/CampaignsRepository.cs
index 31f74ab..67997d0 100644
--- a/src/MAVN.Service.SmartVouchers.MsSqlRepositories/Repositories/CampaignsRepository.cs
+++ b/src/MAVN.Service.SmartVouchers.MsSqlRepositories/Repositories/CampaignsRepository.cs
@@ -149,6 +149,7 @@ public async Task GetCampaignsAsync(CampaignListRequest request)
result = await query.ToListAsync();
result = result
.OrderBy(p => partnersOrders[p.PartnerId])
+ .ThenByDescending(i => i.CreationDate)
.Skip(request.Skip)
.Take(request.Take)
.ToList();
diff --git a/src/MAVN.Service.SmartVouchers/MAVN.Service.SmartVouchers.csproj b/src/MAVN.Service.SmartVouchers/MAVN.Service.SmartVouchers.csproj
index 8f14cdc..4acb34d 100644
--- a/src/MAVN.Service.SmartVouchers/MAVN.Service.SmartVouchers.csproj
+++ b/src/MAVN.Service.SmartVouchers/MAVN.Service.SmartVouchers.csproj
@@ -18,7 +18,7 @@
- PreserveNewest
+ Always
PreserveNewest
diff --git a/src/MAVN.Service.SmartVouchers/Modules/ServiceModule.cs b/src/MAVN.Service.SmartVouchers/Modules/ServiceModule.cs
index c8df9dd..d97bc55 100644
--- a/src/MAVN.Service.SmartVouchers/Modules/ServiceModule.cs
+++ b/src/MAVN.Service.SmartVouchers/Modules/ServiceModule.cs
@@ -3,6 +3,7 @@
using Lykke.Sdk;
using Lykke.Sdk.Health;
using Lykke.SettingsReader;
+using MAVN.Service.PartnerManagement.Client;
using MAVN.Service.PaymentManagement.Client;
using MAVN.Service.SmartVouchers.Services;
using MAVN.Service.SmartVouchers.Settings;
@@ -67,6 +68,8 @@ protected override void Load(ContainerBuilder builder)
.SingleInstance();
builder.RegisterPaymentManagementClient(_settings.PaymentManagementServiceClient, null);
+
+ builder.RegisterPartnerManagementClient(_settings.PartnerManagementServiceClient, null);
}
}
}
diff --git a/src/MAVN.Service.SmartVouchers/Settings/AppSettings.cs b/src/MAVN.Service.SmartVouchers/Settings/AppSettings.cs
index 7057bf1..fb680e9 100644
--- a/src/MAVN.Service.SmartVouchers/Settings/AppSettings.cs
+++ b/src/MAVN.Service.SmartVouchers/Settings/AppSettings.cs
@@ -1,5 +1,6 @@
using JetBrains.Annotations;
using Lykke.Sdk.Settings;
+using MAVN.Service.PartnerManagement.Client;
using MAVN.Service.PaymentManagement.Client;
namespace MAVN.Service.SmartVouchers.Settings
@@ -10,5 +11,7 @@ public class AppSettings : BaseAppSettings
public SmartVouchersSettings SmartVouchersService { get; set; }
public PaymentManagementServiceClientSettings PaymentManagementServiceClient { get; set; }
+
+ public PartnerManagementServiceClientSettings PartnerManagementServiceClient { get; set; }
}
}