Firebase 集成FireStore/Stripe/iOS/Cloud功能

Firebase 集成FireStore/Stripe/iOS/Cloud功能,firebase,stripe-payments,google-cloud-firestore,google-cloud-functions,stripe.js,Firebase,Stripe Payments,Google Cloud Firestore,Google Cloud Functions,Stripe.js,我是所有提到的技术的新手。所以,如果这个问题不在这里,我提前道歉 因此,我正在尝试编写firestore等效于firebase提供的示例stripe firebase实时数据库云函数集成。它位于这里: 我成功地转换了exports.createStripeCustomer函数。但是我在addPaymentSource上遇到了麻烦 这就是我到目前为止所做的: exports.addPaymentSource = functions.firestore.document('Users/{user

我是所有提到的技术的新手。所以,如果这个问题不在这里,我提前道歉

因此,我正在尝试编写firestore等效于firebase提供的示例stripe firebase实时数据库云函数集成。它位于这里:

我成功地转换了exports.createStripeCustomer函数。但是我在addPaymentSource上遇到了麻烦

这就是我到目前为止所做的:

  exports.addPaymentSource = functions.firestore.document('Users/{userId}/paymentSources/{paymentID}').onWrite((change, context) => {
  let newPaymentSource = change.after.data();
  let token = newPaymentSource.token;

  return functions.firestore.document(`Users/${context.params.userId}`).get('customer_data')
      .then((snapshot) => {
        return snapshot.val();
      }).then((customer) => {
        return stripe.customers.createSource(customer, {newPaymentSource});
      }).then((response) => {
        return change.after.ref.parent.set(response);
      }, (error) => {
        return change.after.ref.parent.child('error').set(userFacingMessage(error));
      }).then(() => {
        return reportError(error, {user: context.params.userId});
      });
 });
部署成功,但函数失败,出现以下错误

TypeError:functions.firestore.document(…).get不是函数 在exports.addPaymentSource.functions.firestore.document.onWrite(/user\u code/index.js:73:77) 反对。(/user_code/node_modules/firebase functions/lib/cloud functions.js:112:27) 在下一个(本地) at/user\u code/node\u modules/firebase functions/lib/cloud functions.js:28:71 at_uuwaiter(/user_code/node_modules/firebase functions/lib/cloud functions.js:24:12) 在cloudFunction(/user\u code/node\u modules/firebase functions/lib/cloud functions.js:82:36) at/var/tmp/worker/worker.js:728:24 在进程中。_tickDomainCallback(internal/process/next_tick.js:135:7)

显然,“get”似乎不是一个函数。我从下面的参考文档中得到了这个函数


我好像错过了什么。这件事我已经坚持了好几天了。因此,任何帮助都将不胜感激。提前谢谢

使用
firebase admin

const admin = require('firebase-admin');
exports.addPaymentSource = functions.firestore.document('Users/{userId}/paymentSources/{paymentID}').onWrite((change, context) => {
  let newPaymentSource = change.after.data();
  let token = newPaymentSource.token;

  return admin.firestore().doc(`Users/${context.params.userId}`).get('customer_data')
      // what you have to do
      });
 });

功能包用于触发功能。您可以使用以下方法:

  • 一次创建
  • 更新
  • 删除
(更多信息请点击此处:)

要使用get()方法,您需要使用firebase管理包-然后可以从admin.firestore()访问firestore


(firebase管理员:)

不太熟悉firestore,但您看过这些文档了吗:似乎您可以使用类似于
firebase.database().ref(`Users/${context.params.userId}')
的方法获取数据库中某个位置的引用,然后使用
.on()
读取匹配的资源。感谢您的回复。不幸的是,我没有使用实时数据库:(我正试图找到相当于该函数调用的firestore。仅供参考:您可以直接在客户端(web sdk)上集成w Stripe)。根本不需要管理员SDK…只是确保您不会使事情过于复杂…Stripe会在您的
/pay
页面中插入一个iFrame,并将令牌交给您,以便与新订单一起存储。它符合PCI标准。