Skip to content

Commit

Permalink
move stripe and client url to appSettings.json
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul-atharva committed May 2, 2023
1 parent fc7e39d commit 2df3342
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 12 deletions.
6 changes: 6 additions & 0 deletions src/BlazorEcommerce.Application/Model/AppConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace BlazorEcommerce.Application.Model;

public class AppConfig
{
public string ClientUrl { get; set; } = string.Empty;
}
7 changes: 7 additions & 0 deletions src/BlazorEcommerce.Application/Model/StripeConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace BlazorEcommerce.Application.Model;

public class StripeConfig
{
public string Secret { get; set; } = string.Empty;
public string ApiKey { get; set; } = string.Empty;
}
5 changes: 5 additions & 0 deletions src/BlazorEcommerce.Infrastructure/ConfigureServices.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BlazorEcommerce.Application.Contracts.Payment;
using BlazorEcommerce.Application.Model;
using BlazorEcommerce.Infrastructure.Services.PaymentService;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -9,6 +10,10 @@ public static class ConfigureServices
{
public static IServiceCollection AddInfrastructureServices(this IServiceCollection services, IConfiguration configuration)
{
services.Configure<StripeConfig>(configuration.GetSection("StripeSettings"));

services.Configure<AppConfig>(configuration.GetSection("AppConfig"));

services.AddScoped<IPaymentService, PaymentService>();
return services;
}
Expand Down
27 changes: 20 additions & 7 deletions src/BlazorEcommerce.Infrastructure/Service/PaymentService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using BlazorEcommerce.Application.Contracts.Identity;
using BlazorEcommerce.Application.Contracts.Payment;
using BlazorEcommerce.Application.Model;
using BlazorEcommerce.Shared.Cart;
using BlazorEcommerce.Shared.Constant;
using BlazorEcommerce.Shared.Response.Abstract;
Expand All @@ -13,16 +14,28 @@ namespace BlazorEcommerce.Infrastructure.Services.PaymentService
public class PaymentService : IPaymentService
{
private readonly ICurrentUser _currentUser;
private readonly StripeConfig _stripeConfig;
private readonly AppConfig _appConfig;

const string secret = "whsec_97ffacb1f4861c5c1d3b471259cea7c26ba8aaa6b103df80ccd9671e5794ce36";
private readonly string secret = string.Empty;

public PaymentService(ICurrentUser currentUser)
public PaymentService(ICurrentUser currentUser, StripeConfig stripeConfig, AppConfig appConfig)
{
StripeConfiguration.ApiKey = "sk_test_51KeFeXSJN18oZA5qDkeNlClNnS5A8xklAv5cvMUJHDRTZTQegBEO36BSpzpBp7gEHGgDUZKNlzmEvHDnhL1CmiRs00bfrcT737";

_currentUser = currentUser;
_stripeConfig = stripeConfig;
_appConfig = appConfig;
StripeConfiguration.ApiKey = _stripeConfig.ApiKey;
secret = _stripeConfig.Secret;
}


//public PaymentService(ICurrentUser currentUser)
//{
// StripeConfiguration.ApiKey = "sk_test_51KeFeXSJN18oZA5qDkeNlClNnS5A8xklAv5cvMUJHDRTZTQegBEO36BSpzpBp7gEHGgDUZKNlzmEvHDnhL1CmiRs00bfrcT737";

// _currentUser = currentUser;
//}

public async Task<IResponse> CreateCheckoutSession(List<CartProductResponse> products)
{
var lineItems = new List<SessionLineItemOptions>();
Expand Down Expand Up @@ -55,8 +68,8 @@ public async Task<IResponse> CreateCheckoutSession(List<CartProductResponse> pro
},
LineItems = lineItems,
Mode = "payment",
SuccessUrl = "https://localhost:7018/order-success",
CancelUrl = "https://localhost:7018/cart"
SuccessUrl = $"{_appConfig.ClientUrl}order-success",
CancelUrl = $"{_appConfig.ClientUrl}cart"
};

var service = new SessionService();
Expand Down Expand Up @@ -86,7 +99,7 @@ public async Task<IResponse> FulfillOrder(HttpRequest request)
catch (StripeException e)
{
return new DataResponse<string?>(null, HttpStatusCodes.InternalServerError, e.Message, false);
}
}
}
}
}
5 changes: 1 addition & 4 deletions src/Presentation/Client/wwwroot/appsettings.development.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
{
"AppConfig": {
"ApiUrl": "https://localhost:7018"
}
{
}
9 changes: 8 additions & 1 deletion src/Presentation/Server/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@
"Default": "Data Source=.;Initial Catalog=blazorecommerce;Integrated Security=True;MultipleActiveResultSets=true;TrustServerCertificate=True"
},
"JwtSettings": {
"Key": "SECRET_JWT_KEY_HERE",
"Key": "kXpCDfN3E9+7pIoOO0d14BFoBeN8bcROxwdPrCCsfeY=",
"Issuer": "BlazorEcommerce.Api",
"Audience": "BlazorEcommerceUser",
"DurationInMinutes": 15
},
"StripeSettings": {
"Secret": "whsec_97ffacb1f4861c5c1d3b471259cea7c26ba8aaa6b103df80ccd9671e5794ce36",
"ApiKey": "sk_test_51KeFeXSJN18oZA5qDkeNlClNnS5A8xklAv5cvMUJHDRTZTQegBEO36BSpzpBp7gEHGgDUZKNlzmEvHDnhL1CmiRs00bfrcT737"
},
"AppConfig": {
"ClientUrl": "https://localhost:7018/"
},
"Logging": {
"LogLevel": {
"Default": "Information",
Expand Down

0 comments on commit 2df3342

Please sign in to comment.