Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 55 additions & 3 deletions gopay-php-api.iml
Original file line number Diff line number Diff line change
@@ -1,6 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="SonarLintModuleSettings">
<option name="uniqueId" value="2d2c7470-064f-4688-a062-16b8bfd62359" />
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" packagePrefix="GoPay\" />
<sourceFolder url="file://$MODULE_DIR$/tests/integration" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/vendor/composer" />
<excludeFolder url="file://$MODULE_DIR$/vendor/doctrine/deprecations" />
<excludeFolder url="file://$MODULE_DIR$/vendor/doctrine/instantiator" />
<excludeFolder url="file://$MODULE_DIR$/vendor/guzzlehttp/guzzle" />
<excludeFolder url="file://$MODULE_DIR$/vendor/guzzlehttp/promises" />
<excludeFolder url="file://$MODULE_DIR$/vendor/guzzlehttp/psr7" />
<excludeFolder url="file://$MODULE_DIR$/vendor/hamcrest/hamcrest-php" />
<excludeFolder url="file://$MODULE_DIR$/vendor/myclabs/deep-copy" />
<excludeFolder url="file://$MODULE_DIR$/vendor/nikic/php-parser" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phar-io/manifest" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phar-io/version" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phpdocumentor/reflection-common" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phpdocumentor/reflection-docblock" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phpdocumentor/type-resolver" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phpspec/prophecy" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phpspec/prophecy-phpunit" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phpstan/phpdoc-parser" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/php-code-coverage" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/php-file-iterator" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/php-invoker" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/php-text-template" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/php-timer" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/phpunit" />
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/http-client" />
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/http-factory" />
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/http-message" />
<excludeFolder url="file://$MODULE_DIR$/vendor/ralouphie/getallheaders" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/cli-parser" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/code-unit" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/code-unit-reverse-lookup" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/comparator" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/complexity" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/diff" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/environment" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/exporter" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/global-state" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/lines-of-code" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/object-enumerator" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/object-reflector" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/recursion-context" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/type" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/version" />
<excludeFolder url="file://$MODULE_DIR$/vendor/staabm/side-effects-detector" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/deprecation-contracts" />
<excludeFolder url="file://$MODULE_DIR$/vendor/theseer/tokenizer" />
<excludeFolder url="file://$MODULE_DIR$/vendor/webmozart/assert" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
2 changes: 1 addition & 1 deletion src/GoPay.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class GoPay
const LOCALE_CZECH = 'cs-CZ';
const LOCALE_ENGLISH = 'en-US';

const VERSION = '1.10.4';
const VERSION = '1.11.0';
const DEFAULT_USER_AGENT = 'GoPay PHP ' . self::VERSION;

private $config;
Expand Down
16 changes: 16 additions & 0 deletions src/Payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ public function getStatus($id)
return $this->get("/payments/payment/{$id}");
}

/**
* Returns QR payment info for a given payment.
*
* @param int|string $id Payment ID
* @param string|null $format Image format of the QR code: 'png' (default) or 'svg'
* @return \GoPay\Http\Response
*/
public function getQrPayment($id, ?string $format = null)
{
$urlPath = "/payments/payment/{$id}/qr-payment";
if ($format !== null) {
$urlPath .= '?format=' . urlencode($format);
}
return $this->get($urlPath);
}

