type Stripe = {
token: string;
};
/**
* Post customers customer bank accounts
* When you create a new credit card, you must specify a customer or recipient on which to create it.
If the card’s owner has no default card, then the new card will become the default.
However, if the owner already has a default, then it will not change.
To change the default, you should update the customer to have a new default_source.
*/
export async function main(
auth: Stripe,
customer: string,
body: {
alipay_account?: string;
bank_account?:
| {
account_holder_name?: string;
account_holder_type?: "company" | "individual";
account_number: string;
country: string;
currency?: string;
object?: "bank_account";
routing_number?: string;
[k: string]: unknown;
}
| string;
card?:
| {
address_city?: string;
address_country?: string;
address_line1?: string;
address_line2?: string;
address_state?: string;
address_zip?: string;
cvc?: string;
exp_month: number;
exp_year: number;
metadata?: { [k: string]: string };
name?: string;
number: string;
object?: "card";
[k: string]: unknown;
}
| string;
expand?: string[];
metadata?: { [k: string]: string };
source?: string;
}
) {
const url = new URL(
`https://api.stripe.com/v1/customers/${customer}/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 368 days ago
type Stripe = {
token: string;
};
/**
* Post customers customer bank accounts
* When you create a new credit card, you must specify a customer or recipient on which to create it.
If the card’s owner has no default card, then the new card will become the default.
However, if the owner already has a default, then it will not change.
To change the default, you should update the customer to have a new default_source.
*/
export async function main(
auth: Stripe,
customer: string,
body: {
alipay_account?: string;
bank_account?:
| {
account_holder_name?: string;
account_holder_type?: "company" | "individual";
account_number: string;
country: string;
currency?: string;
object?: "bank_account";
routing_number?: string;
[k: string]: unknown;
}
| string;
card?:
| {
address_city?: string;
address_country?: string;
address_line1?: string;
address_line2?: string;
address_state?: string;
address_zip?: string;
cvc?: string;
exp_month: number;
exp_year: number;
metadata?: { [k: string]: string };
name?: string;
number: string;
object?: "card";
[k: string]: unknown;
}
| string;
expand?: string[];
metadata?: { [k: string]: string };
source?: string;
}
) {
const url = new URL(
`https://api.stripe.com/v1/customers/${customer}/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 795 days ago
type Stripe = {
token: string;
};
/**
* Post customers customer bank accounts
* <p>When you create a new credit card, you must specify a customer or recipient on which to create it.</p>
<p>If the card’s owner has no default card, then the new card will become the default.
However, if the owner already has a default, then it will not change.
To change the default, you should <a href="/docs/api#update_customer">update the customer</a> to have a new <code>default_source</code>.</p>
*/
export async function main(
auth: Stripe,
customer: string,
body: {
alipay_account?: string;
bank_account?:
| {
account_holder_name?: string;
account_holder_type?: "company" | "individual";
account_number: string;
country: string;
currency?: string;
object?: "bank_account";
routing_number?: string;
[k: string]: unknown;
}
| string;
card?:
| {
address_city?: string;
address_country?: string;
address_line1?: string;
address_line2?: string;
address_state?: string;
address_zip?: string;
cvc?: string;
exp_month: number;
exp_year: number;
metadata?: { [k: string]: string };
name?: string;
number: string;
object?: "card";
[k: string]: unknown;
}
| string;
expand?: string[];
metadata?: { [k: string]: string };
source?: string;
}
) {
const url = new URL(
`https://api.stripe.com/v1/customers/${customer}/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 922 days ago