Introducing Omise\Omise class to manage all credential setting & retrieving
1. Objective
This is the very first part of refactoring for a better organizing constants and variables in Omise-PHP.
While define('OMISE_SECRET_KEY', '') works just fine, it's causing an 'immutable' variable problem.
As it reflects at all of resource classes that, Omise-PHP allows for on-the-fly ket setting (i.e. OmiseAccount::retrieve('', 'new_pkey', 'new_skey')).
If Omise-PHP will eventually allow user to alter the credential, then it at least, should not be set with an immutable constant variable but something that user can properly call to set a new credential, right?
Omise\Omise class provides useful static methods to organize all necessary variables that can be used across the entire library.
This class may, in the future, provide some sort of Omise\Omise::setClient(OmiseClientInterface new OmiseTestClient); to improve the test ability as well.
2. Description of change
-
Introducing a new class,
Omise\Omise, to organize all necessary variables that can be used across the entire library. -
Removing the ability to set a new credential (aka. public key and secret key) on-the-fly from all resource classes (OmiseAccount, OmiseBalance, OmiseCharge, and so on).
Now you can set Omise credential with the following code:
\Omise\Omise::setPublicKey('pkey_test_5fcnkn4378pmguq5zpy');
\Omise\Omise::setSecretKey('skey_test_5fduue09qa7iantplkd');
\Omise\Omise::setApiVersion('2019-05-29');
\Omise\Omise::setUserAgent('CustomUserAgent/1.0');
$account = \Omise\Account::retrieve(); // or OmiseAccount::retrieve(); if you prefer without namespace.
3. Quality assurance
Use https://github.com/guzzilar/omise-php-examples repository to test all possible cases. All code works as expected. Such as
- Retrieve
- Reload
- Create
- Update
- Delete
- Schedule
- Search
etc.
4. Impact of the change
It's a breaking-change for all developers that are assigning Omise keys on-the-fly by passing the credential through Omise resource classes. For example:
define('OMISE_PUBLIC_KEY', 'current_pkey_from_account_a');
define('OMISE_SECRET_KEY', 'current_skey_from_account_a');
$account = OmiseAccount::retrieve('new_pkey_from_account_b', 'new_skey_from_account_b');
This would no longer work as this approach removes those $publickey, $secretkey out from all resource classes.
However, these code will still work just fine.
define('OMISE_PUBLIC_KEY', 'current_pkey_from_account_a');
define('OMISE_SECRET_KEY', 'current_skey_from_account_a');
define('OMISE_API_VERSION', '2019-**-**');
define('OMISE_USER_AGENT_SUFFIX', 'CustomUserAgent/1.0');
For all of those developers who have implemented with the previous define approach, this way works as normal (backward compatibility).
5. Priority of change
Normal, but this PR should be merged before the release v3.0.0-rc1.
6. Additional Notes
All inputs are always welcome.