> ## 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 transaction to a buyer

> Associate a transaction to a customer record.

Once a buyer has been created it's possible to link transactions to that buyer.
There are a few ways to associate a transaction to a buyer.

## Associate the payment method to a `buyer_id`

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

This will find a buyer with that `id` and associate it to the payment method for
this transaction. If a buyer with that `id` could not be found it's ignored.

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

  ```js Node
  const request = new TransactionRequest();
  request.amount = 1299;
  request.currency = "AUD";
  request.buyerId = "fe26475d-ec3e-4884-9553-f7356683f7f9";

  request.paymentMethod = new TransactionPaymentMethodRequest();
  request.paymentMethod.method = "card";
  request.paymentMethod.number = "4111111111111111";
  request.paymentMethod.expirationDate = "11/25";
  request.paymentMethod.securityCode = "123";

  const transaction = await client.authorizeNewTransaction(request);
  ```
</CodeGroup>

## Associate by `buyer_external_identifier`

Alternatively, a transaction can be associated to 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/transactions" \
      -H "Authorization: Bearer [JWT_TOKEN]" \
      -H "Content-Type: application/json" \
      -d '{
        "amount": 1299,
        "currency": "AUD",
        "buyer_external_identifier": "412231123",
        "payment_method": {
          "method": "card",
          "number": "4111111111111111",
          "expiration_date": "11/25",
          "security_code": "123",
        }
      }'
  ```

  ```js Node
  const request = new TransactionRequest();
  request.amount = 1299;
  request.currency = "AUD";
  request.buyerExternalIdentifier = "412231123";

  request.paymentMethod = new TransactionPaymentMethodRequest();
  request.paymentMethod.method = "card";
  request.paymentMethod.number = "4111111111111111";
  request.paymentMethod.expirationDate = "11/25";
  request.paymentMethod.securityCode = "123";

  const transaction = await client.authorizeNewTransaction(request);
  ```
</CodeGroup>
