Create Payment Session
Create a payment session to begin the “Pay with Truemed” checkout flow. Call this endpoint after the customer clicks “Checkout with Truemed” or similar. The customer is redirected to Truemed to complete a health survey and enter HSA/FSA card details, then redirected back to your site via the provided success_url or failure_url.
The outcome is communicated asynchronously via the
payment_session_complete webhook.
Request Notes
total_amount(Required): The total amount in cents to charge the user, inclusive of discounts, shipping, taxes, and other fees being collected by the partner- IMPORTANT: total_amount must equal the sum of:
payment.amount_details.total_additional_chargespayment.amount_details.total_discounts- For each order_item, the sum of:
item.quantity * item.priceitem.amount_details.total_additional_chargesitem.amount_details.total_discounts
- IMPORTANT: total_amount must equal the sum of:
amount_details(Required): Read further heresuccess_url(Required): Where to redirect the user to after Truemed successfully processes a payment- This is often used to display an order confirmation screen, or similar
- Templating:
- We support limited templating of this URL parameter. Any part of the URL string containing
{{payment_session_id}}will be replaced by theid(UUID) returned by this call. - IMPORTANT: The template variable must be EXACTLY
{{payment_session_id}}- no spaces around the braces on either side.
- We support limited templating of this URL parameter. Any part of the URL string containing
- For unattended payment flows using payment tokens, the meaning of the
success_urlis slightly different. In such cases a payment may fail because the stored payment methods are expired or otherwise declined. When those failures occur, we will return a 422 status with aredirect_urlto our page for updating stored payment methods. Merchants should email or otherwise notify users of the need to update their stored payment methods using this url. When users successfully complete that page, they will be redirected to thesuccess_urlprovided here.
failure_url(Required): When the payment fails in an irrecoverable way, or the user is ineligible to spend HSA/FSA funds on the purchase- We attempt to recover from incorrect CVV, or other card detail errors by prompting the user for retry
- The exact failure reason will be communicated in the call to the partner’s
payment_session_completecallback - Templating:
- We support limited templating of this URL parameter. Any part of the URL string containing
{{payment_session_id}}will be replaced by theid(UUID) returned by this call. - IMPORTANT: The template variable must be EXACTLY
{{payment_session_id}}- no spaces around the braces on either side.
- We support limited templating of this URL parameter. Any part of the URL string containing
- For unattended payment flows using payment tokens, the meaning of the
failure_urlis slightly different. In such cases a payment may fail because the stored payment methods are expired or otherwise declined. When those failures occur, we will return a 422 status with aredirect_urlto our page for updating stored payment methods. Merchants should email or otherwise notify users of the need to update their stored payment methods using this url. When users start but cancel the update before fully completing the process, they will be redirected to thefailure_urlprovided here.
customer_state(Optional): The 2-letter ISO 3166-2:US code for a region, without the US- prefix. For example, California should be provided as CA and Rhode Island as RI- If
customer_stateis provided, the state of residence question in the health survey will be prefilled with the full state name that corresponds to the ISO code.
- If
metadata(Optional): - Will be echoed back in the webhook and detail view if present.- IMPORTANT: This must be a string. If you want to include JSON, encode it as a string.
- IMPORTANT: DO NOT INCLUDE sensitive information in this field.
kind(Optional): one of the following:one_time_payment(DEFAULT): The charge is not a subscription related charge. This is the default if this field is not set.authorization: Aone_time_paymentauthorization hold only, must be manually captured or voided with a follow up API call.
payment_token(Conditionally required): the ID returned by Truemed on initial recurring charges (whentokenize=True).- When
payment_tokenis provided, customer identity is derived from the token’s user. Anycustomer_emailorcustomer_namevalues in the request are ignored.
- When
tokenize(Optional):TrueorFalse- set toTrueto enable subsequent charges. Must beFalseifpayment_tokenis provided.request_multicapture(Optional):TrueorFalserequests multi-capture, which collects an authorization in parts.- Your sales channel must have multi-capture enabled. A disabled feature returns
400 FeatureNotEnabled. - Use
tokenize=trueto save cards on the initial order. For later orders, usepayment_tokento reuse saved cards. Both combinations requirekind=authorizationand a positive, non-trial amount. Automatic-capture and free-trial combinations return400 InvalidRequestParameter. - A zero-dollar order with
payment_tokenand nodisplay_next_bill_inforeturns400 TotalAmountInvalid. - For initial orders,
payment_token_updatedsignals that the saved cards are ready for a later order. Token setup can finish at approval, before any capture. - Requests that neither save nor reuse cards retain their automatic-capture behavior. With
kind=one_time_payment, those requests accept the flag and ignore it. - The card network confirms availability after authorization. Read
multicapture_availablethrough session retrieval or thepayment_session_completewebhook. The create response omits this field. - Every card funding the order must support multi-capture. A card saved with a $0 order share does not affect availability.
- When
multicapture_availableisfalse, the session supports a single capture, and a capture sent withfinal: falseis rejected.
- Your sales channel must have multi-capture enabled. A disabled feature returns
display_next_bill_info(Optional): Partners should only provide this field if they want to initiate a free trial subscription for the customer. The information in this object will be displayed on Truemed’s checkout page to provide more context to the customer when submitting their payment method(s)total_amount: The amount in cents the customer will be charged when the free trial period endsdate: A YYYY-MM-DD string indicating the date the free trial period ends- IMPORTANT: This field requires
tokenize=trueandtotal_amount=0(free trial subscriptions only)
Idempotency
idempotency_key lets you safely retry a request (e.g. after a network blip, or to dedupe between concurrent retries) without creating a duplicate payment session.
- Identical retry: If you call this endpoint again with the same
idempotency_keyand the same key request fields, you’ll get back the same payment sessionid(HTTP200). The session is not re-created. - Reused key with a different request: If you reuse the
idempotency_keybut change one of the key fields, you’ll get a400 IdempotencyViolation. Themessagewill name the specific field(s) that diverged so you can debug.
Fields compared (must match the original request to be treated as a retry):
customer_email— compared case-insensitively (User@example.commatchesuser@example.com)total_amountsuccess_url,failure_urlorder_items(name, sku, quantity, price,item_id, and item-level amount details)kindpayment_token(when present on the retry, with the stricter saved-card comparison below)display_next_bill_info.total_amount,display_next_bill_info.date, and the impliedis_free_trialflag (when present on the original)
Saved-card multi-capture retries. Token mode means saving cards with tokenize, reusing cards with payment_token, or neither.
If either request combines multi-capture with saved cards, Truemed compares both requests’ token mode and multi-capture intent.
The supplied token identity must also match.
These checks apply in both directions, including retries after capture.
A mismatch returns 400 IdempotencyViolation before Truemed saves any new cards or tokens.
Requests without tokens. Requests that neither save nor reuse cards retain their existing retry behavior, including adding request_multicapture on a retry. The retry returns the original session and leaves its configuration unchanged.
Fields not compared, except for the saved-card comparison above:
customer_namemetadatacustomer_statesurvey_configbilling_name,billing_address,shipping_name,shipping_addresstest_configand other request configuration
If a retry sends different values for any of these, the original payment session is still returned — the new values are not applied to the existing session.
How order_items is compared. Line order does not matter, and neither does the order of the entries inside a line’s amount_details. A cart carrying the same line twice must replay with it twice. item_id is part of a line’s identity: omit it and Truemed provisions one, so a retry that adds your own id is rejected. Send the same item_id on both calls, or omit it on both.
The 400 carries no payment session id. If you lost the original response, find the session with list payment sessions.
iFrame Payment Session
If use_iframe is set to true, redirect_url will be iframe-compatible. When the customer
finishes, the iframe posts one completion message to your page:
redirectUrl echoes the success_url or failure_url from your request, matching success. See
the Embedded Checkout guide for how to
render the flow, validate the message’s origin, and handle it.
Response Notes
Success Case
HTTP Status: 200
id- the unique ID for this checkout session. The sameidwill be returned if the endpoint is called again with the sameidempotency_keyand the request’s key fields match the original (see Idempotency below).- Associate this id with your internal representation of a checkout session, if applicable
redirect_url- the URL that the partner should redirect the customer to- Typically this would be done after the user presses a “Checkout with Truemed” button or similar on the partner’s site
- The user will perform the following steps on Truemed’s platform
- Complete a health survey to determine eligibility to spend HSA/FSA funds on the purchase
- Enter HSA/FSA card details, and confirm the purchase
- The status of the checkout session will be communicated back to the partner via the
payment_session_completewebhook
Bad Request
HTTP Status: 400
If a field is missing or the request is otherwise can’t be processed, we’ll return a 400 with the following fields:
error: Can be one of:MissingRequiredParameter: A required field is not present in the requestInvalidRequestParameter: A field value is invalid (e.g., malformed email, invalid URL). Multi-capture withtokenizeorpayment_tokenrequireskind=authorizationand a positive, non-trial amount.TotalAmountInvalid: Thetotal_amountfield is either:- Not greater than or equal to the sum of the
object_itemamountfields - The
total_amountis 0 - The
total_amountis negative
- Not greater than or equal to the sum of the
OrderItemsInvalid: Theorder_itemsarray failed validationIdempotencyViolation: Anidempotency_keywas reused with different request parameters. Themessagenames the specific field(s) that diverged from the original request. See Idempotency below for which fields are compared.ServerError: There was an internal server error.- Requests can be retried as long as the
idempotency-keyis the same.
- Requests can be retried as long as the
SessionPending: A charge to the existing payment method is unable to be processed because the user has yet to enter a payment method.- This is only possible when creating a charge using a
payment_tokenbefore the user has finished the initial checkout (for thepayment_sessioncreated withtokenize=True).
- This is only possible when creating a charge using a
TokenizeNotSupported: Bothtokenize=Trueandpayment_tokenwere set. You can’t tokenize a payment session if the session is being billed back to a prior one using apayment_token.FeatureNotEnabled: A required merchant feature is disabled. Examples include Stripe configuration, saved-card support, orrequest_multicapture=trueon a sales channel without multi-capture enabled.
message: A human-readable description of the error
Unprocessable Entity
HTTP Status: 422
If a payment_token was provided and the token requires customer intervention before it can be used again, a 422 will be returned.
next_action: The action the customer must take. Can be one of the following:UpdatePaymentMethod: Customer must enter a new payment method.TakeHealthSurvey: Customer must retake the health survey
redirect_url: Contains a URI through which the customer can correct thepayment_token.
Authentication
Sales channel API key for merchant server-to-server authentication
Request
The email address for the customer. Required unless you send payment_token. When you send payment_token, Truemed ignores this field and uses the email stored on the token. To change that email, call update_payment_token.
When the payment fails in an irrecoverable way, or the user is ineligible to spend HSA/FSA funds on the purchase.
A unique identifier for the checkout session, used to safely retry this request. If the same idempotency_key is sent again with a request whose key fields match the original (customer_email (case-insensitive), total_amount, success_url, failure_url, order_items, kind, payment_token, and any display_next_bill_info fields), the original payment session is returned. If the key is reused with a different request, a 400 IdempotencyViolation is returned naming the field(s) that diverged. customer_name, metadata, and survey configuration are not part of the idempotency comparison.
The Billing address for the order (used for better fraud detection)
The first and last name of the person for billing (used for better fraud detection).
The 2-letter ISO 3166-2:US code for a region, without the US- prefix.
One of the following: one_time_payment (DEFAULT), authorization.
The ID returned by Truemed on initial recurring charges (when tokenize=True). When you send it, Truemed charges the customer who owns the token and ignores customer_email and customer_name.
Request multi-capture to collect an authorization in parts. Your sales channel must have multi-capture enabled. To save cards on an initial order, send tokenize: true. For later orders, send payment_token. Both combinations require kind: "authorization" and a positive, non-trial amount. Automatic capture or a free trial returns 400 InvalidRequestParameter. A zero-dollar order with payment_token and no display_next_bill_info returns 400 TotalAmountInvalid. Disabled features return 400 FeatureNotEnabled. Only requests that neither save nor reuse cards ignore this flag with automatic capture. Check multicapture_available after authorization through session retrieval or webhooks. Create responses omit it. Every card funding the order must support multi-capture. Cards saved with a $0 order share do not affect availability. If total_amount differs from the items’ totals, name the difference in amount_details. See Manual and delayed capture.
The first and last name of the person for shipping (used for better fraud detection).
True or False - set to True to enable subsequent charges.
Optional query parameter that can be used to modify the response’s redirect_url so it can be used and communicated with in an iframe.
Response
When the Letter of Medical Necessity covering this customer expires (inclusive, UTC). Null for sessions that are not tokenized, and for a customer who holds no letter on this sales channel. While a letter is live this is the earliest expiration among them; once none is, it is when the last one lapsed. This is the same value the customer-eligibility endpoints return, so renewal can be driven off whichever call you already make.