BillingBase
in package
Base abstract class implementing shared functions of API and ESPF
Tags
Table of Contents
- DATETIME_FORMAT = 'Y-m-d H:i:s'
- Billing API datetime format
- __construct() : mixed
- Setup the class, load (if any) saved session state and get it ready to use
- checkSession() : void
- Does active sesson check to billing server, relogin if required
- getUsername() : string|null
- Return current user login name
- isSessionPresent() : bool
- Returns true if session data exit and not expired
- login() : void
- Do login and setup the session.
- logout() : void
- Closes the session explicitly.
- timeToBilling() : string
- Return billing API string at UTC fro given Datetime object
- timeToLocal() : DateTime
- Convert billing-supplied UTC time string to DateTime object with target timezone
Constants
DATETIME_FORMAT
Billing API datetime format
public
mixed
DATETIME_FORMAT
= 'Y-m-d H:i:s'
Methods
__construct()
Setup the class, load (if any) saved session state and get it ready to use
public
__construct(ConfigInterface $config) : mixed
On construct:
- Check the cached session token expire time within margin or left
- If token expire soon (within configured margin), try to refresh token
- If token expired or refresh failed - try to relogin if account data present, throwing exceptions on failures.
- If no accoount data present, just left the class un-logged-in, then you need login() to get it connected
Parameters
- $config : ConfigInterface
-
Configuration object to run
Return values
mixed —checkSession()
Does active sesson check to billing server, relogin if required
public
checkSession() : void
Completes 'Session/ping' call to check session state, then:
- If session not recognised, and credentials present, trying to relogin
- If no credentials in config or login failure - throws auth exception
Tags
Return values
void —getUsername()
Return current user login name
public
getUsername() : string|null
Returns username taken from access token or null if no session is up
Return values
string|null —isSessionPresent()
Returns true if session data exit and not expired
public
isSessionPresent() : bool
Returns true if session data (token) exists and not expired, false if not logged in for any reason.
Does not complete active sesion check to the server. Due of serveer configuratioin issues token may be invalidated for inactivity before it's expire time really has come. So, positive isSessionUp() only means persistent session data loaded,
Return values
bool —login()
Do login and setup the session.
public
login(array<string|int, mixed> $account) : void
The session data will be stored if session storage class is supplied
Parameters
- $account : array<string|int, mixed>
-
Account record to login to the billing. Combination of login+password or login+token required
$account = [ 'login' => 'myUserName', // Mandatory username 'password' => 'myPassword', // When login with password 'token' => 'myToken' // When login with API token
Tags
Return values
void —logout()
Closes the session explicitly.
public
logout() : void
Will call '/Session/logout' api method. Due of some problems with Portaone resposes, session will considered closed whatever server respond. No server error will be respected, but conenction errors will thrown.
Tags
Return values
void —timeToBilling()
Return billing API string at UTC fro given Datetime object
public
static timeToBilling(DateTimeInterface $time) : string
The DateTime obhject given will not change.
Parameters
- $time : DateTimeInterface
-
Datetime object to take time from
Return values
string —Billing API-type datetime string, shifted to UTC
timeToLocal()
Convert billing-supplied UTC time string to DateTime object with target timezone
public
static timeToLocal(string $billingTime[, string $timezone = 'UTC' ]) : DateTime
Parameters
- $billingTime : string
-
- datetime string as billing returns
- $timezone : string = 'UTC'
-
- timezone string like 'Europe/London" or '+3000', as defined at https://www.php.net/manual/en/datetimezone.construct.php