type Stripe = {
token: string;
};
/**
* Post terminal readers reader refund payment
* Initiates a refund on a Reader
*/
export async function main(
auth: Stripe,
reader: string,
body: {
amount?: number;
charge?: string;
expand?: string[];
metadata?: { [k: string]: string };
payment_intent?: string;
refund_application_fee?: boolean;
refund_payment_config?: {
enable_customer_cancellation?: boolean;
[k: string]: unknown;
};
reverse_transfer?: boolean;
}
) {
const url = new URL(
`https://api.stripe.com/v1/terminal/readers/${reader}/refund_payment`
);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Authorization: "Bearer " + auth.token,
},
body: encodeParams(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
function encodeParams(o: any) {
function iter(o: any, path: string) {
if (Array.isArray(o)) {
o.forEach(function (a) {
iter(a, path + "[]");
});
return;
}
if (o !== null && typeof o === "object") {
Object.keys(o).forEach(function (k) {
iter(o[k], path + "[" + k + "]");
});
return;
}
data.push(path + "=" + o);
}
const data: string[] = [];
Object.keys(o).forEach(function (k) {
if (o[k] !== undefined) {
iter(o[k], k);
}
});
return new URLSearchParams(data.join("&"));
}
Submitted by hugo697 322 days ago
type Stripe = {
token: string;
};
/**
* Post terminal readers reader refund payment
* <p>Initiates a refund on a Reader</p>
*/
export async function main(
auth: Stripe,
reader: string,
body: {
amount?: number;
charge?: string;
expand?: string[];
metadata?: { [k: string]: string };
payment_intent?: string;
refund_application_fee?: boolean;
reverse_transfer?: boolean;
}
) {
const url = new URL(
`https://api.stripe.com/v1/terminal/readers/${reader}/refund_payment`
);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Authorization: "Bearer " + auth.token,
},
body: encodeParams(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
function encodeParams(o: any) {
function iter(o: any, path: string) {
if (Array.isArray(o)) {
o.forEach(function (a) {
iter(a, path + "[]");
});
return;
}
if (o !== null && typeof o === "object") {
Object.keys(o).forEach(function (k) {
iter(o[k], path + "[" + k + "]");
});
return;
}
data.push(path + "=" + o);
}
const data: string[] = [];
Object.keys(o).forEach(function (k) {
if (o[k] !== undefined) {
iter(o[k], k);
}
});
return new URLSearchParams(data.join("&"));
}
Submitted by hugo697 450 days ago