updates - 更新订阅 Braintree 和 prorateCharges 错误 ID 已被占用
问题描述
大家好,所以我正在尝试将每月订阅更新为 Braintree 中的另一个每月订阅并按比例分配费用。在阅读了他们的文档后,我对如何有效地做到这一点感到困惑。当我去更新订阅时,我收到以下错误消息:“ID 已被占用。”
router.put("/update-subscription", async (req, res, next) => {
try {
console.log("hit route");
if (!res.locals.user) {
throw { status: 403, message: "Not logged in." };
} else {
const { subscriptionId, selectedPlanName } = req.body;
const oldSubscriptionId = subscriptionId;
const selectedPlanId = selectedPlanName.replace(/\s/g, "_");
const userId = res.locals.user.id;
const [[userData]] = await database.query("call getUserByUserId(?)", [
userId
]);
const { braintreeId } = userData;
const { paymentMethods } = await gateway.customer.find("" + braintreeId);
const { token } = paymentMethods.find(p => p.default);
console.log("oldSubscriptionId", oldSubscriptionId);
console.log("selectedPlanId", selectedPlanId);
const subUpdateResponse = await gateway.subscription.update(
oldSubscriptionId,
{
id: selectedPlanId,
paymentMethodToken: token,
options: {
prorateCharges: true
}
}
);
console.log("subUpdateResponse", subUpdateResponse);
if (subUpdateResponse.success) {
res.send("Successfully updated plan");
} else {
throw { message: "An error occurred." };
}
}
} catch (error) {
next(error);
}
});
这是日志
subUpdateResponse ErrorResponse {
errors:
ValidationErrorsCollection {
validationErrors: {},
errorCollections: { subscription: [Object] } },
params:
{ id: 'SILVER_MONTHLY',
paymentMethodToken: 'krs2p5',
options: { prorateCharges: 'true' } },
message: 'ID has already been taken.',
success: false }
{ message: 'An error occurred.' }
我了解“SILVER_MONTHLY”ID 已被使用我的意思是我正在尝试从一个订阅更新到另一个订阅,显然我尝试更新到的订阅已经被使用。同样,我要做的就是从用户已经使用的订阅更新到用户选择要更新到的订阅。这里的任何帮助都会很棒。谢谢
解决方案
完全披露,我在 Braintree 工作。如果您有任何其他问题,我建议您联系支持
您在不正确的参数中传递了计划 ID。该id
参数可用于您希望拥有的新订阅 ID。要更新到不同的计划,您需要传递一个planId
参数,该参数表示您要将它们更新到的计划。
我还注意到您正在传递一个paymentMethodToken
参数。这仅在您更新付款方式令牌时使用。如果这是您的意图,请继续!否则,您不需要在更新请求中传递此参数。
例如,如果您想更新计划并保留相同的付款方式令牌,您的请求可能如下所示:
const subUpdateResponse = await gateway.subscription.update(
oldSubscriptionId,
{
planId: selectedPlanId,
options: {
prorateCharges: true
}
}
);
推荐阅读
- c# - Visual Studio 2019 EDMX 缺少 ADO.NET 实体数据模型项模板
- ruby - 如果 0 索引值是满足条件的唯一值,则 Ruby 中的 Array#bsearch 返回 nil
- .htaccess - 用于 SSL 的 htaccess 301 指令
- c++ - 了解 XML CharData EBNF
- svelte - 制作刷新按钮以更新 store.js 中的 ajax 并触发 {#await} 承诺
- javascript - 在 Javascript 中使用夏令时检查日期范围
- python - 如何在 Python 中用正/负整数和浮点数转换字符串
- python-3.x - 我应该如何使用 pyaudio 进行直播
- java - Bean 应该是“CourseDAO”类型,但实际上是“com.sun.proxy.$Proxy49”类型
- godot - 如何比较godot中的两个节点坐标