Skip to content

Commit

Permalink
Added support for direct charges to connect accounts via the Stripe-A…
Browse files Browse the repository at this point in the history
…ccount header.
  • Loading branch information
Andrewangeta committed Jun 17, 2018
1 parent f172cc6 commit 1e7abbc
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Sources/Stripe/API/Routes/ChargeRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Vapor

public protocol ChargeRoutes {
func create(amount: Int, currency: StripeCurrency, applicationFee: Int?, capture: Bool?, description: String?, destinationAccount: String?, destinationAmount: Int?, transferGroup: String?, onBehalfOf: String?, metadata: [String: String]?, receiptEmail: String?, shipping: ShippingLabel?, customer: String?, source: Any?, statementDescriptor: String?) throws -> Future<StripeCharge>
func create(amount: Int, currency: StripeCurrency, applicationFee: Int?, capture: Bool?, description: String?, directAccountHeader: String?, destinationAccount: String?, destinationAmount: Int?, transferGroup: String?, onBehalfOf: String?, metadata: [String: String]?, receiptEmail: String?, shipping: ShippingLabel?, customer: String?, source: Any?, statementDescriptor: String?) throws -> Future<StripeCharge>
func retrieve(charge: String) throws -> Future<StripeCharge>
func update(charge: String, customer: String?, description: String?, fraudDetails: StripeFraudDetails?, metadata: [String: String]?, receiptEmail: String?, shipping: ShippingLabel?, transferGroup: String?) throws -> Future<StripeCharge>
func capture(charge: String, amount: Int?, applicationFee: Int?, destinationAmount: Int?, receiptEmail: String?, statementDescriptor: String?) throws -> Future<StripeCharge>
Expand All @@ -30,6 +30,7 @@ public struct StripeChargeRoutes: ChargeRoutes {
applicationFee: Int? = nil,
capture: Bool? = nil,
description: String? = nil,
directAccountHeader: String? = nil,
destinationAccount: String? = nil,
destinationAmount: Int? = nil,
transferGroup: String? = nil,
Expand All @@ -41,7 +42,7 @@ public struct StripeChargeRoutes: ChargeRoutes {
source: Any? = nil,
statementDescriptor: String? = nil) throws -> Future<StripeCharge> {
var body: [String: Any] = ["amount": amount, "currency": currency.rawValue]

var headers: HTTPHeaders = [:]
if let applicationFee = applicationFee {
body["application_fee"] = applicationFee
}
Expand All @@ -50,6 +51,10 @@ public struct StripeChargeRoutes: ChargeRoutes {
body["capture"] = capture
}

if let directAccountHeader = directAccountHeader {
headers.replaceOrAdd(name: HTTPHeaderName.stripeAccount, value: directAccountHeader)
}

if let description = description {
body["description"] = description
}
Expand Down Expand Up @@ -98,15 +103,15 @@ 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, headers: headers)
}

/// Retrieve a charge
/// [Learn More →](https://stripe.com/docs/api/curl#retrieve_charge)
public func retrieve(charge: String) throws -> Future<StripeCharge> {
return try request.send(method: .GET, path: StripeAPIEndpoint.charge(charge).endpoint)
}

/// Update a charge
/// [Learn More →](https://stripe.com/docs/api/curl#update_charge)
public func update(charge chargeId: String,
Expand Down Expand Up @@ -198,7 +203,7 @@ public struct StripeChargeRoutes: ChargeRoutes {
if let filter = filter {
queryParams = filter.queryParameters
}

return try request.send(method: .GET, path: StripeAPIEndpoint.account.endpoint, query: queryParams)
}
}

0 comments on commit 1e7abbc

Please sign in to comment.