https://github.com/silverbackstudio/php-iubenda-consent-solution
PHP client for Iubenda Consent Solution HTTP API
https://github.com/silverbackstudio/php-iubenda-consent-solution
Last synced: about 1 year ago
JSON representation
PHP client for Iubenda Consent Solution HTTP API
- Host: GitHub
- URL: https://github.com/silverbackstudio/php-iubenda-consent-solution
- Owner: silverbackstudio
- Created: 2018-07-23T07:19:52.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2021-12-01T16:34:59.000Z (over 4 years ago)
- Last Synced: 2024-11-22T02:01:29.392Z (over 1 year ago)
- Language: PHP
- Size: 7.81 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Iubenda Consent Solution PHP client library
## Installation
Install this package in Yii project root with [Composer](https://getcomposer.org/).
`composer require silverback/iubenda-consent-solution`
## Usage
### Create a new consent
```php
use Iubenda\ConsentSolution\Client;
use Iubenda\ConsentSolution\Consent;
$consentSolution = new ConsentSolution\Client( 'your-private-api-key' );
$consent = new ConsentSolution\Consent;
$user_id = 10;
$consent->setSubject(
[
'id' => sha1( 'my_application_' . $user_id ), // you can omit this field
'email' => 'user@example.com',
'first_name' => 'John',
'last_name' => 'Doe',
'full_name' => 'John Doe',
'verified' => false
]
);
$consent->addLegalNotice( [ 'identifier' => 'privacy_policy' ] );
$consent->addProof( [
'content' => json_encode( [
'first_name' => 'John',
'last_name' => 'Doe',
// other useful form fields
] ),
'form' => '[...]',
] );
$consent->preferences['privacy_policy'] = true;
$consent->preferences['third_party'] = false;
$consent->preferences['newsletter'] = true;
try {
$saved_consent = $consentSolution->createConsent( $consent );
echo "Successfully saved consent: " . $saved_consent->id;
} catch (\Exception $e) {
echo "An error occurred: " . $e->getMessage();
}
```
## Testing
This class uses [PHPUnit](https://phpunit.de/) as test suite, to test the classes and functions follow this steps.
Copy the file `phpunit.xml.dist` in `phpunit.xml` in the library folder and define Api-Key and addresses inside it:
```xml
...
```
Launch a `composer update` to install all the dependencies and test suite.
Run the test with the following commands
```bash
./vendor/bin/phpunit tests/ # all tests
./vendor/bin/phpunit tests/ClientTest # single test
```