Skip to main content
POST
/
api
/
cards
/
assign
Assign Card to Customer
curl --request POST \
  --url https://api.example.com/api/cards/assign \
  --header 'Content-Type: application/json' \
  --data '
{
  "userId": "<string>",
  "source": "<string>"
}
'
{
  "status": true,
  "message": "<string>",
  "data": {
    "cardId": "<string>",
    "brand": "<string>",
    "last4": "<string>"
  }
}
Attaches a tokenized card (source) to an existing Stripe customer. The card becomes a payment method that can be used for future payments.
You must first create a card token using the Create Card Token endpoint before assigning it to a customer.

Request Body

userId
string
required
The Stripe customer ID to assign the card to. Must start with cus_.Example: "cus_QRs9eKZ4xUzN2TP9"
source
string
required
The card token ID obtained from creating a card token. Must start with tok_.Example: "tok_1QRs9eKZ4xUzN2TP9vQqWXYZ"

Response

status
boolean
Indicates if the request was successful (true) or failed (false).
message
string
Human-readable message describing the result.Example: "Tarjeta añadida con éxito"
data
object
The assigned card information.

Example Request

curl -X POST https://your-api.com/api/cards/assign \
  -H "Content-Type: application/json" \
  -d '{
    "userId": "cus_QRs9eKZ4xUzN2TP9",
    "source": "tok_1QRs9eKZ4xUzN2TP9vQqWXYZ"
  }'

Example Response

{
  "status": true,
  "message": "Tarjeta añadida con éxito",
  "data": {
    "cardId": "card_1QRs9eKZ4xUzN2TPabcdefgh",
    "brand": "Visa",
    "last4": "4242"
  }
}

Workflow

The typical workflow for adding a card to a customer:
  1. Tokenize the card - Call Create Card Token with card details
  2. Assign to customer - Use this endpoint to attach the token to a customer
  3. Set as default (optional) - Call Set Default Card to make it the default payment method

Example: Complete Card Assignment Flow

Node.js
// Step 1: Create card token
const tokenResponse = await fetch('https://your-api.com/api/cards/create', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    number: '4242424242424242',
    exp_month: '12',
    exp_year: '2026',
    cvc: '123'
  })
});
const tokenData = await tokenResponse.json();

// Step 2: Assign token to customer
const assignResponse = await fetch('https://your-api.com/api/cards/assign', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    userId: 'cus_QRs9eKZ4xUzN2TP9',
    source: tokenData.data.token_id
  })
});
const assignData = await assignResponse.json();
console.log('Card assigned:', assignData);
Card tokens can only be used once. After assigning a token to a customer, the same token cannot be reused.

Build docs developers (and LLMs) love