Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

licence pre payment link #701

Merged
merged 3 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Spd.Manager.Payment/Contract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public interface IPaymentManager

#region pre payment link
//pre payment link - for dynamics internal use
public record PrePaymentLinkCreateCommand(Guid ApplicationId, string ScreeningAppPaymentUrl) : IRequest<PrePaymentLinkResponse>;
public record PrePaymentLinkCreateCommand(Guid ApplicationId, string ScreeningAppPaymentUrl, string LicensingAppPaymentUrl) : IRequest<PrePaymentLinkResponse>;
public record PrePaymentLinkResponse(string PrePaymentLinkUrl);
#endregion

Expand Down
8 changes: 6 additions & 2 deletions src/Spd.Manager.Payment/PaymentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ public async Task<PrePaymentLinkResponse> Handle(PrePaymentLinkCreateCommand com

var paymentId = Guid.NewGuid();
var encryptedPaymentId = WebUtility.UrlEncode(_dataProtector.Protect(paymentId.ToString(), DateTimeOffset.UtcNow.AddDays(SpdConstants.APPLICATION_INVITE_VALID_DAYS)));
return new PrePaymentLinkResponse($"{command.ScreeningAppPaymentUrl}?encodedAppId={encryptedApplicationId}&encodedPaymentId={encryptedPaymentId}");
if (IApplicationRepository.ScreeningServiceTypes.Contains((ServiceTypeEnum)app.ServiceType))
//if it is screening application
return new PrePaymentLinkResponse($"{command.ScreeningAppPaymentUrl}?encodedAppId={encryptedApplicationId}&encodedPaymentId={encryptedPaymentId}");
else
return new PrePaymentLinkResponse($"{command.LicensingAppPaymentUrl}?encodedAppId={encryptedApplicationId}&encodedPaymentId={encryptedPaymentId}");
}

public async Task<PaymentLinkResponse> Handle(PaymentLinkCreateCommand command, CancellationToken ct)
Expand Down Expand Up @@ -421,7 +425,7 @@ 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 = pbcRefnumberLicConfig.Value,
PbcRefNumber = pbcRefnumberLicConfig.Value,
PaybcRevenueAccount = PaybcRevenueAccountLicConfig.Value,
ServiceCost = Decimal.Round((decimal)price, 2)
};
Expand Down
12 changes: 11 additions & 1 deletion src/Spd.Presentation.Dynamics/Controllers/PaymentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,17 @@ public async Task<PrePaymentLinkResponse> GetPrePaymentLinkAsync(
{
throw new ConfigurationErrorsException("ScreeningHostUrl or screeningPaymentPath is not set correctly.");
}
return await _mediator.Send(new PrePaymentLinkCreateCommand(applicationId, $"{screeningHostUrl}{screeningPaymentPath}"), ct);

string? licensingHostUrl = _configuration.GetValue<string>("LicensingHostUrl");
string? licensingPaymentPath = _configuration.GetValue<string>("LicensingAppPaymentPath");
if (licensingHostUrl == null || licensingPaymentPath == null)
{
throw new ConfigurationErrorsException("ScreeningHostUrl or screeningPaymentPath is not set correctly.");
}

return await _mediator.Send(new PrePaymentLinkCreateCommand(applicationId,
$"{screeningHostUrl}{screeningPaymentPath}",
$"{licensingHostUrl}{licensingPaymentPath}"), ct);

}

