Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add expand to product endpoints #260

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions Sources/StripeKit/Products/Products/ProductRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ public protocol ProductRoutes: StripeAPIRoute {
statementDescriptor: String?,
taxCode: String?,
unitLabel: String?,
url: String?) async throws -> Product
url: String?,
expand: [String]?) async throws -> Product

/// Retrieves the details of an existing product. Supply the unique product ID from either a product creation request or the product list, and Stripe will return the corresponding product information.
///
/// - Parameter id: The identifier of the product to be retrieved.
/// - Returns: Returns a product object if a valid identifier was provided.
func retrieve(id: String) async throws -> Product
func retrieve(id: String, expand: [String]?) async throws -> Product

/// Updates the specific product by setting the values of the parameters passed. Any parameters not provided will be left unchanged.
/// - Parameters:
Expand Down Expand Up @@ -77,7 +78,8 @@ public protocol ProductRoutes: StripeAPIRoute {
statementDescriptor: String?,
taxCode: String?,
unitLabel: String?,
url: String?) async throws -> Product
url: String?,
expand: [String]?) async throws -> Product

/// Returns a list of your products. The products are returned sorted by creation date, with the most recently created products appearing first.
///
Expand Down Expand Up @@ -123,7 +125,8 @@ public struct StripeProductRoutes: ProductRoutes {
statementDescriptor: String? = nil,
taxCode: String? = nil,
unitLabel: String? = nil,
url: String? = nil) async throws -> Product {
url: String? = nil,
expand: [String]? = nil) async throws -> Product {
var body: [String: Any] = [:]

body["name"] = name
Expand Down Expand Up @@ -175,12 +178,20 @@ public struct StripeProductRoutes: ProductRoutes {
if let url {
body["url"] = url
}

if let expand {
body["expand"] = expand
}

return try await apiHandler.send(method: .POST, path: products, body: .string(body.queryParameters), headers: headers)
}

public func retrieve(id: String) async throws -> Product {
try await apiHandler.send(method: .GET, path: "\(products)/\(id)", headers: headers)
public func retrieve(id: String, expand: [String]? = nil) async throws -> Product {
var queryParams = ""
if let expand {
queryParams = ["expand": expand].queryParameters
}
return try await apiHandler.send(method: .GET, path: "\(products)/\(id)", query: queryParams, headers: headers)
}

public func update(product: String,
Expand All @@ -195,7 +206,8 @@ public struct StripeProductRoutes: ProductRoutes {
statementDescriptor: String? = nil,
taxCode: String? = nil,
unitLabel: String? = nil,
url: String? = nil) async throws -> Product {
url: String? = nil,
expand: [String]? = nil) async throws -> Product {
var body: [String: Any] = [:]

if let active {
Expand Down Expand Up @@ -245,6 +257,10 @@ public struct StripeProductRoutes: ProductRoutes {
if let url {
body["url"] = url
}

if let expand {
body["expand"] = expand
}

return try await apiHandler.send(method: .POST, path: "\(products)/\(product)", body: .string(body.queryParameters), headers: headers)
}
Expand Down
Loading