Create Payment Method

Create a payment method from payment details. This endpoint stores payment information securely and returns a tokenized reference.

Request

POST /projects/:projectId/payment-methods

URL Parameters

ParameterRequiredTypeDefaultDescription
projectIdtruestringnullThe project ID (must match JWT issuer).

Request

curl -X POST \
  https://api.basistheory.ai/projects/:projectId/payment-methods \
  -H 'Authorization: Bearer YOUR_JWT_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
    "entityId": "user-12345",
    "card": {
      "number": "4242424242424242",
      "expirationMonth": "12",
      "expirationYear": "2025",
      "cvc": "123"
    }
  }'

Request Parameters

ParameterRequiredTypeDefaultDescription
entityIdtruestringnullUnique user identifier (must match JWT sub claim).
tokenIdconditionalstringnullBasisTheory card token ID (UUID format).
cardconditionalCard ObjectnullCredit or debit card raw details.

Note: Either tokenId or card must be provided, but not both.

Note: Either tokenId or card or encryptedCard must be provided, but not more than one.

Card Object

ParameterRequiredTypeDefaultDescription
numbertruestringnullCredit or debit card number (13-19 digits, digits only).
expirationMonthtruestringnullCard expiration month in MM format (01-12).
expirationYeartruestringnullCard expiration year in YYYY format (current year or later).
cvctruestringnullCard security code (3-4 digits).

Response

{
  "id": "26859380-7829-4ee1-8a0a-38927881e7ef",
  "type": "card",
  "entityId": "user-12345",
  "card": {
    "brand": "mastercard",
    "type": "credit",
    "details": {
      "bin": "424242",
      "last4": "4242",
      "expirationMonth": "12",
      "expirationYear": "2025"
    },
    "display": {
      "name": "Mastercard",
      "color": "#FF5A00"
    }
  },
  "credentialTypes": ["virtual-card"],
  "createdAt": "2025-01-15T14:00:00Z"
}

Response Properties

PropertyTypeDescription
idstringThe payment method ID (UUID).
typestringThe payment method type (always “card”).
entityIdstringThe user ID that owns this payment method.
cardCard ObjectCard-specific details and metadata.
credentialTypesstring[]Array of credential types available (currently only [“virtual-card”]).
createdAtstringISO 8601 timestamp when the payment method was created.
tokenToken ObjectSecure token information from BasisTheory (legacy only).

Card Object

PropertyTypeDescription
typestringThe card type: debit or credit.
brandstringThe card brand (i.e. visa, mastercard).
detailsCard Details ObjectDetails about the card.
displayCard Display ObjectUI details for displaying the card.

Card Details Object

PropertyTypeDescription
binstring6 digit card BIN number.
last4stringCard last 4 numbers.
expirationMonthstringCard expiration month in MM format.
expirationYearstringCard expiration year in YYYY format.

Card Display Object

PropertyTypeDescription
namestringHuman-readable card brand name.
colorstringHex color code for UI rendering.

Token Object (Legacy)

PropertyTypeDescription
idstringBasisTheory token ID for the stored card data.
fingerprintstringUnique fingerprint for identifying duplicate cards.
createdAtstringISO 8601 timestamp when the token was created.
maskedDatastringMasked card number for display purposes.

Error Handling

{
  "error": {
    "status": 400,
    "type": "validation_error",
    "title": "Validation failed",
    "message": "The request contained invalid data.",
    "details": {
      "fields": {
        "card.number": "Card number must be at least 13 digits.",
        "card.expirationMonth": "Expiration month must be in MM format (01-12).",
        "card.expirationYear": "Expiration year must be current year or later.",
        "card.cvc": "CVC must be 3 or 4 digits.",
        "tokenId": "Token ID must be a valid UUID."
      }
    }
  }
}