Members
(static) VERSION :string
The current version of the SDK, i.e. 3.88.3
.
- Source:
Methods
(static) create(options, callbackopt) → {void}
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
Creation options: Properties
|
|||||||||||||||||||||||||||||||
callback |
callback |
<optional> |
The second argument, |
- Source:
Examples
braintree.hostedFields.create({
client: clientInstance,
styles: {
'input': {
'font-size': '16pt',
'color': '#3A3A3A'
},
'.number': {
'font-family': 'monospace'
},
'.valid': {
'color': 'green'
}
},
fields: {
number: {
container: '#card-number'
},
cvv: {
container: '#cvv',
placeholder: '•••'
},
expirationDate: {
container: '#expiration-date'
}
}
}, callback);
braintree.hostedFields.create({
client: clientInstance,
fields: {
number: {
container: '#card-number'
},
cardholderName: {
container: '#cardholder-name'
},
cvv: {
container: '#cvv',
},
expirationDate: {
container: '#expiration-date'
}
}
}, callback);
// in document head
<style>
.braintree-input-class {
color: black;
}
.braintree-valid-class {
color: green;
}
.braintree-invalid-class {
color: red;
}
</style>
// in a script tag
braintree.hostedFields.create({
client: clientInstance,
styles: {
'input': 'braintree-input-class',
'.invalid': 'braintree-invalid-class',
'.valid': {
// you can also use the object syntax alongside
// the class name syntax
color: green;
}
},
fields: {
number: {
container: '#card-number'
},
// etc...
}
}, callback);
braintree.hostedFields.create({
client: clientInstance,
styles: {
'input': {
// other styles
direction: 'rtl'
},
},
fields: {
number: {
container: '#card-number',
// Credit card formatting is not currently supported
// with RTL languages, so we need to turn it off for the number input
formatInput: false
},
cvv: {
container: '#cvv',
placeholder: '•••'
},
expirationDate: {
container: '#expiration-date',
type: 'month'
}
}
}, callback);
braintree.hostedFields.create({
client: clientInstance,
fields: {
// Only add the `cvv` option.
cvv: {
container: '#cvv',
placeholder: '•••'
}
}
}, callback);
var storedCreditCardInformation = {
// get this info from your server
// with a payment method lookup
month: '09',
year: '2017'
};
braintree.hostedFields.create({
client: clientInstance,
fields: {
expirationMonth: {
container: '#expiration-month',
prefill: storedCreditCardInformation.month
},
expirationYear: {
container: '#expiration-year',
prefill: storedCreditCardInformation.year
}
}
}, callback);
braintree.hostedFields.create({
client: clientInstance,
fields: {
number: {
container: '#card-number',
supportedCardBrands: {
visa: false, // prevents Visas from showing up as valid even when the Braintree control panel is configured to allow them
'diners-club': true // allow Diners Club cards to be valid (processed as Discover cards on the Braintree backend)
}
},
cvv: {
container: '#cvv',
placeholder: '•••'
},
expirationDate: {
container: '#expiration-date',
type: 'month'
}
},
}, callback);
(static) supportsInputFormatting() → {Boolean}
Returns false if input formatting will be automatically disabled due to browser incompatibility. Otherwise, returns true. For a list of unsupported browsers, go here.
- Source:
Example
var canFormat = braintree.hostedFields.supportsInputFormatting();
var fields = {
number: {
container: '#card-number'
},
cvv: {
container: '#cvv'
}
};
if (canFormat) {
fields.expirationDate = {
selection: '#expiration-date'
};
functionToCreateAndInsertExpirationDateDivToForm();
} else {
fields.expirationMonth = {
selection: '#expiration-month'
};
fields.expirationYear = {
selection: '#expiration-year'
};
functionToCreateAndInsertExpirationMonthAndYearDivsToForm();
}
braintree.hostedFields.create({
client: clientInstance,
styles: {
// Styles
},
fields: fields
}, callback);
Type Definitions
field :object
Fields used in fields options
Properties:
Name | Type | Attributes | Default | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
selector |
string |
Deprecated: Now an alias for |
|||||||||||||||||
container |
string | HTMLElement |
A DOM node or CSS selector to find the container where the hosted field will be inserted. |
|||||||||||||||||
placeholder |
string |
<optional> |
Will be used as the |
||||||||||||||||
type |
string |
<optional> |
Will be used as the |
||||||||||||||||
iframeTitle |
string |
<optional> |
The title used for the iframe containing the credit card input. By default, this will be |
||||||||||||||||
internalLabel |
string |
<optional> |
Each Hosted Field iframe has a hidden label that is used by screen readers to identify the input. The
|
||||||||||||||||
formatInput |
boolean |
<optional> |
true |
Enable or disable automatic formatting on this field. |
|||||||||||||||
maskInput |
object | boolean |
<optional> |
false |
Enable or disable input masking when input is not focused. If set to Properties
|
|||||||||||||||
select |
object | boolean |
<optional> |
If truthy, this field becomes a Properties
|
||||||||||||||||
maxCardLength |
number |
<optional> |
This option applies only to the number field. Allows a limit to the length of the card number, even if the card brand may support numbers of a greater length. If the value passed is greater than the max length for a card brand, the smaller number of the 2 values will be used. For example, is |
||||||||||||||||
maxlength |
number |
<optional> |
This option applies only to the CVV and postal code fields. Will be used as the |
||||||||||||||||
minlength |
number |
<optional> |
3 |
This option applies only to the cvv and postal code fields. Will be used as the |
|||||||||||||||
prefill |
string |
<optional> |
A value to prefill the field with. For example, when creating an update card form, you can prefill the expiration date fields with the old expiration date data. |
||||||||||||||||
rejectUnsupportedCards |
boolean |
<optional> |
false |
Deprecated since version 3.46.0, use |
|||||||||||||||
supportedCardBrands |
object |
<optional> |
Override card brands that are supported by the card form. Pass Valid card brand ids are:
|
- Source:
fieldOptions :object
An object that has field objects for each field. Used in create.
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
number |
field |
<optional> |
A field for card number. |
expirationDate |
field |
<optional> |
A field for expiration date in |
expirationMonth |
field |
<optional> |
A field for expiration month in |
expirationYear |
field |
<optional> |
A field for expiration year in |
cvv |
field |
<optional> |
A field for 3 or 4 digit card verification code (like CVV or CID). If you wish to create a CVV-only payment method nonce to verify a card already stored in your Vault, omit all other fields to only collect CVV. |
postalCode |
field |
<optional> |
A field for postal or region code. |
cardholderName |
field |
<optional> |
A field for the cardholder name on the customer's credit card. |
- Source:
styleOptions :object
An object that represents CSS that will be applied in each hosted field. This object looks similar to CSS. Typically, these styles involve fonts (such as font-family
or color
).
You may also pass the name of a class on your site that contains the styles you would like to apply. The style properties will be automatically pulled off the class and applied to the Hosted Fields inputs. Note: this is recommended for input
elements only. If using a select
for the expiration date, unexpected styling may occur.
These are the CSS properties that Hosted Fields supports. Any other CSS should be specified on your page and outside of any Braintree configuration. Trying to set unsupported properties will fail and put a warning in the console.
Supported CSS properties are:
appearance
box-shadow
color
direction
font-family
font-size-adjust
font-size
font-stretch
font-style
font-variant-alternates
font-variant-caps
font-variant-east-asian
font-variant-ligatures
font-variant-numeric
font-variant
font-weight
font
letter-spacing
line-height
opacity
outline
margin
margin-top
margin-right
margin-bottom
margin-left
padding
padding-top
padding-right
padding-bottom
padding-left
text-align
text-shadow
transition
-moz-appearance
-moz-box-shadow
-moz-osx-font-smoothing
-moz-tap-highlight-color
-moz-transition
-webkit-appearance
-webkit-box-shadow
-webkit-font-smoothing
-webkit-tap-highlight-color
-webkit-transition
- Source: