Skip to content

Commit 37cb9a8

Browse files
author
Andrew Keynes
committed
Add support for secureXML echo test messages
1 parent 16c7d9e commit 37cb9a8

9 files changed

+106
-8
lines changed

src/Message/SecureXMLAbstractRequest.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ abstract class SecureXMLAbstractRequest extends AbstractRequest
1010
public $testEndpoint = 'https://test.securepay.com.au/xmlapi/payment';
1111
public $liveEndpoint = 'https://api.securepay.com.au/xmlapi/payment';
1212

13+
protected $requestType = 'Payment';
14+
1315
/**
1416
* Set the messageID on the request.
1517
*
@@ -67,7 +69,19 @@ protected function getBaseXML()
6769
$merchantInfo->addChild('merchantID', $this->getMerchantId());
6870
$merchantInfo->addChild('password', $this->getTransactionPassword());
6971

70-
$xml->addChild('RequestType', 'Payment'); // Not related to the transaction type
72+
$xml->addChild('RequestType', $this->requestType); // Not related to the transaction type
73+
74+
return $xml;
75+
}
76+
77+
/**
78+
* XML template of a SecurePayMessage Payment.
79+
*
80+
* @return \SimpleXMLElement SecurePayMessage with transaction details.
81+
*/
82+
protected function getBasePaymentXML()
83+
{
84+
$xml = $this->getBaseXML();
7185

7286
$payment = $xml->addChild('Payment');
7387
$txnList = $payment->addChild('TxnList');
@@ -85,13 +99,14 @@ protected function getBaseXML()
8599
}
86100

87101
/**
88-
* @return \SimpleXMLElement SecurePayMessage with card details.
102+
* @return \SimpleXMLElement SecurePayMessage with transaction and card
103+
* details.
89104
*/
90-
protected function getBaseXMLWithCard()
105+
protected function getBasePaymentXMLWithCard()
91106
{
92107
$this->getCard()->validate();
93108

94-
$xml = $this->getBaseXML();
109+
$xml = $this->getBasePaymentXML();
95110

96111
$card = $xml->Payment->TxnList->Txn->addChild('CreditCardInfo');
97112
$card->addChild('cardNumber', $this->getCard()->getNumber());

src/Message/SecureXMLAuthorizeRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ class SecureXMLAuthorizeRequest extends SecureXMLAbstractRequest
1717

1818
public function getData()
1919
{
20-
return $this->getBaseXMLWithCard();
20+
return $this->getBasePaymentXMLWithCard();
2121
}
2222
}

src/Message/SecureXMLCaptureRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class SecureXMLCaptureRequest extends SecureXMLAbstractRequest
1818

1919
public function getData()
2020
{
21-
$xml = $this->getBaseXML();
21+
$xml = $this->getBasePaymentXML();
2222

2323
$xml->Payment->TxnList->Txn->addChild('preauthID', $this->getPreauthId());
2424

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Omnipay\SecurePay\Message;
4+
5+
/**
6+
* SecurePay SecureXML Echo Request.
7+
*
8+
* Echo requests are used to verify that the SecurePay payment server is
9+
* available.
10+
*
11+
* The status code returned in the response will be '000' if the service is up.
12+
*/
13+
class SecureXMLEchoTestRequest extends SecureXMLAbstractRequest
14+
{
15+
protected $requestType = 'Echo';
16+
protected $requiredFields = [];
17+
18+
public function getData()
19+
{
20+
return $this->getBaseXML();
21+
}
22+
}

src/Message/SecureXMLPurchaseRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ class SecureXMLPurchaseRequest extends SecureXMLAbstractRequest
1212

1313
public function getData()
1414
{
15-
return $this->getBaseXMLWithCard();
15+
return $this->getBasePaymentXMLWithCard();
1616
}
1717
}

src/Message/SecureXMLRefundRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class SecureXMLRefundRequest extends SecureXMLAbstractRequest
1717

1818
public function getData()
1919
{
20-
$xml = $this->getBaseXML();
20+
$xml = $this->getBasePaymentXML();
2121
$xml->Payment->TxnList->Txn->addChild('txnID', $this->getTransactionReference());
2222

2323
return $xml;

src/SecureXMLGateway.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,9 @@ public function refund(array $parameters = array())
102102
{
103103
return $this->createRequest('\Omnipay\SecurePay\Message\SecureXMLRefundRequest', $parameters);
104104
}
105+
106+
public function echoTest(array $parameters = array())
107+
{
108+
return $this->createRequest('\Omnipay\SecurePay\Message\SecureXMLEchoTestRequest', $parameters);
109+
}
105110
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Omnipay\SecurePay\Message;
4+
5+
use Omnipay\Tests\TestCase;
6+
7+
class SecureXMLEchoTestRequestTest extends TestCase
8+
{
9+
public function setUp()
10+
{
11+
$this->request = new SecureXMLEchoTestRequest($this->getHttpClient(), $this->getHttpRequest());
12+
13+
$this->request->initialize(
14+
array(
15+
'merchantId' => 'ABC0030',
16+
'transactionPassword' => 'abc123',
17+
)
18+
);
19+
}
20+
21+
public function testSuccess()
22+
{
23+
$this->setMockHttpResponse('SecureXMLEchoTestRequestSuccess.txt');
24+
$response = $this->request->send();
25+
$data = $response->getData();
26+
27+
$this->assertInstanceOf('Omnipay\\SecurePay\\Message\\SecureXMLResponse', $response);
28+
29+
$this->assertTrue($response->isSuccessful());
30+
$this->assertFalse($response->isRedirect());
31+
$this->assertSame('000', $response->getCode());
32+
$this->assertSame('Normal', $response->getMessage());
33+
}
34+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
HTTP/1.1 100 Continue
2+
Server: Microsoft-IIS/5.0
3+
Date: Mon, 19 Apr 2004 06:19:48 GMT
4+
HTTP/1.1 200 OK
5+
Server: Microsoft-IIS/5.0
6+
Date: Mon, 19 Apr 2004 06:20:01 GMT
7+
Content-Type: text/xml;charset=ISO-8859-1
8+
Content-Length: 929
9+
10+
<?xml version="1.0" encoding="UTF-8"?>
11+
<SecurePayMessage>
12+
<MessageInfo>
13+
<messageID>8af793f9af34bea0cf40f5fb79f383</messageID>
14+
<messageTimestamp>20042403095956732000+660</messageTimestamp>
15+
<apiVersion>xml-4.2</apiVersion>
16+
</MessageInfo>
17+
<RequestType>Echo</RequestType>
18+
<Status>
19+
<statusCode>000</statusCode>
20+
<statusDescription>Normal</statusDescription>
21+
</Status>
22+
</SecurePayMessage>

0 commit comments

Comments
 (0)