gpt4 book ai didi

javascript - Stripe连接传输: Insufficient funds

转载 作者:行者123 更新时间:2023-11-28 14:11:01 27 4
gpt4 key购买 nike

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

Insufficient funds in Stripe account. In test mode, you can add funds to your available balance (bypassing your pending balance) by creating a charge with 4000 0000 0000 0077 as the card number. You can use the the /v1/balance endpoint to view your Stripe balance (for more details, see stripe.com/docs/api#balance).

Stripe Dashboar 中的 paymentIntent 显示 PaymentIntent 状态:requires_confirmation

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

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

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

// 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 有什么区别?

最佳答案

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

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

因此,为了进行测试,您可以手动添加资金,如链接pic of generating new payment manually所示

关于javascript - Stripe连接传输: Insufficient funds,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59443719/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com