jlevers / selling-partner-api

A PHP client library for Amazon's Selling Partner API
BSD 3-Clause "New" or "Revised" License
398 stars 185 forks source link

How to pass ConfigurationOptions to Configuration? #73

Closed discover59 closed 3 years ago

discover59 commented 3 years ago

I prefer to use dynamic ConfigurationOptions for dynamic sellers and pass it to Configuration. But it doesn't accept that type which is confusing.

Please let me know what I can use for this purpose.

jlevers commented 3 years ago

The ConfigurationOptions object was removed in v3 of this library. The Configuration object now just accepts an array of options -- check out the README for details.

discover59 commented 3 years ago

@jlevers What's the best way to use dynamic refresh token with same other information?

jlevers commented 3 years ago

I would store the static info in environment variables using something like vlucas/phpdotenv, and then load those environment variables into the Configuration constructor.

discover59 commented 3 years ago

Hmm, this is not comfortable compared to other libraries I used for MWS.

jlevers commented 3 years ago

MWS was a much simpler system than the SP API.

I originally set up this library to load config info from environment variables by default, but the very first issue someone opened (#1) was a request to leave the environment setup to the user. I thought that was a good point, so I've since changed the library to be more configurable, at the expense of requiring a little more setup for certain use cases.

Using this library with your your own env vars would require installing the package I linked, creating a .env file, and loading the variables in that file into a function or factory class that produces Configuration objects (a couple lines of code).

If you have suggestions for a different way this should work, I'm open to hearing them :)

discover59 commented 3 years ago

I am using .env already, but the case is for multiple sellers and I have to update refresh token and region in the loop of operation. I don't want to include other redundant variables in the loop. That's why I prefer the configuration object updatable by different setters.

https://github.com/clousale/amazon-sp-api-php

Above library does it.

jlevers commented 3 years ago

If something as simple as getters and setters for the configuration options would solve the issue you're having, I'm happy to make that change. I'll try to get that done in the next couple weeks.

jlevers commented 3 years ago

@discover59, those getters and setters have been added in v3.1.4.