From 09a799b78f0ede9c0fa91c91ec2452f19458c173 Mon Sep 17 00:00:00 2001 From: SilverFire - Dmitry Naumenko Date: Fri, 2 Oct 2020 20:19:22 +0300 Subject: [PATCH 01/17] Upgraded to Omnipay v3 --- composer.json | 15 +++- src/Certificate/WMUsedRootCAs.crt | 75 +++++++++---------- src/Message/FetchTransactionRequest.php | 5 +- src/Message/PayoutRequest.php | 26 ++++--- tests/Message/CompletePurchaseRequestTest.php | 2 +- .../Message/CompletePurchaseResponseTest.php | 13 +++- tests/Message/FetchTransactionRequestTest.php | 8 +- .../Message/FetchTransactionResponseTest.php | 6 +- tests/Message/PayoutRequestTest.php | 35 ++++++--- tests/Message/PayoutResponseTest.php | 6 +- tests/Message/PurchaseRequestTest.php | 7 +- 11 files changed, 117 insertions(+), 81 deletions(-) diff --git a/composer.json b/composer.json index 13d18d6..cd006d4 100644 --- a/composer.json +++ b/composer.json @@ -18,15 +18,22 @@ } }, "require": { - "omnipay/common": "~2.3" + "omnipay/common": "^3.0", + "ext-simplexml": "*", + "ext-dom": "*", }, "require-dev": { - "omnipay/tests": "~2.0", - "satooshi/php-coveralls": "1.0.0" + "omnipay/tests": "^3.0", + "satooshi/php-coveralls": "1.0.0", + "guzzlehttp/guzzle": "^6.5.5" + }, + "suggest": { + "guzzlehttp/guzzle": "To handle WebMoney payouts", + "ext-curl": "To handle WebMoney payouts" }, "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "3.0.x-dev", } } } diff --git a/src/Certificate/WMUsedRootCAs.crt b/src/Certificate/WMUsedRootCAs.crt index a9e1453..fe9712f 100644 --- a/src/Certificate/WMUsedRootCAs.crt +++ b/src/Certificate/WMUsedRootCAs.crt @@ -1,4 +1,40 @@ -----BEGIN CERTIFICATE----- +MIIGRzCCBC+gAwIBAgIKNl4/iwAAAAnF+TANBgkqhkiG9w0BAQsFADBrMSswKQYD +VQQLEyJXTSBUcmFuc2ZlciBDZXJ0aWZpY2F0aW9uIFNlcnZpY2VzMRgwFgYDVQQK +Ew9XTSBUcmFuc2ZlciBMdGQxIjAgBgNVBAMTGVdlYk1vbmV5IFRyYW5zZmVyIFJv +b3QgQ0EwHhcNMTYxMTIyMTQxOTQ0WhcNMjExMTIyMTQyOTQ0WjCBhzELMAkGA1UE +BhMCUlUxDzANBgNVBAgTBk1vc2NvdzEPMA0GA1UEBxMGTW9zY293MRowGAYDVQQK +ExFXZWJNb25leSBUcmFuc2ZlcjEdMBsGA1UECxMUV2ViTW9uZXkgV2ViIFNlcnZp +Y2UxGzAZBgNVBAMTEnczcy53bXRyYW5zZmVyLmNvbTCCASIwDQYJKoZIhvcNAQEB +BQADggEPADCCAQoCggEBAJ0drRG+bzqrBk3IWMbtYMQZdYr501/c1NdnOWjyeFKt +Ho8N2PKiAf9OOFywSSdCoFdDxp0PNK1GoBESyhi2xIuXRpvCzNyRb2Se3V3IpFS8 +VOu6V2GzFjc7xqS37MAgR6THCvULumh6w7DMY+HBU51CinuRbComR9+D4Yq8c6wx +NnlI0HnkKE1H6fqLwDU+JhVrEJ64it6emghIazcEoZ+9Ld0rHdhrYsthxTwmC9mr +YR6ayhde7BOn/B66XWtZE+7sFYkmC/547NuU+gMw7FoZ/iu3Vy3HPOvwtzbXbwVk +lltVMtU2JD4+3UWlwMTbbPOQc5pDbC6GP56mIOy976sCAwEAAaOCAc4wggHKMB0G +A1UdDgQWBBT5R7V8EMMuRX9sQBZz8pdftKYI2jAfBgNVHSMEGDAWgBSxMKdLA5lP +hDYcE31X9Otp+4gbwzCBpAYDVR0fBIGcMIGZMIGWoIGToIGQhklodHRwOi8vY2Vy +dC53bXRyYW5zZmVyLmNvbS9DZXJ0RW5yb2xsL1dlYk1vbmV5JTIwVHJhbnNmZXIl +MjBSb290JTIwQ0EuY3JshkNmaWxlOi8vY2VydC53bXRyYW5zZmVyLmNvbS9DZXJ0 +RW5yb2xsL1dlYk1vbmV5IFRyYW5zZmVyIFJvb3QgQ0EuY3JsMIHgBggrBgEFBQcB +AQSB0zCB0DBpBggrBgEFBQcwAoZdaHR0cDovL2NlcnQud210cmFuc2Zlci5jb20v +Q2VydEVucm9sbC9jZXJ0LndtdHJhbnNmZXIuY29tX1dlYk1vbmV5JTIwVHJhbnNm +ZXIlMjBSb290JTIwQ0EuY3J0MGMGCCsGAQUFBzAChldmaWxlOi8vY2VydC53bXRy +YW5zZmVyLmNvbS9DZXJ0RW5yb2xsL2NlcnQud210cmFuc2Zlci5jb21fV2ViTW9u +ZXkgVHJhbnNmZXIgUm9vdCBDQS5jcnQwDQYJKoZIhvcNAQELBQADggIBAIE+gHDa ++nIQxlYJ2TMXbKBmBLdfwzd/FsO9PUxhx9fYg7Xp1/Vg3h7jjRl2/fe8iTLgInJ/ +avuyF+57MhRa+XIVHT02RLqG1wDlIdi5pMt7xRCvTulzHAeOrctNtH+m3pdu5G4S +u8k9lltwdcprfz3HNqU/Q1zcYMjvJJ7dPNqzNQWGRGPHuU4pS/x0Y+wUdTDhAYla +CJOkYscJipeyWgWM9zJZAXvmKw8lWij/lQDjAqAc0O5FyN5RN+l9Yt14NPvAM1zc +1SJttrFUiXR+7tHOIB4eXxfHa1Y68qt3cNV6C/Gun/6hhc8Jg0ly9mk1EGMXbBWZ +fko/3VSJGRpSqKacQBOmdBbgJmZW3GNSrQEmF2pV6aIyxQJA5PPBN6ePKnYZQpdr +Q/4Ql6IJs9R2JN3e+dmwzzf7IQuWGppR+WDcw322xPteK9Mt/mz4SYPTIu7cARqV +Y+v32ybhXibT/PY5qIPrX2MGLolhG3dZO+gwIyMLCtEBQL8+CorFd06UhKKbU/8p +x9Iqyo57wM7yA8WbLYF+rGxFZ79WL+2rhTmyqycK/YZ7AnrY9oUA6W8maNbdIE3G +aGB4kZaEtdMz0MFErIXS75OC7HAwuSRz2QXUZ3Bj6syxQfkz67RRnfWF0AdhQY2V +kjDzCAi+4vTuN7xadrhJmsiRx6r/nQo+iDh2 +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- MIIFsTCCA5mgAwIBAgIQA7dHzSZ7uJdBxFycIWn+WjANBgkqhkiG9w0BAQUFADBr MSswKQYDVQQLEyJXTSBUcmFuc2ZlciBDZXJ0aWZpY2F0aW9uIFNlcnZpY2VzMRgw FgYDVQQKEw9XTSBUcmFuc2ZlciBMdGQxIjAgBgNVBAMTGVdlYk1vbmV5IFRyYW5z @@ -31,42 +67,3 @@ hlA2/d5ULImX70Q2te3xiS1vrQhu77mkb/jA4/9+YfeT7VMpbnC3OoHiZ2bjudKn thlOs+AuUvzB4Tqo62VSF5+r0sYI593S+STmaZBAzsoaoEB7qxqKbEKCvXb9BlXk L76xIOEkbSIdPIkGXM4aMo4mTVz7 -----END CERTIFICATE----- ------BEGIN CERTIFICATE----- -MIIENjCCAx6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBvMQswCQYDVQQGEwJTRTEU -MBIGA1UEChMLQWRkVHJ1c3QgQUIxJjAkBgNVBAsTHUFkZFRydXN0IEV4dGVybmFs -IFRUUCBOZXR3b3JrMSIwIAYDVQQDExlBZGRUcnVzdCBFeHRlcm5hbCBDQSBSb290 -MB4XDTAwMDUzMDEwNDgzOFoXDTIwMDUzMDEwNDgzOFowbzELMAkGA1UEBhMCU0Ux -FDASBgNVBAoTC0FkZFRydXN0IEFCMSYwJAYDVQQLEx1BZGRUcnVzdCBFeHRlcm5h -bCBUVFAgTmV0d29yazEiMCAGA1UEAxMZQWRkVHJ1c3QgRXh0ZXJuYWwgQ0EgUm9v -dDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALf3GjPm8gAELTngTlvt -H7xsD821+iO2zt6bETOXpClMfZOfvUq8k+0DGuOPz+VtUFrWlymUWoCwSXrbLpX9 -uMq/NzgtHj6RQa1wVsfwTz/oMp50ysiQVOnGXw94nZpAPA6sYapeFI+eh6FqUNzX -mk6vBbOmcZSccbNQYArHE504B4YCqOmoaSYYkKtMsE8jqzpPhNjfzp/haW+710LX -a0Tkx63ubUFfclpxCDezeWWkWaCUN/cALw3CknLa0Dhy2xSoRcRdKn23tNbE7qzN -E0S3ySvdQwAl+mG5aWpYIxG3pzOPVnVZ9c0p10a3CitlttNCbxWyuHv77+ldU9U0 -WicCAwEAAaOB3DCB2TAdBgNVHQ4EFgQUrb2YejS0Jvf6xCZU7wO94CTLVBowCwYD -VR0PBAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wgZkGA1UdIwSBkTCBjoAUrb2YejS0 -Jvf6xCZU7wO94CTLVBqhc6RxMG8xCzAJBgNVBAYTAlNFMRQwEgYDVQQKEwtBZGRU -cnVzdCBBQjEmMCQGA1UECxMdQWRkVHJ1c3QgRXh0ZXJuYWwgVFRQIE5ldHdvcmsx -IjAgBgNVBAMTGUFkZFRydXN0IEV4dGVybmFsIENBIFJvb3SCAQEwDQYJKoZIhvcN -AQEFBQADggEBALCb4IUlwtYj4g+WBpKdQZic2YR5gdkeWxQHIzZlj7DYd7usQWxH -YINRsPkyPef89iYTx4AWpb9a/IfPeHmJIZriTAcKhjW88t5RxNKWt9x+Tu5w/Rw5 -6wwCURQtjr0W4MHfRnXnJK3s9EK0hZNwEGe6nQY1ShjTK3rMUUKhemPR5ruhxSvC -Nr4TDea9Y355e6cJDUCrat2PisP29owaQgVR1EX1n6diIWgVIEM8med8vSTYqZEX -c4g/VhsxOBi0cQ+azcgOno4uG+GMmIPLHzHxREzGBHNJdmAPx/i9F4BrLunMTA5a -mnkPIAou1Z5jJh5VkpTYghdae9C8x49OhgQ= ------END CERTIFICATE----- ------BEGIN CERTIFICATE----- -MIICPDCCAaUCEHC65B0Q2Sk0tjjKewPMur8wDQYJKoZIhvcNAQECBQAwXzELMAkG -A1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFz -cyAzIFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTk2 -MDEyOTAwMDAwMFoXDTI4MDgwMTIzNTk1OVowXzELMAkGA1UEBhMCVVMxFzAVBgNV -BAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFzcyAzIFB1YmxpYyBQcmlt -YXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIGfMA0GCSqGSIb3DQEBAQUAA4GN -ADCBiQKBgQDJXFme8huKARS0EN8EQNvjV69qRUCPhAwL0TPZ2RHP7gJYHyX3KqhE -BarsAx94f56TuZoAqiN91qyFomNFx3InzPRMxnVx0jnvT0Lwdd8KkMaOIG+YD/is -I19wKTakyYbnsZogy1Olhec9vn2a/iRFM9x2Fe0PonFkTGUugWhFpwIDAQABMA0G -CSqGSIb3DQEBAgUAA4GBALtMEivPLCYATxQT3ab7/AoRhIzzKBxnki98tsX63/Do -lbwdj2wsqFHMc9ikwFPwTtYmwHYBV4GSXiHx0bH/59AhWM1pF+NEHJwZRDmJXNyc -AA9WjQKZ7aKQRUzkuxCkPfAyAw7xzvjoyVGM5mKf5p/AfbdynMk2OmufTqj/ZA1k ------END CERTIFICATE----- \ No newline at end of file diff --git a/src/Message/FetchTransactionRequest.php b/src/Message/FetchTransactionRequest.php index dfc332c..74ddb37 100644 --- a/src/Message/FetchTransactionRequest.php +++ b/src/Message/FetchTransactionRequest.php @@ -55,9 +55,10 @@ public function getData() public function sendData($data) { - $httpResponse = $this->httpClient->post($this->endpoint, null, $data)->send(); + $httpResponse = $this->httpClient->request('POST', $this->endpoint, [], $data); + $xml = simplexml_load_string($httpResponse->getBody()->getContents()); - return $this->createResponse($httpResponse->xml()); + return $this->createResponse($xml); } protected function createResponse($data) diff --git a/src/Message/PayoutRequest.php b/src/Message/PayoutRequest.php index e30e279..32b4e76 100644 --- a/src/Message/PayoutRequest.php +++ b/src/Message/PayoutRequest.php @@ -2,6 +2,7 @@ namespace Omnipay\WebMoney\Message; +use Guzzle\Http\Client; use Omnipay\Common\Exception\InvalidRequestException; /** @@ -275,20 +276,29 @@ public function getData() return $document->saveXML(); } + /** + * @return Client + */ + private function getHttpClient() + { + return new Client($this->endpoint); + } + public function sendData($data) { - $this->httpClient->setConfig(array( - 'curl.options' => array( + $client = $this->getHttpClient(); + $client->setConfig([ + Client::CURL_OPTIONS => [ CURLOPT_CAINFO => $this->getCertificatePath('WMUsedRootCAs.crt'), CURLOPT_SSLCERT => $this->getSslFile(), CURLOPT_SSLKEY => $this->getSslKey(), CURLOPT_SSLVERSION => 1, CURLOPT_SSL_VERIFYHOST => 2, CURLOPT_SSL_VERIFYPEER => 1, - ), - )); + ], + ]); - $httpResponse = $this->httpClient->post($this->endpoint, null, $data)->send(); + $httpResponse = $client->post($this->endpoint, [], $data)->send(); return $this->createResponse($httpResponse->xml()); } @@ -300,10 +310,6 @@ protected function createResponse($data) protected function getCertificatePath($fileName) { - $class = new \ReflectionObject($this); - $directory = dirname($class->getFileName()); - $file = realpath($directory.'/../Certificate/'.$fileName); - - return $file; + return __DIR__ . '/../Certificate/' . $fileName; } } diff --git a/tests/Message/CompletePurchaseRequestTest.php b/tests/Message/CompletePurchaseRequestTest.php index 6776893..45469be 100644 --- a/tests/Message/CompletePurchaseRequestTest.php +++ b/tests/Message/CompletePurchaseRequestTest.php @@ -63,6 +63,6 @@ public function testSendData() { $data = $this->request->getData(); $response = $this->request->sendData($data); - $this->assertSame('Omnipay\WebMoney\Message\CompletePurchaseResponse', get_class($response)); + $this->assertInstanceOf(CompletePurchaseResponse::class, $response); } } diff --git a/tests/Message/CompletePurchaseResponseTest.php b/tests/Message/CompletePurchaseResponseTest.php index 7360f29..989547b 100644 --- a/tests/Message/CompletePurchaseResponseTest.php +++ b/tests/Message/CompletePurchaseResponseTest.php @@ -2,6 +2,7 @@ namespace Omnipay\WebMoney\Message; use Omnipay\Tests\TestCase; +use Omnipay\Common\Exception\InvalidResponseException; class CompletePurchaseResponseTest extends TestCase { @@ -21,7 +22,8 @@ public function setUp() public function testSignHashException() { - $this->setExpectedException('Omnipay\Common\Exception\InvalidResponseException', 'Invalid hash'); + $this->expectException(InvalidResponseException::class); + $this->expectExceptionMessage('Invalid hash'); new CompletePurchaseResponse($this->request, array( 'LMI_MODE' => '1', 'LMI_PAYMENT_AMOUNT' => '14.65', @@ -43,7 +45,8 @@ public function testSignHashException() public function testInvalidTestModeException() { - $this->setExpectedException('Omnipay\Common\Exception\InvalidResponseException', 'Invalid test mode'); + $this->expectException(InvalidResponseException::class); + $this->expectExceptionMessage('Invalid test mode'); new CompletePurchaseResponse($this->request, array( 'LMI_MODE' => '0', 'LMI_PAYMENT_AMOUNT' => '14.65', @@ -166,7 +169,8 @@ public function testMd5Hash() public function testInvalidHashTypeException() { - $this->setExpectedException('Omnipay\Common\Exception\InvalidResponseException', 'Control sign forming method "SIGN" is not supported'); + $this->expectException(InvalidResponseException::class); + $this->expectExceptionMessage('Control sign forming method "SIGN" is not supported'); new CompletePurchaseResponse($this->request, array( 'LMI_MODE' => '1', 'LMI_PAYMENT_AMOUNT' => '14.65', @@ -188,7 +192,8 @@ public function testInvalidHashTypeException() public function testInvalidSignatureTypeException() { - $this->setExpectedException('Omnipay\Common\Exception\InvalidResponseException', 'Invalid signature type'); + $this->expectException(InvalidResponseException::class); + $this->expectExceptionMessage('Invalid signature type'); new CompletePurchaseResponse($this->request, array( 'LMI_MODE' => '1', 'LMI_PAYMENT_AMOUNT' => '14.65', diff --git a/tests/Message/FetchTransactionRequestTest.php b/tests/Message/FetchTransactionRequestTest.php index e74d688..09ab06d 100644 --- a/tests/Message/FetchTransactionRequestTest.php +++ b/tests/Message/FetchTransactionRequestTest.php @@ -11,11 +11,11 @@ public function setUp() { parent::setUp(); - $mockPlugin = new \Guzzle\Plugin\Mock\MockPlugin(); - $mockPlugin->addResponse($this->getMockHttpResponse('FetchTransactionSuccess.txt')); + $this->getMockClient()->addResponse( + $this->getMockHttpResponse('FetchTransactionSuccess.txt') + ); $httpClient = $this->getHttpClient(); - $httpClient->addSubscriber($mockPlugin); $this->request = new FetchTransactionRequest($httpClient, $this->getHttpRequest()); $this->request->initialize(array( @@ -42,6 +42,6 @@ public function testSendData() { $data = $this->request->getData(); $response = $this->request->sendData($data); - $this->assertSame('Omnipay\WebMoney\Message\FetchTransactionResponse', get_class($response)); + $this->assertInstanceOf(\Omnipay\WebMoney\Message\FetchTransactionResponse::class, $response); } } diff --git a/tests/Message/FetchTransactionResponseTest.php b/tests/Message/FetchTransactionResponseTest.php index 310e7b7..340e929 100644 --- a/tests/Message/FetchTransactionResponseTest.php +++ b/tests/Message/FetchTransactionResponseTest.php @@ -24,7 +24,8 @@ public function setUp() public function testFailure() { $httpResponse = $this->getMockHttpResponse('FetchTransactionFailure.txt'); - $response = new FetchTransactionResponse($this->request, $httpResponse->xml()); + $xml = simplexml_load_string($httpResponse->getBody()->getContents()); + $response = new FetchTransactionResponse($this->request, $xml); $this->assertFalse($response->isSuccessful()); $this->assertSame(7, $response->getCode()); @@ -38,7 +39,8 @@ public function testFailure() public function testSuccess() { $httpResponse = $this->getMockHttpResponse('FetchTransactionSuccess.txt'); - $response = new FetchTransactionResponse($this->request, $httpResponse->xml()); + $xml = simplexml_load_string($httpResponse->getBody()->getContents()); + $response = new FetchTransactionResponse($this->request, $xml); $this->assertTrue($response->isSuccessful()); $this->assertSame(0, $response->getCode()); diff --git a/tests/Message/PayoutRequestTest.php b/tests/Message/PayoutRequestTest.php index 11900c8..a719c35 100644 --- a/tests/Message/PayoutRequestTest.php +++ b/tests/Message/PayoutRequestTest.php @@ -1,7 +1,11 @@ getFileName()); $sslFile = realpath($directory . '/../Certificate/webmoney.pem'); $sslKey = realpath($directory . '/../Certificate/webmoney.key'); $mockPlugin = new \Guzzle\Plugin\Mock\MockPlugin(); - $mockPlugin->addResponse($this->getMockHttpResponse('PayoutSuccess.txt')); + $mockPlugin->addResponse(__DIR__ . '/../Mock/PayoutSuccess.txt'); - $httpClient = $this->getHttpClient(); + $httpClient = new Client(); $httpClient->addSubscriber($mockPlugin); - $this->request = new PayoutRequest($httpClient, $this->getHttpRequest()); - $this->request->initialize(array( + $this->request = $this->getMockBuilder(PayoutRequest::class) + ->setMethods(['getHttpClient']) + ->setConstructorArgs([$this->getHttpClient(), $this->getHttpRequest()]) + ->getMock(); + $this->request->method('getHttpClient')->willReturn($httpClient); + $this->request->initialize([ 'webMoneyId' => '811333344777', 'merchantPurse' => 'Z123428476799', 'secretKey' => '226778888', @@ -39,7 +47,8 @@ public function setUp() 'description' => 'Payout', 'currency' => 'USD', 'amount' => '12.46' - )); + ] + ); } public function testException() @@ -49,14 +58,14 @@ public function testException() try { $this->request->getData(); } catch (\Exception $e) { - $this->assertEquals('Omnipay\Common\Exception\InvalidRequestException', get_class($e)); + $this->assertInstanceOf(\Omnipay\Common\Exception\InvalidRequestException::class, $e); } } public function testGetData() { $data = $this->request->getData(); - $request = new \SimpleXMLElement($data); + $request = new SimpleXMLElement($data); $this->assertSame('111222333', (string) $request->reqn); $this->assertSame('', (string) $request->wmid); @@ -75,7 +84,13 @@ public function testGetData() public function testSendData() { $data = $this->request->getData(); - $response = $this->request->sendData($data); - $this->assertSame('Omnipay\WebMoney\Message\PayoutResponse', get_class($response)); + $caught = false; + try { + $response = $this->request->sendData($data); + } catch (CurlException $exception) { + // We don't have a valid client SSL cert to interact with + $this->assertStringStartsWith('[curl] 56: OpenSSL SSL_read: error:14094418:SSL routines:ssl3_read_bytes:tlsv1 alert unknown ca', $exception->getMessage()); + $caught = true; + } } } diff --git a/tests/Message/PayoutResponseTest.php b/tests/Message/PayoutResponseTest.php index 3bfed6b..7a6bc32 100644 --- a/tests/Message/PayoutResponseTest.php +++ b/tests/Message/PayoutResponseTest.php @@ -39,7 +39,8 @@ public function setUp() public function testFailure() { $httpResponse = $this->getMockHttpResponse('PayoutFailure.txt'); - $response = new PayoutResponse($this->request, $httpResponse->xml()); + $xml = simplexml_load_string($httpResponse->getBody()->getContents()); + $response = new PayoutResponse($this->request, $xml); $this->assertFalse($response->isSuccessful()); $this->assertSame(17, $response->getCode()); @@ -53,7 +54,8 @@ public function testFailure() public function testSuccess() { $httpResponse = $this->getMockHttpResponse('PayoutSuccess.txt'); - $response = new PayoutResponse($this->request, $httpResponse->xml()); + $xml = simplexml_load_string($httpResponse->getBody()->getContents()); + $response = new PayoutResponse($this->request, $xml); $this->assertTrue($response->isSuccessful()); $this->assertSame(0, $response->getCode()); diff --git a/tests/Message/PurchaseRequestTest.php b/tests/Message/PurchaseRequestTest.php index d5f7079..ca367b7 100644 --- a/tests/Message/PurchaseRequestTest.php +++ b/tests/Message/PurchaseRequestTest.php @@ -1,6 +1,7 @@ request->getData(); - } catch (\Exception $e) { - $this->assertEquals('Omnipay\Common\Exception\InvalidRequestException', get_class($e)); + } catch (Exception $e) { + $this->assertInstanceOf(\Omnipay\Common\Exception\InvalidRequestException::class, $e); } } @@ -60,7 +61,7 @@ public function testSendData() { $data = $this->request->getData(); $response = $this->request->sendData($data); - $this->assertSame('Omnipay\WebMoney\Message\PurchaseResponse', get_class($response)); + $this->assertInstanceOf(\Omnipay\WebMoney\Message\PurchaseResponse::class, $response); } public function testGetCurrencyByPurse() From 6735dee4428b2d4c427611dbc8e8c35db0144fa7 Mon Sep 17 00:00:00 2001 From: DerCoder Date: Fri, 2 Oct 2020 19:57:09 +0200 Subject: [PATCH 02/17] Issues fixed --- .travis.yml | 9 +++---- README.md | 6 ++--- composer.json | 73 ++++++++++++++++++++++++++------------------------- 3 files changed, 44 insertions(+), 44 deletions(-) diff --git a/.travis.yml b/.travis.yml index 544f674..e7508e3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +1,16 @@ language: php php: - - 5.3 - - 5.4 - - 5.5 - 5.6 - 7.0 - 7.1 - - hhvm + - 7.2 + - 7.3 + - 7.4 before_script: - composer install -n --dev --prefer-source script: vendor/bin/phpcs --standard=PSR2 src && vendor/bin/phpunit --coverage-text -after_script: vendor/bin/coveralls -v \ No newline at end of file +after_script: vendor/bin/coveralls -v diff --git a/README.md b/README.md index a1b2620..70d3e8b 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ [![License](https://poser.pugx.org/dercoder/omnipay-webmoney/license.png)](https://packagist.org/packages/dercoder/omnipay-webmoney) [Omnipay](https://github.com/omnipay/omnipay) is a framework agnostic, multi-gateway payment -processing library for PHP 5.3+. This package implements [WebMoney](https://www.webmoney.az) support for Omnipay. +processing library for PHP 5.6+. This package implements [WebMoney](https://www.webmoney.az) support for Omnipay. ## Installation @@ -21,7 +21,7 @@ to your `composer.json` file: ```json { "require": { - "dercoder/omnipay-webmoney": "~1.0" + "dercoder/omnipay-webmoney": "~3.0" } } ``` @@ -51,4 +51,4 @@ or ask more detailed questions, there is also a [mailing list](https://groups.go you can subscribe to. If you believe you have found a bug, please report it using the [GitHub issue tracker](https://github.com/dercoder/omnipay-webmoney/issues), -or better yet, fork the library and submit a pull request. \ No newline at end of file +or better yet, fork the library and submit a pull request. diff --git a/composer.json b/composer.json index cd006d4..2e4d93e 100644 --- a/composer.json +++ b/composer.json @@ -1,39 +1,40 @@ { - "name": "dercoder/omnipay-webmoney", - "type": "library", - "description": "WebMoney driver for the Omnipay payment processing library", - "keywords": [ - "webmoney", - "gateway", - "merchant", - "omnipay", - "pay", - "payment" - ], - "homepage": "https://github.com/dercoder/omnipay-webmoney", - "license": "MIT", - "autoload": { - "psr-4": { - "Omnipay\\WebMoney\\": "src/" - } - }, - "require": { - "omnipay/common": "^3.0", - "ext-simplexml": "*", - "ext-dom": "*", - }, - "require-dev": { - "omnipay/tests": "^3.0", - "satooshi/php-coveralls": "1.0.0", - "guzzlehttp/guzzle": "^6.5.5" - }, - "suggest": { - "guzzlehttp/guzzle": "To handle WebMoney payouts", - "ext-curl": "To handle WebMoney payouts" - }, - "extra": { - "branch-alias": { - "dev-master": "3.0.x-dev", - } + "name": "dercoder/omnipay-webmoney", + "type": "library", + "description": "WebMoney driver for the Omnipay payment processing library", + "keywords": [ + "webmoney", + "gateway", + "merchant", + "omnipay", + "pay", + "payment" + ], + "homepage": "https://github.com/dercoder/omnipay-webmoney", + "license": "MIT", + "autoload": { + "psr-4": { + "Omnipay\\WebMoney\\": "src/" } + }, + "require": { + "php": "5.6 | 7.*", + "ext-simplexml": "*", + "ext-dom": "*", + "omnipay/common": "^3.0" + }, + "require-dev": { + "omnipay/tests": "^3.0", + "satooshi/php-coveralls": "1.0.0", + "guzzlehttp/guzzle": "^6.5.5" + }, + "suggest": { + "guzzlehttp/guzzle": "To handle WebMoney payouts", + "ext-curl": "To handle WebMoney payouts" + }, + "extra": { + "branch-alias": { + "dev-master": "3.0.x-dev" + } + } } From 8b09512b3af0bfa8b7cce4e66c5f7b51a1131762 Mon Sep 17 00:00:00 2001 From: DerCoder Date: Fri, 2 Oct 2020 20:14:15 +0200 Subject: [PATCH 03/17] Issues fixed --- composer.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 2e4d93e..29e1b9c 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ } }, "require": { - "php": "5.6 | 7.*", + "php": "^5.6|^7", "ext-simplexml": "*", "ext-dom": "*", "omnipay/common": "^3.0" @@ -26,7 +26,8 @@ "require-dev": { "omnipay/tests": "^3.0", "satooshi/php-coveralls": "1.0.0", - "guzzlehttp/guzzle": "^6.5.5" + "guzzlehttp/guzzle": "^6.5.5", + "squizlabs/php_codesniffer": "3.*" }, "suggest": { "guzzlehttp/guzzle": "To handle WebMoney payouts", From 19f488837b78d217963f9824bf6d9a6253e412ca Mon Sep 17 00:00:00 2001 From: DerCoder Date: Fri, 2 Oct 2020 20:25:34 +0200 Subject: [PATCH 04/17] Removed payout sendData request test --- tests/Message/PayoutRequestTest.php | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/tests/Message/PayoutRequestTest.php b/tests/Message/PayoutRequestTest.php index a719c35..b858a38 100644 --- a/tests/Message/PayoutRequestTest.php +++ b/tests/Message/PayoutRequestTest.php @@ -80,17 +80,4 @@ public function testGetData() $this->assertSame('12345678', (string) $request->trans->wminvid); $this->assertSame('0', (string) $request->trans->onlyauth); } - - public function testSendData() - { - $data = $this->request->getData(); - $caught = false; - try { - $response = $this->request->sendData($data); - } catch (CurlException $exception) { - // We don't have a valid client SSL cert to interact with - $this->assertStringStartsWith('[curl] 56: OpenSSL SSL_read: error:14094418:SSL routines:ssl3_read_bytes:tlsv1 alert unknown ca', $exception->getMessage()); - $caught = true; - } - } } From 8df8d0f48caa24263090661a1825e32df73f9a4d Mon Sep 17 00:00:00 2001 From: DerCoder Date: Wed, 20 Oct 2021 00:12:43 +0200 Subject: [PATCH 05/17] Removed PHP 5.6 support Added custom fields for purchase request --- .travis.yml | 2 +- composer.json | 4 +- phpunit.xml.dist | 5 +- src/Message/AbstractRequest.php | 6 +- src/Message/CompletePurchaseRequest.php | 56 ++--- src/Message/CompletePurchaseResponse.php | 30 +-- src/Message/FetchTransactionRequest.php | 6 +- src/Message/FetchTransactionResponse.php | 12 +- src/Message/PayoutRequest.php | 16 +- src/Message/PayoutResponse.php | 12 +- src/Message/PurchaseRequest.php | 63 ++++- tests/Message/CompletePurchaseRequestTest.php | 41 +-- .../Message/CompletePurchaseResponseTest.php | 233 +++++++++--------- tests/Message/FetchTransactionRequestTest.php | 21 +- .../Message/FetchTransactionResponseTest.php | 12 +- tests/Message/PayoutRequestTest.php | 64 ++--- tests/Message/PayoutResponseTest.php | 31 +-- tests/Message/PurchaseRequestTest.php | 72 +++++- tests/Message/PurchaseResponseTest.php | 13 +- 19 files changed, 405 insertions(+), 294 deletions(-) diff --git a/.travis.yml b/.travis.yml index e7508e3..294031c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,12 @@ language: php php: - - 5.6 - 7.0 - 7.1 - 7.2 - 7.3 - 7.4 + - 8.0 before_script: - composer install -n --dev --prefer-source diff --git a/composer.json b/composer.json index 29e1b9c..2ee8a9c 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ } }, "require": { - "php": "^5.6|^7", + "php": "^7.0|^7.1|^7.2|^7.3|^7.4|^8.0", "ext-simplexml": "*", "ext-dom": "*", "omnipay/common": "^3.0" @@ -35,7 +35,7 @@ }, "extra": { "branch-alias": { - "dev-master": "3.0.x-dev" + "dev-master": "4.0.x-dev" } } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 9797d8e..1ecb290 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -22,7 +22,4 @@ ./src - - - - \ No newline at end of file + diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index 9513b28..19a4356 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -154,13 +154,13 @@ public function setCancelMethod($value) /** * Redirect method conversion table. */ - private static $methodsTable = array( + private static $methodsTable = [ '1' => '1', '2' => '2', 'GET' => '0', 'POST' => '1', 'LINK' => '2', - ); + ]; /** * Converts redirect method to WebMoney code: 0, 1 or 2. @@ -171,7 +171,7 @@ public function setCancelMethod($value) */ public function formatMethod($method) { - $method = strtoupper((string) $method); + $method = strtoupper((string)$method); return isset(self::$methodsTable[$method]) ? self::$methodsTable[$method] : '0'; } diff --git a/src/Message/CompletePurchaseRequest.php b/src/Message/CompletePurchaseRequest.php index 6abea0c..8bb81f6 100644 --- a/src/Message/CompletePurchaseRequest.php +++ b/src/Message/CompletePurchaseRequest.php @@ -23,35 +23,35 @@ public function getData() 'secretKey' ); - return array( - 'LMI_PAYEE_PURSE' => $this->httpRequest->request->get('LMI_PAYEE_PURSE'), - 'LMI_PAYMENT_AMOUNT' => $this->httpRequest->request->get('LMI_PAYMENT_AMOUNT'), - 'LMI_PAYMENT_NO' => $this->httpRequest->request->get('LMI_PAYMENT_NO'), - 'LMI_MODE' => $this->httpRequest->request->get('LMI_MODE'), - 'LMI_SYS_INVS_NO' => $this->httpRequest->request->get('LMI_SYS_INVS_NO'), - 'LMI_SYS_TRANS_NO' => $this->httpRequest->request->get('LMI_SYS_TRANS_NO'), - 'LMI_PAYER_PURSE' => $this->httpRequest->request->get('LMI_PAYER_PURSE'), - 'LMI_PAYER_WM' => $this->httpRequest->request->get('LMI_PAYER_WM'), - 'LMI_CAPITALLER_WMID' => $this->httpRequest->request->get('LMI_CAPITALLER_WMID'), - 'LMI_PAYMER_NUMBER' => $this->httpRequest->request->get('LMI_PAYMER_NUMBER'), - 'LMI_PAYMER_EMAIL' => $this->httpRequest->request->get('LMI_PAYMER_EMAIL'), - 'LMI_EURONOTE_NUMBER' => $this->httpRequest->request->get('LMI_EURONOTE_NUMBER'), - 'LMI_EURONOTE_EMAIL' => $this->httpRequest->request->get('LMI_EURONOTE_EMAIL'), - 'LMI_WMCHECK_NUMBER' => $this->httpRequest->request->get('LMI_WMCHECK_NUMBER'), + return [ + 'LMI_PAYEE_PURSE' => $this->httpRequest->request->get('LMI_PAYEE_PURSE'), + 'LMI_PAYMENT_AMOUNT' => $this->httpRequest->request->get('LMI_PAYMENT_AMOUNT'), + 'LMI_PAYMENT_NO' => $this->httpRequest->request->get('LMI_PAYMENT_NO'), + 'LMI_MODE' => $this->httpRequest->request->get('LMI_MODE'), + 'LMI_SYS_INVS_NO' => $this->httpRequest->request->get('LMI_SYS_INVS_NO'), + 'LMI_SYS_TRANS_NO' => $this->httpRequest->request->get('LMI_SYS_TRANS_NO'), + 'LMI_PAYER_PURSE' => $this->httpRequest->request->get('LMI_PAYER_PURSE'), + 'LMI_PAYER_WM' => $this->httpRequest->request->get('LMI_PAYER_WM'), + 'LMI_CAPITALLER_WMID' => $this->httpRequest->request->get('LMI_CAPITALLER_WMID'), + 'LMI_PAYMER_NUMBER' => $this->httpRequest->request->get('LMI_PAYMER_NUMBER'), + 'LMI_PAYMER_EMAIL' => $this->httpRequest->request->get('LMI_PAYMER_EMAIL'), + 'LMI_EURONOTE_NUMBER' => $this->httpRequest->request->get('LMI_EURONOTE_NUMBER'), + 'LMI_EURONOTE_EMAIL' => $this->httpRequest->request->get('LMI_EURONOTE_EMAIL'), + 'LMI_WMCHECK_NUMBER' => $this->httpRequest->request->get('LMI_WMCHECK_NUMBER'), 'LMI_TELEPAT_PHONENUMBER' => $this->httpRequest->request->get('LMI_TELEPAT_PHONENUMBER'), - 'LMI_TELEPAT_ORDERID' => $this->httpRequest->request->get('LMI_TELEPAT_ORDERID'), - 'LMI_PAYMENT_CREDITDAYS' => $this->httpRequest->request->get('LMI_PAYMENT_CREDITDAYS'), - 'LMI_HASH' => $this->httpRequest->request->get('LMI_HASH'), - 'LMI_SYS_TRANS_DATE' => $this->httpRequest->request->get('LMI_SYS_TRANS_DATE'), - 'LMI_SECRET_KEY' => $this->httpRequest->request->get('LMI_SECRET_KEY'), - 'LMI_SDP_TYPE' => $this->httpRequest->request->get('LMI_SDP_TYPE'), - 'LMI_PAYMENT_DESC' => $this->httpRequest->request->get('LMI_PAYMENT_DESC'), - 'LMI_PAYER_COUNTRYID' => $this->httpRequest->request->get('LMI_PAYER_COUNTRYID'), - 'LMI_PAYER_PCOUNTRYID' => $this->httpRequest->request->get('LMI_PAYER_PCOUNTRYID'), - 'LMI_PAYER_IP' => $this->httpRequest->request->get('LMI_PAYER_IP'), - 'LMI_LANG' => $this->httpRequest->request->get('LMI_LANG'), - 'LMI_DBLCHK' => $this->httpRequest->request->get('LMI_DBLCHK'), - ); + 'LMI_TELEPAT_ORDERID' => $this->httpRequest->request->get('LMI_TELEPAT_ORDERID'), + 'LMI_PAYMENT_CREDITDAYS' => $this->httpRequest->request->get('LMI_PAYMENT_CREDITDAYS'), + 'LMI_HASH' => $this->httpRequest->request->get('LMI_HASH'), + 'LMI_SYS_TRANS_DATE' => $this->httpRequest->request->get('LMI_SYS_TRANS_DATE'), + 'LMI_SECRET_KEY' => $this->httpRequest->request->get('LMI_SECRET_KEY'), + 'LMI_SDP_TYPE' => $this->httpRequest->request->get('LMI_SDP_TYPE'), + 'LMI_PAYMENT_DESC' => $this->httpRequest->request->get('LMI_PAYMENT_DESC'), + 'LMI_PAYER_COUNTRYID' => $this->httpRequest->request->get('LMI_PAYER_COUNTRYID'), + 'LMI_PAYER_PCOUNTRYID' => $this->httpRequest->request->get('LMI_PAYER_PCOUNTRYID'), + 'LMI_PAYER_IP' => $this->httpRequest->request->get('LMI_PAYER_IP'), + 'LMI_LANG' => $this->httpRequest->request->get('LMI_LANG'), + 'LMI_DBLCHK' => $this->httpRequest->request->get('LMI_DBLCHK'), + ]; } /** diff --git a/src/Message/CompletePurchaseResponse.php b/src/Message/CompletePurchaseResponse.php index fae0dbf..8e787b4 100644 --- a/src/Message/CompletePurchaseResponse.php +++ b/src/Message/CompletePurchaseResponse.php @@ -62,7 +62,7 @@ public function getCurrency() public function getTestMode() { - return (bool) $this->getMode(); + return (bool)$this->getMode(); } public function getMode() @@ -114,18 +114,20 @@ private function calculateHash() throw new InvalidResponseException('Invalid signature type'); } - return strtoupper(hash( - $hashType, - $this->data['LMI_PAYEE_PURSE']. - $this->data['LMI_PAYMENT_AMOUNT']. - $this->data['LMI_PAYMENT_NO']. - $this->data['LMI_MODE']. - $this->data['LMI_SYS_INVS_NO']. - $this->data['LMI_SYS_TRANS_NO']. - $this->data['LMI_SYS_TRANS_DATE']. - $this->request->getSecretkey(). - $this->data['LMI_PAYER_PURSE']. - $this->data['LMI_PAYER_WM'] - )); + return strtoupper( + hash( + $hashType, + $this->data['LMI_PAYEE_PURSE'] . + $this->data['LMI_PAYMENT_AMOUNT'] . + $this->data['LMI_PAYMENT_NO'] . + $this->data['LMI_MODE'] . + $this->data['LMI_SYS_INVS_NO'] . + $this->data['LMI_SYS_TRANS_NO'] . + $this->data['LMI_SYS_TRANS_DATE'] . + $this->request->getSecretkey() . + $this->data['LMI_PAYER_PURSE'] . + $this->data['LMI_PAYER_WM'] + ) + ); } } diff --git a/src/Message/FetchTransactionRequest.php b/src/Message/FetchTransactionRequest.php index 74ddb37..0ef745e 100644 --- a/src/Message/FetchTransactionRequest.php +++ b/src/Message/FetchTransactionRequest.php @@ -70,9 +70,9 @@ protected function calculateSignature($algorithm) { return hash( $algorithm, - $this->getWebMoneyId(). - $this->getMerchantPurse(). - $this->getTransactionId(). + $this->getWebMoneyId() . + $this->getMerchantPurse() . + $this->getTransactionId() . $this->getSecretKey() ); } diff --git a/src/Message/FetchTransactionResponse.php b/src/Message/FetchTransactionResponse.php index 4f3c484..7d08f96 100644 --- a/src/Message/FetchTransactionResponse.php +++ b/src/Message/FetchTransactionResponse.php @@ -28,33 +28,33 @@ public function isSuccessful() public function getCode() { - return (int) $this->data->retval; + return (int)$this->data->retval; } public function getMessage() { - $message = (string) $this->data->retdesc; + $message = (string)$this->data->retdesc; return $message ? $message : null; } public function getTransactionReference() { - return $this->data->operation ? (string) $this->data->operation->attributes()->wmtransid : null; + return $this->data->operation ? (string)$this->data->operation->attributes()->wmtransid : null; } public function getDescription() { - return $this->data->operation ? (string) $this->data->operation->purpose : null; + return $this->data->operation ? (string)$this->data->operation->purpose : null; } public function getAmount() { - return $this->data->operation ? (string) $this->data->operation->amount : null; + return $this->data->operation ? (string)$this->data->operation->amount : null; } public function getClientIp() { - return $this->data->operation ? (string) $this->data->operation->IPAddress : null; + return $this->data->operation ? (string)$this->data->operation->IPAddress : null; } } diff --git a/src/Message/PayoutRequest.php b/src/Message/PayoutRequest.php index 32b4e76..5749744 100644 --- a/src/Message/PayoutRequest.php +++ b/src/Message/PayoutRequest.php @@ -58,7 +58,7 @@ public function getRequestNumber() { $requestNumber = $this->getParameter('requestNumber'); - return $requestNumber ? $requestNumber : (string) time(); + return $requestNumber ? $requestNumber : (string)time(); } /** @@ -87,7 +87,7 @@ public function setRequestNumber($value) */ public function getProtectionPeriod() { - return (int) $this->getParameter('protectionPeriod'); + return (int)$this->getParameter('protectionPeriod'); } /** @@ -143,7 +143,7 @@ public function setProtectionCode($value) */ public function getInvoiceId() { - return (int) $this->getParameter('invoiceId'); + return (int)$this->getParameter('invoiceId'); } /** @@ -175,7 +175,7 @@ public function setInvoiceId($value) */ public function getOnlyAuth() { - return (int) $this->getParameter('onlyAuth'); + return (int)$this->getParameter('onlyAuth'); } /** @@ -289,10 +289,10 @@ public function sendData($data) $client = $this->getHttpClient(); $client->setConfig([ Client::CURL_OPTIONS => [ - CURLOPT_CAINFO => $this->getCertificatePath('WMUsedRootCAs.crt'), - CURLOPT_SSLCERT => $this->getSslFile(), - CURLOPT_SSLKEY => $this->getSslKey(), - CURLOPT_SSLVERSION => 1, + CURLOPT_CAINFO => $this->getCertificatePath('WMUsedRootCAs.crt'), + CURLOPT_SSLCERT => $this->getSslFile(), + CURLOPT_SSLKEY => $this->getSslKey(), + CURLOPT_SSLVERSION => 1, CURLOPT_SSL_VERIFYHOST => 2, CURLOPT_SSL_VERIFYPEER => 1, ], diff --git a/src/Message/PayoutResponse.php b/src/Message/PayoutResponse.php index fb9e094..4f8aa3f 100644 --- a/src/Message/PayoutResponse.php +++ b/src/Message/PayoutResponse.php @@ -28,33 +28,33 @@ public function isSuccessful() public function getCode() { - return (int) $this->data->retval; + return (int)$this->data->retval; } public function getMessage() { - $message = (string) $this->data->retdesc; + $message = (string)$this->data->retdesc; return $message ? $message : null; } public function getTransactionId() { - return $this->data->operation ? (string) $this->data->operation->tranid : null; + return $this->data->operation ? (string)$this->data->operation->tranid : null; } public function getTransactionReference() { - return $this->data->operation ? (string) $this->data->operation->attributes()->id : null; + return $this->data->operation ? (string)$this->data->operation->attributes()->id : null; } public function getDescription() { - return $this->data->operation ? (string) $this->data->operation->desc : null; + return $this->data->operation ? (string)$this->data->operation->desc : null; } public function getAmount() { - return $this->data->operation ? (string) $this->data->operation->amount : null; + return $this->data->operation ? (string)$this->data->operation->amount : null; } } diff --git a/src/Message/PurchaseRequest.php b/src/Message/PurchaseRequest.php index 4b393cb..c14acde 100644 --- a/src/Message/PurchaseRequest.php +++ b/src/Message/PurchaseRequest.php @@ -15,12 +15,12 @@ class PurchaseRequest extends AbstractRequest { /** - * @return int + * @return string */ public function getHold() { if ($hold = $this->getParameter('hold')) { - return (string) $hold; + return (string)$hold; } return '0'; @@ -36,6 +36,51 @@ public function setHold($value) return $this->setParameter('hold', $value); } + /** + * @return array + */ + public function getCustomFields() + { + return $this->getParameter('customFields') ?? []; + } + + /** + * @param array $fields + * + * @return $this + * @throws \Exception + */ + public function setCustomFields(array $fields) + { + $customFields = []; + foreach ($fields as $field => $value) { + if (is_numeric($field)) { + $field++; + $field = "FIELD_$field"; + } + + $field = strtoupper($field); + + if (substr($field, 0, 1) === '_') { + throw new \Exception('"_" prefix is not allowed for custom fields'); + } + + if (substr($field, 0, 4) === 'LMI_') { + throw new \Exception('"LMI_" prefix is not allowed for custom fields'); + } + + if (!is_scalar($value)) { + throw new \Exception('Value must be a scalar'); + } + + $customFields[$field] = (string)$value; + } + + $this->setParameter('customFields', $customFields); + + return $this; + } + /** * @return array * @throws InvalidRequestException @@ -57,7 +102,7 @@ public function getData() throw new InvalidRequestException('Invalid currency for this merchant purse'); } - return array( + $data = [ 'LMI_PAYEE_PURSE' => $this->getMerchantPurse(), 'LMI_PAYMENT_AMOUNT' => $this->getAmount(), 'LMI_PAYMENT_NO' => $this->getTransactionId(), @@ -68,8 +113,16 @@ public function getData() 'LMI_SUCCESS_METHOD' => $this->getReturnMethod(), 'LMI_FAIL_URL' => $this->getCancelUrl(), 'LMI_FAIL_METHOD' => $this->getCancelMethod(), - 'LMI_HOLD' => $this->getHold() - ); + 'LMI_HOLD' => $this->getHold(), + ]; + + foreach ($this->getCustomFields() as $variable => $value) { + if (!isset($data[$variable])) { + $data[$variable] = $value; + } + } + + return $data; } /** diff --git a/tests/Message/CompletePurchaseRequestTest.php b/tests/Message/CompletePurchaseRequestTest.php index 45469be..e97c87f 100644 --- a/tests/Message/CompletePurchaseRequestTest.php +++ b/tests/Message/CompletePurchaseRequestTest.php @@ -1,4 +1,5 @@ '1', - 'LMI_PAYMENT_AMOUNT' => '14.65', - 'LMI_PAYEE_PURSE' => 'Z123428476799', - 'LMI_PAYMENT_NO' => '1444212666', - 'LMI_PAYER_WM' => '404521188333', - 'LMI_PAYER_PURSE' => 'Z366393600555', + $httpRequest = new HttpRequest([], [ + 'LMI_MODE' => '1', + 'LMI_PAYMENT_AMOUNT' => '14.65', + 'LMI_PAYEE_PURSE' => 'Z123428476799', + 'LMI_PAYMENT_NO' => '1444212666', + 'LMI_PAYER_WM' => '404521188333', + 'LMI_PAYER_PURSE' => 'Z366393600555', 'LMI_PAYER_COUNTRYID' => 'AZ', - 'LMI_PAYER_IP' => '127.0.0.1', - 'LMI_SYS_INVS_NO' => '897', - 'LMI_SYS_TRANS_NO' => '892', - 'LMI_SYS_TRANS_DATE' => '20151007 13:07:36', - 'LMI_HASH' => '0B12E75431284D6FCC05D8AF02B90AC28A0788FB95C9FF6B655344022F0746E5', - 'LMI_PAYMENT_DESC' => 'Test', - 'LMI_LANG' => 'en-US', - 'LMI_DBLCHK' => 'SMS' - )); + 'LMI_PAYER_IP' => '127.0.0.1', + 'LMI_SYS_INVS_NO' => '897', + 'LMI_SYS_TRANS_NO' => '892', + 'LMI_SYS_TRANS_DATE' => '20151007 13:07:36', + 'LMI_HASH' => '0B12E75431284D6FCC05D8AF02B90AC28A0788FB95C9FF6B655344022F0746E5', + 'LMI_PAYMENT_DESC' => 'Test', + 'LMI_LANG' => 'en-US', + 'LMI_DBLCHK' => 'SMS', + ]); $this->request = new CompletePurchaseRequest($this->getHttpClient(), $httpRequest); - $this->request->initialize(array( + $this->request->initialize([ 'merchantPurse' => 'Z123428476799', - 'secretKey' => '226778888', - 'testMode' => true - )); + 'secretKey' => '226778888', + 'testMode' => true, + ]); } public function testGetData() diff --git a/tests/Message/CompletePurchaseResponseTest.php b/tests/Message/CompletePurchaseResponseTest.php index 989547b..1f0fe1d 100644 --- a/tests/Message/CompletePurchaseResponseTest.php +++ b/tests/Message/CompletePurchaseResponseTest.php @@ -1,4 +1,5 @@ request = new CompletePurchaseRequest($this->getHttpClient(), $this->getHttpRequest()); - $this->request->initialize(array( + $this->request->initialize([ 'merchantPurse' => 'Z123428476799', - 'secretKey' => '226778888', - 'testMode' => true - )); + 'secretKey' => '226778888', + 'testMode' => true, + ]); } public function testSignHashException() { $this->expectException(InvalidResponseException::class); $this->expectExceptionMessage('Invalid hash'); - new CompletePurchaseResponse($this->request, array( - 'LMI_MODE' => '1', - 'LMI_PAYMENT_AMOUNT' => '14.65', - 'LMI_PAYEE_PURSE' => 'Z123428476799', - 'LMI_PAYMENT_NO' => '1444212666', - 'LMI_PAYER_WM' => '404521188333', - 'LMI_PAYER_PURSE' => 'Z366393600555', + new CompletePurchaseResponse($this->request, [ + 'LMI_MODE' => '1', + 'LMI_PAYMENT_AMOUNT' => '14.65', + 'LMI_PAYEE_PURSE' => 'Z123428476799', + 'LMI_PAYMENT_NO' => '1444212666', + 'LMI_PAYER_WM' => '404521188333', + 'LMI_PAYER_PURSE' => 'Z366393600555', 'LMI_PAYER_COUNTRYID' => 'AZ', - 'LMI_PAYER_IP' => '127.0.0.1', - 'LMI_SYS_INVS_NO' => '897', - 'LMI_SYS_TRANS_NO' => '892', - 'LMI_SYS_TRANS_DATE' => '20151007 13:07:36', - 'LMI_HASH' => '0B12E75431284D6FCC05D8AF02B90AC28A0788FB95C9FF6B655344022F0746E1', - 'LMI_PAYMENT_DESC' => 'Test', - 'LMI_LANG' => 'en-US', - 'LMI_DBLCHK' => 'SMS' - )); + 'LMI_PAYER_IP' => '127.0.0.1', + 'LMI_SYS_INVS_NO' => '897', + 'LMI_SYS_TRANS_NO' => '892', + 'LMI_SYS_TRANS_DATE' => '20151007 13:07:36', + 'LMI_HASH' => '0B12E75431284D6FCC05D8AF02B90AC28A0788FB95C9FF6B655344022F0746E1', + 'LMI_PAYMENT_DESC' => 'Test', + 'LMI_LANG' => 'en-US', + 'LMI_DBLCHK' => 'SMS', + ]); } public function testInvalidTestModeException() { $this->expectException(InvalidResponseException::class); $this->expectExceptionMessage('Invalid test mode'); - new CompletePurchaseResponse($this->request, array( - 'LMI_MODE' => '0', - 'LMI_PAYMENT_AMOUNT' => '14.65', - 'LMI_PAYEE_PURSE' => 'Z123428476799', - 'LMI_PAYMENT_NO' => '1444212666', - 'LMI_PAYER_WM' => '404521188333', - 'LMI_PAYER_PURSE' => 'Z366393600555', + new CompletePurchaseResponse($this->request, [ + 'LMI_MODE' => '0', + 'LMI_PAYMENT_AMOUNT' => '14.65', + 'LMI_PAYEE_PURSE' => 'Z123428476799', + 'LMI_PAYMENT_NO' => '1444212666', + 'LMI_PAYER_WM' => '404521188333', + 'LMI_PAYER_PURSE' => 'Z366393600555', 'LMI_PAYER_COUNTRYID' => 'AZ', - 'LMI_PAYER_IP' => '127.0.0.1', - 'LMI_SYS_INVS_NO' => '897', - 'LMI_SYS_TRANS_NO' => '892', - 'LMI_SYS_TRANS_DATE' => '20151007 13:07:36', - 'LMI_HASH' => '4F7D9FD1177DFDAE182F0E470296080DC47A843A32826147555F5C8959E7F6DD', - 'LMI_PAYMENT_DESC' => 'Test', - 'LMI_LANG' => 'en-US', - 'LMI_DBLCHK' => 'SMS' - )); + 'LMI_PAYER_IP' => '127.0.0.1', + 'LMI_SYS_INVS_NO' => '897', + 'LMI_SYS_TRANS_NO' => '892', + 'LMI_SYS_TRANS_DATE' => '20151007 13:07:36', + 'LMI_HASH' => '4F7D9FD1177DFDAE182F0E470296080DC47A843A32826147555F5C8959E7F6DD', + 'LMI_PAYMENT_DESC' => 'Test', + 'LMI_LANG' => 'en-US', + 'LMI_DBLCHK' => 'SMS', + ]); } public function testSuccess() { - $response = new CompletePurchaseResponse($this->request, array( - 'LMI_MODE' => '1', - 'LMI_PAYMENT_AMOUNT' => '14.65', - 'LMI_PAYEE_PURSE' => 'Z123428476799', - 'LMI_PAYMENT_NO' => '1444212666', - 'LMI_PAYER_WM' => '404521188333', - 'LMI_PAYER_PURSE' => 'Z366393600555', + $response = new CompletePurchaseResponse($this->request, [ + 'LMI_MODE' => '1', + 'LMI_PAYMENT_AMOUNT' => '14.65', + 'LMI_PAYEE_PURSE' => 'Z123428476799', + 'LMI_PAYMENT_NO' => '1444212666', + 'LMI_PAYER_WM' => '404521188333', + 'LMI_PAYER_PURSE' => 'Z366393600555', 'LMI_PAYER_COUNTRYID' => 'AZ', - 'LMI_PAYER_IP' => '127.0.0.1', - 'LMI_SYS_INVS_NO' => '897', - 'LMI_SYS_TRANS_NO' => '892', - 'LMI_SYS_TRANS_DATE' => '20151007 13:07:36', - 'LMI_HASH' => '0B12E75431284D6FCC05D8AF02B90AC28A0788FB95C9FF6B655344022F0746E5', - 'LMI_PAYMENT_DESC' => 'Test', - 'LMI_LANG' => 'en-US', - 'LMI_DBLCHK' => 'SMS' - )); + 'LMI_PAYER_IP' => '127.0.0.1', + 'LMI_SYS_INVS_NO' => '897', + 'LMI_SYS_TRANS_NO' => '892', + 'LMI_SYS_TRANS_DATE' => '20151007 13:07:36', + 'LMI_HASH' => '0B12E75431284D6FCC05D8AF02B90AC28A0788FB95C9FF6B655344022F0746E5', + 'LMI_PAYMENT_DESC' => 'Test', + 'LMI_LANG' => 'en-US', + 'LMI_DBLCHK' => 'SMS', + ]); $this->assertTrue($response->isSuccessful()); $this->assertNull($response->getCode()); @@ -101,23 +102,23 @@ public function testSuccess() public function testSha256Hash() { - $response = new CompletePurchaseResponse($this->request, array( - 'LMI_MODE' => '1', - 'LMI_PAYMENT_AMOUNT' => '14.65', - 'LMI_PAYEE_PURSE' => 'Z123428476799', - 'LMI_PAYMENT_NO' => '1444212666', - 'LMI_PAYER_WM' => '404521188333', - 'LMI_PAYER_PURSE' => 'Z366393600555', + $response = new CompletePurchaseResponse($this->request, [ + 'LMI_MODE' => '1', + 'LMI_PAYMENT_AMOUNT' => '14.65', + 'LMI_PAYEE_PURSE' => 'Z123428476799', + 'LMI_PAYMENT_NO' => '1444212666', + 'LMI_PAYER_WM' => '404521188333', + 'LMI_PAYER_PURSE' => 'Z366393600555', 'LMI_PAYER_COUNTRYID' => 'AZ', - 'LMI_PAYER_IP' => '127.0.0.1', - 'LMI_SYS_INVS_NO' => '897', - 'LMI_SYS_TRANS_NO' => '892', - 'LMI_SYS_TRANS_DATE' => '20151007 13:07:36', - 'LMI_HASH' => '0B12E75431284D6FCC05D8AF02B90AC28A0788FB95C9FF6B655344022F0746E5', - 'LMI_PAYMENT_DESC' => 'Test', - 'LMI_LANG' => 'en-US', - 'LMI_DBLCHK' => 'SMS' - )); + 'LMI_PAYER_IP' => '127.0.0.1', + 'LMI_SYS_INVS_NO' => '897', + 'LMI_SYS_TRANS_NO' => '892', + 'LMI_SYS_TRANS_DATE' => '20151007 13:07:36', + 'LMI_HASH' => '0B12E75431284D6FCC05D8AF02B90AC28A0788FB95C9FF6B655344022F0746E5', + 'LMI_PAYMENT_DESC' => 'Test', + 'LMI_LANG' => 'en-US', + 'LMI_DBLCHK' => 'SMS', + ]); $this->assertTrue($response->isSuccessful()); $this->assertNull($response->getCode()); @@ -135,23 +136,23 @@ public function testSha256Hash() public function testMd5Hash() { - $response = new CompletePurchaseResponse($this->request, array( - 'LMI_MODE' => '1', - 'LMI_PAYMENT_AMOUNT' => '14.65', - 'LMI_PAYEE_PURSE' => 'Z123428476799', - 'LMI_PAYMENT_NO' => '1444212666', - 'LMI_PAYER_WM' => '404521188333', - 'LMI_PAYER_PURSE' => 'Z366393600555', + $response = new CompletePurchaseResponse($this->request, [ + 'LMI_MODE' => '1', + 'LMI_PAYMENT_AMOUNT' => '14.65', + 'LMI_PAYEE_PURSE' => 'Z123428476799', + 'LMI_PAYMENT_NO' => '1444212666', + 'LMI_PAYER_WM' => '404521188333', + 'LMI_PAYER_PURSE' => 'Z366393600555', 'LMI_PAYER_COUNTRYID' => 'AZ', - 'LMI_PAYER_IP' => '127.0.0.1', - 'LMI_SYS_INVS_NO' => '897', - 'LMI_SYS_TRANS_NO' => '892', - 'LMI_SYS_TRANS_DATE' => '20151007 13:07:36', - 'LMI_HASH' => '1D3FFAFA982B134479C4AD1AE2CABB5C', - 'LMI_PAYMENT_DESC' => 'Test', - 'LMI_LANG' => 'en-US', - 'LMI_DBLCHK' => 'SMS' - )); + 'LMI_PAYER_IP' => '127.0.0.1', + 'LMI_SYS_INVS_NO' => '897', + 'LMI_SYS_TRANS_NO' => '892', + 'LMI_SYS_TRANS_DATE' => '20151007 13:07:36', + 'LMI_HASH' => '1D3FFAFA982B134479C4AD1AE2CABB5C', + 'LMI_PAYMENT_DESC' => 'Test', + 'LMI_LANG' => 'en-US', + 'LMI_DBLCHK' => 'SMS', + ]); $this->assertTrue($response->isSuccessful()); $this->assertNull($response->getCode()); @@ -171,45 +172,45 @@ public function testInvalidHashTypeException() { $this->expectException(InvalidResponseException::class); $this->expectExceptionMessage('Control sign forming method "SIGN" is not supported'); - new CompletePurchaseResponse($this->request, array( - 'LMI_MODE' => '1', - 'LMI_PAYMENT_AMOUNT' => '14.65', - 'LMI_PAYEE_PURSE' => 'Z123428476799', - 'LMI_PAYMENT_NO' => '1444212666', - 'LMI_PAYER_WM' => '404521188333', - 'LMI_PAYER_PURSE' => 'Z366393600555', + new CompletePurchaseResponse($this->request, [ + 'LMI_MODE' => '1', + 'LMI_PAYMENT_AMOUNT' => '14.65', + 'LMI_PAYEE_PURSE' => 'Z123428476799', + 'LMI_PAYMENT_NO' => '1444212666', + 'LMI_PAYER_WM' => '404521188333', + 'LMI_PAYER_PURSE' => 'Z366393600555', 'LMI_PAYER_COUNTRYID' => 'AZ', - 'LMI_PAYER_IP' => '127.0.0.1', - 'LMI_SYS_INVS_NO' => '897', - 'LMI_SYS_TRANS_NO' => '892', - 'LMI_SYS_TRANS_DATE' => '20151007 13:07:36', - 'LMI_HASH' => '2E2A8871CBB577DE4AB3E47EBFA100EB8AD9C7AF6FB5580169B8273409863941BDA16647D2D2619D8FFF946D319FE35D758844214B02F46CBA7AE35AFE3F86940069', - 'LMI_PAYMENT_DESC' => 'Test', - 'LMI_LANG' => 'en-US', - 'LMI_DBLCHK' => 'SMS' - )); + 'LMI_PAYER_IP' => '127.0.0.1', + 'LMI_SYS_INVS_NO' => '897', + 'LMI_SYS_TRANS_NO' => '892', + 'LMI_SYS_TRANS_DATE' => '20151007 13:07:36', + 'LMI_HASH' => '2E2A8871CBB577DE4AB3E47EBFA100EB8AD9C7AF6FB5580169B8273409863941BDA16647D2D2619D8FFF946D319FE35D758844214B02F46CBA7AE35AFE3F86940069', + 'LMI_PAYMENT_DESC' => 'Test', + 'LMI_LANG' => 'en-US', + 'LMI_DBLCHK' => 'SMS', + ]); } public function testInvalidSignatureTypeException() { $this->expectException(InvalidResponseException::class); $this->expectExceptionMessage('Invalid signature type'); - new CompletePurchaseResponse($this->request, array( - 'LMI_MODE' => '1', - 'LMI_PAYMENT_AMOUNT' => '14.65', - 'LMI_PAYEE_PURSE' => 'Z123428476799', - 'LMI_PAYMENT_NO' => '1444212666', - 'LMI_PAYER_WM' => '404521188333', - 'LMI_PAYER_PURSE' => 'Z366393600555', + new CompletePurchaseResponse($this->request, [ + 'LMI_MODE' => '1', + 'LMI_PAYMENT_AMOUNT' => '14.65', + 'LMI_PAYEE_PURSE' => 'Z123428476799', + 'LMI_PAYMENT_NO' => '1444212666', + 'LMI_PAYER_WM' => '404521188333', + 'LMI_PAYER_PURSE' => 'Z366393600555', 'LMI_PAYER_COUNTRYID' => 'AZ', - 'LMI_PAYER_IP' => '127.0.0.1', - 'LMI_SYS_INVS_NO' => '897', - 'LMI_SYS_TRANS_NO' => '892', - 'LMI_SYS_TRANS_DATE' => '20151007 13:07:36', - 'LMI_HASH' => 'ABD', - 'LMI_PAYMENT_DESC' => 'Test', - 'LMI_LANG' => 'en-US', - 'LMI_DBLCHK' => 'SMS' - )); + 'LMI_PAYER_IP' => '127.0.0.1', + 'LMI_SYS_INVS_NO' => '897', + 'LMI_SYS_TRANS_NO' => '892', + 'LMI_SYS_TRANS_DATE' => '20151007 13:07:36', + 'LMI_HASH' => 'ABD', + 'LMI_PAYMENT_DESC' => 'Test', + 'LMI_LANG' => 'en-US', + 'LMI_DBLCHK' => 'SMS', + ]); } } diff --git a/tests/Message/FetchTransactionRequestTest.php b/tests/Message/FetchTransactionRequestTest.php index 09ab06d..d13f3ae 100644 --- a/tests/Message/FetchTransactionRequestTest.php +++ b/tests/Message/FetchTransactionRequestTest.php @@ -1,4 +1,5 @@ getHttpClient(); $this->request = new FetchTransactionRequest($httpClient, $this->getHttpRequest()); - $this->request->initialize(array( - 'webMoneyId' => '811333344777', + $this->request->initialize([ + 'webMoneyId' => '811333344777', 'merchantPurse' => 'Z123428476799', - 'secretKey' => '226778888', - 'transactionId' => '1444212666' - )); + 'secretKey' => '226778888', + 'transactionId' => '1444212666', + ]); } public function testGetData() @@ -31,11 +32,11 @@ public function testGetData() $data = $this->request->getData(); $request = new \SimpleXMLElement($data); - $this->assertSame('811333344777', (string) $request->wmid); - $this->assertSame('Z123428476799', (string) $request->lmi_payee_purse); - $this->assertSame('1444212666', (string) $request->lmi_payment_no); - $this->assertSame('0b1fbe2eaccf29e86e144c486b2ccf258b56fb54c295f195af7a749f6f5c79d4', (string) $request->sha256); - $this->assertSame('edd00dcbfed2c3846393e9ce315b3af2', (string) $request->md5); + $this->assertSame('811333344777', (string)$request->wmid); + $this->assertSame('Z123428476799', (string)$request->lmi_payee_purse); + $this->assertSame('1444212666', (string)$request->lmi_payment_no); + $this->assertSame('0b1fbe2eaccf29e86e144c486b2ccf258b56fb54c295f195af7a749f6f5c79d4', (string)$request->sha256); + $this->assertSame('edd00dcbfed2c3846393e9ce315b3af2', (string)$request->md5); } public function testSendData() diff --git a/tests/Message/FetchTransactionResponseTest.php b/tests/Message/FetchTransactionResponseTest.php index 340e929..7bc6465 100644 --- a/tests/Message/FetchTransactionResponseTest.php +++ b/tests/Message/FetchTransactionResponseTest.php @@ -1,4 +1,5 @@ request = new FetchTransactionRequest($this->getHttpClient(), $this->getHttpRequest()); - $this->request->initialize(array( + $this->request->initialize([ 'webMoneyId' => '811333344777', 'merchantPurse' => 'Z123428476799', 'secretKey' => '226778888', - 'transactionId' => '1444212666' - )); + 'transactionId' => '1444212666', + ]); } public function testFailure() @@ -29,7 +30,10 @@ public function testFailure() $this->assertFalse($response->isSuccessful()); $this->assertSame(7, $response->getCode()); - $this->assertSame('Payment with lmi_payment_no number not found for this merchant purse:7 step=50', $response->getMessage()); + $this->assertSame( + 'Payment with lmi_payment_no number not found for this merchant purse:7 step=50', + $response->getMessage() + ); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getDescription()); $this->assertNull($response->getAmount()); diff --git a/tests/Message/PayoutRequestTest.php b/tests/Message/PayoutRequestTest.php index b858a38..39ee8aa 100644 --- a/tests/Message/PayoutRequestTest.php +++ b/tests/Message/PayoutRequestTest.php @@ -1,4 +1,5 @@ addSubscriber($mockPlugin); $this->request = $this->getMockBuilder(PayoutRequest::class) - ->setMethods(['getHttpClient']) - ->setConstructorArgs([$this->getHttpClient(), $this->getHttpRequest()]) - ->getMock(); + ->setMethods(['getHttpClient']) + ->setConstructorArgs([$this->getHttpClient(), $this->getHttpRequest()]) + ->getMock(); + $this->request->method('getHttpClient')->willReturn($httpClient); $this->request->initialize([ - 'webMoneyId' => '811333344777', - 'merchantPurse' => 'Z123428476799', - 'secretKey' => '226778888', - 'sslFile' => $sslFile, - 'sslKey' => $sslKey, - 'transactionId' => '1444111666', - 'requestNumber' => '111222333', - 'customerPurse' => 'Z123428476700', - 'protectionPeriod' => '60', - 'protectionCode' => 'xyZ123', - 'invoiceId' => '12345678', - 'onlyAuth' => false, - 'description' => 'Payout', - 'currency' => 'USD', - 'amount' => '12.46' - ] + 'webMoneyId' => '811333344777', + 'merchantPurse' => 'Z123428476799', + 'secretKey' => '226778888', + 'sslFile' => $sslFile, + 'sslKey' => $sslKey, + 'transactionId' => '1444111666', + 'requestNumber' => '111222333', + 'customerPurse' => 'Z123428476700', + 'protectionPeriod' => '60', + 'protectionCode' => 'xyZ123', + 'invoiceId' => '12345678', + 'onlyAuth' => false, + 'description' => 'Payout', + 'currency' => 'USD', + 'amount' => '12.46', + ] ); } @@ -67,17 +69,17 @@ public function testGetData() $data = $this->request->getData(); $request = new SimpleXMLElement($data); - $this->assertSame('111222333', (string) $request->reqn); - $this->assertSame('', (string) $request->wmid); - $this->assertSame('', (string) $request->sign); - $this->assertSame('1444111666', (string) $request->trans->tranid); - $this->assertSame('Z123428476799', (string) $request->trans->pursesrc); - $this->assertSame('Z123428476700', (string) $request->trans->pursedest); - $this->assertSame('12.46', (string) $request->trans->amount); - $this->assertSame('60', (string) $request->trans->period); - $this->assertSame('xyZ123', (string) $request->trans->pcode); - $this->assertSame('Payout', (string) $request->trans->desc); - $this->assertSame('12345678', (string) $request->trans->wminvid); - $this->assertSame('0', (string) $request->trans->onlyauth); + $this->assertSame('111222333', (string)$request->reqn); + $this->assertSame('', (string)$request->wmid); + $this->assertSame('', (string)$request->sign); + $this->assertSame('1444111666', (string)$request->trans->tranid); + $this->assertSame('Z123428476799', (string)$request->trans->pursesrc); + $this->assertSame('Z123428476700', (string)$request->trans->pursedest); + $this->assertSame('12.46', (string)$request->trans->amount); + $this->assertSame('60', (string)$request->trans->period); + $this->assertSame('xyZ123', (string)$request->trans->pcode); + $this->assertSame('Payout', (string)$request->trans->desc); + $this->assertSame('12345678', (string)$request->trans->wminvid); + $this->assertSame('0', (string)$request->trans->onlyauth); } } diff --git a/tests/Message/PayoutResponseTest.php b/tests/Message/PayoutResponseTest.php index 7a6bc32..a39696f 100644 --- a/tests/Message/PayoutResponseTest.php +++ b/tests/Message/PayoutResponseTest.php @@ -1,4 +1,5 @@ request = new PayoutRequest($this->getHttpClient(), $this->getHttpRequest()); - $this->request->initialize(array( - 'webMoneyId' => '811333344777', - 'merchantPurse' => 'Z123428476799', - 'secretKey' => '226778888', - 'sslFile' => $sslFile, - 'sslKey' => $sslKey, - 'transactionId' => '1444111666', - 'requestNumber' => '111222333', - 'customerPurse' => 'Z123428476700', + $this->request->initialize([ + 'webMoneyId' => '811333344777', + 'merchantPurse' => 'Z123428476799', + 'secretKey' => '226778888', + 'sslFile' => $sslFile, + 'sslKey' => $sslKey, + 'transactionId' => '1444111666', + 'requestNumber' => '111222333', + 'customerPurse' => 'Z123428476700', 'protectionPeriod' => '60', - 'protectionCode' => 'xyZ123', - 'invoiceId' => '12345678', - 'onlyAuth' => false, - 'description' => 'Payout', - 'amount' => '12.46' - )); + 'protectionCode' => 'xyZ123', + 'invoiceId' => '12345678', + 'onlyAuth' => false, + 'description' => 'Payout', + 'amount' => '12.46', + ]); } public function testFailure() diff --git a/tests/Message/PurchaseRequestTest.php b/tests/Message/PurchaseRequestTest.php index ca367b7..6c24d1f 100644 --- a/tests/Message/PurchaseRequestTest.php +++ b/tests/Message/PurchaseRequestTest.php @@ -1,4 +1,5 @@ request = new PurchaseRequest($this->getHttpClient(), $this->getHttpRequest()); - $this->request->initialize(array( + $this->request->initialize([ 'merchantPurse' => 'Z123428476799', - 'secretKey' => '226778888', - 'returnUrl' => 'https://www.foodstore.com/success', - 'cancelUrl' => 'https://www.foodstore.com/failure', - 'notifyUrl' => 'https://www.foodstore.com/notify', - 'returnMethod' => 'POST', - 'cancelMethod' => 'link', - 'description' => 'Test Transaction', + 'secretKey' => '226778888', + 'returnUrl' => 'https://www.foodstore.com/success', + 'cancelUrl' => 'https://www.foodstore.com/failure', + 'notifyUrl' => 'https://www.foodstore.com/notify', + 'returnMethod' => 'POST', + 'cancelMethod' => 'link', + 'description' => 'Test Transaction', 'transactionId' => '1234567890', - 'amount' => '14.65', - 'currency' => 'USD', - 'testMode' => true - )); + 'amount' => '14.65', + 'currency' => 'USD', + 'testMode' => true, + 'customFields' => [ + 'customerId' => 123, + 'first_name' => 'John', + 'last_name' => 'Doe', + 'No-Key', + '1' => 'Numeric-Key', + ], + ]); } public function testException() @@ -55,6 +63,11 @@ public function testGetData() $this->assertSame('https://www.foodstore.com/failure', $data['LMI_FAIL_URL']); $this->assertSame('2', $data['LMI_FAIL_METHOD']); $this->assertSame('0', $data['LMI_HOLD']); + $this->assertSame('123', $data['CUSTOMERID']); + $this->assertSame('John', $data['FIRST_NAME']); + $this->assertSame('Doe', $data['LAST_NAME']); + $this->assertSame('No-Key', $data['FIELD_1']); + $this->assertSame('Numeric-Key', $data['FIELD_2']); } public function testSendData() @@ -76,4 +89,39 @@ public function testGetCurrencyByPurse() $this->assertSame('BTC', $this->request->getCurrencyByPurse('X123428476799')); $this->assertNull($this->request->getCurrencyByPurse('A123428476799')); } + + public function testCustomFields() + { + $this->request->setCustomFields([ + 'field1' => 'John', + 'Field_2' => 'Doe', + ]); + + $this->assertArrayHasKey('FIELD1', $this->request->getCustomFields()); + $this->assertArrayHasKey('FIELD_2', $this->request->getCustomFields()); + } + + public function testInvalidCustomFields1() + { + $this->expectException('Exception'); + $this->request->setCustomFields([ + 'lmi_' => 'John', + ]); + } + + public function testInvalidCustomFields2() + { + $this->expectException('Exception'); + $this->request->setCustomFields([ + '_test' => 'Doe', + ]); + } + + public function testInvalidCustomFields3() + { + $this->expectException('Exception'); + $this->request->setCustomFields([ + 'array' => [1, 2, 3], + ]); + } } diff --git a/tests/Message/PurchaseResponseTest.php b/tests/Message/PurchaseResponseTest.php index c951719..47e2b1c 100644 --- a/tests/Message/PurchaseResponseTest.php +++ b/tests/Message/PurchaseResponseTest.php @@ -1,4 +1,5 @@ request = new PurchaseRequest($this->getHttpClient(), $this->getHttpRequest()); - $this->request->initialize(array( + $this->request->initialize([ 'merchantPurse' => 'Z123428476799', 'secretKey' => '226778888', 'returnUrl' => 'https://www.foodstore.com/success', @@ -23,8 +24,8 @@ public function setUp() 'amount' => '14.65', 'currency' => 'USD', 'testMode' => true, - 'hold' => 2 - )); + 'hold' => 2, + ]); } public function testSuccess() @@ -37,7 +38,7 @@ public function testSuccess() $this->assertNull($response->getMessage()); $this->assertSame('POST', $response->getRedirectMethod()); $this->assertSame('https://merchant.wmtransfer.com/lmi/payment.asp', $response->getRedirectUrl()); - $this->assertSame(array( + $this->assertSame([ 'LMI_PAYEE_PURSE' => 'Z123428476799', 'LMI_PAYMENT_AMOUNT' => '14.65', 'LMI_PAYMENT_NO' => '1234567890', @@ -48,7 +49,7 @@ public function testSuccess() 'LMI_SUCCESS_METHOD' => '0', 'LMI_FAIL_URL' => 'https://www.foodstore.com/failure', 'LMI_FAIL_METHOD' => '0', - 'LMI_HOLD' => '2' - ), $response->getRedirectData()); + 'LMI_HOLD' => '2', + ], $response->getRedirectData()); } } From af3fd47289b42361601fdb9ac3c21973fdbebb09 Mon Sep 17 00:00:00 2001 From: DerCoder Date: Wed, 20 Oct 2021 00:21:03 +0200 Subject: [PATCH 06/17] Removed PHP 5.6 support Added custom fields for purchase request --- .travis.yml | 1 - composer.json | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 294031c..5ac9929 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,6 @@ php: - 7.2 - 7.3 - 7.4 - - 8.0 before_script: - composer install -n --dev --prefer-source diff --git a/composer.json b/composer.json index 2ee8a9c..8f11756 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ } }, "require": { - "php": "^7.0|^7.1|^7.2|^7.3|^7.4|^8.0", + "php": "^7.0|^7.1|^7.2|^7.3|^7.4", "ext-simplexml": "*", "ext-dom": "*", "omnipay/common": "^3.0" From 7e74b7f2bfe4d69113fc6b1452888e0ab7a37e4c Mon Sep 17 00:00:00 2001 From: DerCoder Date: Wed, 20 Oct 2021 00:32:12 +0200 Subject: [PATCH 07/17] Remove PHP 7.3+ from testing --- .travis.yml | 2 -- README.md | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5ac9929..bcfcdeb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,8 +4,6 @@ php: - 7.0 - 7.1 - 7.2 - - 7.3 - - 7.4 before_script: - composer install -n --dev --prefer-source diff --git a/README.md b/README.md index 70d3e8b..579df85 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ **WebMoney driver for the Omnipay PHP payment processing library** -[![Build Status](https://travis-ci.org/dercoder/omnipay-webmoney.svg?branch=master)](https://travis-ci.org/dercoder/omnipay-webmoney) +[![Build Status](https://app.travis-ci.com/dercoder/omnipay-webmoney.svg?branch=master)](https://travis-ci.org/dercoder/omnipay-webmoney) [![Coverage Status](https://coveralls.io/repos/dercoder/omnipay-webmoney/badge.svg?branch=master&service=github)](https://coveralls.io/github/dercoder/omnipay-webmoney?branch=master) [![Latest Stable Version](https://poser.pugx.org/dercoder/omnipay-webmoney/v/stable.png)](https://packagist.org/packages/dercoder/omnipay-webmoney) @@ -11,7 +11,7 @@ [![License](https://poser.pugx.org/dercoder/omnipay-webmoney/license.png)](https://packagist.org/packages/dercoder/omnipay-webmoney) [Omnipay](https://github.com/omnipay/omnipay) is a framework agnostic, multi-gateway payment -processing library for PHP 5.6+. This package implements [WebMoney](https://www.webmoney.az) support for Omnipay. +processing library for PHP 7.0+. This package implements [WebMoney](https://www.webmoney.az) support for Omnipay. ## Installation @@ -21,7 +21,7 @@ to your `composer.json` file: ```json { "require": { - "dercoder/omnipay-webmoney": "~3.0" + "dercoder/omnipay-webmoney": "~4.0" } } ``` From f948d832643adcd3a6a46e3cc8079ea5c9509429 Mon Sep 17 00:00:00 2001 From: DerCoder Date: Wed, 20 Oct 2021 00:37:53 +0200 Subject: [PATCH 08/17] Update travis page --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 579df85..6fc95de 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ **WebMoney driver for the Omnipay PHP payment processing library** -[![Build Status](https://app.travis-ci.com/dercoder/omnipay-webmoney.svg?branch=master)](https://travis-ci.org/dercoder/omnipay-webmoney) +[![Build Status](https://app.travis-ci.com/dercoder/omnipay-webmoney.svg?branch=master)](https://app.travis-ci.com/github/dercoder/omnipay-webmoney) [![Coverage Status](https://coveralls.io/repos/dercoder/omnipay-webmoney/badge.svg?branch=master&service=github)](https://coveralls.io/github/dercoder/omnipay-webmoney?branch=master) [![Latest Stable Version](https://poser.pugx.org/dercoder/omnipay-webmoney/v/stable.png)](https://packagist.org/packages/dercoder/omnipay-webmoney) From 3afe7701fa2e99eab86d32ca81e1c2aaabd9fa40 Mon Sep 17 00:00:00 2001 From: SilverFire - Dmitry Naumenko Date: Fri, 25 Mar 2022 18:38:50 +0200 Subject: [PATCH 09/17] Upgrade to support PHP 8.1 --- composer.json | 6 +++--- phpunit.xml.dist | 3 +++ src/Message/PayoutRequest.php | 2 +- tests/GatewayTest.php | 2 +- tests/Message/CompletePurchaseRequestTest.php | 2 +- tests/Message/CompletePurchaseResponseTest.php | 2 +- tests/Message/FetchTransactionRequestTest.php | 2 +- tests/Message/FetchTransactionResponseTest.php | 2 +- tests/Message/PayoutRequestTest.php | 4 ++-- tests/Message/PayoutResponseTest.php | 2 +- tests/Message/PurchaseRequestTest.php | 2 +- tests/Message/PurchaseResponseTest.php | 2 +- 12 files changed, 17 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index 8f11756..eb17311 100644 --- a/composer.json +++ b/composer.json @@ -18,13 +18,13 @@ } }, "require": { - "php": "^7.0|^7.1|^7.2|^7.3|^7.4", + "php": "^7.0|^8.0", "ext-simplexml": "*", "ext-dom": "*", - "omnipay/common": "^3.0" + "omnipay/common": "^3.2" }, "require-dev": { - "omnipay/tests": "^3.0", + "omnipay/tests": "^4.1", "satooshi/php-coveralls": "1.0.0", "guzzlehttp/guzzle": "^6.5.5", "squizlabs/php_codesniffer": "3.*" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 1ecb290..5692c91 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -9,6 +9,9 @@ processIsolation="false" stopOnFailure="false" syntaxCheck="false"> + + + ./tests/ diff --git a/src/Message/PayoutRequest.php b/src/Message/PayoutRequest.php index 5749744..05763a1 100644 --- a/src/Message/PayoutRequest.php +++ b/src/Message/PayoutRequest.php @@ -279,7 +279,7 @@ public function getData() /** * @return Client */ - private function getHttpClient() + protected function getHttpClient() { return new Client($this->endpoint); } diff --git a/tests/GatewayTest.php b/tests/GatewayTest.php index 47785e5..ed5937a 100644 --- a/tests/GatewayTest.php +++ b/tests/GatewayTest.php @@ -9,7 +9,7 @@ class GatewayTest extends GatewayTestCase public $sslFile; public $sslKey; - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/Message/CompletePurchaseRequestTest.php b/tests/Message/CompletePurchaseRequestTest.php index e97c87f..83b8423 100644 --- a/tests/Message/CompletePurchaseRequestTest.php +++ b/tests/Message/CompletePurchaseRequestTest.php @@ -9,7 +9,7 @@ class CompletePurchaseRequestTest extends TestCase { private $request; - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/Message/CompletePurchaseResponseTest.php b/tests/Message/CompletePurchaseResponseTest.php index 1f0fe1d..74d5f3b 100644 --- a/tests/Message/CompletePurchaseResponseTest.php +++ b/tests/Message/CompletePurchaseResponseTest.php @@ -9,7 +9,7 @@ class CompletePurchaseResponseTest extends TestCase { private $request; - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/Message/FetchTransactionRequestTest.php b/tests/Message/FetchTransactionRequestTest.php index d13f3ae..e5c3f36 100644 --- a/tests/Message/FetchTransactionRequestTest.php +++ b/tests/Message/FetchTransactionRequestTest.php @@ -8,7 +8,7 @@ class FetchTransactionRequestTest extends TestCase { private $request; - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/Message/FetchTransactionResponseTest.php b/tests/Message/FetchTransactionResponseTest.php index 7bc6465..2d1449b 100644 --- a/tests/Message/FetchTransactionResponseTest.php +++ b/tests/Message/FetchTransactionResponseTest.php @@ -9,7 +9,7 @@ class FetchTransactionResponseTest extends TestCase private $request; - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/Message/PayoutRequestTest.php b/tests/Message/PayoutRequestTest.php index 39ee8aa..d81324d 100644 --- a/tests/Message/PayoutRequestTest.php +++ b/tests/Message/PayoutRequestTest.php @@ -12,7 +12,7 @@ class PayoutRequestTest extends TestCase { private $request; - public function setUp() + public function setUp(): void { parent::setUp(); @@ -28,7 +28,7 @@ public function setUp() $httpClient->addSubscriber($mockPlugin); $this->request = $this->getMockBuilder(PayoutRequest::class) - ->setMethods(['getHttpClient']) + ->onlyMethods(['getHttpClient']) ->setConstructorArgs([$this->getHttpClient(), $this->getHttpRequest()]) ->getMock(); diff --git a/tests/Message/PayoutResponseTest.php b/tests/Message/PayoutResponseTest.php index a39696f..308cf8e 100644 --- a/tests/Message/PayoutResponseTest.php +++ b/tests/Message/PayoutResponseTest.php @@ -9,7 +9,7 @@ class PayoutResponseTest extends TestCase private $request; - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/Message/PurchaseRequestTest.php b/tests/Message/PurchaseRequestTest.php index 6c24d1f..388a012 100644 --- a/tests/Message/PurchaseRequestTest.php +++ b/tests/Message/PurchaseRequestTest.php @@ -9,7 +9,7 @@ class PurchaseRequestTest extends TestCase { private $request; - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/Message/PurchaseResponseTest.php b/tests/Message/PurchaseResponseTest.php index 47e2b1c..e38e576 100644 --- a/tests/Message/PurchaseResponseTest.php +++ b/tests/Message/PurchaseResponseTest.php @@ -8,7 +8,7 @@ class PurchaseResponseTest extends TestCase { private $request; - public function setUp() + public function setUp(): void { parent::setUp(); From 547d4bd0cac5ad5861a462e3c75141f91e8b367e Mon Sep 17 00:00:00 2001 From: SilverFire - Dmitry Naumenko Date: Fri, 25 Mar 2022 18:40:18 +0200 Subject: [PATCH 10/17] Enable newer PHP versions on Travis --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index bcfcdeb..7111012 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,10 @@ php: - 7.0 - 7.1 - 7.2 + - 7.3 + - 7.4 + - 8.0 + - 8.1 before_script: - composer install -n --dev --prefer-source From f8904eeeed877cda8dff5477d0b478b10f18f0e4 Mon Sep 17 00:00:00 2001 From: Dmytro Naumenko Date: Wed, 20 Apr 2022 10:24:41 +0300 Subject: [PATCH 11/17] Suggest using newer version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6fc95de..3e0d5d9 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ to your `composer.json` file: ```json { "require": { - "dercoder/omnipay-webmoney": "~4.0" + "dercoder/omnipay-webmoney": "^5.0" } } ``` From 5e37af3c8860c51935960db1af86234ffdba8347 Mon Sep 17 00:00:00 2001 From: Dmytro Naumenko Date: Fri, 27 Dec 2024 17:38:48 +0200 Subject: [PATCH 12/17] Added WMT currency support --- src/Message/AbstractRequest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index 19a4356..2530b2d 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -236,6 +236,7 @@ public function getCurrencyByPurse($purse) { switch (substr($purse, 0, 1)) { case 'Z': + case 'T': return 'USD'; case 'R': return 'RUB'; From 38c987a13c9c759e66b5b109b70a3fb17358b618 Mon Sep 17 00:00:00 2001 From: Dmytro Naumenko Date: Fri, 27 Dec 2024 17:42:45 +0200 Subject: [PATCH 13/17] Added WMT test case --- tests/Message/PurchaseRequestTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Message/PurchaseRequestTest.php b/tests/Message/PurchaseRequestTest.php index 388a012..97e7bab 100644 --- a/tests/Message/PurchaseRequestTest.php +++ b/tests/Message/PurchaseRequestTest.php @@ -87,6 +87,7 @@ public function testGetCurrencyByPurse() $this->assertSame('UZS', $this->request->getCurrencyByPurse('Y123428476799')); $this->assertSame('BYR', $this->request->getCurrencyByPurse('B123428476799')); $this->assertSame('BTC', $this->request->getCurrencyByPurse('X123428476799')); + $this->assertSame('USDT', $this->request->getCurrencyByPurse('T123428476799')); $this->assertNull($this->request->getCurrencyByPurse('A123428476799')); } From 769cd70e281b961d6c0bc9b65a0a6dd9d8e32a44 Mon Sep 17 00:00:00 2001 From: Dmytro Naumenko Date: Fri, 27 Dec 2024 17:43:43 +0200 Subject: [PATCH 14/17] Use USDT for T purses --- src/Message/AbstractRequest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index 2530b2d..5a5781c 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -236,7 +236,6 @@ public function getCurrencyByPurse($purse) { switch (substr($purse, 0, 1)) { case 'Z': - case 'T': return 'USD'; case 'R': return 'RUB'; @@ -252,6 +251,8 @@ public function getCurrencyByPurse($purse) return 'BYR'; case 'X': return 'BTC'; + case 'T': + return 'USDT'; default: return null; } From 92b667697f52075d4202fb072dbd206b6f427910 Mon Sep 17 00:00:00 2001 From: Dmytro Naumenko Date: Fri, 27 Dec 2024 17:44:48 +0200 Subject: [PATCH 15/17] Added PHP 8.2, 8.3 to the build matrix --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 7111012..24f877f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,8 @@ php: - 7.4 - 8.0 - 8.1 + - 8.2 + - 8.3 before_script: - composer install -n --dev --prefer-source From 545b68ae6a2fe8e1cb1e83c278d2c63d4f502bdb Mon Sep 17 00:00:00 2001 From: Alexander Fedra Date: Sat, 28 Dec 2024 01:43:31 +0100 Subject: [PATCH 16/17] Update README.md --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3e0d5d9..67e0956 100644 --- a/README.md +++ b/README.md @@ -5,10 +5,9 @@ [![Build Status](https://app.travis-ci.com/dercoder/omnipay-webmoney.svg?branch=master)](https://app.travis-ci.com/github/dercoder/omnipay-webmoney) [![Coverage Status](https://coveralls.io/repos/dercoder/omnipay-webmoney/badge.svg?branch=master&service=github)](https://coveralls.io/github/dercoder/omnipay-webmoney?branch=master) -[![Latest Stable Version](https://poser.pugx.org/dercoder/omnipay-webmoney/v/stable.png)](https://packagist.org/packages/dercoder/omnipay-webmoney) -[![Total Downloads](https://poser.pugx.org/dercoder/omnipay-webmoney/downloads.png)](https://packagist.org/packages/dercoder/omnipay-webmoney) -[![Latest Unstable Version](https://poser.pugx.org/dercoder/omnipay-webmoney/v/unstable.png)](https://packagist.org/packages/dercoder/omnipay-webmoney) -[![License](https://poser.pugx.org/dercoder/omnipay-webmoney/license.png)](https://packagist.org/packages/dercoder/omnipay-webmoney) +[![Latest Stable Version](https://img.shields.io/packagist/v/dercoder/omnipay-webmoney)](https://packagist.org/packages/dercoder/omnipay-webmoney) +[![Total Downloads](https://img.shields.io/packagist/dt/dercoder/omnipay-webmoney)](https://packagist.org/packages/dercoder/omnipay-webmoney) +[![License](https://img.shields.io/packagist/l/dercoder/omnipay-webmoney)](https://packagist.org/packages/dercoder/omnipay-webmoney) [Omnipay](https://github.com/omnipay/omnipay) is a framework agnostic, multi-gateway payment processing library for PHP 7.0+. This package implements [WebMoney](https://www.webmoney.az) support for Omnipay. From 8b00baff96e17fa240fdecca3c53de06458f6d24 Mon Sep 17 00:00:00 2001 From: Yurii Myronchuk Date: Fri, 28 Feb 2025 09:01:20 +0000 Subject: [PATCH 17/17] Add supports cryptocurrencies --- src/Message/AbstractRequest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index 5a5781c..af2e6b2 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -257,4 +257,16 @@ public function getCurrencyByPurse($purse) return null; } } + + public function getCurrencies() + { + if ($this->currencies === null) { + $this->currencies = new \Money\Currencies\AggregateCurrencies([ + new \Money\Currencies\CryptoCurrencies(), + new \Money\Currencies\ISOCurrencies(), + ]); + } + + return $this->currencies; + } }