1 import { HttpTypes } from "@medusajs/types"
2 import { Client } from "../client.js"
3 import { ClientHeaders } from "../types.js"
4
5 export class RefundReason {
6 /**
7 * @ignore
8 */
9 private client: Client
10 /**
11 * @ignore
12 */
13 constructor(client: Client) {
14 this.client = client
15 }
16
17 /**
18 * This method retrieves a list of refund reasons. It sends a request to the
19 * [List Refund Reasons](https://docs.medusajs.com/api/admin/refund-reasons/list-refund-reasons)
20 * API route.
21 *
22 * @param query - Filters and pagination configurations.
23 * @param headers - Headers to pass in the request.
24 * @returns The paginated list of refund reasons.
25 *
26 * @example
27 * To retrieve the list of refund reasons:
28 *
29 * ```ts
30 * sdk.admin.refundReason.list()
31 * .then(({ refund_reasons, count, limit, offset }) => {
32 * console.log(refund_reasons)
33 * })
34 * ```
35 *
36 * To configure the pagination, pass the `limit` and `offset` query parameters.
37 *
38 * For example, to retrieve only 10 items and skip 10 items:
39 *
40 * ```ts
41 * sdk.admin.refundReason.list({
42 * limit: 10,
43 * offset: 10
44 * })
45 * .then(({ refund_reasons, count, limit, offset }) => {
46 * console.log(refund_reasons)
47 * })
48 * ```
49 *
50 * Using the `fields` query parameter, you can specify the fields and relations to retrieve
51 * in each refund reason:
52 *
53 * ```ts
54 * sdk.admin.refundReason.list({
55 * fields: "id,label"
56 * })
57 * .then(({ refund_reasons, count, limit, offset }) => {
58 * console.log(refund_reasons)
59 * })
60 * ```
61 *
62 * Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/admin/select-fields-and-relations).
63 *
64 */
65 async list(
66 query?: HttpTypes.AdminRefundReasonListParams,
67 headers?: ClientHeaders
68 ) {
69 return await this.client.fetch<HttpTypes.RefundReasonsResponse>(
70 `/admin/refund-reasons`,
71 {
72 query,
73 headers,
74 }
75 )
76 }
77
78 /**
79 * This method retrieves a refund reason by ID. It sends a request to the
80 * [Get Refund Reason](https://docs.medusajs.com/api/admin/refund-reasons/get-a-refund-reason)
81 * API route.
82 *
83 * @since 2.11.0
84 *
85 * @param id - The refund reason's ID.
86 * @param query - Configure the fields and relations to retrieve in the refund reason.
87 * @param headers - Headers to pass in the request.
88 * @returns The refund reason's details.
89 *
90 * @example
91 * To retrieve a refund reason by its ID:
92 *
93 * ```ts
94 * sdk.admin.refundReason.retrieve("refr_123")
95 * .then(({ refund_reason }) => {
96 * console.log(refund_reason)
97 * })
98 * ```
99 *
100 * To specify the fields and relations to retrieve:
101 *
102 * ```ts
103 * sdk.admin.refundReason.retrieve("refr_123", {
104 * fields: "id,code"
105 * })
106 * .then(({ refund_reason }) => {
107 * console.log(refund_reason)
108 * })
109 * ```
110 *
111 * Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/admin/select-fields-and-relations).
112 */
113 async retrieve(
114 id: string,
115 query?: HttpTypes.AdminRefundReasonParams,
116 headers?: ClientHeaders
117 ) {
118 return await this.client.fetch<HttpTypes.AdminRefundReasonResponse>(
119 `/admin/refund-reasons/${id}`,
120 {
121 query,
122 headers,
123 }
124 )
125 }
126
127 /**
128 * This method creates a refund reason. It sends a request to the
129 * [Create Refund Reason](https://docs.medusajs.com/api/admin/refund-reasons/create-refund-reason)
130 * API route.
131 *
132 * @since 2.11.0
133 *
134 * @param body - The details of the refund reason to create.
135 * @param query - Configure the fields and relations to retrieve in the refund reason.
136 * @param headers - Headers to pass in the request.
137 * @returns The refund reason's details.
138 *
139 * @example
140 * sdk.admin.refundReason.create({
141 * code: "refund",
142 * label: "Refund",
143 * })
144 * .then(({ refund_reason }) => {
145 * console.log(refund_reason)
146 * })
147 */
148 async create(
149 body: HttpTypes.AdminCreateRefundReason,
150 query?: HttpTypes.AdminRefundReasonParams,
151 headers?: ClientHeaders
152 ) {
153 return this.client.fetch<HttpTypes.AdminRefundReasonResponse>(
154 `/admin/refund-reasons`,
155 {
156 method: "POST",
157 headers,
158 body,
159 query,
160 }
161 )
162 }
163
164 /**
165 * This method updates a refund reason. It sends a request to the
166 * [Update Refund Reason](https://docs.medusajs.com/api/admin/refund-reasons/update-a-refund-reason)
167 * API route.
168 *
169 * @since 2.11.0
170 *
171 * @param id - The refund reason's ID.
172 * @param body - The details of the refund reason to update.
173 * @param query - Configure the fields and relations to retrieve in the refund reason.
174 * @param headers - Headers to pass in the request.
175 * @returns The refund reason's details.
176 *
177 * @example
178 * sdk.admin.refundReason.update("ret_123", {
179 * code: "refund",
180 * label: "Refund",
181 * })
182 * .then(({ refund_reason }) => {
183 * console.log(refund_reason)
184 * })
185 */
186 async update(
187 id: string,
188 body: HttpTypes.AdminUpdateRefundReason,
189 query?: HttpTypes.AdminRefundReasonParams,
190 headers?: ClientHeaders
191 ) {
192 return this.client.fetch<HttpTypes.AdminRefundReasonResponse>(
193 `/admin/refund-reasons/${id}`,
194 {
195 method: "POST",
196 headers,
197 body,
198 query,
199 }
200 )
201 }
202
203 /**
204 * This method deletes a refund reason. It sends a request to the
205 * [Delete Refund Reason](https://docs.medusajs.com/api/admin/refund-reasons/delete-a-refund-reason)
206 * API route.
207 *
208 * @since 2.11.0
209 *
210 * @param id - The refund reason's ID.
211 * @param query - Query parameters to pass to the request.
212 * @param headers - Headers to pass in the request.
213 * @returns The deletion's details.
214 *
215 * @example
216 * sdk.admin.refundReason.delete("ret_123")
217 * .then(({ deleted }) => {
218 * console.log(deleted)
219 * })
220 */
221 async delete(
222 id: string,
223 query?: HttpTypes.AdminRefundReasonParams,
224 headers?: ClientHeaders
225 ) {
226 return await this.client.fetch<HttpTypes.AdminRefundReasonDeleteResponse>(
227 `/admin/refund-reasons/${id}`,
228 {
229 method: "DELETE",
230 headers,
231 query,
232 }
233 )
234 }
235 }