cleanup(thank-you): remove debug, render nothing when no payment data
This commit is contained in:
@@ -78,7 +78,6 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
|
|||||||
Response.json({
|
Response.json({
|
||||||
showPaymentInstructions: false,
|
showPaymentInstructions: false,
|
||||||
reason: "not-manual-payment",
|
reason: "not-manual-payment",
|
||||||
debug: { shop, orderGid, hasOrder: !!orderInfo, txCount: orderInfo?.txCount ?? 0, manualFlags: orderInfo?.manualFlags ?? [] },
|
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ export default async () => {
|
|||||||
function Extension() {
|
function Extension() {
|
||||||
const shopify = (globalThis as any).shopify;
|
const shopify = (globalThis as any).shopify;
|
||||||
const [data, setData] = useState<PaymentInstructions | null>(null);
|
const [data, setData] = useState<PaymentInstructions | null>(null);
|
||||||
const [debug, setDebug] = useState<string>("init");
|
|
||||||
const [done, setDone] = useState(false);
|
const [done, setDone] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -50,25 +49,21 @@ function Extension() {
|
|||||||
async function load() {
|
async function load() {
|
||||||
try {
|
try {
|
||||||
const orderId: string | undefined = shopify?.orderConfirmation?.value?.order?.id;
|
const orderId: string | undefined = shopify?.orderConfirmation?.value?.order?.id;
|
||||||
setDebug(`orderId=${orderId ?? "(none)"}`);
|
|
||||||
if (!orderId) {
|
if (!orderId) {
|
||||||
setDone(true);
|
setDone(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const token: string = await shopify.sessionToken.get();
|
const token: string = await shopify.sessionToken.get();
|
||||||
const appUrl = resolveAppUrl(shopify);
|
const appUrl = resolveAppUrl(shopify);
|
||||||
setDebug(`fetch ${appUrl} orderId=${orderId} tokenLen=${token?.length ?? 0}`);
|
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
`${appUrl}/api/public/payment-info?orderId=${encodeURIComponent(orderId)}`,
|
`${appUrl}/api/public/payment-info?orderId=${encodeURIComponent(orderId)}`,
|
||||||
{ headers: { Authorization: `Bearer ${token}` } },
|
{ headers: { Authorization: `Bearer ${token}` } },
|
||||||
);
|
);
|
||||||
const text = await res.text();
|
|
||||||
setDebug(`status=${res.status} body=${text.slice(0, 300)}`);
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
setDone(true);
|
setDone(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const json = JSON.parse(text) as {
|
const json = (await res.json()) as {
|
||||||
showPaymentInstructions: boolean;
|
showPaymentInstructions: boolean;
|
||||||
payload?: PaymentInstructions;
|
payload?: PaymentInstructions;
|
||||||
};
|
};
|
||||||
@@ -76,8 +71,8 @@ function Extension() {
|
|||||||
if (json.showPaymentInstructions && json.payload) {
|
if (json.showPaymentInstructions && json.payload) {
|
||||||
setData(json.payload);
|
setData(json.payload);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch {
|
||||||
setDebug(`error: ${(err as Error)?.message ?? String(err)}`);
|
// swallow; render nothing
|
||||||
} finally {
|
} finally {
|
||||||
if (!cancelled) setDone(true);
|
if (!cancelled) setDone(true);
|
||||||
}
|
}
|
||||||
@@ -88,22 +83,14 @@ function Extension() {
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
if (!done) {
|
if (!done || !data) {
|
||||||
return <s-skeleton-paragraph />;
|
return null;
|
||||||
}
|
|
||||||
if (!data) {
|
|
||||||
return (
|
|
||||||
<s-section heading="Invoice payment debug">
|
|
||||||
<s-paragraph>{debug}</s-paragraph>
|
|
||||||
</s-section>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<s-section heading={data.heading}>
|
<s-section heading={data.heading}>
|
||||||
<s-paragraph>{data.instructions}</s-paragraph>
|
<s-paragraph>{data.instructions}</s-paragraph>
|
||||||
<s-stack direction="inline" gap="base" align-items="start">
|
<s-grid gridTemplateColumns="200px 1fr" gap="base" alignItems="start">
|
||||||
<s-image src="https://cdn.shopify.com/shopifycloud/web/assets/v1/vite/client/en/assets/shopify-logo-monotone-white-CzwKJF7G.svg" alt="test" inlineSize="fill" aspectRatio="1" />
|
|
||||||
<s-image src={data.giroCodeUrl} alt="GiroCode" inlineSize="fill" aspectRatio="1" />
|
<s-image src={data.giroCodeUrl} alt="GiroCode" inlineSize="fill" aspectRatio="1" />
|
||||||
<s-stack direction="block" gap="small-200">
|
<s-stack direction="block" gap="small-200">
|
||||||
<s-text>{data.labels.recipient}: {data.recipient}</s-text>
|
<s-text>{data.labels.recipient}: {data.recipient}</s-text>
|
||||||
@@ -117,7 +104,7 @@ function Extension() {
|
|||||||
<s-text>{data.labels.amount}: {data.amountFormatted}</s-text>
|
<s-text>{data.labels.amount}: {data.amountFormatted}</s-text>
|
||||||
<s-text>{data.labels.reference}: {data.reference}</s-text>
|
<s-text>{data.labels.reference}: {data.reference}</s-text>
|
||||||
</s-stack>
|
</s-stack>
|
||||||
</s-stack>
|
</s-grid>
|
||||||
</s-section>
|
</s-section>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user