Skip to content

Commit a9f01ba

Browse files
johnkaryamacneil
authored andcommitted
Add more tests. Refs #125
1 parent 22fd000 commit a9f01ba

13 files changed

+403
-7
lines changed

src/Omnipay/PayPal/Message/AbstractRequest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest
1818
{
19+
const API_VERSION = '85.0';
20+
1921
protected $liveEndpoint = 'https://api-3t.paypal.com/nvp';
2022
protected $testEndpoint = 'https://api-3t.sandbox.paypal.com/nvp';
2123

@@ -93,7 +95,7 @@ protected function getBaseData($method)
9395
{
9496
$data = array();
9597
$data['METHOD'] = $method;
96-
$data['VERSION'] = '85.0';
98+
$data['VERSION'] = static::API_VERSION;
9799
$data['USER'] = $this->getUsername();
98100
$data['PWD'] = $this->getPassword();
99101
$data['SIGNATURE'] = $this->getSignature();

tests/Omnipay/CardSave/GatewayTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public function setUp()
3232
'expiryMonth' => '12',
3333
'expiryYear' => '2016',
3434
'cvv' => '123',
35+
'issueNumber' => '5',
36+
'startMonth' => '4',
37+
'startYear' => '2013',
3538
)),
3639
);
3740
}

tests/Omnipay/CardSave/Message/ResponseTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,20 @@
1111

1212
namespace Omnipay\CardSave\Message;
1313

14+
use Mockery as m;
1415
use Omnipay\TestCase;
1516

