I’ve seen this issue/error posted about multiple times, but can’t find any on this forum that actually have a solution. I’m using the Mobile Buy SDK for iOS. I’ve successfully implemented “Buy with Apple Pay” and web checkout buttons in my app for a particular product. The product has only 1 variant.
If I make a purchase in Australia, UK, or the EU, it works fine. If I try to create the checkout using a VPN connected in the USA (i.e. pretending i’m a USA customer), I get the following error from the API: User error: Variant is invalid.
Because all other regions work fine, and even the USA is able to query the product and variant, I’m certain my process for querying products and variants is not the issue. Things I have checked:
- The product is active for the sales channel
- The product is active for the USA market
- The USA market is active in settings > markets
- The product has stock available on hand
- Tried creating a new product, issue persists with new product also
This is how I query for product and variant (and it works successfully)
let productId = "123456"
let query = Storefront.buildQuery { $0
.node(id: productId!) { $0
.onProduct() { $0
.id()
.title()
.tags()
.description()
.availableForSale()
.totalInventory()
.images(first: 1) { $0
.edges { $0
.node { $0
.url()
}
}
}
.priceRange() { $0
.maxVariantPrice() { $0
.amount()
.currencyCode()
}
}
.variants(first: 1) { $0
.edges { $0
.node { $0
.id()
.title()
.availableForSale()
.currentlyNotInStock()
.unitPrice() { $0
.currencyCode()
.amount()
}
}
}
}
}
}
}
let task = client!.queryGraphWith(query) { [self] response, error in
if let response = response {
product = response.node as? Storefront.Product;
let variants = product!.variants.edges.map({$0.node});
variant = variants.first;
}
};
task.resume();
This is my checkout create input (fails for USA only, works for all other regions)
let input = Storefront.CheckoutCreateInput.create(
lineItems: .value([
Storefront.CheckoutLineItemInput.create(quantity: 1, variantId: variant!.id),
]),
customAttributes: .value([
Storefront.AttributeInput(key: "user_id", value: currentUserId() ?? ""),
]),
allowPartialAddresses: .value(true),
presentmentCurrencyCode: .value(currencyCode)
)
let mutation = Storefront.buildMutation { $0
.checkoutCreate(input: input) { $0
...
.checkoutUserErrors { $0
.field()
.message()
}
}
}
let task = client!.mutateGraphWith(mutation) { result, error in
guard error == nil else {
callback(nil);
return
}
guard let userErrors = result?.checkoutCreate?.checkoutUserErrors else {
callback(nil);
return
}
if (userErrors.count > 0) {
//THIS IS WHERE "invalid variation id" error is captured
callback(nil);
return;
}
self.checkout = result?.checkoutCreate?.checkout
callback(self.checkout);
}
task.resume()
}