Skip to content

Commit

Permalink
Merge pull request #88 from pedro-stanaka/enabling-token-request-gateway
Browse files Browse the repository at this point in the history
Enabling token request gateway
  • Loading branch information
delatbabel authored Jul 14, 2017
2 parents f5d5ef9 + a0e2d06 commit f2857b7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
27 changes: 21 additions & 6 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Omnipay\Stripe;

use Omnipay\Common\AbstractGateway;
use Omnipay\Stripe\Message\CreateTokenRequest;

/**
* Stripe Gateway.
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion src/Message/CreateTokenRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ public function setCard($value)
* <strong>Only use this if you are using Connect API</strong>
*
* @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);
}

/**
Expand Down
12 changes: 12 additions & 0 deletions tests/GatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Omnipay\Tests\GatewayTestCase;

/**
* @property Gateway gateway
*/
class GatewayTest extends GatewayTestCase
{
public function setUp()
Expand Down Expand Up @@ -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'));
Expand Down

0 comments on commit f2857b7

Please sign in to comment.