Skip to content

Commit

Permalink
Merge pull request #47 from vapor-community/update/2.1.0
Browse files Browse the repository at this point in the history
Update/2.1.0
  • Loading branch information
Andrewangeta authored Jun 18, 2018
2 parents a08d75e + 1e7abbc commit b44c55e
Show file tree
Hide file tree
Showing 119 changed files with 1,146 additions and 1,928 deletions.
21 changes: 7 additions & 14 deletions Sources/Stripe/API/Routes/AccountRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,13 @@
import Vapor

public protocol AccountRoutes {
associatedtype AC: ConnectAccount
associatedtype LE: LegalEntity
associatedtype TOS: TOSAcceptance
associatedtype DO: DeletedObject
associatedtype L: List
associatedtype CLL: ConnectLoginLink

func create(type: ConnectedAccountType, email: String?, country: String?, metadata: [String: String]?) throws -> Future<AC>
func retrieve(account: String) throws -> Future<AC>
func update(account: String, businessName: String?, businessPrimaryColor: String?, businessUrl: String?, debitNegativeBalances: Bool?, declineChargeOn: [String: Bool]?, defaultCurrency: StripeCurrency?, email: String?, externalAccount: Any?, legalEntity: LE?, metadata: [String: String]?, payoutSchedule: [String: String]?, payoutStatementDescriptor: String?, productDescription: String?, statementDescriptor: String?, supportEmail: String?, supportPhone: String?, supportUrl: String?, tosAcceptance: TOS?) throws -> Future<AC>
func delete(account: String) throws -> Future<DO>
func reject(account: String, for: AccountRejectReason) throws -> Future<AC>
func listAll(filter: [String: Any]?) throws -> Future<L>
func createLoginLink(for: String) throws -> Future<CLL>
func create(type: ConnectedAccountType, email: String?, country: String?, metadata: [String: String]?) throws -> Future<StripeConnectAccount>
func retrieve(account: String) throws -> Future<StripeConnectAccount>
func update(account: String, businessName: String?, businessPrimaryColor: String?, businessUrl: String?, debitNegativeBalances: Bool?, declineChargeOn: [String: Bool]?, defaultCurrency: StripeCurrency?, email: String?, externalAccount: Any?, legalEntity: StripeConnectAccountLegalEntity?, metadata: [String: String]?, payoutSchedule: [String: String]?, payoutStatementDescriptor: String?, productDescription: String?, statementDescriptor: String?, supportEmail: String?, supportPhone: String?, supportUrl: String?, tosAcceptance: StripeTOSAcceptance?) throws -> Future<StripeConnectAccount>
func delete(account: String) throws -> Future<StripeDeletedObject>
func reject(account: String, for: AccountRejectReason) throws -> Future<StripeConnectAccount>
func listAll(filter: [String: Any]?) throws -> Future<ConnectedAccountsList>
func createLoginLink(for: String) throws -> Future<StripeConnectLoginLink>
}