Expand Down
4 changes: 3 additions & 1 deletion src/Spd.Presentation.Dynamics/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
"AllowedHosts": "*",
"AllowedOrigins": "*", // Semicolon separated list. e.g. "https://example.com;http://www.contoso.com",
"ScreeningHostUrl": "http://localhost:5114/", // "https://spd-screening-portal-dev.apps.emerald.devops.gov.bc.ca/",
"LicensingHostUrl": "http://localhost:5114/",
"ScreeningAppPaymentPath": "api/crrpa/payment-secure-link",
"LicensingAppPaymentPath": "api/licensing/payment-secure-link",
"KEY_RING_PATH": "C:\\peggy\\projects\\spd\\github\\PSSG-SPDBT",
"ProtectionShareKeyAppName": "Spd.Presentation.Screening",
"ProtectionShareKeyAppName": "ProtectionShareKeyApp",
"PayBC": {
"DirectRefund": {
"AuthenticationSettings": {
Expand Down
34 changes: 34 additions & 0 deletions src/Spd.Presentation.Licensing/Controllers/PaymentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,40 @@ public async Task<FileStreamResult> LicenceDownloadManualPaymentFormAsync([FromR
return File(content, contentType, response.FileName);
}
#endregion

#region secure-payment-link for dynamics email.
/// <summary>
/// Redirect to PayBC the direct pay payment page
/// </summary>
/// sample:http://localhost:5114/api/licence/payment-secure-link?encodedAppId=CfDJ8MELGoA6ZCBIuDpjih7jnJo3inVYsL3UPdbgBResn9qAoHpjCIIEmMJyuO_oHKEWLi-SA3qmmMJ_yqvl4myfXutYpPB75aOz7Wi49jjp1wHD9J56kmaOvJ3bhJuGl5hjbXybqO1TLXA0KsKO8Qr5IKLF7jK2WDpTn3hYj_U9YQ1g
/// <returns></returns>
[Route("api/licensing/payment-secure-link")]
[HttpGet]
public async Task<ActionResult> CreateLinkRedirectToPaybcPaymentPage([FromQuery] string encodedAppId, [FromQuery] string encodedPaymentId)
{
string? errorPath = _paymentsConfiguration.UnauthPersonalLicPaymentErrorPath;
string? hostUrl = _configuration.GetValue<string>("HostUrl");
try
{
string redirectUrl = $"{hostUrl}api/unauth-licence/payment-result";
PaymentLinkFromSecureLinkCreateRequest linkCreateRequest = new PaymentLinkFromSecureLinkCreateRequest()
{
ApplicationId = null,
EncodedApplicationId = encodedAppId,
EncodedPaymentId = encodedPaymentId,
Description = "Licensing",
PaymentMethod = PaymentMethodCode.CreditCard
};
var result = await _mediator.Send(new PaymentLinkCreateCommand(linkCreateRequest, redirectUrl, _paymentsConfiguration.MaxOnlinePaymentFailedTimes));
return Redirect(result.PaymentLinkUrl);
}
catch (Exception ex)
{
_logger.LogError($"CreateLinkRedirectToPaybcPaymentPage has errors +{ex}");
return Redirect($"{hostUrl}{errorPath}");
}
}
#endregion
}

public class PaybcPaymentResultViewModel
Expand Down
10 changes: 6 additions & 4 deletions src/Spd.Presentation.Licensing/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System.Reflection;
using System.Security.Principal;
using System.Text.Json.Serialization;
using FluentValidation;
using Microsoft.Dynamics.CRM;
using Spd.Presentation.Licensing;
using Spd.Presentation.Licensing.Services;
using Spd.Presentation.Licensing.Swagger;
Expand All @@ -13,7 +11,10 @@
using Spd.Utilities.Payment;
using Spd.Utilities.Recaptcha;
using Spd.Utilities.TempFileStorage;
using StackExchange.Redis;
using System.Configuration;
using System.Reflection;
using System.Security.Principal;
using System.Text.Json.Serialization;

var builder = WebApplication.CreateBuilder(args);

Expand All @@ -35,6 +36,7 @@
builder.Services.ConfigureCors(builder.Configuration);
var assemblyName = $"{typeof(Program).GetTypeInfo().Assembly.GetName().Name}";
builder.Services.ConfigureSwagger(assemblyName);
builder.Services.ConfigureDataProtection(builder.Configuration, "ProtectionShareKeyApp");
builder.Services
.AddEndpointsApiExplorer()
.AddControllers()
Expand Down
3 changes: 2 additions & 1 deletion src/Spd.Presentation.Licensing/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,6 @@
"SecurityGuardUnderSupervision",
"BodyArmourSales"
]
}
},
"KEY_RING_PATH": "C:\\peggy\\projects\\spd\\github\\PSSG-SPDBT"
}
2 changes: 1 addition & 1 deletion src/Spd.Presentation.Screening/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void RegisterServices(IServiceCollection services)
services.ConfigureCors(configuration);
var assemblyName = $"{typeof(Startup).GetTypeInfo().Assembly.GetName().Name}";
services.ConfigureSwagger(assemblyName);
services.ConfigureDataProtection(configuration, assemblyName);
services.ConfigureDataProtection(configuration, "ProtectionShareKeyApp");
services
.AddEndpointsApiExplorer()
.AddControllers()
Expand Down
Loading