Skip to content

Instantly share code, notes, and snippets.

@SeraphimSerapis
Last active August 29, 2015 14:21
Show Gist options
  • Save SeraphimSerapis/b2e895e8af319b6433c4 to your computer and use it in GitHub Desktop.
Save SeraphimSerapis/b2e895e8af319b6433c4 to your computer and use it in GitHub Desktop.
Hosted Fields combined
var HostedFields = React.createClass({
componentDidMount: function() {
this.initBraintree();
},
initBraintree() {
braintree.setup(clientToken, 'custom', {
id: 'hosted',
hostedFields: {
onFieldEvent: function (event) {
if (event.type === 'fieldStateChange') {
var type = '';
if (event.card) {
type = event.card.type.replace('-', '');
}
$('#card-type').text(type);
}
},
number: {
selector: '#card-number'
},
cvv: {
selector: '#cvv'
},
expirationDate: {
selector: '#expiration-date'
}
}
});
},
render: function() {
return (
<form action="/pay" id="hosted">
<FieldCardNumber />
<FieldCVV />
<FieldExpirationDate />
<FieldCardType />
<FieldSubmit />
</form>
);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment