HTML custom element where you wish to display. Ensure to import the script somewhere on your page.
Consume the payload
event, which gets emitted when a valid payment method is chosen and completed by the user.
<braintree-ui token="{{ CLIENT_TOKEN }}" data-amount="0.01"></braintree-ui>
<script src="https://uicomponent.live.pci.cavu-tech.com/payments.js"></script>
<script>
el = document.querySelector('braintree-ui')
function makePayment (nonce) {
fetch('https://example.com/checkout')
.then(response => response.json())
.then(result => {
// Pass the result through to the component.
// Expected format:
// {
// success: Boolean,
// verification: {
// status: String("processor_declined|processor_declined"),
// gatewayRejectionReason: String
// }
// }
el.dispatchEvent(new CustomEvent('complete', { detail: result }))
if (result.success) {
alert('Payment successful')
} else {
el.dataset.error = 'There was an error'
}
})
}
el.addEventListener('payload', function(event) {
console.log(event.detail)
// { nonce: "tokencc_bh_kz4r7k_7c2fsp_4qyf6q_wb5vmy_6y8", ... }
makePayment(event.detail.nonce)
})
</script>
To view debugging in DevTools Console, enable the debug key on LocalStorage.
localStorage.debug = "braintree-ui:*"
Card Number | Card Type | Response |
---|---|---|
4111111111111111 | VISA | Valid |
4000111111111115 | VISA | Processor Declined |
4000000000001000 (Jan, 2 years from now) | VISA | 3D Secure no challenge |
4000000000001091 (Jan, 2 years from now) | VISA | 3D Secure challenge success |
4000000000001109 (Jan, 2 years from now) | VISA | 3D Secure challenge failure |
More information, see Braintree Card Testing
this example is using a sandbox account
Properties and events that can be used to interface with this Web Component.
Property | Attribute | Type | Default | Description |
---|---|---|---|---|
amount | data-amount | string | "" | Defines transaction amount as attribute to pass to braintree. Required for 3D Secure, and Google Payment |
buttonRemoved | data-button-removed | boolean | false | Button Removed Enable the button responsible for tokenise, enabled by default can be set to false to allow for custom tokenise integration. |
buttonText | data-button-text | string | "Pay Now" | Button Text The label for the button text when not in spinner state Default option: - Pay Now |
config | data-config | { token: null; monitorApplicationId: null; monitorClientToken: null; environment: null; } | {"token":null,"monitorApplicationId":null,"monitorClientToken":null,"environment":null} | Object that contains the Braintree Client tokenization key token that authorizes this client to tokenize payment information.As an integrator of this component, This object is returned from the paymentGateway/client-config payments api endpoint when using the corresponding merchantId. |
configurable | boolean | |||
currencyCode | data-currency-code | string | "GBP" | ISO4217 Currency code the given amount is defined using. Required for Google Payment |
defaultPaymentMethod | data-default-payment-method | string | "" | |
enabledPaymentMethods | data-enabled-payment-methods | string[] | Payment methods to display Defaults options: ["hosted-fields", "paypal"] Example: <braintree-ui data-enabled-payment-methods="[\"hosted-fields\"]"></braintree-ui> N.B. The given property must be an valid JSON array string. Double quotes are mandatory in JSON. Available Options: - hosted-fields - paypal - google-payment - apple-pay - When enabled will only show on supported devices/browsers. macOS with TouchID (or via iOS device), iOS with TouchID/FaceID.Note: Apple Pay requires Domain Registration | |
enumerable | boolean | |||
errorMessage | data-error-message | string | "" | Display a Braintree related error message, ideal for server side errors when attempting transactions. |
googleMerchantId | data-google-merchant-id | string | "" | Google Pay Merchant ID Required for Google Pay production mode |
isLoggedIn | data-is-logged-in | boolean | false | Boolean value to let the component know if the user is currently logged in, defaults to false. |
isThreeDSecureChallengeRequestedEnabled | data-enable-three-d-secure-challenge-requested | any | Toggle to force 3D Secure authentication. * Note: if you don't need to force additional 3DS authentication or you are not sure, don't set it. In that case it would not force 3DS authentication. If it will be set to "true/false" will be included in the 3DS verification process | |
isThreeDSecureEnabled | data-enable-three-d-secure | boolean | false | Toggle to Activate or disable 3D Secure. Allows shift of fraud liability to card issuer. Note: You'll need to use a Client Token instead of a Tokenization Key for token |
lang | data-lang | string | "en-US" | The language to use for the display text. This will determine which translated text to display. Default is 'en-US'. |
prefillCardNumber | data-prefill-card-number | string | "" | Prefill Hosted Field Card Number Primarily used in Automation tests. |
prefillCvv | data-prefill-cvv | string | "" | Prefill Hosted Field CVV Primarily used in Automation tests. |
prefillExpiryDate | data-prefill-expiry-date | string | "" | Prefill Hosted Field Expiry Date Primarily used in Automation tests. |
themeLabelMode | data-theme-label-mode | string | "outside" | Label display mode Available options: - outside - edge |
token | token | string | "" | A Braintree Client tokenization key that authorizes this client to tokenize payment information. This tokenization key can be shipped with application without the need to generate a new key for each session. Learn more about tokenization keys Note: If you're using 3D Secure you'll need to generate a JWT Signed Client Token, learn more about client tokens. |
Event | Description |
---|---|
complete | Dispatch this event to the component when you've successfully completed a transaction or when the transaction has failed from your server. |
error | Handle the human readable display of a Server Side error, and allow the user to change payment method. List of all Braintree errors. |
payload | Dispatched when the payment is payment method has been provided |
tokenize | |
userError | Handle the human readable display of a 3d Secure status codes, and allow the user to change payment method. List of all 3d Secure status codes. |
Property | Description |
---|---|
--braintree-ui-border-radius | Border radius of Payment Methods (default: 0.4rem) |
--braintree-ui-color-primary | Primary color for Titles, and Labels (default: #032f61) |
--braintree-ui-gap-spacing | Controls the gap between block elements (default: 1rem) |