# How to Retreive a Payment Method

On this page, you will find a walk-through guide on retrieving a payment method and the necessary information to accomplish this task.

## Prerequisites

Before making any call to the LINKs API, you first need a merchant account. Contact our team at Discover@LinksMerchantServices.com to get started.

## Retrieving a Payment Method

There are three endpoints you can use to retrieve payment methods:

<CardGroup cols={3}>

<Card
  title="Payment Method ID"
  href="#retrieve-payment-method-by-payment-method-id"
  icon="coins"
/>

<Card
  title="Customer ID"
  href="#retrieve-payment-method-by-customer-id"
  icon="id-card"
/>

<Card
  title="Customer Reference"
  href="#retrieve-payment-method-by-customer-reference"
  icon="funnel"
/>

</CardGroup>

### Retrieve Payment Method by Payment Method ID

To retrieve a payment method by its ID, you need to call the [Retrieve a Payment Method endpoint](/api/payment-method/get-api-paymentmethod-identifier). The following is the required parameter:

<table>
  <thead>
    <tr>
      <th><strong>Parameter</strong></th>
      <th><strong>Description</strong></th>
      <th><strong>Required</strong></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code>paymentMethodIdentifier</code></td>
      <td>The unique identifier of the payment method to retrieve.</td>
      <td>Yes</td>
    </tr>
  </tbody>
</table>

You can use the code snippet below to make the endpoint call with the required parameter:

```sh
curl --request GET \
--url 'https://testapi.linksmerchantservices.com/api/paymentmethods/<PAYMENT_METHOD_IDENTIFIER>' \
--header 'Accept: application/json' \
--header 'Authorization: Basic <your_base64_encoded_credentials>'
```

<Callout type="info" title="Authentication">
  Depending on the request, LINKs API offers two forms of authentication,
  `Basic` and `client token`. Refer to the [Authentication](/authentication)
  guide to learn more about it.
</Callout>

This will result in a JSON response exemplified below:

```json
{
  "result": {
    "resultType": "Success",
    "merchantMessage": "Payment method retrieved successfully.",
    "logIdentifier": "def67890",
    "logAsError": false
  },
  "merchantIdentifier": "<your_merchant_id>",
  "customerIdentifier": "<optional_customer_id>",
  "customerReference": "<optional_customer_reference>",
  "paymentMethodIdentifier": "pm_123456789",
  "card": {
    "cardNumber": "************1111",
    "expiryMonth": 12,
    "expiryYear": 2025,
    "cardHolderName": "John Doe",
    "creditCardBrand": "Visa"
  },
  "billingInformation": {
    "firstLine": "123 Main St",
    "secondLine": "Apt 4B",
    "city": "Anytown",
    "region": "Anystate",
    "zipCode": "12345",
    "countryAlpha3Code": "USA",
    "countryId": 840
  }
}
```

### Retrieve Payment Method by Customer ID

To retrieve all payment methods linked to a customer, you need to call the [Retrieve Customer Payment Methods by ID endpoint](/api/payment-method/get-api-paymentmethod-customer-identifier-customeridentifier). The following is the required parameter:

<table>
  <thead>
    <tr>
      <th><strong>Parameter</strong></th>
      <th><strong>Description</strong></th>
      <th><strong>Required</strong></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code>customerIdentifier</code></td>
      <td>The unique identifier of the customer whose payment methods you want to retrieve.</td>
      <td>Yes</td>
    </tr>
  </tbody>
</table>

You can use the code snippet below to make the endpoint call with the required parameter:

```sh
curl --request GET \
--url 'https://testapi.linksmerchantservices.com/api/paymentmethod/customer/identifier/<CUSTOMER_IDENTIFIER>' \
--header 'Accept: application/json' \
--header 'Authorization: Basic <your_base64_encoded_credentials>'
```

This will result in a JSON response exemplified below:

