-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from ruudk/fetch-token
Added FetchTokenRequest
- Loading branch information
Showing
8 changed files
with
196 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Omnipay\Stripe\Message; | ||
|
||
/** | ||
* Stripe Fetch Token Request | ||
*/ | ||
class FetchTokenRequest extends AbstractRequest | ||
{ | ||
public function getData() | ||
{ | ||
$this->validate('token'); | ||
|
||
$data = array(); | ||
|
||
return $data; | ||
} | ||
|
||
public function getEndpoint() | ||
{ | ||
return $this->endpoint.'/tokens/'.$this->getToken(); | ||
} | ||
|
||
public function getHttpMethod() | ||
{ | ||
return 'GET'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Omnipay\Stripe\Message; | ||
|
||
use Omnipay\Tests\TestCase; | ||
|
||
class FetchTokenRequestTest extends TestCase | ||
{ | ||
/** | ||
* @var FetchTokenRequest | ||
*/ | ||
private $request; | ||
|
||
public function setUp() | ||
{ | ||
$this->request = new FetchTokenRequest($this->getHttpClient(), $this->getHttpRequest()); | ||
$this->request->setToken('tok_15Kuns2eZvKYlo2CDt9wRdzS'); | ||
} | ||
|
||
public function testEndpoint() | ||
{ | ||
$this->assertSame('https://api.stripe.com/v1/tokens/tok_15Kuns2eZvKYlo2CDt9wRdzS', $this->request->getEndpoint()); | ||
} | ||
|
||
public function testSendSuccess() | ||
{ | ||
$this->setMockHttpResponse('FetchTokenSuccess.txt'); | ||
$response = $this->request->send(); | ||
|
||
$this->assertTrue($response->isSuccessful()); | ||
$this->assertFalse($response->isRedirect()); | ||
$this->assertSame('tok_15Kuns2eZvKYlo2CDt9wRdzS', $response->getToken()); | ||
$this->assertInternalType('array', $response->getCard()); | ||
$this->assertNull($response->getMessage()); | ||
} | ||
|
||
public function testSendError() | ||
{ | ||
$this->setMockHttpResponse('FetchTokenFailure.txt'); | ||
$response = $this->request->send(); | ||
|
||
$this->assertFalse($response->isSuccessful()); | ||
$this->assertFalse($response->isRedirect()); | ||
$this->assertNull($response->getToken()); | ||
$this->assertNull($response->getCard()); | ||
$this->assertSame('No such token: tok_15Kuns2eZvKYlo2CDt9wRdzS', $response->getMessage()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
HTTP/1.1 404 Not Found | ||
Server: nginx | ||
Date: Wed, 24 Jul 2013 13:40:31 GMT | ||
Content-Type: application/json;charset=utf-8 | ||
Content-Length: 132 | ||
Connection: keep-alive | ||
Access-Control-Allow-Credentials: true | ||
Access-Control-Max-Age: 300 | ||
Cache-Control: no-cache, no-store | ||
|
||
{ | ||
"error": { | ||
"type": "invalid_request_error", | ||
"message": "No such token: tok_15Kuns2eZvKYlo2CDt9wRdzS", | ||
"param": "id" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
HTTP/1.1 200 OK | ||
Server: nginx | ||
Date: Wed, 24 Jul 2013 07:14:02 GMT | ||
Content-Type: application/json;charset=utf-8 | ||
Content-Length: 1092 | ||
Connection: keep-alive | ||
Access-Control-Allow-Credentials: true | ||
Access-Control-Max-Age: 300 | ||
Cache-Control: no-cache, no-store | ||
|
||
{ | ||
"id": "tok_15Kuns2eZvKYlo2CDt9wRdzS", | ||
"livemode": false, | ||
"created": 1421255976, | ||
"used": false, | ||
"object": "token", | ||
"type": "card", | ||
"card": { | ||
"id": "card_15Kuns2eZvKYlo2CugO37SA3", | ||
"object": "card", | ||
"last4": "4242", | ||
"brand": "Visa", | ||
"funding": "credit", | ||
"exp_month": 8, | ||
"exp_year": 2016, | ||
"fingerprint": "Xt5EWLLDS7FJjR1c", | ||
"country": "US", | ||
"name": null, | ||
"address_line1": null, | ||
"address_line2": null, | ||
"address_city": null, | ||
"address_state": null, | ||
"address_zip": null, | ||
"address_country": null, | ||
"cvc_check": null, | ||
"address_line1_check": null, | ||
"address_zip_check": null, | ||
"dynamic_last4": null | ||
} | ||
} |