fixed-issue(32): cupon validation and other minor issues like gateway fees and UI #51

Merged
amit merged 2 commits from cupon-validation-fix into main 2026-10-15 05:03:56 +00:00
7 changed files with 172 additions and 57 deletions
Showing only changes of commit 8f7864bb4d - Show all commits

4
.gitignore vendored
View File

@ -27,3 +27,7 @@ dist-ssr
.env .env
.env.* .env.*
!.env.example !.env.example
# Generated Git Info
.git_*_info

View File

@ -27,6 +27,9 @@ RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /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 --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 RUN ln -sf /usr/share/nginx/html /usr/share/nginx/html/store
EXPOSE 80 EXPOSE 80

View File

@ -664,10 +664,18 @@ export default function App() {
console.error('Pricing engine calculation error:', err); console.error('Pricing engine calculation error:', err);
if (appliedCoupon) { if (appliedCoupon) {
const errorMsg = err.response?.data?.detail || 'Invalid or expired coupon code.'; const errorMsg = err.response?.data?.detail || 'Invalid or expired coupon code.';
setPricingCalc((prev: any) => ({ setPricingCalc((prev: any) => {
...(prev || {}), if (!prev || prev.currency !== currency) {
return {
currency,
coupon_error: errorMsg, coupon_error: errorMsg,
})); };
}
return {
...prev,
coupon_error: errorMsg,
};
});
} else { } else {
setPricingCalc(null); setPricingCalc(null);
} }
@ -953,28 +961,18 @@ export default function App() {
const [downloadingModalInvoice, setDownloadingModalInvoice] = useState<boolean>(false); const [downloadingModalInvoice, setDownloadingModalInvoice] = useState<boolean>(false);
const handleDownloadCheckoutInvoice = async (paymentId: string, directUrl?: string) => { const handleDownloadCheckoutInvoice = async (paymentId: string, directUrl?: string) => {
if (directUrl) {
window.open(directUrl, '_blank');
switchTab('subscriptions');
setVerificationResult(null);
return;
}
if (!userToken) return;
setDownloadingModalInvoice(true); setDownloadingModalInvoice(true);
try { try {
const headers = { 'Authorization': `Bearer ${userToken}` }; let targetUrl = directUrl;
const res = await axios.get(`${API_BASE}/api/checkout/payment/${paymentId}/invoice`, { headers }); if (!targetUrl || targetUrl.includes('rzp.io') || targetUrl.includes('razorpay.com')) {
const { short_url } = res.data; targetUrl = `/api/checkout/payment/${paymentId}/invoice/view`;
if (short_url) { }
window.open(short_url, '_blank'); if (!targetUrl.startsWith('http')) {
targetUrl = `${API_BASE}${targetUrl.startsWith('/') ? '' : '/'}${targetUrl}`;
}
window.open(targetUrl, '_blank');
switchTab('subscriptions'); switchTab('subscriptions');
setVerificationResult(null); setVerificationResult(null);
} else {
throw new Error('Invoice download URL is not available.');
}
} catch (err: any) {
const errorMsg = err.response?.data?.detail || err.message || String(err);
alert(`Could not download invoice: ${errorMsg}`);
} finally { } finally {
setDownloadingModalInvoice(false); setDownloadingModalInvoice(false);
} }
@ -1067,6 +1065,7 @@ export default function App() {
}} }}
onSwitchTab={switchTab} onSwitchTab={switchTab}
curriculumModules={curriculumModules} curriculumModules={curriculumModules}
onDownloadInvoice={handleDownloadCheckoutInvoice}
/> />
)} )}
@ -1157,6 +1156,7 @@ export default function App() {
switchTab('storefront'); switchTab('storefront');
}} }}
curriculumModules={curriculumModules} curriculumModules={curriculumModules}
onDownloadInvoice={handleDownloadCheckoutInvoice}
/> />
{/* 🔐 Password Updated Success Modal */} {/* 🔐 Password Updated Success Modal */}

View File

