{"record":{"id":"b10da19735b0f3bb","repo":"antiwork/gumroad","slug":"something-went-wrong-please-refresh-the-page-to-p","errorCode":null,"errorMessage":"Something went wrong. Please refresh the page to pre-order the product.","messagePattern":"Something went wrong\\. Please refresh the page to pre-order the product\\.","errorType":"exception","errorClass":"Purchase::PurchaseInvalid","httpStatus":null,"severity":"error","filePath":"app/services/purchase/create_service.rb","lineNumber":75,"sourceCode":"        )\n      elsif @product.product_refund_policy_enabled? && @product.product_refund_policy.present?\n        # The enabled flag can be out of sync with the underlying record (the\n        # ProductRefundPolicy row may have been deleted or never created), so we only\n        # attach a purchase refund policy when the record actually exists.\n        purchase.build_purchase_refund_policy(\n          max_refund_period_in_days: @product.product_refund_policy.max_refund_period_in_days,\n          title: @product.product_refund_policy.title,\n          fine_print: @product.product_refund_policy.fine_print\n        )\n      end\n\n      # build pre-order if purchase is for pre-order product & return\n      if purchase.is_preorder_authorization\n        build_preorder(locked_rate: buyer_currency_quote_rate_hint(purchase))\n        return purchase, nil\n      elsif product.is_in_preorder_state?\n        # This should never happen unless the request is tampered with:\n        raise Purchase::PurchaseInvalid, \"Something went wrong. Please refresh the page to pre-order the product.\"\n      end\n\n      purchase.is_commission_deposit_purchase = product.native_type == Link::NATIVE_TYPE_COMMISSION\n\n      # associate correct price for membership product\n      if product.is_recurring_billing || purchase.is_installment_payment\n        # For membership products, params[:price_id] should be provided but if\n        # not, or if a price_id is invalid, associate the default price.\n        price = params[:price_id].present? ?\n          product.prices.alive.find_by_external_id(params[:price_id]) :\n          product.default_price\n\n        purchase.price = price || product.default_price\n\n        # Check for existing subscriptions (active or restartable)\n        if should_check_for_restartable_subscription?\n          existing_purchase, error, sca_response = handle_existing_subscription\n          return nil, nil, sca_response if sca_response.present?","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/antiwork/gumroad/blob/afeacbd394069a1cbf0c6c50ee8e900925050370/app/services/purchase/create_service.rb#L57-L93","documentation":"In Purchase::CreateService, a purchase for a product still in preorder state must be created as a preorder authorization (purchase.is_preorder_authorization, set by the preorder checkout form/token). If the flag is absent while product.is_in_preorder_state? is true, Purchase::PurchaseInvalid is raised — per the code comment, 'This should never happen unless the request is tampered with': the preorder params were altered, dropped, or built by a client that skipped the preorder flow.","triggerScenarios":"Modifying the checkout form/hidden fields (e.g. clearing the preorder authorization flag via devtools), a stale cached checkout page from before the product entered/left preorder, or a scripted POST to the purchase endpoint that omits the preorder authorization params.","commonSituations":"Browser extensions or scripts that rebuild forms; buyers with a long-open tab on a product that just went into preorder; custom automation that doesn't first fetch the live checkout payload.","solutions":["Reload the product page and start checkout fresh so the preorder form/token is regenerated","If scripting, GET the checkout page/props first and forward the preorder params untouched","Never modify or drop the is_preorder_authorization / preorder form fields","Sellers: verify the product's preorder state matches what the checkout page shows before debugging further"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"# Client-side: verify the product's preorder state and fetch a fresh form\ndef fresh_checkout_state?(product)\n  loaded = Product.find_by(unique_permalink: product.unique_permalink)\n  loaded.is_in_preorder_state? == form_preorder_fields_present?\nend","typeGuard":null,"tryCatchPattern":"begin\n  Purchase::CreateService.new(user: buyer, params: purchase_params).perform\nrescue Purchase::PurchaseInvalid => e\n  if e.message.include?('pre-order')\n    redirect_to product_path(product) # restart checkout from a fresh page\n  else\n    render_error(e.message)\n  end\nend","preventionTips":["Always start checkout by fetching the live product/checkout payload — never replay a cached or reconstructed form","Forward preorder form fields (including the authorization flag) untouched; this raise is an anti-tamper tripwire, not a bug to code around","In automation, detect a product entering preorder state and re-GET the page before the purchase POST"],"tags":["ruby","rails","checkout","preorder","tamper-guard"],"backgroundTag":"stale-checkout-state","analyzedSha":"afeacbd394069a1cbf0c6c50ee8e900925050370","analyzedAt":"2026-08-21T17:58:52.159Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}