| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Http\Requests; |
| 4 |
|
| 5 |
use FluentCart\Framework\Foundation\RequestGuard; |
| 6 |
use FluentCart\Framework\Support\Arr; |
| 7 |
|
| 8 |
class UpdateVendorIdsRequest extends RequestGuard |
| 9 |
{ |
| 10 |
public function beforeValidation() |
| 11 |
{ |
| 12 |
return Arr::get($this->all(), 'data', []); |
| 13 |
} |
| 14 |
|
| 15 |
public function rules() |
| 16 |
{ |
| 17 |
// Both ids are interpolated into gateway API paths (Stripe |
| 18 |
// subscriptions/{id}, Mollie customers/{cid}/subscriptions/{id}), so the |
| 19 |
// character set is constrained here rather than at each call site. |
| 20 |
$format = function ($attribute, $value) { |
| 21 |
if ($value && !preg_match('/^[a-zA-Z0-9_.-]+$/', $value)) { |
| 22 |
return __('Vendor IDs may only contain letters, numbers, dots, dashes and underscores.', 'fluent-cart'); |
| 23 |
} |
| 24 |
return null; |
| 25 |
}; |
| 26 |
|
| 27 |
return [ |
| 28 |
'vendor_subscription_id' => ['nullable', 'sanitizeText', 'maxLength:45', 'validFormat' => $format], |
| 29 |
'vendor_customer_id' => ['nullable', 'sanitizeText', 'maxLength:45', 'validFormat' => $format], |
| 30 |
]; |
| 31 |
} |
| 32 |
|
| 33 |
public function messages() |
| 34 |
{ |
| 35 |
return [ |
| 36 |
'vendor_subscription_id.maxLength' => esc_html__('Vendor Subscription ID cannot be longer than 45 characters.', 'fluent-cart'), |
| 37 |
'vendor_customer_id.maxLength' => esc_html__('Vendor Customer ID cannot be longer than 45 characters.', 'fluent-cart'), |
| 38 |
]; |
| 39 |
} |
| 40 |
|
| 41 |
public function sanitize() |
| 42 |
{ |
| 43 |
return [ |
| 44 |
'vendor_subscription_id' => 'sanitize_text_field', |
| 45 |
'vendor_customer_id' => 'sanitize_text_field', |
| 46 |
]; |
| 47 |
} |
| 48 |
} |
| 49 |
|