繁体   English   中英

Stripe Connect 转账:资金不足

[英]Stripe Connect transfer: Insufficient funds

我正在尝试将 Stripe 的 Connect 实施到我的应用程序中。 我已经完成了数小时的研究和反复试验方法调试,现在我处于没有技术错误但错误说的情况:

Stripe 帐户中的资金不足。 在测试模式下,您可以通过创建以 4000 0000 0000 0077 作为卡号的费用来向可用余额中添加资金(绕过您的待处理余额)。 您可以使用 /v1/balance 端点查看您的 Stripe 余额(有关更多详细信息,请参阅 stripe.com/docs/api#balance)。

Stripe Dashboar 中的 paymentIntent 显示PaymentIntent status: requires_confirmation

我的错误似乎很奇怪,因为我正在测试的卡正是他们建议我使用的卡。 请注意,我也尝试过使用其他卡。

我使用 Google Cloud Functions 作为我的 Stipe API 的后端。

这是创建accountcustomer的函数。 我正在创建它们只是为了确保一切正常。

// When a user is created in firebase auth, register them with Stripe
exports.createStripeUser = functions.auth.user().onCreate(async (user) => {
  const account = await stripe.accounts.create({type: 'custom', business_type: 'individual', individual: {email: user.email}, requested_capabilities: ['card_payments', 'transfers'], email: user.email});
  const customer = await stripe.customers.create({email: user.email});
  return admin.firestore().collection('stripe_customers').doc(user.uid).set({account_id: account.id, customer_id: customer.id});
});

现在我正在添加卡信息:

// Add a payment source (card) for a user by writing a stripe payment source token to Cloud Firestore
exports.addPaymentSource = functions.firestore.document('/stripe_customers/{userId}/tokens/{pushId}').onCreate(async (snap, context) => {
  const source = snap.data();
  const token = source.token;
  if (source === null){
    return null;
  }

  try {
    const snapshot = await admin.firestore().collection('stripe_customers').doc(context.params.userId).get();
    const customer =  snapshot.data().customer_id;
    const response = await stripe.customers.createSource(customer, {source: token});
    return admin.firestore().collection('stripe_customers').doc(context.params.userId).collection("sources").doc(response.fingerprint).set(response, {merge: true});
  } catch (error) {
    await snap.ref.set({'error':userFacingMessage(error)},{merge:true});
    return reportError(error, {user: context.params.userId});
  }
});

这就是我创建paymentIntent

// Create Stripe paymentIntent whenever an amount is created in Cloud Firestore
exports.createStripePaymentIntent = functions.firestore.document('stripe_customers/{userId}/charges/{id}').onCreate(async (snap, context) => {
      const val = snap.data();
      try {
        // Look up the Stripe customer id written in createStripeUser
        const snapshot = await admin.firestore().collection(`stripe_customers`).doc(context.params.userId).get()
        const snapval = snapshot.data();
        const customer = snapval.customer_id
        const amount = val.amount;
        const charge = {amount, currency, customer, transfer_group: val.transfer_group, payment_method: val.payment_method};
        if (val.source !== null) {
          charge.source = val.source;
        }
        const response = await stripe.paymentIntents.create(charge);
        // If the result is successful, write it back to the database
        return snap.ref.set(response, { merge: true });
      } catch(error) {
        // We want to capture errors and render them in a user-friendly way, while
        // still logging an exception with StackDriver
        console.log(error);
        await snap.ref.set({error: userFacingMessage(error)}, { merge: true });
        return reportError(error, {user: context.params.userId});
      }
    });

因为现在一切似乎都按预期工作,现在进入了有趣的部分,转移。 由于上述错误,我无法做到。 这是我创建充电的方式:

exports.createStripeTransfer = functions.firestore.document('stripe_customers/{userId}/transfers/{id}').onCreate(async (snap, context) => {
  const val = snap.data();
  try {
    // Look up the Stripe account id written in createStripeUser
    const snapshot = await admin.firestore().collection(`stripe_customers`).doc(context.params.userId).get()
    const snapval = snapshot.data();

    const destinationAccount = val.destination
    const amount = val.amount;
    const charge = {amount, currency, destination: destinationAccount, transfer_group: val.transfer_group};
    if (val.source !== null) {
      charge.source = val.source;
    }
    const response = await stripe.transfers.create(charge);
    stripe.paymentIntents.confirm(response.id, {payment_method: response.payment_method})
    // If the result is successful, write it back to the database
    return snap.ref.set(response, { merge: true });
  } catch(error) {
    // We want to capture errors and render them in a user-friendly way, while
    // still logging an exception with StackDriver
    console.log(error);
    await snap.ref.set({error: userFacingMessage(error)}, { merge: true });
    return reportError(error, {user: context.params.userId});
  }
});

有人可以解释我在这里缺少什么吗? 为什么我收到错误? 我尝试手动充值帐户,这也无济于事。

更新 1 :根据 Sergio Tulentsev 的评论,我似乎必须确认转移才能成功。 所以我在成功传输后确实实现了以下行,但错误仍然相同:

stripe.paymentIntents.confirm(response.id, {payment_method: response.payment_method})

stripe.paymentIntent.confirmstripe.confirmCardPayment什么stripe.confirmCardPayment

您似乎可以访问仪表板并且拥有测试帐户。 在这种情况下,您可以从 Payments -> New 手动添加资金,然后提供如图所示的测试卡详细信息,此处使用的卡号为 4000 0000 0000 0077。

正如您提到的,您正在生成付款意图,这只会在您添加有效的真实账户后才将费用金额计入您的可用资金,直到那时资金将始终处于暂停状态。

因此,为了进行测试,您可以手动添加资金,如手动生成新付款的链接图片所示

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM