Skip to content

Commit 34e6ee8

Browse files
committed
Merge pull request #123 from bc-joshroe/api-fix-1
Adding coupon delete methods
2 parents 1d68679 + cf1ab88 commit 34e6ee8

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

src/Bigcommerce/Api/Client.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,16 @@ public static function updateSku($id, $object)
10051005
return self::updateResource('/product/skus/' . $id, $object);
10061006
}
10071007

1008+
/**
1009+
* Get a single coupon by given id.
1010+
*
1011+
* @param int $id customer id
1012+
* @return Coupon
1013+
*/
1014+
public static function getCoupon($id)
1015+
{
1016+
return self::getResource('/coupon/' . $id, 'Coupon');
1017+
}
10081018

10091019
/**
10101020
* Get coupons
@@ -1041,6 +1051,27 @@ public static function updateCoupon($id, $object)
10411051
return self::updateResource('/coupons/' . $id, $object);
10421052
}
10431053

1054+
/**
1055+
* Delete the given coupon.
1056+
*
1057+
* @param int $id coupon id
1058+
* @return hash|bool|mixed
1059+
*/
1060+
public static function deleteCoupon($id)
1061+
{
1062+
return self::deleteResource('/coupons/' . $id);
1063+
}
1064+
1065+
/**
1066+
* Delete all Coupons.
1067+
*
1068+
* @return hash|bool|mixed
1069+
*/
1070+
public static function deleteAllCoupons()
1071+
{
1072+
return self::deleteResource('/coupons');
1073+
}
1074+
10441075
/**
10451076
* The request logs with usage history statistics.
10461077
*/

test/Unit/Api/ClientTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,4 +532,33 @@ public function testDeletingACustomerDeletesToTheCustomerResource()
532532

533533
Client::deleteCustomers();
534534
}
535+
536+
public function testDeletingAllCouponDeletesToTheCouponResource()
537+
{
538+
$this->connection->expects($this->once())
539+
->method('delete')
540+
->with('/coupons');
541+
542+
Client::deleteAllCoupons();
543+
}
544+
545+
public function testDeletingACouponDeletesToTheCouponResource()
546+
{
547+
$this->connection->expects($this->once())
548+
->method('delete')
549+
->with('/coupons/1');
550+
551+
Client::deleteCoupon(1);
552+
}
553+
554+
public function testGettingASpecifiedCouponReturnsThatCoupon()
555+
{
556+
$this->connection->expects($this->once())
557+
->method('get')
558+
->with('/coupon/1', false)
559+
->will($this->returnValue(array(array(), array())));
560+
561+
$resource = Client::getCoupon(1);
562+
$this->assertInstanceOf('Bigcommerce\\Api\\Resources\\Coupon', $resource);
563+
}
535564
}

0 commit comments

Comments
 (0)