Available Credits
+
Refill
LPA
0): ?>
@@ -71,7 +72,7 @@ try {
-
Insufficient Credits: You do not have enough credits to start a new LPA application. Please contact your administrator to allocate more credits.
+
Insufficient Credits: You do not have enough credits to start a new LPA application. Click here to purchase credits.
diff --git a/db/migrations/08_add_stripe_and_invoices.sql b/db/migrations/08_add_stripe_and_invoices.sql
new file mode 100644
index 0000000..1b8310b
--- /dev/null
+++ b/db/migrations/08_add_stripe_and_invoices.sql
@@ -0,0 +1,48 @@
+-- Add Stripe Configuration table
+CREATE TABLE IF NOT EXISTS stripe_config (
+ id INT AUTO_INCREMENT PRIMARY KEY,
+ setting_key VARCHAR(255) UNIQUE NOT NULL,
+ setting_value TEXT,
+ updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
+) ENGINE=InnoDB;
+
+-- Insert default placeholder keys (empty values)
+INSERT IGNORE INTO stripe_config (setting_key, setting_value) VALUES
+('stripe_publishable_key', ''),
+('stripe_secret_key', ''),
+('stripe_webhook_secret', ''),
+('currency', 'GBP');
+
+-- Create Credit Packages table
+CREATE TABLE IF NOT EXISTS credit_packages (
+ id INT AUTO_INCREMENT PRIMARY KEY,
+ name VARCHAR(255) NOT NULL,
+ description TEXT,
+ credits INT NOT NULL,
+ price_amount DECIMAL(10, 2) NOT NULL,
+ price_currency VARCHAR(3) DEFAULT 'GBP',
+ is_active BOOLEAN DEFAULT TRUE,
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
+) ENGINE=InnoDB;
+
+-- Insert initial credit packages
+INSERT IGNORE INTO credit_packages (name, description, credits, price_amount) VALUES
+('Single LPA', 'Purchase 1 LPA credit', 1, 39.00),
+('Standard Pack', 'Purchase 3 LPA credits', 3, 99.00),
+('Value Pack', 'Purchase 5 LPA credits', 5, 149.00);
+
+-- Create Invoices table
+CREATE TABLE IF NOT EXISTS invoices (
+ id INT AUTO_INCREMENT PRIMARY KEY,
+ user_id INT NOT NULL,
+ invoice_number VARCHAR(50) UNIQUE NOT NULL,
+ amount DECIMAL(10, 2) NOT NULL,
+ currency VARCHAR(3) DEFAULT 'GBP',
+ status VARCHAR(50) DEFAULT 'unpaid', -- unpaid, paid, cancelled
+ stripe_payment_intent_id VARCHAR(255),
+ credits_added INT DEFAULT 0,
+ items_json TEXT, -- JSON representation of items purchased
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+ paid_at TIMESTAMP NULL,
+ FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
+) ENGINE=InnoDB;
diff --git a/purchase_credits.php b/purchase_credits.php
new file mode 100644
index 0000000..ccf38ff
--- /dev/null
+++ b/purchase_credits.php
@@ -0,0 +1,164 @@
+prepare("SELECT credits FROM users WHERE id = ?");
+$stmt->execute([$_SESSION['user_id']]);
+$current_credits = $stmt->fetchColumn() ?: 0;
+
+// Fetch active packages
+$packages = $db->query("SELECT * FROM credit_packages WHERE is_active = 1 ORDER BY price_amount ASC")->fetchAll();
+
+// Fetch Stripe publishable key
+$stripe_pk = $db->query("SELECT setting_value FROM stripe_config WHERE setting_key = 'stripe_publishable_key'")->fetchColumn();
+
+// Fetch user invoices
+$stmt = $db->prepare("SELECT * FROM invoices WHERE user_id = ? ORDER BY created_at DESC");
+$stmt->execute([$_SESSION['user_id']]);
+$invoices = $stmt->fetchAll();
+?>
+
+
+
+
+
+
Purchase Credits —
+
+
+
+
+
+
+
+
+
+
Refill LPA Credits
+
Select the most appropriate package to continue creating your Lasting Power of Attorney documents.
+
+ Current Balance:
+ Credits
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ LPA Credits
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ | Invoice # |
+ Date |
+ Amount |
+ Status |
+ Receipt |
+
+
+
+
+
+ | # |
+ |
+ |
+
+
+
+
+ |
+
+
+ Download PDF
+
+ Pending
+
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+