diff --git a/src/Request/Charges/CreateChargeRequest.php b/src/Request/Charges/CreateChargeRequest.php index bf90b84..138c2b5 100644 --- a/src/Request/Charges/CreateChargeRequest.php +++ b/src/Request/Charges/CreateChargeRequest.php @@ -28,7 +28,7 @@ class CreateChargeRequest protected $customer; /** - * @var CreateCardRequest + * @var CreateCardRequest|string */ protected $card; @@ -121,7 +121,7 @@ public function setCapture($capture) } /** - * @return CreateCardRequest + * @return CreateCardRequest|string */ public function getCard() { @@ -129,10 +129,10 @@ public function getCard() } /** - * @param CreateCardRequest $card + * @param CreateCardRequest|string $card * @return $this */ - public function setCard(CreateCardRequest $card) + public function setCard($card) { $this->card = $card; return $this; diff --git a/tests/Api/ChargesTest.php b/tests/Api/ChargesTest.php index 5caa881..020f720 100644 --- a/tests/Api/ChargesTest.php +++ b/tests/Api/ChargesTest.php @@ -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 @@ -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");