Skip to content

Commit 1d9fbc3

Browse files
cballAndrewangeta
andauthored
add expand to products (#260)
Co-authored-by: Andrew Edwards <[email protected]>
1 parent 4af10ac commit 1d9fbc3

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

Sources/StripeKit/Products/Products/ProductRoutes.swift

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@ public protocol ProductRoutes: StripeAPIRoute {
4040
statementDescriptor: String?,
4141
taxCode: String?,
4242
unitLabel: String?,
43-
url: String?) async throws -> Product
43+
url: String?,
44+
expand: [String]?) async throws -> Product
4445

4546
/// 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.
4647
///
4748
/// - Parameter id: The identifier of the product to be retrieved.
4849
/// - Returns: Returns a product object if a valid identifier was provided.
49-
func retrieve(id: String) async throws -> Product
50+
func retrieve(id: String, expand: [String]?) async throws -> Product
5051

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

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

129132
body["name"] = name
@@ -175,12 +178,20 @@ public struct StripeProductRoutes: ProductRoutes {
175178
if let url {
176179
body["url"] = url
177180
}
181+
182+
if let expand {
183+
body["expand"] = expand
184+
}
178185

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

182-
public func retrieve(id: String) async throws -> Product {
183-
try await apiHandler.send(method: .GET, path: "\(products)/\(id)", headers: headers)
189+
public func retrieve(id: String, expand: [String]? = nil) async throws -> Product {
190+
var queryParams = ""
191+
if let expand {
192+
queryParams = ["expand": expand].queryParameters
193+
}
194+
return try await apiHandler.send(method: .GET, path: "\(products)/\(id)", query: queryParams, headers: headers)
184195
}
185196

186197
public func update(product: String,
@@ -195,7 +206,8 @@ public struct StripeProductRoutes: ProductRoutes {
195206
statementDescriptor: String? = nil,
196207
taxCode: String? = nil,
197208
unitLabel: String? = nil,
198-
url: String? = nil) async throws -> Product {
209+
url: String? = nil,
210+
expand: [String]? = nil) async throws -> Product {
199211
var body: [String: Any] = [:]
200212

201213
if let active {
@@ -245,6 +257,10 @@ public struct StripeProductRoutes: ProductRoutes {
245257
if let url {
246258
body["url"] = url
247259
}
260+
261+
if let expand {
262+
body["expand"] = expand
263+
}
248264

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

0 commit comments

Comments
 (0)