| @@ -64,12 +64,14 @@ | ||
| 64 | 64 | * $data = [ |
| 65 | 65 | * 'id' => (int) Required. The variant ID. |
| 66 | 66 | * 'post_id' => (int) Required. The product ID. |
| 67 | 67 | * 'variant_title' => (string) Required. The variant title. |
| 68 | - * 'item_price' => (float) Required. The item price. | |
| 69 | - * 'compare_price' => (float) Required. The compare price. | |
| 68 | + * 'item_price' => (int) Required. The item price in CENTS — e.g. 129900 means | |
| 69 | + * $1,299.00. Same unit the API returns on read, and the same | |
| 70 | + * unit stored. See dev-docs/PRICING-AND-TAX.md §6. | |
| 71 | + * 'compare_price' => (int) Required. The compare price, in cents (see item_price). | |
| 70 | 72 | * 'manage_cost' => (string) Optional. Whether to manage costs. |
| 71 | - * 'item_cost' => (float) Required if manage cost is yes. The item cost. | |
| 73 | + * 'item_cost' => (int) Required if manage cost is yes. The item cost, in cents. | |
| 72 | 74 | * 'manage_stock' => (string) Required. Whether to manage stock. |
| 73 | 75 | * 'stock_status' => (string) Required. The stock status. |
| 74 | 76 | * 'stock' => (int) Required. The stock quantity. |
| 75 | 77 | * 'media' => (array) Optional. Info of media files for each variant. |
| @@ -79,9 +81,9 @@ | ||
| 79 | 81 | * 'other_info' => (array) Optional. Other information for the variant. |
| 80 | 82 | * 'payment_type' => (string) Required. The payment type. |
| 81 | 83 | * 'times' => (string) Required. The number of times. |
| 82 | 84 | * 'repeat_interval' => (string) Required. The repeat interval unit. |
| 83 | - * 'signup_fee' => (string) Required. The signup fee. | |
| 85 | + * 'signup_fee' => (int) Required. The signup fee, in cents (see item_price). | |
| 84 | 86 | * 'downloadable_files' => (array) Required if downloadable is true. |
| 85 | 87 | * 'download_limit' => (string) Required. The download limit. |
| 86 | 88 | * 'download_expiry' => (string) Required. The download expiry. |
| 87 | 89 | * 'downloadable' => (bool) Optional. Whether the product is downloadable. |
| @@ -95,13 +97,19 @@ | ||
| 95 | 97 | * ]; |
| 96 | 98 | */ |
| 97 | 99 | public static function create($variant, $params = []) |
| 98 | 100 | { |
| 99 | - $otherInfo = Arr::get($variant, 'other_info'); | |
| 101 | + $otherInfo = Arr::wrap(Arr::get($variant, 'other_info')); | |
| 102 | + $otherInfo['tax_exempt'] = Arr::get($otherInfo, 'tax_exempt', 'no'); | |
| 103 | + $otherInfo['tax_class'] = Arr::get($otherInfo, 'tax_class', 'standard'); | |
| 104 | + | |
| 100 | 105 | if (Arr::get($otherInfo, 'payment_type') == 'onetime') { |
| 101 | 106 | $otherInfo = Arr::only($otherInfo, [ |
| 102 | 107 | 'payment_type', |
| 103 | 108 | 'description', |
| 109 | + 'tax_class', | |
| 110 | + 'tax_exempt', | |
| 111 | + 'tax_inclusion', | |
| 104 | 112 | 'package_slug', |
| 105 | 113 | 'weight', |
| 106 | 114 | 'weight_unit', |
| 107 | 115 | 'length', |
| @@ -115,9 +123,10 @@ | ||
| 115 | 123 | unset($otherInfo['signup_fee']); |
| 116 | 124 | unset($otherInfo['setup_fee_per_item']); |
| 117 | 125 | } |
| 118 | 126 | if (Arr::get($otherInfo, 'manage_setup_fee') == 'yes') { |
| 119 | - $signupFee = Helper::toCent(floatval(Arr::get($otherInfo, 'signup_fee', 0))); | |
| 127 | + // Already in cents — normalize only, do not scale. | |
| 128 | + $signupFee = Helper::roundCent(Arr::get($otherInfo, 'signup_fee', 0)); | |
| 120 | 129 | Arr::set($otherInfo, 'signup_fee', $signupFee); |
| 121 | 130 | } |
| 122 | 131 | } |
| 123 | 132 | |
| @@ -147,12 +156,14 @@ | ||
| 147 | 156 | 'available' => Arr::get($variant, 'available'), |
| 148 | 157 | 'committed' => Arr::get($variant, 'committed'), |
| 149 | 158 | 'on_hold' => Arr::get($variant, 'on_hold'), |
| 150 | 159 | 'stock_status' => $stockStatus, |
| 151 | - 'item_price' => Helper::toCent($itemPrice), | |
| 152 | - //'compare_price' => ($comparePrice !== '' && $comparePrice >= $itemPrice) ? Helper::toCent($comparePrice) : Helper::toCent($itemPrice), | |
| 153 | - 'compare_price' => ($comparePrice !== '' && $comparePrice >= $itemPrice) ? Helper::toCent($comparePrice) : 0, | |
| 154 | - 'item_cost' => Helper::toCent(Arr::get($variant, 'item_cost', 0)), | |
| 160 | + // Amounts arrive already in CENTS. roundCent() only normalizes float | |
| 161 | + // artifacts (a client-computed 19.99 * 100 arriving as | |
| 162 | + // 1998.9999999999998) to a whole-cent int — it does not scale. | |
| 163 | + 'item_price' => Helper::roundCent($itemPrice), | |
| 164 | + 'compare_price' => ($comparePrice !== '' && $comparePrice >= $itemPrice) ? Helper::roundCent($comparePrice) : 0, | |
| 165 | + 'item_cost' => Helper::roundCent(Arr::get($variant, 'item_cost', 0)), | |
| 155 | 166 | 'manage_cost' => Arr::get($variant, 'manage_cost', 'false'), |
| 156 | 167 | 'fulfillment_type' => Arr::get($variant, 'fulfillment_type', 'physical'), |
| 157 | 168 | 'shipping_class' => Arr::get($variant, 'shipping_class') ?: null, |
| 158 | 169 | 'variation_title' => Arr::get($variant, 'variation_title', ''), |
| @@ -195,12 +206,14 @@ | ||
| 195 | 206 | * $variant = [ |
| 196 | 207 | * 'id' => (int) Required. The variant ID. |
| 197 | 208 | * 'post_id' => (int) Required. The product ID. |
| 198 | 209 | * 'variant_title' => (string) Required. The variant title. |
| 199 | - * 'item_price' => (float) Required. The item price. | |
| 200 | - * 'compare_price' => (float) Required. The compare price. | |
| 210 | + * 'item_price' => (int) Required. The item price in CENTS — e.g. 129900 means | |
| 211 | + * $1,299.00. Same unit the API returns on read, and the same | |
| 212 | + * unit stored. See dev-docs/PRICING-AND-TAX.md §6. | |
| 213 | + * 'compare_price' => (int) Required. The compare price, in cents (see item_price). | |
| 201 | 214 | * 'manage_cost' => (string) Optional. Whether to manage costs. |
| 202 | - * 'item_cost' => (float) Required if manage cost is yes. The item cost. | |
| 215 | + * 'item_cost' => (int) Required if manage cost is yes. The item cost, in cents. | |
| 203 | 216 | * 'manage_stock' => (string) Required. Whether to manage stock. |
| 204 | 217 | * 'stock_status' => (string) Required. The stock status. |
| 205 | 218 | * 'stock' => (int) Required. The stock quantity. |
| 206 | 219 | * 'media' => (array) Optional. Info of media files for each variant. |
| @@ -210,9 +223,9 @@ | ||
| 210 | 223 | * 'other_info' => (array) Optional. Other information for the variant. |
| 211 | 224 | * 'payment_type' => (string) Required. The payment type. |
| 212 | 225 | * 'times' => (string) Required. The number of times. |
| 213 | 226 | * 'repeat_interval' => (string) Required. The repeat interval unit. |
| 214 | - * 'signup_fee' => (string) Required. The signup fee. | |
| 227 | + * 'signup_fee' => (int) Required. The signup fee, in cents (see item_price). | |
| 215 | 228 | * 'downloadable_files' => (array) Required if downloadable is true. |
| 216 | 229 | * 'download_limit' => (string) Required. The download limit. |
| 217 | 230 | * 'download_expiry' => (string) Required. The download expiry. |
| 218 | 231 | * 'downloadable' => (bool) Optional. Whether the product is downloadable. |
| @@ -225,10 +238,8 @@ | ||
| 225 | 238 | * 'serial' => (string) Required if files. The file serial |
| 226 | 239 | * 'product_terms' => (array) Optional. Terms of the product. |
| 227 | 240 | * 'product-categories' => (array) Required if categories. Product categories. |
| 228 | 241 | * [0] => (int) Optional. The category ID. |
| 229 | - * 'product-tags' => (array) Required if tags. Product tags. | |
| 230 | - * [0] => (int) Optional. The tag ID. | |
| 231 | 242 | * 'product-types' => (array) Required if types. Product types. |
| 232 | 243 | * [0] => (int) Optional. The type ID. |
| 233 | 244 | * ]; |
| 234 | 245 | */ |
| @@ -246,8 +257,11 @@ | ||
| 246 | 257 | if (Arr::get($otherInfo, 'payment_type') == 'onetime') { |
| 247 | 258 | $otherInfo = Arr::only($otherInfo, [ |
| 248 | 259 | 'payment_type', |
| 249 | 260 | 'description', |
| 261 | + 'tax_class', | |
| 262 | + 'tax_exempt', | |
| 263 | + 'tax_inclusion', | |
| 250 | 264 | 'bundle_child_ids', |
| 251 | 265 | 'package_slug', |
| 252 | 266 | 'weight', |
| 253 | 267 | 'weight_unit', |
| @@ -262,9 +276,10 @@ | ||
| 262 | 276 | unset($otherInfo['signup_fee']); |
| 263 | 277 | unset($otherInfo['setup_fee_per_item']); |
| 264 | 278 | } |
| 265 | 279 | if (Arr::get($otherInfo, 'manage_setup_fee') == 'yes') { |
| 266 | - $signupFee = Helper::toCent(floatval(Arr::get($otherInfo, 'signup_fee', 0))); | |
| 280 | + // Already in cents — normalize only, do not scale. | |
| 281 | + $signupFee = Helper::roundCent(Arr::get($otherInfo, 'signup_fee', 0)); | |
| 267 | 282 | Arr::set($otherInfo, 'signup_fee', $signupFee); |
| 268 | 283 | } |
| 269 | 284 | } |
| 270 | 285 | |
| @@ -301,12 +316,14 @@ | ||
| 301 | 316 | 'committed' => Arr::get($variant, 'committed'), |
| 302 | 317 | 'on_hold' => Arr::get($variant, 'on_hold'), |
| 303 | 318 | 'shipping_class' => Arr::get($variant, 'shipping_class') ?: null, |
| 304 | 319 | 'stock_status' => $stockStatus, |
| 305 | - 'item_price' => Helper::toCent($itemPrice), | |
| 306 | - //'compare_price' => ($comparePrice !== '' && $comparePrice >= $itemPrice) ? Helper::toCent($comparePrice) : Helper::toCent($itemPrice), | |
| 307 | - 'compare_price' => ($comparePrice !== '' && $comparePrice >= $itemPrice) ? Helper::toCent($comparePrice) : 0, | |
| 308 | - 'item_cost' => Helper::toCent(Arr::get($variant, 'item_cost', 0)), | |
| 320 | + // Amounts arrive already in CENTS. roundCent() only normalizes float | |
| 321 | + // artifacts (a client-computed 19.99 * 100 arriving as | |
| 322 | + // 1998.9999999999998) to a whole-cent int — it does not scale. | |
| 323 | + 'item_price' => Helper::roundCent($itemPrice), | |
| 324 | + 'compare_price' => ($comparePrice !== '' && $comparePrice >= $itemPrice) ? Helper::roundCent($comparePrice) : 0, | |
| 325 | + 'item_cost' => Helper::roundCent(Arr::get($variant, 'item_cost', 0)), | |
| 309 | 326 | 'manage_cost' => Arr::get($variant, 'manage_cost', 'false'), |
| 310 | 327 | 'fulfillment_type' => Arr::get($variant, 'fulfillment_type', 'physical'), |
| 311 | 328 | 'variation_title' => Arr::get($variant, 'variation_title', ''), |
| 312 | 329 | 'sku' => Arr::get($variant, 'sku') ?: null, |