Credit Cards

Credit cards can be associated to orders as their payment sources. Customers can save their credit cards in their wallets (as customer payment sources).

The credit card object

A credit card object is returned as part of the response body of each successful create, list, retrieve or update API call. The following table contains the list of all its fields along with their type, description and example values.
Object fields:
first_name
string
The cardholder's first name
Example:
John
last_name
string
The cardholder's last name
Example:
Smith
full_name
string
Handy attribute that returns the cardholder's first and last name
Example:
John Smith
month
string
The credit card expiration month
Example:
10
year
string
The credit card expiration year
Example:
2023
valid_thru
string
Handy attribute that returns 'month/year'
Example:
10/2023
card_type
string
The credit card type, e.g. visa, master, american_express
Example:
visa
display_number
string
The obscured credit card number. This can be useful to safely display an order's payment source details.
Example:
XXXX-XXXX-XXXX-1111
name
string
Alias for 'display_number'
Example:
XXXX-XXXX-XXXX-1111
fingerprint
string
A universal unique identifier for the credit card
Example:
9abc5b0ef273e53749068820b3a30640b838
storage_state
string
The credit card storage state within your vault. Can be one of 'cached', 'retained' or 'redacted'.
Example:
cached
id
integer
Unique identifier for the resource.
Example:
1234
created_at
datetime
Time at which the resource was created.
Example:
2018-01-01T12:00:00.000Z
updated_at
datetime
Time at which the resource was last updated.
Example:
2018-01-01T12:00:00.000Z
reference
string
A string that you can use to add your own identifier to the resource. This can be useful for intergrating the resource to an external system, like an ERP, a marketing tool or a CRM.
Example:
ANYREFEFERNCE
metadata
object
Set of key-value pairs that you can attach to the resource. This can be useful for storing additional information about the resource in a structured format.
Example:
{"foo":"bar"}
relationship (N:1)
The order associated to the credit card. If present, the credit card is set as the order's payment source.

Create a credit card

To create a new credit card, send a POST request to the /api/credit_cards endpoint, passing the resource arguments in the request body. The following table contains the list of all the possible arguments, along with their type, description and examples values. All the arguments marked as required must be present in the request.
Arguments:
first_name
required
The cardholder's first name
Example:
John
last_name
required
The cardholder's last name
Example:
Smith
number
required
The credit card number
Example:
4111111111111111
month
required
The credit card expiration month
Example:
10
year
required
The credit card expiration year
Example:
2023
verification_value
required
The credit card verification value (CCV, CVV)
Example:
123
reference
optional
A string that you can use to add your own identifier to the resource. This can be useful for intergrating the resource to an external system, like an ERP, a marketing tool or a CRM.
Example:
ANYREFEFERNCE
metadata
optional
Set of key-value pairs that you can attach to the resource. This can be useful for storing additional information about the resource in a structured format.
Example:
#
required
The order associated to the credit card. If present, the credit card is set as the order's payment source.
Example request:
POST /api/credit_cards HTTP/1.1
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json

{
  "data": {
    "type": "credit_cards",
    "attributes": {
      "first_name": "John",
      "last_name": "Smith",
      "number": "4111111111111111",
      "month": "10",
      "year": "2023",
      "verification_value": "123"
    },
    "relationships": {
      "order": {
        "data": {
          "type": "orders",
          "id": "1234"
        }
      }
    }
  }
}
Example response: 201 Created
HTTP/1.1 201 Created
Content-Type: application/vnd.api+json

{
  "data": {
    "id": "1234",
    "type": "credit_cards",
    "links": {
      "self": "https://your-brand.commercelayer.io/api/credit_cards/1234"
    },
    "attributes": {
      "first_name": "John",
      "last_name": "Smith",
      "full_name": "John Smith",
      "month": "10",
      "year": "2023",
      "valid_thru": "10/2023",
      "card_type": "visa",
      "display_number": "XXXX-XXXX-XXXX-1111",
      "name": "XXXX-XXXX-XXXX-1111",
      "fingerprint": "9abc5b0ef273e53749068820b3a30640b838",
      "storage_state": "cached",
      "id": "1234",
      "created_at": "2018-01-01T12:00:00.000Z",
      "updated_at": "2018-01-01T12:00:00.000Z",
      "reference": "ANYREFEFERNCE",
      "metadata": {
        "foo": "bar"
      }
    },
    "relationships": {
      "order": {
        "links": {
          "self": "https://your-brand.commercelayer.io/api/credit_cards/1234/relationships/order",
          "related": "https://your-brand.commercelayer.io/api/credit_cards/1234/order"
        }
      }
    },
    "meta": {
      "mode": "test"
    }
  }
}

List all credit cards

To fetch a collection of credit cards, send a GET request to the /api/credit_cards endpoint.

Example request:
GET /api/credit_cards HTTP/1.1
Accept: application/vnd.api+json
Example response: 200 OK
HTTP/1.1 200 OK
Content-Type: application/vnd.api+json

