Ruby on rails 条带:未定义的方法';最后4';检索条带充电轨的最后4位数字时

Ruby on rails 条带:未定义的方法';最后4';检索条带充电轨的最后4位数字时,ruby-on-rails,stripe-payments,Ruby On Rails,Stripe Payments,我的rails应用程序正在使用Stripe成功地进行支付,但在尝试从成功的收费中检索信用卡的最后4位数字时,我遇到了一个未定义的方法错误 错误: undefined method `last4' for #<Stripe::Charge:0x007ff2704febc8> app/models/order.rb:33:in `stripe_retrieve' app/controllers/orders_controller.rb:54:in `block in create' a

我的rails应用程序正在使用Stripe成功地进行支付,但在尝试从成功的收费中检索信用卡的最后4位数字时,我遇到了一个未定义的方法错误

错误:

undefined method `last4' for #<Stripe::Charge:0x007ff2704febc8>

app/models/order.rb:33:in `stripe_retrieve'
app/controllers/orders_controller.rb:54:in `block in create'
app/controllers/orders_controller.rb:52:in `create'
order.rb

def save_with_payment
if valid?
  customer = Stripe::Customer.create(description: email, card: stripe_card_token)
  self.stripe_customer_token = customer.id
  self.user.update_column(:customer_id, customer.id)
  save!

  Stripe::Charge.create(
      :amount => (total * 100).to_i, # in cents
      :currency => "usd",
      :customer => customer.id
  )
 end
rescue Stripe::InvalidRequestError => e
logger.error "Stripe error while creating customer: #{e.message}"
errors.add :base, "There was a problem with your credit card."
false
end

def stripe_retrieve
charge = Stripe::Charge.retrieve("ch_10U9oojbTJN535")
self.last_4_digits = charge.last4
self.user.update_column(:last_4_digits, charge.last4)
save!
end
这是显示如何检索费用的条带文档,您可以看到“last4”是正确的,那么为什么它会显示为未定义的方法呢


响应将返回一张卡,该卡本身有一个last4。因此,卡是它自己的对象

charge.card.last4
以下是文件:

#<Stripe::Charge id=ch_0ZHWhWO0DKQ9tX 0x00000a> JSON: {
  "card": {
    "type": "Visa",
    "address_line1_check": null,
    "address_city": null,
    "country": "US",
    "exp_month": 3,
    "address_zip": null,
    "exp_year": 2015,
    "address_state": null,
    "object": "card",
    "address_country": null,
    "cvc_check": "unchecked",
    "address_line1": null,
    "name": null,
    "last4": "1111",
#JSON:{
“卡片”:{
“类型”:“Visa”,
“地址行1检查”:空,
“地址城市”:空,
“国家”:“美国”,
“经验月”:3,
“地址”:空,
“经验年”:2015年,
“地址状态”:空,
“对象”:“卡片”,
“地址/国家”:空,
“cvc_检查”:“未检查”,
“地址_行1”:空,
“名称”:空,
“last4”:“1111”,

响应将返回一张卡,该卡本身有一个last4。因此该卡是它自己的对象

charge.card.last4
以下是文件:

#<Stripe::Charge id=ch_0ZHWhWO0DKQ9tX 0x00000a> JSON: {
  "card": {
    "type": "Visa",
    "address_line1_check": null,
    "address_city": null,
    "country": "US",
    "exp_month": 3,
    "address_zip": null,
    "exp_year": 2015,
    "address_state": null,
    "object": "card",
    "address_country": null,
    "cvc_check": "unchecked",
    "address_line1": null,
    "name": null,
    "last4": "1111",
#JSON:{
“卡片”:{
“类型”:“Visa”,
“地址行1检查”:空,
“地址城市”:空,
“国家”:“美国”,
“经验月”:3,
“地址”:空,
“经验年”:2015年,
“地址状态”:空,
“对象”:“卡片”,
“地址/国家”:空,
“cvc_检查”:“未检查”,
“地址_行1”:空,
“名称”:空,
“last4”:“1111”,