Skip to content

Commit

Permalink
Merge pull request #7 from skelpo/develop
Browse files Browse the repository at this point in the history
Version 0.3.0
  • Loading branch information
calebkleveter authored Jan 23, 2019
2 parents c4b0d39 + 3583185 commit 7db8317
Show file tree
Hide file tree
Showing 352 changed files with 3,664 additions and 8,497 deletions.
66 changes: 42 additions & 24 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,62 @@
"repositoryURL": "https://github.com/vapor/console.git",
"state": {
"branch": null,
"revision": "5b9796d39f201b3dd06800437abd9d774a455e57",
"version": "3.0.2"
"revision": "d6cf07af59ae63cd95c4b5f98cf1f25627750fd1",
"version": "3.1.0"
}
},
{
"package": "Core",
"repositoryURL": "https://github.com/vapor/core.git",
"state": {
"branch": null,
"revision": "7f56a09995bf3c8df562be456bdcda405d9d0678",
"version": "3.4.1"
"revision": "1794ff138bd669175a2528d27695028d7cb30471",
"version": "3.5.0"
}
},
{
"package": "Countries",
"repositoryURL": "https://github.com/skelpo/Countries.git",
"state": {
"branch": null,
"revision": "95962a77438b5c949f9d812a700cbabbefcf15da",
"version": "0.9.1"
}
},
{
"package": "Crypto",
"repositoryURL": "https://github.com/vapor/crypto.git",
"state": {
"branch": null,
"revision": "4b85405430df1892ee3aa1554bdb477e96cf46ad",
"version": "3.2.0"
"revision": "bce9ac891c9b33fc045deda713e0d976d13b749a",
"version": "3.3.1"
}
},
{
"package": "DatabaseKit",
"repositoryURL": "https://github.com/vapor/database-kit.git",
"state": {
"branch": null,
"revision": "7a01659316b9f033fa2150d5cd5e9d3c3e46c2e3",
"version": "1.3.0"
"revision": "3557894af50914e134803a684b42a9ea6eefaea2",
"version": "1.3.2"
}
},
{
"package": "Failable",
"repositoryURL": "https://github.com/skelpo/Failable.git",
"state": {
"branch": null,
"revision": "34dde6d29991ddfc583d71d81e6ad90aac3fe2e5",
"version": "0.3.0"
}
},
{
"package": "HTTP",
"repositoryURL": "https://github.com/vapor/http.git",
"state": {
"branch": null,
"revision": "8123ea00e9858b369cd168d0303d33e7d3804d19",
"version": "3.0.7"
"revision": "6973bf50dab8dd00e4daf8cb82ca72b33f5db016",
"version": "3.1.6"
}
},
{
Expand Down Expand Up @@ -96,17 +114,17 @@
"repositoryURL": "https://github.com/apple/swift-nio.git",
"state": {
"branch": null,
"revision": "cf08e673dc41dc63d34065234c8fc432e8d334c4",
"version": "1.9.2"
"revision": "03c541a24dd0558c942b15d8464eb75d70a921c4",
"version": "1.12.1"
}
},
{
"package": "swift-nio-ssl",
"repositoryURL": "https://github.com/apple/swift-nio-ssl.git",
"state": {
"branch": null,
"revision": "6617eb0d3afcb12170594968df01ca63afb58ac5",
"version": "1.2.0"
"revision": "0f3999f3e3c359cc74480c292644c3419e44a12f",
"version": "1.4.0"
}
},
{
Expand Down Expand Up @@ -141,44 +159,44 @@
"repositoryURL": "https://github.com/vapor/template-kit.git",
"state": {
"branch": null,
"revision": "db35b1c35aabd0f5db3abca0cfda7becfe9c43e2",
"version": "1.1.0"
"revision": "aff2d6fc65bfd04579b0201b31a8d6720239c1cf",
"version": "1.1.1"
}
},
{
"package": "URLEncodedForm",
"repositoryURL": "https://github.com/vapor/url-encoded-form.git",
"state": {
"branch": null,
"revision": "cbfe7ef6301557d3f2d0807a98165232ae06e1c6",
"version": "1.0.4"
"revision": "932024f363ee5ff59059cf7d67194a1c271d3d0c",
"version": "1.0.5"
}
},
{
"package": "Validation",
"repositoryURL": "https://github.com/vapor/validation.git",
"state": {
"branch": null,
"revision": "156f8adeac3440e868da3757777884efbc6ec0cc",
"version": "2.1.0"
"revision": "4de213cf319b694e4ce19e5339592601d4dd3ff6",
"version": "2.1.1"
}
},
{
"package": "Vapor",
"repositoryURL": "https://github.com/vapor/vapor.git",
"state": {
"branch": null,
"revision": "54632a6c1e7ecd9923c0d00b612de936de1c4745",
"version": "3.0.8"
"revision": "54cbf396147aba77ecb32e7fc75a3d13251551b1",
"version": "3.1.1"
}
},
{
"package": "WebSocket",
"repositoryURL": "https://github.com/vapor/websocket.git",
"state": {
"branch": null,
"revision": "141cb4d3814dc8062cb0b2f43e72801b5dfcf272",
"version": "1.0.1"
"revision": "21eb4773e25a8ff96fe347a31fe106900a69fa6a",
"version": "1.1.1"
}
}
]
Expand Down
13 changes: 10 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ let package = Package(
.library(name: "PayPal", targets: ["PayPal"]),
],
dependencies: [
.package(url: "https://github.com/vapor/vapor.git", from: "3.0.5"),
.package(url: "https://github.com/skelpo/Countries.git", from: "0.9.1"),
.package(url: "https://github.com/skelpo/Failable.git", from: "0.2.0"),
.package(url: "https://github.com/vapor/vapor.git", from: "3.1.0"),
.package(url: "https://github.com/skelpo/JSON.git", from: "0.13.1"),
.package(url: "https://github.com/twostraws/SwiftGD.git", from: "2.2.0")
],
targets: [
.target(name: "PayPal", dependencies: ["Vapor", "JSON"]),
.testTarget(name: "PayPalTests", dependencies: ["PayPal", "Vapor", "JSON", "SwiftGD"]),
.target(name: "PayPal", dependencies: ["Vapor", "JSON", "Failable", "Countries"]),

.target(name: "TestUtilities", dependencies: ["PayPal", "Vapor"]),
.testTarget(name: "ConfigTests", dependencies: ["PayPal", "TestUtilities"]),
.testTarget(name: "ControllerTests", dependencies: ["PayPal", "SwiftGD", "TestUtilities"]),
.testTarget(name: "ModelTests", dependencies: ["PayPal", "TestUtilities"]),
.testTarget(name: "PayPalTests", dependencies: ["PayPal", "Vapor", "JSON"]),
]
)
2 changes: 1 addition & 1 deletion Sources/PayPal/Config/Environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public enum Environment: String, Codable, CaseIterable {

/// The root of the URI used to access the PayPal API
/// based on the current environment.
var domain: String {
public var domain: String {
switch self {
case .sandbox: return "https://api.sandbox.paypal.com"
case .production: return "https://api.paypal.com"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Countries
import Vapor

/// A family relationship of an account owner.
Expand Down
54 changes: 4 additions & 50 deletions Sources/PayPal/Models/Account/MerchantAccount.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Vapor

/// The detaild data of a PayPal merchant account.
public struct MerchantAccount: Content, ValidationSetable, Equatable {
public struct MerchantAccount: Content, Equatable {

/// An array of request-related [HATEOAS links](https://developer.paypal.com/docs/api/overview/#hateoas-links).
public let links: [LinkDescription]?
Expand Down Expand Up @@ -36,11 +36,8 @@ public struct MerchantAccount: Content, ValidationSetable, Equatable {

/// An ID that the partner creates for the merchant account. Note: This information is not available for retrieval.
///
/// This property can be set using the `MerchantAccount.set(_:)` method. This method
/// validatse the new value before assigning it to the property.
///
/// Maximum length: 127.
public private(set) var partnerExternalID: String?
public var partnerExternalID: Optional127String

/// Whether the account allows the merchant to log in. Accounts managed by their parent only are not loginable.
public var loginable: Bool?
Expand Down Expand Up @@ -86,13 +83,13 @@ public struct MerchantAccount: Content, ValidationSetable, Equatable {
relations: [AccountRelation]?,
permissions: [AccountPermission]?,
timezone: Timezone?,
partnerExternalID: String?,
partnerExternalID: Optional127String,
loginable: Bool?,
partnerTaxReporting: Bool?,
signupOptions: SignupOptions?,
errors: [AccountError]?,
financialInstruments: FinancialInstruments?
)throws {
) {
self.links = nil

self.owner = owner
Expand All @@ -110,49 +107,6 @@ public struct MerchantAccount: Content, ValidationSetable, Equatable {
self.signupOptions = signupOptions
self.errors = errors
self.financialInstruments = financialInstruments

try self.set(\.partnerExternalID <~ partnerExternalID)
}

/// See [`Decodable.init(from:)`](https://developer.apple.com/documentation/swift/decodable/2894081-init).
public init(from decoder: Decoder)throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let partnerExternalID = try container.decodeIfPresent(String.self, forKey: .partnerExternalID)

self.partnerExternalID = partnerExternalID
self.links = try container.decodeIfPresent([LinkDescription].self, forKey: .links)
self.owner = try container.decodeIfPresent(BusinessOwner.self, forKey: .owner)
self.business = try container.decodeIfPresent(Business.self, forKey: .business)
self.status = try container.decodeIfPresent(AccountStatus.self, forKey: .status)
self.currency = try container.decodeIfPresent(Currency.self, forKey: .currency)
self.seconderyCurrencies = try container.decodeIfPresent([Currency].self, forKey: .seconderyCurrencies)
self.paymentReceiving = try container.decodeIfPresent(PaymentReceivingPreferences.self, forKey: .paymentReceiving)
self.relations = try container.decodeIfPresent([AccountRelation].self, forKey: .relations)
self.permissions = try container.decodeIfPresent([AccountPermission].self, forKey: .permissions)
self.timezone = try container.decodeIfPresent(Timezone.self, forKey: .timezone)
self.partnerExternalID = try container.decodeIfPresent(String.self, forKey: .partnerExternalID)
self.loginable = try container.decodeIfPresent(Bool.self, forKey: .loginable)
self.partnerTaxReporting = try container.decodeIfPresent(Bool.self, forKey: .partnerTaxReporting)
self.signupOptions = try container.decodeIfPresent(SignupOptions.self, forKey: .signupOptions)
self.errors = try container.decodeIfPresent([AccountError].self, forKey: .errors)
self.financialInstruments = try container.decodeIfPresent(FinancialInstruments.self, forKey: .financialInstruments)

try self.set(\.partnerExternalID <~ partnerExternalID)
}


/// See `ValidationSetable.setterValidations()`.
public func setterValidations() -> SetterValidations<MerchantAccount> {
var validations = SetterValidations(MerchantAccount.self)

validations.set(\.partnerExternalID) { id in
guard let id = id else { return }
guard id.count <= 127 else {
throw PayPalError(status: .badRequest, identifier: "invalidLength", reason: "`partnerExternalID` value length must be 127 or less")
}
}

return validations
}

enum CodingKeys: String, CodingKey {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Vapor

/// The body of the response when a new merchant account is created.
public struct CreatedMerchantResponse: Content, ValidationSetable, Equatable {
public struct CreatedMerchantResponse: Content, Equatable {

/// An array of request-related [HATEOAS links](https://developer.paypal.com/docs/api/overview/#hateoas-links).
public let links: [LinkDescription]?
Expand All @@ -14,56 +14,17 @@ public struct CreatedMerchantResponse: Content, ValidationSetable, Equatable {
/// The partner-specified ID for the account, which was passed in the `partner_merchant_external_id` request parameter.
///
/// Maximum length: 127.
public var partnerExternalID: String?
public var partnerExternalID: Optional127String

/// The merchant authorization code.
public var authCode: String?
public var authCode: Optional127String

/// An array of key-and-value pairs that contain custom data. For example, `aa_token`.
public var custom: [KeyValue]?

/// An array of errors, if any, that occurred during account creation.
public var errors: [AccountError]?


/// See [`Decodable.init(from:)`](https://developer.apple.com/documentation/swift/decodable/2894081-init).
public init(from decoder: Decoder)throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let payer = try container.decodeIfPresent(String.self, forKey: .payer)
let partnerExternalID = try container.decodeIfPresent(String.self, forKey: .partnerExternalID)

self.payer = payer
self.partnerExternalID = partnerExternalID
self.links = try container.decodeIfPresent([LinkDescription].self, forKey: .links)
self.authCode = try container.decodeIfPresent(String.self, forKey: .authCode)
self.custom = try container.decodeIfPresent([KeyValue].self, forKey: .custom)
self.errors = try container.decodeIfPresent([AccountError].self, forKey: .errors)

try self.set(\.payer <~ payer)
try self.set(\.partnerExternalID <~ partnerExternalID)
}


/// See `ValidationSetable.setterValidations()`.
public func setterValidations() -> SetterValidations<CreatedMerchantResponse> {
var validations = SetterValidations(CreatedMerchantResponse.self)

validations.set(\.payer) { payer in
guard let payer = payer else { return }
guard payer.count <= 127 else {
throw PayPalError(status: .badRequest, identifier: "invalidLength", reason: "`payer` value length must be 127 or less")
}
}
validations.set(\.partnerExternalID) { partnerExternalID in
guard let partnerExternalID = partnerExternalID else { return }
guard partnerExternalID.count <= 127 else {
throw PayPalError(status: .badRequest, identifier: "invalidLength", reason: "`partnerExternalID` value length must be 127 or less")
}
}

return validations
}

enum CodingKeys: String, CodingKey {
case links, errors
case payer = "payer_id"
Expand Down
6 changes: 3 additions & 3 deletions Sources/PayPal/Models/Activity/Activity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public struct Activity: Content, Equatable {

/// The date and time when the activity was created,
/// in [Internet date and time format](https://tools.ietf.org/html/rfc3339#section-5.6).
public var timeCreated: String
public var timeCreated: ISO8601Date

/// The type of activity that the object represents.
public var type: ActivityType
Expand Down Expand Up @@ -42,7 +42,7 @@ public struct Activity: Content, Equatable {
/// Creates a new `Activity` instance.
public init(
id: String,
timeCreated: String,
timeCreated: Date,
type: ActivityType,
subtype: SubType?,
status: Status?,
Expand All @@ -54,7 +54,7 @@ public struct Activity: Content, Equatable {
extensions: Extensions?
) {
self.id = id
self.timeCreated = timeCreated
self.timeCreated = ISO8601Date(timeCreated)
self.type = type
self.subtype = subtype
self.status = status
Expand Down
1 change: 1 addition & 0 deletions Sources/PayPal/Models/Address/Address.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Countries
import Vapor

public struct Address: Content, Equatable {
Expand Down
Loading

0 comments on commit 7db8317

Please sign in to comment.