When adding a payment source to a customer, you can add it in two different ways

  • Add as the new default source
  • Add retaining the current default payment source

There are also many ways you can add a default source. Any of these methods can be used in the above two scenarios

{
    "payment_source": {
        "vault_token": "8549cac2-c4bb-432a-b4db-63e6614ac46c"
    }
}
{
    "payment_source": {
        "token": "8549cac2-c4bb-432a-b4db-63e6614ac46c"
    }
}
{
    "payment_source": {
        "card_name": "Wanda Mertz",
        "card_number": "4242424242424242",
        "expire_month": "09",
        "expire_year": "21",
        "card_ccv": "123"
    }
}
{
    "payment_source": {
        "gateway_id": "5cbede1f151b842653e987be",
        // add this value along with any other method of adding a payment source
        // this will tie the payment source to a gateway and create a gateway token.
    }
}

Add as new default source

POST /v1/customers/:id HTTP/1.1
Host: api.paydock.com
x-user-secret-key: {{secretKey}}
Content-Type: application/json
{
    "payment_source": {
        "gateway_id": "5cbede1f151b842653e987be",
        "card_name": "Wanda Mertz",
        "card_number": "4242424242424242",
        "expire_month": "09",
        "expire_year": "21",
        "card_ccv": "123"
    }
}

Add retaining the current default payment source

Perform a customer search by id

{
    "status": 200,
    "error": null,
    "resource": {
        "type": "customer",
        "data": {
            "_id": "654306419a90eda1ebc4be73",
            "_source_ip_address": "220.233.78.99",
            "first_name": "John",
            "last_name": "Smith",
            "email": "johnsmith@paydock.com",
            "phone": "+61411111111",
            "default_source": "65af21ec30c9a1524a4a65d4",
            "status": "active",
            "archived": false,
            "created_at": "2023-11-02T02:15:29.267Z",
            "updated_at": "2024-01-23T02:18:20.132Z",
            "_check_expire_date": false,
            "statistics": {
                "successful_transactions": 0,
                "total_collected_amount": 0
            },
            "_service": {
                "default_gateway_id": "65af1f3230c9a1524a4a5730"
            },
            "payment_sources": [
                {
                    "_id": "654306419a90eda1ebc4be76",
                    "type": "card",
                    "vault_token": "3dc68807-d6d9-44bc-89a3-4cd922131b01",
                    "card_name": "Wanda Mertz",
                    "card_number_bin": "51234500",
                    "card_number_last4": "0008",
                    "card_scheme": "mastercard",
                    "expire_month": 1,
                    "expire_year": 2039,
                    "status": "active",
                    "created_at": "2023-11-02T02:15:29.288Z",
                    "updated_at": "2024-01-23T02:18:20.131Z"
                },
                {
                    "_id": "65af21ec30c9a1524a4a65d4",
                    "type": "card",
                    "gateway_id": "65af1f3230c9a1524a4a5730",
                    "vault_token": "e4cdc653-171f-49e1-8d0a-e37b95ab79a9",
                    "card_name": "John Smith",
                    "card_number_last4": "4242",
                    "card_scheme": "visa",
                    "expire_month": 12,
                    "expire_year": 2024,
                    "status": "active",
                    "created_at": "2024-01-23T02:18:20.117Z",
                    "updated_at": "2024-01-23T02:18:20.131Z",
                    "ref_token": "cus_PQQPtePkIhwrZv"
                }
            ],
            "payment_destinations": [],
            "company_id": "65235992df412413b29a8f3b"
        }
    }
}

Get the resource.data.default_source from the response and pass that in your request to retain the current default source.

POST /v1/customers/:id HTTP/1.1
Host: api.paydock.com
x-user-secret-key: {{secretKey}}
Content-Type: application/json
{
    "default_source": "5ece5ed2bf87e8587723dd46",
    "payment_source": {
        "gateway_id": "5cbede1f151b842653e987be",
        "card_name": "Wanda Mertz",
        "card_number": "4242424242424242",
        "expire_month": "09",
        "expire_year": "21",
        "card_ccv": "123"
    }
}