We have a store that requires customers to be logged in and approved in order to make purchases. We are experiencing an issue with the express Shop Pay checkout option. If a customer pays with Shop Pay that is connected to a different email than they are logged in as, the order will be attributed to the email on the Shop Pay account, thus creating a new customer account in Shopify. This is an issue because orders and rewards will be attributed to the wrong account.
Unfortunately, disabling Shop Pay in the store is not an option. In an attempt to fix this, I tried implementing a Checkout Validation function that will check if the customer email on the cart has the specific tags that determines if a customer is verified or not.
The issue is that the checkout function always validates the logged in customer email, rather than the email Shop Pay is actually applying.
For example, if I’m logged into my approved account as approved@email.com (which is the account we actually want the order to be attached to) and my Shop Pay account express checkout puts in shoppay@email.com (the wrong email), I want the Checkout Validation function to read the wrong email and prevent the order. But it is reading the approved email every time.
Is there a way for a checkout validation function to read the email Shop Pay is ACTUALLY putting in? Or is there another function that will allow us to prevent orders being attributed to the wrong customer email?
query CartValidationsGenerateRunInput {
buyerJourney {
step
}
cart {
buyerIdentity {
email
customer {
hasAnyTag(tags: ["approved"])
}
}
}
}
import { BuyerJourneyStep } from "../generated/api";
/**
* @typedef {import("../generated/api").CartValidationsGenerateRunInput} CartValidationsGenerateRunInput
* @typedef {import("../generated/api").CartValidationsGenerateRunResult} CartValidationsGenerateRunResult
*/
/**
* @param {CartValidationsGenerateRunInput} input
* @returns {CartValidationsGenerateRunResult}
*/
export function cartValidationsGenerateRun(input) {
const step = input.buyerJourney.step;
const customer = input.cart?.buyerIdentity?.customer;
const email = input.cart?.buyerIdentity?.email;
const isApproved = customer?.hasAnyTag;
if (step === BuyerJourneyStep.CartInteraction || !email) {
return { operations: [] };
}
if (!isApproved) {
return {
operations: [
{
validationAdd: {
errors: [
{
message:
`Your email address (${email}) is not approved to place orders. If you're using Shop Pay, ensure it's connected to your approved account email, or select a different payment method.`,
target: "$.cart.buyerIdentity.email",
},
],
},
},
],
};
}
return { operations: [] };
}