<?php
namespace Maatwebsite\Excel\Validators;
use Illuminate\Contracts\Validation\Factory;
use Illuminate\Support\Str;
use Illuminate\Validation\ValidationException as IlluminateValidationException;
use Maatwebsite\Excel\Concerns\SkipsOnFailure;
use Maatwebsite\Excel\Concerns\WithValidation;
use Maatwebsite\Excel\Exceptions\RowSkippedException;
class RowValidator
{
/**
* @var Factory
*/
private $validator;
/**
* @param Factory $validator
*/
public function __construct(Factory $validator)
{
$this->validator = $validator;
}
/**
* @param array $rows
* @param WithValidation $import
*
* @throws ValidationException
* @throws RowSkippedException
*/
public function validate(array $rows, WithValidation $import)
{
$rules = $this->rules($import);
$messages = $this->messages($import);
$attributes = $this->attributes($import);
try {
$validator = $this->validator->make($rows, $rules, $messages, $attributes);
if (method_exists($import, 'withValidator')) {
$import->withValidator($validator);
}
$validator->validate();
} catch (IlluminateValidationException $e) {
$failures = [];
foreach ($e->errors() as $attribute => $messages) {
$row = strtok($attribute, '.');
$attributeName = strtok('');
$attributeName = $attributes['*.' . $attributeName] ?? $attributeName;
$failures[] = new Failure(
$row,
$attributeName,
str_replace($attribute, $attributeName, $messages),
$rows[$row] ?? []
);
}
if ($import instanceof SkipsOnFailure) {
$import->onFailure(...$failures);
throw new RowSkippedException(...$failures);
}
throw new ValidationException(
$e,
$failures
);
}
}
/**
* @param WithValidation $import
* @return array
*/
private function messages(WithValidation $import): array
{
return method_exists($import, 'customValidationMessages')
? $this->formatKey($import->customValidationMessages())
: [];
}
/**
* @param WithValidation $import
* @return array
*/
private function attributes(WithValidation $import): array
{
return method_exists($import, 'customValidationAttributes')
? $this->formatKey($import->customValidationAttributes())
: [];
}
/**
* @param WithValidation $import
* @return array
*/
private function rules(WithValidation $import): array
{
return $this->formatKey($import->rules());
}
/**
* @param array $elements
* @return array
*/
private function formatKey(array $elements): array
{
return collect($elements)->mapWithKeys(function ($rule, $attribute) {
$attribute = Str::startsWith($attribute, '*.') ? $attribute : '*.' . $attribute;
return [$attribute => $this->formatRule($rule)];
})->all();
}
/**
* @param string|object|callable|array $rules
* @return string|array
*/
private function formatRule($rules)
{
if (is_array($rules)) {
foreach ($rules as $rule) {
$formatted[] = $this->formatRule($rule);
}
return $formatted ?? [];
}
if (is_object($rules) || is_callable($rules)) {
return $rules;
}
if (Str::contains($rules, 'required_') && preg_match('/(.*?):(.*),(.*)/', $rules, $matches)) {
$column = Str::startsWith($matches[2], '*.') ? $matches[2] : '*.' . $matches[2];
return $matches[1] . ':' . $column . ',' . $matches[3];
}
return $rules;
}
}
At NFC Pay, we strive to provide a seamless and satisfactory experience with our services. This Refund Policy outlines the circumstances under which refunds may be issued for transactions made through our platform. Please read this policy carefully to understand your rights regarding refunds.
1. Eligibility for Refunds
Refunds may be considered under the following circumstances:
2. Non-Refundable Situations
Refunds will generally not be issued in the following situations:
3. Refund Process
To request a refund, please follow these steps:
4. Refund Exceptions
Certain transactions may be subject to specific terms and conditions, including non-refundable fees or charges. Please review the terms associated with each transaction carefully, as some fees may not be eligible for refunds.
5. Modifications to the Refund Policy
NFC Pay reserves the right to modify this Refund Policy at any time. Changes will be communicated through updates on our website and app, and the effective date will be updated accordingly. We encourage you to review this policy periodically to stay informed about our refund practices.
By using NFC Pay, you agree to this Refund Policy and understand the terms under which refunds may be issued. Our goal is to ensure a fair and transparent refund process, providing you with confidence and peace of mind when using our services.