0

I am using a payment merchant in my React app which requires that I import their v1.js script and then use it to create an object.

First I tried to download the script and import it via import ./v1.js, but that left me with plenty of errors:

enter image description here

I've then imported the script in my index.html file instead via <script type="text/javascript" src="https://tpgw.trustpay.eu/js/v1.js"></script>.

This didn't incur any errors, however, the next step requires me to create an object referenced in the script using var trustPayApi = new TrustPayApi({secrets});.

When I run this code in my React app (substituting secrets for the correct value), I get an error saying

'TrustPayApi' is not defined

How can I correctly implement the script and use the TrustPayApi object defined within it?

8
  • The messages in the image are not code errors, but linting errors. They can be ignored for running the code Commented May 3, 2022 at 8:10
  • Apologies, I'm not familiar with those. How can I get around them? Commented May 3, 2022 at 8:11
  • Does this address your issue: stackoverflow.com/a/50802718/3977134 ? Commented May 3, 2022 at 8:12
  • 1
    It does indeed. I had to use the window. prefix when creating the trustPayApi object. Thank you. Commented May 3, 2022 at 8:27
  • 1
    @Sam in case you want to use the downloaded file rather than including a script tag in your index.html, you can exclude v1.js from linting. In your eslint config you can place a ignorePatterns property (for reference: eslint.org/docs/user-guide/configuring/ignoring-code) Commented May 3, 2022 at 9:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.