Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions examples/refundTransaction.ts
Original file line number Diff line number Diff line change
@@ -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);
}
15 changes: 15 additions & 0 deletions src/order/OrderApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,19 @@
);
return await response.body<Order>();
}

/**
* 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<Order> {
const response = await this.apiClient.request(
new RestApiRequest(`v2/transactions/${orderId}/refund`, {
method: 'PATCH',
json: { amount: {value: amountInCents ? amountInCents : null} },

Check failure on line 207 in src/order/OrderApi.ts

View workflow job for this annotation

GitHub Actions / lint-and-type-check

Replace `value:·amountInCents·?·amountInCents·:·null` with `·value:·amountInCents·?·amountInCents·:·null·`
}),
);
return await response.body<Order>();
}
}
Loading