type Stripe = {
token: string;
};
/**
* Post accounts account bank accounts
* Create an external account for a given account.
*/
export async function main(
auth: Stripe,
account: string,
body: {
bank_account?:
| {
account_holder_name?: string;
account_holder_type?: "company" | "individual";
account_number: string;
account_type?: "checking" | "futsu" | "savings" | "toza";
country: string;
currency?: string;
documents?: {
bank_account_ownership_verification?: {
files?: string[];
[k: string]: unknown;
};
[k: string]: unknown;
};
object?: "bank_account";
routing_number?: string;
[k: string]: unknown;
}
| string;
default_for_currency?: boolean;
expand?: string[];
external_account?: string;
metadata?: { [k: string]: string };
}
) {
const url = new URL(
`https://api.stripe.com/v1/accounts/${account}/bank_accounts`
);
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 374 days ago
type Stripe = {
token: string;
};
/**
* Post accounts account bank accounts
* <p>Create an external account for a given account.</p>
*/
export async function main(
auth: Stripe,
account: string,
body: {
bank_account?:
| {
account_holder_name?: string;
account_holder_type?: "company" | "individual";
account_number: string;
account_type?: "checking" | "futsu" | "savings" | "toza";
country: string;
currency?: string;
documents?: {
bank_account_ownership_verification?: {
files?: string[];
[k: string]: unknown;
};
[k: string]: unknown;
};
object?: "bank_account";
routing_number?: string;
[k: string]: unknown;
}
| string;
default_for_currency?: boolean;
expand?: string[];
external_account?: string;
metadata?: { [k: string]: string };
}
) {
const url = new URL(
`https://api.stripe.com/v1/accounts/${account}/bank_accounts`
);
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 502 days ago