{
  "data": [
    {
      "id": "1234",
      "type": "credit_cards",
      "links": {
        "self": "https://your-brand.commercelayer.io/api/credit_cards/1234"
      },
      "attributes": {
        "first_name": "John",
        "last_name": "Smith",
        "full_name": "John Smith",
        "month": "10",
        "year": "2023",
        "valid_thru": "10/2023",
        "card_type": "visa",
        "display_number": "XXXX-XXXX-XXXX-1111",
        "name": "XXXX-XXXX-XXXX-1111",
        "fingerprint": "9abc5b0ef273e53749068820b3a30640b838",
        "storage_state": "cached",
        "id": "1234",
        "created_at": "2018-01-01T12:00:00.000Z",
        "updated_at": "2018-01-01T12:00:00.000Z",
        "reference": "ANYREFEFERNCE",
        "metadata": {
          "foo": "bar"
        }
      },
      "relationships": {
        "order": {
          "links": {
            "self": "https://your-brand.commercelayer.io/api/credit_cards/1234/relationships/order",
            "related": "https://your-brand.commercelayer.io/api/credit_cards/1234/order"
          }
        }
      },
      "meta": {
        "mode": "test"
      }
    },
    {
      "other": "... 24 credit_cards (first page)"
    }
  ],
  "meta": {
    "record_count": 125,
    "page_count": 5
  },
  "links": {
    "first": "/api/credit_cards?page[number]=1&page[size]=25",
    "prev": "/api/credit_cards?page[number]=2&page[size]=25",
    "next": "/api/credit_cards?page[number]=4&page[size]=25",
    "last": "/api/credit_cards?page[number]=5&page[size]=25"
  }
}
Available filters
idcard_typereferenceidscreated_at_fromcreated_at_toupdated_at_fromupdated_at_to
Sortable attributes
card_typeidcreated_atupdated_atreference

Retrieve a credit card

To fetch a single credit card, send a GET request to the /api/credit_cards/{{id}} endpoint, where {{id}} is the id of the resource that you want to retrieve.
Example request:
GET /api/credit_cards/1234 HTTP/1.1
Accept: application/vnd.api+json
Example response: 200 OK
HTTP/1.1 200 OK
Content-Type: application/vnd.api+json

{
  "data": {
    "id": "1234",
    "type": "credit_cards",
    "links": {
      "self": "https://your-brand.commercelayer.io/api/credit_cards/1234"
    },
    "attributes": {
      "first_name": "John",
      "last_name": "Smith",
      "full_name": "John Smith",
      "month": "10",
      "year": "2023",
      "valid_thru": "10/2023",
      "card_type": "visa",
      "display_number": "XXXX-XXXX-XXXX-1111",
      "name": "XXXX-XXXX-XXXX-1111",
      "fingerprint": "9abc5b0ef273e53749068820b3a30640b838",
      "storage_state": "cached",
      "id": "1234",
      "created_at": "2018-01-01T12:00:00.000Z",
      "updated_at": "2018-01-01T12:00:00.000Z",
      "reference": "ANYREFEFERNCE",
      "metadata": {
        "foo": "bar"
      }
    },
    "relationships": {
      "order": {
        "links": {
          "self": "https://your-brand.commercelayer.io/api/credit_cards/1234/relationships/order",
          "related": "https://your-brand.commercelayer.io/api/credit_cards/1234/order"
        }
      }
    },
    "meta": {
      "mode": "test"
    }
  }
}

Update a credit card

To update an existing credit card, send a PATCH request to the /api/credit_cards/{{id}} endpoint, where {{id}} is the id of the resource that you want to update. The following table contains the list of all the possible arguments that you can pass with the request body, along with their type, description and examples values. Please note that all arguments are optional.
Arguments:
first_name
optional
The cardholder's first name
Example:
John
last_name
optional
The cardholder's last name
Example:
Smith
month
optional
The credit card expiration month
Example:
10
year
optional
The credit card expiration year
Example:
2023
reference
optional
A string that you can use to add your own identifier to the resource. This can be useful for intergrating the resource to an external system, like an ERP, a marketing tool or a CRM.
Example:
ANYREFEFERNCE
metadata
optional
Set of key-value pairs that you can attach to the resource. This can be useful for storing additional information about the resource in a structured format.
Example:
#
optional
The order associated to the credit card. If present, the credit card is set as the order's payment source.
Example request:
PATCH /api/credit_cards/1234 HTTP/1.1
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json

{
  "data": {
    "type": "credit_cards",
    "id": 1234,
    "attributes": {
      "first_name": "John"
    },
    "relationships": {
    }
  }
}
Example response: 200 OK
HTTP/1.1 200 OK
Content-Type: application/vnd.api+json

{
  "data": {
    "id": "1234",
    "type": "credit_cards",
    "links": {
      "self": "https://your-brand.commercelayer.io/api/credit_cards/1234"
    },
    "attributes": {
      "first_name": "John",
      "last_name": "Smith",
      "full_name": "John Smith",
      "month": "10",
      "year": "2023",
      "valid_thru": "10/2023",
      "card_type": "visa",
      "display_number": "XXXX-XXXX-XXXX-1111",
      "name": "XXXX-XXXX-XXXX-1111",
      "fingerprint": "9abc5b0ef273e53749068820b3a30640b838",
      "storage_state": "cached",
      "id": "1234",
      "created_at": "2018-01-01T12:00:00.000Z",
      "updated_at": "2018-01-01T12:00:00.000Z",
      "reference": "ANYREFEFERNCE",
      "metadata": {
        "foo": "bar"
      }
    },
    "relationships": {
      "order": {
        "links": {
          "self": "https://your-brand.commercelayer.io/api/credit_cards/1234/relationships/order",
          "related": "https://your-brand.commercelayer.io/api/credit_cards/1234/order"
        }
      }
    },
    "meta": {
      "mode": "test"
    }
  }
}

Delete a credit card

To delete a credit card, send a DELETE request to the /api/credit_cards/{{id}} endpoint, where {{id}} is the id of the resource that you want to delete.
Example request:
DELETE /api/credit_cards/1234 HTTP/1.1
Accept: application/vnd.api+json
Example response: 204 No Content
HTTP/1.1 204 No Content

Get our machine-readable JSON schema that follows the OpenAPI Specification (formerly Swagger).

Get our Postman collection in one click and start making real calls to Commerce Layer API in minutes.

Get in touch with our support team if you have any questions or want to learn more about Commerce Layer.