Skip to content
This repository has been archived by the owner on Mar 30, 2023. It is now read-only.

Commit

Permalink
Merge pull request #7 from elitalon/taxes
Browse files Browse the repository at this point in the history
Adds support for calculating taxes
  • Loading branch information
Carlos Hernández Medina committed Nov 24, 2015
2 parents e271d13 + eff5497 commit be2b726
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 4 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@ All notable changes to this project will be documented in this file. `Quaderno`

#### 0.x Releases
- `0.0.x` Releases - [0.0.1](#001) | [0.0.2](#002)
- `0.x.x` Releases - [0.1.0](#010) | [0.2.0](#020) | [0.3.0](#030) | [0.4.0](#040)
- `0.x.x` Releases - [0.1.0](#010) | [0.2.0](#020) | [0.3.0](#030) | [0.4.0](#040) | [0.5.0](#050)

---

## [0.5.0](https://github.com/quaderno/quaderno-swift/releases/tag/0.5.0)

Unreleased.

#### Added

- A `Tax` resource for calculating taxes.


## [0.4.0](https://github.com/quaderno/quaderno-swift/releases/tag/0.4.0)

Unreleased.
Expand Down
4 changes: 2 additions & 2 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- Alamofire (3.1.2)
- Alamofire (3.1.3)
- OHHTTPStubs (4.6.0):
- OHHTTPStubs/Default (= 4.6.0)
- OHHTTPStubs/Core (4.6.0)
Expand All @@ -22,7 +22,7 @@ DEPENDENCIES:
- OHHTTPStubs/Swift (~> 4.0)

SPEC CHECKSUMS:
Alamofire: 7c16ca65f3c7e681fd925fd7f2dec7747ff96855
Alamofire: 9f93b56389e48def9220dd57d1f44b1927229a5a
OHHTTPStubs: cb1aefbbeb4de4e741644455d4b945538e5248a2

COCOAPODS: 0.39.0
2 changes: 1 addition & 1 deletion Quaderno.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Quaderno'
s.version = '0.4.0'
s.version = '0.5.0'
s.license = 'MIT'
s.summary = 'Swift wrapper for the Quaderno API.'
s.homepage = 'https://www.quaderno.io'
Expand Down
8 changes: 8 additions & 0 deletions Quaderno.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
31082B6C1C04B99900719A6A /* Tax.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31082B6B1C04B99900719A6A /* Tax.swift */; };
31082B6E1C04E83100719A6A /* TaxTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31082B6D1C04E83100719A6A /* TaxTests.swift */; };
310F1F211BF36FE1001C9335 /* Deliverable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 310F1F201BF36FE1001C9335 /* Deliverable.swift */; };
310F1F231BF36FED001C9335 /* Invoice.swift in Sources */ = {isa = PBXBuildFile; fileRef = 310F1F221BF36FED001C9335 /* Invoice.swift */; };
3110B8E11BFB7A1C005B0893 /* Authorization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3110B8E01BFB7A1C005B0893 /* Authorization.swift */; };
Expand Down Expand Up @@ -64,6 +66,8 @@
/* Begin PBXFileReference section */
0B20ABB1A21628A3D0539641 /* Pods-QuadernoTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-QuadernoTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-QuadernoTests/Pods-QuadernoTests.debug.xcconfig"; sourceTree = "<group>"; };
252028C5EDD0749F182145E2 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = "<group>"; };
31082B6B1C04B99900719A6A /* Tax.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Tax.swift; sourceTree = "<group>"; };
31082B6D1C04E83100719A6A /* TaxTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TaxTests.swift; sourceTree = "<group>"; };
310F1F201BF36FE1001C9335 /* Deliverable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Deliverable.swift; sourceTree = "<group>"; };
310F1F221BF36FED001C9335 /* Invoice.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Invoice.swift; sourceTree = "<group>"; };
3110B8E01BFB7A1C005B0893 /* Authorization.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Authorization.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -255,6 +259,7 @@
31938A901BF504BA00147F0C /* Item.swift */,
31C2E1861BECA7A5005104BB /* Ping.swift */,
317C08381BF5EF200080F561 /* Recurring.swift */,
31082B6B1C04B99900719A6A /* Tax.swift */,
317C083C1BF5F38F0080F561 /* Webhook.swift */,
);
name = Resources;
Expand All @@ -272,6 +277,7 @@
31938A8D1BF5047B00147F0C /* ItemTests.swift */,
31C2E18A1BECACCB005104BB /* PingTests.swift */,
317C083A1BF5EF750080F561 /* RecurringTests.swift */,
31082B6D1C04E83100719A6A /* TaxTests.swift */,
317C083E1BF5F3D40080F561 /* WebhookTests.swift */,
);
name = Resources;
Expand Down Expand Up @@ -517,6 +523,7 @@
317C08311BF5EB930080F561 /* Estimate.swift in Sources */,
3110B8E61BFB7D72005B0893 /* AccountCredentials.swift in Sources */,
3110B8E11BFB7A1C005B0893 /* Authorization.swift in Sources */,
31082B6C1C04B99900719A6A /* Tax.swift in Sources */,
3139A16B1BF14D54003D6D66 /* CRUD.swift in Sources */,
310F1F231BF36FED001C9335 /* Invoice.swift in Sources */,
);
Expand All @@ -543,6 +550,7 @@
31938A8E1BF5047B00147F0C /* ItemTests.swift in Sources */,
3117FB321BE693B20096D05A /* ConnectionEntitlementsTests.swift in Sources */,
317C08371BF5EE870080F561 /* ExpenseTests.swift in Sources */,
31082B6E1C04E83100719A6A /* TaxTests.swift in Sources */,
3117FB2E1BE675970096D05A /* OHHTTPStubs+Quaderno.swift in Sources */,
317E9C491BF257CA00A1C331 /* ContactTests.swift in Sources */,
);
Expand Down
98 changes: 98 additions & 0 deletions Source/Tax.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
//
// Tax.swift
//
// Copyright (c) 2015 Recrea (http://recreahq.com/)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import Alamofire


