type Stripe = {
token: string;
};
/**
* Post payment intents intent capture
* Capture the funds of an existing uncaptured PaymentIntent when its status is requires_capture.
Uncaptured PaymentIntents are cancelled a set number of days (7 by default) after their creation.
Learn more about separate authorization and capture.
*/
export async function main(
auth: Stripe,
intent: string,
body: {
amount_to_capture?: number;
application_fee_amount?: number;
expand?: string[];
final_capture?: boolean;
metadata?: { [k: string]: string } | "";
statement_descriptor?: string;
statement_descriptor_suffix?: string;
transfer_data?: { amount?: number; [k: string]: unknown };
}
) {
const url = new URL(
`https://api.stripe.com/v1/payment_intents/${intent}/capture`
);
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 payment intents intent capture
* Capture the funds of an existing uncaptured PaymentIntent when its status is requires_capture.
Uncaptured PaymentIntents are cancelled a set number of days (7 by default) after their creation.
Learn more about separate authorization and capture.
*/
export async function main(
auth: Stripe,
intent: string,
body: {
amount_to_capture?: number;
application_fee_amount?: number;
expand?: string[];
final_capture?: boolean;
metadata?: { [k: string]: string } | "";
statement_descriptor?: string;
statement_descriptor_suffix?: string;
transfer_data?: { amount?: number; [k: string]: unknown };
}
) {
const url = new URL(
`https://api.stripe.com/v1/payment_intents/${intent}/capture`
);
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 payment intents intent capture
* <p>Capture the funds of an existing uncaptured PaymentIntent when its status is <code>requires_capture</code>.</p>
<p>Uncaptured PaymentIntents are cancelled a set number of days (7 by default) after their creation.</p>
<p>Learn more about <a href="/docs/payments/capture-later">separate authorization and capture</a>.</p>
*/
export async function main(
auth: Stripe,
intent: string,
body: {
amount_to_capture?: number;
application_fee_amount?: number;
expand?: string[];
final_capture?: boolean;
metadata?: { [k: string]: string } | "";
statement_descriptor?: string;
statement_descriptor_suffix?: string;
transfer_data?: { amount?: number; [k: string]: unknown };
}
) {
const url = new URL(
`https://api.stripe.com/v1/payment_intents/${intent}/capture`
);
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