diff --git a/README.md b/README.md index 4dc28bf..e4a753f 100644 --- a/README.md +++ b/README.md @@ -40,8 +40,12 @@ API: | Segments | +Events +| Promotions | +Async Actions +| Utils

@@ -529,6 +533,18 @@ $client->segments->get($segment_id); $client->segments->delete($segment_id); ``` +--- +### Events API +Methods are provided within `$client->customEvents->*` namespace. +- [Track Custom Event](#track-custom-event) + +Check [event object](https://docs.voucherify.io/reference/the-custom-event-object?utm_source=github&utm_medium=sdk&utm_campaign=acq). + +#### [Track Custom Event] +```php +$client->customEvent->track($event, $customer); +``` + --- ### Promotions API @@ -587,6 +603,8 @@ $client->promotions->tiers->delete($promotionTierId); $client->promotions->tiers->getAvailable(); ``` +--- + ### Async Actions API Methods are provided within `$client->asyncActions->*` namespace. - [Get Async Action](#get-async-action) @@ -747,6 +765,7 @@ class Voucher extends CI_Controller { Bug reports and pull requests are welcome through [GitHub Issues](https://github.com/rspective/voucherify-php-sdk/issues). ### Changelog +- **2022-05-16** - `2.2.0` - Add CustomEvents support - **2022-03-11** - `2.1.0` - Add AsyncActions support and a `$customHeaders` param - **2019-07-19** - `2.0.0` - Hide API versioning in `$apiUrl` param - **2018-12-28** - `1.7.10` - Add Validation Rule Assignments @@ -869,3 +888,5 @@ Bug reports and pull requests are welcome through [GitHub Issues](https://github [Update Promotion's Tier]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#update-promotion [Delete Promotion's Tier]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#delete-promotion [List Available Promotion Tiers]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#introduction-1 + +[Track Custom Event]: https://docs.voucherify.io/reference/create-custom-event?utm_source=github&utm_medium=sdk&utm_campaign=acq \ No newline at end of file diff --git a/src/CustomEvents.php b/src/CustomEvents.php index 99b40e7..93ccd40 100644 --- a/src/CustomEvents.php +++ b/src/CustomEvents.php @@ -32,22 +32,22 @@ public function __construct($client) public function track($event, $customer, $metadata = null, $referral = null, $loyalty = null) { $params = [ - 'event' => $event, - 'customer' => $customer, + "event" => $event, + "customer" => $customer ]; if ($metadata) { - $params['metadata'] = (object)$metadata; + $params["metadata"] = (object)$metadata; } if ($referral) { - $params['referral'] = (object)$referral; + $params["referral"] = (object)$referral; } if ($loyalty) { - $params['loyalty'] = (object)$loyalty; + $params["loyalty"] = (object)$loyalty; } - return $this->client->post("/events", $params); + return $this->client->post("/events/", $params); } } diff --git a/test/AsyncActionsTest.php b/test/AsyncActionsTest.php index e6e290d..889acd8 100644 --- a/test/AsyncActionsTest.php +++ b/test/AsyncActionsTest.php @@ -17,10 +17,10 @@ public static function setUpBeforeClass() self::$apiId = "c70a6f00-cf91-4756-9df5-47628850002b"; self::$apiKey = "3266b9f8-e246-4f79-bdf0-833929b1380c"; self::$headers = [ - "Content-Type: application/json", - "X-App-Id: " . self::$apiId, - "X-App-Token: " . self::$apiKey, - "X-Voucherify-Channel: PHP-SDK" + "content-type: application/json", + "x-app-id: " . self::$apiId, + "x-app-token: " . self::$apiKey, + "x-voucherify-channel: PHP-SDK" ]; self::$client = new VoucherifyClient(self::$apiId, self::$apiKey); diff --git a/test/CustomEventsTest.php b/test/CustomEventsTest.php new file mode 100644 index 0000000..1beeddf --- /dev/null +++ b/test/CustomEventsTest.php @@ -0,0 +1,54 @@ +post("/events/", [ + "event" => "php-event", + "customer" => [ + "source_id" => "php-test-customer" + ] + ]) + ->reply(200, [ "status" => "ok" ]); + + $result = self::$client->customEvents->track("php-event", (object)[ + "source_id" => "php-test-customer" + ]); + + $this->assertEquals($result, (object)[ "status" => "ok" ]); + + CurlMock::done(); + } +}