Skip to content

Commit 4831470

Browse files
Merge pull request #75 from ostdotcom/develop
Redemptions API.
2 parents 3c4a825 + d19a5d8 commit 4831470

File tree

12 files changed

+339
-4
lines changed

12 files changed

+339
-4
lines changed

.env.example

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ OST_KIT_RECOVERY_OWNER_ADDRESS=RecoveryOwnerAddressOfUser
99
OST_KIT_SESSION_ADDRESS=SessionAddressOfUser
1010
OST_KIT_RULE_ADDRESS=AddressForExecutingRule
1111
OST_KIT_USER2_TOKEN_HOLDER_ADDRESS=TokenHolderAddressForReceiver
12-
OST_KIT_TRANSACTION_ID=TransactionIdUsedToTestGet
12+
OST_KIT_TRANSACTION_ID=TransactionIdUsedToTestGet
13+
OST_KIT_REDEMPTION_ID=RedemptionIdUsedToTestGet
14+
OST_KIT_REDEEMABLE_SKU_ID=RedeemableSkuIdUsedToTestGet

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ php:
1616
- 5.6
1717
- 7.0
1818
- 7.1
19-
- 7.2
19+
- 7.3
2020
env:
2121
- BUILD_ENV=TRAVIS
2222
before_install:

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
[OST PHP SDK v2.2.3](https://github.com/ostdotcom/ost-sdk-php/tree/v2.2.3)
2+
---
3+
4+
* Added redemptions module to call redemptions management OST APIs.
5+
* Added redeemable sku module to call redeemable sku management OST APIs.
6+
17
[OST PHP SDK v2.2.2](https://github.com/ostdotcom/ost-sdk-php/tree/v2.2.2)
28
---
39

README.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,3 +807,109 @@ For executing transactions, you need to understand the 4 modules described below
807807
$response = $webhooksService->verifySignature($params);
808808
echo json_encode($response, JSON_PRETTY_PRINT);
809809
```
810+
811+
812+
### Redemption Modules
813+
814+
Two modules of redemption, "Redeemable SKUs" and "User Redemptions", are described below.
815+
816+
#### Redeemable SKUs Module
817+
818+
* Initialize Redeemable SKUs service object to perform redeemable skus specific actions.
819+
820+
```php
821+
$redeemableSkusService = $ostObj->services->redeemableSkus;
822+
```
823+
824+
* Get Redeemable SKU detail using the redeemable sku id.
825+
826+
```php
827+
// Mandatory API parameters
828+
829+
// Fetch details of following redeemable sku.
830+
$redeemableSkuId = '1';
831+
832+
$getParams = array();
833+
$getParams['redeemable_sku_id'] = $redeemableSkuId;
834+
$response = $redeemableSkusService->get($getParams)->wait();
835+
echo json_encode($response, JSON_PRETTY_PRINT);
836+
```
837+
838+
* Get Redeemable SKUs List. Pagination is supported by this API.
839+
840+
```php
841+
// Mandatory API parameters
842+
// NOTE: No mandatory parameters.
843+
844+
// Optional API parameters
845+
846+
// Limit.
847+
$limit = 10;
848+
849+
// Array of redeemable SKU ids.
850+
$redeemableSkuIds = array('1', '2');
851+
852+
// Pagination identifier from the previous API call response. Not needed for page one.
853+
$paginationIdentifier = 'eyJsY___';
854+
855+
$getParams = array();
856+
$getParams['redeemable_sku_ids'] = $redeemableSkuIds;
857+
$getParams['limit'] = $limit;
858+
$getParams['pagination_identifier'] = $paginationIdentifier;
859+
860+
$response = $redeemableSkusService->getList($getParams)->wait();
861+
echo json_encode($response, JSON_PRETTY_PRINT);
862+
```
863+
864+
#### User Redemptions Module
865+
866+
* Initialize Redemptions service object to perform user redemption specific actions.
867+
868+
```php
869+
$redemptionsService = $ostObj->services->redemptions;
870+
```
871+
872+
* Get User redemption details using the userId and redemptionId.
873+
874+
```php
875+
// Mandatory API parameters
876+
877+
// UserId of user for whom redemption details needs to be fetched.
878+
$userId = 'ee8___';
879+
880+
// Unique identifier of the redemption of user.
881+
$redemptionId = 'aa___';
882+
883+
$getParams = array();
884+
$getParams['user_id'] = $userId;
885+
$getParams['redemption_id'] = $redemptionId;
886+
$response = $redemptionsService->get($getParams)->wait();
887+
echo json_encode($response, JSON_PRETTY_PRINT);
888+
```
889+
890+
* Get User Redemptions List. Pagination is supported by this API.
891+
892+
```php
893+
// Mandatory API parameters
894+
$userId = 'ee89___';
895+
896+
// Optional API parameters
897+
898+
// Limit.
899+
$limit = 10;
900+
901+
// Array of user redemption uuids.
902+
$redemptionIds = array('a743___', 'a743___');
903+
904+
// Pagination identifier from the previous API call response. Not needed for page one.
905+
$paginationIdentifier = 'eyJsY___';
906+
907+
$getParams = array();
908+
$getParams['user_id'] = $userId;
909+
$getParams['redemption_ids'] = $redemptionIds;
910+
$getParams['limit'] = $limit;
911+
$getParams['pagination_identifier'] = $paginationIdentifier;
912+
913+
$response = $redemptionsService->getList($getParams)->wait();
914+
echo json_encode($response, JSON_PRETTY_PRINT);
915+
```

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.2.2
1+
2.2.3

src/Services/Base.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,30 @@ protected function getTransactionId(array $params)
131131
return $this->getValueForKey($params, "transaction_id");
132132
}
133133

134+
/**
135+
* getRedemptionId from params array
136+
*
137+
* @param array $params request object which would fire API calls
138+
*
139+
* @return string
140+
*/
141+
protected function getRedemptionId(array $params)
142+
{
143+
return $this->getValueForKey($params, "redemption_id");
144+
}
145+
146+
/**
147+
* getRedeemableSkuId from params array
148+
*
149+
* @param array $params request object which would fire API calls
150+
*
151+
* @return string
152+
*/
153+
protected function getRedeemableSkuId(array $params)
154+
{
155+
return $this->getValueForKey($params, "redeemable_sku_id");
156+
}
157+
134158
/**
135159
* getRecoveryOwnerAddress from params array
136160
*

src/Services/Manifest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ class Manifest
3232
/** @var RecoveryOwners object which has methods to fire API's belonging to RecoveryOwners module */
3333
public $recoveryOwners;
3434

35+
/** @var Redemptions object which has methods to fire API's belonging to Redemptions module */
36+
public $redemptions;
37+
38+
/** @var RedeemableSkus object which has methods to fire API's belonging to RedeemableSkus module */
39+
public $redeemableSkus;
40+
3541
/** @var Rules object which has methods to fire API's belonging to Rules module */
3642
public $rules;
3743

@@ -83,6 +89,10 @@ public function __construct($params)
8389

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

92+
$this->redemptions = new Redemptions($requestObj);
93+
94+
$this->redeemableSkus = new RedeemableSkus($requestObj);
95+
8696
$this->rules = new Rules($requestObj);
8797

8898
$this->sessions = new Sessions($requestObj);

src/Services/RedeemableSkus.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* RedeemableSkus class
4+
*/
5+
6+
namespace OST;
7+
8+
use OST\Base;
9+
10+
/**
11+
* Class encapsulating methods to interact with API's for RedeemableSkus module
12+
*/
13+
class RedeemableSkus extends Base
14+
{
15+
16+
const PREFIX = '/redeemable-skus';
17+
18+
/**
19+
* List RedeemableSkus
20+
*
21+
* @param array $params params for fetching redeemable skus list
22+
*
23+
* @return object
24+
*
25+
*/
26+
public function getList(array $params = array())
27+
{
28+
return $this->requestObj->get($this->getPrefix() . '/', $params);
29+
}
30+
31+
/**
32+
* Get RedeemableSku details of a uuid
33+
*
34+
* @param array $params params for fetching details of a redeemable sku
35+
*
36+
* @return object
37+
*
38+
*/
39+
public function get(array $params = array())
40+
{
41+
return $this->requestObj->get($this->getPrefix() . '/' . $this->getRedeemableSkuId($params) . '/', $params);
42+
}
43+
44+
}

src/Services/Redemptions.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Redemptions class
4+
*/
5+
6+
namespace OST;
7+
8+
use OST\Base;
9+
10+
/**
11+
* Class encapsulating methods to interact with API's for Redemptions module
12+
*/
13+
class Redemptions extends Base
14+
{
15+
16+
const PREFIX = '/users';
17+
const SUFFIX = '/redemptions';
18+
19+
/**
20+
* List Redemptions of a user
21+
*
22+
* @param array $params params for fetching redemptions list
23+
*
24+
* @return object
25+
*
26+
*/
27+
public function getList(array $params = array())
28+
{
29+
return $this->requestObj->get($this->getPrefix() . '/' . $this->getUserId($params) . $this->getSuffix() . '/', $params);
30+
}
31+
32+
/**
33+
* Get Redemption details of a uuid
34+
*
35+
* @param array $params params for fetching details of a redemption
36+
*
37+
* @return object
38+
*
39+
*/
40+
public function get(array $params = array())
41+
{
42+
return $this->requestObj->get($this->getPrefix() . '/' . $this->getUserId($params) . $this->getSuffix() . '/' . $this->getRedemptionId($params) . '/', $params);
43+
}
44+
45+
}

tests/Services/RedeemableSkusTest.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: aman
5+
* Date: 2020-02-20
6+
* Time: 16:44
7+
*/
8+
$filepath = realpath (dirname(__FILE__));
9+
require_once($filepath."/ServiceTestBase.php");
10+
11+
final class RedeemableSkusTest extends ServiceTestBase
12+
{
13+
/**
14+
*
15+
* Get a redemption info
16+
*
17+
* @test
18+
*
19+
* @throws Exception
20+
*/
21+
public function get()
22+
{
23+
$redeemableSkusService = $this->ostObj->services->redeemableSkus;
24+
$params = array();
25+
$params['redeemable_sku_id'] = $this->environmentVariables['redeemableSkuId'];
26+
$response = $redeemableSkusService->get($params)->wait();
27+
$this->isSuccessResponse($response);
28+
}
29+
30+
/**
31+
*
32+
* Get all redeemableSkus
33+
*
34+
* @test
35+
*
36+
* @throws Exception
37+
*/
38+
public function getList()
39+
{
40+
$ostObj = $this->instantiateOSTSDKForV2Api();
41+
$redeemableSkusService = $ostObj->services->redeemableSkus;
42+
$params = array();
43+
$response = $redeemableSkusService->getList($params)->wait();
44+
$this->isSuccessResponse($response);
45+
}
46+
47+
}

tests/Services/RedemptionsTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: aman
5+
* Date: 2020-02-20
6+
* Time: 16:44
7+
*/
8+
$filepath = realpath (dirname(__FILE__));
9+
require_once($filepath."/ServiceTestBase.php");
10+
11+
final class RedemptionsTest extends ServiceTestBase
12+
{
13+
/**
14+
*
15+
* Get a redemption info
16+
*
17+
* @test
18+
*
19+
* @throws Exception
20+
*/
21+
public function get()
22+
{
23+
$redemptionsService = $this->ostObj->services->redemptions;
24+
$params = array();
25+
$params['user_id'] = $this->environmentVariables['userId'];
26+
$params['redemption_id'] = $this->environmentVariables['redemptionId'];
27+
$response = $redemptionsService->get($params)->wait();
28+
$this->isSuccessResponse($response);
29+
}
30+
31+
/**
32+
*
33+
* Get all redemptions for a user
34+
*
35+
* @test
36+
*
37+
* @throws Exception
38+
*/
39+
public function getList()
40+
{
41+
$ostObj = $this->instantiateOSTSDKForV2Api();
42+
$redemptionsService = $ostObj->services->redemptions;
43+
$params = array();
44+
$params['user_id'] = $this->environmentVariables['userId'];
45+
$response = $redemptionsService->getList($params)->wait();
46+
$this->isSuccessResponse($response);
47+
}
48+
49+
}

0 commit comments

Comments
 (0)