{"record":{"id":"3875d7f2bda32b8f","repo":"antiwork/gumroad","slug":"you-entered-a-zip-code-that-doesn-t-exist-within-y","errorCode":null,"errorMessage":"You entered a ZIP Code that doesn't exist within your country.","messagePattern":"You entered a ZIP Code that doesn't exist within your country\\.","errorType":"exception","errorClass":"Purchase::PurchaseInvalid","httpStatus":null,"severity":"error","filePath":"app/services/purchase/create_service.rb","lineNumber":356,"sourceCode":"        gift\n      else\n        error_message = product.user.gifting_disabled? ? \"The creator has disabled gifting for their products.\" : \"Gifting is not yet enabled for pre-orders.\"\n        raise Purchase::PurchaseInvalid, error_message\n      end\n    end\n\n    def validate_perceived_price\n      if purchase_params[:perceived_price_cents] && !Purchase::MAX_PRICE_RANGE.cover?(purchase_params[:perceived_price_cents])\n        raise Purchase::PurchaseInvalid, \"Purchase price is invalid. Please check the price.\"\n      end\n    end\n\n    def validate_zip_code\n      country_code_for_validation = purchase_params[:country].presence || purchase_params[:sales_tax_country_code_election]\n\n      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?\n        Rails.logger.info(\"Zip code #{purchase_params[:zip_code]} is invalid, customer email #{purchase_params[:email]}\")\n        raise Purchase::PurchaseInvalid, \"You entered a ZIP Code that doesn't exist within your country.\"\n      end\n    end\n\n    def perceived_price_matches_accepted_offer?(offer_code)\n      return false unless offer_code\n\n      original_offer_code = purchase.offer_code\n      purchase.offer_code = offer_code\n      purchase.minimum_paid_price_cents + params[:tip_cents].to_i == purchase_params[:perceived_price_cents].to_i\n    ensure\n      purchase.offer_code = original_offer_code if purchase\n    end\n\n    def validate_perceived_free_trial_params\n      return if is_gift?\n\n      free_trial_params = params[:perceived_free_trial_duration]\n      if product.free_trial_enabled?","sourceCodeStart":338,"sourceCodeEnd":374,"githubUrl":"https://github.com/antiwork/gumroad/blob/afeacbd394069a1cbf0c6c50ee8e900925050370/app/services/purchase/create_service.rb#L338-L374","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before: country US with a non-US postcode\npurchase_params[:country] = 'US'\npurchase_params[:zip_code] = 'M5V 2T6'\n\n# after: keep country and postcode consistent\npurchase_params[:country] = 'CA' # or fix zip_code to e.g. '94107'","handlingStrategy":"validation","validationCode":"country = purchase_params[:country].presence || purchase_params[:sales_tax_country_code_election]\nif purchase_params[:perceived_price_cents].to_i > 0 && country == 'US'\n  raise ArgumentError, 'invalid US ZIP' unless purchase_params[:zip_code].to_s.match?(/\\A\\d{5}(-\\d{4})?\\z/)\nend","typeGuard":"def valid_us_zip?(zip_code)\n  zip_code.to_s.match?(/\\A\\d{5}(-\\d{4})?\\z/) && UsZipCodes.identify_state_code(zip_code).present?\nend","tryCatchPattern":"begin\n  Purchase::CreateService.new(product:, params:, buyer:).perform\nrescue Purchase::PurchaseInvalid => e\n  # prompt the buyer to correct the ZIP or the country selection; no automated fix\n  render_checkout_error(e.message) if e.message.include?(\"ZIP Code that doesn't exist\")\nend","preventionTips":["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."],"tags":["zip-code","address-validation","sales-tax","us","checkout","gumroad"],"backgroundTag":"invalid-postal-code","analyzedSha":"afeacbd394069a1cbf0c6c50ee8e900925050370","analyzedAt":"2026-08-21T17:58:52.159Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}