What could be the reason for receiving the error "client.getVersion is not a function" while using Braintree (Braintree-Web)?

When attempting to render the hostedFields from Braintree, I encounter an issue. After creating a key and obtaining my token, I pass it to my function to create the hostedFields. However, I am faced with an error message stating

client.getVersion is not a function
. Despite confirming that the client token I passed is accurate and that the SDK versions align, the fields do not match. Can you identify any missing elements in the code snippet provided below?

import { client, hostedFields } from 'braintree-web';
import styles from '../../styles/Booking.module.css';

export default function PaymentForm() {

    const createClient = async () => {
        try {
            const res = await client.create({
                authorization: '<MY_SANDBOX_KEY>'
             });
             const clientToken = res._configuration.authorization;
             clientDidCreate(clientToken)
        } catch (err) {
            console.error(err);
        }

    }

    const clientDidCreate = (client) => {
       console.log(client);
        hostedFields.create({
            client: client,
            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'
                }
            }
        }) 

        console.log(res);
    }


    useEffect(() => {   
     createClient()
    }, []);
  
    return (
            <form>
                <label htmlFor="card-number">Card Number</label>
                <div id="card-number"></div>
                <label htmlFor="cvv">CVV</label>
                <div id="cvv"></div>
                <label htmlFor="expiration-date">Expiration Date</label>
                <div id="expiration-date"></div>
                <p>By submitting this order, I agree to the <a href="#">Treatment Program Terms</a> and <a href="#"> Privacy Notice.</a></p>
                <button  type="button">Submit </button>
            </form>
       
    )
}

Answer №1

When using hostedFields.create, make sure to use the authorization option instead of the client.

hostedFields.create({
  authorization: client,
  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'
    }
  }
}) 

console.log(res);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Seamless integration of NextJS with Woocommerce backend

I am currently in the process of integrating NextJS with a backend WooCommerce using GraphQL. One thing that I have been pondering is how to reconfigure the setup. Currently, Wordpress/WooCommerce is set up as follows: mywebwoo.com - default WordPress sto ...

Leveraging the output of the useSelector() hook within a component

Currently, I am utilizing react-redux for state management and axios to handle API requests. Here is my initial state setup: const defaultState = { isLoading: true, isAuthenticated: false, authUser: {} } After a successful login API call, bot ...

Utilize React to Effectively Control Multiple Audio Files on a Single Page, Ensuring Only One Plays at a Time with Function

I am currently working on a new React app that includes multiple music cards on the same page. I am looking to modify the state of the previous card before updating the state of the new card. Essentially, I aim to pause the audio playing in the previous ca ...

Error in Next.js: ReferenceError: document is not defined

Having trouble setting up a payment form for users to make payments, encountering the error message below: document is not defined Currently working with Next.js. Here is the code snippet I'm using: import React from "react"; import {Elem ...

ESLint is cautioning developers that React Query mutations should be be added to the dependency array

When using the react-query library, I encountered a warning about the ESLint useEffect dependency. Here is an example of my code: const postProductMutation = useMutation(...); useEffect(() => { postProductMutation.mutateAsync() }, []) The issue is ...

How can you trigger useEffect using a context variable as a dependency in React?

Struggling to get a useEffect hook to trigger when its dependency is a useContext variable. The Context contains an "update" variable that changes, but the effect doesn't fire as expected. import { useEffect, useState, useContext } from "react" import ...

Issues with sending emails through Nodemailer in a Next.js project using Typescript

I'm currently working on a personal project using Nodemailer along with Next.js and Typescript. This is my first time incorporating Nodemailer into my project, and I've encountered some issues while trying to make it work. I've been followin ...

No matter how many times I enter my environment variables as my password, the system just won't accept

When I run my code locally, everything works fine. However, I'm trying to store my password in the .envlocal file but it's not working. Here is the working code: export default function (req, res) { let nodemailer = require('nodemailer ...

Express/React: Using Relative Paths for Static Files

Currently, my react client is running on localhost:3000 while my express server is running on localhost:4000. In the server, there is a static folder containing images. I am facing an issue where I need to store the image path in a MySQL database and use ...

Is it necessary for the React generic type prop to be an extension of another type

I have recently started using TypeScript and I am facing a confusion regarding passing generic types into my higher-order component (HOC). My objective is to pass the component props as a generic type in order to have the Component with those specific type ...

Troubleshooting SCSS Issues in NextJS

Can anyone help me with debugging SCSS in NEXT.JS? I've been trying to figure it out but haven't had any luck. When I use @debug on a SCSS module, nothing shows up in the console. Do I need to configure something in the next.config.js file or is ...

During the rendering process, the array mysteriously disappears

Currently, I have a working MYProfile.js file from which I removed the imports and styles section for simplicity. class MyProfile extends Component { constructor({match}) { console.log("constructor"); super() this.state = { user: &apos ...

Learn to save Canvas graphics as an image file with the powerful combination of fabric.js and React

I am currently utilizing fabric.js in a React application. I encountered an issue while attempting to export the entire canvas as an image, outlined below: The canvas resets after clicking the export button. When zoomed or panned, I am unable to export co ...

Modify the color of the select element when it is in an open state

If you're new to Material UI, I have a select element that I would like to change the color of. When 'None' is selected, I want the background color of the input field above it to match the 'None' section. Then, when the dropdown m ...

Emphasize a specific portion of the text

While developing a project similar to Google Search using React.js and GoogleAPI, an issue arose. For instance, when searching "tea" on Google, the results display "Searches related to tea" at the bottom. The term "tea" appears in bold. How can this be imp ...

Embed a Material-ui icon within a circular progress indicator

I am looking to incorporate a circular progress indicator from Material-UI into the header of my app. However, I am struggling to seamlessly integrate a download icon from Material Icons so that the progress bar can move around the icon. Here is my current ...

Sending data elements to ReactJS Material UI modal

As a newcomer to react, the store.js file contains a modal that includes the farmerreview component to load when the modal is opened. The goal is to pass the uid prop to the farmerreview component. The store.js file houses the modal code. import React, ...

Animating the exit transition in NextJS 14 with Framer Motion

I am currently working on implementing page transition animations for a Next.js 14 application using Framer Motion. I have created PageTransitionLayout.tsx with the following code: 'use client'; import { motion, AnimatePresence } from "fram ...

Looking for a more efficient approach to writing React styles for color?

Desire I am interested in customizing colors within Material UI components. Moreover, I aim to develop a React Component that allows for dynamic color switching through Props. Challenge The current approach using withStyles results in redundant and lengt ...

transferring user input to the server side

I've created a form in React using Material UI, and I need to send the form data to the backend. Currently, all fields are displaying the values except for the dateAndTime field, which is not connected to the rest of the fields. How can I ensure that ...