Gift packages: buy a main package for someone, with a printable gift card
- /ajandek: the package, whom it is for and from whom, the recipient's address typed twice (or "I hand it over"), a message; paid on Stripe like any package, the invoice is the buyer's - On payment the gift gets its own code (not a promo code: it cannot be withdrawn, and it adds the whole package); redeemed on /bevaltas - The recipient's e-mail carries the message and the code, with the gift card attached as a PDF; the buyer's confirmation says it was a gift - /ajandekaim: codes, state, the card to download, sending it by e-mail (again, or to another address) up to three times - crates/gift-card draws the A4 card (example chart, questions avatar, QR code) as SVG and makes a PDF with krilla, fonts compiled in; the backend draws downloads on a blocking thread, the worker the e-mails - Telegram notices say "(ajándék)"; unpaid gifts go after a week Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -22,6 +22,7 @@ export function PackageCards({
|
||||
canPay,
|
||||
compact = false,
|
||||
row = false,
|
||||
giftLinks = false,
|
||||
onBought,
|
||||
}: {
|
||||
packages: Package[];
|
||||
@@ -32,6 +33,8 @@ export function PackageCards({
|
||||
compact?: boolean;
|
||||
/** One line per package (name, price, button), for tight places like the question panel. */
|
||||
row?: boolean;
|
||||
/** A "give it as a gift" link under the buy button of the main packages. */
|
||||
giftLinks?: boolean;
|
||||
/** After a stand-in purchase (default: reload the page data). */
|
||||
onBought?: (p: Package) => Promise<void> | void;
|
||||
}) {
|
||||
@@ -153,6 +156,11 @@ export function PackageCards({
|
||||
</p>
|
||||
)}
|
||||
{buyButton(p)}
|
||||
{giftLinks && canPay && p.tier === "main" && (
|
||||
<Link href={`/ajandek?csomag=${p.id}`} className="pkg-gift">
|
||||
Ajándékba adom →
|
||||
</Link>
|
||||
)}
|
||||
</article>
|
||||
);
|
||||
})}
|
||||
|
||||
@@ -41,12 +41,19 @@ export function PaymentReturn() {
|
||||
(async () => {
|
||||
for (let i = 0; i < POLLS && !stopped; i++) {
|
||||
try {
|
||||
const r = await api<{ status: string; name: string | null }>(
|
||||
`/payments/checkout/${encodeURIComponent(value)}`,
|
||||
);
|
||||
const r = await api<{
|
||||
status: string;
|
||||
name: string | null;
|
||||
gift: { id: string; recipient_name: string | null; recipient_email: string | null } | null;
|
||||
}>(`/payments/checkout/${encodeURIComponent(value)}`);
|
||||
if (stopped) return;
|
||||
if (r.status === "paid") {
|
||||
setNotice({ kind: "ok", text: `Köszönjük! Jóváírtuk: ${r.name ?? "a csomagod"}.` });
|
||||
const text = !r.gift
|
||||
? `Köszönjük! Jóváírtuk: ${r.name ?? "a csomagod"}.`
|
||||
: r.gift.recipient_email
|
||||
? `Köszönjük! Az ajándékot elküldtük ide: ${r.gift.recipient_email}. Az utalványt lent le is töltheted.`
|
||||
: "Köszönjük! Az ajándékutalvány elkészült: lent letöltheted, és átadhatod.";
|
||||
setNotice({ kind: "ok", text });
|
||||
clean();
|
||||
router.refresh();
|
||||
return;
|
||||
|
||||
@@ -18,18 +18,23 @@ const UNITS: Record<string, string> = {
|
||||
forecast: "éves előrejelzés",
|
||||
person: "személyhely",
|
||||
question: "kérdés",
|
||||
tarot: "kártyajóslás",
|
||||
};
|
||||
|
||||
/** "+2 képletelemzés, +3 kérdés" */
|
||||
/** "+2 képletelemzés, +3 kérdés", in the order of UNITS. */
|
||||
function addedText(added: Record<string, number>): string {
|
||||
const order = Object.keys(UNITS);
|
||||
const rank = (unit: string) => (order.includes(unit) ? order.indexOf(unit) : order.length);
|
||||
return Object.entries(added)
|
||||
.sort(([a], [b]) => rank(a) - rank(b))
|
||||
.map(([unit, n]) => `+${n} ${UNITS[unit] ?? unit}`)
|
||||
.join(", ");
|
||||
}
|
||||
|
||||
/**
|
||||
* Redeeming a promo code. It fills the units up to the package's amounts
|
||||
* (used ones come back, more than that stays).
|
||||
* (used ones come back, more than that stays); a gift code adds the whole
|
||||
* package.
|
||||
*/
|
||||
export function RedeemCode({ initial = "", compact = false }: { initial?: string; compact?: boolean }) {
|
||||
const router = useRouter();
|
||||
@@ -37,17 +42,21 @@ export function RedeemCode({ initial = "", compact = false }: { initial?: string
|
||||
const [code, setCode] = useState(format(initial));
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [got, setGot] = useState<{ name: string; added: string } | null>(null);
|
||||
const [got, setGot] = useState<{ name: string; added: string; gift: { from_name: string | null } | null } | null>(
|
||||
null,
|
||||
);
|
||||
|
||||
async function redeem(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
const r = await api<{ package: { name: string }; added: Record<string, number> }>("/promo-codes/redeem", {
|
||||
body: { code },
|
||||
});
|
||||
setGot({ name: r.package.name, added: addedText(r.added ?? {}) });
|
||||
const r = await api<{
|
||||
package: { name: string };
|
||||
added: Record<string, number>;
|
||||
gift?: { from_name: string | null };
|
||||
}>("/promo-codes/redeem", { body: { code } });
|
||||
setGot({ name: r.package.name, added: addedText(r.added ?? {}), gift: r.gift ?? null });
|
||||
setCode("");
|
||||
router.refresh();
|
||||
} catch (err) {
|
||||
@@ -85,12 +94,19 @@ export function RedeemCode({ initial = "", compact = false }: { initial?: string
|
||||
</div>
|
||||
<div id={`${id}-msg`} aria-live="polite">
|
||||
{error && <p className="msg msg-error">{error}</p>}
|
||||
{got && (
|
||||
<p className="msg msg-ok">
|
||||
Beváltva: <strong>{got.name}</strong>. Feltöltöttük az egyenlegedet: {got.added}.{" "}
|
||||
<Link href="/keplet">Tovább a képletedhez</Link>
|
||||
</p>
|
||||
)}
|
||||
{got &&
|
||||
(got.gift ? (
|
||||
<p className="msg msg-ok">
|
||||
Beváltva: <strong>{got.name}</strong>
|
||||
{got.gift.from_name ? `, ${got.gift.from_name} ajándéka` : " ajándék"}. Hozzáadtuk az egyenlegedhez:{" "}
|
||||
{got.added}. <Link href="/keplet">Tovább a képletedhez</Link>
|
||||
</p>
|
||||
) : (
|
||||
<p className="msg msg-ok">
|
||||
Beváltva: <strong>{got.name}</strong>. Feltöltöttük az egyenlegedet: {got.added}.{" "}
|
||||
<Link href="/keplet">Tovább a képletedhez</Link>
|
||||
</p>
|
||||
))}
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
|
||||
@@ -8,7 +8,7 @@ import { LogoutButton } from "./LogoutButton";
|
||||
|
||||
/**
|
||||
* The account menu under the user's name (top right): profile, invoices,
|
||||
* redeeming a code, logging out. Closes on a click outside, Escape, or
|
||||
* redeeming a code, giving a gift, logging out. Closes on a click outside, Escape, or
|
||||
* moving to another page.
|
||||
*/
|
||||
export function UserMenu({ name, invoices }: { name: string; invoices: boolean }) {
|
||||
@@ -39,6 +39,7 @@ export function UserMenu({ name, invoices }: { name: string; invoices: boolean }
|
||||
{ href: "/profil", label: "Profil" },
|
||||
...(invoices ? [{ href: "/szamlak", label: "Számláim" }] : []),
|
||||
{ href: "/bevaltas", label: "Kód beváltása" },
|
||||
{ href: "/ajandek", label: "Ajándékozás" },
|
||||
];
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user