//native
type Mollie = {
token: string;
};
/**
* Get payment method
* Retrieve a single payment method by its ID.
*/
export async function main(
auth: Mollie,
id: string,
locale: string | undefined,
currency: string | undefined,
profileId: string | undefined,
include: "issuers" | "pricing" | undefined,
sequenceType: string | undefined,
testmode: string | undefined,
) {
const url = new URL(`https://api.mollie.com/v2/methods/${id}`);
for (const [k, v] of [
["locale", locale],
["currency", currency],
["profileId", profileId],
["include", include],
["sequenceType", sequenceType],
["testmode", testmode],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.text();
}
Submitted by hugo697 428 days ago