【问题标题】:Update subscription Braintree and prorateCharges Error ID already taken更新订阅 Braintree 和 prorateCharges 错误 ID 已被占用
【发布时间】:2019-08-20 15:54:31
【问题描述】:

大家好,我正在尝试将每月订阅更新为 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 已被使用我的意思是我正在尝试从一个订阅更新到另一个订阅,显然我尝试更新到的那个订阅已被使用。同样,我要做的就是从用户已经使用的订阅更新到用户选择要更新到的订阅。这里的任何帮助都会很棒。谢谢

【问题讨论】:

    标签: updates subscription braintree


    【解决方案1】:

    完全披露,我在 Braintree 工作。如果您还有任何问题,我建议您联系Support

    您在错误的参数中传递了计划 ID。 id 参数可用于您希望拥有的新订阅 ID。要更新到不同的计划,您需要传递 planId 参数,该参数表示您希望将它们更新到的计划。

    我还注意到您正在传递一个paymentMethodToken 参数。这仅在您更新付款方式令牌时使用。如果这是您的意图,请继续!否则,您不需要在更新请求中传递此参数。

    例如,如果您想更新计划并保留相同的付款方式令牌,您的请求可能如下所示:

    const subUpdateResponse = await gateway.subscription.update(
      oldSubscriptionId,
      {
        planId: selectedPlanId,
        options: {
          prorateCharges: true
        }
      }
    );
    

    【讨论】:

      猜你喜欢
      • 2015-10-25
      • 2017-09-29
      • 2018-11-21
      • 2018-11-28
      • 2015-06-19
      • 2019-03-01
      • 2019-10-01
      • 2015-04-10
      • 1970-01-01
      相关资源
      最近更新 更多