# Components and Fields

The cards and components can be integrated with Chargebee by using 3D Secure, also referred to as 3DS popularly. The integration can be done without 3DS as well. Learn more.

# createComponent

This function is used to create a component based on the componentType and the options passed. Currently we support only the creation of card components, we will start supporting other component types soon.

Chargebee Instance object can be used to create components.

# Syntax

cbInstance.createComponent(componentType, options)
1

# Parameters

componentType
String Required
Allowed Values:
card
options
Object Hide properties
currency
String
Currency code in ISO 4217 format (USD, EUR). By default, base currency code will be used
icon
Boolean
Card type icon
locale
String
Locale code in ISO 639-1 format (en, fr). By default, `en` will be used
placeholder
Object Hide properties
Placeholder texts for number, cvv & expiry fields.
number
string
Given text will be applied as a placeholder for card number field.
expiry
string
Given text will be applied as a placeholder for card expiry field.
cvv
string
Given text will be applied as a placeholder for CVV field.
ariaLabel
Object Hide properties
Labels to be read out by the screen reader for accessibility purpose.
number
string
For the card number field, text given here is read out by the screen reader for accessibility purpose.
expiry
string
For the card expiry field, text given here is read out by the screen reader for accessibility purpose.
cvv
string
For the CVV field, text given here is read out by the screen reader for accessibility purpose.
classes
Object Hide properties
Class names that will be added to all container div elements for different states. Using this you can customize our components for different states.
focus
String
Pass the class name that will be applied during field focus.
empty
String
Pass the class name that will be applied when the field is empty. This will be applied only after blur event is fired on the field.
invalid
String
Pass the class name that will be applied when the field is invalid. This will be applied only after blur event is fired on the field.
complete
String
Pass the class name that will be applied when the field is complete. This will be applied only after blur event is fired on the field.
fonts
Array<Object | String>
Define the list of font definitions or font URLs
Object Hide properties
Font definition that will be used in our components
fontFamily
cssProperty Required
Font name
src
cssProperty Required
Source URL. Google Web Font or Typekit Web Font URL
fontStyle
cssProperty
fontWeight
cssProperty
String
Web font URL (Either Google Web Font or Typekit Web Font)
style
Object Hide properties
Inline styles that needs to be applied to all input fields.
base
Object Hide properties
Pass the set of css properties that needs to be applied on default state.
color
cssProperty
lineHeight
cssProperty
letterSpacing
cssProperty
textAlign
cssProperty
textTransform
cssProperty
textDecoration
cssProperty
textShadow
cssProperty
fontFamily
cssProperty
fontWeight
cssProperty
fontSize
cssProperty
fontSmoothing
cssProperty
fontSmoothing
cssProperty
fontSmoothing
cssProperty
fontStyle
cssProperty
fontVariant
cssProperty
:focus
Object Hide properties
color
cssProperty
fontSize
cssProperty
iconColor
cssProperty
::placeholder
Object Hide properties
color
cssProperty
fontSize
cssProperty
::selection
Object Hide properties
color
cssProperty
backgroundColor
cssProperty
background
cssProperty
:-webkit-autofill
Object Hide properties
color
cssProperty
webkitTextColor
cssProperty
:focus::placeholder
Object Hide properties
color
cssProperty
iconColor
cssProperty
empty
Object Hide properties
Pass the set of css properties that needs to be applied on empty state
color
cssProperty
letterSpacing
cssProperty
textAlign
cssProperty
textTransform
cssProperty
textDecoration
cssProperty
textShadow
cssProperty
fontFamily
cssProperty
fontWeight
cssProperty
fontSize
cssProperty
fontSmoothing
cssProperty
fontSmoothing
cssProperty
fontSmoothing
cssProperty
fontStyle
cssProperty
fontVariant
cssProperty
:focus
Object Hide properties
color
cssProperty
fontSize
cssProperty
iconColor
cssProperty
::placeholder
Object Hide properties
color
cssProperty
fontSize
cssProperty
::selection
Object Hide properties
color
cssProperty
backgroundColor
cssProperty
background
cssProperty
:-webkit-autofill
Object Hide properties
color
cssProperty
webkitTextColor
cssProperty
:focus::placeholder
Object Hide properties
color
cssProperty
iconColor
cssProperty
invalid
Object Hide properties
Pass the set of css properties that needs to be applied on invalid state
color
cssProperty
letterSpacing
cssProperty
textAlign
cssProperty
textTransform
cssProperty
textDecoration
cssProperty
textShadow
cssProperty
fontFamily
cssProperty
fontWeight
cssProperty
fontSize
cssProperty
fontSmoothing
cssProperty
fontSmoothing
cssProperty
fontSmoothing
cssProperty
fontStyle
cssProperty
fontVariant
cssProperty
:focus
Object Hide properties
color
cssProperty
fontSize
cssProperty
iconColor
cssProperty
::placeholder
Object Hide properties
color
cssProperty
fontSize
cssProperty
::selection
Object Hide properties
color
cssProperty
backgroundColor
cssProperty
background
cssProperty
:-webkit-autofill
Object Hide properties
color
cssProperty
webkitTextColor
cssProperty
:focus::placeholder
Object Hide properties
color
cssProperty
iconColor
cssProperty
showTestCards
Boolean
Use this flag to show the test cards for sandbox environments while testing payment workflows for card-based payments.

