Stripe payment method — verifies payment via Stripe PaymentIntent with SPT.
The client creates a Shared Payment Granted Token (SPT) via Stripe, includes
it in the credential payload, and the server creates a PaymentIntent with
confirm: true to charge it immediately.
Configuration
Pass Stripe-specific config via :method_config in MPP.Plug opts:
plug MPP.Plug,
secret_key: "hmac-secret",
realm: "api.example.com",
method: MPP.Methods.Stripe,
amount: "5000",
currency: "usd",
method_config: %{
"stripe_secret_key" => "sk_test_...",
"network_id" => "profile_1Mqx...",
"payment_method_types" => ["card"]
}Config Keys
"stripe_secret_key"— (required) Stripe secret key for PaymentIntent creation"network_id"— (required) Stripe Business Network profile ID"payment_method_types"— (optional) accepted payment methods, defaults to["card"]"realm"— (optional, injected by Plug) server realm for analytics metadata
Credential Payload
The credential payload map must contain:
"spt"— (required) Stripe Shared Payment Granted Token (e.g.,"spt_1N4...")"externalId"— (optional) caller-provided correlation ID, echoed in receipt
API Functions
| Function | Arity | Description | Param Kinds |
|---|---|---|---|
challenge_method_details | 1 | Return Stripe-specific fields (networkId, paymentMethodTypes) for the 402 challenge. | charge: value |
verify | 2 | Verify a Stripe SPT credential by creating a PaymentIntent with confirm: true. | payload: value, charge: value |
validate_config! | 1 | Validate Stripe method_config at init time. Raises on missing stripe_secret_key or network_id. | config: value |
method_name | 0 | Return the payment method identifier for Stripe. | - |
Summary
Functions
Return Stripe-specific fields (networkId, paymentMethodTypes) for the 402 challenge.
Return the payment method identifier for Stripe.
Validate Stripe method_config at init time. Raises on missing stripe_secret_key or network_id.
Verify a Stripe SPT credential by creating a PaymentIntent with confirm: true.
Functions
@spec challenge_method_details(MPP.Intents.Charge.t()) :: map() | nil
@spec challenge_method_details(MPP.Intents.Charge.t()) :: map() | nil
Return Stripe-specific fields (networkId, paymentMethodTypes) for the 402 challenge.
Parameters
charge- Charge struct with method_details containingnetwork_idand optionallypayment_method_types(value)
Returns
Map with networkId and paymentMethodTypes keys, or nil if no network_id configured (map_or_nil)
# descripex:contract
%{
params: %{
charge: %{
description: "Charge struct with method_details containing `network_id` and optionally `payment_method_types`",
kind: :value
}
},
returns: %{
type: :map_or_nil,
description: "Map with `networkId` and `paymentMethodTypes` keys, or `nil` if no `network_id` configured"
}
}
@spec method_name() :: String.t()
Return the payment method identifier for Stripe.
# descripex:contract
%{}
Validate Stripe method_config at init time. Raises on missing stripe_secret_key or network_id.
Parameters
config- method_config map to validate (value)
Returns
:ok on success, raises ArgumentError on missing keys (atom)
# descripex:contract
%{
params: %{
config: %{description: "method_config map to validate", kind: :value}
},
returns: %{
type: :atom,
description: "`:ok` on success, raises `ArgumentError` on missing keys"
}
}
@spec verify(map(), MPP.Intents.Charge.t()) :: {:ok, MPP.Receipt.t()} | {:error, MPP.Errors.t()}
Verify a Stripe SPT credential by creating a PaymentIntent with confirm: true.
Parameters
payload- Credential payload map containing"spt"(Stripe Shared Payment Granted Token) (value)charge- Charge intent struct with amount, currency, and method_details (includingstripe_secret_key) (value)
Returns
{:ok, receipt} on success, {:error, error} on failure (tagged_tuple)
Errors
:invalid_payload:verification_failed
# descripex:contract
%{
params: %{
payload: %{
description: "Credential payload map containing `\"spt\"` (Stripe Shared Payment Granted Token)",
kind: :value
},
charge: %{
description: "Charge intent struct with amount, currency, and method_details (including `stripe_secret_key`)",
kind: :value
}
},
errors: [:invalid_payload, :verification_failed],
returns: %{
type: :tagged_tuple,
description: "`{:ok, receipt}` on success, `{:error, error}` on failure"
}
}