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).
tokenIdconditionalCard ObjectnullBasis Theory Card Token.
cardconditionalCard ObjectnullCredit or debit card raw details.
encryptedCardconditionalstringnullCard details encrypted using provided client encryption key.

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

Card Object

ParameterRequiredTypeDefaultDescription
numbertruestringnullCredit or debit card number.
expirationMonthtruestringnullCard expiration month in MM format.
expirationYeartruestringnullCard expiration year in YYYY format.
cvctruestringnullCard security code.

Response

{
  "id": "26859380-7829-4ee1-8a0a-38927881e7ef",
  "type": "card",
  "entityId": "user-12345",
  "card": {
    "type": "credit",
    "brand": "visa",
    "details": {
      "bin": "424242",
      "last4": "4242",
      "expirationMonth": "12",
      "expirationYear": "2025"
    },
    "display": {
      "name": "Visa",
      "color": "#1A1F71"
    }
  },
  "credentialTypes": ["network-token", "virtual-card", "pan"],
  "createdAt": "2025-01-15T14:00:00Z",
  "token": {
    "id": "token_26859380-7829-4ee1-8a0a-38927881e7ef",
    "fingerprint": "fp_1234567890abcdef",
    "createdAt": "2025-01-15T14:00:00Z",
    "maskedData": "424242****4242"
  }
}

Response Properties

PropertyTypeDescription
idstringThe payment method ID.
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 for this payment method.
createdAtstringISO 8601 timestamp when the payment method was created.
tokenToken ObjectSecure token information from BasisTheory.

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

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.

Note: The token object is only included if the project has its own BasisTheory API key configured.

Error Handling

{
  "error": {
    "status": 400,
    "type": "invalidRequest",
    "title": "The request is invalid",
    "message": "Request is invalid, check details object for details.",
    "details": {
      "fields": {
        "card.number": "Must be a valid card number."
      }
    }
  }
}