> ## Documentation Index
> Fetch the complete documentation index at: https://wpay-feat-edp-guide.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Associate a card to a buyer

> Associate a card to a customer record.

It is possible to bind a vaulted card to a buyer when it is being created.
There are a few ways to do so.

## Associate by `buyer_id`

The easiest way to associate a buyer with a card is to pass along a `buyer_id`
when creating a card.

This will find a buyer with that `id` and associate the card with it. If a buyer
with this `id` could not be found it's ignored.

<CodeGroup>
  ```bash cURL
  curl -i -X POST "https://api.example.gr4vy.app/payment-methods" \
      -H "Authorization: Bearer [JWT_TOKEN]" \
      -H "Content-Type: application/json" \
      -d '{
          "method": "card",
          "number": "4111111111111111",
          "expiration_date": "11 / 22",
          "security_code": "123",
          "buyer_id": "fe26475d-ec3e-4884-9553-f7356683f7f9"
        }'
  ```

  ```js Node
  const request = new CardRequest();
  request.method = "card";
  request.number = "4111111111111111";
  request.expirationDate = "11/25";
  request.securityCode = "123";
  request.buyerId = "fe26475d-ec3e-4884-9553-f7356683f7f9";

  const paymentMethod = await client.storePaymentMethod(request);
  ```
</CodeGroup>

## Associate by `buyer_external_identifier`

Alternatively, a card can be associated with a buyer by its
`external_identifier`. If a buyer with that `external_identifier` could not be
found it's ignored.

<CodeGroup>
  ```bash cURL
  curl -i -X POST "https://api.example.gr4vy.app/payment-methods" \
      -H "Authorization: Bearer [JWT_TOKEN]" \
      -H "Content-Type: application/json" \
      -d '{
          "method": "card",
          "number": "4111111111111111",
          "expiration_date": "11 / 22",
          "security_code": "123",
          "buyer_external_identifier": "412231123"
        }'
  ```

  ```js Node
  const request = new CardRequest();
  request.method = "card";
  request.number = "4111111111111111";
  request.expirationDate = "11/25";
  request.securityCode = "123";
  request.buyerExternalIdentifier = "412231123";

  const paymentMethod = await client.storePaymentMethod(request);
  ```
</CodeGroup>