# Return value

Card component object

# Example

cbInstance.createComponent("card", {
  placeholder: {
    number: "Number",
    expiry: "Expiry",
    cvv: "CVV",
  },
  classes: {
    focus: 'focus',
    invalid: 'invalid',
    empty: 'empty',
    complete: 'complete',
  },
  style: {
    // override styles for default state
    base: {
      color: '#333',
      fontWeight: '500',
      fontFamily: 'Lato, BlinkMacSystemFont, Segoe UI, Helvetica Neue, sans-serif',
      fontSize: '16px',
      fontSmoothing: 'antialiased',
      ':focus': {
        color: '#424770',
      },

      '::placeholder': {
        color: 'transparent',
      },

      ':focus::placeholder': {
        color: '#7b808c',
      },
      ':-webkit-autofill': {
        webkitTextColor: '#333',
      }
    },

    invalid: {
      color: '#e41029',

      ':focus': {
        color: '#e44d5f',
      },
      '::placeholder': {
        color: '#FFCCA5',
      },
    }
  },
  
  fonts: [
    "https://fonts.googleapis.com/css?family=Lato:400,700"
  ]
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

# Card component object

# tokenize

Send the card details to the payment gateway for tokenization. The payment gateway for processing the card details is selected based on smart routing (opens new window).

If multi business entity (opens new window) is configured, then the payment gateway configured for the business entity specified during Chargebee.js initialization init is selected here.

# Syntax

cardComponent.tokenize(additionalData)
1

# Parameters

additionalData
Object Hide properties
Additional information that you collect as part of card details can be passed. These information will be used while creating a payment source for the customer.
firstName
string
First name.
lastName
string
Last name.
addressLine1
string
Billing address line 1.
addressLine2
string
Billing address line 2.
city
string
City.
state
string
State.
stateCode
string
2 letter state code.
zip
string
Zip
countryCode
string
2 letter country code.

# Return value

Promise that resolves Chargebee token object.

{
  // Temp token from chargebee
  "token": "cb_tok_169lsYTCUvZ0l4oKl",
}
1
2
3
4

# Example

let cardComponent = cbInstance.createComponent("card");
cbInstance.tokenize(cardComponent, {
  firstName: "John",
  lastName: "Doe",
  addressLine1: "1600 Amphitheatre Parkway",
  addressLine2: "<replace with sample>",
  city: "Mountain View",
  state: "California",
  stateCode: "CA",
  zip: "94039",
  countryCode: "US",
}).then((data) => {
  console.log('chargebee token', data.token);
}).catch((error) => {
  console.log(error);
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

# authorizeWith3ds

This function is used to initiate 3DS authorization against the card details entered in the card component fields. After successful payment authorization, the payment intent is returned with authorized state. The paymentIntent ID can then be used to create a payment source (opens new window) or create a subscription (opens new window).

This method internally uses the 3DS Helper provided by Chargebee.

# Syntax

cardComponent.authorizeWith3ds(paymentIntent, additionalData, callbacks)
1

# Parameters

paymentIntent
Object Required
Pass the payment intent object.
additionalData
Object Hide properties
Additional information that needs to be passed for improving the chances of frictionless checkout flow.
plan
String
Plan name
billingAddress
Object Hide properties
Card Billing Address
firstName
String Required if Worldpay gateway is used
First name associated with billing address
lastName
String
Last name associated with billing address
phone
String
Phone number associated with the billing address
addressLine1
String
Billing address line 1 (eg. number, street, etc).
addressLine2
String
Billing address line 2 (eg. suite, apt #, etc.).
addressLine3
String
Billing address line 3 (eg. suite, apt #, etc).
city
String
City or locality name
state
String
State
stateCode
String
2 letter code for US states or equivalent
countryCode
String
2 letter country code
zip
String
Zip code or postal code
customerBillingAddress
Object Hide properties
Customer's Billing Address
firstName
String Required if Worldpay gateway is used
First name associated with billing address
lastName
String
Last name associated with billing address
phone
String
Phone number associated with the billing address
addressLine1
String
Billing address line 1 (eg. number, street, etc).
addressLine2
String
Billing address line 2 (eg. suite, apt #, etc.).
addressLine3
String
Billing address line 3 (eg. suite, apt #, etc).
city
String
City or locality name
state
String
State
stateCode
String
2 letter code for US states or equivalent
countryCode
String
2 letter country code
zip
String
Zip code or postal code
shippingAddress
Object Hide properties
Shipping Address
firstName
String Required if Worldpay gateway is used
First name associated with shipping address
lastName
String
Last name associated with shipping address
phone
String
Phone number associated with the shipping address
addressLine1
String
Shipping address line 1 (eg. number, street, etc).
addressLine2
String
Shipping address line 2 (eg. suite, apt #, etc.).
addressLine3
String
Shipping address line 3 (eg. suite, apt #, etc).
city
String
City or locality name
state
String
State
stateCode
String
2 letter code for US states or equivalent
countryCode
String
2 letter country code
zip
String
Zip code or postal code
email
String Required if Worldpay gateway is used
Mail ID of the customer.
phone
String
Phone number
mandate
Object Hide properties
Enabling this parameter will request Additional Factor Authentication (AFA) and mandate setup to the gateway. Applicable only for cards issued in India.
requireMandate
Boolean
Set the value as `true` to create a mandate. The default value is `false`.
description
String
Send the plan name in this description. This plan name will appear on the AFA page.
callbacks
Object Hide properties
Callbacks to be used for this operation.
change
Function
This function will be called during each step of 3DS flow
success
Function
This function will be called if 3DS Authorization is successful
error
Function
This function will be called if 3DS Authorization has failed
challenge
Function
When this callback is implemented, the transaction will proceed in a redirect workflow if supported by the gateway. This callback function will be called with a redirect URL when the 3DS transaction requires a challenge. This workflow is currently supported by Adyen, Braintree and Stripe payment gateways.

# Return value

Promise that resolves to authorized payment intent object.

# Example

const cardComponent = cbInstance.createComponent("card");
cardComponent.mount("#card-field");

function onSubmit() {
  createPaymentIntent().then(paymentIntent => {
    const additionalData = {
      firstName: "John",
      lastName: "Doe",
      billingAddr1: "1600 Amphitheatre Parkway",
      billingCity: "Mountain View",
      billingState: "California",
      billingStateCode: "CA",
      billingZip: "94039",
      billingCountry: "United States",
    };
    return cardComponent.authorizeWith3ds(paymentIntent, additionalData)
  }).then((paymentIntent) => {
    console.log('payment intent authorized', paymentIntent.id);
  }).catch((error) => {
    console.log('payment intent refused');
  });
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

# on

This function is used to attach listeners to the card component. In Default mode, focus, blur, ready, and change events can be attached.

# Syntax

cardComponent.on(eventType, callbackFunction)
1

# Parameters

eventType
String Required
Allowed Values:
ready
focus
blur
change
callbackFunction
Function Required
Function that will be called when the corresponding event fires.
Other than ready event, all callback functions will get the current state as argument, with the following properties,
  • field String
    Corresponding field type
  • type String
    Event type for which the callback got triggered
  • complete Boolean
    This will be true, if the fields are filled completely
  • error Object
    If the component has any validation errors, the corresponding error message and error code are passed {name, message}
  • cardType String
    Card number type
    Example values are: mastercard, visa, amex, etc.
  • empty Boolean
    If the component is empty

# Return value

Returns card component object

# Example

cardComponent.on('ready', () => {
  console.log("field is ready to collect data");
})
cardComponent.on('focus', () => {
  // Triggered when field is focused
})
cardComponent.on('blur', () => {
  // Triggered when field is blurred
})
cardComponent.on('change', (currentState) => {
  // This event will be triggered whenver the state changes from "empty" -> "complete" -> "valid / invalid"
  // The validation errors for this field can be checked here
  console.log(currentState.error);
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# createField

If you want to display the card component in Fields mode, you need to use this method to create number, cvv and expiry fields. You can pass options to override options passed at the component level.

# Syntax

cardComponent.createField(fieldType, options)
1

# Parameters

fieldType
String Required
Allowed Values:
number
cvv
expiry
options
Object Hide properties
placeholder
String
Placeholder text for the corresponding input field.
ariaLabel
String
Label to be read out by the screen reader for accessibility purpose.
icon
Boolean
Card type icon
style
Object Hide properties
Inline styles that needs to be applied to all input fields.
base
Object Hide properties
Pass the set of css properties that needs to be applied on default state.
color
cssProperty
lineHeight
cssProperty
letterSpacing
cssProperty
textAlign
cssProperty
textTransform
cssProperty
textDecoration
cssProperty
textShadow
cssProperty
fontFamily
cssProperty
fontWeight
cssProperty
fontSize
cssProperty
fontSmoothing
cssProperty
fontSmoothing
cssProperty
fontSmoothing
cssProperty
fontStyle
cssProperty
fontVariant
cssProperty
:focus
Object Hide properties
color
cssProperty
fontSize
cssProperty
iconColor
cssProperty
::placeholder
Object Hide properties
color
cssProperty
fontSize
cssProperty
::selection
Object Hide properties
color
cssProperty
backgroundColor
cssProperty
background
cssProperty
:-webkit-autofill
Object Hide properties
color
cssProperty
webkitTextColor
cssProperty
:focus::placeholder
Object Hide properties
color
cssProperty
iconColor
cssProperty
empty
Object Hide properties
Pass the set of css properties that needs to be applied on empty state
color
cssProperty
letterSpacing
cssProperty
textAlign
cssProperty
textTransform
cssProperty
textDecoration
cssProperty
textShadow
cssProperty
fontFamily
cssProperty
fontWeight
cssProperty
fontSize
cssProperty
fontSmoothing
cssProperty
fontSmoothing
cssProperty
fontSmoothing
cssProperty
fontStyle
cssProperty
fontVariant
cssProperty
:focus
Object Hide properties
color
cssProperty
fontSize
cssProperty
iconColor
cssProperty
::placeholder
Object Hide properties
color
cssProperty
fontSize
cssProperty
::selection
Object Hide properties
color
cssProperty
backgroundColor
cssProperty
background
cssProperty
:-webkit-autofill
Object Hide properties
color
cssProperty
webkitTextColor
cssProperty
:focus::placeholder
Object Hide properties
color
cssProperty
iconColor
cssProperty
invalid
Object Hide properties
Pass the set of css properties that needs to be applied on invalid state
color
cssProperty
letterSpacing
cssProperty
textAlign
cssProperty
textTransform
cssProperty
textDecoration
cssProperty
textShadow
cssProperty
fontFamily
cssProperty
fontWeight
cssProperty
fontSize
cssProperty
fontSmoothing
cssProperty
fontSmoothing
cssProperty
fontSmoothing
cssProperty
fontStyle
cssProperty
fontVariant
cssProperty
:focus
Object Hide properties
color
cssProperty
fontSize
cssProperty
iconColor
cssProperty
::placeholder
Object Hide properties
color
cssProperty
fontSize
cssProperty
::selection
Object Hide properties
color
cssProperty
backgroundColor
cssProperty
background
cssProperty
:-webkit-autofill
Object Hide properties
color
cssProperty
webkitTextColor
cssProperty
:focus::placeholder
Object Hide properties
color
cssProperty
iconColor
cssProperty

# Return value

Card Field object

# Example

cardComponent.createField("number", {
  placeholder: "4111 1111 1111 1111",
  styles: {
    // override styles for default state
    base: {
      color: '#333',
      fontWeight: '500',
      fontFamily: 'Poppins,-apple-system, BlinkMacSystemFont, Segoe UI, Helvetica Neue, sans-serif',
      fontSize: '16px',
      fontSmoothing: 'antialiased',
      ':focus': {
        color: '#424770',
      },

      '::placeholder': {
        color: 'transparent',
      },

      ':focus::placeholder': {
        color: '#7b808c',
      },
    },

    invalid: {
      color: '#e41029',

      ':focus': {
        color: '#e44d5f',
      },
      '::placeholder': {
        color: '#FFCCA5',
      },
    }
  },
});

cardComponent.createField("cvv")
cardComponent.createField("expiry")
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

# mount

The components will be inserted into the DOM and will be ready for collecting card details only after this method gets called. The container element for mounting can also be specified here. Accepts either a DOM Element or a CSS Selector.

# Syntax

cardComponent.mount('#card-component');
1

# Parameters

querySelector
String Required
Query selector for the HTML DOM Element
HTMLElement
Object
HTML Element where the component has to be mounted

# Return value

Returns a promise that resolves after successfully mounting the component.

# focus

Use this method to programatically focus on the card field.

# Syntax

cardComponent.focus()
1

# Example

var cardComponent;
function onPageLoad() {
  cardComponent.focus();
}
1
2
3
4

# blur

Use this method to programatically trigger blur event on card fields.

# Syntax

cardComponent.blur();
1

# clear

Use this method to clear contents of card fields.

# Syntax

cardComponent.clear();
1

# update

Use this method to update the configuration for card fields.

# Syntax

cardComponent.update(options)
1

# Parameters

options
Object Hide properties
ariaLabel
String
Label to be read out by the screen reader for accessibility purpose.
classes
Object Hide properties
Class names that will be added to all container div elements for different states. Using this you can customize our components for different states.
focus
String
Pass the class name that will be applied during field focus.
empty
String
Pass the class name that will be applied when the field is empty. This will be applied only after blur event is fired on the field.
invalid
String
Pass the class name that will be applied when the field is invalid. This will be applied only after blur event is fired on the field.
complete
String
Pass the class name that will be applied when the field is complete. This will be applied only after blur event is fired on the field.
currency
String
Currency code in ISO 4217 format (USD, EUR). By default, base currency code will be used
fonts
Array<Object | String>
Define the list of font definitions or font URLs
Object Hide properties
Font definition that will be used in our components
fontFamily
cssProperty Required
Font name
src
cssProperty Required
Source URL. Google Web Font or Typekit Web Font URL
fontStyle
cssProperty
fontWeight
cssProperty
String
Web font URL (Either Google Web Font or Typekit Web Font)
icon
Boolean
Card type icon
locale
String
Locale code in ISO 639-1 format (en, fr). By default, `en` will be used
placeholder
String
Placeholder text for the corresponding input field.
style
Object Hide properties
Inline styles that needs to be applied to all input fields.
base
Object Hide properties
Pass the set of css properties that needs to be applied on default state.
color
cssProperty
lineHeight
cssProperty
letterSpacing
cssProperty
textAlign
cssProperty
textTransform
cssProperty
textDecoration
cssProperty
textShadow
cssProperty
fontFamily
cssProperty
fontWeight
cssProperty
fontSize
cssProperty
fontSmoothing
cssProperty
fontSmoothing
cssProperty
fontSmoothing
cssProperty
fontStyle
cssProperty
fontVariant
cssProperty
:focus
Object Hide properties
color
cssProperty
fontSize
cssProperty
iconColor
cssProperty
::placeholder
Object Hide properties
color
cssProperty
fontSize
cssProperty
::selection
Object Hide properties
color
cssProperty
backgroundColor
cssProperty
background
cssProperty
:-webkit-autofill
Object Hide properties
color
cssProperty
webkitTextColor
cssProperty
:focus::placeholder
Object Hide properties
color
cssProperty
iconColor
cssProperty
empty
Object Hide properties
Pass the set of css properties that needs to be applied on empty state
color
cssProperty
letterSpacing
cssProperty
textAlign
cssProperty
textTransform
cssProperty
textDecoration
cssProperty
textShadow
cssProperty
fontFamily
cssProperty
fontWeight
cssProperty
fontSize
cssProperty
fontSmoothing
cssProperty
fontSmoothing
cssProperty
fontSmoothing
cssProperty
fontStyle
cssProperty
fontVariant
cssProperty
:focus
Object Hide properties
color
cssProperty
fontSize
cssProperty
iconColor
cssProperty
::placeholder
Object Hide properties
color
cssProperty
fontSize
cssProperty
::selection
Object Hide properties
color
cssProperty
backgroundColor
cssProperty
background
cssProperty
:-webkit-autofill
Object Hide properties
color
cssProperty
webkitTextColor
cssProperty
:focus::placeholder
Object Hide properties
color
cssProperty
iconColor
cssProperty
invalid
Object Hide properties
Pass the set of css properties that needs to be applied on invalid state
color
cssProperty
letterSpacing
cssProperty
textAlign
cssProperty
textTransform
cssProperty
textDecoration
cssProperty
textShadow
cssProperty
fontFamily
cssProperty
fontWeight
cssProperty
fontSize
cssProperty
fontSmoothing
cssProperty
fontSmoothing
cssProperty
fontSmoothing
cssProperty
fontStyle
cssProperty
fontVariant
cssProperty
:focus
Object Hide properties
color
cssProperty
fontSize
cssProperty
iconColor
cssProperty
::placeholder
Object Hide properties
color
cssProperty
fontSize
cssProperty
::selection
Object Hide properties
color
cssProperty
backgroundColor
cssProperty
background
cssProperty
:-webkit-autofill
Object Hide properties
color
cssProperty
webkitTextColor
cssProperty
:focus::placeholder
Object Hide properties
color
cssProperty
iconColor
cssProperty

# Example

cardComponent.update({
  placeholder: '4111 1111 1111 1111'
})
1
2
3

# validateCardDetails

Use this method to validate the entered card details.

# Syntax

cardComponent.validateCardDetails()
1

# Return Value

Returns a promise that resolves to a boolean value true if card details are valid, and false if invalid

# Example

cardComponent.validateCardDetails().then(isValid => {
  if(isValid) {
    console.log('Card details are valid')
  } else {
    console.log('Card details are invalid')
  }
})
1
2
3
4
5
6
7

# Card field object

Card field object is used to specify where the fields should be mounted and add event listeners at the individual field level.

let numberField = cardComponent.createField("number")
let expiryField = cardComponent.createField("expiry")
let cvvField = cardComponent.createField("cvv")
1
2
3

Use createField method to create a card field object.

# at

This is needed only if you are using the card component in the field mode. This function is used to specifiy container element where the component will be mounted. Accepts either the CSS selector or a DOM Element.

# Syntax

cardField.at(domElement)
1

# Parameters

querySelector
String Required
Query selector for the HTML DOM element

# Return value

Returns the card field

# Example

cardField.at("#card-field");
1

# on

This function is used to attach listeners to the card component. In Fields mode only ready and change events can be attached.

# Syntax

cardField.on(eventType, callbackFunction)
1

# Parameters

eventType
String Required
Allowed Values:
ready
focus
blur
change
callbackFunction
Function Required
Function that will be called when the corresponding event fires.
Other than ready event, all callback functions will get the current state as argument, with the following properties,
  • field String
    Corresponding field type
  • type String
    Event type for which the callback got triggered
  • complete Boolean
    This will be true, if the fields are filled completely
  • error Object
    If the component has any validation errors, the corresponding error message and error code are passed {name, message}
  • cardType String
    Card number type
    Example values are: mastercard, visa, amex, etc.
  • empty Boolean
    If the component is empty

# Return Value

Returns card field object

# Example

// sample status object for change event on number field with error
{
  type: "change" // event type
  field: "number" // field type
  cardType: "visa" 
  complete: false 
  empty: false
  error: { // Validation error object
    name: "CARD_NUMBER_INCOMPLETE", 
    message: "Invalid card"
  }
}
1
2
3
4
5
6
7
8
9
10
11
12

# update

This function is used to programatically update the styling of field.

# Syntax

cardField.update(options)
1

# Parameters

placeholder
String
Placeholder text for the corresponding input field.
style
Object Hide properties
Inline styles that needs to be applied to all input fields.
base
Object Hide properties
Pass the set of css properties that needs to be applied on default state.
color
cssProperty
lineHeight
cssProperty
letterSpacing
cssProperty
textAlign
cssProperty
textTransform
cssProperty
textDecoration
cssProperty
textShadow
cssProperty
fontFamily
cssProperty
fontWeight
cssProperty
fontSize
cssProperty
fontSmoothing
cssProperty
fontSmoothing
cssProperty
fontSmoothing
cssProperty
fontStyle
cssProperty
fontVariant
cssProperty
:focus
Object Hide properties
color
cssProperty
fontSize
cssProperty
iconColor
cssProperty
::placeholder
Object Hide properties
color
cssProperty
fontSize
cssProperty
::selection
Object Hide properties
color
cssProperty
backgroundColor
cssProperty
background
cssProperty
:-webkit-autofill
Object Hide properties
color
cssProperty
webkitTextColor
cssProperty
:focus::placeholder
Object Hide properties
color
cssProperty
iconColor
cssProperty
empty
Object Hide properties
Pass the set of css properties that needs to be applied on empty state
color
cssProperty
letterSpacing
cssProperty
textAlign
cssProperty
textTransform
cssProperty
textDecoration
cssProperty
textShadow
cssProperty
fontFamily
cssProperty
fontWeight
cssProperty
fontSize
cssProperty
fontSmoothing
cssProperty
fontSmoothing
cssProperty
fontSmoothing
cssProperty
fontStyle
cssProperty
fontVariant
cssProperty
:focus
Object Hide properties
color
cssProperty
fontSize
cssProperty
iconColor
cssProperty
::placeholder
Object Hide properties
color
cssProperty
fontSize
cssProperty
::selection
Object Hide properties
color
cssProperty
backgroundColor
cssProperty
background
cssProperty
:-webkit-autofill
Object Hide properties
color
cssProperty
webkitTextColor
cssProperty
:focus::placeholder
Object Hide properties
color
cssProperty
iconColor
cssProperty
invalid
Object Hide properties
Pass the set of css properties that needs to be applied on invalid state
color
cssProperty
letterSpacing
cssProperty
textAlign
cssProperty
textTransform
cssProperty
textDecoration
cssProperty
textShadow
cssProperty
fontFamily
cssProperty
fontWeight
cssProperty
fontSize
cssProperty
fontSmoothing
cssProperty
fontSmoothing
cssProperty
fontSmoothing
cssProperty
fontStyle
cssProperty
fontVariant
cssProperty
:focus
Object Hide properties
color
cssProperty
fontSize
cssProperty
iconColor
cssProperty
::placeholder
Object Hide properties
color
cssProperty
fontSize
cssProperty
::selection
Object Hide properties
color
cssProperty
backgroundColor
cssProperty
background
cssProperty
:-webkit-autofill
Object Hide properties
color
cssProperty
webkitTextColor
cssProperty
:focus::placeholder
Object Hide properties
color
cssProperty
iconColor
cssProperty
ariaLabel
String
Label to be read out by the screen reader for accessibility purpose.

# Return value

Returns the card field object.

# Example

cardField.update({
  style: {
    base: {
      color: '#fff',
      fontSize: `18px`
    }
  }
});
1
2
3
4
5
6
7
8

# focus

This function is used to programatically focus on the field.

# Syntax

cardField.focus();
1

# blur

This function is used to programatically blur the field.

# Syntax

cardField.blur();
1

# clear

This function is used to clear the contents of the field.

# Syntax

cardField.clear();
1

# mount

This function optionally accepts a query selector for the HTML element, or the HTML element itself where the field has to be mounted.

# Syntax

cardField.mount(domElement);
1

# Parameters

querySelector
String Required
Query selector for the HTML DOM Element
HTMLElement
Object
HTML Element where the component has to be mounted

# Return value

Promise that resolves once the field is successfully mounted

# Example

// Usage 1
cardField.mount("#number-field");

// Usage 2
cardField.at("#number-field").mount();
1
2
3
4
5