diff --git a/.gitignore b/.gitignore index de28197..4a3223f 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,7 @@ dist-ssr .env .env.* !.env.example + +# Generated Git Info +.git_*_info + diff --git a/Dockerfile b/Dockerfile index e61f333..32918a0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,6 +27,9 @@ RUN rm /etc/nginx/conf.d/default.conf COPY nginx.conf /etc/nginx/conf.d/default.conf COPY --from=builder /app/dist /usr/share/nginx/html +# Copy git info metadata if generated on host +COPY .git_store_info* /app/.git_store_info + RUN ln -sf /usr/share/nginx/html /usr/share/nginx/html/store EXPOSE 80 diff --git a/src/App.tsx b/src/App.tsx index 0a717a3..8be4ddb 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -664,10 +664,18 @@ export default function App() { console.error('Pricing engine calculation error:', err); if (appliedCoupon) { const errorMsg = err.response?.data?.detail || 'Invalid or expired coupon code.'; - setPricingCalc((prev: any) => ({ - ...(prev || {}), - coupon_error: errorMsg, - })); + setPricingCalc((prev: any) => { + if (!prev || prev.currency !== currency) { + return { + currency, + coupon_error: errorMsg, + }; + } + return { + ...prev, + coupon_error: errorMsg, + }; + }); } else { setPricingCalc(null); } @@ -953,28 +961,18 @@ export default function App() { const [downloadingModalInvoice, setDownloadingModalInvoice] = useState(false); const handleDownloadCheckoutInvoice = async (paymentId: string, directUrl?: string) => { - if (directUrl) { - window.open(directUrl, '_blank'); - switchTab('subscriptions'); - setVerificationResult(null); - return; - } - if (!userToken) return; setDownloadingModalInvoice(true); try { - const headers = { 'Authorization': `Bearer ${userToken}` }; - const res = await axios.get(`${API_BASE}/api/checkout/payment/${paymentId}/invoice`, { headers }); - const { short_url } = res.data; - if (short_url) { - window.open(short_url, '_blank'); - switchTab('subscriptions'); - setVerificationResult(null); - } else { - throw new Error('Invoice download URL is not available.'); + let targetUrl = directUrl; + if (!targetUrl || targetUrl.includes('rzp.io') || targetUrl.includes('razorpay.com')) { + targetUrl = `/api/checkout/payment/${paymentId}/invoice/view`; } - } catch (err: any) { - const errorMsg = err.response?.data?.detail || err.message || String(err); - alert(`Could not download invoice: ${errorMsg}`); + if (!targetUrl.startsWith('http')) { + targetUrl = `${API_BASE}${targetUrl.startsWith('/') ? '' : '/'}${targetUrl}`; + } + window.open(targetUrl, '_blank'); + switchTab('subscriptions'); + setVerificationResult(null); } finally { setDownloadingModalInvoice(false); } @@ -1067,6 +1065,7 @@ export default function App() { }} onSwitchTab={switchTab} curriculumModules={curriculumModules} + onDownloadInvoice={handleDownloadCheckoutInvoice} /> )} @@ -1157,6 +1156,7 @@ export default function App() { switchTab('storefront'); }} curriculumModules={curriculumModules} + onDownloadInvoice={handleDownloadCheckoutInvoice} /> {/* 🔐 Password Updated Success Modal */} diff --git a/src/components/auth/ProfileDrawer.tsx b/src/components/auth/ProfileDrawer.tsx index 39cbd10..4506fb7 100644 --- a/src/components/auth/ProfileDrawer.tsx +++ b/src/components/auth/ProfileDrawer.tsx @@ -1,7 +1,7 @@ import React, { useState } from 'react'; import { XCircle, Users, ShieldCheck, CheckCircle, AlertCircle, - Eye, EyeOff, RefreshCw, LogOut + Eye, EyeOff, RefreshCw, LogOut, Download } from 'lucide-react'; import type { UserProfile, ModuleItem, Currency } from '../../types'; import { COUNTRY_CODES, getCountryRuleByName } from '../../constants/countries'; @@ -37,6 +37,7 @@ interface ProfileDrawerProps { onLogout: () => void; onBrowseStorefront: () => void; curriculumModules: ModuleItem[]; + onDownloadInvoice?: (paymentId: string, directUrl?: string) => void; } export const ProfileDrawer: React.FC = ({ @@ -69,6 +70,7 @@ export const ProfileDrawer: React.FC = ({ onLogout, onBrowseStorefront, curriculumModules, + onDownloadInvoice, }) => { const [showOldPassword, setShowOldPassword] = useState(false); const [showNewPassword, setShowNewPassword] = useState(false); @@ -380,6 +382,23 @@ export const ProfileDrawer: React.FC = ({ )} + + {(sub.payment_id || sub.invoice_url) && onDownloadInvoice && ( +
+ + {sub.invoice_number ? `INV: ${sub.invoice_number}` : 'Official Invoice'} + + +
+ )} ); })} diff --git a/src/components/cart/CartDrawer.tsx b/src/components/cart/CartDrawer.tsx index 1f54418..5cc51b9 100644 --- a/src/components/cart/CartDrawer.tsx +++ b/src/components/cart/CartDrawer.tsx @@ -39,6 +39,30 @@ export const CartDrawer: React.FC = ({ checkoutLoading, handleCheckout, }) => { + const fallbackCalc = cart.length > 0 ? (() => { + const subtotal = cart.reduce((acc, item) => { + const price = currency === 'INR' ? item.priceInr : currency === 'EUR' ? item.priceEur : item.priceUsd; + return acc + (Number(price) || 0); + }, 0); + return { + currency, + base_subtotal: subtotal, + bundle_discount_amount: 0, + coupon_discount_amount: 0, + total_discounts: 0, + convenience_fee_rate: 0, + convenience_fee: 0, + taxable_amount: 0, + gst_amount: 0, + grand_total: subtotal, + discount_policy: 'None', + coupon_applied: 'None', + coupon_error: null, + }; + })() : null; + + const activePricing = (pricingCalc && pricingCalc.currency === currency) ? pricingCalc : fallbackCalc; + return (
@@ -58,21 +82,19 @@ export const CartDrawer: React.FC = ({
@@ -103,9 +125,7 @@ export const CartDrawer: React.FC = ({
{(() => { - const calculatedItem = pricingCalc?.currency === currency - ? pricingCalc?.cart_items?.find((ci: any) => ci.code === item.code) - : null; + const calculatedItem = activePricing?.cart_items?.find((ci: any) => ci.code === item.code); const price = calculatedItem ? calculatedItem.price : (currency === 'INR' ? item.priceInr : currency === 'EUR' ? item.priceEur : item.priceUsd); @@ -184,66 +204,109 @@ export const CartDrawer: React.FC = ({ Calculating {currency} pricing...
)} - {pricingCalc && pricingCalc.currency === currency && cart.length > 0 && ( + {activePricing && cart.length > 0 && (
Base Subtotal {currency === 'INR' - ? `₹${pricingCalc.base_subtotal}` + ? `₹${activePricing.base_subtotal}` : currency === 'EUR' - ? `€${pricingCalc.base_subtotal}` - : `$${pricingCalc.base_subtotal}`} + ? `€${activePricing.base_subtotal}` + : `$${activePricing.base_subtotal}`}
- {pricingCalc.bundle_discount_amount > 0 && ( + {activePricing.bundle_discount_amount > 0 && (
- Bundle Discount + + {activePricing.discount_policy && activePricing.discount_policy !== 'None' + ? (activePricing.discount_policy.startsWith('Staggered Buy:') + ? activePricing.discount_policy.replace('Staggered Buy:', 'Loyalty Discount:') + : activePricing.discount_policy) + : 'Loyalty Discount'} + -{currency === 'INR' - ? `₹${pricingCalc.bundle_discount_amount}` + ? `₹${activePricing.bundle_discount_amount}` : currency === 'EUR' - ? `€${pricingCalc.bundle_discount_amount}` - : `$${pricingCalc.bundle_discount_amount}`} + ? `€${activePricing.bundle_discount_amount}` + : `$${activePricing.bundle_discount_amount}`}
)} - {pricingCalc.coupon_discount_amount > 0 && ( + {activePricing.coupon_discount_amount > 0 && (
Coupon Discount ({appliedCoupon}) -{currency === 'INR' - ? `₹${pricingCalc.coupon_discount_amount}` + ? `₹${activePricing.coupon_discount_amount}` : currency === 'EUR' - ? `€${pricingCalc.coupon_discount_amount}` - : `$${pricingCalc.coupon_discount_amount}`} + ? `€${activePricing.coupon_discount_amount}` + : `$${activePricing.coupon_discount_amount}`}
)} - {pricingCalc.total_discounts > 0 && - !pricingCalc.bundle_discount_amount && - !pricingCalc.coupon_discount_amount && ( + {activePricing.total_discounts > 0 && + !activePricing.bundle_discount_amount && + !activePricing.coupon_discount_amount && (
Total Discounts -{currency === 'INR' - ? `₹${pricingCalc.total_discounts}` + ? `₹${activePricing.total_discounts}` : currency === 'EUR' - ? `€${pricingCalc.total_discounts}` - : `$${pricingCalc.total_discounts}`} + ? `€${activePricing.total_discounts}` + : `$${activePricing.total_discounts}`}
)} - + {activePricing.convenience_fee > 0 && ( +
+ Gateway fee ({activePricing.convenience_fee_rate}%) + + {currency === 'INR' + ? `₹${activePricing.convenience_fee}` + : currency === 'EUR' + ? `€${activePricing.convenience_fee}` + : `$${activePricing.convenience_fee}`} + +
+ )} + {activePricing.gst_amount > 0 && ( +
+
+ GST (18%) + + {currency === 'INR' + ? `₹${activePricing.gst_amount}` + : currency === 'EUR' + ? `€${activePricing.gst_amount}` + : `$${activePricing.gst_amount}`} + +
+
+ + (Taxable Amount:{' '} + {currency === 'INR' + ? `₹${activePricing.taxable_amount}` + : currency === 'EUR' + ? `€${activePricing.taxable_amount}` + : `$${activePricing.taxable_amount}`} + ) + + +
+
+ )}
Total Chargeable {currency === 'INR' - ? `₹${pricingCalc.grand_total}` + ? `₹${activePricing.grand_total}` : currency === 'EUR' - ? `€${pricingCalc.grand_total}` - : `$${pricingCalc.grand_total}`} + ? `€${activePricing.grand_total}` + : `$${activePricing.grand_total}`}
diff --git a/src/components/subscriptions/SubscriptionsView.tsx b/src/components/subscriptions/SubscriptionsView.tsx index 2bd906c..ce64f6b 100644 --- a/src/components/subscriptions/SubscriptionsView.tsx +++ b/src/components/subscriptions/SubscriptionsView.tsx @@ -1,5 +1,5 @@ import React, { useState } from 'react'; -import { CheckCircle } from 'lucide-react'; +import { CheckCircle, Download } from 'lucide-react'; import { Pagination } from '../common/Pagination'; import type { UserProfile, ModuleItem } from '../../types'; @@ -8,6 +8,7 @@ interface SubscriptionsViewProps { onOpenAuth: (mode: 'login') => void; onSwitchTab: (tab: 'storefront') => void; curriculumModules: ModuleItem[]; + onDownloadInvoice?: (paymentId: string, directUrl?: string) => void; } export const SubscriptionsView: React.FC = ({ @@ -15,6 +16,7 @@ export const SubscriptionsView: React.FC = ({ onOpenAuth, onSwitchTab, curriculumModules, + onDownloadInvoice, }) => { const [currentPage, setCurrentPage] = useState(1); const [pageSize, setPageSize] = useState(6); @@ -147,6 +149,28 @@ export const SubscriptionsView: React.FC = ({ )}
+ + {(sub.payment_id || sub.invoice_url) && onDownloadInvoice && ( +
+ {sub.invoice_number ? ( +
+ Invoice: + {sub.invoice_number} +
+ ) : ( + Tax Invoice + )} + +
+ )}
); diff --git a/src/types/index.ts b/src/types/index.ts index b8a5891..877ee68 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -20,6 +20,8 @@ export interface UserSubscription { expires_at?: string; is_active: boolean; payment_id?: string; + invoice_number?: string; + invoice_url?: string; metadata?: Record; }