-
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 #48 from WellingGuzman/dev
Support: FetchChargeRequest
- Loading branch information
Showing
7 changed files
with
204 additions
and
1 deletion.
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
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,50 @@ | ||
<?php | ||
|
||
/** | ||
* Stripe Fetch Charge Request. | ||
*/ | ||
namespace Omnipay\Stripe\Message; | ||
|
||
/** | ||
* Stripe Fetch Charge Request. | ||
* | ||
* @link https://stripe.com/docs/api#retrieve_charge | ||
*/ | ||
class FetchChargeRequest extends AbstractRequest | ||
{ | ||
/** | ||
* Get the charge reference. | ||
* | ||
* @return string | ||
*/ | ||
public function getChargeReference() | ||
{ | ||
return $this->getParameter('chargeReference'); | ||
} | ||
|
||
/** | ||
* Set the charge reference. | ||
* | ||
* @param string | ||
* @return FetchChargeRequest provides a fluent interface. | ||
*/ | ||
public function setChargeReference($value) | ||
{ | ||
return $this->setParameter('chargeReference', $value); | ||
} | ||
|
||
public function getData() | ||
{ | ||
$this->validate('chargeReference'); | ||
} | ||
|
||
public function getEndpoint() | ||
{ | ||
return $this->endpoint.'/charges/'.$this->getChargeReference(); | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace Omnipay\Stripe\Message; | ||
|
||
use Omnipay\Tests\TestCase; | ||
|
||
class FetchChargeRequestTest extends TestCase | ||
{ | ||
public function setUp() | ||
{ | ||
$this->request = new FetchChargeRequest($this->getHttpClient(), $this->getHttpRequest()); | ||
$this->request->setChargeReference('ch_180ZdUCryC0oikg4v4lc4F59D'); | ||
} | ||
|
||
public function testEndpoint() | ||
{ | ||
$this->assertSame('https://api.stripe.com/v1/charges/ch_180ZdUCryC0oikg4v4lc4F59D', $this->request->getEndpoint()); | ||
} | ||
|
||
public function testSendSuccess() | ||
{ | ||
$this->setMockHttpResponse('FetchChargeSuccess.txt'); | ||
$response = $this->request->send(); | ||
|
||
$this->assertTrue($response->isSuccessful()); | ||
$this->assertFalse($response->isRedirect()); | ||
$this->assertSame('ch_180ZdUCryC0oikg4v4lc4F59D', $response->getChargeReference()); | ||
$this->assertInternalType('array', $response->getSource()); | ||
$this->assertNull($response->getMessage()); | ||
} | ||
|
||
public function testSendFailure() | ||
{ | ||
$this->setMockHttpResponse('FetchChargeFailure.txt'); | ||
$response = $this->request->send(); | ||
|
||
$this->assertFalse($response->isSuccessful()); | ||
$this->assertFalse($response->isRedirect()); | ||
$this->assertNull($response->getChargeReference()); | ||
$this->assertNull($response->getSource()); | ||
$this->assertSame('No such charge: ch_180ZdUCryC0oikg4v4lc4F59D', $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,16 @@ | ||
HTTP/1.1 404 Not Found | ||
Server: nginx | ||
Date: Fri, 15 Apr 2016 21:42:18 GMT | ||
Content-Type: application/json | ||
Content-Length: 138 | ||
Connection: keep-alive | ||
Access-Control-Allow-Credentials: true | ||
Cache-Control: no-cache, no-store | ||
|
||
{ | ||
"error": { | ||
"type": "invalid_request_error", | ||
"message": "No such charge: ch_180ZdUCryC0oikg4v4lc4F59D", | ||
"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,70 @@ | ||
HTTP/1.1 200 OK | ||
Server: nginx | ||
Date: Fri, 15 Apr 2016 21:37:26 GMT | ||
Content-Type: application/json | ||
Content-Length: 1521 | ||
Connection: keep-alive | ||
Cache-Control: no-cache, no-store | ||
|
||
{ | ||
"id": "ch_180ZdUCryC0oikg4v4lc4F59D", | ||
"object": "charge", | ||
"created": 1460437056, | ||
"livemode": false, | ||
"paid": true, | ||
"status": "succeeded", | ||
"amount": 1000, | ||
"currency": "usd", | ||
"refunded": false, | ||
"source": { | ||
"id": "card_990JozzC88C4rAAg4vg5yLG3j3", | ||
"object": "card", | ||
"last4": "1234", | ||
"brand": "Visa", | ||
"funding": "credit", | ||
"exp_month": 1, | ||
"exp_year": 2020, | ||
"fingerprint": "32Q1po9Ujn5DpPgL", | ||
"country": "US", | ||
"name": "", | ||
"address_line1": "", | ||
"address_line2": "", | ||
"address_city": "", | ||
"address_state": "", | ||
"address_zip": "", | ||
"address_country": "", | ||
"cvc_check": null, | ||
"address_line1_check": null, | ||
"address_zip_check": null, | ||
"tokenization_method": null, | ||
"dynamic_last4": null, | ||
"metadata": {}, | ||
"customer": "cus_8GoWuzFake3R8C" | ||
}, | ||
"source_transfer": null, | ||
"captured": true, | ||
"balance_transaction": "txn_180ZdUCry4Lot2g4vHVZH6y4A", | ||
"failure_message": null, | ||
"failure_code": null, | ||
"amount_refunded": 0, | ||
"customer": "cus_8GoWuzFake3R8C", | ||
"invoice": "in_180Z1234yC4r2g4vCYO4qcIY", | ||
"order": null, | ||
"description": null, | ||
"dispute": null, | ||
"metadata": {}, | ||
"statement_descriptor": "STATEMENT", | ||
"fraud_details": {}, | ||
"receipt_email": null, | ||
"receipt_number": null, | ||
"shipping": null, | ||
"destination": null, | ||
"application_fee": null, | ||
"refunds": { | ||
"object": "list", | ||
"total_count": 0, | ||
"has_more": false, | ||
"url": "/v1/charges/ch_180ZdUCryC0oikg4v4lc4F59D/refunds", | ||
"data": [] | ||
} | ||
} |