I tried deploying this function to Firebase
Also, Im using Cloud Firestore as the database
const stripe = require("stripe")("STRIPE_API_KEY");
exports.stripeCharge = functions.firestore
.document("/payments/{userId}/{paymentId}")
.onWrite(event => {
const payment = event.data.val();
const userId = event.params.userId;
const paymentId = event.params.paymentId;
// checks if payment exists or if it has already been charged
if (!payment || payment.charge) return;
return admin
.firestore()
.doc(`/users/${userId}`)
.once("value")
.then(snapshot => {
return snapshot.val();
})
.then(customer => {
const amount = payment.amount;
const idempotency_key = paymentId; // prevent duplicate charges
const source = payment.token.id;
const currency = "eur";
const charge = { amount, currency, source };
return stripe.charges.create(charge, { idempotency_key });
})
.then(charge => {
admin
.firestore()
.doc(`/payments/${userId}/${paymentId}/charge`)
.set(charge),
{ merge: true };
});
});
I followed this tutorial
When I run firebase deploy --only functions
This appears in the terminal
! functions: failed to create function stripeCharge
HTTP Error: 400, The request has errors
Functions deploy had errors with the following functions:
stripeCharge
To try redeploying those functions, run:
firebase deploy --only functions:stripeCharge
To continue deploying other features (such as database), run:
firebase deploy --except functions
Error: Functions did not deploy properly.
And I get this error in the Firebase log Firebase Log error
Anybody have a clue with what could be wrong?
package.jsonfile and confirm that this syntax is in line with your version. Can you add the content of thispackage.jsonfile to your question. In any case it would be a good idea to migrate to a recent CF version. - Renaud Tarnec{ "name": "functions", "description": "Cloud Functions for Firebase", "scripts": { "serve": "firebase serve --only functions", "shell": "firebase functions:shell", "start": "npm run shell", "deploy": "firebase deploy --only functions", "logs": "firebase functions:log" }, "dependencies": { "@sendgrid/mail": "^6.3.1", "cors": "^2.8.5", "firebase-admin": "~7.0.0", "firebase-functions": "^2.2.0", "stripe": "^6.25.1" }, "private": true }- Zafiera Davids