mollie / mollie-api-python

Mollie API client for Python
http://www.mollie.com
BSD 2-Clause "Simplified" License
113 stars 55 forks source link

Enable `testmode` for OAuth/access-token clients globally #273

Closed whyscream closed 1 year ago

whyscream commented 1 year ago

In OAuth and access-token requests, you can specify testmode=true to perform API requests during the development phase. Currently this needs to be done on a per-request basis:

from mollie.api.client import Client
mollie_client = Client()
mollie_client.set_access_token("access_blah")

data = {
    "name": "Customer A",
    "email": "customer@example.org",
}
customer = mollie_client.customers.create(data, testmode="true")

Of course this quickly gets messy when your API requests are all over you application, and you need to adjust all of your code to enable/disable testmode for each call. We want to support enabling this on the client level, e.g:

from mollie.api.client import Client
mollie_client = Client()
mollie_client.set_access_token("access_blah")
mollie.client.set_testmode(True)   # or False

data = {
    "name": "Customer A",
    "email": "customer@example.org",
}
customer = mollie_client.customers.create(data)  # Now this will send the API request with testmode enabled