type Stripe = {
token: string;
};
/**
* Post charges
* This method is no longer recommended—use the Payment Intents API
to initiate a new payment instead. Confirmation of the PaymentIntent creates the Charge
object used to request payment.
*/
export async function main(
auth: Stripe,
body: {
amount?: number;
application_fee?: number;
application_fee_amount?: number;
capture?: boolean;
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;
currency?: string;
customer?: string;
description?: string;
destination?:
| { account: string; amount?: number; [k: string]: unknown }
| string;
expand?: string[];
metadata?: { [k: string]: string } | "";
on_behalf_of?: string;
radar_options?: { session?: string; [k: string]: unknown };
receipt_email?: string;
shipping?: {
address: {
city?: string;
country?: string;
line1?: string;
line2?: string;
postal_code?: string;
state?: string;
[k: string]: unknown;
};
carrier?: string;
name: string;
phone?: string;
tracking_number?: string;
[k: string]: unknown;
};
source?: string;
statement_descriptor?: string;
statement_descriptor_suffix?: string;
transfer_data?: {
amount?: number;
destination: string;
[k: string]: unknown;
};
transfer_group?: string;
}
) {
const url = new URL(`https://api.stripe.com/v1/charges`);
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 charges
* This method is no longer recommended—use the Payment Intents API
to initiate a new payment instead. Confirmation of the PaymentIntent creates the Charge
object used to request payment.
*/
export async function main(
auth: Stripe,
body: {
amount?: number;
application_fee?: number;
application_fee_amount?: number;
capture?: boolean;
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;
currency?: string;
customer?: string;
description?: string;
destination?:
| { account: string; amount?: number; [k: string]: unknown }
| string;
expand?: string[];
metadata?: { [k: string]: string } | "";
on_behalf_of?: string;
radar_options?: { session?: string; [k: string]: unknown };
receipt_email?: string;
shipping?: {
address: {
city?: string;
country?: string;
line1?: string;
line2?: string;
postal_code?: string;
state?: string;
[k: string]: unknown;
};
carrier?: string;
name: string;
phone?: string;
tracking_number?: string;
[k: string]: unknown;
};
source?: string;
statement_descriptor?: string;
statement_descriptor_suffix?: string;
transfer_data?: {
amount?: number;
destination: string;
[k: string]: unknown;
};
transfer_group?: string;
}
) {
const url = new URL(`https://api.stripe.com/v1/charges`);
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 charges
* <p>Use the <a href="/docs/api/payment_intents">Payment Intents API</a> to initiate a new payment instead
of using this method. Confirmation of the PaymentIntent creates the <code>Charge</code>
object used to request payment, so this method is limited to legacy integrations.</p>
*/
export async function main(
auth: Stripe,
body: {
amount?: number;
application_fee?: number;
application_fee_amount?: number;
capture?: boolean;
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;
currency?: string;
customer?: string;
description?: string;
destination?:
| { account: string; amount?: number; [k: string]: unknown }
| string;
expand?: string[];
metadata?: { [k: string]: string } | "";
on_behalf_of?: string;
radar_options?: { session?: string; [k: string]: unknown };
receipt_email?: string;
shipping?: {
address: {
city?: string;
country?: string;
line1?: string;
line2?: string;
postal_code?: string;
state?: string;
[k: string]: unknown;
};
carrier?: string;
name: string;
phone?: string;
tracking_number?: string;
[k: string]: unknown;
};
source?: string;
statement_descriptor?: string;
statement_descriptor_suffix?: string;
transfer_data?: {
amount?: number;
destination: string;
[k: string]: unknown;
};
transfer_group?: string;
}
) {
const url = new URL(`https://api.stripe.com/v1/charges`);
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