Skip to content

Commit

Permalink
Merge pull request #185 from stripe/shale/account-delete
Browse files Browse the repository at this point in the history
Added the ability to delete an account
  • Loading branch information
shalecraig committed Jul 30, 2015
2 parents e587e4b + 7e9e99b commit d9b4717
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ public function save($opts = null)
return $this->_save();
}

/**
* @param array|null $params
* @param array|string|null $opts
*
* @return Account The deleted account.
*/
public function delete($params = null, $opts = null)
{
return $this->_delete($params, $opts);
}

/**
* @param array|null $params
* @param array|string|null $opts
Expand Down
23 changes: 23 additions & 0 deletions tests/AccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ private function managedAccountResponse($id)
);
}

private function deletedAccountResponse($id)
{
return array(
'id' => $id,
'deleted' => true
);
}

public function testBasicRetrieve()
{
$this->mockRequest('GET', '/v1/account', array(), $this->managedAccountResponse('acct_ABC'));
Expand Down Expand Up @@ -86,6 +94,21 @@ public function testCreate()
$this->assertSame($account->id, 'acct_ABC');
}

public function testDelete()
{
$account = self::createTestAccount();

$this->mockRequest(
'DELETE',
'/v1/accounts/' . $account->id,
array(),
$this->deletedAccountResponse('acct_ABC')
);
$deleted = $account->delete();
$this->assertSame($deleted->id, $account->id);
$this->assertTrue($deleted->deleted);
}

public function testUpdateLegalEntity()
{
$response = $this->managedAccountResponse('acct_ABC');
Expand Down
24 changes: 24 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,22 @@ protected static function createTestRecipient(array $attributes = array())
);
}

/**
* Create a test account
*/
protected static function createTestAccount(array $attributes = array())
{
self::authorizeFromEnv();

return Account::create(
$attributes + array(
'managed' => false,
'country' => 'US',
'email' => self::generateRandomEmail(),
)
);
}

/**
* Verify that a plan with a given ID exists, or create a new one if it does
* not.
Expand Down Expand Up @@ -185,6 +201,14 @@ protected static function generateRandomString($length = 24)
return $randomString;
}

/**
* Generate a semi-random email.
*/
protected static function generateRandomEmail($domain = 'bar.com')
{
return self::generateRandomString().'@'.$domain;
}

protected static function createTestBitcoinReceiver($email)
{
$receiver = BitcoinReceiver::create(
Expand Down

0 comments on commit d9b4717

Please sign in to comment.