diff --git a/lib/Source.php b/lib/Source.php index 249713735..372d0b333 100644 --- a/lib/Source.php +++ b/lib/Source.php @@ -67,11 +67,11 @@ public function save($opts = null) /** * @param array|null $params - * @param array|string|null $opts + * @param array|string|null $options * - * @return Source The deleted source. + * @return Source The detached source. */ - public function delete($params = null, $options = null) + public function detach($params = null, $options = null) { self::_validateParams($params); @@ -93,13 +93,25 @@ public function delete($params = null, $options = null) $this->refreshFrom($response, $opts); return $this; } else { - $message = "Source objects cannot be deleted, they can only be " - . "detached from customer objects. This source object does not " - . "appear to be currently attached to a customer object."; + $message = "This source object does not appear to be currently attached " + . "to a customer object."; throw new Error\Api($message); } } + /** + * @param array|null $params + * @param array|string|null $options + * + * @return Source The detached source. + * + * @deprecated Use the `detach` method instead. + */ + public function delete($params = null, $options = null) + { + $this->detach($params, $options); + } + /** * @param array|null $params * @param array|string|null $options diff --git a/tests/SourceTest.php b/tests/SourceTest.php index 5ba142b9b..0752917b4 100644 --- a/tests/SourceTest.php +++ b/tests/SourceTest.php @@ -137,18 +137,16 @@ public function testSaveOwner() $this->assertSame($source->owner['address']['country'], "Test Country"); } - public function testDeleteAttached() + public function testDetachAttached() { $response = array( 'id' => 'src_foo', 'object' => 'source', 'customer' => 'cus_bar', ); - $this->mockRequest( - 'GET', - '/v1/sources/src_foo', - array(), - $response + $source = Source::constructFrom( + $response, + new Util\RequestOptions() ); unset($response['customer']); @@ -159,29 +157,25 @@ public function testDeleteAttached() $response ); - $source = Source::retrieve('src_foo'); - $source->delete(); + $source->detach(); $this->assertFalse(array_key_exists('customer', $source)); } /** * @expectedException Stripe\Error\Api */ - public function testDeleteUnattached() + public function testDetachUnattached() { $response = array( 'id' => 'src_foo', 'object' => 'source', ); - $this->mockRequest( - 'GET', - '/v1/sources/src_foo', - array(), - $response + $source = Source::constructFrom( + $response, + new Util\RequestOptions() ); - $source = Source::retrieve('src_foo'); - $source->delete(); + $source->detach(); } public function testVerify()