```json
{
  "result": {
    "resultType": "Success",
    "merchantMessage": "Payment methods retrieved successfully.",
    "logIdentifier": "ghi90123",
    "logAsError": false
  },
  "merchantIdentifier": "<your_merchant_id>",
  "customerIdentifier": "<customer_id>",
  "customerReference": "<customer_reference>",
  "paymentMethods": [
    {
      "paymentMethodIdentifier": "pm_123456789",
      "card": {
        "cardNumber": "************1111",
        "expiryMonth": 12,
        "expiryYear": 2025,
        "cardHolderName": "John Doe",
        "creditCardBrand": "Visa"
      },
      "billingInformation": {
        "firstLine": "123 Main St",
        "secondLine": "Apt 4B",
        "city": "Anytown",
        "region": "Anystate",
        "zipCode": "12345",
        "countryAlpha3Code": "USA"
      }
    },
    {
      "paymentMethodIdentifier": "pm_987654321",
      "card": {
        "cardNumber": "************4242",
        "expiryMonth": 6,
        "expiryYear": 2024,
        "cardHolderName": "Jane Smith",
        "creditCardBrand": "MasterCard"
      },
      "billingInformation": {
        "firstLine": "456 Elm St",
        "secondLine": null,
        "city": "Othertown",
        "region": "Otherstate",
        "zipCode": "67890",
        "countryAlpha3Code": "USA"
      }
    }
  ]
}
```

<Callout type="info" title="Handling Multiple Payment Methods">
  The `paymentMethods` array may contain multiple payment methods if the customer has more than one saved. Each entry provides the details of a specific payment method.
</Callout>

### Retrieve Payment Method by Customer Reference

To retrieve all payment methods linked to a customer reference, you need to call the [Retrieve Customer Payment Methods by Reference endpoint](/api/payment-method/get-api-paymentmethod-customer-reference-customerreference). The following is the required parameter:

<table>
  <thead>
    <tr>
      <th><strong>Parameter</strong></th>
      <th><strong>Description</strong></th>
      <th><strong>Required</strong></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code>customerReference</code></td>
      <td>The unique reference of the customer whose payment methods you want to retrieve.</td>
      <td>Yes</td>
    </tr>
  </tbody>
</table>

You can use the code snippet below to make the endpoint call with the required parameter:

```sh
curl --request GET \
--url 'https://testapi.linksmerchantservices.com/api/paymentmethod/customer/reference/<CUSTOMER_REFERENCE>' \
--header 'Accept: application/json' \
--header 'Authorization: Basic <your_base64_encoded_credentials>'
```

This will result in a JSON response exemplified below:

```json
{
  "result": {
    "resultType": "Success",
    "merchantMessage": "Payment methods retrieved successfully.",
    "logIdentifier": "mno12345",
    "logAsError": false
  },
  "merchantIdentifier": "<your_merchant_id>",
  "customerIdentifier": "<customer_id>",
  "customerReference": "<customer_reference>",
  "paymentMethods": [
    {
      "paymentMethodIdentifier": "pm_123456789",
      "card": {
        "cardNumber": "************1111",
        "expiryMonth": 12,
        "expiryYear": 2025,
        "cardHolderName": "John Doe",
        "creditCardBrand": "Visa"
      },
      "billingInformation": {
        "firstLine": "123 Main St",
        "secondLine": "Apt 4B",
        "city": "Anytown",
        "region": "Anystate",
        "zipCode": "12345",
        "countryAlpha3Code": "USA"
      }
    },
    {
      "paymentMethodIdentifier": "pm_987654321",
      "card": {
        "cardNumber": "************4242",
        "expiryMonth": 6,
        "expiryYear": 2024,
        "cardHolderName": "Jane Smith",
        "creditCardBrand": "MasterCard"
      },
      "billingInformation": {
        "firstLine": "456 Elm St",
        "secondLine": null,
        "city": "Othertown",
        "region": "Otherstate",
        "zipCode": "67890",
        "countryAlpha3Code": "USA"
      }
    }
  ]
}
```

<Callout type="info" title="Handling Multiple Payment Methods">
  The `paymentMethods` array may contain multiple payment methods if the customer has more than one saved. Each entry provides the details of a specific payment method.
</Callout>