Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrate Cloud Functions for Firebase with Braintree

I'm trying to see if it's possible to integrate Cloud Functions for Firebase with Braintree. I created a project for Cloud Functions according to the docs. In the project directory I ran: npm install braintree. I modified index.js for testing purposes to be the following:

const functions = require('firebase-functions');

var braintree = require("braintree");

var gateway = braintree.connect({
                            environment: 
braintree.Environment.Sandbox,
                            merchantId: "useYourMerchantId",
                            publicKey: "useYourPublicKey",
                            privateKey: "useYourPrivateKey"
                            });


// // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase-
functions
//
 exports.helloWorld = functions.https.onRequest((request, response) => {
  response.send("Hello from Firebase!");
//gateway.clientToken.generate({}, function (err, response) {
    //response.send(response.clientToken);
//});
 });

When I tried to deploy this test function I got the error

Error parsing triggers: Cannot find module 'braintree'

I'm new to Firebase, Cloud Functions, and node.js and would appreciate any input on how to import Braintree to Firebase Functions project.

like image 537
Elena Rubilova Avatar asked Dec 14 '22 19:12

Elena Rubilova


1 Answers

It looks like Cloud Functions for Firebase is not picking up the braintree module. Like most Node.js environments, Cloud Functions reads the dependencies from package.json. When you install a module with npm you can tell it to also write it to package.json by adding --save to the command line. So:

npm install braintree --save
like image 179
Frank van Puffelen Avatar answered Dec 21 '22 11:12

Frank van Puffelen