lundi 19 septembre 2016

Correct way to require Payment API in Rails

I'm trying to integrate Mollie Payments using the Mollie API I added the gem to my gemfile and ran bundle install. After that i did this to my existing controller:

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

Where form_page is the 'new' method and 'success' is the page where it should redirect to after payment has succeeded.

But when going to the form_page view i get this error:

NoMethodError (undefined method `api_key=' for #<Mollie::API::Client:0x007fa6fb8>)

So my guess is that the API isn't required the right way or something like that. Anybody has an idea on what i'm doing wrong? Any help would be much much appreciated!!

Aucun commentaire:

Enregistrer un commentaire