Skip to content

Commit

Permalink
Merge pull request #31 from Raistlfiren/accounts
Browse files Browse the repository at this point in the history
Accounts
  • Loading branch information
jlinn committed Dec 30, 2015
2 parents 4753672 + 8a440f2 commit 80cd3cd
Show file tree
Hide file tree
Showing 26 changed files with 3,040 additions and 37 deletions.
25 changes: 15 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ use Stripe\Stripe;
$stripe = new Stripe("your_api_key");
```

#### Charges calls
```php
// create a charge
$request = $stripe->charges->createChargeRequest(350, "usd")->setCustomer($customer->getId());
$stripe->charges->createCharge($request);

//Without a Customer
$card Request = new CreateCardRequest($number, $expMonth, $expYear, $cvc);
$request = $stripe->charges->createChargeRequest(350, "usd")->setCard($card);
$stripe->charges->createCharge($request);

// retrieve a charge
$charge = $stripe->charges->getCharge("charge_id");
```

#### Customers calls
```php
use Stripe\Request\Cards\CreateCardRequest;
Expand All @@ -37,15 +52,5 @@ $customerId = $customer->getId();
$customer = $stripe->customers()->getCustomer("customer_id");
```

#### Charges calls
```php
// create a charge
$request = $stripe->charges->createChargeRequest(350, "usd")->setCustomer($customer->getId());
$stripe->charges->createCharge($request);

// retrieve a charge
$charge = $stripe->charges->getCharge("charge_id");
```

## Development Status
Currently, all Stripe API calls which do not require [Stripe Connect](https://stripe.com/docs/connect) have been implemented. Documentation and Stripe Connect calls are next on the to-do list.
33 changes: 32 additions & 1 deletion docs/api/accounts.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
# [Accounts](https://github.com/jlinn/stripe-api-php/blob/master/src/Api/Accounts.php)
## Retrieve account data
## Retrieve default account data
```php
$account = $stripe->accounts->getAccount();
```

## Create an account
The `createAccount()` method takes a [`CreateAccountRequest`](https://github.com/jlinn/stripe-api-php/blob/master/src/Request/Accounts/CreateAccountRequest.php) object as its only parameter. This parameter is optional.
```php
$newAccount = new CreateAccountRequest();
$newAccount->setManaged(true);
$request = $stripe->accounts->createAccount($newAccount);
```

## Retrieve a connected account
```php
$customer = $stripe->accounts->getConnectedAccount("account_id");
```

## Update an account
The `UpdateAccount()` method takes an [`UpdateAccountRequest`](https://github.com/jlinn/stripe-api-php/blob/master/src/Request/Accounts/UpdateAccountRequest.php) object as its second parameter.
```php
$newAccount = new UpdateAccountRequest();
$newAccount->setManaged(false);
$request = $stripe->accounts->updateAccount($accountId, $newAccount);
```

## Delete an account
```php
$stripe->accounts->deleteAccount("$accountId");
```

## List accounts
```php
$accounts = $stripe->accounts->listAccounts();
```
56 changes: 56 additions & 0 deletions src/Api/Accounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@
namespace Stripe\Api;

use Stripe\Request\Accounts\CreateAccountRequest;
use Stripe\Request\Accounts\UpdateAccountRequest;
use Stripe\Request\ListRequest;
use Stripe\Response\Accounts\AccountResponse;
use Stripe\Response\Accounts\ListAccountsResponse;
use Stripe\Response\DeleteResponse;

class Accounts extends AbstractApi
{
const ACCOUNT_RESPONSE_CLASS = 'Stripe\Response\Accounts\AccountResponse';
const LIST_ACCOUNT_RESPONSE_CLASS = 'Stripe\Response\Accounts\ListAccountsResponse';

/**
* Retrieves default/main account
* @return AccountResponse
* @link https://stripe.com/docs/api/curl#retrieve_account
*/
Expand All @@ -33,11 +39,61 @@ public function createAccount(CreateAccountRequest $request)
return $this->client->post('accounts', self::ACCOUNT_RESPONSE_CLASS, $request);
}

/**
* @param string $accountId
* @return AccountResponse
* @link https://stripe.com/docs/api/curl#retrieve_account
*/
public function getConnectedAccount($accountId)
{
return $this->client->get($this->buildUrl($accountId), self::ACCOUNT_RESPONSE_CLASS);
}

/**
* @param string $accountId
* @param UpdateAccountRequest $request
* @return AccountResponse
* @link https://stripe.com/docs/api/curl#update_account
*/
public function updateAccount($accountId, UpdateAccountRequest $request)
{
return $this->client->post($this->buildUrl($accountId), self::ACCOUNT_RESPONSE_CLASS, $request);
}

/**
* @param string $accountId
* @return DeleteResponse
* @link https://stripe.com/docs/api/curl#delete_account
*/
public function deleteConnectedAccount($accountId)
{
return $this->client->delete($this->buildUrl($accountId), self::DELETE_RESPONSE_CLASS);
}

/**
* @param ListRequest $request
* @return ListAccountsResponse
* @link https://stripe.com/docs/api/curl#list_accounts
*/
public function listConnectedAccounts(ListRequest $request = null)
{
return $this->client->get('accounts', self::LIST_ACCOUNT_RESPONSE_CLASS, null, $this->listRequestToParams($request));
}

/**
* @return CreateAccountRequest
*/
public function createAccountRequest()
{
return new CreateAccountRequest();
}

/**
* @param string $customerId
* @return string
*/
protected function buildUrl($customerId)
{
return 'accounts/' . $customerId;
}
}
Loading

0 comments on commit 80cd3cd

Please sign in to comment.