Charging with saved payment details

You can store customer credit card and bank account details for future use, such as scheduled billing or re-populating form fields following a rejected transaction due to validation errors. After you create a saved card or bank, you can create a charge with a saved card.

Creating a saved card or bank

You’ll create a one-time payment token using credit card or bank account details and then save that one-time token as a saved payment token.

To create a saved credit card from a one-time token:

  1. Using a payment form, create a one-time token from card details.
  2. Create a saved credit card using a one-time token ID:
    curl -X POST -H "Content-Type:application/json" --user <secret_key>: https://api.chargeio.com/v1/cards  -d '
     {
       "token_id": "olxSbEDSRN6RxIURjOxKTw"
     }'

    Example response
    {
       "id": "RhX6GEGcS8SogoXMPD85xA",
       "created": "2017-02-28T17:46:31.267Z",
       "modified": "2017-02-28T17:46:31.267Z",
       "name": "Dave Bowman",
       "address1": "2001 Odyssey Ln",
       "address2": "Suite 100",
       "city": "Austin",
       "state": "TX",
       "postal_code": "78750",
       "type": "card",
       "number": "************4242",
       "fingerprint": "GunPelYVthifNV63LEw1",
       "card_type": "VISA",
       "exp_month": 10,
       "exp_year": 2022
     }

Tip: Create a saved bank account the same way by tokenizing the bank account details and sending the POST request to the banks endpoint instead.

Creating a charge with a saved card

Using saved payment details to create a charge is as simple as sending a POST request to the charges endpoint. The charge object should include the following properties:

curl -X POST -H "Content-Type:application/json" --user <secret_key>: https://api.chargeio.com/v1/charges -d '
{
  "amount": "50000",
  "method": "RhX6GEGcS8SogoXMPD85xA",
  "account_id": "diON4KOPnesamprmrxA8Iuo"
}'

Updating a saved card or bank

Currently, we only support creating a new saved card or bank from an existing card or bank or from a one-time token. We do not support updating or patching an existing saved card or bank.

You can achieve the desired result, however, by first creating a new one-time token using the existing saved card or bank ID (along with the updated properties) and then creating a new saved card or bank from this one-time token.

For example, to update the address on a saved card:

  1. Using a payment form, create a one-time token from saved card, overriding the address properties: Note: You can specify any of the properties for a one-time token on this request. Any properties you don’t specify will default to the value on the saved card.

    curl -X POST -H "Content-Type: application/json" --user <secret_key>: https://api.chargeio.com/v1/tokens -d '
    {
      "token_id": "RhX6GEGcS8SogoXMPD85xA",
      "address1": "<new address1>",
      "city": "<new city>",
      "state": "<new state>",
      "postal_code": "<new postal code>"
    }'

    Example response
    {
       "id": "zmJ9l9FpRRm-dJS6YkOy0A",
       "created": "2017-02-28T17:49:24.151Z",
       "modified": "2017-02-28T17:49:24.151Z",
       "name": "Dave Bowman",
       "address1": "<new address1>",
       "address2": "Suite 100",
       "city": "<new city>",
       "state": "<new state>",
       "postal_code": "<new postal code>",
       "type": "card",
       "number": "************4242",
       "card_type": "VISA",
       "exp_month": 10,
       "exp_year": 2022
     }
  2. Create a new saved card from the one-time token:
    curl -X POST -H "Content-Type: application/json" --user <secret_key>: https://api.chargeio.com/v1/cards -d '
     {
     "token_id": "zmJ9l9FpRRm-dJS6YkOy0A"
     }'

    Example response
    {
       "id": "EOxH4UW2RLOpDxRUAreCmw",
       "created": "2017-02-28T17:51:03.432Z",
       "modified": "2017-02-28T17:51:03.432Z",
       "name": "Dave Bowman",
       "address1": "<new address1>",
       "address2": "Suite 100",
       "city": "<new city>",
       "state": "<new state>",
       "postal_code": "<new postal code>",
       "type": "card",
       "number": "************4242",
       "fingerprint": "GunPelYVthifNV63LEw1",
       "card_type": "VISA",
       "exp_month": 10,
       "exp_year": 2022
     }
  3. Use the new saved card ID to run a charge:
    curl -X POST -H "Content-Type:application/json" --user <secret_key>: https://api.chargeio.com/v1/charges -d '
     {
       "amount": "50000",
       "method": "EOxH4UW2RLOpDxRUAreCmw",
       "account_id": "diON4KOPnesamprmrxA8Iuo"
     }'