//native
type Mollie = {
token: string;
};
/**
* Create payment refund
* Creates a refund for a specific payment. The refunded amount is credited to your customer usually either via a bank transfer or by refunding the amount to your customer's credit card.
> 🔑 Access with
>
> API key
>
> Access token with **refunds.write**
*/
export async function main(
auth: Mollie,
paymentId: string,
body: {
resource?: string;
id?: string;
mode?: string;
description?: string;
amount: { currency: string; value: string };
settlementAmount?: { currency: string; value: string };
metadata?: string | {} | string[];
paymentId?: string;
settlementId?: string;
status?: string;
createdAt?: string;
externalReference?: { type?: string; id?: string };
reverseRouting?: false | true;
routingReversals?: {
amount?: { currency: string; value: string };
source?: { type?: string; organizationId?: string };
}[];
testmode?: false | true;
_links?: {
self?: { href?: string; type?: string };
payment?: { href?: string; type?: string };
settlement?: { href?: string; type?: string };
documentation?: { href?: string; type?: string };
};
},
) {
const url = new URL(
`https://api.mollie.com/v2/payments/${paymentId}/refunds`,
);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.text();
}
Submitted by hugo697 428 days ago