$errors Specific validation errors */ public function __construct( string $message = 'Webhook payload validation failed.', protected string $gateway = 'unknown', protected array $errors = [] ) { parent::__construct($message); } /** * Get the payment gateway identifier. */ public function getGateway(): string { return $this->gateway; } /** * Get the specific validation errors. * * @return array */ public function getErrors(): array { return $this->errors; } /** * Create an exception for invalid JSON. */ public static function invalidJson(string $gateway, string $error): self { return new self( message: "Invalid JSON payload: {$error}", gateway: $gateway, errors: ['json' => $error] ); } /** * Create an exception for missing required fields. * * @param array $missingFields */ public static function missingFields(string $gateway, array $missingFields): self { $fields = implode(', ', $missingFields); return new self( message: "Missing required fields: {$fields}", gateway: $gateway, errors: ['missing_fields' => $missingFields] ); } /** * Create an exception for invalid field types. * * @param array $typeErrors */ public static function invalidFieldTypes(string $gateway, array $typeErrors): self { $errorMessages = []; foreach ($typeErrors as $field => $types) { $errorMessages[] = "{$field} (expected {$types['expected']}, got {$types['actual']})"; } return new self( message: 'Invalid field types: '.implode(', ', $errorMessages), gateway: $gateway, errors: ['type_errors' => $typeErrors] ); } /** * Create an exception for invalid field values. * * @param array $valueErrors */ public static function invalidFieldValues(string $gateway, array $valueErrors): self { $errorMessages = []; foreach ($valueErrors as $field => $error) { $errorMessages[] = "{$field}: {$error}"; } return new self( message: 'Invalid field values: '.implode(', ', $errorMessages), gateway: $gateway, errors: ['value_errors' => $valueErrors] ); } }