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,13 +3,13 @@ import { authenticate } from "../shopify.server";
|
||||
import db from "../db.server";
|
||||
import {
|
||||
generateAndEmailInvoice,
|
||||
isWireTransferOrder,
|
||||
isManualPaymentOrder,
|
||||
} from "../services/invoice/automations.server";
|
||||
|
||||
/**
|
||||
* orders/fulfilled — Automation 2: when an order is fulfilled and is NOT a
|
||||
* wire-transfer order (e.g. paid by card), automatically email the invoice
|
||||
* to the customer. Wire-transfer orders are intentionally skipped here
|
||||
* wire-transfer (manual-payment-gateway) order, automatically email the
|
||||
* invoice to the customer. Manual-gateway orders are intentionally skipped
|
||||
* because Automation 1 already emailed them at order-create time.
|
||||
*/
|
||||
export const action = async ({ request }: ActionFunctionArgs) => {
|
||||
@@ -27,11 +27,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)) {
|
||||
// Wire-transfer order — handled by Automation 1, skip here.
|
||||
const orderGid = `gid://shopify/Order/${String(orderId).replace(/^.*\//, "")}`;
|
||||
if (await isManualPaymentOrder(admin, orderGid)) {
|
||||
// Manual / wire-transfer order — handled by Automation 1, skip here.
|
||||
return new Response();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user