Skip to content

Commit

Permalink
Finally working
Browse files Browse the repository at this point in the history
  • Loading branch information
Sorix committed Jun 5, 2018
1 parent 357e9d1 commit e71d88c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 7 additions & 4 deletions Sources/Stripe/API/Routes/EphemeralKeyRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Vapor
public protocol EphemeralKeyRoutes {
associatedtype EK: EphemeralKey

func create(customer: String, apiVersion: String) throws -> Future<EK>
func create(customer: String, apiVersion: String?) throws -> Future<EK>
func delete(ephemeralKey: String) throws -> Future<EK>
}

Expand All @@ -22,9 +22,12 @@ public struct StripeEphemeralKeyRoutes: EphemeralKeyRoutes {
self.request = request
}

public func create(customer: String, apiVersion: String) throws -> Future<StripeEphemeralKey> {
var headers = HTTPHeaders()
headers.add(name: "stripe_version", value: apiVersion)
public func create(customer: String, apiVersion: String? = nil) throws -> Future<StripeEphemeralKey> {
var headers: HTTPHeaders = [:]

if let otherApiVersion = apiVersion {
headers.replaceOrAdd(name: .stripeVersion, value: otherApiVersion)
}

let body = ["customer": customer]
return try request.send(method: .POST, path: StripeAPIEndpoint.ephemeralKeys.endpoint, body: body.queryParameters, headers: headers)
Expand Down
4 changes: 3 additions & 1 deletion Sources/Stripe/API/StripeRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ public class StripeAPIRequest: StripeRequest {
public func send<SM: StripeModel>(method: HTTPMethod, path: String, query: String, body: String, headers: HTTPHeaders) throws -> Future<SM> {
var finalHeaders: HTTPHeaders = .stripeDefault

headers.forEach { finalHeaders.add(name: $0.name, value: $0.value) }
headers.forEach {
finalHeaders.replaceOrAdd(name: $0.name, value: $0.value)
}

// Get the appropiate API key based on the environment and if the test key is present
let apiKey = self.httpClient.container.environment == .development ? (self.testApiKey ?? self.apiKey) : self.apiKey
Expand Down

0 comments on commit e71d88c

Please sign in to comment.