Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
# Conflicts:
#	WellnessLiving/Wl/Catalog/CatalogList/CatalogProductModel.php
#	WellnessLiving/Wl/Pay/Account/Charge/ChargeModel.php
#	WellnessLiving/Wl/Shop/Product/Option/Inventory/Count/InventoryCountModel.php
  • Loading branch information
Kasp42 committed Nov 20, 2024
2 parents 1764bdb + 82e5434 commit b71cab4
Show file tree
Hide file tree
Showing 316 changed files with 32,843 additions and 28,253 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
.idea
/vendor/
.idea
/vendor/
168 changes: 84 additions & 84 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,84 +1,84 @@
# WellnessLiving SDK

## Register your application in our system

To register your application, please contact WellnessLiving Support and provide the following information:

* The name of your application.
* Information about what your application does.

After registering, we'll send you the following information:

* The application ID
* The secret code (authorization code)
* An example staff member in staging
* Your staging business ID for testing

We'll also provide you with data to connect to our staging and production environments.
Unique application IDs and secret codes are required for both environments.

## Download

Our SDK can be downloaded at https://github.com/wellnessliving/wl-sdk.

You can also use this bash one-liner to install the SDK with composer:
```shell
([ ! -f composer.json ] && echo '{"name":"sdk/project"}' > composer.json); composer config repositories.wellnessliving/wl-sdk git https://github.com/wellnessliving/wl-sdk && composer require 'wellnessliving/wl-sdk:>=1.0.0' && composer install
```

## How to run example script

After the SDK has been downloaded, try to run the example script placed in the root directory of the WellnessLiving SDK.

To run the example script, perform the following actions:

1. Put your application ID and secret key in `example-config.php`.
2. Put your login/password of your example staff member in `example-sdk.php`.
3. Run the following command using your command-line interface:

php example-sdk.php

## Embed our SDK in your code

To work with our SDK in your code, you'll need the `WellnessLiving/` directory from the root directory of the WellnessLiving SDK.

You can remove example files from your project to suit your business needs.

We recommend using our autoloader that's included in our example:

require_once __DIR__.'/WellnessLiving/wl-autoloader.php';

## Moving to production

When you're ready to switch to the production environment, change your connection configuration class in your config file to inherit from
`\WellnessLiving\Config\WlConfigProduction`. By default, the connection configuration class inherits `\WellnessLiving\Config\WlConfigDeveloper`, which
points to the staging environment.

## Notes about our release process

We maintain three development branches:

* Trunk
* Staging
* Production

Trunk is where our Engineering Department develops new features. Most changes are made in the trunk.

For about two weeks before the release to production, staging is recreated from the trunk.
Staging is used by our QA Team to find bugs.
Also, we use staging to present our new features to our customers so that they can be sure new features work as
they expected before new features move to production.

