Skip to content

Commit

Permalink
Merge pull request #75 from ostdotcom/develop
Browse files Browse the repository at this point in the history
Redemptions API.
  • Loading branch information
kedarchandrayan authored Mar 4, 2020
2 parents 3c4a825 + d19a5d8 commit 4831470
Show file tree
Hide file tree
Showing 12 changed files with 339 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ OST_KIT_RECOVERY_OWNER_ADDRESS=RecoveryOwnerAddressOfUser
OST_KIT_SESSION_ADDRESS=SessionAddressOfUser
OST_KIT_RULE_ADDRESS=AddressForExecutingRule
OST_KIT_USER2_TOKEN_HOLDER_ADDRESS=TokenHolderAddressForReceiver
OST_KIT_TRANSACTION_ID=TransactionIdUsedToTestGet
OST_KIT_TRANSACTION_ID=TransactionIdUsedToTestGet
OST_KIT_REDEMPTION_ID=RedemptionIdUsedToTestGet
OST_KIT_REDEEMABLE_SKU_ID=RedeemableSkuIdUsedToTestGet
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
env:
- BUILD_ENV=TRAVIS
before_install:
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[OST PHP SDK v2.2.3](https://github.com/ostdotcom/ost-sdk-php/tree/v2.2.3)
---

* Added redemptions module to call redemptions management OST APIs.
* Added redeemable sku module to call redeemable sku management OST APIs.

[OST PHP SDK v2.2.2](https://github.com/ostdotcom/ost-sdk-php/tree/v2.2.2)
---

Expand Down
106 changes: 106 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -807,3 +807,109 @@ For executing transactions, you need to understand the 4 modules described below
$response = $webhooksService->verifySignature($params);
echo json_encode($response, JSON_PRETTY_PRINT);
```


### Redemption Modules

Two modules of redemption, "Redeemable SKUs" and "User Redemptions", are described below.

#### Redeemable SKUs Module

* Initialize Redeemable SKUs service object to perform redeemable skus specific actions.

```php
$redeemableSkusService = $ostObj->services->redeemableSkus;
```

* Get Redeemable SKU detail using the redeemable sku id.

```php
// Mandatory API parameters

// Fetch details of following redeemable sku.
$redeemableSkuId = '1';

$getParams = array();
$getParams['redeemable_sku_id'] = $redeemableSkuId;
$response = $redeemableSkusService->get($getParams)->wait();
echo json_encode($response, JSON_PRETTY_PRINT);
```

* Get Redeemable SKUs List. Pagination is supported by this API.

```php
// Mandatory API parameters
// NOTE: No mandatory parameters.

// Optional API parameters

// Limit.
$limit = 10;

// Array of redeemable SKU ids.
$redeemableSkuIds = array('1', '2');

// Pagination identifier from the previous API call response. Not needed for page one.
$paginationIdentifier = 'eyJsY___';

$getParams = array();
$getParams['redeemable_sku_ids'] = $redeemableSkuIds;
$getParams['limit'] = $limit;
$getParams['pagination_identifier'] = $paginationIdentifier;

$response = $redeemableSkusService->getList($getParams)->wait();
echo json_encode($response, JSON_PRETTY_PRINT);
```

#### User Redemptions Module

* Initialize Redemptions service object to perform user redemption specific actions.

```php
$redemptionsService = $ostObj->services->redemptions;
```

* Get User redemption details using the userId and redemptionId.

```php
// Mandatory API parameters

// UserId of user for whom redemption details needs to be fetched.
$userId = 'ee8___';

// Unique identifier of the redemption of user.
$redemptionId = 'aa___';

$getParams = array();
$getParams['user_id'] = $userId;
$getParams['redemption_id'] = $redemptionId;
$response = $redemptionsService->get($getParams)->wait();
echo json_encode($response, JSON_PRETTY_PRINT);
```

* Get User Redemptions List. Pagination is supported by this API.

```php
// Mandatory API parameters
$userId = 'ee89___';

// Optional API parameters

// Limit.
$limit = 10;

// Array of user redemption uuids.
$redemptionIds = array('a743___', 'a743___');

// Pagination identifier from the previous API call response. Not needed for page one.
$paginationIdentifier = 'eyJsY___';

$getParams = array();
$getParams['user_id'] = $userId;
$getParams['redemption_ids'] = $redemptionIds;
$getParams['limit'] = $limit;
$getParams['pagination_identifier'] = $paginationIdentifier;

$response = $redemptionsService->getList($getParams)->wait();
echo json_encode($response, JSON_PRETTY_PRINT);
```
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.2
2.2.3
24 changes: 24 additions & 0 deletions src/Services/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,30 @@ protected function getTransactionId(array $params)
return $this->getValueForKey($params, "transaction_id");
}

/**
* getRedemptionId from params array
*
* @param array $params request object which would fire API calls
*
* @return string
*/
protected function getRedemptionId(array $params)
{
return $this->getValueForKey($params, "redemption_id");
}

/**
* getRedeemableSkuId from params array
*
* @param array $params request object which would fire API calls
*
* @return string
*/
protected function getRedeemableSkuId(array $params)
{
return $this->getValueForKey($params, "redeemable_sku_id");
}

/**
* getRecoveryOwnerAddress from params array
*
Expand Down
10 changes: 10 additions & 0 deletions src/Services/Manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ class Manifest
/** @var RecoveryOwners object which has methods to fire API's belonging to RecoveryOwners module */
public $recoveryOwners;

/** @var Redemptions object which has methods to fire API's belonging to Redemptions module */
public $redemptions;

/** @var RedeemableSkus object which has methods to fire API's belonging to RedeemableSkus module */
public $redeemableSkus;

/** @var Rules object which has methods to fire API's belonging to Rules module */
public $rules;

Expand Down Expand Up @@ -83,6 +89,10 @@ public function __construct($params)

$this->recoveryOwners = new RecoveryOwners($requestObj);

$this->redemptions = new Redemptions($requestObj);

$this->redeemableSkus = new RedeemableSkus($requestObj);

$this->rules = new Rules($requestObj);

$this->sessions = new Sessions($requestObj);
Expand Down
44 changes: 44 additions & 0 deletions src/Services/RedeemableSkus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* RedeemableSkus class
*/

namespace OST;

use OST\Base;

/**
* Class encapsulating methods to interact with API's for RedeemableSkus module
*/
class RedeemableSkus extends Base
{

const PREFIX = '/redeemable-skus';

/**
* List RedeemableSkus
*
* @param array $params params for fetching redeemable skus list
*
* @return object
*
*/
public function getList(array $params = array())
{
return $this->requestObj->get($this->getPrefix() . '/', $params);
}

/**
* Get RedeemableSku details of a uuid
*
* @param array $params params for fetching details of a redeemable sku
*
* @return object
*
*/
public function get(array $params = array())
{
return $this->requestObj->get($this->getPrefix() . '/' . $this->getRedeemableSkuId($params) . '/', $params);
}

}
45 changes: 45 additions & 0 deletions src/Services/Redemptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* Redemptions class
*/

namespace OST;

use OST\Base;

/**
* Class encapsulating methods to interact with API's for Redemptions module
*/
class Redemptions extends Base
{

const PREFIX = '/users';
const SUFFIX = '/redemptions';

/**
* List Redemptions of a user
*
* @param array $params params for fetching redemptions list
*
* @return object
*
*/
public function getList(array $params = array())
{
return $this->requestObj->get($this->getPrefix() . '/' . $this->getUserId($params) . $this->getSuffix() . '/', $params);
}

/**
* Get Redemption details of a uuid
*
* @param array $params params for fetching details of a redemption
*
* @return object
*
*/
public function get(array $params = array())
{
return $this->requestObj->get($this->getPrefix() . '/' . $this->getUserId($params) . $this->getSuffix() . '/' . $this->getRedemptionId($params) . '/', $params);
}

}
47 changes: 47 additions & 0 deletions tests/Services/RedeemableSkusTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* Created by PhpStorm.
* User: aman
* Date: 2020-02-20
* Time: 16:44
*/
$filepath = realpath (dirname(__FILE__));
require_once($filepath."/ServiceTestBase.php");

final class RedeemableSkusTest extends ServiceTestBase
{
/**
*
* Get a redemption info
*
* @test
*
* @throws Exception
*/
public function get()
{
$redeemableSkusService = $this->ostObj->services->redeemableSkus;
$params = array();
$params['redeemable_sku_id'] = $this->environmentVariables['redeemableSkuId'];
$response = $redeemableSkusService->get($params)->wait();
$this->isSuccessResponse($response);
}

/**
*
* Get all redeemableSkus
*
* @test
*
* @throws Exception
*/
public function getList()
{
$ostObj = $this->instantiateOSTSDKForV2Api();
$redeemableSkusService = $ostObj->services->redeemableSkus;
$params = array();
$response = $redeemableSkusService->getList($params)->wait();
$this->isSuccessResponse($response);
}

}
49 changes: 49 additions & 0 deletions tests/Services/RedemptionsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Created by PhpStorm.
* User: aman
* Date: 2020-02-20
* Time: 16:44
*/
$filepath = realpath (dirname(__FILE__));
require_once($filepath."/ServiceTestBase.php");

final class RedemptionsTest extends ServiceTestBase
{
/**
*
* Get a redemption info
*
* @test
*
* @throws Exception
*/
public function get()
{
$redemptionsService = $this->ostObj->services->redemptions;
$params = array();
$params['user_id'] = $this->environmentVariables['userId'];
$params['redemption_id'] = $this->environmentVariables['redemptionId'];
$response = $redemptionsService->get($params)->wait();
$this->isSuccessResponse($response);
}

/**
*
* Get all redemptions for a user
*
* @test
*
* @throws Exception
*/
public function getList()
{
$ostObj = $this->instantiateOSTSDKForV2Api();
$redemptionsService = $ostObj->services->redemptions;
$params = array();
$params['user_id'] = $this->environmentVariables['userId'];
$response = $redemptionsService->getList($params)->wait();
$this->isSuccessResponse($response);
}

}
Loading

0 comments on commit 4831470

Please sign in to comment.