diff --git a/examples/refundTransaction.ts b/examples/refundTransaction.ts new file mode 100644 index 0000000..c9126c4 --- /dev/null +++ b/examples/refundTransaction.ts @@ -0,0 +1,14 @@ +import { createPayNLClient } from '../src/index.ts'; + +const payNL = createPayNLClient({ username: 'AT-1234-5678', password: 'your-api-token' }); + +const orderId = '00000000-1111-2222-3333-000000000000'; + +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); +} diff --git a/src/order/OrderApi.ts b/src/order/OrderApi.ts index 9029d35..29ed021 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 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 { + const response = await this.apiClient.request( + new RestApiRequest(`v2/transactions/${orderId}/refund`, { + method: 'PATCH', + json: { amount: {value: amountInCents ? amountInCents : null} }, + }), + ); + return await response.body(); + } }