payment info updates

This commit is contained in:
Gerhard Scheikl
2026-05-09 21:05:09 +02:00
parent 35dea965f6
commit 8bc86ef985
2 changed files with 32 additions and 7 deletions
@@ -42,6 +42,7 @@ export default async () => {
function Extension() {
const shopify = (globalThis as any).shopify;
const [data, setData] = useState<PaymentInstructions | null>(null);
const [debug, setDebug] = useState<string>("init");
const [done, setDone] = useState(false);
useEffect(() => {
@@ -49,21 +50,25 @@ function Extension() {
async function load() {
try {
const orderId: string | undefined = shopify?.orderConfirmation?.value?.order?.id;
setDebug(`orderId=${orderId ?? "(none)"}`);
if (!orderId) {
setDone(true);
return;
}
const token: string = await shopify.sessionToken.get();
const appUrl = resolveAppUrl(shopify);
setDebug(`fetch ${appUrl} orderId=${orderId} tokenLen=${token?.length ?? 0}`);
const res = await fetch(
`${appUrl}/api/public/payment-info?orderId=${encodeURIComponent(orderId)}`,
{ headers: { Authorization: `Bearer ${token}` } },
);
const text = await res.text();
setDebug(`status=${res.status} body=${text.slice(0, 300)}`);
if (!res.ok) {
setDone(true);
return;
}
const json = (await res.json()) as {
const json = JSON.parse(text) as {
showPaymentInstructions: boolean;
payload?: PaymentInstructions;
};
@@ -71,8 +76,8 @@ function Extension() {
if (json.showPaymentInstructions && json.payload) {
setData(json.payload);
}
} catch {
// ignore — render nothing on error
} catch (err) {
setDebug(`error: ${(err as Error)?.message ?? String(err)}`);
} finally {
if (!cancelled) setDone(true);
}
@@ -87,7 +92,11 @@ function Extension() {
return <s-skeleton-paragraph />;
}
if (!data) {
return null;
return (
<s-section heading="Invoice payment debug">
<s-paragraph>{debug}</s-paragraph>
</s-section>
);
}
return (