Skip to content

Commit

Permalink
Merge pull request #8 from vapor-community/Relay
Browse files Browse the repository at this point in the history
Added all Relay functionality. Orders, Order Items, Returns, and Products.
  • Loading branch information
anthonycastelli authored Aug 26, 2017
2 parents 8f674b7 + 33e4a5b commit ee5137b
Show file tree
Hide file tree
Showing 37 changed files with 2,725 additions and 37 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,11 @@ XCTMain([
* [x] Listing All Accounts (With filters)
* [x] Rejecting accounts
* [x] Creating dashboard login link for express accounts
* [x] Orders
* [x] Order Items
* [x] Products
* [ ] Disputes
* [ ] Cards
* [ ] Orders
* [ ] Order Items

[stripe_home]: http://stripe.com "Stripe"
[stripe_api]: https://stripe.com/docs/api "Stripe API Endpoints"
Expand Down
57 changes: 55 additions & 2 deletions Sources/API/Filter/StripeFilter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ public final class StripeFilter {
*/
public var balanceType: BalanceType?


/**
The status of the subscriptions to retrieve.
*/
Expand All @@ -111,6 +110,42 @@ public final class StripeFilter {
*/
public var plan: Node?

/**
Only return SKUs that have the specified key/value pairs in this partially constructed dictionary.
*/
public var attributes: Node?

/**
Only return SKUs that are active or inactive
Also used for products.
*/
public var active: Node?

/**
Only return SKUs that are either in stock or out of stock
*/
public var inStock: Node?

/**
The ID of the product whose SKUs will be retrieved.
*/
public var product: Node?

/**
Only return products that can be shipped (i.e., physical, not digital products).
*/
public var shippable: Node?

/**
Only return products with the given url.
*/
public var url: Node?

/**
Only return SKUs with the given IDs.
*/
public var skuIds: Node?

internal func createBody() throws -> Node {
var node = Node([:])
if let value = self.created {
Expand All @@ -123,7 +158,7 @@ public final class StripeFilter {
}
}

if let value = self.created {
if let value = self.availableOn {
if let value = value.object {
for (key, value) in value {
node["available_on[\(key)]"] = value
Expand Down Expand Up @@ -178,6 +213,24 @@ public final class StripeFilter {
node["plan"] = value
}

if let value = attributes?.object {
for (key, value) in value {
node["attributes[\(key)]"] = value
}
}

if let shippable = self.shippable {
node["shippable"] = shippable
}

if let url = self.url {
node["url"] = url
}

if let skuids = skuIds?.array {
node["id"] = Node(skuids)
}

return node
}

Expand Down
45 changes: 44 additions & 1 deletion Sources/API/Helpers/Endpoints.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal let APIVersion = "v1/"

internal let DefaultHeaders = [
HeaderKey.contentType: "application/x-www-form-urlencoded",
StripeHeader.Version: "2017-06-05"
StripeHeader.Version: "2017-08-15"
]

internal struct StripeHeader {
Expand Down Expand Up @@ -131,6 +131,35 @@ internal enum API {
case disputes(String)
case closeDispute(String)

/**
SKUS
Stores representations of stock keeping units. SKUs describe specific product variations.
*/
case sku
case skus(String)

/**
PRODUCTS
Store representations of products you sell in product objects, used in conjunction with SKUs.
*/
case product
case products(String)

/**
ORDERS
The purchase of previously defined products
*/
case order
case orders(String)
case ordersPay(String)
case ordersReturn(String)

/**
RETURNS
A return represents the full or partial return of a number of order items.
*/
case orderReturn
case orderReturns(String)

var endpoint: String {
switch self {
Expand Down Expand Up @@ -177,6 +206,20 @@ internal enum API {
case .dispute: return APIBase + APIVersion + "disputes"
case .disputes(let id): return APIBase + APIVersion + "disputes/\(id)"
case .closeDispute(let id): return APIBase + APIVersion + "disputes/\(id)/close"

case .sku: return APIBase + APIVersion + "skus"
case .skus(let id): return APIBase + APIVersion + "skus/\(id)"

case .product: return APIBase + APIVersion + "products"
case .products(let id): return APIBase + APIVersion + "products/\(id)"

case .order: return APIBase + APIVersion + "orders"
case .orders(let id): return APIBase + APIVersion + "orders/\(id)"
case .ordersPay(let id): return APIBase + APIVersion + "orders/\(id)/pay"
case .ordersReturn(let id): return APIBase + APIVersion + "orders/\(id)/returns"

case .orderReturn: return APIBase + APIVersion + "order_returns"
case .orderReturns(let id): return APIBase + APIVersion + "order_returns/\(id)"
}
}
}
7 changes: 4 additions & 3 deletions Sources/API/Routes/CustomerRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,8 @@ public final class CustomerRoutes {

/**
Delete a customer discount
Permanently deletes a customer. It cannot be undone. Also immediately cancels any active subscriptions on the customer.
Removes the currently applied discount on a customer.


- parameter customerId: The Customer's ID

Expand All @@ -395,8 +396,8 @@ public final class CustomerRoutes {
}

/**
Delete a customer discount
Removes the currently applied discount on a customer.
Delete a customer
Permanently deletes a customer. It cannot be undone. Also immediately cancels any active subscriptions on the customer.

- parameter customerId: The Customer's ID

Expand Down
34 changes: 34 additions & 0 deletions Sources/API/Routes/OrderReturnRoutes.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// OrderReturnRoutes.swift
// Stripe
//
// Created by Andrew Edwards on 8/25/17.
//
//

import Foundation
import Node
import Models
import Helpers
import HTTP

public final class OrderReturnRoutes {
let client: StripeClient

init(client: StripeClient) {
self.client = client
}

public func retrieve(orderReturn orderReturnId: String) throws -> StripeRequest<OrderReturn> {
return try StripeRequest(client: self.client, method: .get, route: .orderReturns(orderReturnId), query: [:], body: nil, headers: nil)
}

public func listAll(filter: StripeFilter? = nil) throws -> StripeRequest<OrderReturnList> {
var query = [String : NodeRepresentable]()

if let data = try filter?.createQuery() {
query = data
}
return try StripeRequest(client: self.client, method: .get, route: .orderReturn, query: query, body: nil, headers: nil)
}
}
Loading

0 comments on commit ee5137b

Please sign in to comment.