Generate One Time Token

  • Create a HtmlWidget using the below code.
<html>
    <body>
        <div id="widget"> </div>
        <script src="https://widget.paydock.com/sdk/latest/widget.umd.min.js"></script>
        <script>
            var widget = new paydock.HtmlWidget("#widget", publicKey, gatewayId, "card", "payment_source");
            widget.setEnv("production"); // The environment defaults to sandbox if not explicitly set

            widget.on("finish", function (data) {
                console.log("on:finish", data);
            });

            widget.load();
        </script>
    </body>
</html>
{
    "event": "finish",
    "purpose": "payment_source",
    "message_source": "widget.paydock",
    "ref_id": "",
    "widget_id": "6e66cf5a-4391-1da0-a2c7-8bf122503e75",
    "payment_source": "efa7b3ca-d96a-40ab-b3fc-0570158ce1ad"
}

Converting the One Time Token to a Vault Token

The payment_source in the response is your One time token. To add this as a customer as a payment source, you need to convert it to a vault token.

ENDPOINTMETHODHEADERS
/v1/vault/payment_sources
POST
Content-Type: application/json
Authorization: Bearer token
POST /v1/vault/payment_sources HTTP/1.1
Host: api.paydock.com
x-user-secret-key: {{secret-key}}
Content-Type: application/json
{
    "token": "6311c15f-8024-42f9-8ed5-200621ecfb1d", // one time token
}
{
    "status": 201,
    "error": null,
    "resource": {
        "type": "payment_source",
        "data": {
            "type": "card",
            "_source_ip_address": "x.x.x.x",
            "vault_type": "permanent",
            "expire_month": 1,
            "expire_year": 2039,
            "card_name": "Wanda Mertz",
            "card_scheme": "mastercard",
            "card_number_last4": "0008",
            "card_number_bin": "51234500",
            "ref_token": "9139516499300184",
            "status": "active",
            "created_at": "2023-11-02T02:13:09.832Z",
            "company_id": "65235992df412413b29a8f3b",
            "vault_token": "3dc68807-d6d9-44bc-89a3-4cd922131b01",
            "updated_at": "2023-11-02T02:13:27.960Z"
        }
    }
}

Creating the customer

Using the vault_token received above. Perform a customer creation

When adding the payment source you can add it in one of two ways.

  • Tied to a gateway: Any charge done with this payment source go through a specific gateway to perform the charge.
  • Utilise routing rules: Any charge done with this payment source will apply your configured routing rules to determine which gateway to use when performing the charge.
POST /v1/customers HTTP/1.1
Host: api.paydock.com
x-user-secret-key: {{secret-key}}
Content-Type: application/json

{
    "first_name": "Wanda",
    "last_name": "Mertz",
    "payment_source": {
        "gateway_id": "5cbede1f151b842653e987be",
        "vault_token": "0fd20631-509e-45c7-a8f0-f1f36d6ad298"
    }
}
POST /v1/customers HTTP/1.1
Host: api.paydock.com
x-user-secret-key: {{secret-key}}
Content-Type: application/json

{
    "first_name": "Wanda",
    "last_name": "Mertz",
    "payment_source": {
        "vault_token": "0fd20631-509e-45c7-a8f0-f1f36d6ad298"
    }
}
{
    "status": 201,
    "error": null,
    "resource": {
        "type": "customer",
        "data": {
            "__v": 0,
            "created_at": "2020-05-27T12:15:25.738Z",
            "updated_at": "2020-05-27T12:15:25.738Z",
            "status": "active",
            "default_source": "5ece59dd9c49c657d60630ee",
            "_id": "5ece59dc9c49c657d60630ed",
            "payment_destinations": [],
            "payment_sources": [
                {
                    "updated_at": "2020-05-27T12:15:25.737Z",
                    "gateway_id": "5cbede1f151b842653e987be",
                    "vault_token": "0fd20631-509e-45c7-a8f0-f1f36d6ad298",
                    "card_name": "Wanda Mertz",
                    "expire_month": 9,
                    "expire_year": 2021,
                    "card_number_last4": "4242",
                    "card_number_bin": "42424242",
                    "card_scheme": "visa",
                    "ref_token": "cus_HM6N4T0hv9klsg", // this will be blank if you dont send a gateway when adding the payment source
                    "status": "active",
                    "created_at": "2020-05-27T12:15:25.728Z",
                    "_id": "5ece59dd9c49c657d60630ee",
                    "type": "card"
                }
            ],
            "statistics": {
                "total_collected_amount": 0,
                "successful_transactions": 0
            },
            "_service": {
                "default_gateway_id": "5cbede1f151b842653e987be"
            }
        }
    }
}