Skip to content

Commit

Permalink
Merge branch 'impronunciable-feature-coupons'
Browse files Browse the repository at this point in the history
  • Loading branch information
pazguille committed Jul 20, 2015
2 parents 5dffec3 + 1349ae1 commit 61eb7ca
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ You can also work with all the other resources authenticated with a secret API K
- [Queue](https://developers.getmango.com/en/api/queue/?platform=php)
- [Installments](https://developers.getmango.com/en/api/installments/?platform=php)
- [Promotions](https://developers.getmango.com/en/api/promotions/?platform=php)
- [Coupons](https://developers.getmango.com/en/api/coupons/?platform=php)

## Tests

Expand Down
22 changes: 22 additions & 0 deletions mango.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function __construct($options) {
$this->Queue = new Queue($this);
$this->Installments = new Installments($this);
$this->Promotions = new Promotions($this);
$this->Coupons = new Coupons($this);
}

}
Expand Down Expand Up @@ -163,4 +164,25 @@ public function get($uid) {

}


class Coupons extends Resource {

public function get_list($options = NULL) {
return $this->request("GET", "/coupons/", $api_key = $this->mango->api_key, $options);
}

public function get($uid) {
return $this->request("GET", "/coupons/" . $uid . "/", $api_key = $this->mango->api_key);
}

public function create($options = NULL) {
return $this->request("POST", "/coupons/", $api_key = $this->mango->api_key, $options);
}

public function update($uid, $options = NULL) {
return $this->request("PATCH", "/coupons/" . $uid . "/", $api_key = $this->mango->api_key, $options);
}

}

?>
40 changes: 39 additions & 1 deletion test/MangoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class MangoTest extends PHPUnit_Framework_TestCase {

protected function setUp() {
protected function setUp() {
$this->API_KEY = getenv("MANGO_SECRET_TEST_KEY");
$this->PUBLIC_API_KEY = getenv("MANGO_PUBLIC_TEST_KEY");

Expand Down Expand Up @@ -280,6 +280,44 @@ public function testGetPromotion() {
$this->assertEquals($promotion->uid, $promotion_uid);
}


/* Coupons */
public function testListCoupons(){
$coupons = $this->mango->Coupons->get_list();
$uid = $coupons[0]->uid;
$this->assertTrue(strlen($uid) > 0);
}

public function testGetCoupon(){
$coupons = $this->mango->Coupons->get_list();
$coupon = $coupons[0];
$response = $this->mango->Coupons->get($coupon->uid);
$this->assertEquals($response->uid, $coupon->uid);
}

public function testCreateCoupon() {
date_default_timezone_set("America/Argentina/Buenos_Aires");
$coupon = $this->mango->Coupons->create(array(
"amount" => 3000,
"type" => "pagofacil",
"first_due_date" => date("Y-m-d", mktime(0, 0, 0, date("m")+1, date("d"), date("Y"))),
"second_due_date" => date("Y-m-d", mktime(0, 0, 0, date("m")+2, date("d"), date("Y"))),
"surcharge" => 20
));
$this->assertTrue($coupon->amount == 3000);
}

public function testUpdateCoupon(){
$coupons = $this->mango->Coupons->get_list();
$coupon = $coupons[0];
$response = $this->mango->Coupons->update($coupon->uid, array(
"paid" => true
));
$this->assertEquals($response->uid, $coupon->uid);
$this->assertTrue($response->paid == true);
}


/* Api Keys */
/**
* @expectedException Mango\InvalidApiKey
Expand Down

0 comments on commit 61eb7ca

Please sign in to comment.