be-lenka / exponea-api
Exponea API 的 PHP SDK
1.0.3
2023-12-12 08:03 UTC
Requires
- php: ^7.4 || ^8.0
- ext-json: *
- guzzlehttp/guzzle: ^6.3 || ^7.0
Requires (Dev)
- dealerdirect/phpcodesniffer-composer-installer: ^0.7.2
- phpspec/prophecy: ^1.8
- phpstan/phpstan: ^1.0
- phpunit/phpunit: ^9.5
- sirbrillig/phpcs-variable-analysis: ^2.6
- squizlabs/php_codesniffer: ^3.4
This package is auto-updated.
Last update: 2024-09-11 07:23:13 UTC
README
库仅包含用于 Exponea 集成的必要基本功能。如果您缺少某些方法,请提交合并请求,因为我们的集成不需要它们。
整个库使用异步 Guzzle 请求。请注意,必须使用 wait() 调用每个方法返回的每个 Promise 才能执行。
Exponea API 使用公钥和私钥授权,因此您需要获取 3 个值来发出有效请求
- 公钥
- 私钥
- 项目令牌
Exponea API 参考:https://documentation.bloomreach.com/engagement/reference/welcome
使用示例
请检查以下实现 API 初始化和 getSystemTime() 方法的源代码
使用方法
use belenka\ExponeaApi\Client; $client = new Client([ 'public_key' => getenv('EXPONEA_PUBLIC_KEY'), 'private_key' => getenv('EXPONEA_PRIVATE_KEY'), 'project_token' => getenv('EXPONEA_PROJECT_TOKEN'), ]); try { $systemTime = $client->tracking()->getSystemTime()->wait(); // returns SystemTime object } catch (...) { ... }
跟踪 API
所有方法都包含在 $client->tracking()
方法中。
设置联系协议(同意)
在 Exponea 中,电子邮件和 SMS 协议都称为 consents。它们可以被授予或撤销。
$event = new Consent( new RegisteredCustomer('example@example.com'), Consent::CATEGORY_NEWSLETTER, Consent::ACTION_GRANT ); try { $client->tracking()->addEvent($event)->wait(); // does not return anything } catch (...) { ... }
发送购买
Exponea 需要您发送至少两个事件:购买和 PurchaseItem(每个购买项一个)。
$purchase = new Purchase( new RegisteredCustomer('example@example.com'), 'PREFIX12345', // purchase id [ new Item('012345', 2.99, 1), ], // purchase items 'COD' // payment method ); $purchaseItem = new PurchaseItem( new RegisteredCustomer('example@example.com'), 'PREFIX12345', // purchase id '012345', // item id 2.99, // price 2, // quantity 'SKU012345', // sku (stock keeping unit) 'Product name', new Category('CAT1', 'Some > Category > Breadcrumb') );
您可以选择发送在购买过程中使用的代金券。请参阅 Purchase
构造函数的 $voucher
参数。
更新客户属性
try { $properties = [ 'fidelity_points' => 657, 'first_name' => 'Marian', ]; $client->tracking()->updateCustomerProperties( new RegisteredCustomer('marian@exponea.com'), $properties )->wait(); } catch (...) { ... }
使用此方法可以更新客户属性。属性中的必填字段是 'first_name'。
目录 API
所有方法都包含在 $client->catalog()
方法中。
获取目录名称
try { $catalog = new Catalog('<exponea_catalog_id>'); $response = $this->client ->catalog() ->getCatalogName($catalog) ->wait() ; } catch (...) { ... }
获取目录项目
try { $catalog = new Catalog('<exponea_catalog_id>'); $catalog->setQueryParameters([ 'query' => 1, 'field' => 'item_id', 'count' => 1 ]); $response = $this->client ->catalog() ->getCatalogItems($catalog) ->wait() ; } catch (...) { ... }
通过 ID 获取目录项目
try { $catalog = new Catalog('<exponea_catalog_id>'); $catalog->setItemID(1); $response = $this->client ->catalog() ->getCatalogItem($catalog) ->wait() ; } catch (...) { ... }
创建目录项目
try { $catalogItem = new CatalogItem(1, '<exponea_catalog_id>'); $catalogItem->setProperties([ 'code' => 'product_code', 'active' => false, 'title' => 'product title' // etc ... ]); $response = $this->client ->catalog() ->createCatalogItem($catalogItem) ->wait() ; } catch (...) { ... }
更新目录项目
try { $catalogItem = new CatalogItem(1, '<exponea_catalog_id>'); $catalogItem->setProperties([ 'title' => 'new product title' // etc ... ]); $response = $this->client ->catalog() ->updateCatalogItem($catalogItem) ->wait() ; } catch (...) { ... }