@ -1,7 +1,7 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import { import {
XCircle, Users, ShieldCheck, CheckCircle, AlertCircle, XCircle, Users, ShieldCheck, CheckCircle, AlertCircle,
Eye, EyeOff, RefreshCw, LogOut Eye, EyeOff, RefreshCw, LogOut, Download
} from 'lucide-react'; } from 'lucide-react';
import type { UserProfile, ModuleItem, Currency } from '../../types'; import type { UserProfile, ModuleItem, Currency } from '../../types';
import { COUNTRY_CODES, getCountryRuleByName } from '../../constants/countries'; import { COUNTRY_CODES, getCountryRuleByName } from '../../constants/countries';
@ -37,6 +37,7 @@ interface ProfileDrawerProps {
onLogout: () => void; onLogout: () => void;
onBrowseStorefront: () => void; onBrowseStorefront: () => void;
curriculumModules: ModuleItem[]; curriculumModules: ModuleItem[];
onDownloadInvoice?: (paymentId: string, directUrl?: string) => void;
} }
export const ProfileDrawer: React.FC<ProfileDrawerProps> = ({ export const ProfileDrawer: React.FC<ProfileDrawerProps> = ({
@ -69,6 +70,7 @@ export const ProfileDrawer: React.FC<ProfileDrawerProps> = ({
onLogout, onLogout,
onBrowseStorefront, onBrowseStorefront,
curriculumModules, curriculumModules,
onDownloadInvoice,
}) => { }) => {
const [showOldPassword, setShowOldPassword] = useState(false); const [showOldPassword, setShowOldPassword] = useState(false);
const [showNewPassword, setShowNewPassword] = useState(false); const [showNewPassword, setShowNewPassword] = useState(false);
@ -380,6 +382,23 @@ export const ProfileDrawer: React.FC<ProfileDrawerProps> = ({
</span> </span>
)} )}
</div> </div>
{(sub.payment_id || sub.invoice_url) && onDownloadInvoice && (
<div className="pt-2 border-t border-slate-200/60 flex items-center justify-between">
<span className="text-[9px] font-mono text-slate-500 font-semibold truncate">
{sub.invoice_number ? `INV: ${sub.invoice_number}` : 'Official Invoice'}
</span>
<button
type="button"
onClick={() => onDownloadInvoice(sub.payment_id || '', sub.invoice_url)}
className="inline-flex items-center gap-1 text-[10px] font-bold text-indigo-600 hover:text-indigo-700 bg-indigo-50 hover:bg-indigo-100 px-2 py-1 rounded-md border border-indigo-200 transition-colors cursor-pointer"
title="Download Tax Invoice"
>
<Download className="h-2.5 w-2.5" />
<span>Invoice</span>
</button>
</div>
)}
</div> </div>
); );
})} })}

View File

