Added stripe support

This commit is contained in:
itzMiney committed 2025-08-05 07:33:42 +02:00
1 parent f000688d4e
commit b4020ee40b
12 files changed
+313 -13

No files matched your search

+18
View File
@@ -116,6 +116,24 @@
color: #ffffff;
}
.buy-button {
background-color: rgba(187, 107, 209, 0.5);
border: none;
border-radius: 25px;
color: white;
padding: 10px;
margin-inline: 15px;
margin-top: 20px;
font-size: 1rem;
cursor: pointer;
width: 110px;
display: inline-block;
}
.buy-button:hover {
background-color: rgba(187, 107, 209, 0.62);
}
.tab-content {
margin-top: 10px;
font-size: 0.9rem;
+13 -6
View File
@@ -22,16 +22,23 @@
<button
class="tab-btn"
[class.active]="activeTab[i] === 'basic'"
(click)="switchTab(i, 'basic')">Basic</button>
(click)="switchTab(i, 'basic')">
Basic
</button>
<button
class="tab-btn"
[class.active]="activeTab[i] === 'advanced'"
(click)="switchTab(i, 'advanced')">Advanced</button>
</div>
<div *ngIf="activeTab[i] === 'basic'" class="tab-content" [innerHTML]="service.basic">
</div>
<div *ngIf="activeTab[i] === 'advanced'" class="tab-content" [innerHTML]="service.advanced">
(click)="switchTab(i, 'advanced')">
Advanced
</button>
</div>
<div class="tab-content" [innerHTML]="activeTab[i] === 'basic' ? service.basic : service.advanced"></div>
<button
class="buy-button"
*ngIf="getActivePriceId(service, activeTab[i])"
(click)="checkout(getActivePriceId(service, activeTab[i]) || '')">
Buy Service
</button>
</div>
</div>
</div>
+60 -7
View File
@@ -22,7 +22,13 @@ export class ServicesComponent implements OnInit, OnDestroy, AfterViewInit {
isMobile: boolean = false;
activeTab: string[] = [];
services: { name: string; basic: string; advanced: string }[] = [];
services: {
name: string;
basic: string;
advanced: string;
basicPriceId: string;
advancedPriceId: string;
}[] = [];
constructor(
private vantaService: VantaBackgroundService,
@@ -48,6 +54,9 @@ export class ServicesComponent implements OnInit, OnDestroy, AfterViewInit {
loadServices(): void {
this.translate.get([
'SERVICES.PTERO_NAME',
'SERVICES.PTERO_BASIC',
'SERVICES.PTERO_ADVANCED',
'SERVICES.SUPPORT_NAME',
'SERVICES.SUPPORT_BASIC',
'SERVICES.SUPPORT_ADVANCED',
@@ -68,35 +77,54 @@ export class ServicesComponent implements OnInit, OnDestroy, AfterViewInit {
'SERVICES.SERVER_SETUP_ADVANCED'
]).subscribe(translations => {
this.services = [
{
name: translations['SERVICES.PTERO_NAME'],
basic: translations['SERVICES.PTERO_BASIC'],
advanced: translations['SERVICES.PTERO_ADVANCED'],
basicPriceId: 'price_1RscMR2LT0gYeSqcQ7SDj6gG',
advancedPriceId: 'price_1RscMR2LT0gYeSqcQ7SDj6gG'
},
{
name: translations['SERVICES.SUPPORT_NAME'],
basic: translations['SERVICES.SUPPORT_BASIC'],
advanced: translations['SERVICES.SUPPORT_ADVANCED']
advanced: translations['SERVICES.SUPPORT_ADVANCED'],
basicPriceId: '',
advancedPriceId: ''
},
{
name: translations['SERVICES.WP_FILES_NAME'],
basic: translations['SERVICES.WP_FILES_BASIC'],
advanced: translations['SERVICES.WP_FILES_ADVANCED']
advanced: translations['SERVICES.WP_FILES_ADVANCED'],
basicPriceId: '',
advancedPriceId: ''
},
{
name: translations['SERVICES.WP_SETUP_NAME'],
basic: translations['SERVICES.WP_SETUP_BASIC'],
advanced: translations['SERVICES.WP_SETUP_ADVANCED']
advanced: translations['SERVICES.WP_SETUP_ADVANCED'],
basicPriceId: '',
advancedPriceId: ''
},
{
name: translations['SERVICES.ANGULAR_FILES_NAME'],
basic: translations['SERVICES.ANGULAR_FILES_BASIC'],
advanced: translations['SERVICES.ANGULAR_FILES_ADVANCED']
advanced: translations['SERVICES.ANGULAR_FILES_ADVANCED'],
basicPriceId: '',
advancedPriceId: ''
},
{
name: translations['SERVICES.ANGULAR_SETUP_NAME'],
basic: translations['SERVICES.ANGULAR_SETUP_BASIC'],
advanced: translations['SERVICES.ANGULAR_SETUP_ADVANCED']
advanced: translations['SERVICES.ANGULAR_SETUP_ADVANCED'],
basicPriceId: '',
advancedPriceId: ''
},
{
name: translations['SERVICES.SERVER_SETUP_NAME'],
basic: translations['SERVICES.SERVER_SETUP_BASIC'],
advanced: translations['SERVICES.SERVER_SETUP_ADVANCED']
advanced: translations['SERVICES.SERVER_SETUP_ADVANCED'],
basicPriceId: '',
advancedPriceId: ''
}
];
@@ -121,4 +149,29 @@ export class ServicesComponent implements OnInit, OnDestroy, AfterViewInit {
// Update the minHeight and minWidth when the window is resized
this.vantaService.resizeVanta(this.elementId);
}
checkout(priceId: string): void {
fetch('http://localhost:7020/api/stripe/create-checkout-session', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ priceId })
})
.then(res => res.json())
.then(data => {
if (data.url) {
window.location.href = data.url;
} else {
alert('Checkout session failed.');
}
})
.catch(err => {
console.error('Stripe error:', err);
alert('Error creating checkout session.');
});
}
getActivePriceId(service: any, activeTab: string): string | null {
const priceId = activeTab === 'basic' ? service.basicPriceId : service.advancedPriceId;
return priceId?.trim() || null;
}
}