From 0637d5a29fed19c1d5d35bf75eb8c7165a50a791 Mon Sep 17 00:00:00 2001 From: Kevin Verschoor Date: Tue, 19 May 2026 15:10:36 +0200 Subject: [PATCH 1/4] PLUG-5623 - Add refund function --- examples/refundTransaction.ts | 11 +++++++++++ src/order/OrderApi.ts | 15 +++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 examples/refundTransaction.ts diff --git a/examples/refundTransaction.ts b/examples/refundTransaction.ts new file mode 100644 index 0000000..a662f84 --- /dev/null +++ b/examples/refundTransaction.ts @@ -0,0 +1,11 @@ +import { createPayNLClient } from '../src/index.ts'; + +const payNL = createPayNLClient({ username: 'AT-1234-5678', password: 'your-api-token' }); + +const orderId = '00000000-1111-2222-3333-000000000000'; + +const refund = await payNL.Orders.refund(orderId); +// or +const refund = await payNL.Orders.refund(orderId, 100); + +console.log(refund.description); diff --git a/src/order/OrderApi.ts b/src/order/OrderApi.ts index 9029d35..dc0f5ce 100644 --- a/src/order/OrderApi.ts +++ b/src/order/OrderApi.ts @@ -194,4 +194,19 @@ export class OrderApi { ); return await response.body(); } + + /** + * Refund an order, with amount + * + * @see https://developer.pay.nl/reference/patch_transactions-transactionid-refund + */ + async refund(orderId: string, amountInCents: number): Promise { + const response = await this.apiClient.request( + new RestApiRequest(`v2/transactions/${orderId}/refund`, { + method: 'PATCH', + json: { amount: {value: amountInCents ? amountInCents : null} }, + }), + ); + return await response.body(); + } } From f7de4f72c64a499a0c55f0df9fb11b8f55f12405 Mon Sep 17 00:00:00 2001 From: Kevin Verschoor Date: Wed, 20 May 2026 13:36:09 +0200 Subject: [PATCH 2/4] Make amountInCents Optional --- examples/refundTransaction.ts | 2 +- src/order/OrderApi.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/refundTransaction.ts b/examples/refundTransaction.ts index a662f84..439c85c 100644 --- a/examples/refundTransaction.ts +++ b/examples/refundTransaction.ts @@ -5,7 +5,7 @@ const payNL = createPayNLClient({ username: 'AT-1234-5678', password: 'your-api- const orderId = '00000000-1111-2222-3333-000000000000'; const refund = await payNL.Orders.refund(orderId); -// or +// or const refund = await payNL.Orders.refund(orderId, 100); console.log(refund.description); diff --git a/src/order/OrderApi.ts b/src/order/OrderApi.ts index dc0f5ce..29ed021 100644 --- a/src/order/OrderApi.ts +++ b/src/order/OrderApi.ts @@ -194,19 +194,19 @@ export class OrderApi { ); return await response.body(); } - + /** - * Refund an order, with amount + * Refund an order, with an optional amount. If no amount is specified, the full order amount will be refunded. * * @see https://developer.pay.nl/reference/patch_transactions-transactionid-refund */ - async refund(orderId: string, amountInCents: number): Promise { + async refund(orderId: string, amountInCents?: number): Promise { const response = await this.apiClient.request( new RestApiRequest(`v2/transactions/${orderId}/refund`, { method: 'PATCH', json: { amount: {value: amountInCents ? amountInCents : null} }, }), - ); + ); return await response.body(); } } From 8ad87e643217334abc5a92be9fba4a16174b1649 Mon Sep 17 00:00:00 2001 From: woutse Date: Wed, 20 May 2026 15:19:28 +0200 Subject: [PATCH 3/4] Updated sample --- examples/refundTransaction.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/examples/refundTransaction.ts b/examples/refundTransaction.ts index 439c85c..b60f564 100644 --- a/examples/refundTransaction.ts +++ b/examples/refundTransaction.ts @@ -4,8 +4,12 @@ const payNL = createPayNLClient({ username: 'AT-1234-5678', password: 'your-api- const orderId = '00000000-1111-2222-3333-000000000000'; -const refund = await payNL.Orders.refund(orderId); -// or -const refund = await payNL.Orders.refund(orderId, 100); +try { + const refund = await payNL.Orders.refund(orderId, 100); + console.log(refund.description); +} catch (error) { + console.log(error.statusCode); + console.log(error.body?.detail); + console.log(error.body?.violations); +} -console.log(refund.description); From feca21be923009ec1725e37214136ed22f4608e3 Mon Sep 17 00:00:00 2001 From: woutse Date: Wed, 20 May 2026 15:37:13 +0200 Subject: [PATCH 4/4] Updated sample --- examples/refundTransaction.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/refundTransaction.ts b/examples/refundTransaction.ts index b60f564..c9126c4 100644 --- a/examples/refundTransaction.ts +++ b/examples/refundTransaction.ts @@ -12,4 +12,3 @@ try { console.log(error.body?.detail); console.log(error.body?.violations); } -