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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With