Skip to content

Commit

Permalink
Allow charges to be created using card tokens. Fixes #24
Browse files Browse the repository at this point in the history
  • Loading branch information
jlinn committed Sep 20, 2014
1 parent 6daff63 commit 0498cc9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Request/Charges/CreateChargeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CreateChargeRequest
protected $customer;

/**
* @var CreateCardRequest
* @var CreateCardRequest|string
*/
protected $card;

Expand Down Expand Up @@ -121,18 +121,18 @@ public function setCapture($capture)
}

/**
* @return CreateCardRequest
* @return CreateCardRequest|string
*/
public function getCard()
{
return $this->card;
}

/**
* @param CreateCardRequest $card
* @param CreateCardRequest|string $card
* @return $this
*/
public function setCard(CreateCardRequest $card)
public function setCard($card)
{
$this->card = $card;
return $this;
Expand Down
14 changes: 14 additions & 0 deletions tests/Api/ChargesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@


use Stripe\Api\Charges;
use Stripe\Api\Tokens;
use Stripe\Request\Cards\CreateCardRequest;
use Stripe\Request\Charges\CreateChargeRequest;
use Stripe\Request\Tokens\CreateCardTokenRequest;
use Stripe\Tests\StripeTestCase;

class ChargesTest extends StripeTestCase
Expand All @@ -35,6 +37,18 @@ public function testCreateCharge()
$this->assertInstanceOf(Charges::CHARGE_RESPONSE_CLASS, $response);
}

public function testCreateChargeWithToken(){
// create a token
$tokens = new Tokens($this->client);
$tokenResponse = $tokens->createCardToken(new CreateCardTokenRequest(self::VISA_1, 1, 2020));

$request = new CreateChargeRequest(350, "usd");
$request->setCard($tokenResponse->getId());
$response = $this->charges->createCharge($request);

$this->assertInstanceOf(Charges::CHARGE_RESPONSE_CLASS, $response);
}

public function testGetCharge()
{
$createRequest = new CreateChargeRequest(350, "usd");
Expand Down

0 comments on commit 0498cc9

Please sign in to comment.