Skip to content

Commit

Permalink
Refined environment handling with setEnvironment(), `getUrlForErp()…
Browse files Browse the repository at this point in the history
…` and `getUrlForProvider()` to properly detect development and production environments.
  • Loading branch information
firebed committed Oct 12, 2024
1 parent abcfd74 commit d790b26
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/Http/MyDataRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,44 @@ public static function setHandler(?MockHandler $handler): void
self::$handler = HandlerStack::create($handler);
}

/**
* Initialize the myDATA API with the user_id, subscription_key and environment.
*
* @param string $user_id The user id provided by AADE
* @param string $subscription_key The subscription key provided by AADE
* @param string $env 'dev' or 'prod'
* @param bool $is_provider Set to true if the request is for the providers
* @return void
*/
public static function init(string $user_id, string $subscription_key, string $env, bool $is_provider = false): void
{
self::setCredentials($user_id, $subscription_key);
self::setEnvironment($env, $is_provider);
}

/**
* Set the user_id and subscription_key for the myDATA API.
*
* @param string $user_id The user id provided by AADE
* @param string $subscription_key The subscription key provided by AADE
* @return void
*/
public static function setCredentials(string $user_id, string $subscription_key): void
{
self::$user_id = $user_id;
self::$subscription_key = $subscription_key;
}

/**
* Set the environment to either 'dev' or 'prod'.
*
* @param string $env 'dev' or 'prod'
* @param bool $is_provider Set to true if the request is for the providers
* @return void
*/
public static function setEnvironment(string $env, bool $is_provider = false): void
{
self::$env = $env;
self::$env = strtolower($env);
self::$is_provider = $is_provider;
}

Expand Down Expand Up @@ -246,12 +269,12 @@ public function getUrl(): string

private function getUrlForErp(): string
{
return self::isDevelopment() ? self::DEV_ERP_URL : self::PROD_ERP_URL;
return self::isProduction() ? self::PROD_ERP_URL : self::DEV_ERP_URL;
}

private function getUrlForProvider(): string
{
return self::isDevelopment() ? self::DEV_PROVIDER_URL : self::PROD_PROVIDER_URL;
return self::isProduction() ? self::PROD_PROVIDER_URL : self::DEV_PROVIDER_URL;
}

private function getAction(): string
Expand Down

0 comments on commit d790b26

Please sign in to comment.