mercredi 8 septembre 2021

unable to import Braintree Javascript SDK in Ember "ember-cli": "^3.25.2",

I have installed the braintree package via npm, outlined here,

using

const braintree = require("braintree");

results in

loader.js:247 Uncaught Error: Could not find module braintree imported from (require)

attempting a manual install suggested here

app.import('node_modules/braintree/lib/braintree/braintree_gateway.js');

with

const braintree = require("braintree");

results

loader.js:247 Uncaught Error: Could not find module braintree imported from (require)

this

app.import('node_modules/braintree/lib/braintree.js');

results

card-payment.js:343 Uncaught TypeError: braintree.BraintreeGateway is not a constructor

grep -r BraintreeGateway node_modules/braintree/
node_modules/braintree/lib/braintree/braintree_gateway.js:class BraintreeGateway {
node_modules/braintree/lib/braintree/braintree_gateway.js:module.exports = {BraintreeGateway: BraintreeGateway};
node_modules/braintree/lib/braintree.js:let BraintreeGateway = require('./braintree/braintree_gateway').BraintreeGateway;
node_modules/braintree/lib/braintree.js:  BraintreeGateway: BraintreeGateway,
node_modules/braintree/CHANGELOG.md:* Add `GraphQLClient` to `BraintreeGateway` class
node_modules/braintree/README.md:var gateway = new braintree.BraintreeGateway({
node_modules/braintree/README.md:var gateway = new braintree.BraintreeGateway({

a grep of the node modules appears to show the last manual import as in the ballpark of correct.

component-class

  @action
  saveNonce() {
    // const braintree = require("braintree");

    var gateway = new braintree.BraintreeGateway({
      environment: String(ENV.BRAINTREE_ENVIRONMENT),
      merchantId: String(ENV.BRAINTREE_MERCHANT_ID),
      publicKey: String(ENV.BRAINTREE_PUBLIC_KEY),
      privateKey: String(ENV.BRAINTREE_PRIVATE_KEY)
    });

    let clientNonce = document.getElementById('save-nonce').value;

    gateway.transaction.sale({
      amount: String(this.amount/100),
      paymentMethodNonce: clientNonce,
      // deviceData: deviceDataFromTheClient,
      options: {
        submitForSettlement: true
      }
    }, (err, result) => {
    });

  }

package.json

...
"ember-cli": "^3.25.2",
"braintree": "^3.7.0",
...



Aucun commentaire:

Enregistrer un commentaire