Dev*_*er 2 javascript node.js stripe-payments firebase google-cloud-functions
我正在颤振应用程序中使用条带支付。流程是我正在生成卡片令牌并稍后发送到火力基地云功能将获取卡片详细信息并使用条带 API 收取付款我遇到了问题npm install strip成功安装条带但是当我运行时firebase deploy它显示错误。这是我正在编写云函数。
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
//const firestore= admin.firestore();
//const setting ={timestampInSnapshots:true};
// firebase.setting(setting);
const stripe = require('stripe')(functions.config().stripe.testkey)
exports.addStripeSource =functions.firestore.document('cards/{userid}/Tokens/{tokenid}}')
.onCreate(async (tokenSnap, context)=> {
var customer;
const data=tokenSnap.aftter.data();
if(data == null){
return null;
}
const token =data.tokenId;
const snapshot =await firestore.collection('cards').doc(context.params.userId).get();
const customerId=snapshot.data().custId;
const customerEmail=snapshot.data().Email;
if(customerId == 'new')
{
customer= await stripe.customers.create({
email: customerEmail,
source: token,
});
firestore.collection('cards').doc(context.params.userId).update ({
custId: customer.id,
})
}
else{
customer= await stripe.customers.retrieve(customerId);
}
const customerSource= customer.sources.data[0];
return firestore.collection('cards').doc(context.params.userId).collection('sources').doc(customerSource.card.fingerprint).set(customerSource)
}
)
Run Code Online (Sandbox Code Playgroud)
package.json 文件
{
"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"
},
"engines": {
"node": "8"
},
"dependencies": {
"firebase-admin": "^8.6.0",
"firebase-functions": "^3.3.0"
},
"devDependencies": {
"firebase-functions-test": "^0.1.6"
},
"private": true
}
Run Code Online (Sandbox Code Playgroud)
我有同样的问题。发现我需要打开终端或命令提示符并 cd 到 firebase 的“functions”文件夹,然后npm install stripe在那里运行。一旦完成,它就起作用了。
看来您安装的是strip您应该安装以下内容:
npm install stripe --save
Run Code Online (Sandbox Code Playgroud)
https://www.npmjs.com/package/stripe
确保从函数目录而不是项目目录安装包。我在项目目录中意外安装了软件包,它在本地工作正常,但在部署时会产生错误。所以,
cd functions
npm install [your package]
Run Code Online (Sandbox Code Playgroud)
然后就可以正常工作了
| 归档时间: |
|
| 查看次数: |
4048 次 |
| 最近记录: |