[英]Stripe - Update default card
I am trying to allow the user to update their default payment method after they add it. 我试图允许用户在添加默认付款方式后对其进行更新。 I am getting this in Firebase Functions:
Error: No such source: card_1EhmibFZW9pBNLO2aveVfEm6
. 我在Firebase功能中得到此
Error: No such source: card_1EhmibFZW9pBNLO2aveVfEm6
。
This leads me to believe that I need to pass default_source
a src_XXX...
id rather than a card_XXX...
id. 这使我相信我需要传递
default_source
一个src_XXX...
id而不是card_XXX...
id。 Anyone have an idea on this? 有人对此有想法吗?
Firebase Function: Firebase功能:
// Update Stripe default card based on user choice
exports.updateDefaultSource = functions.firestore
.document("users/{userId}")
.onUpdate(async (change, context) => {
const newValue = change.after.data();
const previousValue = change.before.data();
console.log("previousValue.default_source: "+previousValue.default_source)
console.log("newValue.default_source: "+newValue.default_source)
if (
previousValue.default_source &&
newValue.default_source !== previousValue.default_source
) {
// this triggers on every update to profile (more overhead), can we reduce this?
try {
console.log("newValue.default_source: "+newValue.default_source)
const response = await stripe.customers.update(
previousValue.customer_id,
{ default_source: newValue.default_source },
(err, customer) => {
console.log(err);
}
);
return console.log("Response from Stripe update: " + response);
} catch (error) {
console.log(error);
await change.ref.set(
{ error: userFacingMessage(error) },
{ merge: true }
);
return reportError(error, { user: context.params.userId });
}
}
});
Firebase Function logs after I add the second Card to account: 将第二张卡添加到帐户后,Firebase功能将记录日志:
Looks like this error solved itself, not 100% sure on how, but my guess is it had to do with Redux and/or Redux Persist not having everything loaded into the store. 看来此错误已解决,但不是100%知道如何解决,但我想这与Redux和/或Redux Persist没有将所有内容加载到商店有关。
My main question was answered by @hmunoz on whether or not the default_source accepted the card_123 type, which it does. @hmunoz回答了我的主要问题,有关default_source是否接受card_123类型,它是否这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.