Closed rickpastoor closed 5 years ago
uninitialized constant Moneybird::Service::Payment (NameError)
This tells me lib/moneybird/service/payment.rb
is not loaded, which is odd, since it is loaded here.
Can you access the rest of the Moneybird gem?
I can load other classes, yes. Which is weird indeed.
Regardless, is my way of approaching adding a new payment the preferred way or should I try a different route?
I think you need to first instantiate a service object, like so:
service = Moneybird::Service::Payment.new(client, administration.id, invoice.id)
service.create(payment_date: date, price: amount)
Payments are een subroute under sales invoices. In the gem you can get the invoice first for which you want to create the payment. Then the payment property of that invoice will get you the correct service.
invoice = administration.sales_invoices.find(id)
invoice.payments.create(payment_date: date, price: amount)
Late to the party:
@rickpastoor / @mvz I also can't access the payment class via the Moneybird gem, Product
and Purchase
invoice are the only classes accessible via the service class that being with P.
with both suggestions from @LuukvH and @mvz not working for me, due to the Payment class being inaccessible.
My work around is using HTTParty to handle this single request, be cool if this would work... maybe I can find time to dig into the gem & contribute :)
Well, d'oh! The version with Moneybird::Service::Payment
hasn't been released yet.
I can release a new version this weekend :)
@maarteenvanvliet ~ hero, that would awesome.
I thought this was a discussion of current gem functionality rather than proposed ;)
@noccor I think all participants thought that :laughing:.
I'm glad I commented or I'd probably not figure it out until this time next week :D thanks for getting back to me guys.
I cut a release 😀I also was able to register a payment the way @LuukvH described.
Awesome! I'll give it a whirl on Monday :) ~ not related to this thread... but is it possible to create "paid" invoices via MoneyBird immediately? Rather than 'Draft > Send > Paid' I've reached out to MB support / consulted myself against the API docs ~ but they never seem to quite answer my question
I've been considering an edge case where the create_payment
is not processed quickly enough on MB (or own BE), and sends the client an invoice with an outstanding payment. (We process invoices post-purchase, handel payments via Mollie and only use MB for book keeping).
I don't know of a way to bypass the 'Draft > Send > Paid' flow in one go. You certainly have a valid use-case, would be cool to embed the payments into an invoice when you create it and have it marked as paid immediately.
What you could look into is pausing the workflow of a sales_invoice (https://developer.moneybird.com/api/sales_invoices/#post_sales_invoices_id_pause). I believe this would stop any followup emails on outstanding payments. It's not supported in the gem yet but should be trivial to implement.
Perhaps a good idea ~ easy enough to implement outside of the gem. I'll do some testing, perhaps using MB's delay payment method and sending the invoice X hours later is sufficient ~ that way the client gets their invoices immediately and the customer should get their invoice once, marked as paid (if you can add a payment to a delayed send that is). It's not that uncommon to receive an invoice a short time after payment.
Thanks again Maarten for getting back to me :) !
@maartenvanvliet I think this can be closed now.
👍
I can't get this to work. I don't fully grasp how this library works and the latest addition to add payments does not have tests attached, so I can't defer the inner workings from there.
Returns
uninitialized constant Moneybird::Service::Payment (NameError)
I've loaded the gem like this, but that does not solve things:
gem 'moneybird', git: 'git@github.com:maartenvanvliet/moneybird.git', ref: 'ecb947d35619273d8e4b4179a0f1414f3cdf47bc'
I've now solved this by manually posting the payment via Excon, but that's not the nicest solution :)