Skip to main content

Documentation

Create Card Token

Create a hosted page for a customer to save card details and manage cards.

Prerequisites

Note

  • Certain card operations on the hosted page require 3DS authentication by the cardholder. To simulate the cardholder's action in the sandbox, see Simulating 3DS Authentication.

  • Before you run this method, verify that the payment method can be tokenized. See List Payment Methods by Country.

  • In the sandbox, card tokens are removed after six months.

Rapyd sends you webhooks for the following customer actions:

  • /v1/hosted/collect/card

  • Create Card Token

  • curl -X post 'https://sandboxapi.rapyd.net/v1/hosted/collect/card' \
    -H 'access_key: your-access-key-here' \
    -H 'Content-Type: application/json' \
    -H 'idempotency: your-idempotency-parameter-here' \
    -H 'salt: your-random-string-here' \
    -H 'signature: your-calculated-signature-here' \
    -H 'timestamp: your-unix-timestamp-here' \
    --data-raw '{
        "country": "GB",
        "customer": "cus_4e25112ac20e144ad073a614dc46934b",
        "complete_payment_url": "https://complete.rapyd.net/",
        "error_payment_url": "https://error.rapyd.net/",
        "card_fields": {
            "recurrence_type": "unscheduled"
        }
    }'
  • {
        "status": {
            "error_code": "",
            "status": "SUCCESS",
            "message": "",
            "response_code": "",
            "operation_id": "1c1bb5dc-4712-4afe-a253-b17ca129855f"
        },
        "data": {
            "id": "hp_card_dffdf3cfaa42472779c75f3e869ae964",
            "status": "NEW",
            "cancel_url": "https://example1234.net",
            "complete_url": "https://example1234.net",
            "language": null,
            "merchant_color": "323fff",
            "merchant_logo": null,
            "merchant_website": "https://example1234.net",
            "merchant_customer_support": {
                "url": "https://example1234.net",
                "email": "support@example1234.net",
                "phone_number": "121255551213"
            },
            "merchant_alias": "Doc Team",
            "page_expiration": 1764770507,
            "redirect_url": "https://sandboxhosted.rapyd.net/collect/card?token=hp_card_dffdf3cfaa42472779c75f3e869ae964",
            "category": "card",
            "country": "GB",
            "currency": "GBP",
            "customer": "cus_4e25112ac20e144ad073a614dc46934b",
            "payment_method_type": null,
            "payment_params": {
                "complete_payment_url": "https://complete.rapyd.net/",
                "error_payment_url": "https://error.rapyd.net/"
            },
            "billing_address_collect": false,
            "customer_card_payment_methods": null,
            "auto_set_default": false,
            "card_fields": {
                "recurrence_type": "unscheduled"
            }
        }
    }
  • Bad Request - Payment Method Not Supported in Country

  • curl -X post 'https://sandboxapi.rapyd.net/v1/hosted/collect/card' \
    -H 'access_key: your-access-key-here' \
    -H 'Content-Type: application/json' \
    -H 'idempotency: your-idempotency-parameter-here' \
    -H 'salt: your-random-string-here' \
    -H 'signature: your-calculated-signature-here' \
    -H 'timestamp: your-unix-timestamp-here' \
    --data-raw '{
    	"country": "ES",
    	"customer": "cus_2549026c92bd7cb5b02ba608daeb424b",
    	"payment_method_type": "us_mastercard_card"
    }'
  • {
        "status": {
            "error_code": "ERROR_HOSTED_PAGE_COLLECT_CARD_PAYMENT_METHOD_TYPE_NOT_SUPPORTED",
            "status": "ERROR",
            "message": "Please contact Rapyd Client Support.",
            "response_code": "ERROR_HOSTED_PAGE_COLLECT_CARD_PAYMENT_METHOD_TYPE_NOT_SUPPORTED",
            "operation_id": "b1e7792a-ac2f-4c35-8695-cedad3b74b51"
        }
    }
  • Bad Request - Customer Not Found

  • curl -X post 'https://sandboxapi.rapyd.net/v1/hosted/collect/card' \
    -H 'access_key: your-access-key-here' \
    -H 'Content-Type: application/json' \
    -H 'idempotency: your-idempotency-parameter-here' \
    -H 'salt: your-random-string-here' \
    -H 'signature: your-calculated-signature-here' \
    -H 'timestamp: your-unix-timestamp-here' \
    --data-raw '{
    	"country": "ES",
    	"customer": "cus_2549026c92bd7cb5b02ba608daeb424",
    	"payment_method_type": "es_mastercard_card"
    }'
  • {
        "status": {
            "error_code": "ERROR_HOSTED_PAGE_COLLECT_CARD_CUSTOMER_NOT_FOUND",
            "status": "ERROR",
            "message": "The request attempted a hosted page operation, but the customer was not found. The request was rejected. Corrective action: For 'customer', provide a valid customer ID, a string starting with 'cus_'.",
            "response_code": "ERROR_HOSTED_PAGE_COLLECT_CARD_CUSTOMER_NOT_FOUND",
            "operation_id": "7bb83aba-ed17-4aea-8d7b-e45e5dc2ef50"
        }
    }
Related Information