PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.4
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 1.2.0 All 47 releases
fluent-cart / app / Http / Requests / UpdateSubscriptionRequest.php

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

69 lines 2.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\Status;
6 use FluentCart\Framework\Foundation\RequestGuard;
7 use FluentCart\Framework\Support\Arr;
8
9 class UpdateSubscriptionRequest extends RequestGuard
10 {
11 public function beforeValidation()
12 {
13 return Arr::get($this->all(), 'data', []);
14 }
15
16 public function rules()
17 {
18 $allowedStatuses = [
19 Status::SUBSCRIPTION_ACTIVE,
20 Status::SUBSCRIPTION_PAUSED,
21 Status::SUBSCRIPTION_TRIALING,
22 Status::SUBSCRIPTION_CANCELED,
23 Status::SUBSCRIPTION_EXPIRED,
24 Status::SUBSCRIPTION_COMPLETED,
25 Status::SUBSCRIPTION_PAST_DUE,
26 ];
27
28 return [
29 'recurring_total' => 'nullable|numeric|min:0',
30 'bill_times' => 'nullable|numeric|min:0',
31 'billing_interval' => 'nullable|sanitizeText|maxLength:100',
32 'status' => ['required', 'sanitizeText', 'validStatus' => function ($attribute, $value) use ($allowedStatuses) {
33 if (!in_array($value, $allowedStatuses, true)) {
34 return __('Invalid subscription status.', 'fluent-cart');
35 }
36 return null;
37 }],
38 'next_billing_date' => ['nullable', 'sanitizeText', 'maxLength:25', 'validDate' => function ($attribute, $value) {
39 if ($value && strtotime($value) === false) {
40 return __('Invalid date format for next billing date.', 'fluent-cart');
41 }
42 return null;
43 }],
44 ];
45 }
46
47 public function messages()
48 {
49 return [
50 'recurring_total.numeric' => esc_html__('Recurring total must be a number.', 'fluent-cart'),
51 'recurring_total.min' => esc_html__('Recurring total cannot be negative.', 'fluent-cart'),
52 'bill_times.numeric' => esc_html__('Bill times must be a number.', 'fluent-cart'),
53 'bill_times.min' => esc_html__('Bill times cannot be negative.', 'fluent-cart'),
54 'status.required' => esc_html__('Subscription status is required.', 'fluent-cart'),
55 ];
56 }
57
58 public function sanitize()
59 {
60 return [
61 'recurring_total' => 'floatval',
62 'bill_times' => 'intval',
63 'billing_interval' => 'sanitize_text_field',
64 'status' => 'sanitize_text_field',
65 'next_billing_date' => 'sanitize_text_field',
66 ];
67 }
68 }
69