1617
class ResponseTest extends TestCase
1718
{
19+
/**
20+
* @expectedException \Omnipay\Common\Exception\InvalidResponseException
21+
*/
22+
public function testPurchaseWithoutStatusCode()
23+
{
24+
$httpResponse = $this->getMockHttpResponse('PurchaseFailureWithoutStatusCode.txt');
25+
new Response($this->getMockRequest(), $httpResponse->getBody());
26+
}
27+
1828
public function testPurchaseSuccess()
1929
{
2030
$httpResponse = $this->getMockHttpResponse('PurchaseSuccess.txt');
@@ -23,6 +33,7 @@ public function testPurchaseSuccess()
2333
$this->assertTrue($response->isSuccessful());
2434
$this->assertEquals('130215141054377801316798', $response->getTransactionReference());
2535
$this->assertSame('AuthCode: 672167', $response->getMessage());
36+
$this->assertEmpty($response->getRedirectUrl());
2637
}
2738

2839
public function testPurchaseFailure()
@@ -34,4 +45,25 @@ public function testPurchaseFailure()
3445
$this->assertSame('', $response->getTransactionReference());
3546
$this->assertSame('Input variable errors', $response->getMessage());
3647
}
48+
49+
public function testRedirect()
50+
{
51+
$httpResponse = $this->getMockHttpResponse('PurchaseRedirect.txt');
52+
53+
$request = m::mock('\Omnipay\Common\Message\AbstractRequest');
54+
$request->shouldReceive('getReturnUrl')->once()->andReturn('http://store.example.com/');
55+
56+
$response = new Response($request, $httpResponse->getBody());
57+
58+
$this->assertTrue($response->isRedirect());
59+
$this->assertSame('POST', $response->getRedirectMethod());
60+
$this->assertSame('http://some.redirect.com/', $response->getRedirectUrl());
61+
62+
$expectedData = array(
63+
'PaReq' => 'Some PaREQ',
64+
'TermUrl' => 'http://store.example.com/',
65+
'MD' => '130215141054377801316798',
66+
);
67+
$this->assertEquals($expectedData, $response->getRedirectData());
68+
}
3769
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
HTTP/1.1 200 OK
2+
Cache-Control: private, max-age=0
3+
Content-Length: 689
4+
Content-Type: text/xml; charset=utf-8
5+
Node: VENUS
6+
X-Powered-By: ASP.NET
7+
X-AspNet-Version: 4.0.30319
8+
Date: Fri, 15 Feb 2013 14:06:34 GMT
9+
10+
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><CardDetailsTransactionResponse xmlns="https://www.thepaymentgateway.net/"><CardDetailsTransactionResult AuthorisationAttempted="False"><Message>Input variable errors</Message><ErrorMessages><MessageDetail><Detail>Required variable (PaymentMessage.TransactionDetails.OrderID) is missing</Detail></MessageDetail></ErrorMessages></CardDetailsTransactionResult><TransactionOutputData /></CardDetailsTransactionResponse></soap:Body></soap:Envelope>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
HTTP/1.1 200 OK
2+
Cache-Control: private, max-age=0
3+
Content-Length: 944
4+
Content-Type: text/xml; charset=utf-8
5+
Node: VENUS
6+
X-Powered-By: ASP.NET
7+
X-AspNet-Version: 4.0.30319
8+
Date: Fri, 15 Feb 2013 14:10:53 GMT
9+
10+
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><CardDetailsTransactionResponse xmlns="https://www.thepaymentgateway.net/"><CardDetailsTransactionResult AuthorisationAttempted="True"><StatusCode>3</StatusCode><Message>AuthCode: 672167</Message></CardDetailsTransactionResult><TransactionOutputData CrossReference="130215141054377801316798"><AuthCode>672167</AuthCode><ThreeDSecureOutputData><ACSURL>http://some.redirect.com/</ACSURL><PaREQ>Some PaREQ</PaREQ></ThreeDSecureOutputData><ThreeDSecureAuthenticationCheckResult>NOT_ENROLLED</ThreeDSecureAuthenticationCheckResult><GatewayEntryPoints><GatewayEntryPoint EntryPointURL="https://gw1.cardsaveonlinepayments.com:4430/" Metric="100" /><GatewayEntryPoint EntryPointURL="https://gw2.cardsaveonlinepayments.com:4430/" Metric="200" /></GatewayEntryPoints></TransactionOutputData></CardDetailsTransactionResponse></soap:Body></soap:Envelope>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Omnipay\Netaxept\Message;
4+
5+
use Omnipay\TestCase;
6+
7+
class CompletePurchaseRequestTest extends TestCase
8+
{
9+
/**
10+
* @var \Symfony\Component\HttpFoundation\Request
11+
*/
12+
private $httpRequest;
13+
14+
/**
15+
* @var \Omnipay\Netaxept\Message\CompletePurchaseRequest
16+
*/
17+
private $request;
18+
19+
public function setUp()
20+
{
21+
$client = $this->getHttpClient();
22+
$this->httpRequest = $this->getHttpRequest();
23+
24+
$this->request = new CompletePurchaseRequest($client, $this->httpRequest);
25+
}
26+
27+
/**
28+
* @expectedException \Omnipay\Common\Exception\InvalidResponseException
29+
*/
30+
public function testGetDataThrowsExceptionWithoutResponseCode()
31+
{
32+
$this->httpRequest->query->set('transactionId', 'TRANS-123');
33+
34+
$this->request->getData();
35+
}
36+
37+
/**
38+
* @expectedException \Omnipay\Common\Exception\InvalidResponseException
39+
*/
40+
public function testGetDataThrowsExceptionWithoutTransactionId()
41+
{
42+
$this->httpRequest->query->set('responseCode', 'ABC-123');
43+
44+
$this->request->getData();
45+
}
46+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
namespace Omnipay\Netaxept\Message;
4+
5+
use Omnipay\Common\CreditCard;
6+
use Omnipay\TestCase;
7+
8+
class PurchaseRequestTest extends TestCase
9+
{
10+
/**
11+
* @var \Omnipay\Netaxept\Message\PurchaseRequest
12+
*/
13+
private $request;
14+
15+
public function setUp()
16+
{
17+
$client = $this->getHttpClient();
18+
$request = $this->getHttpRequest();
19+
20+
$this->request = new PurchaseRequest($client, $request);
21+
}
22+
23+
public function testGetDataWithCard()
24+
{
25+
$this->request->setMerchantId('MERCH-123');
26+
$this->request->setPassword('PASSWORD-123');
27+
$this->request->setAmount('1.23');
28+
$this->request->setCurrency('USD');
29+
$this->request->setTransactionId('ABC-123');
30+
$this->request->setReturnUrl('http://return.domain.com/');
31+
32+
$card = new CreditCard(array(
33+
'firstName' => 'John',
34+
'lastName' => 'Doe',
35+
'email' => '[email protected]',
36+
'phone' => '555-555-5555',
37+
'address1' => '123 NW Blvd',
38+
'address2' => 'Lynx Lane',
39+
'postcode' => '66605',
40+
'city' => 'Topeka',
41+
'country' => 'USA',
42+
));
43+
$this->request->setCard($card);
44+
45+
$expected = array(
46+
'merchantId' => 'MERCH-123',
47+
'token' => 'PASSWORD-123',
48+
'serviceType' => 'B',
49+
'orderNumber' => 'ABC-123',
50+
'currencyCode' => 'USD',
51+
'amount' => 123,
52+
'redirectUrl' => 'http://return.domain.com/',
53+
'customerFirstName' => 'John',
54+
'customerLastName' => 'Doe',
55+
'customerEmail' => '[email protected]',
56+
'customerPhoneNumber' => '555-555-5555',
57+
'customerAddress1' => '123 NW Blvd',
58+
'customerAddress2' => 'Lynx Lane',
59+
'customerPostcode' => '66605',
60+
'customerTown' => 'Topeka',
61+
'customerCountry' => 'USA',
62+
);
63+
64+
$this->assertEquals($expected, $this->request->getData());
65+
}
66+
}

tests/Omnipay/Netaxept/Message/ResponseTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public function testPurchaseFailure()
3333

3434
$this->assertFalse($response->isSuccessful());
3535
$this->assertFalse($response->isRedirect());
36+
$this->assertNull($response->getRedirectUrl());
37+
$this->assertNull($response->getRedirectData());
3638
$this->assertNull($response->getTransactionReference());
3739
$this->assertSame("Missing parameter: 'Order Number'", $response->getMessage());
3840
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Omnipay\PayPal\Message;
4+
5+
use Omnipay\PayPal\Message\CaptureRequest;
6+
use Omnipay\TestCase;
7+
8+
class CaptureRequestTest extends TestCase
9+
{
10+
/**
11+
* @var \Omnipay\PayPal\Message\CaptureRequest
12+
*/
13+
private $request;
14+
15+
public function setUp()
16+
{
17+
$client = $this->getHttpClient();
18+
$request = $this->getHttpRequest();
19+
$this->request = new CaptureRequest($client, $request);
20+
}
21+
22+
public function testGetData()
23+
{
24+
$this->request->setTransactionReference('ABC-123');
25+
$this->request->setAmount('1.23');
26+
$this->request->setCurrency('USD');
27+
$this->request->setUsername('testuser');
28+
$this->request->setPassword('testpass');
29+
$this->request->setSignature('SIG');
30+
$this->request->setSubject('SUB');
31+
32+
$expected = array();
33+
$expected['METHOD'] = 'DoCapture';
34+
$expected['AUTHORIZATIONID'] = 'ABC-123';
35+
$expected['AMT'] = '1.23';
36+
$expected['CURRENCYCODE'] = 'USD';
37+
$expected['COMPLETETYPE'] = 'Complete';
38+
$expected['USER'] = 'testuser';
39+
$expected['PWD'] = 'testpass';
40+
$expected['SIGNATURE'] = 'SIG';
41+
$expected['SUBJECT'] = 'SUB';
42+
$expected['VERSION'] = CaptureRequest::API_VERSION;
43+
44+
$this->assertEquals($expected, $this->request->getData());
45+
}
46+
}

tests/Omnipay/PayPal/Message/ExpressAuthorizeRequestTest.php

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Omnipay\PayPal\Message;
1313

14+
use Omnipay\Common\CreditCard;
1415
use Omnipay\TestCase;
1516

1617
class ExpressAuthorizeRequestTest extends TestCase
@@ -29,7 +30,7 @@ public function setUp()
2930
);
3031
}
3132

