Skip to content

Commit

Permalink
Merge pull request #77 from voucherifyio/aw/async-actions
Browse files Browse the repository at this point in the history
Support for Async Actions
  • Loading branch information
mandraszyk authored Mar 11, 2022
2 parents 066beab + a3e695e commit b8b8608
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 1 deletion.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,21 @@ $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)
- [List Async Actions](#list-async-actions)

#### [Get Async Action]
```php
$client->asyncActions->get($id);
```
#### [List Async Actions]
```php
$client->asyncActions->getList();
$client->asyncActions->getList($params);
```

---

### Utils
Expand Down Expand Up @@ -744,7 +759,8 @@ Bug reports and pull requests are welcome through [GitHub Issues](https://github
- Voucher informations: *get*, *redemption*
- Voucher operations: *redeem*


[Get Async Action]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#get-async-actions-1
[List Async Actions]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#list-async-actions

[Create Voucher]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#create-voucher
[Get Voucher]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#vouchers-get
Expand Down
46 changes: 46 additions & 0 deletions src/AsyncActions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Voucherify;

class AsyncActions
{
/**
* @var \Voucherify\ApiClient
*/
private $client;

/**
* @param \Voucherify\ApiClient $client
*/
public function __construct($client)
{
$this->client = $client;
}

/**
* @param string $id
*
* Get Async Action details.
*
* @throws \Voucherify\ClientException
*/
public function get($id)
{
return $this->client->get("/async-actions/" . rawurlencode($id), null);
}

/**
* @param array|stdClass $filter
*
* Get a filtered list of Async Actions. The filter can include following properties:
* - limit - number
* - end_date - date in iso format
*
* @throws \Voucherify\ClientException
*/
public function getList($filter = null)
{
return $this->client->get("/async-actions/", $filter);
}

}
6 changes: 6 additions & 0 deletions src/VoucherifyClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ class VoucherifyClient
*/
public $vouchers;

/**
* @var \Voucherify\AsyncActions
*/
public $asyncActions;

/**
* @param string $apiId
* @param string $apiKey
Expand Down Expand Up @@ -99,6 +104,7 @@ public function __construct($apiId, $apiKey, $apiVersion = null, $apiUrl = null)
]);
$this->validationRules = new ValidationRules($this->client);
$this->vouchers = new Vouchers($this->client);
$this->asyncActions = new AsyncActions($this->client);

/* ********* BACKWARD COMPATIBILITY ********* */

Expand Down
75 changes: 75 additions & 0 deletions test/AsyncActionsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

use Voucherify\Test\Helpers\CurlMock;

use Voucherify\VoucherifyClient;
use Voucherify\ClientException;

class AsyncActionsTest extends PHPUnit_Framework_TestCase
{
protected static $headers;
protected static $apiId;
protected static $apiKey;
protected static $client;

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"
];
self::$client = new VoucherifyClient(self::$apiId, self::$apiKey);

CurlMock::enable();
}

public static function tearDownAfterClass()
{
CurlMock::disable();
}

public function testGet()
{
CurlMock::register("https://api.voucherify.io/v1", self::$headers)
->get("/async-actions/test-id")
->reply(200, [ "status" => "ok" ]);

$result = self::$client->asyncActions->get("test-id");

$this->assertEquals($result, (object)[ "status" => "ok" ]);

CurlMock::done();
}

public function testGetList()
{
CurlMock::register("https://api.voucherify.io/v1", self::$headers)
->get("/async-actions/")
->reply(200, [ "status" => "ok" ]);

$result = self::$client->asyncActions->getList();

$this->assertEquals($result, (object)[ "status" => "ok" ]);

CurlMock::done();
}

public function testGetListByQuery()
{
CurlMock::register("https://api.voucherify.io/v1", self::$headers)
->get("/async-actions/")
->query([ "limit" => 5, "end_date" => "2021-07-16T15:12:43Z" ])
->reply(200, [ "status" => "ok" ]);

$result = self::$client->asyncActions->getList([ "limit" => 5, "end_date" => "2021-07-16T15:12:43Z" ]);

$this->assertEquals($result, (object)[ "status" => "ok" ]);

CurlMock::done();
}

}

0 comments on commit b8b8608

Please sign in to comment.