rails 4.2.6 ruby 2.3.1
我正在使用Ruby,并且已经成功地创建了支付并保存了payment_id。我在尝试开具退款时收到以下错误。
NoMethodError: undefined method 'refund_request' for #<PayPal::SDK::REST::DataTypes::Payment>
def self.refund_successful?(payment_id)
require 'paypal-sdk-rest'
include PayPal::SDK::REST
include PayPal::SDK::Core::Logging
PayPal::SDK::REST.set_config(
:mode => "sandbox", # "sandbox" or "live"
:client_id => ENV["paypal_client_id"],
:client_secret => ENV["paypal_client_secret"])
payment = Payment.find(payment_id)
refund = payment.refund_request # <= Error occurs here.
refund = payment.refund_request({}) # <= Also tried this.
if refund.success?
return true
else
return false
end
end我没有在refund_request方法中添加任何参数,因为退还的金额是“全部”金额而不是“部分”金额。虽然,只是为了测试目的,我添加了amount,但仍然收到相同的错误。
这是我从PayPal上看到的:
https://github.com/paypal/PayPal-Ruby-SDK/blob/master/samples/sale/refund.rb
发布于 2017-05-05 17:55:39
这是一个类中的方法吗?如果是这样,请记住,当您使用self.method_name定义方法时,它被视为类常量,不能在实例化的类上调用。
例如
class HelloWorld
def self.foo
puts "Hello World!"
end
def bar
puts "Hello World!"
end
end只能通过以下方式调用foo方法
HelloWorld.foobar方法只能通过首先实例化类,然后调用该方法来调用。例如,
hello_world = HelloWorld.new
hello_world.barhttps://stackoverflow.com/questions/43794670
复制相似问题