omise / omise-ruby

Omise Ruby Library
https://docs.opn.ooo
MIT License
40 stars 20 forks source link

`key` parameter fails to propagate #30

Closed scomma closed 3 years ago

scomma commented 5 years ago

We toggle between multiple keys but it appears the library is working against us in many cases.

  1. Omise.api_key must be set (I found issue #19 with an identical problem but it was cryptically closed without documenting the solution)
  2. Omise::Charge.retrieve('chrg_xxxxxx', key: 'xxxxxxxx') works, but calling charge.transaction on the result results in a transaction not found error, unless I repeat the key with charge.transaction(key: 'xxxxxxxx')
  3. Omise::List object doesn't retain the key when I paginate with next_page, and this one doesn't even accept the key parameter
robinclart commented 5 years ago

Hi @scomma. I'm currently working on a permanent fix for this but it's taking a bit of time as a lot of internals needs a serious rework to make this fully correct. Will update here once it's ready.

robinclart commented 5 years ago

@scomma you can try this branch #32 to see if it fixes your issues.

It removes the key: option and instead you should change accounts like this:

Omise.secret_api_key = "skey_1"

Omise.use_account(secret_api_key: "skey_2") do
  # while in this block all calls will use `skey_2`
  charge = Omise::Charge.create(charge)
  # etc.
end

# From this point the original key is back.
Omise::Customer.create(customer)
robinclart commented 5 years ago

Note that this should also work if you're using multiple threads as Omise.account uses a thread local variable.