refactor(automations): detect manual payment via OrderTransaction.manualPaymentGateway
- Drop wireTransferGatewayNames from ShopSettings (new migration). - Replace string-matching with a GraphQL query against Order.transactions[].manualPaymentGateway, the first-class flag Shopify exposes for any merchant-defined manual payment method. - Both webhook handlers now fetch the order on the fly to classify it, removing the configurable gateway-names field from settings.
This commit is contained in:
@@ -3,14 +3,14 @@ import { authenticate } from "../shopify.server";
|
||||
import db from "../db.server";
|
||||
import {
|
||||
generateAndEmailInvoice,
|
||||
isWireTransferOrder,
|
||||
isManualPaymentOrder,
|
||||
} from "../services/invoice/automations.server";
|
||||
|
||||
/**
|
||||
* orders/create — Automation 1: when a wire-transfer order is placed,
|
||||
* immediately generate and email the invoice (which includes the bank
|
||||
* details + GiroCode) so the customer can pay. Other orders are ignored
|
||||
* here; they're handled by orders/fulfilled (Automation 2).
|
||||
* orders/create — Automation 1: when a wire-transfer (manual-payment-gateway)
|
||||
* order is placed, immediately generate and email the invoice (which includes
|
||||
* the bank details + GiroCode) so the customer can pay. Other orders are
|
||||
* ignored here; they're handled by orders/fulfilled (Automation 2).
|
||||
*/
|
||||
export const action = async ({ request }: ActionFunctionArgs) => {
|
||||
const { shop, topic, payload, session, admin } = await authenticate.webhook(request);
|
||||
@@ -24,12 +24,9 @@ export const action = async ({ request }: ActionFunctionArgs) => {
|
||||
const orderId = payload?.id;
|
||||
if (orderId == null) return new Response();
|
||||
|
||||
const gateways: string[] = Array.isArray(payload?.payment_gateway_names)
|
||||
? payload.payment_gateway_names
|
||||
: [];
|
||||
if (!isWireTransferOrder(gateways, settings.wireTransferGatewayNames)) {
|
||||
return new Response();
|
||||
}
|
||||
const orderGid = `gid://shopify/Order/${String(orderId).replace(/^.*\//, "")}`;
|
||||
const isManual = await isManualPaymentOrder(admin, orderGid);
|
||||
if (!isManual) return new Response();
|
||||
|
||||
try {
|
||||
const result = await generateAndEmailInvoice({
|
||||
|
||||
Reference in New Issue
Block a user