Skip to content

Commit

Permalink
added capture test example file
Browse files Browse the repository at this point in the history
  • Loading branch information
beinbm committed Aug 5, 2015
1 parent 6d56e45 commit 74df913
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest
*
* @var string URL
*/
protected $liveEndpoint = 'https://sandbox.checkout.com/api2/v2'; //https://api2.checkout.com/v2
protected $liveEndpoint = 'https://api2.checkout.com/v2';
protected $testEndpoint = 'https://sandbox.checkout.com/api2/v2';

public function setSecretApiKey($value)
Expand Down
54 changes: 54 additions & 0 deletions tests/Message/CaptureRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace Omnipay\CheckoutCom\Message;

use Omnipay\Tests\TestCase;

class CaptureRequestTest extends TestCase
{
public function setUp()
{
$this->request = new CaptureRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setTransactionReference('foo');
}

public function testEndpoint()
{
$this->assertSame('https://api2.checkout.com/v2/charges/foo', $this->request->getEndpoint());
}

public function testAmount()
{
// defualt is no amount
$this->assertArrayNotHasKey('amount', $this->request->getData());

$this->request->setAmount('10.00');

$data = $this->request->getData();
$this->assertSame(1000, $data['amount']);
}

public function testSendSuccess()
{
$this->setMockHttpResponse('CaptureSuccess.txt');
$response = $this->request->send();

$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('ch_1lvgjcQgrNWUuZ', $response->getTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertNull($response->getMessage());
}

public function testSendError()
{
$this->setMockHttpResponse('CaptureFailure.txt');
$response = $this->request->send();

$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertSame('Charge ch_1lvgjcQgrNWUuZ has already been captured.', $response->getMessage());
}
}
16 changes: 16 additions & 0 deletions tests/Mock/CaptureFailure.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
HTTP/1.1 400 Bad Request
Server: nginx
Date: Sun, 05 May 2013 08:52:09 GMT
Content-Type: application/json;charset=utf-8
Content-Length: 127
Connection: keep-alive
Cache-Control: no-cache, no-store
Access-Control-Max-Age: 300
Access-Control-Allow-Credentials: true

{
"error": {
"type": "invalid_request_error",
"message": "Charge ch_1lvgjcQgrNWUuZ has already been captured."
}
}
57 changes: 57 additions & 0 deletions tests/Mock/CaptureSuccess.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
HTTP/1.1 200 OK
Server: nginx
Date: Sun, 05 May 2013 08:51:15 GMT
Content-Type: application/json;charset=utf-8
Content-Length: 997
Connection: keep-alive
Cache-Control: no-cache, no-store
Access-Control-Max-Age: 300
Access-Control-Allow-Credentials: true

{
"id": "ch_1lvgjcQgrNWUuZ",
"object": "charge",
"created": 1367743707,
"livemode": false,
"paid": true,
"amount": 1000,
"currency": "usd",
"refunded": false,
"fee": 59,
"fee_details": [
{
"amount": 59,
"currency": "usd",
"type": "stripe_fee",
"description": "Stripe processing fees",
"application": null,
"amount_refunded": 0
}
],
"card": {
"object": "card",
"last4": "4242",
"type": "Visa",
"exp_month": 9,
"exp_year": 2015,
"fingerprint": "dfB0t0avO0bWr9eY",
"country": "US",
"name": "fdsa asdf",
"address_line1": "",
"address_line2": "",
"address_city": "",
"address_state": "",
"address_zip": "",
"address_country": "",
"cvc_check": "pass",
"address_line1_check": "pass",
"address_zip_check": "pass"
},
"captured": true,
"failure_message": null,
"amount_refunded": 0,
"customer": null,
"invoice": null,
"description": "",
"dispute": null
}

0 comments on commit 74df913

Please sign in to comment.