Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/404.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript firebase stripe示例云函数的自适应返回未指定错误_Javascript_Node.js_Firebase_Google Cloud Functions_Stripe Payments - Fatal编程技术网

Javascript firebase stripe示例云函数的自适应返回未指定错误

Javascript firebase stripe示例云函数的自适应返回未指定错误,javascript,node.js,firebase,google-cloud-functions,stripe-payments,Javascript,Node.js,Firebase,Google Cloud Functions,Stripe Payments,我正在通过以下示例实现firebase stripe cloud函数:在我的Vue webapp中进行了一些修改(主要是在cloud函数上而不是在前端运行stripe.confirmCardSetup(),因为我在尝试将stripe正确导入函数文件之外时遇到了很多麻烦) 但是,代码原样会产生一个没有类型规范的错误,这就是为什么它会将字段“error”设置为“发生错误,开发人员已收到警报”,如函数userFacingMessage()中所定义 是什么导致了这些错误? 顺便说一句,我仍然在测试模式下

我正在通过以下示例实现firebase stripe cloud函数:在我的Vue webapp中进行了一些修改(主要是在cloud函数上而不是在前端运行stripe.confirmCardSetup(),因为我在尝试将stripe正确导入函数文件之外时遇到了很多麻烦)

但是,代码原样会产生一个没有类型规范的错误,这就是为什么它会将字段“error”设置为“发生错误,开发人员已收到警报”,如函数userFacingMessage()中所定义

是什么导致了这些错误? 顺便说一句,我仍然在测试模式下运行stripe并使用测试卡进行测试,但是,我不认为这会导致错误

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();

// const { Logging } = require('@google-cloud/logging');
// const logging = new Logging({
//   projectId: "",
// });

const stripe = require('stripe')(functions.config().stripe.secret, {
    apiVersion: '2020-03-02',
  });

exports.createStripeCustomerSA = functions
.region('southamerica-east1')
.auth.user().onCreate(async (user) => {
  const customer = await stripe.customers.create({ email: user.email });
  const intent = await stripe.setupIntents.create({
      customer: customer.id,
  });
  await admin.firestore().collection('users').doc(user.email).set({
      customer_id: customer.id,
      setup_secret: intent.client_secret
  });
  return;
});

exports.createStripePaymentSA = functions
.region('southamerica-east1')  
  .firestore
  .document('users/{userId}/payments/{pushId}')
  .onCreate(async (snap, context) => {
    const { amount, payment_method } = snap.data();
    try {
      // Look up the Stripe customer id.
      const customer = (await snap.ref.parent.parent.get()).data().customer_id;
      const setup_secret = (await snap.ref.parent.parent.get()).data().setup_secret;

      const { setupIntent, error } = await stripe.confirmCardSetup(
        await setup_secret,
          {
            payment_method
          }
      );

      if (error) {
        await snap.ref.set({"confirmCardSetupError": 1});
        return;
      }

      // Create a charge using the pushId as the idempotency key
      // to protect against double charges.
      const idempotencyKey = context.params.pushId;
      const payment = await stripe.paymentIntents.create(
        {
          amount: amount,
          currency: 'BRL',
          customer: customer,
          payment_method: setupIntent.payment_method,
          off_session: false,
          confirm: true,
          confirmation_method: 'manual',
        },
        { idempotencyKey }
      );
      // If the result is successful, write it back to the database.
      await snap.ref.set(payment);

      //CREAT THE COLLECTION OF PAID ITEMS
      await snap.ref.parent.parent.collection("wantedCourses").map(function (course) {
        return course.set("paid", 1);
      })

    } catch (error) {
      // We want to capture errors and render them in a user-friendly way, while
      // still logging an exception with StackDriver
      
      await snap.ref.set({ error: userFacingMessage(error) }, { merge: true });
      // await reportError(error, { user: context.params.userId });
    }
});

exports.confirmStripePaymentSA = functions
.region('southamerica-east1')
  .firestore
  .document('stripe_customers/{userId}/payments/{pushId}')
  .onUpdate(async (change, context) => {
    if (change.after.data().status === 'requires_confirmation') {
      const payment = await stripe.paymentIntents.confirm(
        change.after.data().id
      );
      change.after.ref.set(payment);
    }
});

function userFacingMessage(error) {
    return error.type
      ? error.message
      : 'An error occurred, developers have been alerted';
  }

请编辑问题以显示特定的错误消息文本以及生成该问题的代码行。