diff --git a/README.md b/README.md index 6bad99a5..5c996829 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ to your `composer.json` file: ```json { "require": { - "dercoder/omnipay-ecopayz": "~1.0" + "dercoder/omnipay-ecopayz": "~2.0.x-dev" } } ``` diff --git a/composer.json b/composer.json index 2933d767..cb73f953 100644 --- a/composer.json +++ b/composer.json @@ -16,15 +16,16 @@ "psr-0": { "Omnipay\\Ecopayz\\" : "src/" } }, "require": { - "omnipay/common": "~2.3" + "omnipay/common": "^3.0" }, "require-dev": { - "omnipay/tests": "~2.0", - "satooshi/php-coveralls": "1.0.0" + "omnipay/tests": "^3.0.0", + "php-coveralls/php-coveralls": "^2.4.0", + "squizlabs/php_codesniffer": "3.*" }, "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "2.0.x-dev" } } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index ad0befd1..da14877a 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -14,9 +14,6 @@ ./tests/ - - - ./src diff --git a/src/Omnipay/Ecopayz/Message/AbstractRequest.php b/src/Omnipay/Ecopayz/Message/AbstractRequest.php index a21aea85..dfcaa703 100644 --- a/src/Omnipay/Ecopayz/Message/AbstractRequest.php +++ b/src/Omnipay/Ecopayz/Message/AbstractRequest.php @@ -16,14 +16,14 @@ abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest * * @var string URL */ - protected $testEndpoint = 'https://secure.test.ecopayz.com/services/MerchantAPI/MerchantAPIService.asmx'; + protected $testEndpoint = 'https://merchantapi.test.payz.com/MerchantAPIService.asmx'; /** * Live Endpoint URL * * @var string URL */ - protected $liveEndpoint = 'https://secure.ecopayz.com/services/MerchantAPI/MerchantAPIService.asmx'; + protected $liveEndpoint = 'https://merchantapi.payz.com/MerchantAPIService.asmx'; /** * Get the Merchant ID diff --git a/src/Omnipay/Ecopayz/Message/CompletePurchaseRequest.php b/src/Omnipay/Ecopayz/Message/CompletePurchaseRequest.php index 911dbea9..4e599be3 100644 --- a/src/Omnipay/Ecopayz/Message/CompletePurchaseRequest.php +++ b/src/Omnipay/Ecopayz/Message/CompletePurchaseRequest.php @@ -27,20 +27,15 @@ public function getData() ); if ($xml = $this->httpRequest->request->get('XML')) { - if (!$this->validateChecksum($xml)) { throw new InvalidRequestException('Invalid XML checksum'); } return new \SimpleXMLElement($xml); - } elseif ($xml = $this->httpRequest->getContent()) { return new \SimpleXMLElement($xml); - } else { - throw new InvalidRequestException('Missing XML'); - } } @@ -53,7 +48,6 @@ public function getData() public function sendData($data) { if (isset($data->StatusReport)) { - if (in_array($data->StatusReport->Status, array(1, 2, 3))) { $response = $this->createResponse('OK', 0, 'OK'); } elseif (in_array($data->StatusReport->Status, array(4, 5))) { @@ -65,7 +59,6 @@ public function sendData($data) header('Content-Type: text/xml; charset=utf-8'); echo $response; die(); - } else { return new CompletePurchaseResponse($this, $data); } diff --git a/src/Omnipay/Ecopayz/Message/FetchTransactionRequest.php b/src/Omnipay/Ecopayz/Message/FetchTransactionRequest.php index 3c5e3616..53a06df2 100644 --- a/src/Omnipay/Ecopayz/Message/FetchTransactionRequest.php +++ b/src/Omnipay/Ecopayz/Message/FetchTransactionRequest.php @@ -1,4 +1,5 @@ getTransactionReference()) { - $query = $body->appendChild( $document->createElement('q0:QueryBySVSTransactionID') ); @@ -63,9 +63,7 @@ public function getData() $request->appendChild( $document->createElement('q0:SVSTxID', $transactionReference) ); - } elseif ($transactionId = $this->getTransactionId()) { - $query = $body->appendChild( $document->createElement('q0:QueryByCustomerTransactionID') ); @@ -85,11 +83,8 @@ public function getData() $request->appendChild( $document->createElement('q0:TxID', $transactionId) ); - } else { - throw new InvalidRequestException('The transactionId or transactionReference parameter is required'); - } return $document->saveXML(); @@ -98,23 +93,21 @@ public function getData() /** * Send the request with specified data * - * @param mixed $data The data to send - * @throws InvalidResponseException - * @throws InvalidRequestException + * @param mixed $data The data to send * @return FetchTransactionResponse + * @throws InvalidRequestException + * @throws InvalidResponseException */ public function sendData($data) { if (strpos($data, 'QueryBySVSTransactionID') !== false) { - $headers = array( 'Content-Type' => 'text/xml; charset=utf-8', 'SOAPAction' => 'http://www.ecocard.com/merchantAPI/QueryBySVSTransactionID' ); - $httpRequest = $this->httpClient->createRequest('POST', $this->getEndpoint(), $headers, $data); - $httpResponse = $httpRequest->send(); - $xmlResponse = $httpResponse->xml() + $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, $data); + $xmlResponse = simplexml_load_string($httpResponse->getBody()->getContents()) ->children('http://schemas.xmlsoap.org/soap/envelope/') ->children('http://www.ecocard.com/merchantAPI/'); @@ -132,17 +125,14 @@ public function sendData($data) ->QueryBySVSTransactionIDResponse ->TransactionResponse ); - } elseif (strpos($data, 'QueryByCustomerTransactionID') !== false) { - $headers = array( 'Content-Type' => 'text/xml; charset=utf-8', 'SOAPAction' => 'http://www.ecocard.com/merchantAPI/QueryByCustomerTransactionID' ); - $httpRequest = $this->httpClient->createRequest('POST', $this->getEndpoint(), $headers, $data); - $httpResponse = $httpRequest->send(); - $xmlResponse = $httpResponse->xml() + $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, $data); + $xmlResponse = simplexml_load_string($httpResponse->getBody()->getContents()) ->children('http://schemas.xmlsoap.org/soap/envelope/') ->children('http://www.ecocard.com/merchantAPI/'); @@ -160,11 +150,8 @@ public function sendData($data) ->QueryByCustomerTransactionIDResponse ->TransactionResponse ); - } else { - throw new InvalidRequestException('The transactionId or transactionReference parameter is required'); - } } } diff --git a/src/Omnipay/Ecopayz/Message/PayoutRequest.php b/src/Omnipay/Ecopayz/Message/PayoutRequest.php index db74a59a..41a27783 100644 --- a/src/Omnipay/Ecopayz/Message/PayoutRequest.php +++ b/src/Omnipay/Ecopayz/Message/PayoutRequest.php @@ -159,9 +159,8 @@ public function sendData($data) 'SOAPAction' => 'http://www.ecocard.com/merchantAPI/Payout' ); - $httpRequest = $this->httpClient->createRequest('POST', $this->getEndpoint(), $headers, $data); - $httpResponse = $httpRequest->send(); - $xmlResponse = $httpResponse->xml() + $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, $data); + $xmlResponse = simplexml_load_string($httpResponse->getBody()->getContents()) ->children('http://schemas.xmlsoap.org/soap/envelope/') ->children('http://www.ecocard.com/merchantAPI/'); diff --git a/src/Omnipay/Ecopayz/Message/PurchaseResponse.php b/src/Omnipay/Ecopayz/Message/PurchaseResponse.php index 9137bab8..9083925c 100644 --- a/src/Omnipay/Ecopayz/Message/PurchaseResponse.php +++ b/src/Omnipay/Ecopayz/Message/PurchaseResponse.php @@ -16,8 +16,10 @@ */ class PurchaseResponse extends AbstractResponse implements RedirectResponseInterface { - protected $testEndpoint = 'https://secure.test.ecopayz.com/PrivateArea/WithdrawOnlineTransfer.aspx'; - protected $liveEndpoint = 'https://secure.ecopayz.com/PrivateArea/WithdrawOnlineTransfer.aspx'; + protected $testEndpoint = 'https://myaccount.test.payz.com/purchase/create'; + protected $liveEndpoint = 'https://myaccount.payz.com/purchase/create'; + protected $testRedirectEndpoint = 'https://myaccount.test.payz.com/purchase/request'; + protected $redirectEndpoint = 'https://myaccount.payz.com/purchase/request'; public function __construct(RequestInterface $request, $data) { @@ -37,7 +39,7 @@ public function isRedirect() public function getRedirectUrl() { - return $this->getEndpoint() . '?' . http_build_query($this->data, '', '&'); + return $this->getRedirectEndpoint() . '?' . http_build_query($this->data, '', '&'); } public function getRedirectMethod() @@ -54,4 +56,9 @@ protected function getEndpoint() { return $this->getRequest()->getTestMode() ? $this->testEndpoint : $this->liveEndpoint; } + + protected function getRedirectEndpoint() + { + return $this->getRequest()->getTestMode() ? $this->testRedirectEndpoint : $this->redirectEndpoint; + } } diff --git a/tests/Omnipay/Ecopayz/Message/PurchaseResponseTest.php b/tests/Omnipay/Ecopayz/Message/PurchaseResponseTest.php index 8158a8b9..326ab1ea 100644 --- a/tests/Omnipay/Ecopayz/Message/PurchaseResponseTest.php +++ b/tests/Omnipay/Ecopayz/Message/PurchaseResponseTest.php @@ -25,7 +25,7 @@ public function testResult() $this->assertTrue($response->isRedirect()); $this->assertNull($response->getCode()); $this->assertNull($response->getMessage()); - $this->assertSame('https://secure.ecopayz.com/PrivateArea/WithdrawOnlineTransfer.aspx?PaymentPageID=100&MerchantAccountNumber=100001&CustomerIdAtMerchant=1123456789&TxID=TX4567890&Amount=12.34&Currency=EUR&MerchantFreeText=Free+Text+Description&Checksum=84bbad2a636aa9226c03f17ff813a181', $response->getRedirectUrl()); + $this->assertSame('https://myaccount.payz.com/purchase/request?PaymentPageID=100&MerchantAccountNumber=100001&CustomerIdAtMerchant=1123456789&TxID=TX4567890&Amount=12.34&Currency=EUR&MerchantFreeText=Free+Text+Description&Checksum=84bbad2a636aa9226c03f17ff813a181', $response->getRedirectUrl()); $this->assertSame('GET', $response->getRedirectMethod()); $this->assertNull($response->getRedirectData()); }