From f59446b726ef0cd9ad372a5d2114e146a9f3f44e Mon Sep 17 00:00:00 2001 From: Andrew Edwards Date: Wed, 21 Mar 2018 19:17:45 -0400 Subject: [PATCH 01/17] Updated with newer transaction types. --- .../Models/Balance/BalanceTransactionType.swift | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Sources/Stripe/Models/Balance/BalanceTransactionType.swift b/Sources/Stripe/Models/Balance/BalanceTransactionType.swift index 8058f62..bc20c1d 100644 --- a/Sources/Stripe/Models/Balance/BalanceTransactionType.swift +++ b/Sources/Stripe/Models/Balance/BalanceTransactionType.swift @@ -14,13 +14,19 @@ import Foundation */ public enum BalanceTransactionType: String, Codable { - case charge - case refund case adjustment case applicationFee = "application_fee" case applicationFeeRefund = "application_fee_refund" - case transfer + case charge case payment + case paymentFailureRefund = "payment_failure_refund" + case paymentRefund = "payment_refund" + case refund + case transfer + case transferRefund = "transfer_refund" case payout + case payoutCancel = "payout_cancel" case payoutFailure = "payout_failure" + case validation + case stripeFee = "stripe_fee" } From cb9c82f8ddc6390fc372e73f8b8f89b4d4b41b51 Mon Sep 17 00:00:00 2001 From: Andrew Edwards Date: Wed, 21 Mar 2018 19:18:41 -0400 Subject: [PATCH 02/17] Updated plans to support latest API changes. --- Sources/Stripe/API/Routes/PlanRoutes.swift | 26 +++++++++++----------- Sources/Stripe/Models/Plans/Plans.swift | 8 +++---- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Sources/Stripe/API/Routes/PlanRoutes.swift b/Sources/Stripe/API/Routes/PlanRoutes.swift index e4d4cd3..b41390e 100644 --- a/Sources/Stripe/API/Routes/PlanRoutes.swift +++ b/Sources/Stripe/API/Routes/PlanRoutes.swift @@ -13,9 +13,9 @@ public protocol PlanRoutes { associatedtype DO: DeletedObject associatedtype L: List - func create(id: String?, currency: StripeCurrency, interval: StripePlanInterval, name: String, amount: Int?, intervalCount: Int?, metadata: [String: String]?, statementDescriptor: String?) throws -> Future

+ func create(id: String?, currency: StripeCurrency, interval: StripePlanInterval, product: String, amount: Int?, intervalCount: Int?, metadata: [String: String]?, nickname: String?) throws -> Future

func retrieve(plan: String) throws -> Future

- func update(plan: String, metadata: [String: String]?, name: String?, statementDescriptor: String?) throws -> Future

+ func update(plan: String, metadata: [String: String]?, nickname: String?, product: String?) throws -> Future

func delete(plan: String) throws -> Future func listAll(filter: [String: Any]?) throws -> Future } @@ -32,16 +32,16 @@ public struct StripePlanRoutes: PlanRoutes { public func create(id: String? = nil, currency: StripeCurrency, interval: StripePlanInterval, - name: String, + product: String, amount: Int? = nil, intervalCount: Int? = nil, metadata: [String : String]? = nil, - statementDescriptor: String? = nil) throws -> Future { + nickname: String? = nil) throws -> Future { var body: [String: Any] = [:] body["currency"] = currency.rawValue body["interval"] = interval.rawValue - body["name"] = name + body["product"] = product if let id = id { body["id"] = id @@ -59,8 +59,8 @@ public struct StripePlanRoutes: PlanRoutes { metadata.forEach { body["metadata[\($0)]"] = $1 } } - if let statementDescriptor = statementDescriptor { - body["statement_descriptor"] = statementDescriptor + if let nickname = nickname { + body["nickname"] = nickname } return try request.send(method: .post, path: StripeAPIEndpoint.plans.endpoint, body: body.queryParameters) @@ -76,20 +76,20 @@ public struct StripePlanRoutes: PlanRoutes { /// [Learn More →](https://stripe.com/docs/api/curl#update_plan) public func update(plan: String, metadata: [String : String]? = nil, - name: String? = nil, - statementDescriptor: String? = nil) throws -> Future { + nickname: String? = nil, + product: String? = nil) throws -> Future { var body: [String: Any] = [:] if let metadata = metadata { metadata.forEach { body["metadata[\($0)]"] = $1 } } - if let name = name { - body["name"] = name + if let nickname = nickname { + body["nickname"] = nickname } - if let statementDescriptor = statementDescriptor { - body["statement_descriptor"] = statementDescriptor + if let product = product { + body["product"] = product } return try request.send(method: .post, path: StripeAPIEndpoint.plan(plan).endpoint, body: body.queryParameters) diff --git a/Sources/Stripe/Models/Plans/Plans.swift b/Sources/Stripe/Models/Plans/Plans.swift index 63fd703..e551c96 100644 --- a/Sources/Stripe/Models/Plans/Plans.swift +++ b/Sources/Stripe/Models/Plans/Plans.swift @@ -23,8 +23,8 @@ public protocol Plan { var intervalCount: Int? { get } var livemode: Bool? { get } var metadata: [String: String]? { get } - var name: String? { get } - var statementDescriptor: String? { get } + var nickname: String? { get } + var product: String? { get } var trialPeriodDays: Int? { get } } @@ -38,7 +38,7 @@ public struct StripePlan: Plan, StripeModel { public var intervalCount: Int? public var livemode: Bool? public var metadata: [String: String]? - public var name: String? - public var statementDescriptor: String? + public var nickname: String? + public var product: String? public var trialPeriodDays: Int? } From c8b1f1b30bbbb3061af37dbe768e7998ef4b0bfc Mon Sep 17 00:00:00 2001 From: Andrew Edwards Date: Wed, 21 Mar 2018 19:19:35 -0400 Subject: [PATCH 03/17] Updated products to latest API changes. --- Sources/Stripe/API/Routes/ProductRoutes.swift | 17 +++++++++++++++-- Sources/Stripe/Models/Products/Products.swift | 4 ++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Sources/Stripe/API/Routes/ProductRoutes.swift b/Sources/Stripe/API/Routes/ProductRoutes.swift index 697ba49..f177911 100644 --- a/Sources/Stripe/API/Routes/ProductRoutes.swift +++ b/Sources/Stripe/API/Routes/ProductRoutes.swift @@ -14,9 +14,9 @@ public protocol ProductRoutes { associatedtype L: List associatedtype PD: PackageDimensions - func create(id: String?, name: String, active: Bool?, attributes: [String]?, caption: String?, deactivateOn: [String]?, description: String?, images: [String]?, metadata: [String: String]?, packageDimensions: PD?, shippable: Bool?, url: String?) throws -> Future + func create(id: String?, name: String, type: String, active: Bool?, attributes: [String]?, caption: String?, deactivateOn: [String]?, description: String?, images: [String]?, metadata: [String: String]?, packageDimensions: PD?, shippable: Bool?, statementDescriptor: String?, url: String?) throws -> Future func retrieve(id: String) throws -> Future - func update(product: String, active: Bool?, attributes: [String]?, caption: String?, deactivateOn: [String]?, description: String?, images: [String]?, metadata: [String: String]?, name: String?, packageDimensions: PD?, shippable: Bool?, url: String?) throws -> Future + func update(product: String, active: Bool?, attributes: [String]?, caption: String?, deactivateOn: [String]?, description: String?, images: [String]?, metadata: [String: String]?, name: String?, packageDimensions: PD?, shippable: Bool?, statementDescriptor: String?, url: String?) throws -> Future func listAll(filter: [String: Any]?) throws -> Future func delete(id: String) throws -> Future } @@ -32,6 +32,7 @@ public struct StripeProductRoutes: ProductRoutes { /// [Learn More →](https://stripe.com/docs/api/curl#create_product) public func create(id: String? = nil, name: String, + type: String, active: Bool? = nil, attributes: [String]? = nil, caption: String? = nil, @@ -41,10 +42,13 @@ public struct StripeProductRoutes: ProductRoutes { metadata: [String : String]? = nil, packageDimensions: StripePackageDimensions? = nil, shippable: Bool? = nil, + statementDescriptor: String? = nil, url: String? = nil) throws -> Future { var body: [String: Any] = [:] body["name"] = name + + body["type"] = type if let id = id { body["id"] = id @@ -91,6 +95,10 @@ public struct StripeProductRoutes: ProductRoutes { if let shippable = shippable { body["shippable"] = shippable } + + if let statementDescriptor = statementDescriptor { + body["statement_descriptor"] = statementDescriptor + } if let url = url { body["url"] = url @@ -118,6 +126,7 @@ public struct StripeProductRoutes: ProductRoutes { name: String? = nil, packageDimensions: StripePackageDimensions? = nil, shippable: Bool? = nil, + statementDescriptor: String? = nil, url: String? = nil) throws -> Future { var body: [String: Any] = [:] @@ -167,6 +176,10 @@ public struct StripeProductRoutes: ProductRoutes { body["shippable"] = shippable } + if let statementDescriptor = statementDescriptor { + body["statement_descriptor"] = statementDescriptor + } + if let url = url { body["url"] = url } diff --git a/Sources/Stripe/Models/Products/Products.swift b/Sources/Stripe/Models/Products/Products.swift index fc9a26d..823f6b4 100644 --- a/Sources/Stripe/Models/Products/Products.swift +++ b/Sources/Stripe/Models/Products/Products.swift @@ -32,6 +32,8 @@ public protocol Product { var packageDimensions: PD? { get } var shippable: Bool? { get } var skus: L? { get } + var statementDescriptor: String? { get } + var type: String? { get } var updated: Date? { get } var url: String? { get } } @@ -52,6 +54,8 @@ public struct StripeProduct: Product, StripeModel { public var packageDimensions: StripePackageDimensions? public var shippable: Bool? public var skus: SKUList? + public var statementDescriptor: String? + public var type: String? public var updated: Date? public var url: String? } From faf06cea9ec48929108ba53b22a398f1c3ed1991 Mon Sep 17 00:00:00 2001 From: Andrew Edwards Date: Wed, 21 Mar 2018 19:24:55 -0400 Subject: [PATCH 04/17] Updated product tests. --- Tests/StripeTests/ProductTests.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tests/StripeTests/ProductTests.swift b/Tests/StripeTests/ProductTests.swift index a3636e6..38220b2 100644 --- a/Tests/StripeTests/ProductTests.swift +++ b/Tests/StripeTests/ProductTests.swift @@ -73,6 +73,7 @@ class ProductTests: XCTestCase { "url": "/v1/skus?product=prod_BosWT9EsdzgjPn&active=true" }, "updated": 1511422435, + "type": "good", "url": "https://api.stripe.com/" } """ @@ -106,6 +107,7 @@ class ProductTests: XCTestCase { XCTAssertEqual(product.shippable, false) XCTAssertEqual(product.updated, Date(timeIntervalSince1970: 1511422435)) XCTAssertEqual(product.url, "https://api.stripe.com/") + XCTAssertEqual(product.type, "good") XCTAssertEqual(product.skus?.object, "list") XCTAssertEqual(product.skus?.hasMore, false) XCTAssertEqual(product.skus?.totalCount, 1) From b0e893e42ad77b4d3a9047a715315d7864e9955e Mon Sep 17 00:00:00 2001 From: Andrew Edwards Date: Wed, 21 Mar 2018 19:27:41 -0400 Subject: [PATCH 05/17] Updates for Subscription API changes. --- .../API/Routes/SubscriptionRoutes.swift | 32 +++++++++++++++---- .../Models/Subscriptions/Subscription.swift | 2 ++ Tests/StripeTests/SubscriptionTests.swift | 2 ++ 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/Sources/Stripe/API/Routes/SubscriptionRoutes.swift b/Sources/Stripe/API/Routes/SubscriptionRoutes.swift index 0127187..bb45cb7 100644 --- a/Sources/Stripe/API/Routes/SubscriptionRoutes.swift +++ b/Sources/Stripe/API/Routes/SubscriptionRoutes.swift @@ -8,15 +8,15 @@ import Vapor import Foundation - +// TODO: Support sources being different objects public protocol SubscriptionRoutes { associatedtype SB: Subscription associatedtype L: List associatedtype DO: DeletedObject - func create(customer: String, applicationFeePercent: Decimal?, billing: String?, coupon: String?, daysUntilDue: Int?, items: [String: Any]?, metadata: [String: String]?, source: Any?, taxPercent: Decimal?, trialEnd: Date?, trialPeriodDays: Int?) throws -> Future + func create(customer: String, applicationFeePercent: Decimal?, billing: String?, billingCycleAnchor: Date?, coupon: String?, daysUntilDue: Int?, items: [String: Any]?, metadata: [String: String]?, source: Any?, taxPercent: Decimal?, trialEnd: Any?, trialPeriodDays: Int?) throws -> Future func retrieve(id: String) throws -> Future - func update(subscription: String, applicationFeePercent: Decimal?, billing: String?, coupon: String?, daysUntilDue: Int?, items: [String: Any]?, metadata: [String: String]?, prorate: Bool?, prorationDate: Date?, source: Any?, taxPercent: Decimal?, trialEnd: Date?) throws -> Future + func update(subscription: String, applicationFeePercent: Decimal?, billing: String?, billingCycleAnchor: String?, coupon: String?, daysUntilDue: Int?, items: [String: Any]?, metadata: [String: String]?, prorate: Bool?, prorationDate: Date?, source: Any?, taxPercent: Decimal?, trialEnd: Any?) throws -> Future func cancel(subscription: String, atPeriodEnd: Bool?) throws -> Future func listAll(filter: [String: Any]?) throws -> Future func deleteDiscount(subscription: String) throws -> Future @@ -34,13 +34,14 @@ public struct StripeSubscriptionRoutes: SubscriptionRoutes { public func create(customer: String, applicationFeePercent: Decimal? = nil, billing: String? = nil, + billingCycleAnchor: Date? = nil, coupon: String? = nil, daysUntilDue: Int? = nil, items: [String : Any]? = nil, metadata: [String : String]? = nil, source: Any? = nil, taxPercent: Decimal? = nil, - trialEnd: Date? = nil, + trialEnd: Any? = nil, trialPeriodDays: Int? = nil) throws -> Future { var body: [String: Any] = [:] @@ -54,6 +55,10 @@ public struct StripeSubscriptionRoutes: SubscriptionRoutes { body["billing"] = billing } + if let billingCycleAnchor = billingCycleAnchor { + body["billing_cycle_anchor"] = Int(billingCycleAnchor.timeIntervalSince1970) + } + if let coupon = coupon { body["coupon"] = coupon } @@ -82,10 +87,14 @@ public struct StripeSubscriptionRoutes: SubscriptionRoutes { body["tax_percent"] = taxPercent } - if let trialEnd = trialEnd { + if let trialEnd = trialEnd as? Date { body["trial_end"] = Int(trialEnd.timeIntervalSince1970) } + if let trialEnd = trialEnd as? String { + body["trial_end"] = trialEnd + } + if let trialPeriodDays = trialPeriodDays { body["trial_period_days"] = trialPeriodDays } @@ -104,6 +113,7 @@ public struct StripeSubscriptionRoutes: SubscriptionRoutes { public func update(subscription: String, applicationFeePercent: Decimal? = nil, billing: String? = nil, + billingCycleAnchor: String? = nil, coupon: String? = nil, daysUntilDue: Int? = nil, items: [String : Any]? = nil, @@ -112,7 +122,7 @@ public struct StripeSubscriptionRoutes: SubscriptionRoutes { prorationDate: Date? = nil, source: Any? = nil, taxPercent: Decimal? = nil, - trialEnd: Date? = nil) throws -> Future { + trialEnd: Any? = nil) throws -> Future { var body: [String: Any] = [:] if let applicationFeePercent = applicationFeePercent { @@ -123,6 +133,10 @@ public struct StripeSubscriptionRoutes: SubscriptionRoutes { body["billing"] = billing } + if let billingCycleAnchor = billingCycleAnchor { + body["billing_cycle_anchor"] = billingCycleAnchor + } + if let coupon = coupon { body["coupon"] = coupon } @@ -159,10 +173,14 @@ public struct StripeSubscriptionRoutes: SubscriptionRoutes { body["tax_percent"] = taxPercent } - if let trialEnd = trialEnd { + if let trialEnd = trialEnd as? Date { body["trial_end"] = Int(trialEnd.timeIntervalSince1970) } + if let trialEnd = trialEnd as? String { + body["trial_end"] = trialEnd + } + return try request.send(method: .post, path: StripeAPIEndpoint.subscriptions(subscription).endpoint, body: body.queryParameters) } diff --git a/Sources/Stripe/Models/Subscriptions/Subscription.swift b/Sources/Stripe/Models/Subscriptions/Subscription.swift index ec19aa6..4772bb4 100644 --- a/Sources/Stripe/Models/Subscriptions/Subscription.swift +++ b/Sources/Stripe/Models/Subscriptions/Subscription.swift @@ -22,6 +22,7 @@ public protocol Subscription { var object: String? { get } var applicationFeePercent: Decimal? { get } var billing: String? { get } + var billingCycleAnchor: Date? { get } var cancelAtPeriodEnd: Bool? { get } var canceledAt: Date? { get } var created: Date? { get } @@ -48,6 +49,7 @@ public struct StripeSubscription: Subscription, StripeModel { public var object: String? public var applicationFeePercent: Decimal? public var billing: String? + public var billingCycleAnchor: Date? public var cancelAtPeriodEnd: Bool? public var canceledAt: Date? public var created: Date? diff --git a/Tests/StripeTests/SubscriptionTests.swift b/Tests/StripeTests/SubscriptionTests.swift index a1ad8bc..e812cae 100644 --- a/Tests/StripeTests/SubscriptionTests.swift +++ b/Tests/StripeTests/SubscriptionTests.swift @@ -98,6 +98,7 @@ class SubscriptionTests: XCTestCase { XCTAssertEqual(sub.object, "subscription") XCTAssertEqual(sub.applicationFeePercent, 12.7) XCTAssertEqual(sub.billing, "charge_automatically") + XCTAssertEqual(sub.billingCycleAnchor, Date(timeIntervalSince1970: 1490398710)) XCTAssertEqual(sub.cancelAtPeriodEnd, false) XCTAssertEqual(sub.canceledAt, Date(timeIntervalSince1970: 1489793914)) XCTAssertEqual(sub.created, Date(timeIntervalSince1970: 1489793910)) @@ -129,6 +130,7 @@ class SubscriptionTests: XCTestCase { "object": "subscription", "application_fee_percent": 12.7, "billing": "charge_automatically", + "billing_cycle_anchor": 1490398710, "cancel_at_period_end": false, "canceled_at": 1489793914, "created": 1489793910, From 765e4ec3899eeb65710ba9ef0aef786b2a6f314c Mon Sep 17 00:00:00 2001 From: Andrew Edwards Date: Wed, 21 Mar 2018 19:28:07 -0400 Subject: [PATCH 06/17] Updated tests for Plan API changes. --- Tests/StripeTests/SubscriptionTests.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Tests/StripeTests/SubscriptionTests.swift b/Tests/StripeTests/SubscriptionTests.swift index e812cae..9df0576 100644 --- a/Tests/StripeTests/SubscriptionTests.swift +++ b/Tests/StripeTests/SubscriptionTests.swift @@ -75,8 +75,8 @@ class SubscriptionTests: XCTestCase { XCTAssertEqual(sub.items?.data?[0].plan?.intervalCount, 1) XCTAssertEqual(sub.items?.data?[0].plan?.livemode, false) XCTAssertEqual(sub.items?.data?[0].plan?.metadata?["hello"], "world") - XCTAssertEqual(sub.items?.data?[0].plan?.name, "Foo") - XCTAssertEqual(sub.items?.data?[0].plan?.statementDescriptor, "FOO") + XCTAssertEqual(sub.items?.data?[0].plan?.nickname, "Foo") + XCTAssertEqual(sub.items?.data?[0].plan?.product, "prod_1234") XCTAssertEqual(sub.items?.data?[0].plan?.trialPeriodDays, 3) // These cover the Plan object @@ -90,8 +90,8 @@ class SubscriptionTests: XCTestCase { XCTAssertEqual(sub.plan?.intervalCount, 1) XCTAssertEqual(sub.plan?.livemode, false) XCTAssertEqual(sub.plan?.metadata?["hello"], "world") - XCTAssertEqual(sub.plan?.name, "Foo") - XCTAssertEqual(sub.plan?.statementDescriptor, "PLAN FOO") + XCTAssertEqual(sub.plan?.nickname, "Foo") + XCTAssertEqual(sub.plan?.product, "prod_1234") XCTAssertEqual(sub.plan?.trialPeriodDays, 14) XCTAssertEqual(sub.id, "sub_AJ6s2Iy65K3RxN") @@ -186,8 +186,8 @@ class SubscriptionTests: XCTestCase { "metadata": { "hello": "world" }, - "name": "Foo", - "statement_descriptor": "FOO", + "nickname": "Foo", + "product": "prod_1234", "trial_period_days": 3 }, "quantity": 1, @@ -214,8 +214,8 @@ class SubscriptionTests: XCTestCase { "metadata": { "hello": "world" }, - "name": "Foo", - "statement_descriptor": "PLAN FOO", + "nickname": "Foo", + "product": "prod_1234", "trial_period_days": 14 }, "quantity": 1, From 5a327b30fe221d436781fddd05bdb7ad2bebe9a9 Mon Sep 17 00:00:00 2001 From: Andrew Edwards Date: Wed, 21 Mar 2018 19:28:58 -0400 Subject: [PATCH 07/17] Removed very bad synchronous code. --- Sources/Stripe/API/StripeRequest.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Stripe/API/StripeRequest.swift b/Sources/Stripe/API/StripeRequest.swift index a467421..ded2c18 100644 --- a/Sources/Stripe/API/StripeRequest.swift +++ b/Sources/Stripe/API/StripeRequest.swift @@ -25,10 +25,10 @@ public extension StripeRequest { decoder.dateDecodingStrategy = .secondsSince1970 decoder.keyDecodingStrategy = .convertFromSnakeCase - guard response.status == .ok else - { - let error = try decoder.decode(StripeAPIError.self, from: response.body).requireCompleted() - throw StripeError.apiError(error) + guard response.status == .ok else { + return try decoder.decode(StripeAPIError.self, from: response.body).map(to: SM.self) { error in + throw StripeError.apiError(error) + } } return try decoder.decode(SM.self, from: response.body) From 1e85c48d5101953d22ed21f0e367d86991c4e48f Mon Sep 17 00:00:00 2001 From: Andrew Edwards Date: Wed, 21 Mar 2018 19:29:20 -0400 Subject: [PATCH 08/17] Upgraded to latest API version. --- Sources/Stripe/API/StripeRequest.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Stripe/API/StripeRequest.swift b/Sources/Stripe/API/StripeRequest.swift index ded2c18..4088065 100644 --- a/Sources/Stripe/API/StripeRequest.swift +++ b/Sources/Stripe/API/StripeRequest.swift @@ -38,7 +38,7 @@ public extension StripeRequest { public class StripeAPIRequest: StripeRequest { private let httpClient: Client private let apiKey: String - private let StripeDefaultHeaders: HTTPHeaders = ["Stripe-Version": "2017-08-15", .contentType: "application/x-www-form-urlencoded"] + private let StripeDefaultHeaders: HTTPHeaders = ["Stripe-Version": "2018-02-28", .contentType: "application/x-www-form-urlencoded"] init(httpClient: Client, apiKey: String) { self.httpClient = httpClient From befaddd9b38d9ce62858245f02bc9d10ecf2cf90 Mon Sep 17 00:00:00 2001 From: Andrew Edwards Date: Wed, 21 Mar 2018 19:29:54 -0400 Subject: [PATCH 09/17] Added Error support. --- Sources/Stripe/Errors/StripeAPIError.swift | 25 +-- Sources/Stripe/Errors/StripeError.swift | 233 +++++++++------------ Tests/StripeTests/ErrorTests.swift | 49 +++++ 3 files changed, 154 insertions(+), 153 deletions(-) create mode 100644 Tests/StripeTests/ErrorTests.swift diff --git a/Sources/Stripe/Errors/StripeAPIError.swift b/Sources/Stripe/Errors/StripeAPIError.swift index 1b4ea37..e72613c 100644 --- a/Sources/Stripe/Errors/StripeAPIError.swift +++ b/Sources/Stripe/Errors/StripeAPIError.swift @@ -6,30 +6,25 @@ // import Foundation +/** + Error object + https://stripe.com/docs/api#errors + */ public protocol APIError { - //var type: StripeAPIErrorType { get } + var type: StripeAPIErrorType? { get } var charge: String? { get } var message: String? { get } - //var code: StripeAPICardErrorType { get } - //var declineCode: StripeAPIDeclineCode { get } + var code: StripeAPICardErrorType? { get } + var declineCode: StripeAPIDeclineCode? { get } var param: String? { get } } public struct StripeAPIError: APIError, StripeModel { - //public var type: StripeAPIErrorType + public var type: StripeAPIErrorType? public var charge: String? public var message: String? - //public var code: StripeAPICardErrorType? - //public var declineCode: StripeAPIDeclineCode? + public var code: StripeAPICardErrorType? + public var declineCode: StripeAPIDeclineCode? public var param: String? - - enum CodingKeys: String, CodingKey { - // case type - case charge - case message - // case code - // case declineCode = "decline_code" - case param - } } diff --git a/Sources/Stripe/Errors/StripeError.swift b/Sources/Stripe/Errors/StripeError.swift index f541283..d6e1e27 100644 --- a/Sources/Stripe/Errors/StripeError.swift +++ b/Sources/Stripe/Errors/StripeError.swift @@ -22,142 +22,99 @@ public enum StripeError: Error { } } } -// -//public enum StripeAPIErrorType: String, Codable { -// case apiConnectionError(String) -// case apiError(String) -// case authenticationError(String) -// case cardError(String) -// case invalidRequestError(String) -// case rateLimitError(String) -// -// enum CodingKeys: String, CodingKey { -// case apiConnectionError = "api_connection_error" -// case apiError = "api_error" -// case authenticationError = "authentication_error" -// case cardError = "card_error" -// case invalidRequestError = "invalid_request_error" -// case rateLimitError = "rate_limit_error" -// } -//} -// -//public enum StripeAPICardErrorType: String, Codable { -// case invalidNumber(String) -// case invalidExpiryMonth(String) -// case invalidExpiryYear(String) -// case invalidCVC(String) -// case invalidSwipeData(String) -// case incorrectNumber(String) -// case expiredCard(String) -// case incorrectCVC(String) -// case incorrectZip(String) -// case cardDeclined(String) -// case missing(String) -// case processingError(String) -// -// enum CodingKeys: String, CodingKey { -// case invalidNumber = "invalid_number" -// case invalidExpiryMonth = "invalid_expiry_month" -// case invalidExpiryYear = "invalid_expiry_year" -// case invalidCVC = "invalid_cvc" -// case invalidSwipeData = "invalid_swipe_data" -// case incorrectNumber = "incorrect_number" -// case expiredCard = "expired_card" -// case incorrectCVC = "incorrect_cvc" -// case incorrectZip = "incorrect_zip" -// case cardDeclined = "card_declined" -// case missing -// case processingError = "processing_error" -// } -//} -// -//public enum StripeAPIDeclineCode: String, Codable { -// case approveWithId(String) -// case callIssuer(String) -// case cardNotSupported(String) -// case cardVelocityExceeded(String) -// case currencyNotSupported(String) -// case doNotHonor(String) -// case doNotTryAgain(String) -// case duplicateTransaction(String) -// case expiredCard(String) -// case fradulent(String) -// case genericDecline(String) -// case incorrectNumber(String) -// case incorrectCVC(String) -// case incorrectPin(String) -// case incorrectZip(String) -// case insufficientFunds(String) -// case invalidAccount(String) -// case invalidAmount(String) -// case invalidCVC(String) -// case invalidExpiryYear(String) -// case invalidNumber(String) -// case invalidPin(String) -// case issuerNotAvailable(String) -// case lostCard(String) -// case newAccountInformationAvailable(String) -// case noActionTaken(String) -// case notPermitted(String) -// case pickupCard(String) -// case pinTryExceeded(String) -// case processingError(String) -// case reenterTransaction(String) -// case restrictedCard(String) -// case revocationOfAllAuthorizations(String) -// case revocationOfAuthorization(String) -// case securityViolation(String) -// case serviceNotAllowed(String) -// case stolenCard(String) -// case stopPaymentOrder(String) -// case testmodeDecline(String) -// case transactionNotAllowed(String) -// case tryAgainLater(String) -// case withdrawalCountLimitExceeded(String) -// -// enum CodingKeys: String, CodingKey { -// case approveWithId = "approve_with_id" -// case callIssuer = "call_issuer" -// case cardNotSupported = "card_not_supported" -// case cardVelocityExceeded = "card_velocity_exceeded" -// case currencyNotSupported = "currency_not_supported" -// case doNotHonor = "do_not_honor" -// case doNotTryAgain = "do_not_try_again" -// case duplicateTransaction = "duplicate_transaction" -// case expiredCard = "expired_card" -// case fradulent -// case genericDecline = "generic_decline" -// case incorrectNumber = "incorrect_number" -// case incorrectCVC = "incorrect_cvc" -// case incorrectPin = "incorrect_pin" -// case incorrectZip = "incorrect_zip" -// case insufficientFunds = "insufficient_funds" -// case invalidAccount = "invalid_account" -// case invalidAmount = "invalid_amount" -// case invalidCVC = "invalid_cvc" -// case invalidExpiryYear = "invalid_expiry_year" -// case invalidNumber = "invalid_number" -// case invalidPin = "invalid_pin" -// case issuerNotAvailable = "issuer_not_available" -// case lostCard = "lost_card" -// case newAccountInformationAvailable = "new_account_information_available" -// case noActionTaken = "no_action_taken" -// case notPermitted = "not_permitted" -// case pickupCard = "pickup_card" -// case pinTryExceeded = "pin_try_exceeded" -// case processingError = "processing_error" -// case reenterTransaction = "reenter_transaction" -// case restrictedCard = "restricted_card" -// case revocationOfAllAuthorizations = "revocation_of_all_authorizations" -// case revocationOfAuthorization = "revocation_of_authorization" -// case securityViolation = "security_violation" -// case serviceNotAllowed = "service_not_allowed" -// case stolenCard = "stolen_card" -// case stopPaymentOrder = "stop_payment_order" -// case testmodeDecline = "testmode_decline" -// case transactionNotAllowed = "transaction_not_allowed" -// case tryAgainLater = "try_again_later" -// case withdrawalCountLimitExceeded = "withdrawal_count_limit_exceeded" -// } -//} +// https://stripe.com/docs/api#errors-type +public enum StripeAPIErrorType: String, StripeModel { + case apiConnectionError = "api_connection_error" + case apiError = "api_error" + case authenticationError = "authentication_error" + case cardError = "card_error" + case invalidRequestError = "invalid_request_error" + case rateLimitError = "rate_limit_error" + + public init(from decoder: Decoder) throws { + let value = try decoder.singleValueContainer() + guard let possible = StripeAPIErrorType(rawValue: try value.decode(String.self)) else { + throw DecodingError.typeMismatch(StripeAPIErrorType.self, DecodingError.Context(codingPath: [], debugDescription: "Unknown error type returned from stripe.")) + } + self = possible + } +} + +// https://stripe.com/docs/api#errors-code +public enum StripeAPICardErrorType: String, StripeModel { + case invalidNumber = "invalid_number" + case invalidExpiryMonth = "invalid_expiry_month" + case invalidExpiryYear = "invalid_expiry_year" + case invalidCVC = "invalid_cvc" + case invalidSwipeData = "invalid_swipe_data" + case incorrectNumber = "incorrect_number" + case expiredCard = "expired_card" + case incorrectCVC = "incorrect_cvc" + case incorrectZip = "incorrect_zip" + case cardDeclined = "card_declined" + case missing + case processingError = "processing_error" + + public init(from decoder: Decoder) throws { + let value = try decoder.singleValueContainer() + guard let possible = StripeAPICardErrorType(rawValue: try value.decode(String.self)) else { + throw DecodingError.typeMismatch(StripeAPICardErrorType.self, DecodingError.Context(codingPath: [], debugDescription: "Unknown card error returned from stripe.")) + } + self = possible + } +} + +// https://stripe.com/docs/api#errors-decline-code +public enum StripeAPIDeclineCode: String, StripeModel { + case approveWithId = "approve_with_id" + case callIssuer = "call_issuer" + case cardNotSupported = "card_not_supported" + case cardVelocityExceeded = "card_velocity_exceeded" + case currencyNotSupported = "currency_not_supported" + case doNotHonor = "do_not_honor" + case doNotTryAgain = "do_not_try_again" + case duplicateTransaction = "duplicate_transaction" + case expiredCard = "expired_card" + case fradulent + case genericDecline = "generic_decline" + case incorrectNumber = "incorrect_number" + case incorrectCVC = "incorrect_cvc" + case incorrectPin = "incorrect_pin" + case incorrectZip = "incorrect_zip" + case insufficientFunds = "insufficient_funds" + case invalidAccount = "invalid_account" + case invalidAmount = "invalid_amount" + case invalidCVC = "invalid_cvc" + case invalidExpiryYear = "invalid_expiry_year" + case invalidNumber = "invalid_number" + case invalidPin = "invalid_pin" + case issuerNotAvailable = "issuer_not_available" + case lostCard = "lost_card" + case newAccountInformationAvailable = "new_account_information_available" + case noActionTaken = "no_action_taken" + case notPermitted = "not_permitted" + case pickupCard = "pickup_card" + case pinTryExceeded = "pin_try_exceeded" + case processingError = "processing_error" + case reenterTransaction = "reenter_transaction" + case restrictedCard = "restricted_card" + case revocationOfAllAuthorizations = "revocation_of_all_authorizations" + case revocationOfAuthorization = "revocation_of_authorization" + case securityViolation = "security_violation" + case serviceNotAllowed = "service_not_allowed" + case stolenCard = "stolen_card" + case stopPaymentOrder = "stop_payment_order" + case testmodeDecline = "testmode_decline" + case transactionNotAllowed = "transaction_not_allowed" + case tryAgainLater = "try_again_later" + case withdrawalCountLimitExceeded = "withdrawal_count_limit_exceeded" + + public init(from decoder: Decoder) throws { + let value = try decoder.singleValueContainer() + guard let possible = StripeAPIDeclineCode(rawValue: try value.decode(String.self)) else { + throw DecodingError.typeMismatch(StripeAPIDeclineCode.self, DecodingError.Context(codingPath: [], debugDescription: "Unknown decline code returned from stripe.")) + } + self = possible + } +} diff --git a/Tests/StripeTests/ErrorTests.swift b/Tests/StripeTests/ErrorTests.swift new file mode 100644 index 0000000..4f6cad2 --- /dev/null +++ b/Tests/StripeTests/ErrorTests.swift @@ -0,0 +1,49 @@ +// +// ErrorTests.swift +// StripeTests +// +// Created by Andrew Edwards on 2/27/18. +// + +import XCTest +@testable import Stripe +@testable import Vapor + +class ErrorTests: XCTestCase { + let errorString = """ +{ + "type": "card_error", + "charge": "ch_12345", + "message": "Sorry kiddo", + "code": "invalid_swipe_data", + "decline_code": "stolen_card", + "param": "card_number" +} +""" + + func testErrorParsedProperly() throws { + do { + let decoder = JSONDecoder() + decoder.dateDecodingStrategy = .secondsSince1970 + decoder.keyDecodingStrategy = .convertFromSnakeCase + + let body = HTTPBody(string: errorString) + let futureError = try decoder.decode(StripeAPIError.self, from: body) + + futureError.do { (stripeError) in + XCTAssertEqual(stripeError.type, .cardError) + XCTAssertEqual(stripeError.charge, "ch_12345") + XCTAssertEqual(stripeError.message, "Sorry kiddo") + XCTAssertEqual(stripeError.code, .invalidSwipeData) + XCTAssertEqual(stripeError.declineCode, .stolenCard) + XCTAssertEqual(stripeError.param, "card_number") + + }.catch { (error) in + XCTFail("\(error.localizedDescription)") + } + } + catch { + XCTFail("\(error.localizedDescription)") + } + } +} From 3ce5c085f100d09733d67ae1bae407b981a47168 Mon Sep 17 00:00:00 2001 From: Andrew Edwards Date: Wed, 21 Mar 2018 19:30:17 -0400 Subject: [PATCH 10/17] Updated LinuxMain. --- Tests/LinuxMain.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift index aaa4a71..7e123f8 100644 --- a/Tests/LinuxMain.swift +++ b/Tests/LinuxMain.swift @@ -41,6 +41,12 @@ static var allTests = [ ] } +extension ErrorTests { +static var allTests = [ + ("testErrorParsedProperly", testErrorParsedProperly), +] +} + extension InvoiceTests { static var allTests = [ ("testInvoiceParsedProperly", testInvoiceParsedProperly), @@ -108,6 +114,7 @@ XCTMain([ testCase(CustomerTests.allTests), testCase(DisputeTests.allTests), testCase(EphemeralKeyTests.allTests), + testCase(ErrorTests.allTests), testCase(InvoiceTests.allTests), testCase(OrderTests.allTests), testCase(ProductTests.allTests), From 52e8d5b984d52cff18d2b668bff5e9da4ec8b927 Mon Sep 17 00:00:00 2001 From: Andrew Edwards Date: Wed, 21 Mar 2018 19:31:01 -0400 Subject: [PATCH 11/17] Updated and cleaned up README. --- README.md | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 561b621..b1f86b2 100644 --- a/README.md +++ b/README.md @@ -47,25 +47,53 @@ futureCharge.do({ (charge) in And you can always check the documentation to see the required paramaters for specific API calls. +## Linux compatibility +Currently the project won't compile for linux. +You can track this issue [here](https://bugs.swift.org/browse/SR-7180) + ## Whats Implemented -* [x] Balance Fetching + +### Core Resources +* [x] Balance * [x] Charges * [x] Customers -* [x] Coupons -* [x] Plans +* [x] Disputes +* [ ] Events +* [ ] File Uploads +* [ ] Payouts * [x] Refunds * [x] Tokens +--- +### Payment Methods +* [x] Bank Accounts +* [x] Cards * [x] Sources +--- +### Subscriptions +* [x] Coupons +* [x] Discounts +* [x] Invoices +* [x] Invoice Items +* [x] Plans * [x] Subscriptions -* [x] Connect account +* [x] Subscription items +--- +### Connect +* [x] Account +* [ ] Application Fee Refunds +* [ ] Application Fees +* [ ] Country Specs +* [x] External Accounts +* [ ] Transfers +* [ ] Transfer Reversals +--- +### Relay * [x] Orders * [x] Order Items * [x] Products -* [x] Disputes -* [x] Invoices -* [x] Invoice Items +* [x] Returns +* [x] SKUs * [x] Ephemeral Keys -* [] Events API [stripe_home]: http://stripe.com "Stripe" [stripe_api]: https://stripe.com/docs/api "Stripe API Endpoints" From cd88f7c08bf3deb848fa9ae605ec71b138a4934b Mon Sep 17 00:00:00 2001 From: Andrew Edwards Date: Wed, 21 Mar 2018 19:33:39 -0400 Subject: [PATCH 12/17] Updated to use latest release candidates. --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 4735abf..43e25c6 100644 --- a/Package.swift +++ b/Package.swift @@ -7,7 +7,7 @@ let package = Package( .library(name: "Stripe", targets: ["Stripe"]) ], dependencies: [ - .package(url: "https://github.com/vapor/vapor.git", from: "3.0.0-beta"), + .package(url: "https://github.com/vapor/vapor.git", from: "3.0.0-rc"), ], targets: [ .target(name: "Stripe", dependencies: ["Vapor"]), From b4e28cface266b0ff85b8ff9a54a5a0bc05c91b7 Mon Sep 17 00:00:00 2001 From: Andrew Edwards Date: Thu, 22 Mar 2018 14:00:28 -0400 Subject: [PATCH 13/17] Updated tests to use EventLoop --- Tests/StripeTests/AccountTests.swift | 2 +- Tests/StripeTests/BalanceTests.swift | 4 ++-- Tests/StripeTests/ChargeTests.swift | 2 +- Tests/StripeTests/CustomerTests.swift | 2 +- Tests/StripeTests/DisputeTests.swift | 2 +- Tests/StripeTests/EphemeralKeyTests.swift | 2 +- Tests/StripeTests/ErrorTests.swift | 2 +- Tests/StripeTests/InvoiceTests.swift | 6 +++--- Tests/StripeTests/OrderTests.swift | 2 +- Tests/StripeTests/ProductTests.swift | 2 +- Tests/StripeTests/RefundTests.swift | 2 +- Tests/StripeTests/SKUTests.swift | 2 +- Tests/StripeTests/SourceTests.swift | 20 ++++++++++---------- Tests/StripeTests/SubscriptionTests.swift | 2 +- Tests/StripeTests/TokenTests.swift | 4 ++-- 15 files changed, 28 insertions(+), 28 deletions(-) diff --git a/Tests/StripeTests/AccountTests.swift b/Tests/StripeTests/AccountTests.swift index a7d7d55..73fce87 100644 --- a/Tests/StripeTests/AccountTests.swift +++ b/Tests/StripeTests/AccountTests.swift @@ -171,7 +171,7 @@ class AccountTests: XCTestCase { decoder.keyDecodingStrategy = .convertFromSnakeCase let body = HTTPBody(string: accountString) - let futureAccount = try decoder.decode(StripeConnectAccount.self, from: body) + let futureAccount = try decoder.decode(StripeConnectAccount.self, from: body, on: EmbeddedEventLoop()) futureAccount.do { (account) in XCTAssertEqual(account.id, "acct_1032D82eZvKYlo2C") diff --git a/Tests/StripeTests/BalanceTests.swift b/Tests/StripeTests/BalanceTests.swift index ad6fdb9..0b942e1 100644 --- a/Tests/StripeTests/BalanceTests.swift +++ b/Tests/StripeTests/BalanceTests.swift @@ -72,7 +72,7 @@ class BalanceTests: XCTestCase { decoder.keyDecodingStrategy = .convertFromSnakeCase let body = HTTPBody(string: balanceString) - let futureBalance = try decoder.decode(StripeBalance.self, from: body) + let futureBalance = try decoder.decode(StripeBalance.self, from: body, on: EmbeddedEventLoop()) futureBalance.do { (balance) in XCTAssertEqual(balance.object, "balance") @@ -143,7 +143,7 @@ class BalanceTests: XCTestCase { decoder.keyDecodingStrategy = .convertFromSnakeCase let body = HTTPBody(string: balanceTransactionString) - let futureBalanceTransaction = try decoder.decode(StripeBalanceTransactionItem.self, from: body) + let futureBalanceTransaction = try decoder.decode(StripeBalanceTransactionItem.self, from: body, on: EmbeddedEventLoop()) futureBalanceTransaction.do { (balancetransaction) in XCTAssertEqual(balancetransaction.id, "txn_19XJJ02eZvKYlo2ClwuJ1rbA") diff --git a/Tests/StripeTests/ChargeTests.swift b/Tests/StripeTests/ChargeTests.swift index 2e24ae5..d85f4fa 100644 --- a/Tests/StripeTests/ChargeTests.swift +++ b/Tests/StripeTests/ChargeTests.swift @@ -66,7 +66,7 @@ class ChargeTests: XCTestCase { decoder.keyDecodingStrategy = .convertFromSnakeCase let body = HTTPBody(string: chargeString) - let futureCharge = try decoder.decode(StripeCharge.self, from: body) + let futureCharge = try decoder.decode(StripeCharge.self, from: body, on: EmbeddedEventLoop()) futureCharge.do { (charge) in XCTAssertEqual(charge.id, "ch_1BrbM42eZvKYlo2CIu7qiNPF") diff --git a/Tests/StripeTests/CustomerTests.swift b/Tests/StripeTests/CustomerTests.swift index 8215d4b..018ab23 100644 --- a/Tests/StripeTests/CustomerTests.swift +++ b/Tests/StripeTests/CustomerTests.swift @@ -39,7 +39,7 @@ class CustomerTests: XCTestCase { decoder.keyDecodingStrategy = .convertFromSnakeCase let body = HTTPBody(string: customerString) - let futureCustomer = try decoder.decode(StripeCustomer.self, from: body) + let futureCustomer = try decoder.decode(StripeCustomer.self, from: body, on: EmbeddedEventLoop()) futureCustomer.do { (customer) in XCTAssertEqual(customer.id, "cus_CG7FIUH6U4JTkB") diff --git a/Tests/StripeTests/DisputeTests.swift b/Tests/StripeTests/DisputeTests.swift index 1e06527..2312183 100644 --- a/Tests/StripeTests/DisputeTests.swift +++ b/Tests/StripeTests/DisputeTests.swift @@ -70,7 +70,7 @@ class DisputeTests: XCTestCase { decoder.keyDecodingStrategy = .convertFromSnakeCase let body = HTTPBody(string: disputeString) - let futureDispute = try decoder.decode(StripeDispute.self, from: body) + let futureDispute = try decoder.decode(StripeDispute.self, from: body, on: EmbeddedEventLoop()) futureDispute.do { (dispute) in XCTAssertEqual(dispute.amount, 1000) diff --git a/Tests/StripeTests/EphemeralKeyTests.swift b/Tests/StripeTests/EphemeralKeyTests.swift index 351480d..317312d 100644 --- a/Tests/StripeTests/EphemeralKeyTests.swift +++ b/Tests/StripeTests/EphemeralKeyTests.swift @@ -31,7 +31,7 @@ class EphemeralKeyTests: XCTestCase { decoder.keyDecodingStrategy = .convertFromSnakeCase let body = HTTPBody(string: emphkeyString) - let futureKey = try decoder.decode(StripeEphemeralKey.self, from: body) + let futureKey = try decoder.decode(StripeEphemeralKey.self, from: body, on: EmbeddedEventLoop()) futureKey.do { (key) in XCTAssertEqual(key.id, "eph_123456") diff --git a/Tests/StripeTests/ErrorTests.swift b/Tests/StripeTests/ErrorTests.swift index 4f6cad2..27ca1ef 100644 --- a/Tests/StripeTests/ErrorTests.swift +++ b/Tests/StripeTests/ErrorTests.swift @@ -28,7 +28,7 @@ class ErrorTests: XCTestCase { decoder.keyDecodingStrategy = .convertFromSnakeCase let body = HTTPBody(string: errorString) - let futureError = try decoder.decode(StripeAPIError.self, from: body) + let futureError = try decoder.decode(StripeAPIError.self, from: body, on: EmbeddedEventLoop()) futureError.do { (stripeError) in XCTAssertEqual(stripeError.type, .cardError) diff --git a/Tests/StripeTests/InvoiceTests.swift b/Tests/StripeTests/InvoiceTests.swift index f86cc12..34d3882 100644 --- a/Tests/StripeTests/InvoiceTests.swift +++ b/Tests/StripeTests/InvoiceTests.swift @@ -69,7 +69,7 @@ class InvoiceTests: XCTestCase { decoder.keyDecodingStrategy = .convertFromSnakeCase let body = HTTPBody(string: invoiceString) - let futureInvoice = try decoder.decode(StripeInvoice.self, from: body) + let futureInvoice = try decoder.decode(StripeInvoice.self, from: body, on: EmbeddedEventLoop()) futureInvoice.do { (invoice) in XCTAssertEqual(invoice.id, "in_1BoJ2NKrZ43eBVAbQ8jb0Xfj") @@ -152,7 +152,7 @@ class InvoiceTests: XCTestCase { decoder.keyDecodingStrategy = .convertFromSnakeCase let body = HTTPBody(string: invoiceItemString) - let futureInvoiceItem = try decoder.decode(StripeInvoiceItem.self, from: body) + let futureInvoiceItem = try decoder.decode(StripeInvoiceItem.self, from: body, on: EmbeddedEventLoop()) futureInvoiceItem.do { (invoiceItem) in XCTAssertEqual(invoiceItem.id, "ii_1BtydB2eZvKYlo2CzeKs27EC") @@ -177,4 +177,4 @@ class InvoiceTests: XCTestCase { XCTFail("\(error.localizedDescription)") } } -} \ No newline at end of file +} diff --git a/Tests/StripeTests/OrderTests.swift b/Tests/StripeTests/OrderTests.swift index 13f50fe..320e0ac 100644 --- a/Tests/StripeTests/OrderTests.swift +++ b/Tests/StripeTests/OrderTests.swift @@ -93,7 +93,7 @@ class OrderTests: XCTestCase { decoder.keyDecodingStrategy = .convertFromSnakeCase let body = HTTPBody(string: orderString) - let futureOrder = try decoder.decode(StripeOrder.self, from: body) + let futureOrder = try decoder.decode(StripeOrder.self, from: body, on: EmbeddedEventLoop()) futureOrder.do { (order) in XCTAssertEqual(order.id, "or_1BoJ2NKrZ43eBVAbFf4SZyvD") diff --git a/Tests/StripeTests/ProductTests.swift b/Tests/StripeTests/ProductTests.swift index 38220b2..1849f25 100644 --- a/Tests/StripeTests/ProductTests.swift +++ b/Tests/StripeTests/ProductTests.swift @@ -85,7 +85,7 @@ class ProductTests: XCTestCase { decoder.keyDecodingStrategy = .convertFromSnakeCase let body = HTTPBody(string: productString) - let futureProduct = try decoder.decode(StripeProduct.self, from: body) + let futureProduct = try decoder.decode(StripeProduct.self, from: body, on: EmbeddedEventLoop()) futureProduct.do { (product) in XCTAssertEqual(product.id, "prod_BosWT9EsdzgjPn") diff --git a/Tests/StripeTests/RefundTests.swift b/Tests/StripeTests/RefundTests.swift index aef3005..63e6be0 100644 --- a/Tests/StripeTests/RefundTests.swift +++ b/Tests/StripeTests/RefundTests.swift @@ -36,7 +36,7 @@ class RefundTests: XCTestCase { decoder.keyDecodingStrategy = .convertFromSnakeCase let body = HTTPBody(string: refundString) - let futureRefund = try decoder.decode(StripeRefund.self, from: body) + let futureRefund = try decoder.decode(StripeRefund.self, from: body, on: EmbeddedEventLoop()) futureRefund.do { (refund) in XCTAssertEqual(refund.id, "re_1BrXqE2eZvKYlo2Cfa7NO6GF") diff --git a/Tests/StripeTests/SKUTests.swift b/Tests/StripeTests/SKUTests.swift index 657d026..0532361 100644 --- a/Tests/StripeTests/SKUTests.swift +++ b/Tests/StripeTests/SKUTests.swift @@ -50,7 +50,7 @@ class SKUTests: XCTestCase { decoder.keyDecodingStrategy = .convertFromSnakeCase let body = HTTPBody(string: skuString) - let futureSku = try decoder.decode(StripeSKU.self, from: body) + let futureSku = try decoder.decode(StripeSKU.self, from: body, on: EmbeddedEventLoop()) futureSku.do { (sku) in XCTAssertEqual(sku.id, "sku_CG2zw7j7H8NEQq") diff --git a/Tests/StripeTests/SourceTests.swift b/Tests/StripeTests/SourceTests.swift index c639b0c..a1ab648 100644 --- a/Tests/StripeTests/SourceTests.swift +++ b/Tests/StripeTests/SourceTests.swift @@ -85,7 +85,7 @@ class SourceTests: XCTestCase { func testCardSourceParsedProperly() throws { do { let body = HTTPBody(string: cardSourceString) - let source = try decoder.decode(StripeSource.self, from: body) + let source = try decoder.decode(StripeSource.self, from: body, on: EmbeddedEventLoop()) source.do { (source) in XCTAssertNil(source.threeDSecure) @@ -194,7 +194,7 @@ class SourceTests: XCTestCase { func testThreeDSecureSourceParsedProperly() throws { do { let body = HTTPBody(string: threeDSecureSourceString) - let source = try decoder.decode(StripeSource.self, from: body) + let source = try decoder.decode(StripeSource.self, from: body, on: EmbeddedEventLoop()) source.do { (source) in XCTAssertNil(source.card) @@ -258,7 +258,7 @@ class SourceTests: XCTestCase { func testSepaDebitSourceParsedProperly() throws { do { let body = HTTPBody(string: sepaDebitSourceString) - let source = try decoder.decode(StripeSource.self, from: body) + let source = try decoder.decode(StripeSource.self, from: body, on: EmbeddedEventLoop()) source.do { (source) in XCTAssertNil(source.card) @@ -327,7 +327,7 @@ class SourceTests: XCTestCase { func testAlipaySourceParsedProperly() throws { do { let body = HTTPBody(string: alipaySourceString) - let source = try decoder.decode(StripeSource.self, from: body) + let source = try decoder.decode(StripeSource.self, from: body, on: EmbeddedEventLoop()) source.do { (source) in XCTAssertNil(source.card) @@ -395,7 +395,7 @@ class SourceTests: XCTestCase { func testGiropaySourceParsedProperly() throws { do { let body = HTTPBody(string: giroPaySourceString) - let source = try decoder.decode(StripeSource.self, from: body) + let source = try decoder.decode(StripeSource.self, from: body, on: EmbeddedEventLoop()) source.do { (source) in XCTAssertNil(source.card) @@ -465,7 +465,7 @@ class SourceTests: XCTestCase { func testIdealSourceParsedProperly() throws { do { let body = HTTPBody(string: idealSourceString) - let source = try decoder.decode(StripeSource.self, from: body) + let source = try decoder.decode(StripeSource.self, from: body, on: EmbeddedEventLoop()) source.do { (source) in XCTAssertNil(source.card) @@ -532,7 +532,7 @@ class SourceTests: XCTestCase { func testP24SourceParsedProperly() throws { do { let body = HTTPBody(string: p24SourceString) - let source = try decoder.decode(StripeSource.self, from: body) + let source = try decoder.decode(StripeSource.self, from: body, on: EmbeddedEventLoop()) source.do { (source) in XCTAssertNil(source.card) @@ -602,7 +602,7 @@ class SourceTests: XCTestCase { func testSofortSourceParsedProperly() throws { do { let body = HTTPBody(string: sofortSourceString) - let source = try decoder.decode(StripeSource.self, from: body) + let source = try decoder.decode(StripeSource.self, from: body, on: EmbeddedEventLoop()) source.do { (source) in XCTAssertNil(source.card) @@ -676,7 +676,7 @@ class SourceTests: XCTestCase { func testBancontactSourceParsedProperly() throws { do { let body = HTTPBody(string: bancontactSourceString) - let source = try decoder.decode(StripeSource.self, from: body) + let source = try decoder.decode(StripeSource.self, from: body, on: EmbeddedEventLoop()) source.do { (source) in XCTAssertNil(source.card) @@ -746,7 +746,7 @@ class SourceTests: XCTestCase { func testACHSourceParsedProperly() throws { do { let body = HTTPBody(string: achSourceString) - let source = try decoder.decode(StripeSource.self, from: body) + let source = try decoder.decode(StripeSource.self, from: body, on: EmbeddedEventLoop()) source.do { (source) in XCTAssertNil(source.card) diff --git a/Tests/StripeTests/SubscriptionTests.swift b/Tests/StripeTests/SubscriptionTests.swift index 9df0576..2c19fed 100644 --- a/Tests/StripeTests/SubscriptionTests.swift +++ b/Tests/StripeTests/SubscriptionTests.swift @@ -18,7 +18,7 @@ class SubscriptionTests: XCTestCase { decoder.keyDecodingStrategy = .convertFromSnakeCase let body = HTTPBody(string: subscriptionString) - let subscription = try decoder.decode(StripeSubscription.self, from: body) + let subscription = try decoder.decode(StripeSubscription.self, from: body, on: EmbeddedEventLoop()) subscription.do({ (sub) in diff --git a/Tests/StripeTests/TokenTests.swift b/Tests/StripeTests/TokenTests.swift index 4a375aa..e9b390a 100644 --- a/Tests/StripeTests/TokenTests.swift +++ b/Tests/StripeTests/TokenTests.swift @@ -18,7 +18,7 @@ class TokenTests: XCTestCase { decoder.keyDecodingStrategy = .convertFromSnakeCase let body = HTTPBody(string: cardTokenString) - let cardToken = try decoder.decode(StripeToken.self, from: body) + let cardToken = try decoder.decode(StripeToken.self, from: body, on: EmbeddedEventLoop()) cardToken.do { (token) in XCTAssertNil(token.bankAccount) @@ -71,7 +71,7 @@ class TokenTests: XCTestCase { decoder.keyDecodingStrategy = .convertFromSnakeCase let body = HTTPBody(string: bankAccountTokenString) - let bankToken = try decoder.decode(StripeToken.self, from: body) + let bankToken = try decoder.decode(StripeToken.self, from: body, on: EmbeddedEventLoop()) bankToken.do { (token) in XCTAssertNil(token.card) From 872c7537290bae38491497783ba3dc1f41c9d781 Mon Sep 17 00:00:00 2001 From: Andrew Edwards Date: Thu, 22 Mar 2018 14:05:31 -0400 Subject: [PATCH 14/17] Updated to use NIO's HTTPMethod enums. --- Sources/Stripe/API/Routes/AccountRoutes.swift | 14 ++++++------- Sources/Stripe/API/Routes/BalanceRoutes.swift | 6 +++--- Sources/Stripe/API/Routes/ChargeRoutes.swift | 10 +++++----- Sources/Stripe/API/Routes/CouponRoutes.swift | 10 +++++----- .../Stripe/API/Routes/CustomerRoutes.swift | 20 +++++++++---------- Sources/Stripe/API/Routes/DisputeRoutes.swift | 8 ++++---- .../API/Routes/EphemeralKeyRoutes.swift | 4 ++-- .../Stripe/API/Routes/InvoiceItemRoutes.swift | 10 +++++----- Sources/Stripe/API/Routes/InvoiceRoutes.swift | 14 ++++++------- .../Stripe/API/Routes/OrderReturnRoutes.swift | 4 ++-- Sources/Stripe/API/Routes/OrderRoutes.swift | 12 +++++------ Sources/Stripe/API/Routes/PlanRoutes.swift | 10 +++++----- Sources/Stripe/API/Routes/ProductRoutes.swift | 10 +++++----- Sources/Stripe/API/Routes/RefundRoutes.swift | 8 ++++---- Sources/Stripe/API/Routes/SKURoutes.swift | 10 +++++----- Sources/Stripe/API/Routes/SourceRoutes.swift | 6 +++--- .../API/Routes/SubscriptionItemRoutes.swift | 10 +++++----- .../API/Routes/SubscriptionRoutes.swift | 12 +++++------ Sources/Stripe/API/Routes/TokenRoutes.swift | 8 ++++---- 19 files changed, 93 insertions(+), 93 deletions(-) diff --git a/Sources/Stripe/API/Routes/AccountRoutes.swift b/Sources/Stripe/API/Routes/AccountRoutes.swift index 39485be..64bbcd8 100644 --- a/Sources/Stripe/API/Routes/AccountRoutes.swift +++ b/Sources/Stripe/API/Routes/AccountRoutes.swift @@ -53,13 +53,13 @@ public struct StripeConnectAccountRoutes: AccountRoutes { metadata.forEach { body["metadata[\($0)]"] = $1 } } - return try request.send(method: .post, path: StripeAPIEndpoint.account.endpoint, body: body.queryParameters) + return try request.send(method: .POST, path: StripeAPIEndpoint.account.endpoint, body: body.queryParameters) } /// Retrieve account details /// [Learn More →](https://stripe.com/docs/api/curl#retrieve_account) public func retrieve(account accountId: String) throws -> Future { - return try request.send(method: .get, path: StripeAPIEndpoint.accounts(accountId).endpoint) + return try request.send(method: .GET, path: StripeAPIEndpoint.accounts(accountId).endpoint) } /// Update an account @@ -161,20 +161,20 @@ public struct StripeConnectAccountRoutes: AccountRoutes { try tos.toEncodedDictionary().forEach { body["tos_acceptance[\($0)]"] = $1 } } - return try request.send(method: .post, path: StripeAPIEndpoint.accounts(accountId).endpoint, body: body.queryParameters) + return try request.send(method: .POST, path: StripeAPIEndpoint.accounts(accountId).endpoint, body: body.queryParameters) } /// Delete an account /// [Learn More →](https://stripe.com/docs/api/curl#delete_account) public func delete(account accountId: String) throws -> Future { - return try request.send(method: .delete, path: StripeAPIEndpoint.accounts(accountId).endpoint) + return try request.send(method: .DELETE, path: StripeAPIEndpoint.accounts(accountId).endpoint) } /// Reject an account /// [Learn More →](https://stripe.com/docs/api/curl#reject_account) public func reject(account accountId: String, for rejectReason: AccountRejectReason) throws -> Future { let body = ["reason": rejectReason.rawValue].queryParameters - return try request.send(method: .post, path: StripeAPIEndpoint.accountsReject(accountId).endpoint, body: body) + return try request.send(method: .POST, path: StripeAPIEndpoint.accountsReject(accountId).endpoint, body: body) } /// List all connected accounts @@ -184,12 +184,12 @@ public struct StripeConnectAccountRoutes: AccountRoutes { if let filter = filter { queryParams = filter.queryParameters } - return try request.send(method: .get, path: StripeAPIEndpoint.account.endpoint, query: queryParams) + return try request.send(method: .GET, path: StripeAPIEndpoint.account.endpoint, query: queryParams) } /// Create a login link /// [Learn More →](https://stripe.com/docs/api/curl#create_login_link) public func createLoginLink(for accountId: String) throws -> Future { - return try request.send(method: .post, path: StripeAPIEndpoint.accountsLoginLink(accountId).endpoint) + return try request.send(method: .POST, path: StripeAPIEndpoint.accountsLoginLink(accountId).endpoint) } } diff --git a/Sources/Stripe/API/Routes/BalanceRoutes.swift b/Sources/Stripe/API/Routes/BalanceRoutes.swift index 0ffc7e8..808849d 100644 --- a/Sources/Stripe/API/Routes/BalanceRoutes.swift +++ b/Sources/Stripe/API/Routes/BalanceRoutes.swift @@ -28,13 +28,13 @@ public struct StripeBalanceRoutes: BalanceRoutes { /// Retrieve balance /// [Learn More →](https://stripe.com/docs/api/curl#retrieve_balance) public func retrieve() throws -> Future { - return try request.send(method: .get, path: StripeAPIEndpoint.balance.endpoint) + return try request.send(method: .GET, path: StripeAPIEndpoint.balance.endpoint) } /// Retrieve a balance transaction /// [Learn More →](https://stripe.com/docs/api/curl#balance_transaction_retrieve) public func retrieve(forTransaction transactionId: String) throws -> Future { - return try request.send(method: .get, path: StripeAPIEndpoint.balanceHistoryTransaction(transactionId).endpoint) + return try request.send(method: .GET, path: StripeAPIEndpoint.balanceHistoryTransaction(transactionId).endpoint) } /// List all balance history @@ -44,6 +44,6 @@ public struct StripeBalanceRoutes: BalanceRoutes { if let filter = filter { queryParams = filter.queryParameters } - return try request.send(method: .get, path: StripeAPIEndpoint.account.endpoint, query: queryParams) + return try request.send(method: .GET, path: StripeAPIEndpoint.account.endpoint, query: queryParams) } } diff --git a/Sources/Stripe/API/Routes/ChargeRoutes.swift b/Sources/Stripe/API/Routes/ChargeRoutes.swift index 71f30e1..8bbd434 100644 --- a/Sources/Stripe/API/Routes/ChargeRoutes.swift +++ b/Sources/Stripe/API/Routes/ChargeRoutes.swift @@ -103,13 +103,13 @@ public struct StripeChargeRoutes: ChargeRoutes { body["statement_descriptor"] = statementDescriptor } - return try request.send(method: .post, path: StripeAPIEndpoint.charges.endpoint, body: body.queryParameters) + return try request.send(method: .POST, path: StripeAPIEndpoint.charges.endpoint, body: body.queryParameters) } /// Retrieve a charge /// [Learn More →](https://stripe.com/docs/api/curl#retrieve_charge) public func retrieve(charge: String) throws -> Future { - return try request.send(method: .get, path: StripeAPIEndpoint.charge(charge).endpoint) + return try request.send(method: .GET, path: StripeAPIEndpoint.charge(charge).endpoint) } /// Update a charge @@ -160,7 +160,7 @@ public struct StripeChargeRoutes: ChargeRoutes { body["transfer_group"] = transferGroup } - return try request.send(method: .post, path: StripeAPIEndpoint.charge(chargeId).endpoint, body: body.queryParameters) + return try request.send(method: .POST, path: StripeAPIEndpoint.charge(chargeId).endpoint, body: body.queryParameters) } /// Capture a charge @@ -193,7 +193,7 @@ public struct StripeChargeRoutes: ChargeRoutes { body["statement_descriptor"] = statementDescriptor } - return try request.send(method: .post, path: StripeAPIEndpoint.captureCharge(charge).endpoint, body: body.queryParameters) + return try request.send(method: .POST, path: StripeAPIEndpoint.captureCharge(charge).endpoint, body: body.queryParameters) } /// List all charges @@ -204,6 +204,6 @@ public struct StripeChargeRoutes: ChargeRoutes { queryParams = filter.queryParameters } - return try request.send(method: .get, path: StripeAPIEndpoint.account.endpoint, query: queryParams) + return try request.send(method: .GET, path: StripeAPIEndpoint.account.endpoint, query: queryParams) } } diff --git a/Sources/Stripe/API/Routes/CouponRoutes.swift b/Sources/Stripe/API/Routes/CouponRoutes.swift index cdd1af0..60eadb3 100644 --- a/Sources/Stripe/API/Routes/CouponRoutes.swift +++ b/Sources/Stripe/API/Routes/CouponRoutes.swift @@ -71,13 +71,13 @@ public struct StripeCouponRoutes: CouponRoutes { metadata.forEach { body["metadata[\($0)]"] = $1 } } - return try request.send(method: .post, path: StripeAPIEndpoint.coupons.endpoint, body: body.queryParameters) + return try request.send(method: .POST, path: StripeAPIEndpoint.coupons.endpoint, body: body.queryParameters) } /// Retrieve coupon /// [Learn More →](https://stripe.com/docs/api/curl#retrieve_coupon) public func retrieve(coupon: String) throws -> Future { - return try request.send(method: .get, path: StripeAPIEndpoint.coupon(coupon).endpoint) + return try request.send(method: .GET, path: StripeAPIEndpoint.coupon(coupon).endpoint) } /// Update coupon @@ -89,13 +89,13 @@ public struct StripeCouponRoutes: CouponRoutes { metadata.forEach { body["metadata[\($0)]"] = $1 } } - return try request.send(method: .post, path: StripeAPIEndpoint.coupon(coupon).endpoint, body: body.queryParameters) + return try request.send(method: .POST, path: StripeAPIEndpoint.coupon(coupon).endpoint, body: body.queryParameters) } /// Delete coupon /// [Learn More →](https://stripe.com/docs/api/curl#delete_coupon) public func delete(coupon: String) throws -> Future { - return try request.send(method: .delete, path: StripeAPIEndpoint.coupon(coupon).endpoint) + return try request.send(method: .DELETE, path: StripeAPIEndpoint.coupon(coupon).endpoint) } /// List all coupons @@ -106,6 +106,6 @@ public struct StripeCouponRoutes: CouponRoutes { queryParams = filter.queryParameters } - return try request.send(method: .get, path: StripeAPIEndpoint.coupons.endpoint, query: queryParams) + return try request.send(method: .GET, path: StripeAPIEndpoint.coupons.endpoint, query: queryParams) } } diff --git a/Sources/Stripe/API/Routes/CustomerRoutes.swift b/Sources/Stripe/API/Routes/CustomerRoutes.swift index 46361c5..199b94d 100644 --- a/Sources/Stripe/API/Routes/CustomerRoutes.swift +++ b/Sources/Stripe/API/Routes/CustomerRoutes.swift @@ -89,13 +89,13 @@ public struct StripeCustomerRoutes: CustomerRoutes { cardDictionarySource.forEach { body["source[\($0)]"] = $1 } } - return try request.send(method: .post, path: StripeAPIEndpoint.customers.endpoint, body: body.queryParameters) + return try request.send(method: .POST, path: StripeAPIEndpoint.customers.endpoint, body: body.queryParameters) } /// Retrieve customer /// [Learn More →](https://stripe.com/docs/api/curl#retrieve_customer) public func retrieve(customer: String) throws -> Future { - return try request.send(method: .get, path: StripeAPIEndpoint.customer(customer).endpoint) + return try request.send(method: .GET, path: StripeAPIEndpoint.customer(customer).endpoint) } /// Update customer @@ -152,13 +152,13 @@ public struct StripeCustomerRoutes: CustomerRoutes { cardDictionarySource.forEach { body["source[\($0)]"] = $1 } } - return try request.send(method: .post, path: StripeAPIEndpoint.customer(customer).endpoint, body: body.queryParameters) + return try request.send(method: .POST, path: StripeAPIEndpoint.customer(customer).endpoint, body: body.queryParameters) } /// Delete a customer /// [Learn More →](https://stripe.com/docs/api/curl#delete_customer) public func delete(customer: String) throws -> Future { - return try request.send(method: .delete, path: StripeAPIEndpoint.customer(customer).endpoint) + return try request.send(method: .DELETE, path: StripeAPIEndpoint.customer(customer).endpoint) } /// List all customers @@ -169,7 +169,7 @@ public struct StripeCustomerRoutes: CustomerRoutes { queryParams = filter.queryParameters } - return try request.send(method: .get, path: StripeAPIEndpoint.customers.endpoint, query: queryParams) + return try request.send(method: .GET, path: StripeAPIEndpoint.customers.endpoint, query: queryParams) } /// Attach a source @@ -182,7 +182,7 @@ public struct StripeCustomerRoutes: CustomerRoutes { headers["Stripe-Account"] = connectedAccount } - return try request.send(method: .post, path: StripeAPIEndpoint.customerSources(customer).endpoint, body: body.queryParameters, headers: headers) + return try request.send(method: .POST, path: StripeAPIEndpoint.customerSources(customer).endpoint, body: body.queryParameters, headers: headers) } /// Create a bank account @@ -207,7 +207,7 @@ public struct StripeCustomerRoutes: CustomerRoutes { metadata.forEach { body["metadata[\($0)]"] = $1 } } - return try request.send(method: .post, path: StripeAPIEndpoint.customerSources(customer).endpoint, body: body.queryParameters, headers: headers) + return try request.send(method: .POST, path: StripeAPIEndpoint.customerSources(customer).endpoint, body: body.queryParameters, headers: headers) } /// Create a card @@ -232,18 +232,18 @@ public struct StripeCustomerRoutes: CustomerRoutes { metadata.forEach { body["metadata[\($0)]"] = $1 } } - return try request.send(method: .post, path: StripeAPIEndpoint.customerSources(customer).endpoint, body: body.queryParameters, headers: headers) + return try request.send(method: .POST, path: StripeAPIEndpoint.customerSources(customer).endpoint, body: body.queryParameters, headers: headers) } /// Detach a source /// [Learn More →](https://stripe.com/docs/api/curl#detach_source) public func deleteSource(customer: String, source: String) throws -> Future { - return try request.send(method: .delete, path: StripeAPIEndpoint.customerDetachSources(customer, source).endpoint) + return try request.send(method: .DELETE, path: StripeAPIEndpoint.customerDetachSources(customer, source).endpoint) } /// Delete a customer discount /// [Learn More →](https://stripe.com/docs/api/curl#delete_discount) public func deleteDiscount(customer: String) throws -> Future { - return try request.send(method: .delete, path: StripeAPIEndpoint.customerDiscount(customer).endpoint) + return try request.send(method: .DELETE, path: StripeAPIEndpoint.customerDiscount(customer).endpoint) } } diff --git a/Sources/Stripe/API/Routes/DisputeRoutes.swift b/Sources/Stripe/API/Routes/DisputeRoutes.swift index 0c90014..81c2104 100644 --- a/Sources/Stripe/API/Routes/DisputeRoutes.swift +++ b/Sources/Stripe/API/Routes/DisputeRoutes.swift @@ -29,7 +29,7 @@ public struct StripeDisputeRoutes: DisputeRoutes { /// Retrieve a dispute /// [Learn More →](https://stripe.com/docs/api/curl#retrieve_dispute) public func retrieve(dispute: String) throws -> Future { - return try request.send(method: .get, path: StripeAPIEndpoint.disputes(dispute).endpoint) + return try request.send(method: .GET, path: StripeAPIEndpoint.disputes(dispute).endpoint) } /// Update a dispute @@ -49,13 +49,13 @@ public struct StripeDisputeRoutes: DisputeRoutes { body["submit"] = submit } - return try request.send(method: .post, path: StripeAPIEndpoint.disputes(dispute).endpoint, body: body.queryParameters) + return try request.send(method: .POST, path: StripeAPIEndpoint.disputes(dispute).endpoint, body: body.queryParameters) } /// Close a dispute /// [Learn More →](https://stripe.com/docs/api/curl#close_dispute) public func close(dispute: String) throws -> Future { - return try request.send(method: .post, path: StripeAPIEndpoint.closeDispute(dispute).endpoint) + return try request.send(method: .POST, path: StripeAPIEndpoint.closeDispute(dispute).endpoint) } /// List all disputes @@ -66,6 +66,6 @@ public struct StripeDisputeRoutes: DisputeRoutes { queryParams = filter.queryParameters } - return try request.send(method: .get, path: StripeAPIEndpoint.dispute.endpoint, query: queryParams) + return try request.send(method: .GET, path: StripeAPIEndpoint.dispute.endpoint, query: queryParams) } } diff --git a/Sources/Stripe/API/Routes/EphemeralKeyRoutes.swift b/Sources/Stripe/API/Routes/EphemeralKeyRoutes.swift index 1f8fcf8..5e84daa 100644 --- a/Sources/Stripe/API/Routes/EphemeralKeyRoutes.swift +++ b/Sources/Stripe/API/Routes/EphemeralKeyRoutes.swift @@ -24,10 +24,10 @@ public struct StripeEphemeralKeyRoutes: EphemeralKeyRoutes { public func create(customer: String) throws -> Future { let body = ["customer": customer] - return try request.send(method: .post, path: StripeAPIEndpoint.ephemeralKeys.endpoint, body: body.queryParameters) + return try request.send(method: .POST, path: StripeAPIEndpoint.ephemeralKeys.endpoint, body: body.queryParameters) } public func delete(ephemeralKey: String) throws -> Future { - return try request.send(method: .delete, path: StripeAPIEndpoint.ephemeralKey(ephemeralKey).endpoint) + return try request.send(method: .DELETE, path: StripeAPIEndpoint.ephemeralKey(ephemeralKey).endpoint) } } diff --git a/Sources/Stripe/API/Routes/InvoiceItemRoutes.swift b/Sources/Stripe/API/Routes/InvoiceItemRoutes.swift index 83e96db..b9a7504 100644 --- a/Sources/Stripe/API/Routes/InvoiceItemRoutes.swift +++ b/Sources/Stripe/API/Routes/InvoiceItemRoutes.swift @@ -63,13 +63,13 @@ public struct StripeInvoiceItemRoutes: InvoiceItemRoutes { body["subscription"] = subscription } - return try request.send(method: .post, path: StripeAPIEndpoint.invoiceItems.endpoint, body: body.queryParameters) + return try request.send(method: .POST, path: StripeAPIEndpoint.invoiceItems.endpoint, body: body.queryParameters) } /// Retrieve an invoice item /// [Learn More →](https://stripe.com/docs/api/curl#retrieve_invoiceitem) public func retrieve(invoiceItem: String) throws -> Future { - return try request.send(method: .get, path: StripeAPIEndpoint.invoiceItem(invoiceItem).endpoint) + return try request.send(method: .GET, path: StripeAPIEndpoint.invoiceItem(invoiceItem).endpoint) } /// Update an invoice item @@ -97,13 +97,13 @@ public struct StripeInvoiceItemRoutes: InvoiceItemRoutes { metadata.forEach { body["metadata[\($0)]"] = $1 } } - return try request.send(method: .post, path: StripeAPIEndpoint.invoiceItem(invoiceItem).endpoint, body: body.queryParameters) + return try request.send(method: .POST, path: StripeAPIEndpoint.invoiceItem(invoiceItem).endpoint, body: body.queryParameters) } /// Delete an invoice item /// [Learn More →](https://stripe.com/docs/api/curl#delete_invoiceitem) public func delete(invoiceItem: String) throws -> Future { - return try request.send(method: .delete, path: StripeAPIEndpoint.invoiceItem(invoiceItem).endpoint) + return try request.send(method: .DELETE, path: StripeAPIEndpoint.invoiceItem(invoiceItem).endpoint) } /// List all invoice items @@ -114,6 +114,6 @@ public struct StripeInvoiceItemRoutes: InvoiceItemRoutes { queryParams = filter.queryParameters } - return try request.send(method: .get, path: StripeAPIEndpoint.invoiceItems.endpoint, query: queryParams) + return try request.send(method: .GET, path: StripeAPIEndpoint.invoiceItems.endpoint, query: queryParams) } } diff --git a/Sources/Stripe/API/Routes/InvoiceRoutes.swift b/Sources/Stripe/API/Routes/InvoiceRoutes.swift index af98b2d..710f77d 100644 --- a/Sources/Stripe/API/Routes/InvoiceRoutes.swift +++ b/Sources/Stripe/API/Routes/InvoiceRoutes.swift @@ -88,19 +88,19 @@ public struct StripeInvoiceRoutes: InvoiceRoutes { body["tax_percent"] = taxPercent } - return try request.send(method: .post, path: StripeAPIEndpoint.invoices.endpoint, body: body.queryParameters, headers: headers) + return try request.send(method: .POST, path: StripeAPIEndpoint.invoices.endpoint, body: body.queryParameters, headers: headers) } /// Retrieve an invoice /// [Learn More →](https://stripe.com/docs/api/curl#retrieve_invoice) public func retrieve(invoice: String) throws -> Future { - return try request.send(method: .get, path: StripeAPIEndpoint.invoice(invoice).endpoint) + return try request.send(method: .GET, path: StripeAPIEndpoint.invoice(invoice).endpoint) } /// Retrieve an invoice's line items /// [Learn More →](https://stripe.com/docs/api/curl#invoice_lines) public func retrieveLineItems(invoice: String, filter: [String: Any]? = nil) throws -> Future { - return try request.send(method: .get, path: StripeAPIEndpoint.invoiceLines(invoice).endpoint, query: filter?.queryParameters ?? "") + return try request.send(method: .GET, path: StripeAPIEndpoint.invoiceLines(invoice).endpoint, query: filter?.queryParameters ?? "") } /// Retrieve an upcoming invoice @@ -112,7 +112,7 @@ public struct StripeInvoiceRoutes: InvoiceRoutes { filter.forEach { query["\($0)"] = $1 } } - return try request.send(method: .get, path: StripeAPIEndpoint.upcomingInvoices.endpoint, query: query.queryParameters) + return try request.send(method: .GET, path: StripeAPIEndpoint.upcomingInvoices.endpoint, query: query.queryParameters) } /// Update an invoice @@ -166,7 +166,7 @@ public struct StripeInvoiceRoutes: InvoiceRoutes { body["tax_percent"] = taxPercent } - return try request.send(method: .post, path: StripeAPIEndpoint.invoice(invoice).endpoint, body: body.queryParameters, headers: headers) + return try request.send(method: .POST, path: StripeAPIEndpoint.invoice(invoice).endpoint, body: body.queryParameters, headers: headers) } /// Pay an invoice @@ -178,7 +178,7 @@ public struct StripeInvoiceRoutes: InvoiceRoutes { body["source"] = source } - return try request.send(method: .post, path: StripeAPIEndpoint.payInvoice(invoice).endpoint, body: body.queryParameters) + return try request.send(method: .POST, path: StripeAPIEndpoint.payInvoice(invoice).endpoint, body: body.queryParameters) } /// List all invoices @@ -189,6 +189,6 @@ public struct StripeInvoiceRoutes: InvoiceRoutes { queryParams = filter.queryParameters } - return try request.send(method: .get, path: StripeAPIEndpoint.invoices.endpoint, query: queryParams) + return try request.send(method: .GET, path: StripeAPIEndpoint.invoices.endpoint, query: queryParams) } } diff --git a/Sources/Stripe/API/Routes/OrderReturnRoutes.swift b/Sources/Stripe/API/Routes/OrderReturnRoutes.swift index 915ea5e..12cd3e0 100644 --- a/Sources/Stripe/API/Routes/OrderReturnRoutes.swift +++ b/Sources/Stripe/API/Routes/OrderReturnRoutes.swift @@ -26,7 +26,7 @@ public struct StripeOrderReturnRoutes: OrderReturnRoutes { /// Retrieve an order return /// [Learn More →](https://stripe.com/docs/api/curl#retrieve_order_return) public func retrieve(order: String) throws -> Future { - return try request.send(method: .get, path: StripeAPIEndpoint.orderReturns(order).endpoint) + return try request.send(method: .GET, path: StripeAPIEndpoint.orderReturns(order).endpoint) } /// List all order returns @@ -37,6 +37,6 @@ public struct StripeOrderReturnRoutes: OrderReturnRoutes { queryParams = filter.queryParameters } - return try request.send(method: .get, path: StripeAPIEndpoint.orderReturn.endpoint, query: queryParams) + return try request.send(method: .GET, path: StripeAPIEndpoint.orderReturn.endpoint, query: queryParams) } } diff --git a/Sources/Stripe/API/Routes/OrderRoutes.swift b/Sources/Stripe/API/Routes/OrderRoutes.swift index 142d8ef..c8b1c75 100644 --- a/Sources/Stripe/API/Routes/OrderRoutes.swift +++ b/Sources/Stripe/API/Routes/OrderRoutes.swift @@ -65,13 +65,13 @@ public struct StripeOrderRoutes: OrderRoutes { try shipping.toEncodedDictionary().forEach { body["shipping[\($0)]"] = $1 } } - return try request.send(method: .post, path: StripeAPIEndpoint.order.endpoint, body: body.queryParameters) + return try request.send(method: .POST, path: StripeAPIEndpoint.order.endpoint, body: body.queryParameters) } /// Retrieve a new order /// [Learn More →](https://stripe.com/docs/api/curl#retrieve_order) public func retrieve(order: String) throws -> Future { - return try request.send(method: .get, path: StripeAPIEndpoint.orders(order).endpoint) + return try request.send(method: .GET, path: StripeAPIEndpoint.orders(order).endpoint) } /// Update an order @@ -104,7 +104,7 @@ public struct StripeOrderRoutes: OrderRoutes { body["status"] = status } - return try request.send(method: .post, path: StripeAPIEndpoint.orders(order).endpoint, body: body.queryParameters) + return try request.send(method: .POST, path: StripeAPIEndpoint.orders(order).endpoint, body: body.queryParameters) } /// Pay an order @@ -147,7 +147,7 @@ public struct StripeOrderRoutes: OrderRoutes { metadata.forEach { body["metadata[\($0)]"] = $1 } } - return try request.send(method: .post, path: StripeAPIEndpoint.ordersPay(order).endpoint, body: body.queryParameters, headers: headers) + return try request.send(method: .POST, path: StripeAPIEndpoint.ordersPay(order).endpoint, body: body.queryParameters, headers: headers) } /// List all orders @@ -158,7 +158,7 @@ public struct StripeOrderRoutes: OrderRoutes { queryParams = filter.queryParameters } - return try request.send(method: .get, path: StripeAPIEndpoint.order.endpoint, query: queryParams) + return try request.send(method: .GET, path: StripeAPIEndpoint.order.endpoint, query: queryParams) } /// Return an order @@ -172,6 +172,6 @@ public struct StripeOrderRoutes: OrderRoutes { } } - return try request.send(method: .post, path: StripeAPIEndpoint.ordersReturn(order).endpoint, body: body.queryParameters) + return try request.send(method: .POST, path: StripeAPIEndpoint.ordersReturn(order).endpoint, body: body.queryParameters) } } diff --git a/Sources/Stripe/API/Routes/PlanRoutes.swift b/Sources/Stripe/API/Routes/PlanRoutes.swift index b41390e..2b2b4f9 100644 --- a/Sources/Stripe/API/Routes/PlanRoutes.swift +++ b/Sources/Stripe/API/Routes/PlanRoutes.swift @@ -63,13 +63,13 @@ public struct StripePlanRoutes: PlanRoutes { body["nickname"] = nickname } - return try request.send(method: .post, path: StripeAPIEndpoint.plans.endpoint, body: body.queryParameters) + return try request.send(method: .POST, path: StripeAPIEndpoint.plans.endpoint, body: body.queryParameters) } /// Retrieve a plan /// [Learn More →](https://stripe.com/docs/api/curl#retrieve_plan) public func retrieve(plan: String) throws -> Future { - return try request.send(method: .get, path: StripeAPIEndpoint.plan(plan).endpoint) + return try request.send(method: .GET, path: StripeAPIEndpoint.plan(plan).endpoint) } /// Update a plan @@ -92,13 +92,13 @@ public struct StripePlanRoutes: PlanRoutes { body["product"] = product } - return try request.send(method: .post, path: StripeAPIEndpoint.plan(plan).endpoint, body: body.queryParameters) + return try request.send(method: .POST, path: StripeAPIEndpoint.plan(plan).endpoint, body: body.queryParameters) } /// Delete a plan /// [Learn More →](https://stripe.com/docs/api/curl#delete_plan) public func delete(plan: String) throws -> Future { - return try request.send(method: .delete, path: StripeAPIEndpoint.plan(plan).endpoint) + return try request.send(method: .DELETE, path: StripeAPIEndpoint.plan(plan).endpoint) } /// List all plans @@ -109,6 +109,6 @@ public struct StripePlanRoutes: PlanRoutes { queryParams = filter.queryParameters } - return try request.send(method: .get, path: StripeAPIEndpoint.plans.endpoint, query: queryParams) + return try request.send(method: .GET, path: StripeAPIEndpoint.plans.endpoint, query: queryParams) } } diff --git a/Sources/Stripe/API/Routes/ProductRoutes.swift b/Sources/Stripe/API/Routes/ProductRoutes.swift index f177911..6a1f7dc 100644 --- a/Sources/Stripe/API/Routes/ProductRoutes.swift +++ b/Sources/Stripe/API/Routes/ProductRoutes.swift @@ -104,13 +104,13 @@ public struct StripeProductRoutes: ProductRoutes { body["url"] = url } - return try request.send(method: .post, path: StripeAPIEndpoint.product.endpoint, body: body.queryParameters) + return try request.send(method: .POST, path: StripeAPIEndpoint.product.endpoint, body: body.queryParameters) } /// Retrieve a product /// [Learn More →](https://stripe.com/docs/api/curl#retrieve_product) public func retrieve(id: String) throws -> Future { - return try request.send(method: .get, path: StripeAPIEndpoint.products(id).endpoint) + return try request.send(method: .GET, path: StripeAPIEndpoint.products(id).endpoint) } /// Update a product @@ -184,7 +184,7 @@ public struct StripeProductRoutes: ProductRoutes { body["url"] = url } - return try request.send(method: .post, path: StripeAPIEndpoint.products(product).endpoint, body: body.queryParameters) + return try request.send(method: .POST, path: StripeAPIEndpoint.products(product).endpoint, body: body.queryParameters) } /// List all products @@ -195,12 +195,12 @@ public struct StripeProductRoutes: ProductRoutes { queryParams = filter.queryParameters } - return try request.send(method: .get, path: StripeAPIEndpoint.product.endpoint, query: queryParams) + return try request.send(method: .GET, path: StripeAPIEndpoint.product.endpoint, query: queryParams) } /// Delete a product /// [Learn More →](https://stripe.com/docs/api/curl#delete_product) public func delete(id: String) throws -> Future { - return try request.send(method: .delete, path: StripeAPIEndpoint.products(id).endpoint) + return try request.send(method: .DELETE, path: StripeAPIEndpoint.products(id).endpoint) } } diff --git a/Sources/Stripe/API/Routes/RefundRoutes.swift b/Sources/Stripe/API/Routes/RefundRoutes.swift index 459f61f..f4620c7 100644 --- a/Sources/Stripe/API/Routes/RefundRoutes.swift +++ b/Sources/Stripe/API/Routes/RefundRoutes.swift @@ -57,13 +57,13 @@ public struct StripeRefundRoutes: RefundRoutes { body["reverse_transfer"] = reverseTransfer } - return try request.send(method: .post, path: StripeAPIEndpoint.refunds.endpoint, body: body.queryParameters) + return try request.send(method: .POST, path: StripeAPIEndpoint.refunds.endpoint, body: body.queryParameters) } /// Retrieve a refund /// [Learn More →](https://stripe.com/docs/api/curl#retrieve_refund) public func retrieve(refund: String) throws -> Future { - return try request.send(method: .get, path: StripeAPIEndpoint.refund(refund).endpoint) + return try request.send(method: .GET, path: StripeAPIEndpoint.refund(refund).endpoint) } /// Update a refund @@ -75,7 +75,7 @@ public struct StripeRefundRoutes: RefundRoutes { metadata.forEach { body["metadata[\($0)]"] = $1 } } - return try request.send(method: .post, path: StripeAPIEndpoint.refund(refund).endpoint, body: body.queryParameters) + return try request.send(method: .POST, path: StripeAPIEndpoint.refund(refund).endpoint, body: body.queryParameters) } /// List all refunds @@ -86,6 +86,6 @@ public struct StripeRefundRoutes: RefundRoutes { queryParams = filter.queryParameters } - return try request.send(method: .get, path: StripeAPIEndpoint.refunds.endpoint, query: queryParams) + return try request.send(method: .GET, path: StripeAPIEndpoint.refunds.endpoint, query: queryParams) } } diff --git a/Sources/Stripe/API/Routes/SKURoutes.swift b/Sources/Stripe/API/Routes/SKURoutes.swift index 8039949..095f86c 100644 --- a/Sources/Stripe/API/Routes/SKURoutes.swift +++ b/Sources/Stripe/API/Routes/SKURoutes.swift @@ -72,13 +72,13 @@ public struct StripeSKURoutes: SKURoutes { try packageDimensions.toEncodedDictionary().forEach { body["package_dimensions[\($0)]"] = $1 } } - return try request.send(method: .post, path: StripeAPIEndpoint.sku.endpoint, body: body.queryParameters) + return try request.send(method: .POST, path: StripeAPIEndpoint.sku.endpoint, body: body.queryParameters) } /// Retrieve a SKU /// [Learn More →](https://stripe.com/docs/api/curl#retrieve_sku) public func retrieve(id: String) throws -> Future { - return try request.send(method: .get, path: StripeAPIEndpoint.skus(id).endpoint) + return try request.send(method: .GET, path: StripeAPIEndpoint.skus(id).endpoint) } /// Update a SKU @@ -131,7 +131,7 @@ public struct StripeSKURoutes: SKURoutes { body["product"] = product } - return try request.send(method: .post, path: StripeAPIEndpoint.skus(sku).endpoint, body: body.queryParameters) + return try request.send(method: .POST, path: StripeAPIEndpoint.skus(sku).endpoint, body: body.queryParameters) } /// List all SKUs @@ -142,12 +142,12 @@ public struct StripeSKURoutes: SKURoutes { queryParams = filter.queryParameters } - return try request.send(method: .get, path: StripeAPIEndpoint.sku.endpoint, query: queryParams) + return try request.send(method: .GET, path: StripeAPIEndpoint.sku.endpoint, query: queryParams) } /// Delete a SKU /// [Learn More →](https://stripe.com/docs/api/curl#delete_sku) public func delete(sku: String) throws -> Future { - return try request.send(method: .delete, path: StripeAPIEndpoint.skus(sku).endpoint) + return try request.send(method: .DELETE, path: StripeAPIEndpoint.skus(sku).endpoint) } } diff --git a/Sources/Stripe/API/Routes/SourceRoutes.swift b/Sources/Stripe/API/Routes/SourceRoutes.swift index 82bbf25..2160406 100644 --- a/Sources/Stripe/API/Routes/SourceRoutes.swift +++ b/Sources/Stripe/API/Routes/SourceRoutes.swift @@ -83,7 +83,7 @@ public struct StripeSourceRoutes: SourceRoutes { body["usage"] = usage } - return try request.send(method: .post, path: StripeAPIEndpoint.sources.endpoint, body: body.queryParameters) + return try request.send(method: .POST, path: StripeAPIEndpoint.sources.endpoint, body: body.queryParameters) } /// Retrieve a source @@ -94,7 +94,7 @@ public struct StripeSourceRoutes: SourceRoutes { query = "client_secret=\(clientSecret)" } - return try request.send(method: .get, path: StripeAPIEndpoint.source(source).endpoint, query: query) + return try request.send(method: .GET, path: StripeAPIEndpoint.source(source).endpoint, query: query) } /// Update a source @@ -117,6 +117,6 @@ public struct StripeSourceRoutes: SourceRoutes { try owner.toEncodedDictionary().forEach { body["owner[\($0)]"] = $1 } } - return try request.send(method: .post, path: StripeAPIEndpoint.source(source).endpoint, body: body.queryParameters) + return try request.send(method: .POST, path: StripeAPIEndpoint.source(source).endpoint, body: body.queryParameters) } } diff --git a/Sources/Stripe/API/Routes/SubscriptionItemRoutes.swift b/Sources/Stripe/API/Routes/SubscriptionItemRoutes.swift index bcb0bee..b17825b 100644 --- a/Sources/Stripe/API/Routes/SubscriptionItemRoutes.swift +++ b/Sources/Stripe/API/Routes/SubscriptionItemRoutes.swift @@ -56,13 +56,13 @@ public struct StripeSubscriptionItemRoutes: SubscriptionItemRoutes { body["quantity"] = quantity } - return try request.send(method: .post, path: StripeAPIEndpoint.subscriptionItem.endpoint, body: body.queryParameters) + return try request.send(method: .POST, path: StripeAPIEndpoint.subscriptionItem.endpoint, body: body.queryParameters) } /// Retrieve a subscription item /// [Learn More →](https://stripe.com/docs/api/curl#retrieve_subscription_item) public func retrieve(item: String) throws -> Future { - return try request.send(method: .get, path: StripeAPIEndpoint.subscriptionItems(item).endpoint) + return try request.send(method: .GET, path: StripeAPIEndpoint.subscriptionItems(item).endpoint) } /// Update a subscription item @@ -95,7 +95,7 @@ public struct StripeSubscriptionItemRoutes: SubscriptionItemRoutes { body["quantity"] = quantity } - return try request.send(method: .post, path: StripeAPIEndpoint.subscriptionItems(item).endpoint, body: body.queryParameters) + return try request.send(method: .POST, path: StripeAPIEndpoint.subscriptionItems(item).endpoint, body: body.queryParameters) } /// Delete a subscription item @@ -113,7 +113,7 @@ public struct StripeSubscriptionItemRoutes: SubscriptionItemRoutes { body["proration_date"] = Int(prorationDate.timeIntervalSince1970) } - return try request.send(method: .delete, path: StripeAPIEndpoint.subscriptionItems(item).endpoint, body: body.queryParameters) + return try request.send(method: .DELETE, path: StripeAPIEndpoint.subscriptionItems(item).endpoint, body: body.queryParameters) } /// List all subscription items @@ -124,6 +124,6 @@ public struct StripeSubscriptionItemRoutes: SubscriptionItemRoutes { queryParams = filter.queryParameters } - return try request.send(method: .get, path: StripeAPIEndpoint.subscriptionItems(subscription).endpoint, query: queryParams) + return try request.send(method: .GET, path: StripeAPIEndpoint.subscriptionItems(subscription).endpoint, query: queryParams) } } diff --git a/Sources/Stripe/API/Routes/SubscriptionRoutes.swift b/Sources/Stripe/API/Routes/SubscriptionRoutes.swift index bb45cb7..544ac4e 100644 --- a/Sources/Stripe/API/Routes/SubscriptionRoutes.swift +++ b/Sources/Stripe/API/Routes/SubscriptionRoutes.swift @@ -99,13 +99,13 @@ public struct StripeSubscriptionRoutes: SubscriptionRoutes { body["trial_period_days"] = trialPeriodDays } - return try request.send(method: .post, path: StripeAPIEndpoint.subscription.endpoint, body: body.queryParameters) + return try request.send(method: .POST, path: StripeAPIEndpoint.subscription.endpoint, body: body.queryParameters) } /// Retrieve a subscription /// [Learn More →](https://stripe.com/docs/api/curl#retrieve_subscription) public func retrieve(id: String) throws -> Future { - return try request.send(method: .get, path: StripeAPIEndpoint.subscriptions(id).endpoint) + return try request.send(method: .GET, path: StripeAPIEndpoint.subscriptions(id).endpoint) } /// Update a subscription @@ -181,7 +181,7 @@ public struct StripeSubscriptionRoutes: SubscriptionRoutes { body["trial_end"] = trialEnd } - return try request.send(method: .post, path: StripeAPIEndpoint.subscriptions(subscription).endpoint, body: body.queryParameters) + return try request.send(method: .POST, path: StripeAPIEndpoint.subscriptions(subscription).endpoint, body: body.queryParameters) } /// Cancel a subscription @@ -193,7 +193,7 @@ public struct StripeSubscriptionRoutes: SubscriptionRoutes { body["at_period_end"] = atPeriodEnd } - return try request.send(method: .delete, path: StripeAPIEndpoint.subscriptions(subscription).endpoint, body: body.queryParameters) + return try request.send(method: .DELETE, path: StripeAPIEndpoint.subscriptions(subscription).endpoint, body: body.queryParameters) } /// List subscriptions @@ -204,12 +204,12 @@ public struct StripeSubscriptionRoutes: SubscriptionRoutes { queryParams = filter.queryParameters } - return try request.send(method: .get, path: StripeAPIEndpoint.subscription.endpoint, query: queryParams) + return try request.send(method: .GET, path: StripeAPIEndpoint.subscription.endpoint, query: queryParams) } /// Delete a subscription discount /// [Learn More →](https://stripe.com/docs/api/curl#delete_subscription_discount) public func deleteDiscount(subscription: String) throws -> Future { - return try request.send(method: .delete, path: StripeAPIEndpoint.subscriptionDiscount(subscription).endpoint) + return try request.send(method: .DELETE, path: StripeAPIEndpoint.subscriptionDiscount(subscription).endpoint) } } diff --git a/Sources/Stripe/API/Routes/TokenRoutes.swift b/Sources/Stripe/API/Routes/TokenRoutes.swift index 6d51b64..670b226 100644 --- a/Sources/Stripe/API/Routes/TokenRoutes.swift +++ b/Sources/Stripe/API/Routes/TokenRoutes.swift @@ -44,7 +44,7 @@ public struct StripeTokenRoutes: TokenRoutes { headers["Stripe-Account"] = connectAccount } - return try request.send(method: .post, path: StripeAPIEndpoint.tokens.endpoint, body: body.queryParameters, headers: headers) + return try request.send(method: .POST, path: StripeAPIEndpoint.tokens.endpoint, body: body.queryParameters, headers: headers) } /// Create a bank account token @@ -67,7 +67,7 @@ public struct StripeTokenRoutes: TokenRoutes { headers["Stripe-Account"] = connectAccount } - return try request.send(method: .post, path: StripeAPIEndpoint.tokens.endpoint, body: body.queryParameters, headers: headers) + return try request.send(method: .POST, path: StripeAPIEndpoint.tokens.endpoint, body: body.queryParameters, headers: headers) } /// Create a PII token @@ -79,12 +79,12 @@ public struct StripeTokenRoutes: TokenRoutes { body["personal_id_number"] = personalId } - return try request.send(method: .post, path: StripeAPIEndpoint.tokens.endpoint, body: body.queryParameters) + return try request.send(method: .POST, path: StripeAPIEndpoint.tokens.endpoint, body: body.queryParameters) } /// Retrieve a token /// [Learn More →](https://stripe.com/docs/api/curl#retrieve_token) public func retrieve(token: String) throws -> Future { - return try request.send(method: .get, path: StripeAPIEndpoint.token(token).endpoint) + return try request.send(method: .GET, path: StripeAPIEndpoint.token(token).endpoint) } } From 9f11b1afcb92ee1bd1be16ac0ca43e9967756417 Mon Sep 17 00:00:00 2001 From: Andrew Edwards Date: Thu, 22 Mar 2018 14:06:52 -0400 Subject: [PATCH 15/17] Updated to use NIO's headers and made more type safe headers. --- .../Stripe/API/Routes/CustomerRoutes.swift | 6 ++-- Sources/Stripe/API/Routes/InvoiceRoutes.swift | 4 +-- Sources/Stripe/API/Routes/OrderRoutes.swift | 2 +- Sources/Stripe/API/Routes/TokenRoutes.swift | 4 +-- Sources/Stripe/API/StripeRequest.swift | 31 ++++++++++++++----- 5 files changed, 32 insertions(+), 15 deletions(-) diff --git a/Sources/Stripe/API/Routes/CustomerRoutes.swift b/Sources/Stripe/API/Routes/CustomerRoutes.swift index 199b94d..4bc6d2f 100644 --- a/Sources/Stripe/API/Routes/CustomerRoutes.swift +++ b/Sources/Stripe/API/Routes/CustomerRoutes.swift @@ -179,7 +179,7 @@ public struct StripeCustomerRoutes: CustomerRoutes { var headers: HTTPHeaders = [:] if let connectedAccount = toConnectedAccount { - headers["Stripe-Account"] = connectedAccount + headers.add(name: .stripeAccount, value: connectedAccount) } return try request.send(method: .POST, path: StripeAPIEndpoint.customerSources(customer).endpoint, body: body.queryParameters, headers: headers) @@ -192,7 +192,7 @@ public struct StripeCustomerRoutes: CustomerRoutes { var headers: HTTPHeaders = [:] if let connectedAccount = toConnectedAccount { - headers["Stripe-Account"] = connectedAccount + headers.add(name: .stripeAccount, value: connectedAccount) } if let source = source as? String { @@ -217,7 +217,7 @@ public struct StripeCustomerRoutes: CustomerRoutes { var headers: HTTPHeaders = [:] if let connectedAccount = toConnectedAccount { - headers["Stripe-Account"] = connectedAccount + headers.add(name: .stripeAccount, value: connectedAccount) } if let source = source as? String { diff --git a/Sources/Stripe/API/Routes/InvoiceRoutes.swift b/Sources/Stripe/API/Routes/InvoiceRoutes.swift index 710f77d..c0037c9 100644 --- a/Sources/Stripe/API/Routes/InvoiceRoutes.swift +++ b/Sources/Stripe/API/Routes/InvoiceRoutes.swift @@ -53,7 +53,7 @@ public struct StripeInvoiceRoutes: InvoiceRoutes { } if let connectAccount = connectAccount { - headers["Stripe-Account"] = connectAccount + headers.add(name: .stripeAccount, value: connectAccount) } if let billing = billing { @@ -135,7 +135,7 @@ public struct StripeInvoiceRoutes: InvoiceRoutes { } if let connectAccount = connectAccount { - headers["Stripe-Account"] = connectAccount + headers.add(name: .stripeAccount, value: connectAccount) } if let closed = closed { diff --git a/Sources/Stripe/API/Routes/OrderRoutes.swift b/Sources/Stripe/API/Routes/OrderRoutes.swift index c8b1c75..5d8362c 100644 --- a/Sources/Stripe/API/Routes/OrderRoutes.swift +++ b/Sources/Stripe/API/Routes/OrderRoutes.swift @@ -136,7 +136,7 @@ public struct StripeOrderRoutes: OrderRoutes { } if let connectAccount = connectAccount { - headers["Stripe-Account"] = connectAccount + headers.add(name: .stripeAccount, value: connectAccount) } if let email = email { diff --git a/Sources/Stripe/API/Routes/TokenRoutes.swift b/Sources/Stripe/API/Routes/TokenRoutes.swift index 670b226..311e9ca 100644 --- a/Sources/Stripe/API/Routes/TokenRoutes.swift +++ b/Sources/Stripe/API/Routes/TokenRoutes.swift @@ -41,7 +41,7 @@ public struct StripeTokenRoutes: TokenRoutes { } if let connectAccount = connectAccount { - headers["Stripe-Account"] = connectAccount + headers.add(name: .stripeAccount, value: connectAccount) } return try request.send(method: .POST, path: StripeAPIEndpoint.tokens.endpoint, body: body.queryParameters, headers: headers) @@ -64,7 +64,7 @@ public struct StripeTokenRoutes: TokenRoutes { } if let connectAccount = connectAccount { - headers["Stripe-Account"] = connectAccount + headers.add(name: .stripeAccount, value: connectAccount) } return try request.send(method: .POST, path: StripeAPIEndpoint.tokens.endpoint, body: body.queryParameters, headers: headers) diff --git a/Sources/Stripe/API/StripeRequest.swift b/Sources/Stripe/API/StripeRequest.swift index 4088065..4c37b35 100644 --- a/Sources/Stripe/API/StripeRequest.swift +++ b/Sources/Stripe/API/StripeRequest.swift @@ -31,14 +31,31 @@ public extension StripeRequest { } } - return try decoder.decode(SM.self, from: response.body) + return try decoder.decode(SM.self, from: response.body, on: worker) + } +} + +extension HTTPHeaderName { + public static var stripeVersion: HTTPHeaderName { + return .init("Stripe-Version") + } + public static var stripeAccount: HTTPHeaderName { + return .init("Stripe-Version") + } +} + +extension HTTPHeaders { + public static var stripeDefault: HTTPHeaders { + var headers: HTTPHeaders = [:] + headers.replaceOrAdd(name: .stripeVersion, value: "2018-02-28") + headers.replaceOrAdd(name: .contentType, value: MediaType.urlEncodedForm.description) + return headers } } public class StripeAPIRequest: StripeRequest { private let httpClient: Client private let apiKey: String - private let StripeDefaultHeaders: HTTPHeaders = ["Stripe-Version": "2018-02-28", .contentType: "application/x-www-form-urlencoded"] init(httpClient: Client, apiKey: String) { self.httpClient = httpClient @@ -48,16 +65,16 @@ public class StripeAPIRequest: StripeRequest { public func send(method: HTTPMethod, path: String, query: String, body: String, headers: HTTPHeaders) throws -> Future { let encodedHTTPBody = HTTPBody(string: body) - var finalHeaders: HTTPHeaders = StripeDefaultHeaders + var finalHeaders: HTTPHeaders = .stripeDefault - headers.forEach { finalHeaders[$0.name] = $0.value } + headers.forEach { finalHeaders.add(name: $0.name, value: $0.value) } - finalHeaders[.authorization] = "Bearer \(apiKey)" + finalHeaders.add(name: .authorization, value: "Bearer \(apiKey)") - let request = HTTPRequest(method: method, uri: URI(stringLiteral: path + "?" + query), headers: StripeDefaultHeaders, body: encodedHTTPBody) + let request = HTTPRequest(method: method, url: URL(string: "\(path)?\(query)") ?? .root, headers: finalHeaders, body: encodedHTTPBody) return try httpClient.respond(to: Request(http: request, using: httpClient.container)).flatMap(to: SM.self) { (response) -> Future in - return try self.serializedResponse(response: response.http) + return try self.serializedResponse(response: response.http, worker: self.httpClient.container.eventLoop) } } } From 7498ad7e998c38d98507cc2ad88b3d5c28d029ef Mon Sep 17 00:00:00 2001 From: Andrew Edwards Date: Thu, 22 Mar 2018 14:07:26 -0400 Subject: [PATCH 16/17] Updates for NIO changes to vapor. --- Sources/Stripe/API/StripeRequest.swift | 6 +++--- Sources/Stripe/Provider/Provider.swift | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Sources/Stripe/API/StripeRequest.swift b/Sources/Stripe/API/StripeRequest.swift index 4c37b35..396b0d7 100644 --- a/Sources/Stripe/API/StripeRequest.swift +++ b/Sources/Stripe/API/StripeRequest.swift @@ -11,7 +11,7 @@ import Vapor import HTTP public protocol StripeRequest: class { - func serializedResponse(response: HTTPResponse) throws -> Future + func serializedResponse(response: HTTPResponse, worker: EventLoop) throws -> Future func send(method: HTTPMethod, path: String, query: String, body: String, headers: HTTPHeaders) throws -> Future } @@ -20,13 +20,13 @@ public extension StripeRequest { return try send(method: method, path: path, query: query, body: body, headers: headers) } - public func serializedResponse(response: HTTPResponse) throws -> Future { + public func serializedResponse(response: HTTPResponse, worker: EventLoop) throws -> Future { let decoder = JSONDecoder() decoder.dateDecodingStrategy = .secondsSince1970 decoder.keyDecodingStrategy = .convertFromSnakeCase guard response.status == .ok else { - return try decoder.decode(StripeAPIError.self, from: response.body).map(to: SM.self) { error in + return try decoder.decode(StripeAPIError.self, from: response.body, on: worker).map(to: SM.self) { error in throw StripeError.apiError(error) } } diff --git a/Sources/Stripe/Provider/Provider.swift b/Sources/Stripe/Provider/Provider.swift index 4e1b725..3954f37 100644 --- a/Sources/Stripe/Provider/Provider.swift +++ b/Sources/Stripe/Provider/Provider.swift @@ -20,10 +20,14 @@ public final class StripeProvider: Provider { public func boot(_ worker: Container) throws {} + public func didBoot(_ worker: Container) throws -> EventLoopFuture { + return .done(on: worker) + } + public func register(_ services: inout Services) throws { services.register { (container) -> StripeClient in - let httpClient = try container.make(Client.self, for: StripeClient.self) - let config = try container.make(StripeConfig.self, for: StripeClient.self) + let httpClient = try container.make(Client.self) + let config = try container.make(StripeConfig.self) return StripeClient(config: config, client: httpClient) } } From 9a7b60204165b53fb893ca1679f12d8b61750829 Mon Sep 17 00:00:00 2001 From: Andrew Edwards Date: Thu, 22 Mar 2018 14:14:50 -0400 Subject: [PATCH 17/17] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b1f86b2..79bee9a 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ And you can always check the documentation to see the required paramaters for sp ## Linux compatibility Currently the project won't compile for linux. -You can track this issue [here](https://bugs.swift.org/browse/SR-7180) +You can track this issue [here](https://bugs.swift.org/browse/SR-7180) and [here](https://github.com/apple/swift-corelibs-foundation/pull/1347) ## Whats Implemented