-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
066b2da
commit 622e810
Showing
16 changed files
with
721 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
/*.xcodeproj | ||
xcuserdata/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
.swiftpm/xcode/package.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded</key> | ||
<true/> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "1140" | ||
version = "1.3"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES"> | ||
<BuildActionEntries> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "Vatifier" | ||
BuildableName = "Vatifier" | ||
BlueprintName = "Vatifier" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "NO" | ||
buildForArchiving = "NO" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "VatifierTests" | ||
BuildableName = "VatifierTests" | ||
BlueprintName = "VatifierTests" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
</BuildActionEntries> | ||
</BuildAction> | ||
<TestAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
shouldUseLaunchSchemeArgsEnv = "YES"> | ||
<Testables> | ||
<TestableReference | ||
skipped = "NO"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "VatifierTests" | ||
BuildableName = "VatifierTests" | ||
BlueprintName = "VatifierTests" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</TestableReference> | ||
</Testables> | ||
</TestAction> | ||
<LaunchAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
launchStyle = "0" | ||
useCustomWorkingDirectory = "NO" | ||
ignoresPersistentStateOnLaunch = "NO" | ||
debugDocumentVersioning = "YES" | ||
debugServiceExtension = "internal" | ||
allowLocationSimulation = "YES"> | ||
</LaunchAction> | ||
<ProfileAction | ||
buildConfiguration = "Release" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
savedToolIdentifier = "" | ||
useCustomWorkingDirectory = "NO" | ||
debugDocumentVersioning = "YES"> | ||
<MacroExpansion> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "Vatifier" | ||
BuildableName = "Vatifier" | ||
BlueprintName = "Vatifier" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</MacroExpansion> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
{ | ||
"object": { | ||
"pins": [ | ||
{ | ||
"package": "async-http-client", | ||
"repositoryURL": "https://github.com/swift-server/async-http-client.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "037b70291941fe43de668066eb6fb802c5e181d2", | ||
"version": "1.1.1" | ||
} | ||
}, | ||
{ | ||
"package": "async-kit", | ||
"repositoryURL": "https://github.com/vapor/async-kit.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "635a259c57ba682b60bebf005c52a92cfafc73f5", | ||
"version": "1.1.0" | ||
} | ||
}, | ||
{ | ||
"package": "console-kit", | ||
"repositoryURL": "https://github.com/vapor/console-kit.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "7a97a5ea7fefe61cf2c943242113125b0f396a98", | ||
"version": "4.1.0" | ||
} | ||
}, | ||
{ | ||
"package": "routing-kit", | ||
"repositoryURL": "https://github.com/vapor/routing-kit.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "e7f2d5bd36dc65a9edb303541cb678515a7fece3", | ||
"version": "4.1.0" | ||
} | ||
}, | ||
{ | ||
"package": "swift-backtrace", | ||
"repositoryURL": "https://github.com/swift-server/swift-backtrace.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "f2fd8c4845a123419c348e0bc4b3839c414077d5", | ||
"version": "1.2.0" | ||
} | ||
}, | ||
{ | ||
"package": "swift-crypto", | ||
"repositoryURL": "https://github.com/apple/swift-crypto.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "d67ac68d09a95443303e9d6e37b34e7ba101d5f1", | ||
"version": "1.0.1" | ||
} | ||
}, | ||
{ | ||
"package": "swift-log", | ||
"repositoryURL": "https://github.com/apple/swift-log.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "74d7b91ceebc85daf387ebb206003f78813f71aa", | ||
"version": "1.2.0" | ||
} | ||
}, | ||
{ | ||
"package": "swift-metrics", | ||
"repositoryURL": "https://github.com/apple/swift-metrics.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "708b960b4605abb20bc55d65abf6bad607252200", | ||
"version": "2.0.0" | ||
} | ||
}, | ||
{ | ||
"package": "swift-nio", | ||
"repositoryURL": "https://github.com/apple/swift-nio.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "c5fa0b456524cd73dc3ddbb263d4f46c20b86ca3", | ||
"version": "2.17.0" | ||
} | ||
}, | ||
{ | ||
"package": "swift-nio-extras", | ||
"repositoryURL": "https://github.com/apple/swift-nio-extras.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "7cd24c0efcf9700033f671b6a8eaa64a77dd0b72", | ||
"version": "1.5.1" | ||
} | ||
}, | ||
{ | ||
"package": "swift-nio-http2", | ||
"repositoryURL": "https://github.com/apple/swift-nio-http2.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "c8f952dbc37fe60def17eb15e2c90787ce6ee78a", | ||
"version": "1.12.1" | ||
} | ||
}, | ||
{ | ||
"package": "swift-nio-ssl", | ||
"repositoryURL": "https://github.com/apple/swift-nio-ssl.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "10e0e17dd47b594c3d864a063f343d716e33e5c1", | ||
"version": "2.7.3" | ||
} | ||
}, | ||
{ | ||
"package": "SwiftyXMLParser", | ||
"repositoryURL": "https://github.com/yahoojapan/SwiftyXMLParser.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "9d82653e535a13a518b411934c0a5c0c84406c22", | ||
"version": "5.2.0" | ||
} | ||
}, | ||
{ | ||
"package": "vapor", | ||
"repositoryURL": "https://github.com/vapor/vapor.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "6dfdb3445308c40280bf1c071fe14c1c92f98a0d", | ||
"version": "4.7.1" | ||
} | ||
}, | ||
{ | ||
"package": "websocket-kit", | ||
"repositoryURL": "https://github.com/vapor/websocket-kit.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "021edd1ca55451ad15b3e84da6b4064e4b877b34", | ||
"version": "2.1.0" | ||
} | ||
} | ||
] | ||
}, | ||
"version": 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// swift-tools-version:5.2 | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "vatifier", | ||
platforms: [ | ||
.macOS(.v10_15) | ||
], | ||
products: [ | ||
.library( | ||
name: "Vatifier", | ||
targets: ["Vatifier"]), | ||
], | ||
dependencies: [ | ||
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"), | ||
.package(url: "https://github.com/yahoojapan/SwiftyXMLParser.git", from: "5.2.0") | ||
], | ||
targets: [ | ||
.target( | ||
name: "Vatifier", | ||
dependencies: [ | ||
.product(name: "Vapor", package: "vapor"), | ||
.product(name: "SwiftyXMLParser", package: "SwiftyXMLParser") | ||
]), | ||
.testTarget( | ||
name: "VatifierTests", | ||
dependencies: ["Vatifier", .product(name: "XCTVapor", package: "vapor")]), | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Vatifier | ||
|
||
![Swift](http://img.shields.io/badge/swift-5.2-brightgreen.svg) | ||
![Vapor](http://img.shields.io/badge/vapor-4.0-brightgreen.svg) | ||
|
||
### Vatifier is a Vapor helper for verifying VAT numbers via the [VIES service](https://ec.europa.eu/taxation_customs/vies/) | ||
|
||
## Usage | ||
Add the following line to your `Package.swift` | ||
~~~~swift | ||
.package(url: "https://github.com/vapor-community/vatifier.git", from: "1.0.0") | ||
|
||
.product(name: "Vatifier", package: "vatifier") | ||
~~~~ | ||
|
||
Add this line to your `configure.swift` file: | ||
~~~~swift | ||
import Vatifier | ||
|
||
app.vatifier.use(.VIES) | ||
~~~~ | ||
|
||
You can now verify VAT numbers from `Application` or `Request` | ||
~~~~swift | ||
app.vatifier.verify("47458714", country: "DK") | ||
req.vatifier.verify("47458714", country: "DK") | ||
~~~~ | ||
|
||
If the API request was successfull you will have a `VATVerificationResponse` which contains an `isValid` boolean and optional `name` and `address` properties. If the API request failed, the future will be in an error state and a `VIESError` will be returned. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import Vapor | ||
|
||
public protocol VatifierClient { | ||
func hopped(to eventLoop: EventLoop) -> VatifierClient | ||
func verify(_ vatNumber: String, country: Country) -> EventLoopFuture<VATVerificationResponse> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
public enum Country: String, ExpressibleByStringLiteral { | ||
case austria = "AT" | ||
case belgium = "BE" | ||
case bulgaria = "BG" | ||
case croatia = "HR" | ||
case cyprus = "CY" | ||
case czechRepublic = "CZ" | ||
case denmark = "DK" | ||
case estonia = "EE" | ||
case finland = "FI" | ||
case france = "FR" | ||
case germany = "DE" | ||
case hungary = "HU" | ||
case ireland = "IE" | ||
case italy = "IT" | ||
case latvia = "LV" | ||
case lithuania = "LT" | ||
case luxembourg = "LU" | ||
case malta = "MT" | ||
case netherlands = "NL" | ||
case poland = "PL" | ||
case portugal = "PT" | ||
case romania = "RO" | ||
case slovakia = "SK" | ||
case slovenia = "SI" | ||
case spain = "ES" | ||
case sweden = "SE" | ||
case unitedKingdom = "GB" | ||
case invalid | ||
|
||
public init(stringLiteral value: String) { | ||
if let country = Country(rawValue: value) { | ||
self = country | ||
} else { | ||
self = .invalid | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import Vapor | ||
|
||
public struct VATVerificationResponse: Content { | ||
public let isValid: Bool | ||
public let name: String? | ||
public let address: String? | ||
} |
Oops, something went wrong.