Credit Cards .: Create

API Reference / v15

Create a Credit Card

This endpoint adds a new credit card for a user.

To add a credit card, you must have a token with the manage_user_payment_methods permission.

All credit card data must be encrypted client-side before it is sent over the API using one of the applicable Braintree client side encryption libraries.

Note: If you are using the LevelUp Sandbox for development, please see our list of test credit cards.

Request Endpoint

POST /v15/credit_cards

Authorization Required – User Token in Header

Authorization: token user="123897-99SCvr3kSe3TqqQid3DyPXfo2Kq98MyhF6CaNPqoDeMhJ18Uopq19uddcznu6R"

Request Body

{
  "credit_card": {
    "braintree_payment_nonce": "1d33bd85-b7e9-06ba-522f-c8e63a43950a"
  }
}

Request Parameters

Param Type Required Description
braintree_payment_
nonce
String Yes The nonce returned from Braintree using the applicable client side encryption library.

cURL Example

curl -X POST https://sandbox.thelevelup.com/v15/credit_cards \
  -H Accept:application/json \
  -H Content-Type:application/json \
  -H 'Authorization:token 123897-99SCvr3kSe3TqqQid3DyPXfo2Kq98MyhF6CaNPqoDeMhJ18Uopq19uddcznu6R' \
  -d '{
    "credit_card": {
      "braintree_payment_nonce": "f29237a1-59eb-0fd6-76a6-d0e6d32b4534"
    }
  }'

Example Response

HTTP/1.1 200 OK

{
  "credit_card": {
    "bin": "123456",
    "description": "JCB ending in 1234",
    "expiration_month": 7,
    "expiration_year": 2015,
    "id": 305999,
    "last_4": "1234",
    "promoted": true,
    "state": "active",
    "type": "JCB"
  }
}

Response Parameters

Key Type Description
bin String The first six digits of the card number.
description String A human-readable description of the credit card.
expiration_month Integer The month in which the card expires.
expiration_year Integer The year in which the card expires.
id Integer The credit card’s ID.
last_4 String The last four characters of the card number.
promoted Boolean Whether the card is the user’s promoted payment instrument.
state String The card’s state. Possible values: “active” — the card is available to be charged, “inactive” — the card may not be charged.
type String The type of card, e.g. Visa, Mastercard

Errors

The credit card details were invalid

HTTP/1.1 422 Unprocessable Entity

[
  {
    "error": {
      "object": "credit_card",
      "property": "expiration_year",
      "message": "Expiration year is invalid."
    }
  }
]

The credit card is already used by another LevelUp user

HTTP/1.1 422 Unprocessable Entity

[
  {
    "error": {
      "object": "credit_card",
      "property": "number",
      "message": "This card has already been associated with another LevelUp account..."
    }
  }
]