type Stripe = {
token: string;
};
/**
* Get credit notes preview
* Get a preview of a credit note without creating it.
*/
export async function main(
auth: Stripe,
amount: string | undefined,
credit_amount: string | undefined,
effective_at: string | undefined,
expand: any,
invoice: string | undefined,
lines: any,
memo: string | undefined,
metadata: any,
out_of_band_amount: string | undefined,
reason:
| "duplicate"
| "fraudulent"
| "order_change"
| "product_unsatisfactory"
| undefined,
refund: string | undefined,
refund_amount: string | undefined,
shipping_cost: any
) {
const url = new URL(`https://api.stripe.com/v1/credit_notes/preview`);
for (const [k, v] of [
["amount", amount],
["credit_amount", credit_amount],
["effective_at", effective_at],
["invoice", invoice],
["memo", memo],
["out_of_band_amount", out_of_band_amount],
["reason", reason],
["refund", refund],
["refund_amount", refund_amount],
]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
encodeParams({ expand, lines, metadata, shipping_cost }).forEach((v, k) => {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
});
const response = await fetch(url, {
method: "GET",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
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 368 days ago
type Stripe = {
token: string;
};
/**
* Get credit notes preview
* Get a preview of a credit note without creating it.
*/
export async function main(
auth: Stripe,
amount: string | undefined,
credit_amount: string | undefined,
effective_at: string | undefined,
expand: any,
invoice: string | undefined,
lines: any,
memo: string | undefined,
metadata: any,
out_of_band_amount: string | undefined,
reason:
| "duplicate"
| "fraudulent"
| "order_change"
| "product_unsatisfactory"
| undefined,
refund: string | undefined,
refund_amount: string | undefined,
shipping_cost: any
) {
const url = new URL(`https://api.stripe.com/v1/credit_notes/preview`);
for (const [k, v] of [
["amount", amount],
["credit_amount", credit_amount],
["effective_at", effective_at],
["invoice", invoice],
["memo", memo],
["out_of_band_amount", out_of_band_amount],
["reason", reason],
["refund", refund],
["refund_amount", refund_amount],
]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
encodeParams({ expand, lines, metadata, shipping_cost }).forEach((v, k) => {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
});
const response = await fetch(url, {
method: "GET",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
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 795 days ago
type Stripe = {
token: string;
};
/**
* Get credit notes preview
* <p>Get a preview of a credit note without creating it.</p>
*/
export async function main(
auth: Stripe,
amount: string | undefined,
credit_amount: string | undefined,
effective_at: string | undefined,
expand: any,
invoice: string | undefined,
lines: any,
memo: string | undefined,
metadata: any,
out_of_band_amount: string | undefined,
reason:
| "duplicate"
| "fraudulent"
| "order_change"
| "product_unsatisfactory"
| undefined,
refund: string | undefined,
refund_amount: string | undefined,
shipping_cost: any
) {
const url = new URL(`https://api.stripe.com/v1/credit_notes/preview`);
for (const [k, v] of [
["amount", amount],
["credit_amount", credit_amount],
["effective_at", effective_at],
["invoice", invoice],
["memo", memo],
["out_of_band_amount", out_of_band_amount],
["reason", reason],
["refund", refund],
["refund_amount", refund_amount],
]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
encodeParams({ expand, lines, metadata, shipping_cost }).forEach((v, k) => {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
});
const response = await fetch(url, {
method: "GET",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
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 922 days ago