Closed michaelshmitty closed 7 years ago
You're right, this gem does need some love! We're currently working on a new 2.0.0-release. I'll make sure the code examples on the docs are correct for this new release.
I think the code examples in the documentation use methods that aren't implemented yet in our Ruby client.
Let me try to help out: When setting up a payment using the documentation as it stands now I get: "wrong number of arguments (given 0, expected 1)"
mollie = Mollie::API::Client.new
mollie.setApiKey 'test_EygcTKUUPHnS85C4c5x2GAQ74rnyWr'
Should in fact be mollie = Mollie::API::Client.new 'test_EygcTKUUPHnS85C4c5x2GAQ74rnyWr'
in order for it to work.
Then the next thing that I get jammed on and haven't solved yet is: undefined method `getPaymentUrl' for #
Thing is also, the context isn't that clear. I am using Rails, not Sinatra as my Ruby framework.
Where am I supposed to put all this code was the first thing I was wondering and how should I route it? Should my action be explicitly called post
instead of get
when I build the member action in the order actions?
I'll keep you updated if you'd like about me progressing through all this.
Where this Rails implementation of Mollie in my application stands right now:
undefined method `getPaymentUrl' for #
I am trying to accomplish a payment like so:
orders_controller.rb
require 'Mollie/API/Client'
# ...omitted
def pay
mollie = Mollie::API::Client.new 'test_EygcTKUUPHnS85C4c5x2GAQ74rnyWr'
begin
payment = mollie.payments.create({
:method => "ideal",
:amount => @order.total_price_in_euros,
:description => "#{@order.customer.first_name} #{@order.customer.last_name} order: #{@order.id}",
:redirectUrl => "http://localhost:3000/orders/#{@order.id}/success",
:metadata => {
:order_id => @order.id
}
})
# # Send the customer off to complete the payment.
redirect_to payment.getPaymentUrl
rescue Mollie::API::Exception => e
$response.body << "API call failed: " << (CGI.escapeHTML e.message)
end
end
routes.rb
resources 'orders', only: [:index] do
member do
get 'empty'
get 'check_out'
get 'confirm'
get 'pay'
get 'success'
end
resources 'invoices', only: [:show] do
member do
get 'sent_out'
end
resource 'download', only: [:show]
end
end
end
Not sure if it should be get 'pay'
or post 'pay'
that I should be using. Both works for getting orders with an "open" status in my Mollie Dashboard.
Invokation starts after clicking this link:
<%= link_to 'Pay for order', [:pay, @order] %>
Obviously after having confirmed all the order details (and having made a customer account /w address).
I have identified the mistake that gave me the error.
# on your website
$response.redirect payment.getPaymentUrl
# what works for me
redirect_to payment.payment_url
It seems that the ruby code is mixed with JS code inside of the docs on the Mollie website.
Anyway with this change my def pay
now works. My first web-application's payment is a fact!
Thanks for your feedback @Lubmes! We'll take this into account when we update the Ruby examples on our website.
Thanks, we've updated the documentation on our site. Let us know if we missed anything.
@willemstuursma the examples on the site still use withParentId
for the mandates API, when it should just be with
.
Hey @mvz, how are you? I will doing some maintenance on this whole repo and that will include updating the examples. Examples should be updated in the next coming weeks.
After that the examples on the website will have to be updated as well..
Doing fine, @benoist. How about you?
Good to hear the examples will be updated. I wasn't very clear in my previous comment that I meant the example in the documentation here: https://www.mollie.com/nl/docs/reference/mandates/list#example
@mvz thanks! @benoist still not updated in the docs (withParentId)
hi @ajw400, thanks for the reminder. The new version has recently been released and I will ask Mollie when they will be able to update the docs on the website. The examples have been updated and can be used instead of the code sample on the website.
@Smitsel can you update it on our website?
How can we create mandates?
@maysam Creating a mandate appears to be easy. For a payment method that supports subscriptions you simple add
recurring_type: "first"
to your call to
mollie.payments.create
This will automatically create a mandate after the customer has created an initial payment.
For getting the mandates for a user this seems to work:
mollie.customers_mandates.with("cst_xxxxxxx").all()
(where cst.xxxxxx is the customer_id that you get after the initial payment) Please not that this differs from the documentation on the Mollie website - withParentId seems to not work.
Am I correct in assuming that currently cancelling a mandate or subscription is not possible through the gem ?
does it still support subscriptions? I cannot find any documentations on it
@maysam I am able to create subscriptions with it. After you've created the first payment you can do this:
subscription = mollie.customers_subscriptions.with("cst_xxxxxxx").create({ :amount => 24.50, :interval => "1 month", :description => "Subscription", :startDate => Time.now+1.month, webhookUrl:"http://your-webhook-url", })
Basically I let them make a first payment and then the next payments will be automatically done on a monthly basis.
I can't find anything on cancelling the subscription through the gem though, I'd like to cancel the mandate with a before_destroy callback on my user model.
@rogerheykoop @maysam You can look at this file how to create a subscription via the new Api 3.1.1+
https://github.com/mollie/mollie-api-ruby/blob/master/examples/apis/subscriptions.rb#L104
@benoist subscriptions = Mollie::Customer::Subscriptions.all doesnt work with version 3, are you sure it's working?
You need to add a customer_id in the params
yes, but this is the error I get
NameError: uninitialized constant Mollie::Customer::Subscriptions
and everything else is working fine
GIT remote: https://github.com/mollie/mollie-api-ruby.git revision: 644d646e65b7b2cc8ee1b3b6aedf742bf8819384 tag: v3.1.0 specs: mollie-api-ruby (3.1.0)
its singular Subscription, but I see its shown incorrect in the examples
Either the documentation here is out of date or this gem is broken. The documentation and examples in this gem are rather poor.
My ultimate goal is to create a subscription / recurring payment. But I can't even seem to get past listing the active mandates after creating the customer and processing an initial payment:
require 'Mollie/API/Client'
mollie = Mollie::API::Client.new
mollie.api_key = 'test_...'
customers_mandates = mollie.customers_mandates.withParentId("cst_...").all
NoMethodError: undefined method 'withParentId' for #<Mollie::API::Resource::Customers::Mandates:0x007fd004711278>
Judging from some of the other issues listed here, this gem urgently needs some love. I urge Mollie to get some people to work on this because they will lose customers who are trying to integrate their API into their rails app.