type Stripe = {
token: string;
};
type Base64 = string;
/**
* Post files
* To upload a file to Stripe, you need to send a request of type multipart/form-data. Include the file you want to upload in the request, and the parameters for creating a file.
All of Stripe’s officially supported Client libraries support sending multipart/form-data.
*/
export async function main(
auth: Stripe,
body: {
expand?: string[];
file: {
base64: Base64;
type:
| "image/png"
| "image/jpeg"
| "image/gif"
| "application/pdf"
| "appication/json"
| "text/csv"
| "text/plain"
| "audio/mpeg"
| "audio/wav"
| "video/mp4";
name: string;
};
file_link_data?: {
create: boolean;
expires_at?: number;
metadata?: { [k: string]: string } | "";
[k: string]: unknown;
};
purpose:
| "account_requirement"
| "additional_verification"
| "business_icon"
| "business_logo"
| "customer_signature"
| "dispute_evidence"
| "identity_document"
| "pci_document"
| "tax_document_user_upload"
| "terminal_reader_splashscreen";
}
) {
const url = new URL(`https://api.stripe.com/v1/files`);
const formData = new FormData();
for (const [k, v] of Object.entries(body)) {
if (v !== undefined && v !== "") {
if (["file"].includes(k)) {
const { base64, type, name } = v as {
base64: Base64;
type: string;
name: string;
};
formData.append(
k,
new Blob([Uint8Array.from(atob(base64), (m) => m.codePointAt(0)!)], {
type,
}),
name
);
} else {
formData.append(k, String(v));
}
}
}
const response = await fetch(url, {
method: "POST",
headers: {
Authorization: "Bearer " + auth.token,
},
body: formData,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 74 days ago
type Stripe = {
token: string;
};
/**
* Post files
* <p>To upload a file to Stripe, you need to send a request of type <code>multipart/form-data</code>. Include the file you want to upload in the request, and the parameters for creating a file.</p>
<p>All of Stripe’s officially supported Client libraries support sending <code>multipart/form-data</code>.</p>
*/
export async function main(auth: Stripe) {
const url = new URL(`https://api.stripe.com/v1/files`);
const response = await fetch(url, {
method: "POST",
headers: {
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 202 days ago