/**
A resource for calculating taxes.
- seealso: [Taxes](https://github.com/quaderno/quaderno-api/blob/master/sections/taxes.md).
*/
public struct Tax: Resource {

// MARK: Resource

public static let name = "taxes"

// MARK: Transaction Types

/**
Represents a type of transaction involved in tax calculation.
- `Service`: A transaction.
- `Book`: A transaction.
- `Standard`: A transaction.
*/
public enum Transaction: String {
case Service = "eservice"
case Book = "ebook"
case Standard = "standard"
}

// MARK: Calculating Taxes

struct CalculateRequest: Request {

// MARK: Request

var method: Alamofire.Method {
return .GET
}

func uri(baseURL baseURL: String) -> String {
return (baseURL + Tax.name + "/calculate").appendJSONSuffix()
}

let parameters: RequestParameters?

}

/**
Creates a request for calculating the taxes to apply to a given customer.
- parameter country: A two-letter string representing a country code as defined by [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2).
- parameter postalCode: The postal code of a customer.
- parameter vatNumber: The VAT number of a customer.
- parameter transactionType: The type of transaction. The default value is `Service`.
- returns: A request for calculating the taxes.
*/
public static func calculate(country country: String, postalCode: String? = nil, vatNumber: String? = nil, transactionType: Transaction = .Service) -> Request {
var parameters: RequestParameters = [
"country": country,
"transaction_type": transactionType.rawValue,
]

if postalCode != nil {
parameters["postal_code"] = postalCode
}

if vatNumber != nil {
parameters["vat_number"] = vatNumber
}

return CalculateRequest(parameters: parameters)
}

}
72 changes: 72 additions & 0 deletions Tests/TaxTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//
// TaxTests.swift
//
// Copyright (c) 2015 Recrea (http://recreahq.com/)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

@testable import Quaderno

import XCTest
import Alamofire


class TaxTests: XCTestCase {

func testThatCalculatingTaxesReturnsAValidRequest() {
let request = Tax.calculate(country: "ES")

XCTAssertEqual(request.method, Alamofire.Method.GET)
XCTAssertNotNil(request.parameters)

let baseURL = "https://quadernoapp.com/api/v1/"
let uri = request.uri(baseURL: baseURL)
XCTAssertEqual(uri, "https://quadernoapp.com/api/v1/taxes/calculate.json")
XCTAssertNotNil(NSURL(string: uri))
}

func testThatDefaultValuesForCalculatingTaxesAreValid() {
let request = Tax.calculate(country: "ES")

guard let parameters = request.parameters else {
XCTFail("Unexpected nil parameters for request")
return
}

XCTAssertEqual(parameters["country"] as? String, "ES")
XCTAssertNil(parameters["postal_code"])
XCTAssertNil(parameters["vat_number"])
XCTAssertEqual(parameters["transaction_type"] as? String, Tax.Transaction.Service.rawValue)
}

func testThatGivenParametersForCalculatingTaxesAreHonoured() {
let request = Tax.calculate(country: "ES", transactionType: .Standard, postalCode: "1234", vatNumber: "4321")

guard let parameters = request.parameters else {
XCTFail("Unexpected nil parameters for request")
return
}

XCTAssertEqual(parameters["country"] as? String, "ES")
XCTAssertEqual(parameters["postal_code"] as? String, "1234")
XCTAssertEqual(parameters["vat_number"] as? String, "4321")
XCTAssertEqual(parameters["transaction_type"] as? String, Tax.Transaction.Standard.rawValue)
}

}

0 comments on commit be2b726

Please sign in to comment.