From c229f40da8236e8d9431a2db3d9c7bb62f8229cd Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Fri, 10 Apr 2026 12:05:50 -0400 Subject: [PATCH 1/2] feat: add Print Receipt button to completed transactions Add a 'Print Receipt' option for completed credit purchase transactions in the AI provider config dialog. Clicking it opens a print-friendly receipt with Soapbox Technology, LLC business details (soapbox.pub, contact@soapbox.pub) in a standard receipt layout showing payment ID, date, method, credits, processing fee, and total charged. Follows the existing window.open() print pattern used by gift card QR code printing. Adds i18n translations for all 6 supported languages. --- src/components/AIProviderConfigDialog.tsx | 233 ++++++++++++++++++++++ src/locales/en.json | 10 +- src/locales/ha.json | 10 +- src/locales/ig.json | 10 +- src/locales/pt.json | 10 +- src/locales/yo.json | 10 +- src/locales/zh.json | 10 +- 7 files changed, 287 insertions(+), 6 deletions(-) diff --git a/src/components/AIProviderConfigDialog.tsx b/src/components/AIProviderConfigDialog.tsx index 94a11e9c..f3776b87 100644 --- a/src/components/AIProviderConfigDialog.tsx +++ b/src/components/AIProviderConfigDialog.tsx @@ -895,6 +895,228 @@ export function AIProviderConfigDialog({ } }; + const handlePrintReceipt = (payment: Payment) => { + const receiptDate = new Date((payment.completed_at ?? payment.created_at) * 1000); + const formattedDate = new Intl.DateTimeFormat('en-US', { + year: 'numeric', + month: 'long', + day: 'numeric', + }).format(receiptDate); + const formattedTime = new Intl.DateTimeFormat('en-US', { + hour: '2-digit', + minute: '2-digit', + }).format(receiptDate); + + const paymentMethodDisplay = payment.method === 'stripe' ? t('creditCard') : t('lightning'); + const statusDisplay = payment.status.charAt(0).toUpperCase() + payment.status.slice(1); + + const printWindow = window.open('', '_blank'); + if (!printWindow) { + toast({ + title: t('printFailed'), + description: t('failedToOpenPrintWindow'), + variant: 'destructive', + }); + return; + } + + const printHTML = ` + + + + ${t('receipt')} - ${payment.id} + + + +
+
+
Soapbox Technology, LLC
+
+ soapbox.pub
+ contact@soapbox.pub +
+
+ +
${t('receipt')}
+ +
+
${t('receiptNumber')}
+
${payment.id}
+
${t('date')}
+
${formattedDate} ${formattedTime}
+
${t('status')}
+
${statusDisplay}
+
${t('paymentMethodLabel')}
+
${paymentMethodDisplay}
+ ${payment.description ? `
${t('description')}
${payment.description}
` : ''} +
+ +
+ +
+
+ ${t('credits')} + ${formatCurrency(payment.amount)} +
+ ${payment.fee > 0 ? ` +
+ ${t('processingFee')} + ${formatCurrency(payment.fee)} +
+ ` : ''} +
+ ${t('totalCharged')} + ${formatCurrency(payment.total)} +
+
+ + +
+ + + `; + + printWindow.document.write(printHTML); + printWindow.document.close(); + + printWindow.onload = () => { + setTimeout(() => { + printWindow.print(); + }, 250); + }; + }; + const handleDownloadCSV = () => { if (!giftcards || giftcards.length === 0) return; @@ -1307,6 +1529,17 @@ export function AIProviderConfigDialog({ )} )} + {payment.status === 'completed' && ( + + )} ))} diff --git a/src/locales/en.json b/src/locales/en.json index e33e1769..e9923e2e 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -573,5 +573,13 @@ "failedToDuplicateProject": "Failed to duplicate project", "newProjectName": "New Project Name", "duplicateProjectDescription": "Create a copy of this project with a new name", - "resume": "Resume" + "resume": "Resume", + "printReceipt": "Print Receipt", + "receipt": "Receipt", + "receiptNumber": "Receipt #", + "date": "Date", + "status": "Status", + "paymentMethodLabel": "Payment Method", + "totalCharged": "Total Charged", + "thankYouForPurchase": "Thank you for your purchase!" } diff --git a/src/locales/ha.json b/src/locales/ha.json index bd95306b..b5d34bb9 100644 --- a/src/locales/ha.json +++ b/src/locales/ha.json @@ -487,5 +487,13 @@ "failedToDuplicateProject": "An kasa kwafin aikin", "newProjectName": "Sunan Sabon Aikin", "duplicateProjectDescription": "Ƙirƙiri kwafin wannan aikin da sabon suna", - "resume": "Ci gaba" + "resume": "Ci gaba", + "printReceipt": "Buga Rasidi", + "receipt": "Rasidi", + "receiptNumber": "Rasidi #", + "date": "Kwanan wata", + "status": "Matsayi", + "paymentMethodLabel": "Hanyar Biyan Kuɗi", + "totalCharged": "Jimlar da aka Caji", + "thankYouForPurchase": "Mun gode da sayan ku!" } diff --git a/src/locales/ig.json b/src/locales/ig.json index 58b24e41..66848ace 100644 --- a/src/locales/ig.json +++ b/src/locales/ig.json @@ -484,5 +484,13 @@ "failedToDuplicateProject": "Ọ dara ada imepụta ọrụ", "newProjectName": "Aha Ọrụ Ọhụrụ", "duplicateProjectDescription": "Mepụta oyiri nke ọrụ a na aha ọhụrụ", - "resume": "Gaa n'ihu" + "resume": "Gaa n'ihu", + "printReceipt": "Bipụta Risịịtị", + "receipt": "Risịịtị", + "receiptNumber": "Risịịtị #", + "date": "Ụbọchị", + "status": "Ọnọdụ", + "paymentMethodLabel": "Ụzọ Ịkwụ Ụgwọ", + "totalCharged": "Nchịkọta Ego a Gbara", + "thankYouForPurchase": "Daalụ maka ịzụta gị!" } diff --git a/src/locales/pt.json b/src/locales/pt.json index b3e97f27..b207028a 100644 --- a/src/locales/pt.json +++ b/src/locales/pt.json @@ -496,5 +496,13 @@ "failedToDuplicateProject": "Falha ao duplicar projeto", "newProjectName": "Nome do Novo Projeto", "duplicateProjectDescription": "Criar uma cópia deste projeto com um novo nome", - "resume": "Retomar" + "resume": "Retomar", + "printReceipt": "Imprimir Recibo", + "receipt": "Recibo", + "receiptNumber": "Recibo Nº", + "date": "Data", + "status": "Status", + "paymentMethodLabel": "Método de Pagamento", + "totalCharged": "Total Cobrado", + "thankYouForPurchase": "Obrigado pela sua compra!" } diff --git a/src/locales/yo.json b/src/locales/yo.json index 2a83cf7a..f18a585e 100644 --- a/src/locales/yo.json +++ b/src/locales/yo.json @@ -484,5 +484,13 @@ "failedToDuplicateProject": "O kuna lati ṣe ẹda iṣẹ akanṣe", "newProjectName": "Orukọ Iṣẹ Akanṣe Tuntun", "duplicateProjectDescription": "Ṣẹda ẹda ti iṣẹ akanṣe yii pẹlu orukọ tuntun", - "resume": "Tẹsiwaju" + "resume": "Tẹsiwaju", + "printReceipt": "Tẹ Ìwé Ẹ̀rí", + "receipt": "Ìwé Ẹ̀rí", + "receiptNumber": "Ìwé Ẹ̀rí #", + "date": "Ọjọ́", + "status": "Ipò", + "paymentMethodLabel": "Ọ̀nà Ìsanwó", + "totalCharged": "Àpapọ̀ tí a gba", + "thankYouForPurchase": "A dúpẹ́ fún rírà rẹ!" } diff --git a/src/locales/zh.json b/src/locales/zh.json index 45af437d..a5c936da 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -496,5 +496,13 @@ "failedToDuplicateProject": "复制项目失败", "newProjectName": "新项目名称", "duplicateProjectDescription": "使用新名称创建此项目的副本", - "resume": "继续" + "resume": "继续", + "printReceipt": "打印收据", + "receipt": "收据", + "receiptNumber": "收据编号", + "date": "日期", + "status": "状态", + "paymentMethodLabel": "支付方式", + "totalCharged": "总收费", + "thankYouForPurchase": "感谢您的购买!" } From 47f9edacfd450c8ca1e5800237a2810b5011682c Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Sun, 12 Apr 2026 12:58:57 -0400 Subject: [PATCH 2/2] fix: escape HTML in receipt print template to prevent injection --- src/components/AIProviderConfigDialog.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/AIProviderConfigDialog.tsx b/src/components/AIProviderConfigDialog.tsx index f3776b87..e99eff56 100644 --- a/src/components/AIProviderConfigDialog.tsx +++ b/src/components/AIProviderConfigDialog.tsx @@ -895,6 +895,9 @@ export function AIProviderConfigDialog({ } }; + const escapeHtml = (str: string): string => + str.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"').replace(/'/g, '''); + const handlePrintReceipt = (payment: Payment) => { const receiptDate = new Date((payment.completed_at ?? payment.created_at) * 1000); const formattedDate = new Intl.DateTimeFormat('en-US', { @@ -924,7 +927,7 @@ export function AIProviderConfigDialog({ - ${t('receipt')} - ${payment.id} + ${t('receipt')} - ${escapeHtml(payment.id)}