PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.3
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.3
1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk All 48 releases
fluent-cart / app / Http / Requests / OrderRequest.php

OrderRequest.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.3, at app/Http/Requests/OrderRequest.php

243 lines 12.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Http\Requests;
4
5 use FluentCart\App\Helpers\Helper;
6 use FluentCart\Framework\Foundation\RequestGuard;
7
8 class OrderRequest extends RequestGuard
9 {
10
11 /**
12 * @return array
13 */
14 public function rules(): array
15 {
16 return [
17 'status' => 'nullable|sanitizeText|maxLength:50',
18 'invoice_no' => 'nullable|sanitizeText|maxLength:100',
19 'fulfillment_type' => 'nullable|sanitizeText|maxLength:50',
20 'type' => 'nullable|sanitizeText|maxLength:50',
21 'payment_method' => 'nullable|sanitizeText|maxLength:50',
22 'payment_method_title' => 'nullable|sanitizeText|maxLength:50',
23 'payment_status' => 'nullable|sanitizeText|maxLength:50',
24 'currency' => 'nullable|sanitizeText|maxLength:10',
25 'subtotal' => 'numeric',
26 'discount_tax' => 'numeric',
27 'manual_discount_total' => 'numeric',
28 'coupon_discount_total' => 'numeric',
29 'shipping_tax' => 'numeric',
30 // min/max close the silent-corruption window: 1e19 passes `numeric`
31 // but wraps to a negative BIGINT through a float-to-int cast, and a
32 // negative shipping charge has no meaning. The bound matches the
33 // Helper::roundCent() guard (float's exact-integer range).
34 'shipping_total' => 'numeric|min:0|max:9000000000000000',
35 'tax_total' => 'numeric',
36 'total_amount' => 'numeric',
37 'rate' => 'numeric',
38 'note' => 'nullable|sanitizeTextArea|maxLength:5000',
39 'uuid' => 'nullable|sanitizeText|maxLength:100',
40 'ip_address' => 'nullable|sanitizeText|maxLength:100',
41 'completed_at' => 'nullable|sanitizeText|maxLength:100',
42 'refunded_at' => 'nullable|sanitizeText|maxLength:100',
43 'customer_id' => 'required|numeric',
44 'user_tz' => 'nullable|sanitizeText|maxLength:50',
45
46 'order_items' => 'required|array',
47 "order_items.*.id" => 'numeric|min:1',
48 "order_items.*.order_id" => 'numeric|min:1',
49 "order_items.*.post_id" => 'numeric|min:1',
50 "order_items.*.variation_id" => 'numeric|min:1',
51 "order_items.*.object_id" => 'numeric|min:1',
52 "order_items.*.fulfillment_type" => 'nullable|sanitizeText',
53 "order_items.*.payment_type" => 'nullable|sanitizeText|maxLength:100',
54 "order_items.*.quantity" => 'numeric|min:1',
55 "order_items.*.post_title" => 'nullable|sanitizeText|maxLength:255',
56 "order_items.*.title" => 'nullable|sanitizeText|maxLength:255',
57 "order_items.*.price" => 'numeric',
58 "order_items.*.unit_price" => 'numeric',
59 "order_items.*.shipping_charge" => 'nullable|numeric',
60 "order_items.*.item_cost" => 'numeric',
61 "order_items.*.item_total" => 'numeric',
62 "order_items.*.tax_amount" => 'numeric',
63 "order_items.*.discount_total" => 'numeric',
64 "order_items.*.total" => 'numeric',
65 "order_items.*.line_total" => 'numeric',
66 "order_items.*.cart_index" => 'nullable|numeric',
67 "order_items.*.rate" => 'nullable|numeric',
68 "order_items.*.line_meta" => 'nullable|array',
69 "order_items.*.other_info" => 'nullable|array',
70
71 "discount.type" => 'nullable|sanitizeText|maxLength:100',
72 "discount.value" => 'nullable|numeric',
73 "discount.label" => 'nullable|sanitizeText|maxLength:100',
74 "discount.reason" => 'nullable|sanitizeText|maxLength:100',
75 "discount.action" => 'nullable|sanitizeText|maxLength:100',
76
77 'shipping' => 'nullable|array',
78 "shipping.*.type" => 'nullable|sanitizeText|maxLength:100',
79 "shipping.*.rate_name" => 'nullable|sanitizeText|maxLength:100',
80 "shipping.*.custom_price" => 'nullable|numeric',
81
82 'deletedItems' => 'nullable|array',
83 'tax_behavior' => 'nullable|numeric|min:0',
84 'tax_lines' => 'nullable|array',
85 'tax_lines.*.rate_id' => 'nullable|numeric|min:0',
86 'tax_lines.*.tax_amount' => 'nullable|numeric|min:0',
87 'tax_lines.*.label' => 'nullable|sanitizeText',
88 'tax_lines.*.is_compound'=> 'nullable',
89
90 'applied_coupon' => 'nullable|array',
91 "applied_coupon.*.id" => 'nullable|numeric|min:1',
92 "applied_coupon.*.order_id" => 'nullable|numeric|min:1',
93 "applied_coupon.*.coupon_id" => 'required|numeric|min:1',
94 //"applied_coupon.*.title" => 'required|string|max:100',
95 "applied_coupon.*.code" => 'required|sanitizeText|maxLength:100',
96 //"applied_coupon.*.status" => 'required|string|max:100',
97 //"applied_coupon.*.type" => 'required|string|max:100',
98 "applied_coupon.*.amount" => 'nullable|numeric',
99 "applied_coupon.*.discounted_amount" => 'required|numeric',
100 "applied_coupon.*.discount" => 'nullable|numeric',
101 "applied_coupon.*.stackable" => 'required|numeric',
102 "applied_coupon.*.priority" => 'nullable|numeric',
103 "applied_coupon.*.max_uses" => 'nullable|numeric',
104 "applied_coupon.*.use_count" => 'nullable|numeric',
105 "applied_coupon.*.max_per_customer" => 'nullable|numeric|min:1',
106 "applied_coupon.*.min_purchase_amount" => 'nullable|numeric',
107 "applied_coupon.*.max_discount_amount" => 'nullable|numeric',
108 "applied_coupon.*.notes" => 'nullable|sanitizeTextArea|maxLength:100',
109 'trigger' => 'nullable|string',
110 ];
111 }
112
113
114 /**
115 * @return array
116 */
117 public function messages(): array
118 {
119 return [
120 'customer_id.required' => esc_html__('Customer selection is required', 'fluent-cart'),
121 'order_items.required' => esc_html__('Item selection is required', 'fluent-cart'),
122 ];
123 }
124
125
126 /**
127 * @return array
128 */
129 public function sanitize()
130 {
131 return [
132 'id' => 'intval',
133 'status' => 'sanitize_text_field',
134 'invoice_no' => 'sanitize_text_field',
135 'fulfillment_type' => 'sanitize_text_field',
136 'type' => 'sanitize_text_field',
137 'customer_id' => 'intval',
138 'payment_method' => 'sanitize_text_field',
139 'payment_method_title' => 'sanitize_text_field',
140 'payment_status' => 'sanitize_text_field',
141 'currency' => 'sanitize_text_field',
142 'subtotal' => 'floatval',
143 'discount_tax' => 'floatval',
144 'manual_discount_total' => 'floatval',
145 'coupon_discount_total' => 'floatval',
146 'shipping_tax' => 'floatval',
147 // Cents column: normalize at the boundary so every consumer of this request
148 // receives a whole-cent int. floatval alone let a client-computed 19.99 * 100
149 // arrive as 1998.9999999999998, which any later int cast would truncate.
150 //
151 // Wrapped in a closure, NOT passed as [Helper::class, 'roundCent']: an array
152 // value in this map is a LIST of callbacks, iterated one by one
153 // (vendor/wpfluent/framework/src/WPFluent/Support/Sanitizer.php:456-464), so the
154 // array-callable form would try to call Helper() as a function.
155 'shipping_total' => function ($value) {
156 return Helper::roundCent($value);
157 },
158 'tax_total' => 'floatval',
159 'tax_behavior' => 'intval',
160 'total_amount' => 'floatval',
161 'rate' => 'sanitize_text_field',
162 'note' => 'sanitize_text_field',
163 'uuid' => 'sanitize_text_field',
164 'ip_address' => 'sanitize_text_field',
165 'billing_address_id' => 'intval',
166 'shipping_address_id' => 'intval',
167 'completed_at' => 'sanitize_text_field',
168 'refunded_at' => 'sanitize_text_field',
169 'user_tz' => 'sanitize_text_field',
170
171 "order_items.*.id" => 'intval',
172 "order_items.*.order_id" => 'intval',
173 "order_items.*.post_id" => 'intval',
174 "order_items.*.object_id" => 'intval',
175 "order_items.*.payment_type" => 'sanitize_text_field',
176 "order_items.*.quantity" => 'intval',
177 "order_items.*.post_title" => 'sanitize_text_field',
178 "order_items.*.title" => 'sanitize_text_field',
179 "order_items.*.shipping_charge" => 'intval',
180 "order_items.*.price" => 'floatval',
181 "order_items.*.unit_price" => 'floatval',
182 "order_items.*.item_cost" => 'floatval',
183 "order_items.*.item_total" => 'floatval',
184 "order_items.*.tax_amount" => 'floatval',
185 "order_items.*.discount_total" => 'floatval',
186 "order_items.*.total" => 'floatval',
187 "order_items.*.line_total" => 'floatval',
188 "order_items.*.cart_index" => 'intval',
189 "order_items.*.rate" => 'floatval',
190 "order_items.*.line_meta" => function ($value) {
191 return is_array($value) ? $value : [];
192 },
193 "order_items.*.other_info" => function ($value) {
194 return is_array($value) ? $value : [];
195 },
196
197 "discount.type" => 'sanitize_text_field',
198 "discount.value" => 'floatval',
199 "discount.label" => 'sanitize_text_field',
200 "discount.reason" => 'sanitize_text_field',
201 "discount.action" => 'sanitize_text_field',
202
203 "shipping.*.type" => 'sanitize_text_field',
204 "shipping.*.rate_name" => 'sanitize_text_field',
205 "shipping.*.custom_price" => 'floatval',
206
207 "deletedItems" => function ($value) {
208 return is_array($value) ? $value : [];
209 },
210 "tax_lines" => function ($value) {
211 return is_array($value) ? $value : [];
212 },
213 "tax_lines.*.rate_id" => 'intval',
214 "tax_lines.*.tax_amount" => 'intval',
215 "tax_lines.*.label" => 'sanitize_text_field',
216 "tax_lines.*.is_compound"=> function ($value) {
217 return (bool) $value;
218 },
219
220 "applied_coupon.*.id" => 'intval',
221 "applied_coupon.*.order_id" => 'intval',
222 "applied_coupon.*.coupon_id" => 'intval',
223 "applied_coupon.*.title" => 'sanitize_text_field',
224 "applied_coupon.*.discount" => 'intval',
225 "applied_coupon.*.code" => 'sanitize_text_field',
226 "applied_coupon.*.status" => 'sanitize_text_field',
227 "applied_coupon.*.type" => 'sanitize_text_field',
228 "applied_coupon.*.amount" => 'intval',
229 "applied_coupon.*.discounted_amount" => 'intval',
230 "applied_coupon.*.stackable" => 'intval',
231 "applied_coupon.*.priority" => 'intval',
232 "applied_coupon.*.max_uses" => 'intval',
233 "applied_coupon.*.use_count" => 'intval',
234 "applied_coupon.*.max_per_customer" => 'intval',
235 "applied_coupon.*.min_purchase_amount" => 'intval',
236 "applied_coupon.*.max_discount_amount" => 'intval',
237 "applied_coupon.*.notes" => 'sanitize_text_field',
238 'trigger' => 'sanitize_text_field',
239 ];
240
241 }
242 }
243