PaymentMethods: retrieve, attach to and detach from customers, update, and list. Payment methods are usually created client-side with Stripe.js (or saved with a SetupIntent) and then attached server-side. See https://docs.stripe.com/api/payment_methods.

Functions

attach-payment-method

fn (payment-method: Str, customer: Str): Map
fn (payment-method: Str, customer: Str, options: ::stripe::api/RequestOptions | Map): Map

POST /v1/payment_methods/{payment_method}/attach - Attach a PaymentMethod to a customer. Prefer saving cards with a SetupIntent (::stripe::setup-intents), which also handles authentication; attaching directly skips it. Set the customer's default with update-customer(..., {invoice_settings: {default_payment_method}}).

Example

::pm ::stripe::payment-methods

::pm/attach-payment-method("pm_...", "cus_...")

detach-payment-method

fn (payment-method: Str): Map
fn (payment-method: Str, options: ::stripe::api/RequestOptions | Map): Map

POST /v1/payment_methods/{payment_method}/detach - Detach a PaymentMethod from its customer. The PaymentMethod cannot be used for payments afterwards.

Example

::pm ::stripe::payment-methods

detached ::pm/detach-payment-method("pm_123")
detached.customer

get-payment-method

fn (payment-method: Str): Map
fn (payment-method: Str, opts: Map): Map

GET /v1/payment_methods/{payment_method} - Retrieve a PaymentMethod by ID.

Example

::pm ::stripe::payment-methods

method ::pm/get-payment-method("pm_123")
method.card.last4

list-payment-methods

fn (customer: Str): Map
fn (customer: Str, request: ListPaymentMethodsRequest): Map
fn (customer: Str, request: ListPaymentMethodsRequest, opts: Map): Map

GET /v1/customers/{customer}/payment_methods - List a customer's PaymentMethods. Optionally filter by type (e.g. "card").

Example

::pm ::stripe::payment-methods

page ::pm/list-payment-methods("cus_123", ::pm/ListPaymentMethodsRequest({type: "card"}))
last-fours map(page.data, %.card.last4)

update-payment-method

fn (payment-method: Str, request: UpdatePaymentMethodRequest): Map
fn (payment-method: Str, request: UpdatePaymentMethodRequest, options: ::stripe::api/RequestOptions | Map): Map

POST /v1/payment_methods/{payment_method} - Update a PaymentMethod attached to a customer. card accepts exp_month/exp_year updates; allow_redisplay is "always", "limited", or "unspecified".

Example

::pm ::stripe::payment-methods

::pm/update-payment-method("pm_123", ::pm/UpdatePaymentMethodRequest({
  card: {exp_month: 12, exp_year: 2030},
  billing_details: {name: "Alice Smith"}
}))

Types

ListPaymentMethodsRequest

ListPaymentMethodsRequest type {
    type: Str?,
    allow_redisplay: Str?,
    limit: Int?,
    starting_after: Str?,
    ending_before: Str?,
    expand: Vec<Str>?
}

UpdatePaymentMethodRequest

UpdatePaymentMethodRequest type {
    billing_details: Map?,
    card: Map?,
    metadata: Map?,
    allow_redisplay: Str?,
    expand: Vec<Str>?
}