solidusio-contrib / solidus_klarna_payments

Klarna Payments gateway for Solidus.
Apache License 2.0
6 stars 17 forks source link

how to set the Zone for other endpoint than us? #57

Open hefan opened 1 year ago

hefan commented 1 year ago

At the moment the extension seems to always connect with the default endpoint from klarna_proxy https://api-na.klarna.com (production) https://api-na.playground.klarna.com (test) see here https://github.com/nebulab/klarna_proxy/blob/main/lib/klarna/configuration.rb#L9

Is there a possibility to add a zone parameter or something similar to be able to send to the europe or oceania servers?

kennyadsl commented 1 year ago

Hey @hefan! Reading the code I think you can do:

klarna_config = Klarna::Configuration.new
klarna_config.zone = :europe

and this line will pick up the right endpoint.

Let me know if that's correct, please!

BTW, I think it's a good idea to make it configurable, so if you want to contribute for that, I guess it's a good change.

kennyadsl commented 1 year ago

Also, reading this other piece, you can probably add to an initializer:

Klarna.configuration do |config|
  config.zone = :europe
end

cc @vassalloandrea (pinging you because you are among the authors of that extension)

hefan commented 1 year ago

Hello @kennyadsl

Adding

Klarna.configure do |config|
  config.zone = :europe
end

to an initializer went well in my case, thank you!

However, for being able to configure it, zone needs to be added at least to https://github.com/solidusio-contrib/solidus_klarna_payments/blob/master/lib/active_merchant/billing/klarna_gateway.rb#L13 and https://github.com/solidusio-contrib/solidus_klarna_payments/blob/master/app/services/solidus_klarna_payments/validate_klarna_credentials_service.rb#L7

The Zone should be added as a dropdown for the three zones in the payment method settings, i suppose. Maybe it could also be a good idea to leave it as an initializer and tell about zones in the Readme.

If you tell me what is the way you would prefer, i am happy to open a pull request theses days.

kennyadsl commented 1 year ago

I think the initializer is the best trade-off for now, and we can fix it immediately. If you have extra time for proposing to change it with something in the Admin UI, it would be great as well, but could come later. 🙏

hefan commented 1 year ago

so it would be best to mention in Readme, no?

kennyadsl commented 1 year ago

Yes!

hefan commented 1 year ago

ok. i will open a respective pull request later or tomorrow..