Watch
1
0
Fork
You've already forked packages
0

packages/ at markup-kit dd1e6eb5270e

A snapshot of packages/ in the Weft repository; the official packages are published from these commits.

Markup-Kit-Commit: dd1e6eb5270e62e0c8b6c202b3d01f0da6e00ddc
This commit is contained in:
Weft packages 2026-11-19 20:43:26 +00:00
commit 306b143104
72 changed files with 10915 additions and 0 deletions

235
stripe/payment_intents.weft Normal file
View file

@ -0,0 +1,235 @@
// Payment intents: one attempt to collect a payment.
import { collect, request, segment } from "./stripe"
import type { Client, Page, RequestOptions, SearchPage, StripeError } from "./stripe"
/// A payment intent. `customer`, `payment_method` and `latest_charge` are expandable: `idOf` gives their ids.
export type PaymentIntent = {
id: string,
amount: float,
currency: string,
status: string,
amount_capturable?: float,
amount_received?: float,
application_fee_amount?: float,
capture_method?: string,
client_secret?: string,
confirmation_method?: string,
customer?: json,
description?: string,
last_payment_error?: json,
latest_charge?: json,
metadata?: json,
next_action?: json,
on_behalf_of?: json,
payment_method?: json,
payment_method_types?: string[],
receipt_email?: string,
statement_descriptor?: string,
transfer_data?: json,
transfer_group?: string,
canceled_at?: float,
cancellation_reason?: string,
created?: float,
livemode?: boolean,
}
/// A new payment intent. `amount` is in the currency's smallest unit. `extra` holds any field this type doesn't list.
export type PaymentIntentParams = {
amount: float,
currency: string,
customer?: string,
description?: string,
metadata?: Map<string, string>,
payment_method?: string,
payment_method_types?: string[],
automatic_payment_methods?: { enabled: boolean, allow_redirects?: string },
capture_method?: string,
confirm?: boolean,
return_url?: string,
receipt_email?: string,
setup_future_usage?: string,
statement_descriptor?: string,
application_fee_amount?: float,
on_behalf_of?: string,
transfer_data?: { destination: string, amount?: float },
transfer_group?: string,
extra?: json,
}
/// The fields of a payment intent that can change before it is confirmed.
export type PaymentIntentUpdateParams = {
amount?: float,
currency?: string,
customer?: string,
description?: string,
metadata?: Map<string, string>,
payment_method?: string,
receipt_email?: string,
application_fee_amount?: float,
extra?: json,
}
/// What to list.
export type PaymentIntentListParams = {
customer?: string,
limit?: float,
starting_after?: string,
ending_before?: string,
extra?: json,
}
/// Creates a payment intent.
///
/// ```weft
/// let intent = try await paymentIntents.create(stripe, {
/// amount: 1999,
/// currency: "eur",
/// automatic_payment_methods: { enabled: true },
/// }, { idempotencyKey: `order-${order.id}` })
/// ```
export async fn create(
c: Client,
params: PaymentIntentParams,
options: RequestOptions = {},
): PaymentIntent ! StripeError {
return try await request(
c,
"POST",
"/v1/payment_intents",
params,
options,
j => try j as PaymentIntent,
)
}
/// Gets a payment intent by id.
export async fn retrieve(
c: Client,
id: string,
options: RequestOptions = {},
): PaymentIntent ! StripeError {
return try await request(
c,
"GET",
`/v1/payment_intents/${segment(id)}`,
null,
options,
j => try j as PaymentIntent,
)
}
/// Changes the fields given.
export async fn update(
c: Client,
id: string,
params: PaymentIntentUpdateParams,
options: RequestOptions = {},
): PaymentIntent ! StripeError {
return try await request(
c,
"POST",
`/v1/payment_intents/${segment(id)}`,
params,
options,
j => try j as PaymentIntent,
)
}
/// Confirms that the customer intends to pay. `params` may name a `payment_method` or a `return_url`.
export async fn confirm(
c: Client,
id: string,
params: json = null,
options: RequestOptions = {},
): PaymentIntent ! StripeError {
return try await request(
c,
"POST",
`/v1/payment_intents/${segment(id)}/confirm`,
params,
options,
j => try j as PaymentIntent,
)
}
/// Captures an authorised payment, all of it unless `params` gives an `amount_to_capture`.
export async fn capture(
c: Client,
id: string,
params: json = null,
options: RequestOptions = {},
): PaymentIntent ! StripeError {
return try await request(
c,
"POST",
`/v1/payment_intents/${segment(id)}/capture`,
params,
options,
j => try j as PaymentIntent,
)
}
/// Cancels a payment intent that hasn't succeeded.
export async fn cancel(
c: Client,
id: string,
params: json = null,
options: RequestOptions = {},
): PaymentIntent ! StripeError {
return try await request(
c,
"POST",
`/v1/payment_intents/${segment(id)}/cancel`,
params,
options,
j => try j as PaymentIntent,
)
}
/// One page of payment intents, newest first.
export async fn list(
c: Client,
params: PaymentIntentListParams = {},
options: RequestOptions = {},
): Page<PaymentIntent> ! StripeError {
return try await request(
c,
"GET",
"/v1/payment_intents",
params,
options,
j => try j as Page<PaymentIntent>,
)
}
/// Every payment intent matching `params`, up to `max`.
export async fn listAll(
c: Client,
params: PaymentIntentListParams = {},
options: RequestOptions = {},
max: int = 10000,
): PaymentIntent[] ! StripeError {
return try await collect(
c,
"/v1/payment_intents",
params,
options,
j => try j as Page<PaymentIntent>,
x => x.id,
max,
)
}
/// Payment intents matching a search query (`status:"succeeded"`).
export async fn search(c: Client, query: string, options: RequestOptions = {}): SearchPage<
PaymentIntent,
> ! StripeError {
return try await request(
c,
"GET",
"/v1/payment_intents/search",
{ query },
options,
j => try j as SearchPage<PaymentIntent>,
)
}