Have a Shopify app - with 3 extensions (shopify functions).
When testing on dev store the output is always empty, but if I use the same input (grabbed from partner extension logs) and test it locally via the function runner (https://shopify.dev/docs/apps/build/functions/test-debug-functions#test-a-function-using-the-function-runner) it returns the expected output.
Just trying to hide a payment method for customer’s that have a specific metafield value:
Here is the Input query:
query RunInput {
cart {
buyerIdentity {
customer {
metafield(key: "payment_terms", namespace: "company") {
value
}
}
}
}
paymentMethods {
id
name
}
}
example response would be:
{
"cart": {
"buyerIdentity": {
"customer": {
"metafield": {
"value": "Terms 30"
}
}
}
},
"paymentMethods": [
{
"id": "gid://shopify/PaymentCustomizationPaymentMethod/0",
"name": "Deferred"
},
{
"id": "gid://shopify/PaymentCustomizationPaymentMethod/1",
"name": "(for testing) Bogus Gateway"
},
{
"id": "gid://shopify/PaymentCustomizationPaymentMethod/2",
"name": "Invoice"
}
]
}
and the function is
// -check
/**
* @typedef {import("../generated/api").RunInput} RunInput
* @typedef {import("../generated/api").FunctionRunResult} FunctionRunResult
* @typedef {import("../generated/api").Operation} Operation
*/
/**
* {FunctionRunResult}
*/
const NO_CHANGES = {
operations: [],
};
/**
* @param {RunInput} input
* @returns {FunctionRunResult}
*/
export function run(input) {
const payment_terms = input?.cart?.buyerIdentity?.customer?.metafield?.value;
if (payment_terms === undefined) {
console.error('Metafield is missing.');
return NO_CHANGES;
}
let hidePaymentMethod = null;
if (payment_terms.toUpperCase() === 'PREPAID') {
// prepaid - hide invoice
hidePaymentMethod = input.paymentMethods.find((method) =>
method.name.includes('Invoice')
);
} else {
// terms - hide credit card
hidePaymentMethod = input.paymentMethods.find((method) =>
method.name.includes('(for testing) Bogus Gateway')
);
}
if (!hidePaymentMethod) {
return NO_CHANGES;
}
return {
operations: [
{
hide: {
paymentMethodId: hidePaymentMethod.id,
},
},
],
};
}
expected output is:
{
"operations": [
{
"hide": {
"paymentMethodId": "gid://shopify/PaymentCustomizationPaymentMethod/1"
}
}
]
}
which is what the function runner (local testing) returns, but when looking in partner dashboard logs :
{
"operations": []
}
i also can’t seem to output to stderr either on development store via console.error, but this is working locally.
Thanks,
Kele