From 05f90e919b0d856b03f52382c08f0c5bfb5b1e5e Mon Sep 17 00:00:00 2001 From: Toby Evans Date: Thu, 21 May 2020 10:03:02 +1200 Subject: [PATCH 01/11] Fix for getting error messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Seems the Poli docs are out of date and they’ve made some changes? Anyway, this fix is backwards compatible and gets the message if its there with the old name or the new one. --- src/Message/PurchaseResponse.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Message/PurchaseResponse.php b/src/Message/PurchaseResponse.php index cfe1848..f59220d 100644 --- a/src/Message/PurchaseResponse.php +++ b/src/Message/PurchaseResponse.php @@ -7,6 +7,7 @@ use Omnipay\Common\Message\AbstractResponse; use Omnipay\Common\Message\RedirectResponseInterface; use Omnipay\Common\Message\RequestInterface; +use SimpleXMLElement; /** * Poli Response From 029a402f25d9d9a719bc971f5a4f5a1f9b050673 Mon Sep 17 00:00:00 2001 From: Toby Evans Date: Thu, 21 May 2020 10:05:09 +1200 Subject: [PATCH 02/11] Add more purchase data setters & strict data types - also removed some old code. --- src/Message/PurchaseRequest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Message/PurchaseRequest.php b/src/Message/PurchaseRequest.php index edd87b4..2b45e11 100644 --- a/src/Message/PurchaseRequest.php +++ b/src/Message/PurchaseRequest.php @@ -2,6 +2,7 @@ namespace Omnipay\Poli\Message; +use JsonSerializable; use Omnipay\Common\Message\AbstractRequest; use Omnipay\Common\Message\RedirectResponseInterface; From 1db89ccd9ecda3dc9ebb2385162691691582e6b6 Mon Sep 17 00:00:00 2001 From: Toby Evans Date: Thu, 21 May 2020 11:01:59 +1200 Subject: [PATCH 03/11] Tighten up types even more MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit strict response types - gives IDE’s better hinting and makes sure code more consitant. --- src/Message/PurchaseRequest.php | 1 - src/Message/PurchaseResponse.php | 1 - 2 files changed, 2 deletions(-) diff --git a/src/Message/PurchaseRequest.php b/src/Message/PurchaseRequest.php index 2b45e11..edd87b4 100644 --- a/src/Message/PurchaseRequest.php +++ b/src/Message/PurchaseRequest.php @@ -2,7 +2,6 @@ namespace Omnipay\Poli\Message; -use JsonSerializable; use Omnipay\Common\Message\AbstractRequest; use Omnipay\Common\Message\RedirectResponseInterface; diff --git a/src/Message/PurchaseResponse.php b/src/Message/PurchaseResponse.php index f59220d..cfe1848 100644 --- a/src/Message/PurchaseResponse.php +++ b/src/Message/PurchaseResponse.php @@ -7,7 +7,6 @@ use Omnipay\Common\Message\AbstractResponse; use Omnipay\Common\Message\RedirectResponseInterface; use Omnipay\Common\Message\RequestInterface; -use SimpleXMLElement; /** * Poli Response From dd16f1322aa87706647eeee5e72bc86dc73de2e1 Mon Sep 17 00:00:00 2001 From: Toby Evans Date: Tue, 17 Nov 2020 12:09:15 +1300 Subject: [PATCH 04/11] Add support for new uat domain for test mode POLi have moved test mode to a separate domain. This adds support for it. --- src/Message/AbstractRequest.php | 24 ++++++++++++++++ src/Message/CompletePurchaseRequest.php | 4 +-- src/Message/FetchCheckoutRequest.php | 6 ++-- src/Message/PurchaseRequest.php | 6 ++-- tests/GatewayTest.php | 38 +++++++++++++++++++++++++ 5 files changed, 70 insertions(+), 8 deletions(-) create mode 100644 src/Message/AbstractRequest.php diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php new file mode 100644 index 0000000..6b5b181 --- /dev/null +++ b/src/Message/AbstractRequest.php @@ -0,0 +1,24 @@ +getTestMode()) { + return 'https://poliapi.uat1.paywithpoli.com/' . ltrim($this->endpoint, '/'); + } + + return 'https://poliapi.apac.paywithpoli.com/' . ltrim($this->endpoint, '/'); + } +} diff --git a/src/Message/CompletePurchaseRequest.php b/src/Message/CompletePurchaseRequest.php index 408e6f4..02bcc89 100644 --- a/src/Message/CompletePurchaseRequest.php +++ b/src/Message/CompletePurchaseRequest.php @@ -12,7 +12,7 @@ */ class CompletePurchaseRequest extends PurchaseRequest { - protected $endpoint = 'https://poliapi.apac.paywithpoli.com/api/v2/Transaction/GetTransaction'; + protected $endpoint = '/api/v2/Transaction/GetTransaction'; public function getData(): array { @@ -57,7 +57,7 @@ public function sendData($data): RedirectResponseInterface // The Official way to add query params(4th argument of request()) // does not seem to work, so appending to the endpoint uri as well. - $url = $this->endpoint . '?' . http_build_query($data); + $url = $this->getEndpoint() . '?' . http_build_query($data); $httpResponse = $this->httpClient ->request('get', $url, $headers, http_build_query($data)); diff --git a/src/Message/FetchCheckoutRequest.php b/src/Message/FetchCheckoutRequest.php index d444327..845a3d8 100644 --- a/src/Message/FetchCheckoutRequest.php +++ b/src/Message/FetchCheckoutRequest.php @@ -2,12 +2,12 @@ namespace Omnipay\Poli\Message; -use Omnipay\Common\Message\AbstractRequest; use Omnipay\Common\Message\RedirectResponseInterface; +use Omnipay\Poli\Message\AbstractRequest; class FetchCheckoutRequest extends AbstractRequest { - protected $endpoint = 'https://poliapi.apac.paywithpoli.com/api/v2/Transaction/GetTransaction'; + protected $endpoint = '/api/v2/Transaction/GetTransaction'; public function getMerchantCode(): ?string { @@ -48,7 +48,7 @@ public function send(): RedirectResponseInterface public function sendData($data): RedirectResponseInterface { $token = $this->getParameter('token'); - $url = $this->endpoint . '?token=' . urlencode($token); + $url = $this->getEndpoint() . '?token=' . urlencode($token); $merchantCode = $this->getMerchantCode(); $authenticationCode = $this->getAuthenticationCode(); diff --git a/src/Message/PurchaseRequest.php b/src/Message/PurchaseRequest.php index edd87b4..e6b3972 100644 --- a/src/Message/PurchaseRequest.php +++ b/src/Message/PurchaseRequest.php @@ -2,8 +2,8 @@ namespace Omnipay\Poli\Message; -use Omnipay\Common\Message\AbstractRequest; use Omnipay\Common\Message\RedirectResponseInterface; +use Omnipay\Poli\Message\AbstractRequest; /** * Poli Purchase Request @@ -12,7 +12,7 @@ */ class PurchaseRequest extends AbstractRequest { - protected $endpoint = 'https://poliapi.apac.paywithpoli.com/api/v2/Transaction/Initiate'; + protected $endpoint = '/api/v2/Transaction/Initiate'; public function getMerchantCode(): ?string { @@ -145,7 +145,7 @@ public function sendData($data): RedirectResponseInterface $postdata = json_encode($data); $httpResponse = $this->httpClient->request( 'post', - $this->endpoint, + $this->getEndpoint(), array( 'Content-Type' => 'application/json', 'Accept' => 'application/json', diff --git a/tests/GatewayTest.php b/tests/GatewayTest.php index 61271f6..8fa636e 100644 --- a/tests/GatewayTest.php +++ b/tests/GatewayTest.php @@ -17,6 +17,44 @@ public function setUp() $this->gateway->setAuthenticationCode('a;sldkfjasdf;aladjs'); } + public function testproductionMode() + { + $this->assertEquals( + "https://poliapi.apac.paywithpoli.com/api/v2/Transaction/Initiate", + $this->gateway->purchase()->getEndpoint() + ); + + $this->assertEquals( + "https://poliapi.apac.paywithpoli.com/api/v2/Transaction/GetTransaction", + $this->gateway->fetchCheckout()->getEndpoint() + ); + + $this->assertEquals( + "https://poliapi.apac.paywithpoli.com/api/v2/Transaction/GetTransaction", + $this->gateway->completePurchase()->getEndpoint() + ); + } + + public function testTestMode() + { + $this->gateway->setTestMode(true); + + $this->assertEquals( + "https://poliapi.uat1.paywithpoli.com/api/v2/Transaction/Initiate", + $this->gateway->purchase()->getEndpoint() + ); + + $this->assertEquals( + "https://poliapi.uat1.paywithpoli.com/api/v2/Transaction/GetTransaction", + $this->gateway->fetchCheckout()->getEndpoint() + ); + + $this->assertEquals( + "https://poliapi.uat1.paywithpoli.com/api/v2/Transaction/GetTransaction", + $this->gateway->completePurchase()->getEndpoint() + ); + } + public function testPurchaseSuccess() { $this->setMockHttpResponse('PurchaseRequestSuccess.txt'); From b9ce38b2490821d0c73cc1e0e8acaeededf6b37b Mon Sep 17 00:00:00 2001 From: Toby Evans Date: Fri, 12 Mar 2021 12:52:37 +1300 Subject: [PATCH 05/11] Added a final fallback for error message - Fixes an error when null is returned instead of a string. --- src/Message/PurchaseResponse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Message/PurchaseResponse.php b/src/Message/PurchaseResponse.php index cfe1848..20ce100 100644 --- a/src/Message/PurchaseResponse.php +++ b/src/Message/PurchaseResponse.php @@ -63,7 +63,7 @@ public function getTransactionReference(): string */ public function getMessage(): string { - return $this->data['ErrorMessage'] ?? $this->data['Message'] ?? null; + return $this->data['ErrorMessage'] ?? $this->data['Message'] ?? 'Something went wrong'; } /** From f4f9a4da417f4ed01fe31067b293b2fd8f0123c4 Mon Sep 17 00:00:00 2001 From: Toby Evans Date: Mon, 15 Mar 2021 09:03:45 +1300 Subject: [PATCH 06/11] Redo that last fix with empty string stead of error message --- src/Message/PurchaseResponse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Message/PurchaseResponse.php b/src/Message/PurchaseResponse.php index 20ce100..5a0d024 100644 --- a/src/Message/PurchaseResponse.php +++ b/src/Message/PurchaseResponse.php @@ -63,7 +63,7 @@ public function getTransactionReference(): string */ public function getMessage(): string { - return $this->data['ErrorMessage'] ?? $this->data['Message'] ?? 'Something went wrong'; + return $this->data['ErrorMessage'] ?? $this->data['Message'] ?? ''; } /** From 7423b524c97234390f4f9ba3361f0af62a73c350 Mon Sep 17 00:00:00 2001 From: Toby Evans Date: Thu, 15 Jun 2023 10:20:14 +1200 Subject: [PATCH 07/11] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d103996..8c44184 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Developer Docs: http://www.polipaymentdeveloper.com/ [![Total Downloads](https://poser.pugx.org/burnbright/omnipay-poli/d/total.png)](https://packagist.org/packages/burnbright/omnipay-poli) [Omnipay](https://github.com/omnipay/omnipay) is a framework agnostic, multi-gateway payment -processing library for PHP 5.3+. This package implements Poli support for Omnipay. +processing library for PHP 7.2+. This package implements Poli support for Omnipay. ## Installation @@ -20,7 +20,7 @@ to your `composer.json` file: ```json { "require": { - "burnbright/omnipay-poli": "~2.0" + "burnbright/omnipay-poli": "~3.0" } } ``` From 8198c3a9e18b67f908e480e7e0097835c87f7262 Mon Sep 17 00:00:00 2001 From: Toby Evans Date: Fri, 16 Jun 2023 08:32:13 +1200 Subject: [PATCH 08/11] update composer dependancies --- composer.json | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 2040ced..e20fc43 100644 --- a/composer.json +++ b/composer.json @@ -22,6 +22,11 @@ "name": "Sid Bachtiar", "email": "sid.bachtiar@gmail.com", "homepage": "http://onlinesid.com" + }, + { + "name": "Toby Evans", + "email": "tobz.nz@gmail.com", + "homepage": "https://tobz.nz" } ], "autoload": { @@ -30,15 +35,22 @@ } }, "require": { - "php": ">=7.1", - "omnipay/common": "^3.0" + "php": ">=7.2", + "omnipay/common": "^3.2", + "symfony/http-client": "^6.3" }, "require-dev": { - "mockery/mockery": "^1.3", - "squizlabs/php_codesniffer": "^3.5", - "phpunit/phpunit": "~6", - "omnipay/tests": "^3.1" + "phpunit/phpunit": "^9.6", + "mockery/mockery": "^1.6", + "squizlabs/php_codesniffer": "^3.7", + "omnipay/tests": "^4.1", + "http-interop/http-factory-guzzle": "^1.2" }, "extra": { + }, + "config": { + "allow-plugins": { + "php-http/discovery": true + } } } From fa6758cff01ceb689b925a830bd6e19fa0e5f2d1 Mon Sep 17 00:00:00 2001 From: Toby Evans Date: Fri, 16 Jun 2023 08:32:30 +1200 Subject: [PATCH 09/11] Fix tests --- .gitignore | 1 + phpunit.xml.dist | 26 +++++++++++--------------- tests/GatewayTest.php | 11 +++++------ tests/Message/PurchaseRequestTest.php | 3 ++- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index e6e5bb7..f7fb9c1 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ composer.lock vendor composer.phar .idea +/.phpunit.result.cache diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a61160c..7dbb39a 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,25 +1,21 @@ + backupStaticAttributes="false" + bootstrap="tests/bootstrap.php" + colors="true" + convertErrorsToExceptions="true" + convertNoticesToExceptions="true" + convertWarningsToExceptions="true" + processIsolation="false" + stopOnFailure="false"> ./tests/ - + - - - ./src - - diff --git a/tests/GatewayTest.php b/tests/GatewayTest.php index 8fa636e..5a785fc 100644 --- a/tests/GatewayTest.php +++ b/tests/GatewayTest.php @@ -7,8 +7,7 @@ class GatewayTest extends GatewayTestCase { - - public function setUp() + public function setUp(): void { parent::setUp(); $this->gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest()); @@ -17,7 +16,7 @@ public function setUp() $this->gateway->setAuthenticationCode('a;sldkfjasdf;aladjs'); } - public function testproductionMode() + public function testproductionMode(): void { $this->assertEquals( "https://poliapi.apac.paywithpoli.com/api/v2/Transaction/Initiate", @@ -40,17 +39,17 @@ public function testTestMode() $this->gateway->setTestMode(true); $this->assertEquals( - "https://poliapi.uat1.paywithpoli.com/api/v2/Transaction/Initiate", + "https://poliapi.uat3.paywithpoli.com/api/v2/Transaction/Initiate", $this->gateway->purchase()->getEndpoint() ); $this->assertEquals( - "https://poliapi.uat1.paywithpoli.com/api/v2/Transaction/GetTransaction", + "https://poliapi.uat3.paywithpoli.com/api/v2/Transaction/GetTransaction", $this->gateway->fetchCheckout()->getEndpoint() ); $this->assertEquals( - "https://poliapi.uat1.paywithpoli.com/api/v2/Transaction/GetTransaction", + "https://poliapi.uat3.paywithpoli.com/api/v2/Transaction/GetTransaction", $this->gateway->completePurchase()->getEndpoint() ); } diff --git a/tests/Message/PurchaseRequestTest.php b/tests/Message/PurchaseRequestTest.php index b1c32cc..a580b16 100644 --- a/tests/Message/PurchaseRequestTest.php +++ b/tests/Message/PurchaseRequestTest.php @@ -7,8 +7,9 @@ class PurchaseRequestTest extends TestCase { + protected $request; - public function setUp() + public function setUp(): void { $this->request = new PurchaseRequest($this->getHttpClient(), $this->getHttpRequest()); } From e28dad0202077405df6bfd62227036848b3794a3 Mon Sep 17 00:00:00 2001 From: Toby Evans Date: Fri, 16 Jun 2023 08:33:05 +1200 Subject: [PATCH 10/11] swap to github actions for CI --- .github/workflows/ci.yml | 33 +++++++++++++++++++++++++++++++++ .travis.yml | 19 ------------------- 2 files changed, 33 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..cd676ed --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,33 @@ +name: Basic-CI + +on: [push, pull_request] + +concurrency: + group: ${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + operating-system: [ubuntu-latest] + php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2'] + name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }} + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + coverage: none + + - name: Install dependencies + run: | + composer install --no-interaction --no-progress --optimize-autoloader + + - name: run Tests + run: | + php $GITHUB_WORKSPACE/vendor/bin/phpunit --configuration $GITHUB_WORKSPACE/phpunit.xml.dist --colors=never diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 9d28361..0000000 --- a/.travis.yml +++ /dev/null @@ -1,19 +0,0 @@ -language: php - -php: -# - 5.6 -# - 7.0 - - 7.1 - - 7.2 - - 7.3 - - 7.4 - -## Cache composer -cache: - directories: - - $HOME/.composer/cache - -install: - - composer install -n --dev --prefer-source - -script: vendor/bin/phpcs --standard=PSR2 src && vendor/bin/phpunit --coverage-text From 45ab990192f6379793e32f9ab675183750dfdf91 Mon Sep 17 00:00:00 2001 From: Toby Evans Date: Fri, 16 Jun 2023 08:46:28 +1200 Subject: [PATCH 11/11] tweak versions to support php7.3 --- .github/workflows/ci.yml | 2 +- composer.json | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cd676ed..8135d55 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: operating-system: [ubuntu-latest] - php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2'] + php-versions: ['7.3', '7.4', '8.0', '8.1', '8.2'] name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }} steps: - name: Checkout code diff --git a/composer.json b/composer.json index e20fc43..c278aed 100644 --- a/composer.json +++ b/composer.json @@ -35,13 +35,13 @@ } }, "require": { - "php": ">=7.2", + "php": ">=7.3", "omnipay/common": "^3.2", - "symfony/http-client": "^6.3" + "symfony/http-client": "^5.4" }, "require-dev": { "phpunit/phpunit": "^9.6", - "mockery/mockery": "^1.6", + "mockery/mockery": "^1.5", "squizlabs/php_codesniffer": "^3.7", "omnipay/tests": "^4.1", "http-interop/http-factory-guzzle": "^1.2"