type Stripe = {
token: string;
};
/**
* Post test helpers treasury received debits
* Use this endpoint to simulate a test mode ReceivedDebit initiated by a third party. In live mode, you can’t directly create ReceivedDebits initiated by third parties.
*/
export async function main(
auth: Stripe,
body: {
amount: number;
currency: string;
description?: string;
expand?: string[];
financial_account: string;
initiating_payment_method_details?: {
type: "us_bank_account";
us_bank_account?: {
account_holder_name?: string;
account_number?: string;
routing_number?: string;
[k: string]: unknown;
};
[k: string]: unknown;
};
network: "ach";
}
) {
const url = new URL(
`https://api.stripe.com/v1/test_helpers/treasury/received_debits`
);
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 test helpers treasury received debits
* Use this endpoint to simulate a test mode ReceivedDebit initiated by a third party. In live mode, you can’t directly create ReceivedDebits initiated by third parties.
*/
export async function main(
auth: Stripe,
body: {
amount: number;
currency: string;
description?: string;
expand?: string[];
financial_account: string;
initiating_payment_method_details?: {
type: "us_bank_account";
us_bank_account?: {
account_holder_name?: string;
account_number?: string;
routing_number?: string;
[k: string]: unknown;
};
[k: string]: unknown;
};
network: "ach";
}
) {
const url = new URL(
`https://api.stripe.com/v1/test_helpers/treasury/received_debits`
);
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 test helpers treasury received debits
* <p>Use this endpoint to simulate a test mode ReceivedDebit initiated by a third party. In live mode, you can’t directly create ReceivedDebits initiated by third parties.</p>
*/
export async function main(
auth: Stripe,
body: {
amount: number;
currency: string;
description?: string;
expand?: string[];
financial_account: string;
initiating_payment_method_details?: {
type: "us_bank_account";
us_bank_account?: {
account_holder_name?: string;
account_number?: string;
routing_number?: string;
[k: string]: unknown;
};
[k: string]: unknown;
};
network: "ach";
}
) {
const url = new URL(
`https://api.stripe.com/v1/test_helpers/treasury/received_debits`
);
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