![](/img/trans.png)
[英]I keep getting "StripeInvalidRequestError: Insufficient funds in Stripe account." even though that I do have enough funds
[英]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 的后端。
这是创建account
和customer
的函数。 我正在创建它们只是为了确保一切正常。
// 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.confirm
与stripe.confirmCardPayment
什么stripe.confirmCardPayment
?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.