Define dwolla in react for dwolla.js

I am using dwolla.js in attempts to add account with IAV. When following the boilerplate code, I am getting the error “dwolla is not defined”. See my code below. Using react, how do I define dwolla on the front end? I have included the script tag in my header, but am not sure how to define the variable.

I tried const dwolla = require(‘dwolla-v2’); but get the error “dwolla.configure is not a function”.

Thanks.

     const iavSubmit = async (customerURL) => {
        let response = await Util.apiPost('/api/dwolla/fundingSourcesToken', { URL: customerURL });
        let iavToken = response.data;
        **dwolla**.configure('sandbox');
        **dwolla**.Client().
            dwolla.iav.start(iavToken, {
                container: 'iavContainer',
                stylesheets: [
                    'https://fonts.googleapis.com/css?family=Lato&subset=latin,latin-ext'
                ],
                microDeposits: false,
                fallbackToMicroDeposits: false
            }, function (err, res) {
                console.log('Error: ' + JSON.stringify(err) + ' -- Response: ' + JSON.stringify(res));
            });
    }

Hey Noah,

It should be defined by including the <script> tag in your <head> section as you mentioned. Is your application’s <script> being included after the Dwolla.js one? Also, what is returned when you type dwolla into your browser’s console?

Another thing to note is that dwolla-v2 (our Node.js client) is separate from Dwolla.js (at the moment we do not provide an npm package for Dwolla.js).

Hi Stephen,

I figured it out, I’ll chalk this one up to lack of sleep. In React, the variable is not automatically defined by including the CDN in the head. Each component needs to define the variable when it mounts.

I solved this by doing the following:

Const dwolla = window.dwolla;

Hopefully this helps anyone else using react.js and dwolla.js

2 Likes