Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Fix: send refund_reason_id from @spree/admin-sdk refunds.create (#14696)
Damian Legawiecd065d0b79304
diff --git a/.changeset/admin-sdk-refund-reason-param.md b/.changeset/admin-sdk-refund-reason-param.mdnew file mode 100644index 0000000000..ca1ebf8e4f--- /dev/null+++ b/.changeset/admin-sdk-refund-reason-param.md@@ -0,0 +1,5 @@+---+"@spree/admin-sdk": patch+---++`orders.refunds.create` no longer accepts `reason_id`. The Admin API only reads `refund_reason_id` (matching the `Refund` response field), so a `reason_id` was silently dropped and the refund fell back to the store's first refund reason. The params are now typed as `RefundCreateParams`; pass `refund_reason_id` instead.diff --git a/packages/admin-sdk/src/admin-client.ts b/packages/admin-sdk/src/admin-client.tsindex 5dbb9648e1..1b0f05827a 100644--- a/packages/admin-sdk/src/admin-client.ts+++ b/packages/admin-sdk/src/admin-client.ts@@ -337,6 +337,7 @@ import type {ReasonCreateParams,ReasonUpdateParams,ReceivableCloseParams,+ RefundCreateParams,ResourceTypeDefinition,ReturnCreateParams,ReturnReceiveParams,@@ -2135,13 +2136,7 @@ export class AdminClient {create: (orderId: string,- params: {- payment_id: string- /** Decimal amount; see `PaymentCreateParams.amount` for the string rationale. */- amount: string | number- reason_id?: string- refund_reason_id?: string- },+ params: RefundCreateParams,options?: RequestOptions,): Promise<Refund> =>this.request<Refund>('POST', `/orders/${orderId}/refunds`, { ...options, body: params }),diff --git a/packages/admin-sdk/src/params.ts b/packages/admin-sdk/src/params.tsindex 4060f19132..41a17607f6 100644--- a/packages/admin-sdk/src/params.ts+++ b/packages/admin-sdk/src/params.ts@@ -204,6 +204,7 @@ export interface RefundCreateParams {payment_id: string/** Decimal amount; see `PaymentCreateParams.amount` for the string rationale. */amount: string | number+ /** Refund reason ID (`refrsn_…`). Omitted → the store's first refund reason. */refund_reason_id?: string}diff --git a/packages/admin-sdk/tests/orders.test.ts b/packages/admin-sdk/tests/orders.test.tsindex e23d3e830c..3db3a2a528 100644--- a/packages/admin-sdk/tests/orders.test.ts+++ b/packages/admin-sdk/tests/orders.test.ts@@ -234,6 +234,24 @@ describe('orders', () => {expect(body).toEqual({ payment_id: 'pay_1', amount: 10 })})++ it('sends the reason as refund_reason_id, the param the API reads', async () => {+ let body: Record<string, unknown> | null = null+ server.use(+ http.post(`${API_PREFIX}/orders/order_abc123/refunds`, async ({ request }) => {+ body = (await request.json()) as Record<string, unknown>+ return HttpResponse.json(sampleRefund, { status: 201 })+ }),+ )++ await createTestClient().orders.refunds.create('order_abc123', {+ payment_id: 'pay_1',+ amount: '5.00',+ refund_reason_id: 'refrsn_1',+ })++ expect(body).toEqual({ payment_id: 'pay_1', amount: '5.00', refund_reason_id: 'refrsn_1' })+ })})describe('nested gift cards & store credits', () => {