Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

detach method for detaching sources from customers #378

Merged
merged 1 commit into from
Oct 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions lib/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
Expand Down
26 changes: 10 additions & 16 deletions tests/SourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand All @@ -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()
Expand Down