Step 3: Add your own Javascript file that gathers the required information and submits it to your backend
<scriptsrc="/js/checkout.js"></script>
//checkout.jsvar form;var cardelem;var paymentForm;var browserInfo;var token;document.addEventListener('DOMContentLoaded',function() {setupCardForm();});functionsetupCardForm() { cardelem =document.getElementById('card-element'); paymentForm =document.getElementById('paymentForm');var submit =document.getElementById('submitButton'); browserInfo =document.getElementById('browserInfo'); token =document.getElementById('token');//Set up and display the hosted payment field using the BreathePay JS Fileif(cardelem && submit) { form =newwindow.hostedFields.classes.Form(cardelem, {"autoSetup":true,"autoSubmit":true,"tokenise":".add-to-token","stylesheets":"#hostedfield-stylesheet","fields":{"any":{"nativeEvents":true },"cardDetails":{"selector":"#cardDetails","style":"font: 400 16px Helvetica, sans-serif;","placeholder":"0000 0000 0000 0000|00/00|000" } },"classes":{"invalid":"error"},"merchantID":'YOUR_MERCHANT_ID' });//Listed for the submit button click to gather informationsubmit.addEventListener('click', getCardDetails); }}functiongetCardDetails() {form.validate().then(function(valid) {//Use the BreathePay JS File to validate customer payment informationif(valid) {//Sends the customer payment information to the BreathePay API and returns a payment tokenform.getPaymentDetails().then(function(details) {if(details.success) {//Set the payment token for use in your backend token.value =details.paymentToken;//Get the users browser info and attaches that to the frontend formbrowserInfo.value =JSON.stringify(getBrowserInfo());//Submit the frontend formpaymentForm.submit(); } else {var error =details.defaultErrorMessage;//Could not get payment token from BreathePay API, display your error message } }); } else {//Display your error message } });}//Get the required browser information used to securely make paymentsfunctiongetBrowserInfo() {let browserInfo = {};var screen_width = (window &&window.screen ?window.screen.width :'0');var screen_height = (window &&window.screen ?window.screen.height :'0');var screen_depth = (window &&window.screen ?window.screen.colorDepth :'0');var identity = (window &&window.navigator ?window.navigator.userAgent :'');var language = (window &&window.navigator ? (window.navigator.language ?window.navigator.language :window.navigator.browserLanguage) :'');var timezone = (newDate()).getTimezoneOffset();var java = (window &&window.navigator ?navigator.javaEnabled() :false);browserInfo.deviceIdentity = identity;browserInfo.deviceTimeZone = timezone;browserInfo.deviceCapabilities ='javascript'+ (java ?',java':'');browserInfo.deviceAcceptLanguage = language;browserInfo.deviceScreenResolution = screen_width +'x'+ screen_height +'x'+ screen_depth;return browserInfo;}
Step 4: Add a custom style sheet for your payment fields
Add a CSS file and link to it in the HEAD section of your HTML page