public struct StripeConnectAccountRoutes: AccountRoutes {
Expand Down
10 changes: 3 additions & 7 deletions Sources/Stripe/API/Routes/BalanceRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@
import Vapor

public protocol BalanceRoutes {
associatedtype B: Balance
associatedtype BT: BalanceTransactionItem
associatedtype BHL: List

func retrieve() throws -> Future<B>
func retrieve(forTransaction: String) throws -> Future<BT>
func listAll(filter: [String: Any]?) throws -> Future<BHL>
func retrieve() throws -> Future<StripeBalance>
func retrieve(forTransaction: String) throws -> Future<StripeBalanceTransactionItem>
func listAll(filter: [String: Any]?) throws -> Future<BalanceHistoryList>
}

public struct StripeBalanceRoutes: BalanceRoutes {
Expand Down
28 changes: 14 additions & 14 deletions Sources/Stripe/API/Routes/ChargeRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,11 @@
import Vapor

public protocol ChargeRoutes {
associatedtype CH: Charge
associatedtype SH: Shipping
associatedtype FD: FraudDetails
associatedtype CHL: List

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: SH?, customer: String?, source: Any?, statementDescriptor: String?) throws -> Future<CH>
func retrieve(charge: String) throws -> Future<CH>
func update(charge: String, customer: String?, description: String?, fraudDetails: FD?, metadata: [String: String]?, receiptEmail: String?, shipping: SH?, transferGroup: String?) throws -> Future<CH>
func capture(charge: String, amount: Int?, applicationFee: Int?, destinationAmount: Int?, receiptEmail: String?, statementDescriptor: String?) throws -> Future<CH>
func listAll(filter: [String: Any]?) throws -> Future<CHL>
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>
func listAll(filter: [String: Any]?) throws -> Future<ChargesList>
}

public struct StripeChargeRoutes: ChargeRoutes {
Expand All @@ -35,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 @@ -46,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 @@ -55,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 @@ -103,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 @@ -203,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)
}
}
14 changes: 5 additions & 9 deletions Sources/Stripe/API/Routes/CouponRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,11 @@ import Foundation
import Vapor

public protocol CouponRoutes {
associatedtype CP: Coupon
associatedtype DO: DeletedObject
associatedtype L: List

func create(id: String?, duration: StripeDuration, amountOff: Int?, currency: StripeCurrency?, durationInMonths: Int?, maxRedemptions: Int?, metadata: [String: String]?, percentOff: Int?, redeemBy: Date?) throws -> Future<CP>
func retrieve(coupon: String) throws -> Future<CP>
func update(coupon: String, metadata: [String: String]?) throws -> Future<CP>
func delete(coupon: String) throws -> Future<DO>
func listAll(filter: [String: Any]?) throws -> Future<L>
func create(id: String?, duration: StripeDuration, amountOff: Int?, currency: StripeCurrency?, durationInMonths: Int?, maxRedemptions: Int?, metadata: [String: String]?, percentOff: Int?, redeemBy: Date?) throws -> Future<StripeCoupon>
func retrieve(coupon: String) throws -> Future<StripeCoupon>
func update(coupon: String, metadata: [String: String]?) throws -> Future<StripeCoupon>
func delete(coupon: String) throws -> Future<StripeDeletedObject>
func listAll(filter: [String: Any]?) throws -> Future<CouponsList>
}

