{"record":{"id":"6921090529294993","repo":"phacility/phabricator","slug":"maximum-allowed-amount-is-s","errorCode":null,"errorMessage":"Maximum allowed amount is %s.","messagePattern":"Maximum allowed amount is (.+?)\\.","errorType":"validation","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/applications/phortune/currency/PhortuneCurrency.php","lineNumber":228,"sourceCode":"            $min->formatForDisplay(),\n            $max->formatForDisplay()));\n      }\n    }\n\n    if ($minimum !== null) {\n      $min = self::newFromString($minimum);\n      if ($min->value > $this->value) {\n        throw new Exception(\n          pht(\n            'Minimum allowed amount is %s.',\n            $min->formatForDisplay()));\n      }\n    }\n\n    if ($maximum !== null) {\n      $max = self::newFromString($maximum);\n      if ($max->value < $this->value) {\n        throw new Exception(\n          pht(\n            'Maximum allowed amount is %s.',\n            $max->formatForDisplay()));\n      }\n    }\n\n    return $this;\n  }\n\n\n}\n","sourceCodeStart":210,"sourceCodeEnd":240,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/phortune/currency/PhortuneCurrency.php#L210-L240","documentation":"Thrown by PhortuneCurrency::assertInRange($minimum, $maximum) when the object's value (integer cents) exceeds the parsed $maximum. Bounds are inclusive: the check is $max->value < $this->value, so a value exactly equal to the maximum passes. The message shows the maximum formatted for display (e.g. '$500.00 USD'), ready to show to an end user.","triggerScenarios":"Calling PhortuneCurrency::newFromString('750.00 USD')->assertInRange('5.00 USD', '500.00 USD') — 75000 cents > 50000 cents throws. Typically hit when a product price, cart total, or one-time payment amount is set above a configured ceiling.","commonSituations":"Capping maximum purchase or top-up amounts to limit fraud exposure; subscription price ceilings in plan configuration; multiplying a unit price by a quantity and forgetting to re-check the total against the cap; changing a config ceiling after products were already priced above it.","solutions":["Lower the value being validated to or below the maximum shown in the message.","Raise the configured maximum string if business rules changed — check where the bound is defined (config, product metadata, form field limit).","Verify quantity math: unit price in range does not imply (unit * quantity) in range; assert on the computed total.","Catch the Exception and render the message as a field-level validation error rather than letting it bubble as a 500."],"exampleFix":"// before\n$total->assertInRange('1.00 USD', '500.00 USD');\n\n// after\ntry {\n  $total->assertInRange('1.00 USD', '500.00 USD');\n} catch (Exception $ex) {\n  return $this->newDialog()\n    ->setTitle(pht('Amount Too Large'))\n    ->appendParagraph($ex->getMessage())\n    ->addCancelButton($cart->getCheckoutURI());\n}","handlingStrategy":"validation","validationCode":"// Compare in cents BEFORE calling assertInRange.\nfunction currency_within_maximum(PhortuneCurrency $amount, $maximum_string) {\n  if ($maximum_string === null) {\n    return true;\n  }\n  $max = PhortuneCurrency::newFromString($maximum_string);\n  return $amount->getValue() <= $max->getValue();\n}\n\nif (!currency_within_maximum($total, $maximum)) {\n  $field_error = pht(\n    'Maximum allowed amount is %s.',\n    PhortuneCurrency::newFromString($maximum)->formatForDisplay());\n}","typeGuard":null,"tryCatchPattern":"try {\n  $total->assertInRange($minimum, $maximum);\n} catch (Exception $ex) {\n  // Bounds are inclusive; the message names the exact cap to show the user.\n  return $this->newDialog()\n    ->setTitle(pht('Amount Out of Range'))\n    ->appendParagraph($ex->getMessage())\n    ->addCancelButton($this->getApplicationURI());\n}","preventionTips":["Assert on computed totals (unit price * quantity), not just the unit price.","Keep the maximum in configuration, not inlined per call site, so raising it is a one-line change.","Bound strings are parsed with the same strict grammar as amounts — keep them as '500.00 USD' style strings."],"tags":["php","phabricator","phortune","currency","range-validation","payments"],"backgroundTag":"value-out-of-range","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}