silverback / iubenda-consent-solution
Iubenda Consent Solution HTTP API 的 PHP 客户端
1.0.0
2018-07-24 10:06 UTC
Requires
- php: >=5.6
- guzzlehttp/guzzle: ^6.3
- psr/log: ^1.0
Requires (Dev)
- phpunit/phpunit: ^6.5
- squizlabs/php_codesniffer: 3.*
This package is auto-updated.
Last update: 2024-08-26 21:35:17 UTC
README
安装
使用 Composer 在 Yii 项目根目录中安装此包。
composer require silverback/iubenda-consent-solution
使用方法
创建新的同意
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' => '<form><input type="text" name="first_name">[...]</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(); }
测试
此类使用 PHPUnit 作为测试套件,测试类和函数时请遵循以下步骤。
将文件 phpunit.xml.dist
复制到库文件夹中的 phpunit.xml
,并在其中定义 Api-Key 和地址
<php> <const name="CONSENT_SOLUTION_API_KEY" value="foobar"/> <const name="CONSENT_SOLUTION_TEST_CONSENT" value="foobar"/> <const name="CONSENT_SOLUTION_TEST_SUBJECT" value="foobar"/> ... </php>
运行 composer update
命令以安装所有依赖项和测试套件。
使用以下命令运行测试
./vendor/bin/phpunit tests/ # all tests ./vendor/bin/phpunit tests/ClientTest # single test