Skip to content

Commit

Permalink
Merge pull request #48 from IliyanIlievPH/47
Browse files Browse the repository at this point in the history
Closes #47
  • Loading branch information
starkmsu authored May 29, 2020
2 parents 987dcf4 + e8d649a commit cc43d12
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@ public enum RedeemVoucherErrorCodes
VoucherCampaignNotFound,
/// <summary>Voucher campaign not active</summary>
VoucherCampaignNotActive,
/// <summary>The passed seller id does not have a linked partner id</summary>
SellerCustomerIsNotALinkedPartner,
/// <summary>The passed seller id does not match the voucher issuer id</summary>
SellerCustomerIsNotTheVoucherIssuer,
}
}
3 changes: 3 additions & 0 deletions settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,6 @@ MonitoringServiceClient:
PaymentManagementServiceClient:
ServiceUrl:
settings-key: PaymentManagementServiceUrl
PartnerManagementServiceClient:
ServiceUrl:
settings-key: PartnerManagementServiceUrl
2 changes: 2 additions & 0 deletions src/MAVN.Job.SmartVouchers/Modules/ServiceModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -43,6 +44,7 @@ protected override void Load(ContainerBuilder builder)
.SingleInstance();

builder.RegisterPaymentManagementClient(_settings.PaymentManagementServiceClient, null);
builder.RegisterPartnerManagementClient(_settings.PartnerManagementServiceClient, null);
}
}
}
3 changes: 3 additions & 0 deletions src/MAVN.Job.SmartVouchers/Settings/AppSettings.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,5 +10,7 @@ public class AppSettings : BaseAppSettings
public SmartVouchersJobSettings SmartVouchersJob { get; set; }

public PaymentManagementServiceClientSettings PaymentManagementServiceClient { get; set; }

public PartnerManagementServiceClientSettings PartnerManagementServiceClient { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ public enum RedeemVoucherError
WrongValidationCode,
VoucherCampaignNotFound,
VoucherCampaignNotActive,
SellerCustomerIsNotALinkedPartner,
SellerCustomerIsNotTheVoucherIssuer,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<ItemGroup>
<PackageReference Include="AutoMapper" Version="9.0.0" />
<PackageReference Include="Lykke.RabbitMqBroker" Version="7.13.1" />
<PackageReference Include="MAVN.Service.PartnerManagement.Client" Version="2.8.2" />
<PackageReference Include="MAVN.Service.PaymentManagement.Client" Version="1.18.0" />
<PackageReference Include="MAVN.Service.PaymentManagement.Contract" Version="1.18.0" />
<PackageReference Include="StackExchange.Redis" Version="2.1.30" />
Expand Down
15 changes: 15 additions & 0 deletions src/MAVN.Service.SmartVouchers.DomainServices/VouchersService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -35,6 +37,7 @@ public class VouchersService : IVouchersService

public VouchersService(
IPaymentManagementClient paymentManagementClient,
IPartnerManagementClient partnerManagementClient,
IVouchersRepository vouchersRepository,
ICampaignsRepository campaignsRepository,
IPaymentRequestsRepository paymentRequestsRepository,
Expand All @@ -45,6 +48,7 @@ public VouchersService(
TimeSpan lockTimeOut)
{
_paymentManagementClient = paymentManagementClient;
_partnerManagementClient = partnerManagementClient;
_vouchersRepository = vouchersRepository;
_campaignsRepository = campaignsRepository;
_paymentRequestsRepository = paymentRequestsRepository;
Expand Down Expand Up @@ -247,6 +251,17 @@ public async Task<RedeemVoucherError> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public async Task<CampaignsPage> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Dockerfile">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
Expand Down
3 changes: 3 additions & 0 deletions src/MAVN.Service.SmartVouchers/Modules/ServiceModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -67,6 +68,8 @@ protected override void Load(ContainerBuilder builder)
.SingleInstance();

builder.RegisterPaymentManagementClient(_settings.PaymentManagementServiceClient, null);

builder.RegisterPartnerManagementClient(_settings.PartnerManagementServiceClient, null);
}
}
}
3 changes: 3 additions & 0 deletions src/MAVN.Service.SmartVouchers/Settings/AppSettings.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,5 +11,7 @@ public class AppSettings : BaseAppSettings
public SmartVouchersSettings SmartVouchersService { get; set; }

public PaymentManagementServiceClientSettings PaymentManagementServiceClient { get; set; }

public PartnerManagementServiceClientSettings PartnerManagementServiceClient { get; set; }
}
}

0 comments on commit cc43d12

Please sign in to comment.