Start work for stripe payments
This commit is contained in:
@@ -44,8 +44,18 @@ namespace MistoxWebsite.Server.Controllers {
|
||||
return "Unable to find account";
|
||||
}
|
||||
}
|
||||
|
||||
[Route("/api/payment/publickey")]
|
||||
[HttpGet]
|
||||
public IActionResult GetPaymentKey() {
|
||||
try {
|
||||
return Ok(IPayment._PublicKey);
|
||||
} catch (Exception ex) {
|
||||
return NotFound(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[Route( "/api/payment/response" )]
|
||||
[Route("/api/payment/response")]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> paymentWebhook() {
|
||||
try {
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace MistoxWebsite.Server.Controllers.Payment {
|
||||
|
||||
public static PaymentType _PaymentType;
|
||||
public static string _EndpointSecret = "";
|
||||
public static string _PublicKey = "";
|
||||
|
||||
public Task<(bool, string)> TryGetCheckoutToken(string OrderNumber, Account user, Cart[] cart);
|
||||
public Task ValidatePurchase(string WebHookData, string Headers);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using MistoxWebsite.Server.Controllers;
|
||||
using MistoxWebsite.Server.Controllers.Payment;
|
||||
using MistoxWebsite.Server.Services;
|
||||
using MistoxWebsite.Server.Services.DatabaseService;
|
||||
@@ -11,40 +10,72 @@ var builder = WebApplication.CreateBuilder(args);
|
||||
#pragma warning disable CS8600
|
||||
#pragma warning disable CS8604
|
||||
|
||||
// Database Service
|
||||
////////////////////////////////
|
||||
/////// Database Service ///////
|
||||
////////////////////////////////
|
||||
|
||||
// Address
|
||||
string? _dbserver = Environment.GetEnvironmentVariable("MySQLServer");
|
||||
string dbserver = !string.IsNullOrEmpty(_dbserver) ? _dbserver : "localhost";
|
||||
string? _dbuser = Environment.GetEnvironmentVariable("MySQLUser");
|
||||
string dbUser = !string.IsNullOrEmpty(_dbuser) ? _dbuser : "root";
|
||||
|
||||
// Database
|
||||
string? _dbdatabase = Environment.GetEnvironmentVariable("MySQLDatabase");
|
||||
string dbdatabase = !string.IsNullOrEmpty(_dbdatabase) ? _dbdatabase : "mistox";
|
||||
|
||||
// UserName
|
||||
string? _dbuser = Environment.GetEnvironmentVariable("MySQLUser");
|
||||
string dbUser = !string.IsNullOrEmpty(_dbuser) ? _dbuser : "root";
|
||||
|
||||
// Password
|
||||
string? _dbpass = Environment.GetEnvironmentVariable("MySQLPass");
|
||||
string dbPass = !string.IsNullOrEmpty(_dbpass) ? _dbpass : "oasv34$8gpv023dd";
|
||||
string connStr = "server=" + dbserver + ";user=" + dbUser + ";database=" + dbdatabase + ";password=" + dbPass + ";port=3306;";
|
||||
DatabaseService databaseService = new DatabaseService( connectionString: connStr );
|
||||
|
||||
// Create the database serivice
|
||||
DatabaseService databaseService = new DatabaseService(connectionString: "server=" + dbserver + ";user=" + dbUser + ";database=" + dbdatabase + ";password=" + dbPass + ";port=3306;");
|
||||
builder.Services.Add( new ServiceDescriptor( typeof( DatabaseService ), databaseService ) );
|
||||
|
||||
// Email Service
|
||||
////////////////////////////////
|
||||
///////// Email Service ////////
|
||||
////////////////////////////////
|
||||
|
||||
// Address
|
||||
string? _eServer = Environment.GetEnvironmentVariable("EmailServer");
|
||||
string EmailServer = !string.IsNullOrEmpty(_eServer) ? _eServer : "mail.mistox.com";
|
||||
|
||||
// Port
|
||||
string? _ePort = Environment.GetEnvironmentVariable("EmailPort");
|
||||
int EmailPort = !string.IsNullOrEmpty(_ePort) ? Convert.ToInt32(_ePort) : 587;
|
||||
|
||||
// User
|
||||
string? _eAddress = Environment.GetEnvironmentVariable("EmailAddress");
|
||||
string EmailAddress = !string.IsNullOrEmpty(_eAddress) ? _eAddress : "no-reply@mistox.com";
|
||||
|
||||
// Password
|
||||
string? _ePassword = Environment.GetEnvironmentVariable("EmailPassword");
|
||||
string EmailPassword = !string.IsNullOrEmpty(_ePassword) ? _ePassword : "";
|
||||
|
||||
// Create the email service
|
||||
EmailService Emailservice = new EmailService( EmailServer, EmailPort, EmailAddress, EmailPassword );
|
||||
builder.Services.Add( new ServiceDescriptor( typeof( EmailService ), Emailservice ));
|
||||
|
||||
// Payment Service
|
||||
////////////////////////////////
|
||||
/////// Payment Service ////////
|
||||
////////////////////////////////
|
||||
|
||||
// Payment service name -> must be name of PaymentType enum
|
||||
string? PaymentService = Environment.GetEnvironmentVariable("PaymentService");
|
||||
IPayment._PaymentType = (PaymentType)Enum.Parse(typeof(PaymentType), PaymentService, true);
|
||||
|
||||
if (IPayment._PaymentType == PaymentType.StripeIntent) {
|
||||
string? StripeKey = Environment.GetEnvironmentVariable("StripeKey");
|
||||
StripeConfiguration.ApiKey = StripeKey;
|
||||
// Get PublicKey
|
||||
string? StripePublicKey = Environment.GetEnvironmentVariable("StripePublicKey");
|
||||
IPayment._PublicKey = string.IsNullOrEmpty(StripePublicKey) ? "" : StripePublicKey;
|
||||
// Get PrivateKey
|
||||
string? StripeAPIKey = Environment.GetEnvironmentVariable("StripeApiKey");
|
||||
StripeConfiguration.ApiKey = StripeAPIKey;
|
||||
// Get Endpoint secret
|
||||
string? StripeEndpointKey = Environment.GetEnvironmentVariable("StripeEndpointSecret");
|
||||
IPayment._EndpointSecret = string.IsNullOrEmpty(StripeEndpointKey) ? "" : StripeEndpointKey ;
|
||||
IPayment._EndpointSecret = string.IsNullOrEmpty(StripeEndpointKey) ? "" : StripeEndpointKey;
|
||||
}
|
||||
|
||||
// Authentication Service
|
||||
|
||||
Reference in New Issue
Block a user