Constructor
new HostedFields(configuration)
Do not use this constructor directly. Use braintree.hosted-fields.create instead.
Parameters:
| Name | Type | Description |
|---|---|---|
configuration |
object | Hosted Fields create options |
Methods
on(event, handler) → {void}
Subscribes a handler function to a named event, such as fieldEvent
Parameters:
| Name | Type | Description |
|---|---|---|
event |
string | The name of the event to subscribe to |
handler |
function | A callback to handle the event |
Returns:
- Type
- void
Example
Listening to a fieldEvent
var hostedFields = require('braintree/hosted-fields');
hostedFields.create({ ... }, function (err, instance) {
instance.on('fieldEvent', function (event) {
if (event.card != null) {
console.log(event.card.type);
} else {
console.log('Type of card not yet known');
}
}
});
teardown(done) → {void}
Cleanly tear down anything set up by create
Parameters:
| Name | Type | Description |
|---|---|---|
done |
errorCallback | An errback called when teardown has completed |
Returns:
- Type
- void
Example
hostedFieldsInstance.teardown(function (err) {
if (err) {
console.error('Could not tear down hosted fields!');
} else {
console.info('Hosted Fields has been torn down!');
}
});
tokenize(callback) → {void}
Attempts to tokenize fields, returning a nonce payload
Parameters:
| Name | Type | Description |
|---|---|---|
callback |
errback | The second argument, |
Returns:
- Type
- void
Example
hostedFieldsInstance.tokenize(function (err, payload) {
if (err) {
console.error(err);
} else {
console.log('Got nonce:', payload.nonce);
}
});
Type Definitions
tokenizePayload
Type:
- object
Properties:
| Name | Type | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
nonce |
string | The payment method nonce |
|||||||||
type |
string | Always |
|||||||||
details |
object | Additional account details Properties
|
|||||||||
description |
string | A human-readable description |
Events
fieldEvent
This event is emitted when activity within one or more inputs has resulted in a change of state, such as a field attaining focus, an input becoming empty, or the user entering enough information for us to guess the type of card.
Type:
- object
Properties:
| Name | Type | Attributes | Description | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
type |
string |
|
|||||||||||||||||||||||||
isEmpty |
boolean | Whether or not the user has entered a value in the input |
|||||||||||||||||||||||||
isFocused |
boolean | Whether or not the input is currently focused |
|||||||||||||||||||||||||
isPotentiallyValid |
boolean | A determination based on the future validity of the input value.
This is helpful when a user is entering a card number and types |
|||||||||||||||||||||||||
isValid |
boolean | Whether or not the value of the associated input is fully qualified for submission |
|||||||||||||||||||||||||
target |
object |
Properties
|
|||||||||||||||||||||||||
card |
object |
<nullable> |
If not enough information is available, or if there is invalid data, this value will be Properties
|
Example
Listening to a fieldEvent
var hostedFields = require('braintree/hosted-fields');
hostedFields.create({ ... }, function (err, instance) {
instance.on('fieldEvent', function (event) {
console.log('fieldEvent', event.type', triggered on "', event.target.fieldKey, '" field');
if (event.card != null) {
console.log(event.card.type);
} else {
console.log('Type of card not yet known');
}
}
});