我正在尝试使用Mollie API整合Mollie Payments 我将gem添加到我的gemfile并运行bundle install。之后,我对现有的控制器做了这个:
class PagesController < ApplicationController
require 'Mollie/API/Client'
def form_page
mollie = Mollie::API::Client.new
mollie.api_key = 'test_SKQzVUv7Rs7AUqmW7FdTvF9SbEujmQ'
payment = mollie.payments.create(
amount: 10.00,
description: 'My first API payment',
redirectUrl: '/index'
)
payment = mollie.payments.get(payment.id)
if payment.paid?
puts 'Payment received.'
end
end
def success
end
end
form_page是'new'方法,'success'是付款成功后应该重定向到的页面。
但是当进入form_page视图时,我收到此错误:
NoMethodError (undefined method `api_key=' for #<Mollie::API::Client:0x007fa6fb8>)
所以我的猜测是,API不是正确的方式或类似的东西。有人知道我做错了吗?任何帮助将非常感谢!!
答案 0 :(得分:1)
要避免此异常,请尝试使用方法setApiKey
代替api_key =
mollie = Mollie::API::Client.new
mollie.setApiKey "test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM"
示例dir:
中描述了如何处理webapp请求的更多示例https://github.com/mollie/mollie-api-ruby/tree/master/examples