eventix/eu-vat 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

eventix/eu-vat

Composer 安装命令:

composer require eventix/eu-vat

包简介

Eu VAT formatting and validation Laravel package

README 文档

README

PHP Version Laravel Version License

This Laravel package enables the formatting and validation of (EU) VAT numbers.

For validation it uses the endpoints of the European Commission's VAT Information Exchange Service (VIES)

Table of Contents

Installation

Via Composer

$ composer require eventix/eu-vat

Usage

When the package is included in a Laravel project, composer autoload functionality has automatically discovered a Service Provider. This will extend the Laravel Validator with a validation rule (vat_number).

Also an alias for a Facade is registered. This facade (EuVat) will enable manual formatting and validation for vat numbers.

Supported countries

EuVat::codes(): array; // List of supported country codes 
EuVat::supports(string $countryCode): bool; // Determines if a given country code is supported
EuVat::name(string $countryCode): ?string; // Returns the (english) name associated with a country code if it is supported)
EuVat::inferCountry(string $vatNumber): ?string; // (Try to) guess the country of a vat number.

Vat Numbers

EuVat::format(string $vatNumber, ?string $countryCode = null): ?string // (Try to) format a vat number by the formatting rules of a given country, or a guessed country
EuVat::validate(string $vatNumber, ?string $countryCode = null): ?string // (Try to) validate a vat number by the formatting rules of a given country, or a guessed country

Validator

Validates the vat number by inferring its country

$data = [
    'vat_nr' => 'NL123456789B01',
];

$validator = Validator::make($data, [
    'vat_nr' => 'required|vat_number',
]);

Validates the vat number for a given country

$data = [
    'vat_nr' => 'NL123456789B01',
];

$validator = Validator::make($data, [
    'vat_nr' => 'required|vat_number:NL',
]);

Validates the vat number for a country determined by another field

$data = [
    'country' => 'NL',
    'vat_nr' => 'NL123456789B01',
];

$validator = Validator::make($data, [
    'vat_nr' => 'required|vat_number:country',
]);

Validation ONLY when the vat number changes

If the value does not change... it should already be valid. This will reduce the calls to VIES. Note: The validation rule needs the original value for this to work.

Validates a changed vat number for an inferred country

$data = [
    'vat_nr' => 'NL123456789B01',
];

$validator = Validator::make($data, [
    'vat_nr' => 'required|vat_number:NULL,NL123456789B01',
]);

Validates a changed vat number for a country determined by another field

$data = [
    'country' => 'NL',
    'vat_nr' => 'NL123456789B01',
];

$validator = Validator::make($data, [
    'vat_nr' => 'required|vat_number:country,NL123456789B01',
]);

Validates a changed vat number for a given country

$data = [
    'vat_nr' => 'NL123456789B01',
];

$validator = Validator::make($data, [
    'vat_nr' => 'required|vat_number:NL,NL123456789B01',
]);

Testing

Note, for testing the project needs to be cloned and all dependencies installed first.

$ cd /packages/directory
$ git clone git@github.com:Eventix/eu-vat.git
$ composer install
$ composer test

License

Please see License File.

No liability, implementor is responsible for reviewing code!

Issues

Please open an issue.

Contributing

Please contribute using Github Flow. Fork the project, create a branch, add commits, and open a pull request.

Opportunities

  • Test coverage is not a 100% yet.

Potentials

  • Opportunities for localized country names
  • Opportunities for 3 char country codes
  • Opportunities for country/ies outside the EU

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-08-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固