32-
public function testGetData()
33+
public function testGetDataWithoutCard()
3334
{
3435
$this->request->initialize(array(
3536
'amount' => '10.00',
@@ -56,6 +57,67 @@ public function testGetData()
5657
$this->assertSame('https://www.example.com/header.jpg', $data['HDRIMG']);
5758
}
5859

60+
public function testGetDataWitCard()
61+
{
62+
$this->request->initialize(array(
63+
'amount' => '10.00',
64+
'currency' => 'AUD',
65+
'transactionId' => '111',
66+
'description' => 'Order Description',
67+
'returnUrl' => 'https://www.example.com/return',
68+
'cancelUrl' => 'https://www.example.com/cancel',
69+
'notifyUrl' => 'https://www.example.com/notify',
70+
'subject' => '[email protected]',
71+
'headerImageUrl' => 'https://www.example.com/header.jpg',
72+
));
73+
74+
$card = new CreditCard(array(
75+
'name' => 'John Doe',
76+
'address1' => '123 NW Blvd',
77+
'address2' => 'Lynx Lane',
78+
'city' => 'Topeka',
79+
'state' => 'KS',
80+
'country' => 'USA',
81+
'postcode' => '66605',
82+
'phone' => '555-555-5555',
83+
'email' => '[email protected]',
84+
));
85+
$this->request->setCard($card);
86+
87+
$expected = array(
88+
'METHOD' => 'SetExpressCheckout',
89+
'VERSION' => ExpressAuthorizeRequest::API_VERSION,
90+
'USER' => null,
91+
'PWD' => null,
92+
'SIGNATURE' => null,
93+
'PAYMENTREQUEST_0_PAYMENTACTION' => 'Authorization',
94+
'SOLUTIONTYPE' => null,
95+
'LANDINGPAGE' => null,
96+
'NOSHIPPING' => 1,
97+
'ALLOWNOTE' => 0,
98+
'PAYMENTREQUEST_0_AMT' => '10.00',
99+
'PAYMENTREQUEST_0_CURRENCYCODE' => 'AUD',
100+
'PAYMENTREQUEST_0_INVNUM' => '111',
101+
'PAYMENTREQUEST_0_DESC' => 'Order Description',
102+
'RETURNURL' => 'https://www.example.com/return',
103+
'CANCELURL' => 'https://www.example.com/cancel',
104+
'PAYMENTREQUEST_0_NOTIFYURL' => 'https://www.example.com/notify',
105+
'SUBJECT' => '[email protected]',
106+
'HDRIMG' => 'https://www.example.com/header.jpg',
107+
'PAYMENTREQUEST_0_SHIPTONAME' => 'John Doe',
108+
'PAYMENTREQUEST_0_SHIPTOSTREET' => '123 NW Blvd',
109+
'PAYMENTREQUEST_0_SHIPTOSTREET2' => 'Lynx Lane',
110+
'PAYMENTREQUEST_0_SHIPTOCITY' => 'Topeka',
111+
'PAYMENTREQUEST_0_SHIPTOSTATE' => 'KS',
112+
'PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE' => 'USA',
113+
'PAYMENTREQUEST_0_SHIPTOZIP' => '66605',
114+
'PAYMENTREQUEST_0_SHIPTOPHONENUM' => '555-555-5555',
115+
'EMAIL' => '[email protected]',
116+
);
117+
118+
$this->assertEquals($expected, $this->request->getData());
119+
}
120+
59121
public function testHeaderImageUrl()
60122
{
61123
$this->assertSame($this->request, $this->request->setHeaderImageUrl('https://www.example.com/header.jpg'));

0 commit comments

Comments
 (0)