Skip to content
LogoLogo

Method.stripe.charge

One-time payments via Shared Payment Tokens

Creates a Stripe charge payment method for client-side SPT-based payments.

Usage

 
import {  } from '@stripe/stripe-js'
import { ,  } from 'mppx/client'
 
const  = (await ('pk_test_...'))!
 
.({
  : [
    .({
      : ,
      : async ({ , , , , ,  }) => {
        const  = await ('/api/create-spt', {
          : 'POST',
          : { 'Content-Type': 'application/json' },
          : .({ , , , , ,  }),
        })
        return (await .()).spt
      },
    }),
  ],
})

Return type

import type { Method } from 'mppx'
 
type ReturnType = Method.Client

Parameters

client (optional)

  • Type: StripeJs

Stripe.js instance from @stripe/stripe-js. Forwarded to the createToken callback for use with Stripe Elements.

 
import {  } from '@stripe/stripe-js'
import {  } from 'mppx/client'
 
const  = (await ('pk_test_...'))!
 
const  = .({
  : , 
  : async () => '...',
})

createToken

  • Type: (params: OnChallengeParameters) => Promise<string>

Callback invoked when a Stripe Challenge is received. Must return an SPT token string (spt_...). Typically proxied through a server endpoint since SPT creation requires a Stripe secret key.

The callback receives:

FieldTypeDescription
amountstringPayment amount in smallest currency unit
challengeChallengeThe parsed Challenge from the server
clientStripeJs | undefinedStripe.js instance, if provided
currencystringThree-letter ISO currency code
expiresAtnumberSPT expiration as a Unix timestamp (seconds)
metadataRecord<string, string>Optional metadata from the Challenge
networkIdstring | undefinedStripe Business Network profile ID
paymentMethodstring | undefinedStripe payment method ID

externalId (optional)

  • Type: string

Client reference ID included in the Credential payload.

paymentMethod (optional)

  • Type: string

Default Stripe payment method ID (for example pm_card_visa). Overridden by context.paymentMethod at Credential-creation time.

 
import {  } from 'mppx/client'
 
const  = .({
  : async () => '...',
  : 'pm_card_visa', 
})