saving payment data
This commit is contained in:
Binary file not shown.
@@ -675,4 +675,54 @@ def update_pricing_plan_status(plan_id):
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
db.session.rollback()
|
db.session.rollback()
|
||||||
|
return jsonify({'error': str(e)}), 500
|
||||||
|
|
||||||
|
@admin.route('/api/admin/pricing-plans', methods=['GET'])
|
||||||
|
@login_required
|
||||||
|
def get_pricing_plans():
|
||||||
|
"""Get all active pricing plans for instance launch"""
|
||||||
|
if not current_user.is_admin:
|
||||||
|
return jsonify({'error': 'Unauthorized'}), 403
|
||||||
|
|
||||||
|
try:
|
||||||
|
from models import PricingPlan
|
||||||
|
|
||||||
|
# Get all active pricing plans ordered by order_index
|
||||||
|
plans = PricingPlan.query.filter_by(is_active=True).order_by(PricingPlan.order_index).all()
|
||||||
|
|
||||||
|
plans_data = []
|
||||||
|
for plan in plans:
|
||||||
|
plans_data.append({
|
||||||
|
'id': plan.id,
|
||||||
|
'name': plan.name,
|
||||||
|
'description': plan.description,
|
||||||
|
'monthly_price': plan.monthly_price,
|
||||||
|
'annual_price': plan.annual_price,
|
||||||
|
'features': plan.features,
|
||||||
|
'button_text': plan.button_text,
|
||||||
|
'button_url': plan.button_url,
|
||||||
|
'is_popular': plan.is_popular,
|
||||||
|
'is_custom': plan.is_custom,
|
||||||
|
'is_active': plan.is_active,
|
||||||
|
'order_index': plan.order_index,
|
||||||
|
'room_quota': plan.room_quota,
|
||||||
|
'conversation_quota': plan.conversation_quota,
|
||||||
|
'storage_quota_gb': plan.storage_quota_gb,
|
||||||
|
'manager_quota': plan.manager_quota,
|
||||||
|
'admin_quota': plan.admin_quota,
|
||||||
|
'format_quota_display': {
|
||||||
|
'room_quota': plan.format_quota_display('room_quota'),
|
||||||
|
'conversation_quota': plan.format_quota_display('conversation_quota'),
|
||||||
|
'storage_quota_gb': plan.format_quota_display('storage_quota_gb'),
|
||||||
|
'manager_quota': plan.format_quota_display('manager_quota'),
|
||||||
|
'admin_quota': plan.format_quota_display('admin_quota')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
'success': True,
|
||||||
|
'plans': plans_data
|
||||||
|
})
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
return jsonify({'error': str(e)}), 500
|
return jsonify({'error': str(e)}), 500
|
||||||
@@ -2599,6 +2599,32 @@ async function checkStackExists(stackName) {
|
|||||||
// Add new function to deploy stack
|
// Add new function to deploy stack
|
||||||
async function deployStack(dockerComposeContent, stackName, port) {
|
async function deployStack(dockerComposeContent, stackName, port) {
|
||||||
try {
|
try {
|
||||||
|
// Get the launch data from sessionStorage to access pricing tier info
|
||||||
|
const launchData = JSON.parse(sessionStorage.getItem('instanceLaunchData'));
|
||||||
|
|
||||||
|
// Fetch the pricing tier details to get the actual quota values
|
||||||
|
let pricingTierDetails = null;
|
||||||
|
if (launchData?.pricingTier?.id) {
|
||||||
|
try {
|
||||||
|
const pricingResponse = await fetch(`/api/admin/pricing-plans/${launchData.pricingTier.id}`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').content
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (pricingResponse.ok) {
|
||||||
|
const pricingData = await pricingResponse.json();
|
||||||
|
if (pricingData.success) {
|
||||||
|
pricingTierDetails = pricingData.plan;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Failed to fetch pricing tier details:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// First, attempt to deploy the stack
|
// First, attempt to deploy the stack
|
||||||
const response = await fetch('/api/admin/deploy-stack', {
|
const response = await fetch('/api/admin/deploy-stack', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -2633,6 +2659,35 @@ async function deployStack(dockerComposeContent, stackName, port) {
|
|||||||
{
|
{
|
||||||
name: 'DEPLOYED_AT',
|
name: 'DEPLOYED_AT',
|
||||||
value: new Date().toISOString()
|
value: new Date().toISOString()
|
||||||
|
},
|
||||||
|
// Pricing tier environment variables with actual quota values
|
||||||
|
{
|
||||||
|
name: 'PRICING_TIER_ID',
|
||||||
|
value: launchData?.pricingTier?.id?.toString() || '0'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'PRICING_TIER_NAME',
|
||||||
|
value: launchData?.pricingTier?.name || 'Unknown'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'ROOM_QUOTA',
|
||||||
|
value: pricingTierDetails?.room_quota?.toString() || '0'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'CONVERSATION_QUOTA',
|
||||||
|
value: pricingTierDetails?.conversation_quota?.toString() || '0'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'STORAGE_QUOTA_GB',
|
||||||
|
value: pricingTierDetails?.storage_quota_gb?.toString() || '0'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'MANAGER_QUOTA',
|
||||||
|
value: pricingTierDetails?.manager_quota?.toString() || '0'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'ADMIN_QUOTA',
|
||||||
|
value: pricingTierDetails?.admin_quota?.toString() || '0'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -49,6 +49,54 @@
|
|||||||
.badge.bg-orange:hover {
|
.badge.bg-orange:hover {
|
||||||
background-color: #e55a00 !important;
|
background-color: #e55a00 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Pricing tier selection styles */
|
||||||
|
.pricing-card {
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
border: 2px solid transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pricing-card:hover {
|
||||||
|
transform: translateY(-2px);
|
||||||
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
||||||
|
border-color: var(--primary-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.pricing-card.selected {
|
||||||
|
border-color: var(--primary-color);
|
||||||
|
background-color: rgba(22, 118, 123, 0.05);
|
||||||
|
box-shadow: 0 4px 12px rgba(22, 118, 123, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.pricing-card.selected::after {
|
||||||
|
content: '✓';
|
||||||
|
position: absolute;
|
||||||
|
top: 10px;
|
||||||
|
right: 10px;
|
||||||
|
background-color: var(--primary-color);
|
||||||
|
color: white;
|
||||||
|
width: 24px;
|
||||||
|
height: 24px;
|
||||||
|
border-radius: 50%;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pricing-card.border-primary {
|
||||||
|
border-color: var(--primary-color) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.quota-info {
|
||||||
|
font-size: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.features {
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
@@ -246,6 +294,10 @@
|
|||||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
|
<!-- Hidden fields for pricing tier selection -->
|
||||||
|
<input type="hidden" id="selectedPricingTierId" value="">
|
||||||
|
<input type="hidden" id="selectedPricingTierName" value="">
|
||||||
|
|
||||||
<!-- Steps Navigation -->
|
<!-- Steps Navigation -->
|
||||||
<div class="d-flex justify-content-between mb-4">
|
<div class="d-flex justify-content-between mb-4">
|
||||||
<div class="step-item active" data-step="1">
|
<div class="step-item active" data-step="1">
|
||||||
@@ -270,6 +322,10 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="step-item" data-step="6">
|
<div class="step-item" data-step="6">
|
||||||
<div class="step-circle">6</div>
|
<div class="step-circle">6</div>
|
||||||
|
<div class="step-label">Pricing Tier</div>
|
||||||
|
</div>
|
||||||
|
<div class="step-item" data-step="7">
|
||||||
|
<div class="step-circle">7</div>
|
||||||
<div class="step-label">Launch</div>
|
<div class="step-label">Launch</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -479,8 +535,30 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Step 6 -->
|
<!-- Step 6: Pricing Tier Selection -->
|
||||||
<div class="step-pane" id="step6">
|
<div class="step-pane" id="step6">
|
||||||
|
<div class="step-content">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title mb-4">Select Pricing Tier</h5>
|
||||||
|
<p class="text-muted mb-4">Choose the pricing tier that best fits your needs. This will determine the resource limits for your instance.</p>
|
||||||
|
|
||||||
|
<div id="pricingTiersContainer" class="row">
|
||||||
|
<!-- Pricing tiers will be loaded here -->
|
||||||
|
<div class="col-12 text-center">
|
||||||
|
<div class="spinner-border text-primary" role="status">
|
||||||
|
<span class="visually-hidden">Loading pricing tiers...</span>
|
||||||
|
</div>
|
||||||
|
<p class="mt-2">Loading available pricing tiers...</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Step 7 -->
|
||||||
|
<div class="step-pane" id="step7">
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<i class="fas fa-rocket fa-4x mb-4" style="color: var(--primary-color);"></i>
|
<i class="fas fa-rocket fa-4x mb-4" style="color: var(--primary-color);"></i>
|
||||||
<h4>Ready to Launch!</h4>
|
<h4>Ready to Launch!</h4>
|
||||||
@@ -494,6 +572,7 @@
|
|||||||
<p><strong>Repository:</strong> <span id="reviewRepo"></span></p>
|
<p><strong>Repository:</strong> <span id="reviewRepo"></span></p>
|
||||||
<p><strong>Branch:</strong> <span id="reviewBranch"></span></p>
|
<p><strong>Branch:</strong> <span id="reviewBranch"></span></p>
|
||||||
<p><strong>Company:</strong> <span id="reviewCompany"></span></p>
|
<p><strong>Company:</strong> <span id="reviewCompany"></span></p>
|
||||||
|
<p><strong>Pricing Tier:</strong> <span id="reviewPricingTier"></span></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<p><strong>Port:</strong> <span id="reviewPort"></span></p>
|
<p><strong>Port:</strong> <span id="reviewPort"></span></p>
|
||||||
@@ -723,7 +802,7 @@ let launchStepsModal;
|
|||||||
let currentStep = 1;
|
let currentStep = 1;
|
||||||
|
|
||||||
// Update the total number of steps
|
// Update the total number of steps
|
||||||
const totalSteps = 6;
|
const totalSteps = 7;
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
addInstanceModal = new bootstrap.Modal(document.getElementById('addInstanceModal'));
|
addInstanceModal = new bootstrap.Modal(document.getElementById('addInstanceModal'));
|
||||||
@@ -1650,6 +1729,11 @@ function updateStepDisplay() {
|
|||||||
if (currentStep === 4) {
|
if (currentStep === 4) {
|
||||||
getNextAvailablePort();
|
getNextAvailablePort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we're on step 6, load pricing tiers
|
||||||
|
if (currentStep === 6) {
|
||||||
|
loadPricingTiers();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function nextStep() {
|
function nextStep() {
|
||||||
@@ -1662,6 +1746,9 @@ function nextStep() {
|
|||||||
if (currentStep === 4 && !validateStep4()) {
|
if (currentStep === 4 && !validateStep4()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (currentStep === 6 && !validateStep6()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (currentStep < totalSteps) {
|
if (currentStep < totalSteps) {
|
||||||
currentStep++;
|
currentStep++;
|
||||||
@@ -2066,6 +2153,7 @@ function updateReviewSection() {
|
|||||||
const webAddresses = Array.from(document.querySelectorAll('.web-address'))
|
const webAddresses = Array.from(document.querySelectorAll('.web-address'))
|
||||||
.map(input => input.value)
|
.map(input => input.value)
|
||||||
.join(', ');
|
.join(', ');
|
||||||
|
const pricingTier = document.getElementById('selectedPricingTierName').value;
|
||||||
|
|
||||||
// Update the review section
|
// Update the review section
|
||||||
document.getElementById('reviewRepo').textContent = repo;
|
document.getElementById('reviewRepo').textContent = repo;
|
||||||
@@ -2073,6 +2161,7 @@ function updateReviewSection() {
|
|||||||
document.getElementById('reviewCompany').textContent = company;
|
document.getElementById('reviewCompany').textContent = company;
|
||||||
document.getElementById('reviewPort').textContent = port;
|
document.getElementById('reviewPort').textContent = port;
|
||||||
document.getElementById('reviewWebAddresses').textContent = webAddresses;
|
document.getElementById('reviewWebAddresses').textContent = webAddresses;
|
||||||
|
document.getElementById('reviewPricingTier').textContent = pricingTier || 'Not selected';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to launch the instance
|
// Function to launch the instance
|
||||||
@@ -2099,6 +2188,10 @@ function launchInstance() {
|
|||||||
colors: {
|
colors: {
|
||||||
primary: document.getElementById('primaryColor').value,
|
primary: document.getElementById('primaryColor').value,
|
||||||
secondary: document.getElementById('secondaryColor').value
|
secondary: document.getElementById('secondaryColor').value
|
||||||
|
},
|
||||||
|
pricingTier: {
|
||||||
|
id: document.getElementById('selectedPricingTierId').value,
|
||||||
|
name: document.getElementById('selectedPricingTierName').value
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -2240,5 +2333,119 @@ async function refreshLatestVersion() {
|
|||||||
console.log('Manual refresh of latest version requested');
|
console.log('Manual refresh of latest version requested');
|
||||||
await fetchLatestVersion();
|
await fetchLatestVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Function to load pricing tiers
|
||||||
|
async function loadPricingTiers() {
|
||||||
|
const container = document.getElementById('pricingTiersContainer');
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch('/api/admin/pricing-plans', {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').content
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('Failed to load pricing tiers');
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
if (data.plans && data.plans.length > 0) {
|
||||||
|
container.innerHTML = data.plans.map(plan => `
|
||||||
|
<div class="col-md-6 col-lg-4 mb-3">
|
||||||
|
<div class="card pricing-card h-100 ${plan.is_popular ? 'border-primary' : ''}"
|
||||||
|
onclick="selectPricingTier(${plan.id}, '${plan.name}')">
|
||||||
|
<div class="card-body text-center">
|
||||||
|
${plan.is_popular ? '<div class="badge bg-primary mb-2">Most Popular</div>' : ''}
|
||||||
|
<h5 class="card-title">${plan.name}</h5>
|
||||||
|
${plan.description ? `<p class="text-muted small mb-3">${plan.description}</p>` : ''}
|
||||||
|
|
||||||
|
<div class="pricing mb-3">
|
||||||
|
${plan.is_custom ?
|
||||||
|
'<span class="h4 text-primary">Custom Pricing</span>' :
|
||||||
|
`<span class="h4 text-primary">€${plan.monthly_price}</span><span class="text-muted">/month</span>`
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="quota-info small text-muted mb-3">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-6">
|
||||||
|
<i class="fas fa-door-open me-1"></i>${plan.format_quota_display.room_quota}<br>
|
||||||
|
<i class="fas fa-comments me-1"></i>${plan.format_quota_display.conversation_quota}<br>
|
||||||
|
<i class="fas fa-hdd me-1"></i>${plan.format_quota_display.storage_quota_gb}
|
||||||
|
</div>
|
||||||
|
<div class="col-6">
|
||||||
|
<i class="fas fa-user-tie me-1"></i>${plan.format_quota_display.manager_quota}<br>
|
||||||
|
<i class="fas fa-user-shield me-1"></i>${plan.format_quota_display.admin_quota}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="features small">
|
||||||
|
${plan.features.slice(0, 3).map(feature => `<div>✓ ${feature}</div>`).join('')}
|
||||||
|
${plan.features.length > 3 ? `<div class="text-muted">+${plan.features.length - 3} more features</div>` : ''}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`).join('');
|
||||||
|
} else {
|
||||||
|
container.innerHTML = `
|
||||||
|
<div class="col-12 text-center">
|
||||||
|
<div class="alert alert-warning">
|
||||||
|
<i class="fas fa-exclamation-triangle me-2"></i>
|
||||||
|
No pricing tiers available. Please contact your administrator.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error loading pricing tiers:', error);
|
||||||
|
container.innerHTML = `
|
||||||
|
<div class="col-12 text-center">
|
||||||
|
<div class="alert alert-danger">
|
||||||
|
<i class="fas fa-exclamation-triangle me-2"></i>
|
||||||
|
Error loading pricing tiers: ${error.message}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to select a pricing tier
|
||||||
|
function selectPricingTier(planId, planName) {
|
||||||
|
// Remove selection from all cards
|
||||||
|
document.querySelectorAll('.pricing-card').forEach(card => {
|
||||||
|
card.classList.remove('selected');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add selection to clicked card
|
||||||
|
event.currentTarget.classList.add('selected');
|
||||||
|
|
||||||
|
// Store the selection
|
||||||
|
document.getElementById('selectedPricingTierId').value = planId;
|
||||||
|
document.getElementById('selectedPricingTierName').value = planName;
|
||||||
|
|
||||||
|
// Enable next button if not already enabled
|
||||||
|
const nextButton = document.querySelector('#launchStepsFooter .btn-primary');
|
||||||
|
if (nextButton.disabled) {
|
||||||
|
nextButton.disabled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to validate step 6 (pricing tier selection)
|
||||||
|
function validateStep6() {
|
||||||
|
const selectedTierId = document.getElementById('selectedPricingTierId').value;
|
||||||
|
|
||||||
|
if (!selectedTierId) {
|
||||||
|
alert('Please select a pricing tier before proceeding.');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user