Skip to content

Commit 5dffec3

Browse files
Merge pull request #8 from juanrossi/master
Added Promotion resource and tests. Fixed Installments options not worki...
2 parents fd31e48 + ea748cf commit 5dffec3

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ You can also work with all the other resources authenticated with a secret API K
8181
- [Cards](https://developers.getmango.com/en/api/cards/?platform=php)
8282
- [Queue](https://developers.getmango.com/en/api/queue/?platform=php)
8383
- [Installments](https://developers.getmango.com/en/api/installments/?platform=php)
84+
- [Promotions](https://developers.getmango.com/en/api/promotions/?platform=php)
8485

8586
## Tests
8687

mango.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function __construct($options) {
2222
$this->Cards = new Cards($this);
2323
$this->Queue = new Queue($this);
2424
$this->Installments = new Installments($this);
25+
$this->Promotions = new Promotions($this);
2526
}
2627

2728
}
@@ -144,7 +145,20 @@ public function delete_all() {
144145
class Installments extends Resource {
145146

146147
public function get_list($options = NULL) {
147-
return $this->request("GET", "/installments/", $api_key = $this->mango->api_key);
148+
return $this->request("GET", "/installments/", $api_key = $this->mango->api_key, $options);
149+
}
150+
151+
}
152+
153+
154+
class Promotions extends Resource {
155+
156+
public function get_list($options) {
157+
return $this->request("GET", "/promotions/", $api_key = $this->mango->api_key, $options);
158+
}
159+
160+
public function get($uid) {
161+
return $this->request("GET", "/promotions/" . $uid . "/", $api_key = $this->mango->api_key);
148162
}
149163

150164
}

test/MangoTest.php

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,41 @@ public function testListRefunds() {
244244

245245
/* Installments */
246246
public function testListInstallment() {
247-
$installment = $this->mango->Installments->get_list();
248-
$this->assertTrue(is_array($installment));
247+
$installments = $this->mango->Installments->get_list();
248+
$this->assertTrue(is_array($installments));
249249
}
250250

251+
public function testListInstallmentWithOptions() {
252+
$installments = $this->mango->Installments->get_list(array(
253+
'cardtype' => 'visa'
254+
));
255+
$this->assertTrue(is_array($installments));
256+
foreach ( $installments as $key => $val ) {
257+
$this->assertEquals($val->cardtype, 'visa');
258+
}
259+
}
260+
261+
262+
/* Promotions */
263+
public function testListPromotions() {
264+
$promotions = $this->mango->Promotions->get_list(array(
265+
"status" => "active"
266+
));
267+
$this->assertTrue(is_array($promotions));
268+
foreach ( $promotions as $key => $val ) {
269+
$this->assertEquals($val->status, "active");
270+
}
271+
}
272+
273+
public function testGetPromotion() {
274+
$promotion_list = $this->mango->Promotions->get_list(array(
275+
"status" => "active"
276+
));
277+
$promotion_uid = $promotion_list[0]->uid;
278+
$promotion = $this->mango->Promotions->get($promotion_uid);
279+
$this->assertEquals($promotion->status, 'active');
280+
$this->assertEquals($promotion->uid, $promotion_uid);
281+
}
251282

252283
/* Api Keys */
253284
/**

0 commit comments

Comments
 (0)