Download the PHP package digitsrl/php-wom-connector without Composer
On this page you can find all versions of the php package digitsrl/php-wom-connector. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download digitsrl/php-wom-connector
More information about digitsrl/php-wom-connector
Files in digitsrl/php-wom-connector
Package php-wom-connector
Short Description A PHP connector library for the WOM Platform, that allows clients to develop custom Instruments (WOM sources) and Merchants (WOM consumers).
License MIT
Homepage https://wom.social
Informations about the package php-wom-connector
PHP Connector for the WOM Platform
Setup
Installation of the PHP WOM Connector is only a Composer command away:
This will automatically install all packages required by the Connector and check compatibility with your setup.
Configuration
Check out /test/example_instrument.php
, /test/example_pos.php
, and /test/example_check.php
files for samples of how to use the connector.
It is suggested to set the default timezone to UTC before using the Connector.
By default, the WOM Connector sets up an internal logger that writes informative messages to STDERR
, but you can customize the logging handlers using the Initialize
method (which takes a single handler or an array of Monolog handlers):
WOM vouchers can be generated on different domains, with different (and custom) Registry installations.
By default, the Connector picks the standard Registry, which lives on the official wom.social
domain.
You can customize this using the following configuration line:
When developing your new WOM Platform integration, it can be useful to test on the development domain dev.wom.social
(contact the WOM development team about this).
The POS/Instrument keys and IDs that are used in the test scripts can be freely used on the development domain.
Voucher generation
The process of generating WOMs is pretty straightforward. You just need to be sure to comply with the requirements of the Platform and be registered as a WOM "Instrument".
The very first step is to import the connector library, including the autoload script generated by Composer.
Creating an Instrument
To generate WOMs you need to instantiate an Instrument.
To do that, you will need the Id and the Private Key associated with your Instrument.
Note that the second parameter contains the path to the key file (.pem
).
Note: if your key is password-protected, you can optionally pass the password along with the other parameters. Otherwise, pass in NULL
or an empty string.
Generating voucher specifications
To request WOMs you need to specify what kind of information you need them to contain. Since multiple vouchers can be requested at once, you need to instantiate an array of voucher specifications.
In this case, we populate the array with just one type of voucher:
In case you need many identical vouchers you can specify their quantity with the additional parameter count
:
Here we are asking for 100 WOM vouchers.
Perform the request
You are almost done! You just need to actually request the vouchers. If the request is successful the server response will contain the OTC and the Password which you should present to your users in order to allow them to redeem the WOMs they earned.
The full example is in example_instrument.php
.
Payment request generation
The process of generating payments for the WOM Platform is very similar to the voucher generation process: please follow the same setup and autoload steps.
Creating a Point of Service
Just like when instantiating Instruments, you can instantiate your POS by providing its Id and its Private Key:
Note: just like above, the private key parameter contains the path to the key file. Also, even if POS and Instrument belong to the same entity, they will have different IDs and keys.
Generating a payment filter
To obtain a payment request you usually only need to specify the amount of WOMs to be paid. However, you may also specify a filter that will be used to select which WOM vouchers are valid for payment and which are not.
Providing a payment filter makes you able to choose which kind of vouchers can be used to pay your services. Filters can be comprised of one or more of the following elements:
- Maximum age: the maximum amount of days between now and when the vouchers were generated. Vouchers that are older than the set amount of days will not be accepted.
- Geographical region: a geogrphical (rectangular) bounding box. Only vouchers earned within the specified area are allowed (notice that the region is specified as a couple of coordinates, top left and bottom right, both of which are expressed as an array of numbers, latitude and then longitude).
- Aim: setting an aim code filters out vouchers that volunteers earned by contributing to other public aims. Note that aim codes are hierarchical, so filtering on ‘H’ will accept any voucher with an aim starting with the same letter (for instance ‘HE’).
All parameters are optional:
In case you want to accept any kind of vouchers as a payment, you still need to provide an empty filter:
Generating the request
You are just a method invocation away from generating a proper payment request.
Just call the RequestVouchers
method as shown below:
The full example is in example_pos.php
.
All versions of php-wom-connector with dependencies
ext-openssl Version *
php Version >=7.0
guzzlehttp/guzzle Version ^6.5
ramsey/uuid Version ^3.9
monolog/monolog Version ^1.16
phpseclib/phpseclib Version ^2.0