public struct StripeCouponRoutes: CouponRoutes {
Expand Down
30 changes: 11 additions & 19 deletions Sources/Stripe/API/Routes/CustomerRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,16 @@
import Vapor

public protocol CustomerRoutes {
associatedtype C: Customer
associatedtype SH: Shipping
associatedtype DO: DeletedObject
associatedtype L: List
associatedtype SRC: Source
associatedtype BNK: BankAccount
associatedtype CRD: Card

func create(accountBalance: Int?, businessVatId: String?, coupon: String?, defaultSource: String?, description: String?, email: String?, metadata: [String: String]?, shipping: SH?, source: Any?) throws -> Future<C>
func retrieve(customer: String) throws -> Future<C>
func update(customer: String, accountBalance: Int?, businessVatId: String?, coupon: String?, defaultSource: String?, description: String?, email: String?, metadata: [String: String]?, shipping: SH?, source: Any?) throws -> Future<C>
func delete(customer: String) throws -> Future<DO>
func listAll(filter: [String: Any]?) throws -> Future<L>
func addNewSource(customer: String, source: String, toConnectedAccount: String?) throws -> Future<SRC>
func addNewBankAccountSource(customer: String, source: Any, toConnectedAccount: String?, metadata: [String: String]?) throws -> Future<BNK>
func addNewCardSource(customer: String, source: Any, toConnectedAccount: String?, metadata: [String : String]?) throws -> Future<CRD>
func deleteSource(customer: String, source: String) throws -> Future<SRC>
func deleteDiscount(customer: String) throws -> Future<DO>
func create(accountBalance: Int?, businessVatId: String?, coupon: String?, defaultSource: String?, description: String?, email: String?, metadata: [String: String]?, shipping: ShippingLabel?, source: Any?) throws -> Future<StripeCustomer>
func retrieve(customer: String) throws -> Future<StripeCustomer>
func update(customer: String, accountBalance: Int?, businessVatId: String?, coupon: String?, defaultSource: String?, description: String?, email: String?, metadata: [String: String]?, shipping: ShippingLabel?, source: Any?) throws -> Future<StripeCustomer>
func delete(customer: String) throws -> Future<StripeDeletedObject>
func listAll(filter: [String: Any]?) throws -> Future<StripeCustomersList>
func addNewSource(customer: String, source: String, toConnectedAccount: String?) throws -> Future<StripeSource>
func addNewBankAccountSource(customer: String, source: Any, toConnectedAccount: String?, metadata: [String: String]?) throws -> Future<StripeBankAccount>
func addNewCardSource(customer: String, source: Any, toConnectedAccount: String?, metadata: [String : String]?) throws -> Future<StripeCard>
func deleteSource(customer: String, source: String) throws -> Future<StripeSource>
func deleteDiscount(customer: String) throws -> Future<StripeDeletedObject>
}

public struct StripeCustomerRoutes: CustomerRoutes {
Expand Down Expand Up @@ -163,7 +155,7 @@ public struct StripeCustomerRoutes: CustomerRoutes {

/// List all customers
/// [Learn More →](https://stripe.com/docs/api/curl#list_customers)
public func listAll(filter: [String: Any]? = nil) throws -> Future<CustomersList> {
public func listAll(filter: [String: Any]? = nil) throws -> Future<StripeCustomersList> {
var queryParams = ""
if let filter = filter {
queryParams = filter.queryParameters
Expand Down
12 changes: 4 additions & 8 deletions Sources/Stripe/API/Routes/DisputeRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@
import Vapor

public protocol DisputeRoutes {
associatedtype D: Dispute
associatedtype DE: DisputeEvidence
associatedtype L: List

func retrieve(dispute: String) throws -> Future<D>
func update(dispute: String, disputeEvidence: DE?, metadata: [String: String]?, submit: Bool?) throws -> Future<D>
func close(dispute: String) throws -> Future<D>
func listAll(filter: [String: Any]?) throws -> Future<L>
func retrieve(dispute: String) throws -> Future<StripeDispute>
func update(dispute: String, disputeEvidence: StripeDisputeEvidence?, metadata: [String: String]?, submit: Bool?) throws -> Future<StripeDispute>
func close(dispute: String) throws -> Future<StripeDispute>
func listAll(filter: [String: Any]?) throws -> Future<DisputesList>
}

public struct StripeDisputeRoutes: DisputeRoutes {
Expand Down
22 changes: 10 additions & 12 deletions Sources/Stripe/API/Routes/EphemeralKeyRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
import Vapor

public protocol EphemeralKeyRoutes {
associatedtype EK: EphemeralKey

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

public struct StripeEphemeralKeyRoutes: EphemeralKeyRoutes {
Expand All @@ -23,14 +21,14 @@ public struct StripeEphemeralKeyRoutes: EphemeralKeyRoutes {
}

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)
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)
}

public func delete(ephemeralKey: String) throws -> Future<StripeEphemeralKey> {
Expand Down
14 changes: 5 additions & 9 deletions Sources/Stripe/API/Routes/InvoiceItemRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@
import Vapor

public protocol InvoiceItemRoutes {
associatedtype II: InvoiceItem
associatedtype DO: DeletedObject
associatedtype L: List

func create(amount: Int, currency: StripeCurrency, customer: String, description: String?, discountable: Bool?, invoice: String?, metadata: [String: String]?, subscription: String?) throws -> Future<II>
func retrieve(invoiceItem: String) throws -> Future<II>
func update(invoiceItem: String, amount: Int?, description: String?, discountable: Bool?, metadata: [String: String]?) throws -> Future<II>
func delete(invoiceItem: String) throws -> Future<DO>
func listAll(filter: [String: Any]?) throws -> Future<L>
func create(amount: Int, currency: StripeCurrency, customer: String, description: String?, discountable: Bool?, invoice: String?, metadata: [String: String]?, subscription: String?) throws -> Future<StripeInvoiceItem>
func retrieve(invoiceItem: String) throws -> Future<StripeInvoiceItem>
func update(invoiceItem: String, amount: Int?, description: String?, discountable: Bool?, metadata: [String: String]?) throws -> Future<StripeInvoiceItem>
func delete(invoiceItem: String) throws -> Future<StripeDeletedObject>
func listAll(filter: [String: Any]?) throws -> Future<InvoiceItemsList>
}

public struct StripeInvoiceItemRoutes: InvoiceItemRoutes {
Expand Down
19 changes: 8 additions & 11 deletions Sources/Stripe/API/Routes/InvoiceRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@
import Vapor
import Foundation

public protocol InvoiceRoutes {
associatedtype I: Invoice
associatedtype L: List

func create(customer: String, applicationFee: Int?, connectAccount: String?, billing: String?, daysUntilDue: Int?, description: String?, dueDate: Date?, metadata: [String: String]?, statementDescriptor: String?, subscription: String?, taxPercent: Decimal?) throws -> Future<I>
func retrieve(invoice: String) throws -> Future<I>
func retrieveLineItems(invoice: String, filter: [String: Any]?) throws -> Future<L>
func retrieveUpcomingInvoice(customer: String, filter: [String: Any]?) throws -> Future<I>
public protocol InvoiceRoutes {
func create(customer: String, applicationFee: Int?, connectAccount: String?, billing: String?, daysUntilDue: Int?, description: String?, dueDate: Date?, metadata: [String: String]?, statementDescriptor: String?, subscription: String?, taxPercent: Decimal?) throws -> Future<StripeInvoice>
func retrieve(invoice: String) throws -> Future<StripeInvoice>
func retrieveLineItems(invoice: String, filter: [String: Any]?) throws -> Future<InvoiceLineGroup>
func retrieveUpcomingInvoice(customer: String, filter: [String: Any]?) throws -> Future<StripeInvoice>
func update(invoice: String, applicationFee: Int?,
connectAccount: String?, closed: Bool?, description: String?, forgiven: Bool?, metadata: [String: String]?, paid: Bool?, statementDescriptor: String?, taxPercent: Decimal?) throws -> Future<I>
func pay(invoice: String, source: String?) throws -> Future<I>
func listAll(filter: [String: Any]?) throws -> Future<L>
connectAccount: String?, closed: Bool?, description: String?, forgiven: Bool?, metadata: [String: String]?, paid: Bool?, statementDescriptor: String?, taxPercent: Decimal?) throws -> Future<StripeInvoice>
func pay(invoice: String, source: String?) throws -> Future<StripeInvoice>
func listAll(filter: [String: Any]?) throws -> Future<InvoiceLineGroup>
}

public struct StripeInvoiceRoutes: InvoiceRoutes {
Expand Down
9 changes: 3 additions & 6 deletions Sources/Stripe/API/Routes/OrderReturnRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@

import Vapor

public protocol OrderReturnRoutes {
associatedtype OR: OrderReturn
associatedtype L: List

func retrieve(order: String) throws -> Future<OR>
func listAll(filter: [String: Any]?) throws -> Future<L>
public protocol OrderReturnRoutes {
func retrieve(order: String) throws -> Future<StripeOrderReturn>
func listAll(filter: [String: Any]?) throws -> Future<OrderReturnList>
}

public struct StripeOrderReturnRoutes: OrderReturnRoutes {
Expand Down
Loading

0 comments on commit b44c55e

Please sign in to comment.