diff --git a/src/Gateway.php b/src/Gateway.php index a47bf756..d45fcfdd 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -6,6 +6,7 @@ namespace Omnipay\Stripe; use Omnipay\Common\AbstractGateway; +use Omnipay\Stripe\Message\CreateTokenRequest; /** * Stripe Gateway. @@ -80,7 +81,11 @@ * * @see \Omnipay\Common\AbstractGateway * @see \Omnipay\Stripe\Message\AbstractRequest + * * @link https://stripe.com/docs/api + * + * @method \Omnipay\Common\Message\RequestInterface completeAuthorize(array $options = array()) + * @method \Omnipay\Common\Message\RequestInterface completePurchase(array $options = array()) */ class Gateway extends AbstractGateway { @@ -539,12 +544,22 @@ public function deleteCustomer(array $parameters = array()) // Tokens // @link https://stripe.com/docs/api#tokens // - // This gateway does not currently have a CreateToken message. In - // any case tokens are probably not what you are looking for because - // they are single use. You probably want to create a Customer or - // Card reference instead. This function is left here for further - // expansion. - // + + /** + * Creates a single use token that wraps the details of a credit card. + * This token can be used in place of a credit card associative array with any API method. + * These tokens can only be used once: by creating a new charge object, or attaching them to a customer. + * + * This kind of token is also useful when sharing clients between one platform and a connect account. + * Use this request to create a new token to make a direct charge on a customer of the platform. + * + * @param array $parameters parameters to be passed in to the TokenRequest. + * @return CreateTokenRequest|\Omnipay\Common\Message\AbstractRequest The create token request. + */ + public function createToken(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Stripe\Message\CreateTokenRequest', $parameters); + } /** * Stripe Fetch Token Request. diff --git a/src/Message/CreateTokenRequest.php b/src/Message/CreateTokenRequest.php index 5b7c16dc..2b0cf47e 100644 --- a/src/Message/CreateTokenRequest.php +++ b/src/Message/CreateTokenRequest.php @@ -37,10 +37,11 @@ public function setCard($value) * Only use this if you are using Connect API * * @param string $customer The id of the customer + * @return \Omnipay\Common\Message\AbstractRequest|\Omnipay\Stripe\Message\CreateTokenRequest */ public function setCustomer($customer) { - $this->setParameter('customer', $customer); + return $this->setParameter('customer', $customer); } /** diff --git a/tests/GatewayTest.php b/tests/GatewayTest.php index d1ffe219..3f5a6a68 100644 --- a/tests/GatewayTest.php +++ b/tests/GatewayTest.php @@ -4,6 +4,9 @@ use Omnipay\Tests\GatewayTestCase; +/** + * @property Gateway gateway + */ class GatewayTest extends GatewayTestCase { public function setUp() @@ -73,6 +76,15 @@ public function testFetchToken() $this->assertInstanceOf('Omnipay\Stripe\Message\FetchTokenRequest', $request); } + public function testCreateToken() + { + $request = $this->gateway->createToken(array('customer' => 'cus_foo')); + + $this->assertInstanceOf('Omnipay\Stripe\Message\CreateTokenRequest', $request); + $params = $request->getParameters(); + $this->assertSame('cus_foo', $params['customer']); + } + public function testCreateCard() { $request = $this->gateway->createCard(array('description' => 'foo'));