> For the complete documentation index, see [llms.txt](https://apidocs.akinon.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://apidocs.akinon.com/commerce/users/user-payment-and-card-management.md).

# User Payment & Card Management

### `GET` List User Saved Cards

Lists all saved credit cards associated with the authenticated user in the Commerce system. The response includes details like card ID, creation and modification dates, card name, masked card number, and the associated user ID.

**Path:** `/users/saved-cards/`

**Authentication Required:** Yes

**Headers:**

```
Accept-Language: <iso_language_code>
Cookie: <cookie-name>=<session_id>
```

**Example Request**

```py
import requests

url = "https://{commerce_url}/users/saved-cards/"

headers = {
  'Accept-Language: '<iso_language_code>',
  'Cookie': '<cookie-name>=<session_id>'
}

response = requests.get(url, headers=headers)
print(response.text)
```

**Example Response (200 OK)**

```json
{
    "count": 2,
    "next": null,
    "previous": null,
    "results": [
        {
            "id": 1,
            "created_date": "2024-11-18T14:05:59.000043Z",
            "modified_date": "2024-11-18T14:05:59.000798Z",
            "name": "Card 1",
            "token": "5420c64565001c88d4a40ea2196e0fcd",
            "masked_card_number": "**** **** **** 1234",
            "user": 414183
        },
        {
            "id": 20,
            "created_date": "2024-09-18T14:05:59.000043Z",
            "modified_date": "2024-09-18T14:05:59.000798Z",
            "name": "Card 2",
            "token": "fbab4cccbfddff68dca70d1e12b072bd",
            "masked_card_number": "**** **** **** 4523",
            "user": 414183
        }
    ]
}
```

### `GET` Retrieve User Saved Card

Retrieves the details of a specific saved card for the authenticated user, in the Commerce system. You must provide the card ID in the URL path.

**Path:** `/users/saved-cards/<card-id>/`

**Authentication Required:** Yes

**Headers:**

```
Cookie: <cookie-name>=<session_id>
```

**Example Request**

```py
import requests

url = "https://{commerce_url}/users/saved-cards/<card-id>"

headers = {
  'Cookie': '<cookie-name>=<session_id>',
}

response = requests.get(url, headers=headers)
print(response.text)
```

**Example Response (200 OK)**

```json
{
    "id": 20,
    "created_date": "2024-09-18T14:05:59.000043Z",
    "modified_date": "2024-09-18T14:05:59.000798Z",
    "name": "Card 2",
    "token": "fbab4cccbfddff68dca70d1e12b072bd",
    "masked_card_number": "**** **** **** 4523",
    "user": 414183
}
```

### `PATCH` Update User Saved Card

Updates the name of an existing specific saved card for the authenticated user, in the Commerce system. You must provide the card ID in the URL path.

**Path:** `/users/saved-cards/<card-id>/`

**Authentication Required:** Yes

**Headers:**

```
Content-Type: application/json
Accept-Language: <iso_language_code>
Cookie: <cookie-name>=<session_id>
x-csrftoken: <token>
```

**Body Parameters**

| Property | Data Type | Required | Description                               |
| :------: | :-------: | :------: | ----------------------------------------- |
|   name   |   String  |   False  | The name of the saved card to be updated. |

**Request Body**

```json
{
    "name": "Travel Card"
}
```

**Example Request**

```py
import requests

url = "https://{commerce_url}/user/saved-cards/<card-id>/"

headers = {
  'Content-Type': 'application/json',
  'Accept-Language: '<iso_language_code>',
  'Cookie': '<cookie-name>=<session_id>',
  'x-csrftoken': '<token>'
}

payload = json.dumps({
    "name": "Travel Card"
})

response = requests.patch(url, headers=headers, data=payload)
print(response.json())
```

**Example Response (200 OK)**

```json
{
    "id": 20,
    "created_date": "2024-09-18T14:05:59.000043Z",
    "modified_date": "2024-09-18T14:05:59.000798Z",
    "name": "Travel Card",
    "token": "fbab4cccbfddff68dca70d1e12b072bd",
    "masked_card_number": "**** **** **** 4523",
    "user": 414183
}
```

### `DELETE` Delete User Saved Card

Deletes a specific saved card for the authenticated user, in the Commerce system. You must provide the card ID in the URL path.

**Path:** `/users/saved-cards/<card-id>/`

**Authentication Required:** Yes

**Headers:**

```
Accept-Language: <iso_language_code>
Cookie: <cookie-name>=<session_id>
x-csrftoken: <token>
```

**Example Request**

```py
import requests

url = "https://{commerce_url}/users/saved-cards/<card-id>/"

headers = {
  'Accept-Language: '<iso_language_code>',
  'Cookie': '<cookie-name>=<session_id>'
  'x-csrftoken': '<token>'
}

response = requests.delete(url, headers=headers)
print(response.text)
```

**Example Response (204 No Content)**

No content is returned when the request is successful.

### `GET` User List Stored Cards

This endpoint retrieves a list of the stored cards for the authenticated user, stored on a different payment gateway. The information is masked for security reasons, ensuring that full card details are not exposed.

**Path:** `/users/stored-cards/`

**Authentication Required:** Yes

**Headers:**

```
Accept-Language: <iso_language_code>
Cookie: <cookie-name>=<session_id>
```

**Example Request**

```py
import requests

url = "https://{commerce_url}/users/stored-cards/"

headers = {
   'Accept-Language': '<iso_language_code>',
   'Cookie': '<cookie-name>=<session_id>'
}

response = requests.get(url, headers=headers)
print(response.text)
```

**Example Response (200 OK)**

```json
{
  "cards": [
    {
      "card_number": "555555******4444",
      "card_identifier": "f8a82d05-abe1-4ef6-a8d7-2c5ad7301bbd"
    },
    ...
  ]
}
```

**Response Parameters:**

| Property         | Data Type | Description                                 |
| ---------------- | --------- | ------------------------------------------- |
| card\_number     | string    | A masked version of the credit card number. |
| card\_identifier | string    | A unique identifier for the stored card.    |

### `DELETE` Delete User Stored Card

This endpoint is used to delete a stored card for the authenticated user, stored on a different payment gateway.

**Path:** `/users/stored-cards/<card-id>/`

**Authentication Required:** Yes

**Headers:**

```
Accept-Language: <iso_language_code>
Cookie: <cookie-name>=<session_id>
x-csrftoken: <token>
```

**Example Request**

```py
import requests

url = "https://{commerce_url}/user/cards/<card-id>/"
headers = {
   'Accept-Language': '<iso_language_code>',
   'Cookie': '<cookie-name>=<session_id>'
   'x-csrftoken': '<token>'
}

response = requests.delete(url, headers=headers)
print(response.status_code)
```

**Example Response (200 OK)**

No content returned.

**Example Response (400 Bad Request)**

If an error occurs while interacting with the gateway instance:

```json
{
  "non_field_errors": "An error occurred. Please try again later."
}
```

If an error occurs on a third-party API:

```json
{
   "error": "Invalid request data"
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://apidocs.akinon.com/commerce/users/user-payment-and-card-management.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
