Start work for stripe payments

This commit is contained in:
2025-06-29 19:00:25 -07:00
parent b494fef8cc
commit dc36f91353
11 changed files with 164 additions and 15 deletions
+2 -1
View File
@@ -1,6 +1,7 @@
Payment_Service=StripeIntent # Options are [ StripeIntent ] Payment_Service=StripeIntent # Options are [ StripeIntent ]
Stripe_Key= Stripe_PublicKey=
Stripe_PublicKey=
Stripe_Endpoint_Secret= Stripe_Endpoint_Secret=
MySQL_Server=mistox-database MySQL_Server=mistox-database
+2 -1
View File
@@ -6,7 +6,8 @@ services:
restart: always restart: always
environment: environment:
- PaymentService=${Payment_Service} - PaymentService=${Payment_Service}
- StripeKey=${Stripe_Key} - StripePublicKey=${Stripe_PublicKey}
- StripeApiKey=${Stripe_ApiKey}
- StripeEndpointSecret=&{Stripe_Endpoint_Secret} - StripeEndpointSecret=&{Stripe_Endpoint_Secret}
- MySQLServer=${MySQL_Server} - MySQLServer=${MySQL_Server}
- MySQLUser=${MySQL_User} - MySQLUser=${MySQL_User}
+10
View File
@@ -14,6 +14,7 @@
"@angular/forms": "^20.0.0", "@angular/forms": "^20.0.0",
"@angular/platform-browser": "^20.0.0", "@angular/platform-browser": "^20.0.0",
"@angular/router": "^20.0.0", "@angular/router": "^20.0.0",
"@stripe/stripe-js": "^7.4.0",
"rxjs": "~7.8.0", "rxjs": "~7.8.0",
"tslib": "^2.3.0", "tslib": "^2.3.0",
"zone.js": "~0.15.0" "zone.js": "~0.15.0"
@@ -3196,6 +3197,15 @@
"dev": true, "dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/@stripe/stripe-js": {
"version": "7.4.0",
"resolved": "https://registry.npmjs.org/@stripe/stripe-js/-/stripe-js-7.4.0.tgz",
"integrity": "sha512-lQHQPfXPTBeh0XFjq6PqSBAyR7umwcJbvJhXV77uGCUDD6ymXJU/f2164ydLMLCCceNuPlbV9b+1smx98efwWQ==",
"license": "MIT",
"engines": {
"node": ">=12.16"
}
},
"node_modules/@tufjs/canonical-json": { "node_modules/@tufjs/canonical-json": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/@tufjs/canonical-json/-/canonical-json-2.0.0.tgz", "resolved": "https://registry.npmjs.org/@tufjs/canonical-json/-/canonical-json-2.0.0.tgz",
+1
View File
@@ -16,6 +16,7 @@
"@angular/forms": "^20.0.0", "@angular/forms": "^20.0.0",
"@angular/platform-browser": "^20.0.0", "@angular/platform-browser": "^20.0.0",
"@angular/router": "^20.0.0", "@angular/router": "^20.0.0",
"@stripe/stripe-js": "^7.4.0",
"rxjs": "~7.8.0", "rxjs": "~7.8.0",
"tslib": "^2.3.0", "tslib": "^2.3.0",
"zone.js": "~0.15.0" "zone.js": "~0.15.0"
@@ -8,7 +8,7 @@ import { Authentication } from '../../../services/Authentication';
import { Product } from 'app/models/Product'; import { Product } from 'app/models/Product';
@Component({ @Component({
selector: 'catalog', selector: 'store-catalog',
templateUrl: './catalog.component.html', templateUrl: './catalog.component.html',
styleUrl: './catalog.component.css', styleUrl: './catalog.component.css',
imports: [ FormsModule, CommonModule, RouterModule ] imports: [ FormsModule, CommonModule, RouterModule ]
@@ -0,0 +1,24 @@
#payment-form {
max-width: 500px;
margin: 0 auto;
}
.form-group {
margin-bottom: 20px;
}
#card-element {
padding: 12px;
border: 1px solid #ccc;
border-radius: 4px;
background: #fff;
}
#submit {
background-color: #5469d4;
color: white;
padding: 12px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
}
@@ -0,0 +1,8 @@
<form id="payment-form">
<div class="form-group">
<label for="card-element">Card Details</label>
<div id="card-element"></div>
<div id="card-errors" role="alert"></div>
</div>
<button id="submit">Pay</button>
</form>
@@ -0,0 +1,62 @@
import { Component } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { FormsModule } from '@angular/forms';
import { Router, ActivatedRoute, RouterModule } from '@angular/router';
import { Title } from '@angular/platform-browser';
import { CommonModule } from '@angular/common';
import { Authentication } from '../../../services/Authentication';
import { loadStripe, Stripe, StripeElements } from '@stripe/stripe-js';
import { firstValueFrom } from 'rxjs';
@Component({
selector: 'store-payment',
templateUrl: './payment.component.html',
styleUrl: './payment.component.css',
imports: [ FormsModule, CommonModule, RouterModule ]
})
export class PaymentComponent {
stripe: Stripe | null = null;
elements: StripeElements | null = null;
async ngOnInit(){
let ApiKey = await firstValueFrom(this.http.get<string>("/api/payment/publickey"));
this.stripe = await loadStripe(ApiKey);
if (this.stripe){
this.elements = this.stripe?.elements();
}
}
ngAfterViewInit(){
if (this.elements){
const cardStyle = {
base: {
color: '#32325d',
fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
fontSize: '16px',
'::placeholder': {
color: '#aab7c4',
}
},
invalid: {
color: '#fa755a',
}
}
const card = this.elements.create('card', { style: cardStyle });
card.mount('#card-element');
}
}
constructor( private http: HttpClient, private router: Router, private route: ActivatedRoute, private title: Title, public auth: Authentication ) {
this.title.setTitle("Payment | Mistox");
http.post<void[]>("api/product/getall", null).subscribe(
response => {
}
)
};
}
@@ -45,6 +45,16 @@ namespace MistoxWebsite.Server.Controllers {
} }
} }
[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] [HttpPost]
public async Task<IActionResult> paymentWebhook() { public async Task<IActionResult> paymentWebhook() {
@@ -6,6 +6,7 @@ namespace MistoxWebsite.Server.Controllers.Payment {
public static PaymentType _PaymentType; public static PaymentType _PaymentType;
public static string _EndpointSecret = ""; public static string _EndpointSecret = "";
public static string _PublicKey = "";
public Task<(bool, string)> TryGetCheckoutToken(string OrderNumber, Account user, Cart[] cart); public Task<(bool, string)> TryGetCheckoutToken(string OrderNumber, Account user, Cart[] cart);
public Task ValidatePurchase(string WebHookData, string Headers); public Task ValidatePurchase(string WebHookData, string Headers);
+41 -10
View File
@@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authentication.Cookies;
using MistoxWebsite.Server.Controllers;
using MistoxWebsite.Server.Controllers.Payment; using MistoxWebsite.Server.Controllers.Payment;
using MistoxWebsite.Server.Services; using MistoxWebsite.Server.Services;
using MistoxWebsite.Server.Services.DatabaseService; using MistoxWebsite.Server.Services.DatabaseService;
@@ -11,38 +10,70 @@ var builder = WebApplication.CreateBuilder(args);
#pragma warning disable CS8600 #pragma warning disable CS8600
#pragma warning disable CS8604 #pragma warning disable CS8604
// Database Service ////////////////////////////////
/////// Database Service ///////
////////////////////////////////
// Address
string? _dbserver = Environment.GetEnvironmentVariable("MySQLServer"); string? _dbserver = Environment.GetEnvironmentVariable("MySQLServer");
string dbserver = !string.IsNullOrEmpty(_dbserver) ? _dbserver : "localhost"; 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 = Environment.GetEnvironmentVariable("MySQLDatabase");
string dbdatabase = !string.IsNullOrEmpty(_dbdatabase) ? _dbdatabase : "mistox"; 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 = Environment.GetEnvironmentVariable("MySQLPass");
string dbPass = !string.IsNullOrEmpty(_dbpass) ? _dbpass : "oasv34$8gpv023dd"; 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 ) ); builder.Services.Add( new ServiceDescriptor( typeof( DatabaseService ), databaseService ) );
// Email Service ////////////////////////////////
///////// Email Service ////////
////////////////////////////////
// Address
string? _eServer = Environment.GetEnvironmentVariable("EmailServer"); string? _eServer = Environment.GetEnvironmentVariable("EmailServer");
string EmailServer = !string.IsNullOrEmpty(_eServer) ? _eServer : "mail.mistox.com"; string EmailServer = !string.IsNullOrEmpty(_eServer) ? _eServer : "mail.mistox.com";
// Port
string? _ePort = Environment.GetEnvironmentVariable("EmailPort"); string? _ePort = Environment.GetEnvironmentVariable("EmailPort");
int EmailPort = !string.IsNullOrEmpty(_ePort) ? Convert.ToInt32(_ePort) : 587; int EmailPort = !string.IsNullOrEmpty(_ePort) ? Convert.ToInt32(_ePort) : 587;
// User
string? _eAddress = Environment.GetEnvironmentVariable("EmailAddress"); string? _eAddress = Environment.GetEnvironmentVariable("EmailAddress");
string EmailAddress = !string.IsNullOrEmpty(_eAddress) ? _eAddress : "no-reply@mistox.com"; string EmailAddress = !string.IsNullOrEmpty(_eAddress) ? _eAddress : "no-reply@mistox.com";
// Password
string? _ePassword = Environment.GetEnvironmentVariable("EmailPassword"); string? _ePassword = Environment.GetEnvironmentVariable("EmailPassword");
string EmailPassword = !string.IsNullOrEmpty(_ePassword) ? _ePassword : ""; string EmailPassword = !string.IsNullOrEmpty(_ePassword) ? _ePassword : "";
// Create the email service
EmailService Emailservice = new EmailService( EmailServer, EmailPort, EmailAddress, EmailPassword ); EmailService Emailservice = new EmailService( EmailServer, EmailPort, EmailAddress, EmailPassword );
builder.Services.Add( new ServiceDescriptor( typeof( EmailService ), Emailservice )); 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"); string? PaymentService = Environment.GetEnvironmentVariable("PaymentService");
IPayment._PaymentType = (PaymentType)Enum.Parse(typeof(PaymentType), PaymentService, true); IPayment._PaymentType = (PaymentType)Enum.Parse(typeof(PaymentType), PaymentService, true);
if (IPayment._PaymentType == PaymentType.StripeIntent) { if (IPayment._PaymentType == PaymentType.StripeIntent) {
string? StripeKey = Environment.GetEnvironmentVariable("StripeKey"); // Get PublicKey
StripeConfiguration.ApiKey = StripeKey; 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"); string? StripeEndpointKey = Environment.GetEnvironmentVariable("StripeEndpointSecret");
IPayment._EndpointSecret = string.IsNullOrEmpty(StripeEndpointKey) ? "" : StripeEndpointKey; IPayment._EndpointSecret = string.IsNullOrEmpty(StripeEndpointKey) ? "" : StripeEndpointKey;
} }