diff --git a/.travis.yml b/.travis.yml index 67753ce..7eaadb3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,11 @@ language: php php: - - 5.3 - - 5.4 - - 5.5 - 5.6 - - hhvm + - 7.0 + - 7.1 + - 7.2 + - 7.3 before_script: - composer install -n --dev --prefer-source diff --git a/README.md b/README.md index ecfc9fa..20da931 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,9 @@ [![Total Downloads](https://poser.pugx.org/omnipay/pin/d/total.png)](https://packagist.org/packages/omnipay/pin) [Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment -processing library for PHP 5.3+. This package implements [Pin](https://pin.net.au/) support for Omnipay. +processing library for PHP 5.3+. This package implements [Pin](https://pinpayments.com/) support for Omnipay. -[Pin Payments](https://pin.net.au/) is an Australian all-in-one payment system, allowing you +[Pin Payments](https://pinpayments.com/) is an Australian all-in-one payment system, allowing you to accept multi-currency credit card payments without a security deposit or a merchant account. @@ -21,7 +21,7 @@ to your `composer.json` file: ```json { "require": { - "omnipay/pin": "~2.0" + "omnipay/pin": "~3.0" } } ``` diff --git a/composer.json b/composer.json index 1b861c6..89d05dd 100644 --- a/composer.json +++ b/composer.json @@ -26,14 +26,15 @@ "psr-4": { "Omnipay\\Pin\\" : "src/" } }, "require": { - "omnipay/common": "~2.0" + "omnipay/common": "~3.0" }, "require-dev": { - "omnipay/tests": "~2.0" + "omnipay/tests": "~3.0", + "squizlabs/php_codesniffer": "^3" }, "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "3.0.x-dev" } } } diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index 3b0b133..767aecc 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -40,14 +40,14 @@ abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest * * @var string URL */ - protected $testEndpoint = 'https://test-api.pin.net.au/'; + protected $testEndpoint = 'https://test-api.pinpayments.com/'; /** * Live Endpoint URL * * @var string URL */ - protected $liveEndpoint = 'https://api.pin.net.au/'; + protected $liveEndpoint = 'https://api.pinpayments.com/'; /** * Get secret key @@ -119,24 +119,14 @@ protected function getEndpoint() * * @return HttpResponse */ - public function sendRequest($action, $data = null, $method = RequestInterface::POST) + public function sendRequest($action, $data = null, $method = 'POST') { - // don't throw exceptions for 4xx errors - $this->httpClient->getEventDispatcher()->addListener( - 'request.error', - function ($event) { - if ($event['response']->isClientError()) { - $event->stopPropagation(); - } - } - ); - - // Return the response we get back from Pin Payments - return $this->httpClient->createRequest( + $body = $data ? http_build_query($data) : null; + return $this->httpClient->request( $method, $this->getEndpoint() . $action, array('Authorization' => 'Basic ' . base64_encode($this->getSecretKey() . ':')), - $data - )->send(); + $body + ); } } diff --git a/src/Message/AuthorizeRequest.php b/src/Message/AuthorizeRequest.php index ae76766..bae7e2a 100644 --- a/src/Message/AuthorizeRequest.php +++ b/src/Message/AuthorizeRequest.php @@ -16,26 +16,26 @@ * * Gateway Parameters * - * * email Email address of the customer. Obtained from the card data. - * * description Description of the item purchased (e.g. "500g of single origin beans"). - * * amount Amount to charge in the currency’s base unit (e.g. cents + * * email Email address of the customer. Obtained from the card data. + * * description Description of the item purchased (e.g. "500g of single origin beans"). + * * amount Amount to charge in the currency’s base unit (e.g. cents * for AUD, yen for JPY). There is a minimum charge amount for each * currency; refer to the documentation on supported currencies. - * * ip_address IP address of the person submitting the payment. + * * ip_address IP address of the person submitting the payment. * Obtained from getClientIp. - * * Optional currency The three-character ISO 4217 currency code of one + * * Optional currency The three-character ISO 4217 currency code of one * of our supported currencies, e.g. AUD or USD. Default value is "AUD". - * * Optional capture Whether or not to immediately capture the charge + * * Optional capture Whether or not to immediately capture the charge * ("true" or "false"). If capture is false an authorisation is created. * Later you can capture. Authorised charges automatically expire after * 5 days. Default value is "true". * * and one of the following: * - * * card The full details of the credit card to be charged (CreditCard object) - * * card_token Token of the card to be charged, as returned from the card + * * card The full details of the credit card to be charged (CreditCard object) + * * card_token Token of the card to be charged, as returned from the card * tokens API or customer API. - * * customer_token Token of the customer to be charged, as returned + * * customer_token Token of the customer to be charged, as returned * from the customers API. * * ### Example diff --git a/src/Message/CaptureRequest.php b/src/Message/CaptureRequest.php index 028ee64..4a1cb77 100644 --- a/src/Message/CaptureRequest.php +++ b/src/Message/CaptureRequest.php @@ -27,8 +27,8 @@ public function sendData($data) $httpResponse = $this->sendRequest( '/charges/' . $this->getTransactionReference() . '/capture', $data, - RequestInterface::PUT + 'PUT' ); - return $this->response = new CaptureResponse($this, $httpResponse->json()); + return $this->response = new CaptureResponse($this, $httpResponse->getBody()->getContents()); } } diff --git a/src/Message/CreateCardRequest.php b/src/Message/CreateCardRequest.php index 2fc759d..08fc796 100644 --- a/src/Message/CreateCardRequest.php +++ b/src/Message/CreateCardRequest.php @@ -95,6 +95,6 @@ public function sendData($data) { $httpResponse = $this->sendRequest('/cards', $data); - return $this->response = new Response($this, $httpResponse->json()); + return $this->response = new Response($this, $httpResponse->getBody()->getContents()); } } diff --git a/src/Message/CreateCustomerRequest.php b/src/Message/CreateCustomerRequest.php index bfc61af..35195af 100644 --- a/src/Message/CreateCustomerRequest.php +++ b/src/Message/CreateCustomerRequest.php @@ -17,7 +17,7 @@ * The card object in returned customer information represents * this primary card. It contains a member called primary, * which says whether the card is a customer’s primary card; - * its value will always be true. + * its value will always be true. * * Example: * @@ -100,6 +100,6 @@ public function sendData($data) { $httpResponse = $this->sendRequest('/customers', $data); - return $this->response = new Response($this, $httpResponse->json()); + return $this->response = new Response($this, $httpResponse->getBody()->getContents()); } } diff --git a/src/Message/PurchaseRequest.php b/src/Message/PurchaseRequest.php index e354867..c293b24 100644 --- a/src/Message/PurchaseRequest.php +++ b/src/Message/PurchaseRequest.php @@ -16,26 +16,26 @@ * * Gateway Parameters * - * * email Email address of the customer. Obtained from the card data. - * * description Description of the item purchased (e.g. "500g of single origin beans"). - * * amount Amount to charge in the currency’s base unit (e.g. cents + * * email Email address of the customer. Obtained from the card data. + * * description Description of the item purchased (e.g. "500g of single origin beans"). + * * amount Amount to charge in the currency’s base unit (e.g. cents * for AUD, yen for JPY). There is a minimum charge amount for each * currency; refer to the documentation on supported currencies. - * * ip_address IP address of the person submitting the payment. + * * ip_address IP address of the person submitting the payment. * Obtained from getClientIp. - * * Optional currency The three-character ISO 4217 currency code of one + * * Optional currency The three-character ISO 4217 currency code of one * of our supported currencies, e.g. AUD or USD. Default value is "AUD". - * * Optional capture Whether or not to immediately capture the charge + * * Optional capture Whether or not to immediately capture the charge * ("true" or "false"). If capture is false an authorisation is created. * Later you can capture. Authorised charges automatically expire after * 5 days. Default value is "true". * * and one of the following: * - * * card The full details of the credit card to be charged (CreditCard object) - * * card_token Token of the card to be charged, as returned from the card + * * card The full details of the credit card to be charged (CreditCard object) + * * card_token Token of the card to be charged, as returned from the card * tokens API or customer API. - * * customer_token Token of the customer to be charged, as returned + * * customer_token Token of the customer to be charged, as returned * from the customers API. * * Example: @@ -157,7 +157,7 @@ public function sendData($data) { $httpResponse = $this->sendRequest('/charges', $data); - return $this->response = new Response($this, $httpResponse->json()); + return $this->response = new Response($this, $httpResponse->getBody()->getContents()); } /** diff --git a/src/Message/RefundRequest.php b/src/Message/RefundRequest.php index 8004e82..7d3e639 100644 --- a/src/Message/RefundRequest.php +++ b/src/Message/RefundRequest.php @@ -50,6 +50,6 @@ public function sendData($data) { $httpResponse = $this->sendRequest('/charges/' . $this->getTransactionReference() . '/refunds', $data); - return $this->response = new Response($this, $httpResponse->json()); + return $this->response = new Response($this, $httpResponse->getBody()->getContents()); } } diff --git a/src/Message/Response.php b/src/Message/Response.php index c7f4e38..176a416 100644 --- a/src/Message/Response.php +++ b/src/Message/Response.php @@ -6,6 +6,7 @@ namespace Omnipay\Pin\Message; use Omnipay\Common\Message\AbstractResponse; +use Omnipay\Common\Message\RequestInterface; /** * Pin Response @@ -16,6 +17,15 @@ */ class Response extends AbstractResponse { + public function __construct(RequestInterface $request, $data, $decode = true) + { + parent::__construct($request, $data); + + if ($decode) { + $this->data = json_decode($data, true); + } + } + public function isSuccessful() { return !isset($this->data['error']); diff --git a/tests/Message/CaptureResponseTest.php b/tests/Message/CaptureResponseTest.php index 49bc8c0..8248580 100644 --- a/tests/Message/CaptureResponseTest.php +++ b/tests/Message/CaptureResponseTest.php @@ -9,7 +9,7 @@ class CaptureResponseTest extends TestCase public function testCaptureSuccess() { $httpResponse = $this->getMockHttpResponse('CaptureSuccess.txt'); - $response = new CaptureResponse($this->getMockRequest(), $httpResponse->json()); + $response = new CaptureResponse($this->getMockRequest(), $httpResponse->getBody()->getContents()); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); @@ -20,7 +20,7 @@ public function testCaptureSuccess() public function testCaptureFailure() { $httpResponse = $this->getMockHttpResponse('CaptureFailure.txt'); - $response = new CaptureResponse($this->getMockRequest(), $httpResponse->json()); + $response = new CaptureResponse($this->getMockRequest(), $httpResponse->getBody()->getContents()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); diff --git a/tests/Message/ResponseTest.php b/tests/Message/ResponseTest.php index dc60b43..c670166 100644 --- a/tests/Message/ResponseTest.php +++ b/tests/Message/ResponseTest.php @@ -9,7 +9,7 @@ class ResponseTest extends TestCase public function testPurchaseSuccess() { $httpResponse = $this->getMockHttpResponse('PurchaseSuccess.txt'); - $response = new Response($this->getMockRequest(), $httpResponse->json()); + $response = new Response($this->getMockRequest(), $httpResponse->getBody()->getContents()); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); @@ -20,7 +20,7 @@ public function testPurchaseSuccess() public function testPurchaseFailure() { $httpResponse = $this->getMockHttpResponse('PurchaseFailure.txt'); - $response = new Response($this->getMockRequest(), $httpResponse->json()); + $response = new Response($this->getMockRequest(), $httpResponse->getBody()->getContents()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); @@ -31,7 +31,7 @@ public function testPurchaseFailure() public function testCardSuccess() { $httpResponse = $this->getMockHttpResponse('CardSuccess.txt'); - $response = new Response($this->getMockRequest(), $httpResponse->json()); + $response = new Response($this->getMockRequest(), $httpResponse->getBody()->getContents()); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); @@ -42,7 +42,7 @@ public function testCardSuccess() public function testCardFailure() { $httpResponse = $this->getMockHttpResponse('CardFailure.txt'); - $response = new Response($this->getMockRequest(), $httpResponse->json()); + $response = new Response($this->getMockRequest(), $httpResponse->getBody()->getContents()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); @@ -53,7 +53,7 @@ public function testCardFailure() public function testCustomerSuccess() { $httpResponse = $this->getMockHttpResponse('CustomerSuccess.txt'); - $response = new Response($this->getMockRequest(), $httpResponse->json()); + $response = new Response($this->getMockRequest(), $httpResponse->getBody()->getContents()); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); @@ -64,7 +64,7 @@ public function testCustomerSuccess() public function testCustomerFailure() { $httpResponse = $this->getMockHttpResponse('CustomerFailure.txt'); - $response = new Response($this->getMockRequest(), $httpResponse->json()); + $response = new Response($this->getMockRequest(), $httpResponse->getBody()->getContents()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect());