【问题标题】:Stripe API throwing error when trying to delete a card尝试删除卡时 Stripe API 抛出错误
【发布时间】:2013-07-22 09:16:41
【问题描述】:

我正在尝试使用 ruby​​ 库从 Stripe 中删除一张卡片,但我遇到了以下错误。

undefined method `delete' for Stripe::Customer:Class

这是我的代码中导致错误的行

customer = Stripe::Customer.delete(@user.stripe_id)

Customer 类上似乎没有删除方法,但文档说有。

这是 Stripe 文档中处理删除卡片的部分。 https://stripe.com/docs/api/ruby#delete_card

如您所见,我的代码与文档中的行相同,但客户 ID 的来源除外。

另外,我确实注意到文档中有一个错误,

customer = Stripe::Customer.delete({CARD_ID})

应该是,

customer = Stripe::Customer.delete({CUSTOMER_ID})

我也尝试过使用卡 ID 以确保它会产生相同的错误。

如果有人有任何想法,将不胜感激。

编辑:到目前为止,我一直在使用条带,其他方法(例如 Stripe::Customer.retrieve())工作得很好。

编辑 2:我正在使用 gem 版本 1.8.4,这似乎是最新版本。

【问题讨论】:

  • 是的,Stripe 还是不让客户delete its card number,我觉得不能接受。
  • 其实是有可能的,见blog postrelevant API。不过,到目前为止我遇到的使用 Stripe 的网站并不关心实现这个功能。

标签: ruby stripe-payments payment-gateway


【解决方案1】:

文档中似乎有两个错误,您是否尝试过这个:

customer = Stripe::Customer.retrieve({CUSTOMER_ID})
customer.cards.retrieve({CARD_ID}).delete()

【讨论】:

  • 我在尝试删除卡片时收到*** NoMethodError Exception: undefined method 'delete' for #<Stripe::ListObject:0x007fb62e33afb8>
  • 修复:card = customer.cards.retrieve({CARD_ID}); card.delete
  • 谢谢大家!我使用了更新文档中的版本,并且成功了!
  • 现在是card = customer.sources.retrieve({CARD_ID})
猜你喜欢
  • 2020-06-24
  • 2022-01-27
  • 2017-06-18
  • 2020-07-15
  • 2021-11-08
  • 2021-04-03
  • 2014-12-02
  • 2015-12-08
  • 1970-01-01
相关资源
最近更新 更多