Skip to content

Commit 61eb7ca

Browse files
committed
Merge branch 'impronunciable-feature-coupons'
2 parents 5dffec3 + 1349ae1 commit 61eb7ca

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

README.md

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

8687
## Tests
8788

mango.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public function __construct($options) {
2323
$this->Queue = new Queue($this);
2424
$this->Installments = new Installments($this);
2525
$this->Promotions = new Promotions($this);
26+
$this->Coupons = new Coupons($this);
2627
}
2728

2829
}
@@ -163,4 +164,25 @@ public function get($uid) {
163164

164165
}
165166

167+
168+
class Coupons extends Resource {
169+
170+
public function get_list($options = NULL) {
171+
return $this->request("GET", "/coupons/", $api_key = $this->mango->api_key, $options);
172+
}
173+
174+
public function get($uid) {
175+
return $this->request("GET", "/coupons/" . $uid . "/", $api_key = $this->mango->api_key);
176+
}
177+
178+
public function create($options = NULL) {
179+
return $this->request("POST", "/coupons/", $api_key = $this->mango->api_key, $options);
180+
}
181+
182+
public function update($uid, $options = NULL) {
183+
return $this->request("PATCH", "/coupons/" . $uid . "/", $api_key = $this->mango->api_key, $options);
184+
}
185+
186+
}
187+
166188
?>

test/MangoTest.php

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class MangoTest extends PHPUnit_Framework_TestCase {
66

7-
protected function setUp() {
7+
protected function setUp() {
88
$this->API_KEY = getenv("MANGO_SECRET_TEST_KEY");
99
$this->PUBLIC_API_KEY = getenv("MANGO_PUBLIC_TEST_KEY");
1010

@@ -280,6 +280,44 @@ public function testGetPromotion() {
280280
$this->assertEquals($promotion->uid, $promotion_uid);
281281
}
282282

283+
284+
/* Coupons */
285+
public function testListCoupons(){
286+
$coupons = $this->mango->Coupons->get_list();
287+
$uid = $coupons[0]->uid;
288+
$this->assertTrue(strlen($uid) > 0);
289+
}
290+
291+
public function testGetCoupon(){
292+
$coupons = $this->mango->Coupons->get_list();
293+
$coupon = $coupons[0];
294+
$response = $this->mango->Coupons->get($coupon->uid);
295+
$this->assertEquals($response->uid, $coupon->uid);
296+
}
297+
298+
public function testCreateCoupon() {
299+
date_default_timezone_set("America/Argentina/Buenos_Aires");
300+
$coupon = $this->mango->Coupons->create(array(
301+
"amount" => 3000,
302+
"type" => "pagofacil",
303+
"first_due_date" => date("Y-m-d", mktime(0, 0, 0, date("m")+1, date("d"), date("Y"))),
304+
"second_due_date" => date("Y-m-d", mktime(0, 0, 0, date("m")+2, date("d"), date("Y"))),
305+
"surcharge" => 20
306+
));
307+
$this->assertTrue($coupon->amount == 3000);
308+
}
309+
310+
public function testUpdateCoupon(){
311+
$coupons = $this->mango->Coupons->get_list();
312+
$coupon = $coupons[0];
313+
$response = $this->mango->Coupons->update($coupon->uid, array(
314+
"paid" => true
315+
));
316+
$this->assertEquals($response->uid, $coupon->uid);
317+
$this->assertTrue($response->paid == true);
318+
}
319+
320+
283321
/* Api Keys */
284322
/**
285323
* @expectedException Mango\InvalidApiKey

0 commit comments

Comments
 (0)