Skip to content

Commit

Permalink
Merge pull request #105 from vapor-community/direct-charges
Browse files Browse the repository at this point in the history
charges: Add direct charing
  • Loading branch information
Anthony authored Jul 5, 2019
2 parents bde3f32 + b6d897e commit 9185d94
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Sources/Stripe/API/Routes/ChargeRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public protocol ChargeRoutes {
shipping: [String: Any]?,
source: Any?,
statementDescriptor: String?,
directChargeAccount: String?,
transferData: [String: Any]?,
transferGroup: String?) throws -> Future<StripeCharge>
func retrieve(charge: String) throws -> Future<StripeCharge>
Expand Down Expand Up @@ -49,6 +50,7 @@ extension ChargeRoutes {
shipping: [String: Any]? = nil,
source: Any? = nil,
statementDescriptor: String? = nil,
directChargeAccount: String? = nil,
transferData: [String: Any]? = nil,
transferGroup: String? = nil) throws -> Future<StripeCharge> {
return try create(amount: amount,
Expand All @@ -63,6 +65,7 @@ extension ChargeRoutes {
shipping: shipping,
source: source,
statementDescriptor: statementDescriptor,
directChargeAccount: directChargeAccount,
transferData: transferData,
transferGroup: transferGroup)
}
Expand Down Expand Up @@ -129,6 +132,7 @@ public struct StripeChargeRoutes: ChargeRoutes {
shipping: [String: Any]?,
source: Any?,
statementDescriptor: String?,
directChargeAccount: String?,
transferData: [String: Any]?,
transferGroup: String?) throws -> Future<StripeCharge> {
var body: [String: Any] = ["amount": amount, "currency": currency.rawValue]
Expand Down Expand Up @@ -184,7 +188,12 @@ public struct StripeChargeRoutes: ChargeRoutes {
body["transfer_group"] = transferGroup
}

return try request.send(method: .POST, path: StripeAPIEndpoint.charges.endpoint, body: body.queryParameters)
var headers: HTTPHeaders = [:]
if let directChargeAccount = directChargeAccount {
headers.replaceOrAdd(name: HTTPHeaderName.stripeAccount, value: directChargeAccount)
}

return try request.send(method: .POST, path: StripeAPIEndpoint.charges.endpoint, body: body.queryParameters, headers: headers)
}

/// Retrieve a charge
Expand Down

0 comments on commit 9185d94

Please sign in to comment.