Skip to content

Commit

Permalink
licensing payment -config from dynamics (#694)
Browse files Browse the repository at this point in the history
# Description

This PR includes the following proposed change(s):

- read config from dynamics
  • Loading branch information
peggy-quartech authored Jan 19, 2024
1 parent 006c39f commit ec95d1c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
40 changes: 19 additions & 21 deletions src/Spd.Manager.Payment/PaymentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,49 +365,47 @@ public async Task<UpdateInvoicesFromCasResponse> Handle(UpdateInvoicesFromCasCom

private async Task<SpdPaymentConfig> GetSpdPaymentInfoAsync(ApplicationResult app, CancellationToken ct)
{
ConfigResult? configResult = await _cache.Get<ConfigResult>("spdPayBCConfigs");
if (configResult == null)
{
configResult = await _configRepository.Query(new ConfigQuery(null, IConfigRepository.PAYBC_GROUP), ct);
await _cache.Set<ConfigResult>("spdPayBCConfigs", configResult, new TimeSpan(1, 0, 0));
}
if (IApplicationRepository.ScreeningServiceTypes.Contains((ServiceTypeEnum)app.ServiceType))
{
//screening price and payment setting
SpdPaymentConfig? spdPaymentConfig = await _cache.Get<SpdPaymentConfig>("spdPaymentConfig");
if (spdPaymentConfig != null) return spdPaymentConfig;

var configs = await _configRepository.Query(new ConfigQuery(null, IConfigRepository.PAYBC_GROUP), ct);
var pbcRefnumberConfig = configs.ConfigItems.FirstOrDefault(c => c.Key == IConfigRepository.PAYBC_PBCREFNUMBER_KEY);
var pbcRefnumberConfig = configResult.ConfigItems.FirstOrDefault(c => c.Key == IConfigRepository.PAYBC_PBCREFNUMBER_KEY);
if (pbcRefnumberConfig == null)
throw new ApiException(HttpStatusCode.InternalServerError, "Dynamics did not set pbcRefNumber correctly.");

var PaybcRevenueAccountConfig = configs.ConfigItems.FirstOrDefault(c => c.Key == IConfigRepository.PAYBC_REVENUEACCOUNT_KEY);
var PaybcRevenueAccountConfig = configResult.ConfigItems.FirstOrDefault(c => c.Key == IConfigRepository.PAYBC_REVENUEACCOUNT_KEY);
if (PaybcRevenueAccountConfig == null)
throw new ApiException(HttpStatusCode.InternalServerError, "Dynamics did not set paybc revenue account correctly.");

var serviceCostConfig = configs.ConfigItems.FirstOrDefault(c => c.Key == IConfigRepository.PAYBCS_SERVICECOST_KEY);
var serviceCostConfig = configResult.ConfigItems.FirstOrDefault(c => c.Key == IConfigRepository.PAYBCS_SERVICECOST_KEY);
if (serviceCostConfig == null)
throw new ApiException(HttpStatusCode.InternalServerError, "Dynamics did not set service cost correctly.");

spdPaymentConfig = new SpdPaymentConfig()
SpdPaymentConfig spdPaymentConfig = new SpdPaymentConfig()
{
PbcRefNumber = pbcRefnumberConfig.Value,
PaybcRevenueAccount = PaybcRevenueAccountConfig.Value,
ServiceCost = Decimal.Round(Decimal.Parse(serviceCostConfig.Value), 2)
};
await _cache.Set<SpdPaymentConfig>("spdPaymentConfig", spdPaymentConfig, new TimeSpan(1, 0, 0));
return spdPaymentConfig;
}
else
{
var licApp = await _licAppRepository.GetLicenceApplicationAsync(app.Id, ct);
//licensing price and payment setting
var configs = await _configRepository.Query(new ConfigQuery(null, IConfigRepository.PAYBC_GROUP), ct);
var pbcRefnumberLicConfig = configResult.ConfigItems.FirstOrDefault(c => c.Key == IConfigRepository.PAYBC_PBCREFNUMBER_LICENSING_KEY);
if (pbcRefnumberLicConfig == null)
throw new ApiException(HttpStatusCode.InternalServerError, "Dynamics did not set pbcRefNumberLicensing correctly.");

//todo, get to know if there will be a new setting in config entity.
var pbcRefnumberConfig = configs.ConfigItems.FirstOrDefault(c => c.Key == IConfigRepository.PAYBC_PBCREFNUMBER_KEY);
if (pbcRefnumberConfig == null)
throw new ApiException(HttpStatusCode.InternalServerError, "Dynamics did not set pbcRefNumber correctly.");

var PaybcRevenueAccountConfig = configs.ConfigItems.FirstOrDefault(c => c.Key == IConfigRepository.PAYBC_REVENUEACCOUNT_KEY);
if (PaybcRevenueAccountConfig == null)
throw new ApiException(HttpStatusCode.InternalServerError, "Dynamics did not set paybc revenue account correctly.");
var PaybcRevenueAccountLicConfig = configResult.ConfigItems.FirstOrDefault(c => c.Key == IConfigRepository.PAYBC_REVENUEACCOUNT_LICENSING_KEY);
if (PaybcRevenueAccountLicConfig == null)
throw new ApiException(HttpStatusCode.InternalServerError, "Dynamics did not set paybc revenue account licensing correctly.");

var licApp = await _licAppRepository.GetLicenceApplicationAsync(app.Id, ct);
LicenceFeeListResp feeList = await _licFeeRepository.QueryAsync(
new LicenceFeeQry
{
Expand All @@ -423,8 +421,8 @@ private async Task<SpdPaymentConfig> GetSpdPaymentInfoAsync(ApplicationResult ap
throw new ApiException(HttpStatusCode.InternalServerError, $"The price for {licApp.WorkerLicenceTypeCode} {licApp.ApplicationTypeCode} {licApp.LicenceTermCode} is not set correctly in dynamics.");
SpdPaymentConfig spdPaymentConfig = new()
{
PbcRefNumber = pbcRefnumberConfig.Value, //"10016" //todo: Waiting for PBC 's response, if it is different ref number, then change it accordingly.
PaybcRevenueAccount = PaybcRevenueAccountConfig.Value,
PbcRefNumber = pbcRefnumberLicConfig.Value,
PaybcRevenueAccount = PaybcRevenueAccountLicConfig.Value,
ServiceCost = Decimal.Round((decimal)price, 2)
};
return spdPaymentConfig;
Expand Down
2 changes: 2 additions & 0 deletions src/Spd.Resource.Organizations/Config/Contract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ public interface IConfigRepository
public static readonly string PAYBC_GROUP = "PAYBC";
public static readonly string PAYBC_REVENUEACCOUNT_KEY = "RevenueAccount";
public static readonly string PAYBC_PBCREFNUMBER_KEY = "PbcRefNumber";
public static readonly string PAYBC_PBCREFNUMBER_LICENSING_KEY = "PbcRefNumberLicensing";
public static readonly string PAYBC_REVENUEACCOUNT_LICENSING_KEY = "RevenueAccountLicensing";
public static readonly string PAYBCS_SERVICECOST_KEY = "Service Amount";
Task<ConfigResult> Query(ConfigQuery query, CancellationToken ct);
}
Expand Down
3 changes: 0 additions & 3 deletions src/Spd.Utilities.Payment/PaymentService.DirectPay.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using Microsoft.Extensions.Logging;
using System;
using System.Configuration;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace Spd.Utilities.Payment
Expand Down

0 comments on commit ec95d1c

Please sign in to comment.