/** @see refundPaymentEET */
public function refundPayment($id, $data)
{
Expand Down
151 changes: 151 additions & 0 deletions tests/integration/QrPaymentTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<?php

namespace GoPay;

require_once 'TestUtils.php';
require_once 'CreatePaymentTest.php';

use PHPUnit\Framework\TestCase;

use function PHPUnit\Framework\assertNotEmpty;
use function PHPUnit\Framework\assertNotNull;
use function PHPUnit\Framework\assertArrayNotHasKey;
use function PHPUnit\Framework\assertArrayHasKey;

/**
* Class QrPaymentTest
* @package GoPay
*
* Tests for endpoint GET /payments/payment/{id}/qr-payment
* Run: C:\Php\php.exe bin\phpunit --configuration phpunit.xml.dist .\tests\integration\QrPaymentTest.php
*/
class QrPaymentTest extends TestCase
{
/** @var Payments */
private $gopay;

protected function setUp(): void
{
$this->gopay = TestUtils::setup();
}

/**
* Helper: creates a base payment and returns its ID.
*/
private function createPaymentAndGetId(): string
{
$basePayment = CreatePaymentTest::createBasePayment();
$response = $this->gopay->createPayment($basePayment);
$responseBody = $response->json;

assertNotEmpty($responseBody);
assertArrayNotHasKey('errors', $responseBody);
assertNotNull($responseBody['id']);

return (string) $responseBody['id'];
}

/**
* Creates a payment and fetches QR payment info with default format (png).
*/
public function testGetQrPaymentDefaultFormat()
{
$paymentId = $this->createPaymentAndGetId();
echo "\nCreated payment ID: {$paymentId}\n";

$response = $this->gopay->getQrPayment($paymentId);
$responseBody = $response->json;

echo "QR Payment response:\n";
echo print_r($responseBody, true);

assertNotEmpty($responseBody);
assertArrayNotHasKey('errors', $responseBody);

// Response must contain amount and currency
assertArrayHasKey('amount', $responseBody);
assertArrayHasKey('currency', $responseBody);

// Response must contain qr_code block with at least one QR type
assertArrayHasKey('qr_code', $responseBody);
$qrCode = $responseBody['qr_code'];
assertNotEmpty($qrCode);

// At least one of the known QR code types must be present
$knownTypes = ['spayd', 'paybysquare', 'sepa', 'mnb_qr'];
$foundAny = false;
foreach ($knownTypes as $type) {
if (!empty($qrCode[$type])) {
$foundAny = true;
echo "QR type '{$type}' is present (base64 length: " . strlen($qrCode[$type]) . ")\n";
}
}
$this->assertTrue($foundAny, 'Response qr_code must contain at least one QR code type (spayd, paybysquare, sepa, mnb_qr)');

echo "HTTP status: {$response->statusCode}\n";
}

/**
* Creates a payment and fetches QR payment info explicitly requesting PNG format.
*/
public function testGetQrPaymentPngFormat()
{
$paymentId = $this->createPaymentAndGetId();
echo "\nCreated payment ID: {$paymentId}\n";

$response = $this->gopay->getQrPayment($paymentId, 'png');
$responseBody = $response->json;

echo "QR Payment (png) response:\n";
echo print_r($responseBody, true);

assertNotEmpty($responseBody);
assertArrayNotHasKey('errors', $responseBody);
assertArrayHasKey('qr_code', $responseBody);

echo "HTTP status: {$response->statusCode}\n";
}

/**
* Creates a payment and fetches QR payment info requesting SVG format.
*/
public function testGetQrPaymentSvgFormat()
{
$paymentId = $this->createPaymentAndGetId();
echo "\nCreated payment ID: {$paymentId}\n";

$response = $this->gopay->getQrPayment($paymentId, 'svg');
$responseBody = $response->json;

echo "QR Payment (svg) response:\n";
echo print_r($responseBody, true);

assertNotEmpty($responseBody);
assertArrayNotHasKey('errors', $responseBody);
assertArrayHasKey('qr_code', $responseBody);

echo "HTTP status: {$response->statusCode}\n";
}

/**
* Verifies that the recipient info is returned in the response.
*/
public function testGetQrPaymentContainsRecipient()
{
$paymentId = $this->createPaymentAndGetId();

$response = $this->gopay->getQrPayment($paymentId);
$responseBody = $response->json;

assertNotEmpty($responseBody);
assertArrayNotHasKey('errors', $responseBody);

// Recipient block should be present
assertArrayHasKey('recipient', $responseBody);
$recipient = $responseBody['recipient'];
assertNotEmpty($recipient);

echo "\nRecipient info:\n";
echo print_r($recipient, true);
}
}
8 changes: 4 additions & 4 deletions tests/integration/TestUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
class TestUtils
{

const GO_ID = '8583067438';
const CLIENT_ID = '1223619925';
const CLIENT_SECRET = '6vkhVP8c';
const GO_ID = '8761908826';
const CLIENT_ID = 'app@musicshop.cz';
const CLIENT_SECRET = 'VpnJVcTn';

const GO_ID_EET = '8289213768';
const CLIENT_ID_EET = '1365575992';
Expand All @@ -22,7 +22,7 @@ public static function setup()
'goid' => self::GO_ID,
'clientId' => self::CLIENT_ID,
'clientSecret' => self::CLIENT_SECRET,
'gatewayUrl' => 'https://gw.sandbox.gopay.com/api',
'gatewayUrl' => 'https://gw.pmaryska.dev.gopay.com/api',
'language' => Language::CZECH
]);
return $gopay;
Expand Down
Loading