antiwork/gumroad · error · Purchase::PurchaseInvalid
You entered a ZIP Code that doesn't exist within your countr
Error message
You entered a ZIP Code that doesn't exist within your country.
What it means
For US checkouts of paid products, validate_zip_code raises when UsZipCodes.identify_state_code cannot resolve the submitted ZIP to a state, because sales tax cannot be computed from it. The invalid ZIP and buyer email are logged (Rails.logger.info) immediately before the raise.
Source
Thrown at app/services/purchase/create_service.rb:356
gift
else
error_message = product.user.gifting_disabled? ? "The creator has disabled gifting for their products." : "Gifting is not yet enabled for pre-orders."
raise Purchase::PurchaseInvalid, error_message
end
end
def validate_perceived_price
if purchase_params[:perceived_price_cents] && !Purchase::MAX_PRICE_RANGE.cover?(purchase_params[:perceived_price_cents])
raise Purchase::PurchaseInvalid, "Purchase price is invalid. Please check the price."
end
end
def validate_zip_code
country_code_for_validation = purchase_params[:country].presence || purchase_params[:sales_tax_country_code_election]
if purchase_params[:perceived_price_cents].to_i > 0 && country_code_for_validation == Compliance::Countries::USA.alpha2 && UsZipCodes.identify_state_code(purchase_params[:zip_code]).nil?
Rails.logger.info("Zip code #{purchase_params[:zip_code]} is invalid, customer email #{purchase_params[:email]}")
raise Purchase::PurchaseInvalid, "You entered a ZIP Code that doesn't exist within your country."
end
end
def perceived_price_matches_accepted_offer?(offer_code)
return false unless offer_code
original_offer_code = purchase.offer_code
purchase.offer_code = offer_code
purchase.minimum_paid_price_cents + params[:tip_cents].to_i == purchase_params[:perceived_price_cents].to_i
ensure
purchase.offer_code = original_offer_code if purchase
end
def validate_perceived_free_trial_params
return if is_gift?
free_trial_params = params[:perceived_free_trial_duration]
if product.free_trial_enabled?View on GitHub (pinned to afeacbd394)
Solutions
- Enter a valid 5-digit US ZIP (leading zeros matter; ZIP+4 also accepted).
- Verify the country selection matches the postal code format - switch country for non-US addresses.
- Integrators: validate the format ^\d{5}(-\d{4})?$ for US checkouts before submit.
Example fix
# before: country US with a non-US postcode purchase_params[:country] = 'US' purchase_params[:zip_code] = 'M5V 2T6' # after: keep country and postcode consistent purchase_params[:country] = 'CA' # or fix zip_code to e.g. '94107'
Defensive patterns
Strategy: validation
Validate before calling
country = purchase_params[:country].presence || purchase_params[:sales_tax_country_code_election]
if purchase_params[:perceived_price_cents].to_i > 0 && country == 'US'
raise ArgumentError, 'invalid US ZIP' unless purchase_params[:zip_code].to_s.match?(/\A\d{5}(-\d{4})?\z/)
end Type guard
def valid_us_zip?(zip_code)
zip_code.to_s.match?(/\A\d{5}(-\d{4})?\z/) && UsZipCodes.identify_state_code(zip_code).present?
end Try / catch
begin
Purchase::CreateService.new(product:, params:, buyer:).perform
rescue Purchase::PurchaseInvalid => e
# prompt the buyer to correct the ZIP or the country selection; no automated fix
render_checkout_error(e.message) if e.message.include?("ZIP Code that doesn't exist")
end Prevention
- Validate US ZIPs as 5 digits (optionally ZIP+4) before submit.
- Preserve leading zeros - format ZIP inputs as strings, not numbers.
- Cross-check that the selected country matches the postal code format the buyer typed.
When it happens
Trigger: purchase_params[:perceived_price_cents].to_i > 0, country (or sales_tax_country_code_election fallback) == Compliance::Countries::USA.alpha2 ('US'), and UsZipCodes.identify_state_code(purchase_params[:zip_code]) returns nil - malformed, foreign, or nonexistent ZIP.
Common situations: Buyer selects United States but types a non-US postal code (Canadian/UK format); typos; dropped leading zeros (e.g. '2101' instead of '02101'); test checkouts with placeholder strings like '12345' variants that do not map to a state.
Related errors
- The cart does not have any products to which the upsell appl
- Tip is not allowed for this product
- Tip is too large for this purchase
- You can't gift your own product. To give it away for free, c
- You cannot gift a product to yourself. Please try gifting to
AI-assisted analysis of antiwork/gumroad@afeacbd394 (2026-08-21).
Data as JSON: /api/errors/3875d7f2bda32b8f.
Report an issue: GitHub.