【问题标题】:Update payment methods in stripe更新条带中的付款方式
【发布时间】:2021-10-12 03:23:15
【问题描述】:

我正在尝试在条带付款方式中存在的计费详细信息对象中添加电话号码。到目前为止,我能够通过电子邮件和类型获取付款方式的数据,现在我正在尝试以单独的方法发送更新模型,该方法将更新计费详细信息中的电话号码。但是我收到了这个错误

"message":"No such PaymentMethod: 'cus_JztknPBEnl5h8x'","stack":"Error: No such PaymentMethod: 'cus_JztknPBEnl5h8x'\n at Function.generate (/Users/mac/Desktop/Batch-Skip/batch -skip-tracing/server/node_modules/stripe/lib/Error.js:40:16)\n 在 IncomingMessage. (/Users/mac/Desktop/Batch-Skip/batch-skip-tracing/server/node_modules/stripe/ lib/StripeResource.js:203:33)\n 在 Object.onceWrapper (events.js:481:28)\n 在 IncomingMessage.emit (events.js:387:35)\n 在 IncomingMessage.emit (domain.js :470:12)\n 在 endReadableNT (internal/streams/readable.js:1317:12)\n 在 processTicksAndRejections (internal/process/task_queues.js:82:21)","context":"payment-controller" ,"method":"addNewCard","level":"error","timestamp":"2021-08-07 23:08:18 +0500"}

这是我的 getPaymentDetails 方法

  public async getAllStripePayments(id: string): Promise<Stripe.Response<Stripe.ApiList<Stripe.PaymentMethod>>> {
    const paymentMethods = await this.stripeClient.paymentMethods.list({customer: id, type: 'card'});
    return paymentMethods;
  }

这里是更新方法

      public async updateStripePaymentMethods(id: string, updateModel: Stripe.PaymentMethodUpdateParams): Promise<Stripe.Response<Stripe.PaymentMethod>> {
        const paymentMethods = await this.stripeClient.paymentMethods.update(id, updateModel);
        return paymentMethods;
      }

这样调用更新方法

const paymentMethod = await this.stripeApi.getAllStripePayments(stripeCustomer.id);
    console.log(JSON.stringify(paymentMethod));
    const updateModel = {
      billing_details: {
        phone: customerMeta.phoneNumber,
      },
    };
    const updatePaymentMethod = await this.stripeApi.updateStripePaymentMethods(stripeCustomer.id, updateModel);
    console.log(updatePaymentMethod);

getPaymentDetails 方法返回的数据如下所示

{
  "object": "list",
  "data": [
    {
      "id": "card_xxxxxxxxxxxx",
      "object": "payment_method",
      "billing_details": {
        "address": {
          "city": null,
          "country": null,
          "line1": null,
          "line2": null,
          "postal_code": "xxxxx",
          "state": null
        },
        "email": null,
        "name": null,
        "phone": null
      },
      "card": {
        "brand": "visa",
        "checks": {
          "address_line1_check": null,
          "address_postal_code_check": "pass",
          "cvc_check": "pass"
        },
        "country": "US",
        "exp_month": 7,
        "exp_year": 2026,
        "fingerprint": "rxyg7B0k7Wp2Komf",
        "funding": "credit",
        "generated_from": null,
        "last4": "4242",
        "networks": {
          "available": [
            "visa"
          ],
          "preferred": null
        },
        "three_d_secure_usage": {
          "supported": true
        },
        "wallet": null
      },
      "created": 1628359699,
      "customer": "cus_JztknPBEnl5h8x",
      "livemode": false,
      "metadata": {},
      "type": "card"
    }
  ],
  "has_more": false,
  "url": "/v1/payment_methods"
}

【问题讨论】:

    标签: node.js express stripe-payments


    【解决方案1】:

    您将 stripeCustomer.id 传递给 updateStripePaymentMethods 调用 paymentMethods.update - 这就是您收到错误消息的原因 No such PaymentMethod: 'cus_123'。这是客户 ID,而不是付款方式 ID。付款方式更新需要一个付款方式 ID。 https://stripe.com/docs/api/payment_methods/update

    看起来paymentMethod 实际上是paymentMethods 复数的列表,因此您需要选择一个并提供该ID(或依次迭代并提供每个ID)。

    【讨论】:

    • 所以我现在尝试像这样paymentMethod.data[0].id 在其中添加卡的ID,但出现错误{"message":"This PaymentMethod was converted from a legacy Card object. You may not update the email or phone number of these PaymentMethods."
    • 问题是当得到付款方式时,没有付款方式的ID,因为它应该以关键字“pm”开头
    • 我想我遇到了问题。由于我正在创建客户,因此付款方式实际上是旧卡对象,并且无法更新旧卡对象,如错误所述。所以我想我在这个死胡同。你觉得我的发现怎么样?
    猜你喜欢
    • 2020-01-16
    • 2018-01-10
    • 1970-01-01
    • 2021-07-02
    • 2021-09-19
    • 2021-11-13
    • 1970-01-01
    • 2018-06-06
    • 2016-11-05
    相关资源
    最近更新 更多