@ -39,6 +39,30 @@ export const CartDrawer: React.FC<CartDrawerProps> = ({
checkoutLoading, checkoutLoading,
handleCheckout, 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 ( return (
<div className="xl:col-span-1"> <div className="xl:col-span-1">
<div className="sticky top-12 bg-white border border-slate-200 rounded-3xl p-6 shadow-xl space-y-6"> <div className="sticky top-12 bg-white border border-slate-200 rounded-3xl p-6 shadow-xl space-y-6">
@ -58,8 +82,7 @@ export const CartDrawer: React.FC<CartDrawerProps> = ({
<div className="flex bg-slate-100 rounded-lg p-0.5 border border-slate-200 self-end sm:self-auto flex-shrink-0"> <div className="flex bg-slate-100 rounded-lg p-0.5 border border-slate-200 self-end sm:self-auto flex-shrink-0">
<button <button
onClick={() => setCurrency('INR')} onClick={() => setCurrency('INR')}
className={`px-3 py-1 rounded-md text-xs font-bold transition-all duration-300 ${ className={`px-3 py-1 rounded-md text-xs font-bold transition-all duration-300 ${currency === 'INR'
currency === 'INR'
? 'bg-white text-slate-900 shadow-sm border border-slate-200/50' ? 'bg-white text-slate-900 shadow-sm border border-slate-200/50'
: 'text-slate-500 hover:text-slate-800' : 'text-slate-500 hover:text-slate-800'
}`} }`}
@ -68,8 +91,7 @@ export const CartDrawer: React.FC<CartDrawerProps> = ({
</button> </button>
<button <button
onClick={() => setCurrency('USD')} onClick={() => setCurrency('USD')}
className={`px-3 py-1 rounded-md text-xs font-bold transition-all duration-300 ${ className={`px-3 py-1 rounded-md text-xs font-bold transition-all duration-300 ${currency === 'USD'
currency === 'USD'
? 'bg-white text-slate-900 shadow-sm border border-slate-200/50' ? 'bg-white text-slate-900 shadow-sm border border-slate-200/50'
: 'text-slate-500 hover:text-slate-800' : 'text-slate-500 hover:text-slate-800'
}`} }`}
@ -103,9 +125,7 @@ export const CartDrawer: React.FC<CartDrawerProps> = ({
<div className="flex items-center gap-3"> <div className="flex items-center gap-3">
<span className="text-xs font-bold text-indigo-600"> <span className="text-xs font-bold text-indigo-600">
{(() => { {(() => {
const calculatedItem = pricingCalc?.currency === currency const calculatedItem = activePricing?.cart_items?.find((ci: any) => ci.code === item.code);
? pricingCalc?.cart_items?.find((ci: any) => ci.code === item.code)
: null;
const price = calculatedItem const price = calculatedItem
? calculatedItem.price ? calculatedItem.price
: (currency === 'INR' ? item.priceInr : currency === 'EUR' ? item.priceEur : item.priceUsd); : (currency === 'INR' ? item.priceInr : currency === 'EUR' ? item.priceEur : item.priceUsd);
@ -184,66 +204,109 @@ export const CartDrawer: React.FC<CartDrawerProps> = ({
<span>Calculating {currency} pricing...</span> <span>Calculating {currency} pricing...</span>
</div> </div>
)} )}
{pricingCalc && pricingCalc.currency === currency && cart.length > 0 && ( {activePricing && cart.length > 0 && (
<div className="space-y-3 bg-slate-50 border border-slate-200/60 p-4 rounded-2xl"> <div className="space-y-3 bg-slate-50 border border-slate-200/60 p-4 rounded-2xl">
<div className="flex justify-between text-xs text-slate-600 font-bold"> <div className="flex justify-between text-xs text-slate-600 font-bold">
<span>Base Subtotal</span> <span>Base Subtotal</span>
<span> <span>
{currency === 'INR' {currency === 'INR'
? `₹${pricingCalc.base_subtotal}` ? `₹${activePricing.base_subtotal}`
: currency === 'EUR' : currency === 'EUR'
? `€${pricingCalc.base_subtotal}` ? `€${activePricing.base_subtotal}`
: `$${pricingCalc.base_subtotal}`} : `$${activePricing.base_subtotal}`}
</span> </span>
</div> </div>
{pricingCalc.bundle_discount_amount > 0 && ( {activePricing.bundle_discount_amount > 0 && (
<div className="flex justify-between text-xs text-emerald-700 font-bold"> <div className="flex justify-between text-xs text-emerald-700 font-bold">
<span>Bundle Discount</span> <span>
{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'}
</span>
<span> <span>
-{currency === 'INR' -{currency === 'INR'
? `₹${pricingCalc.bundle_discount_amount}` ? `₹${activePricing.bundle_discount_amount}`
: currency === 'EUR' : currency === 'EUR'
? `€${pricingCalc.bundle_discount_amount}` ? `€${activePricing.bundle_discount_amount}`
: `$${pricingCalc.bundle_discount_amount}`} : `$${activePricing.bundle_discount_amount}`}
</span> </span>
</div> </div>
)} )}
{pricingCalc.coupon_discount_amount > 0 && ( {activePricing.coupon_discount_amount > 0 && (
<div className="flex justify-between text-xs text-emerald-700 font-bold"> <div className="flex justify-between text-xs text-emerald-700 font-bold">
<span>Coupon Discount ({appliedCoupon})</span> <span>Coupon Discount ({appliedCoupon})</span>
<span> <span>
-{currency === 'INR' -{currency === 'INR'
? `₹${pricingCalc.coupon_discount_amount}` ? `₹${activePricing.coupon_discount_amount}`
: currency === 'EUR' : currency === 'EUR'
? `€${pricingCalc.coupon_discount_amount}` ? `€${activePricing.coupon_discount_amount}`
: `$${pricingCalc.coupon_discount_amount}`} : `$${activePricing.coupon_discount_amount}`}
</span> </span>
</div> </div>
)} )}
{pricingCalc.total_discounts > 0 && {activePricing.total_discounts > 0 &&
!pricingCalc.bundle_discount_amount && !activePricing.bundle_discount_amount &&
!pricingCalc.coupon_discount_amount && ( !activePricing.coupon_discount_amount && (
<div className="flex justify-between text-xs text-emerald-700 font-bold"> <div className="flex justify-between text-xs text-emerald-700 font-bold">
<span>Total Discounts</span> <span>Total Discounts</span>
<span> <span>
-{currency === 'INR' -{currency === 'INR'
? `₹${pricingCalc.total_discounts}` ? `₹${activePricing.total_discounts}`
: currency === 'EUR' : currency === 'EUR'
? `€${pricingCalc.total_discounts}` ? `€${activePricing.total_discounts}`
: `$${pricingCalc.total_discounts}`} : `$${activePricing.total_discounts}`}
</span> </span>
</div> </div>
)} )}
{activePricing.convenience_fee > 0 && (
<div className="flex justify-between text-xs text-slate-600 font-bold">
<span>Gateway fee ({activePricing.convenience_fee_rate}%)</span>
<span>
{currency === 'INR'
? `₹${activePricing.convenience_fee}`
: currency === 'EUR'
? `€${activePricing.convenience_fee}`
: `$${activePricing.convenience_fee}`}
</span>
</div>
)}
{activePricing.gst_amount > 0 && (
<div className="space-y-0.5">
<div className="flex justify-between text-xs text-slate-600 font-bold">
<span>GST (18%)</span>
<span>
{currency === 'INR'
? `₹${activePricing.gst_amount}`
: currency === 'EUR'
? `€${activePricing.gst_amount}`
: `$${activePricing.gst_amount}`}
</span>
</div>
<div className="flex justify-between text-[10px] text-slate-400 font-semibold italic">
<span>
(Taxable Amount:{' '}
{currency === 'INR'
? `₹${activePricing.taxable_amount}`
: currency === 'EUR'
? `€${activePricing.taxable_amount}`
: `$${activePricing.taxable_amount}`}
)
</span>
<span></span>
</div>
</div>
)}
<div className="h-px bg-slate-200 my-2" /> <div className="h-px bg-slate-200 my-2" />
<div className="flex justify-between items-center text-sm font-bold text-slate-800"> <div className="flex justify-between items-center text-sm font-bold text-slate-800">
<span>Total Chargeable</span> <span>Total Chargeable</span>
<span className="text-indigo-600 text-lg font-extrabold"> <span className="text-indigo-600 text-lg font-extrabold">
{currency === 'INR' {currency === 'INR'
? `₹${pricingCalc.grand_total}` ? `₹${activePricing.grand_total}`
: currency === 'EUR' : currency === 'EUR'
? `€${pricingCalc.grand_total}` ? `€${activePricing.grand_total}`
: `$${pricingCalc.grand_total}`} : `$${activePricing.grand_total}`}
</span> </span>
</div> </div>
</div> </div>

View File

@ -1,5 +1,5 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import { CheckCircle } from 'lucide-react'; import { CheckCircle, Download } from 'lucide-react';
import { Pagination } from '../common/Pagination'; import { Pagination } from '../common/Pagination';
import type { UserProfile, ModuleItem } from '../../types'; import type { UserProfile, ModuleItem } from '../../types';
@ -8,6 +8,7 @@ interface SubscriptionsViewProps {
onOpenAuth: (mode: 'login') => void; onOpenAuth: (mode: 'login') => void;
onSwitchTab: (tab: 'storefront') => void; onSwitchTab: (tab: 'storefront') => void;
curriculumModules: ModuleItem[]; curriculumModules: ModuleItem[];
onDownloadInvoice?: (paymentId: string, directUrl?: string) => void;
} }
export const SubscriptionsView: React.FC<SubscriptionsViewProps> = ({ export const SubscriptionsView: React.FC<SubscriptionsViewProps> = ({
@ -15,6 +16,7 @@ export const SubscriptionsView: React.FC<SubscriptionsViewProps> = ({
onOpenAuth, onOpenAuth,
onSwitchTab, onSwitchTab,
curriculumModules, curriculumModules,
onDownloadInvoice,
}) => { }) => {
const [currentPage, setCurrentPage] = useState(1); const [currentPage, setCurrentPage] = useState(1);
const [pageSize, setPageSize] = useState(6); const [pageSize, setPageSize] = useState(6);
@ -147,6 +149,28 @@ export const SubscriptionsView: React.FC<SubscriptionsViewProps> = ({
</span> </span>
)} )}
</div> </div>
{(sub.payment_id || sub.invoice_url) && onDownloadInvoice && (
<div className="mt-1 pt-3 border-t border-slate-100 flex items-center justify-between gap-2">
{sub.invoice_number ? (
<div className="text-[11px] font-mono text-slate-500 font-medium truncate">
<span className="text-slate-400 mr-1">Invoice:</span>
<span className="text-slate-800 font-bold">{sub.invoice_number}</span>
</div>
) : (
<span className="text-[11px] text-slate-400 font-medium">Tax Invoice</span>
)}
<button
type="button"
onClick={() => onDownloadInvoice(sub.payment_id || '', sub.invoice_url)}
className="inline-flex items-center gap-1.5 px-3 py-1.5 bg-indigo-50 hover:bg-indigo-100 border border-indigo-200 text-indigo-700 font-bold text-xs rounded-xl transition-colors duration-200 shadow-sm flex-shrink-0 cursor-pointer"
title="Download Tax Invoice PDF"
>
<Download className="h-3.5 w-3.5" />
<span>Download Invoice</span>
</button>
</div>
)}
</div> </div>
</div> </div>
); );

View File

@ -20,6 +20,8 @@ export interface UserSubscription {
expires_at?: string; expires_at?: string;
is_active: boolean; is_active: boolean;
payment_id?: string; payment_id?: string;
invoice_number?: string;
invoice_url?: string;
metadata?: Record<string, any>; metadata?: Record<string, any>;
} }