mollie-api-ruby icon indicating copy to clipboard operation
mollie-api-ruby copied to clipboard

Ensure base get always receives an ID

Open moiristo opened this issue 2 years ago • 2 comments

Yesterday, there was a major disruption in mollie. I found out that some payments were created, but we didn't get a response back. Later on, we did get a webhook calllback though.

The issue we encountered is that when you do a get without an ID, you get a collection of payments as a response. This cannot be mapped to the object (Payment), but yields an 'empty' Payment object anyway. However, this also means that if you call chargebacks on that object, that you receive a collection of all available chargebacks for the account. This had some unfortunate consequences for us :)

moiristo avatar Nov 10 '22 09:11 moiristo

Thanks @moiristo,

That's certainly unexpected. I think we can safely raise an error when id is nil. There are no use-cases for a get without an id as far as I know.

justincase avatar Nov 10 '22 19:11 justincase

Hi @justincase, thanks for the feedback. I changed it to raise an ArgumentError instead and also check for blank values.

moiristo avatar Nov 11 '22 11:11 moiristo

Thanks again @moiristo,

I've changed the PR slightly. I'll revisit this at some point for further improvements:

  • Mollie::Payment.new(id: nil).chargebacks also returns all chargebacks
  • Improve path construction. The current implementation is a bit naive and doesn't work for some endpoints (/v2/payment-links (hypen), /v2/wallets/applepay/sessions and /v2/methods/voucher/issuers (> 2 path segments).
  • (maybe) validate resource prefixes, tr_, re_, chb_, mdt_, etc though not all resources have a prefix (methods, permissions)

justincase avatar Dec 01 '22 22:12 justincase