From 1d9fbc3e7c36a58f83c1bed6f8f4a08b10a4cbbc Mon Sep 17 00:00:00 2001 From: Chris Ball Date: Wed, 17 Jul 2024 11:48:27 -0400 Subject: [PATCH] add expand to products (#260) Co-authored-by: Andrew Edwards --- .../Products/Products/ProductRoutes.swift | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/Sources/StripeKit/Products/Products/ProductRoutes.swift b/Sources/StripeKit/Products/Products/ProductRoutes.swift index 39cf92c1..49e3436b 100644 --- a/Sources/StripeKit/Products/Products/ProductRoutes.swift +++ b/Sources/StripeKit/Products/Products/ProductRoutes.swift @@ -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: @@ -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. /// @@ -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 @@ -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, @@ -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 { @@ -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) }