Require page count, don't allow over 10lbs, don't allow over 20 pages in printed envelope

This commit is contained in:
Skylar Ittner 2024-08-27 19:34:37 -06:00
parent f3a9ba258a
commit 0545140672
2 changed files with 13 additions and 0 deletions

File diff suppressed because one or more lines are too long

View File

@ -59,11 +59,23 @@ try {
if (!empty($_REQUEST["page_count"]) && is_numeric($_REQUEST["page_count"])) {
// about 5 pages per ounce
$weight = ($_REQUEST["page_count"] * 1 + 1) / 5;
} else {
throw new Exception("Enter the number of pages you're sending so we can estimate the weight for your postage.");
}
if ($weight > 3.5 && $_REQUEST["postagetype"] == "first") {
throw new Exception("Too many pages to send as a First-Class letter. Use Priority Mail instead.");
}
if ($weight > 160) {
// Don't allow over 10 pounds, seems like a good stopping point...
throw new Exception("Wow, that's a lot of pages! You should mail that at a Post Office instead to make sure it's handled and weighed properly.");
}
if ($_REQUEST["page_count"] * 1 > 20
&& $_REQUEST["postagetype"] == "priority"
&& (empty($_REQUEST["label_only"]) || $_REQUEST["label_only"] != "label_only")
&& (empty($_REQUEST["flat_rate"]) || $_REQUEST["flat_rate"] != "flat_rate")) {
throw new Exception("That probably won't fit in our DIY printable envelope. Select the \"Print Postage Only\" option and use your own (large) envelope instead.");
}
if (!empty($_REQUEST["flat_rate"]) && $_REQUEST["flat_rate"] == "flat_rate") {
$shipmentinfo["parcel"] = \EasyPost\Parcel::create([