### Versioning
The versioning scheme we use is based on [Semantic Versioning](https://semver.org), wherein version suffixes are added in accordance to [Composer's version stability protocols](https://getcomposer.org/doc/articles/versions.md#stabilities).
* Trunk (development) releases are tagged with only numbers, without any special suffix (for example, v1.0.4).
* Staging releases are tagged with `rc` suffix (for example, v1.0.3-rc).
* Production releases are tagged with `stable` suffix (for example, v1.0.0-stable).
If you're checking out a version with a specific suffix, changes in the API code are only available on the proper backend server (demo, stable, or production respectively) or a lower one (staging version is auto-merged into development, but not vice versa).

**Note:** Our API and SDK is subject to change at any time without notice.

Review changes in the SDK repository to determine if there are any incompatible changes.

You must also write integration tests to be sure that your application is fully compatible with
our new version of SDK and staging.
# WellnessLiving SDK

## Register your application in our system

To register your application, please contact WellnessLiving Support and provide the following information:

* The name of your application.
* Information about what your application does.

After registering, we'll send you the following information:

* The application ID
* The secret code (authorization code)
* An example staff member in staging
* Your staging business ID for testing

We'll also provide you with data to connect to our staging and production environments.
Unique application IDs and secret codes are required for both environments.

## Download

Our SDK can be downloaded at https://github.com/wellnessliving/wl-sdk.

You can also use this bash one-liner to install the SDK with composer:
```shell
([ ! -f composer.json ] && echo '{"name":"sdk/project"}' > composer.json); composer config repositories.wellnessliving/wl-sdk git https://github.com/wellnessliving/wl-sdk && composer require 'wellnessliving/wl-sdk:>=1.0.0' && composer install
```

## How to run example script

After the SDK has been downloaded, try to run the example script placed in the root directory of the WellnessLiving SDK.

To run the example script, perform the following actions:

1. Put your application ID and secret key in `example-config.php`.
2. Put your login/password of your example staff member in `example-sdk.php`.
3. Run the following command using your command-line interface:

php example-sdk.php

## Embed our SDK in your code

To work with our SDK in your code, you'll need the `WellnessLiving/` directory from the root directory of the WellnessLiving SDK.

You can remove example files from your project to suit your business needs.

We recommend using our autoloader that's included in our example:

require_once __DIR__.'/WellnessLiving/wl-autoloader.php';

## Moving to production

When you're ready to switch to the production environment, change your connection configuration class in your config file to inherit from
`\WellnessLiving\Config\WlConfigProduction`. By default, the connection configuration class inherits `\WellnessLiving\Config\WlConfigDeveloper`, which
points to the staging environment.

## Notes about our release process

We maintain three development branches:

* Trunk
* Staging
* Production

Trunk is where our Engineering Department develops new features. Most changes are made in the trunk.

For about two weeks before the release to production, staging is recreated from the trunk.
Staging is used by our QA Team to find bugs.
Also, we use staging to present our new features to our customers so that they can be sure new features work as
they expected before new features move to production.

### Versioning
The versioning scheme we use is based on [Semantic Versioning](https://semver.org), wherein version suffixes are added in accordance to [Composer's version stability protocols](https://getcomposer.org/doc/articles/versions.md#stabilities).
* Trunk (development) releases are tagged with only numbers, without any special suffix (for example, v1.0.4).
* Staging releases are tagged with `rc` suffix (for example, v1.0.3-rc).
* Production releases are tagged with `stable` suffix (for example, v1.0.0-stable).
If you're checking out a version with a specific suffix, changes in the API code are only available on the proper backend server (demo, stable, or production respectively) or a lower one (staging version is auto-merged into development, but not vice versa).

**Note:** Our API and SDK is subject to change at any time without notice.

Review changes in the SDK repository to determine if there are any incompatible changes.

You must also write integration tests to be sure that your application is fully compatible with
our new version of SDK and staging.
118 changes: 118 additions & 0 deletions WellnessLiving/Config/WlConfigAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use WellnessLiving\Wl\WlRegionSid;
use WellnessLiving\WlAssertException;
use WellnessLiving\WlTool;

/**
* Contains WellnessLiving SDK configuration.
Expand Down Expand Up @@ -321,6 +322,123 @@ final public function csrfCode($s_session_key)
return hash('sha3-512',$s_session_key.'::'.$this::AUTHORIZE_CODE.'::'.$t_time).'.'.$t_time.'.'.substr($s_session_key,0,5);
}

/**
* Gets the local host name.
*
* @return string The local host name.
*/
public function hostname()
{
if(!array_key_exists('HTTP_HOST',$_SERVER))
return 'localhost';

return $_SERVER['HTTP_HOST'];
}

/**
* Retrieves the raw content of the HTTP request body.
*
* ## PHP 5.5 and 5.6 compatibility notes
*
* In PHP 5.5 and before, there was not possible to make multiple reads from `php://input` stream.
* And, this method requires reading from this stream.
* If you use PHP 5.5, this will interfere with your application which also needs to read from this stream.
* Please, override this method in your configuration subclass to provide a method to read the entire HTTP request body.
*
* Note that there are messages that `php://input` was not reusable in PHP 5.6 either. See links below for details.
*
* You may also need to override this method if `always_populate_raw_post_data` is disabled.
*
* Feel free to override it in other cases when this default implementation does not work well for you.
*
* @return string|null The raw body content of the POST request. `null` if the POST request body is empty.
* @link https://stackoverflow.com/questions/31762278/how-the-php-input-was-made-reusable-in-5-6 It seems they have removed the notice from their official documentation about that `php://input` was not reusable in PHP 5.5.
* @link https://stackoverflow.com/questions/35361763/php-input-can-only-be-read-once-in-php-5-6-16 Messages that it was not working for someone in PHP 5.6.
* @link https://www.php.net/manual/en/migration56.new-features.php#migration56.new-features.reusable-input PHP 5.6 migration notes: php://input is reusable
*/
public static function postRawData()
{
if(version_compare(PHP_VERSION,'5.6.0')<0)
{
$s_always_populate_raw_post_data = ini_get('always_populate_raw_post_data');
$is_always_populate_raw_post_data =
$s_always_populate_raw_post_data &&
$s_always_populate_raw_post_data!=-1
;

if(!$is_always_populate_raw_post_data)
{
trigger_error(
"The 'always_populate_raw_post_data' option disabled. ".
"You must enable the 'always_populate_raw_post_data' option or override this method.",
E_USER_ERROR
);

/**
* User code may ignore errors that are caused through {@link \trigger_error()}.
* Therefore we return `null`.
*
* @noinspection PhpUnreachableStatementInspection
*/
return null;
}

if(!array_key_exists('HTTP_RAW_POST_DATA',$GLOBALS))
{
trigger_error("The 'HTTP_RAW_POST_DATA' global variable is not available.", E_USER_ERROR);

/**
* User code may ignore errors that are caused through {@link \trigger_error()}.
* Therefore we return `null`.
*
* @noinspection PhpUnreachableStatementInspection
*/
return null;
}

return $GLOBALS['HTTP_RAW_POST_DATA'];
}

$a_header = WlTool::getAllHeaders();
if(!array_key_exists('Content-Type',$a_header))
{
trigger_error("The 'Content-Type' header is missing: \n".var_export($a_header,true),E_USER_ERROR);

/**
* User code may ignore errors that are caused through {@link \trigger_error()}.
* Therefore we return `null`.
*
* @noinspection PhpUnreachableStatementInspection
*/
return null;
}

if(
ini_get('enable_post_data_reading') &&
(
$a_header['Content-Type']==='multipart/form-data' ||
strncmp($a_header['Content-Type'],'multipart/form-data;',20)==0
)
)
{
trigger_error("Cannot read POST request data with content type 'multipart/form-data': \n".var_export($a_header,true),E_USER_ERROR);

/**
* User code may ignore errors that are caused through {@link \trigger_error()}.
* Therefore we return `null`.
*
* @noinspection PhpUnreachableStatementInspection
*/
return null;
}

$s_post_raw = file_get_contents('php://input');
if(!$s_post_raw)
return null;

return $s_post_raw;
}

/**
* Returns URL of the server in the current configuration (including trailing slash).
*
Expand Down
Loading

0 comments on commit b71cab4

Please sign in to comment.