diff --git a/.github/workflows/code_checks.yaml b/.github/workflows/code_checks.yaml index 776cdf9..9cef462 100644 --- a/.github/workflows/code_checks.yaml +++ b/.github/workflows/code_checks.yaml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: ['7.3', '7.4', '8.0', '8.1', '8.2'] + php: ['8.0', '8.1', '8.2'] fail-fast: false name: PHPUnit (PHP ${{ matrix.php }}) steps: @@ -59,7 +59,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: 7.4 + php-version: 8.0 coverage: xdebug - name: Get Composer cache directory diff --git a/Action/CaptureReferencedAction.php b/Action/CaptureReferencedAction.php index 48ee8fa..75e9f50 100644 --- a/Action/CaptureReferencedAction.php +++ b/Action/CaptureReferencedAction.php @@ -41,7 +41,7 @@ public function execute($request): void { RequestNotSupportedException::assertSupports($this, $request); - /** @var $payment PaymentInterface */ + /** @var PaymentInterface $payment */ $payment = $request->getModel(); $this->gateway->execute($status = new GetHumanStatus($payment)); diff --git a/Action/InsertCardAliasAction.php b/Action/InsertCardAliasAction.php index 72b3a46..a8d2d5b 100644 --- a/Action/InsertCardAliasAction.php +++ b/Action/InsertCardAliasAction.php @@ -26,7 +26,7 @@ public function execute($request): void { RequestNotSupportedException::assertSupports($this, $request); - /** @var $cardAlias CardAliasInterface */ + /** @var CardAliasInterface $cardAlias */ $cardAlias = $request->getModel(); $details = ArrayObject::ensureArrayObject($cardAlias->getDetails()); diff --git a/Api.php b/Api.php index 4fdeef6..7e88ac1 100644 --- a/Api.php +++ b/Api.php @@ -10,32 +10,23 @@ class Api { - const SPEC_VERSION = '1.10'; - const PAYMENT_PAGE_INIT_PATH = '/Payment/v1/PaymentPage/Initialize'; - const PAYMENT_PAGE_ASSERT_PATH = '/Payment/v1/PaymentPage/Assert'; - const TRANSACTION_INIT_PATH = '/Payment/v1/Transaction/Initialize'; - const TRANSACTION_AUTHORIZE_PATH = '/Payment/v1/Transaction/Authorize'; - const TRANSACTION_AUTHORIZE_REFERENCED_PATH = '/Payment/v1/Transaction/AuthorizeReferenced'; - const TRANSACTION_CAPTURE_PATH = '/Payment/v1/Transaction/Capture'; - const TRANSACTION_REFUND_PATH = '/Payment/v1/Transaction/Refund'; - const ALIAS_INSERT_PATH = '/Payment/v1/Alias/Insert'; - const ALIAS_ASSERT_INSERT_PATH = '/Payment/v1/Alias/AssertInsert'; - const ALIAS_DELETE_PATH = '/Payment/v1/Alias/Delete'; - - /** - * @var HttpClientInterface - */ - protected $client; - - /** - * @var MessageFactory - */ - protected $messageFactory; - - /** - * @var array - */ - protected $options = array( + public const SPEC_VERSION = '1.10'; + public const PAYMENT_PAGE_INIT_PATH = '/Payment/v1/PaymentPage/Initialize'; + public const PAYMENT_PAGE_ASSERT_PATH = '/Payment/v1/PaymentPage/Assert'; + public const TRANSACTION_INIT_PATH = '/Payment/v1/Transaction/Initialize'; + public const TRANSACTION_AUTHORIZE_PATH = '/Payment/v1/Transaction/Authorize'; + public const TRANSACTION_AUTHORIZE_REFERENCED_PATH = '/Payment/v1/Transaction/AuthorizeReferenced'; + public const TRANSACTION_CAPTURE_PATH = '/Payment/v1/Transaction/Capture'; + public const TRANSACTION_REFUND_PATH = '/Payment/v1/Transaction/Refund'; + public const ALIAS_INSERT_PATH = '/Payment/v1/Alias/Insert'; + public const ALIAS_ASSERT_INSERT_PATH = '/Payment/v1/Alias/AssertInsert'; + public const ALIAS_DELETE_PATH = '/Payment/v1/Alias/Delete'; + + protected HttpClientInterface $client; + + protected MessageFactory $messageFactory; + + protected array|ArrayObject $options = [ 'username' => null, 'password' => null, 'customerId' => null, @@ -43,24 +34,28 @@ class Api 'sandbox' => null, 'interface' => null, 'optionalParameters' => null, - ); + ]; public function __construct(array $options, HttpClientInterface $client, MessageFactory $messageFactory) { - $options = ArrayObject::ensureArrayObject($options); - $options->defaults($this->options); - $options->validateNotEmpty([ + $optionsObj = ArrayObject::ensureArrayObject($options); + $optionsObj->defaults($this->options); + $optionsObj->validateNotEmpty([ 'username', 'password', 'customerId', 'terminalId', ]); if (!is_bool($options['sandbox'])) { throw new InvalidArgumentException('The boolean sandbox option must be set.'); } - $this->options = $options; + $this->options = $optionsObj; $this->client = $client; $this->messageFactory = $messageFactory; } + /** + * @param array $fields + * @return array + */ protected function doRequest(string $path, array $fields): array { $headers = [ @@ -72,7 +67,7 @@ protected function doRequest(string $path, array $fields): array 'RequestHeader' => [ 'SpecVersion' => self::SPEC_VERSION, 'CustomerId' => $this->options['customerId'], - 'RequestId' => uniqid(), + 'RequestId' => uniqid('', true), 'RetryIndicator' => 0, ], ], $fields); @@ -95,7 +90,7 @@ protected function doRequest(string $path, array $fields): array ); } - private function parseResponse($content) + private function parseResponse(string $content): array { return json_decode($content, true); } diff --git a/Constants.php b/Constants.php index d3f9dec..244a154 100644 --- a/Constants.php +++ b/Constants.php @@ -4,31 +4,31 @@ interface Constants { - const INTERFACE_PAYMENT_PAGE = 'PAYMENT_PAGE'; - const INTERFACE_TRANSACTION = 'TRANSACTION'; + public const INTERFACE_PAYMENT_PAGE = 'PAYMENT_PAGE'; + public const INTERFACE_TRANSACTION = 'TRANSACTION'; - const STATUS_PENDING = 'PENDING'; - const STATUS_AUTHORIZED = 'AUTHORIZED'; - const STATUS_CAPTURED = 'CAPTURED'; - const STATUS_CANCELED = 'CANCELED'; - const STATUS_ABORTED = 'ABORTED'; - const STATUS_FAILED = 'FAILED'; + public const STATUS_PENDING = 'PENDING'; + public const STATUS_AUTHORIZED = 'AUTHORIZED'; + public const STATUS_CAPTURED = 'CAPTURED'; + public const STATUS_CANCELED = 'CANCELED'; + public const STATUS_ABORTED = 'ABORTED'; + public const STATUS_FAILED = 'FAILED'; - const TYPE_PURCHASE = 'PURCHASE'; - const TYPE_PAYMENT = 'PAYMENT'; - const TYPE_REFUND = 'REFUND'; + public const TYPE_PURCHASE = 'PURCHASE'; + public const TYPE_PAYMENT = 'PAYMENT'; + public const TYPE_REFUND = 'REFUND'; - const ALIAS_TYPE_CARD = 'CARD'; - const ALIAS_TYPE_BANK_ACCOUNT = 'BANK_ACCOUNT'; - const ALIAS_TYPE_POSTFINANCE = 'POSTFINANCE'; - const ALIAS_TYPE_TWINT = 'TWINT'; + public const ALIAS_TYPE_CARD = 'CARD'; + public const ALIAS_TYPE_BANK_ACCOUNT = 'BANK_ACCOUNT'; + public const ALIAS_TYPE_POSTFINANCE = 'POSTFINANCE'; + public const ALIAS_TYPE_TWINT = 'TWINT'; - const ALIAS_ID_GENERATOR_MANUAL = 'MANUAL'; - const ALIAS_ID_GENERATOR_RANDOM = 'RANDOM'; - const ALIAS_ID_GENERATOR_RANDOM_UNIQUE = 'RANDOM_UNIQUE'; + public const ALIAS_ID_GENERATOR_MANUAL = 'MANUAL'; + public const ALIAS_ID_GENERATOR_RANDOM = 'RANDOM'; + public const ALIAS_ID_GENERATOR_RANDOM_UNIQUE = 'RANDOM_UNIQUE'; - const LS_IF_ALLOWED_BY_SCHEME = 'IF_ALLOWED_BY_SCHEME'; - const LS_WITH_LIABILITY_SHIFT = 'WITH_LIABILITY_SHIFT'; + public const LS_IF_ALLOWED_BY_SCHEME = 'IF_ALLOWED_BY_SCHEME'; + public const LS_WITH_LIABILITY_SHIFT = 'WITH_LIABILITY_SHIFT'; - const ERROR_NAME_TRANSACTION_ALREADY_CAPTURED = 'TRANSACTION_ALREADY_CAPTURED'; + public const ERROR_NAME_TRANSACTION_ALREADY_CAPTURED = 'TRANSACTION_ALREADY_CAPTURED'; } diff --git a/Exception/SaferpayHttpException.php b/Exception/SaferpayHttpException.php index b0de336..250c9f0 100644 --- a/Exception/SaferpayHttpException.php +++ b/Exception/SaferpayHttpException.php @@ -9,18 +9,16 @@ final class SaferpayHttpException extends HttpException { // https://saferpay.github.io/jsonapi/index.html#errorhandling - const BEHAVIOR_ABORT = 'ABORT'; - const BEHAVIOR_RETRY = 'RETRY'; - const BEHAVIOR_RETRY_LATER = 'RETRY_LATER'; - const BEHAVIOR_OTHER_MEANS = 'OTHER_MEANS'; + public const BEHAVIOR_ABORT = 'ABORT'; + public const BEHAVIOR_RETRY = 'RETRY'; + public const BEHAVIOR_RETRY_LATER = 'RETRY_LATER'; + public const BEHAVIOR_OTHER_MEANS = 'OTHER_MEANS'; - /** @var array|null */ - protected $data; + protected ?array $data = null; + protected ?string $info = null; - /** @var string|null */ - protected $info; - - public static function factory(RequestInterface $request, ResponseInterface $response) { + public static function factory(RequestInterface $request, ResponseInterface $response): SaferpayHttpException + { /** @var SaferpayHttpException $e */ $e = parent::factory($request, $response); $contents = $response->getBody()->getContents(); diff --git a/Model/CardAlias.php b/Model/CardAlias.php index d5f1ae8..01c7fa2 100644 --- a/Model/CardAlias.php +++ b/Model/CardAlias.php @@ -6,11 +6,7 @@ class CardAlias extends CreditCard implements CardAliasInterface { - /** - * @var array - */ - protected $details; - + protected array $details; public function __construct() { @@ -24,7 +20,7 @@ public function getDetails(): array } /** - * @param array $details + * @param array|\Traversable $details */ public function setDetails($details): void { diff --git a/README.md b/README.md index ad346ed..8d610b0 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Here is how Transaction interface looks like: ## Requirements -- PHP 7.3+ +- PHP 8.0+ - [Payum](https://github.com/Payum/Payum) - Optionally [PayumBundle](https://github.com/Payum/PayumBundle) and Symfony 3 or 4+ @@ -343,27 +343,27 @@ payum: ``` #### Payment Page interface -| Key | Description | -| --------------------------------------| ------------| -| `config_set` | This parameter let you define your payment page config (PPConfig) by name. If this parameters is not set, your default PPConfig will be applied if available. When the PPConfig can't be found (e.g. wrong name), the Saferpay basic style will be applied to the payment page. | -| `payment_methods` | Used to restrict the means of payment which are available to the payer for this transaction. If only one payment method id is set, the payment selection step will be skipped. | -| `wallets` | Used to control if wallets should be enabled on the payment selection page and to go directly to the given wallet (if exactly one wallet is filled and PaymentMethods is not set). | -| `notification_merchant_email` | Email addresses to which a confirmation email will be sent to the merchants after successful authorizations. | -| `notification_payer_email` | Email address to which a confirmation email will be sent to the payer after successful authorizations. | -| `styling_css_url` | Deprecated | -| `styling_content_security_enabled` | When enabled, then ContentSecurity/SAQ-A is requested, which leads to the CSS being loaded from the saferpay server. | -| `styling_theme` | This parameter let you customize the appearance of the displayed payment pages. Per default a lightweight responsive styling will be applied.If you don't want any styling use 'NONE'. | -| `payer_note` | Text which will be printed on payer's debit note. Supported by SIX Acquiring. No guarantee that it will show up on the payer's debit note, because his bank has to support it too. Please note that maximum allowed characters are rarely supported. It's usually around 10-12. | +| Key | Description | +|------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `config_set` | This parameter let you define your payment page config (PPConfig) by name. If this parameters is not set, your default PPConfig will be applied if available. When the PPConfig can't be found (e.g. wrong name), the Saferpay basic style will be applied to the payment page. | +| `payment_methods` | Used to restrict the means of payment which are available to the payer for this transaction. If only one payment method id is set, the payment selection step will be skipped. | +| `wallets` | Used to control if wallets should be enabled on the payment selection page and to go directly to the given wallet (if exactly one wallet is filled and PaymentMethods is not set). | +| `notification_merchant_email` | Email addresses to which a confirmation email will be sent to the merchants after successful authorizations. | +| `notification_payer_email` | Email address to which a confirmation email will be sent to the payer after successful authorizations. | +| `styling_css_url` | Deprecated | +| `styling_content_security_enabled` | When enabled, then ContentSecurity/SAQ-A is requested, which leads to the CSS being loaded from the saferpay server. | +| `styling_theme` | This parameter let you customize the appearance of the displayed payment pages. Per default a lightweight responsive styling will be applied.If you don't want any styling use 'NONE'. | +| `payer_note` | Text which will be printed on payer's debit note. Supported by SIX Acquiring. No guarantee that it will show up on the payer's debit note, because his bank has to support it too. Please note that maximum allowed characters are rarely supported. It's usually around 10-12. | #### Transaction interface -| Key | Description | -| --------------------------------------| ------------| -| `config_set` | This parameter let you define your payment page config (PPConfig) by name. If this parameters is not set, your default PPConfig will be applied if available. When the PPConfig can't be found (e.g. wrong name), the Saferpay basic style will be applied to the payment page. | -| `payment_methods` | Used to restrict the means of payment which are available to the payer for this transaction. If only one payment method id is set, the payment selection step will be skipped. | -| `styling_css_url` | Deprecated | -| `styling_content_security_enabled` | When enabled, then ContentSecurity/SAQ-A is requested, which leads to the CSS being loaded from the saferpay server. | -| `styling_theme` | This parameter let you customize the appearance of the displayed payment pages. Per default a lightweight responsive styling will be applied. If you don't want any styling use 'NONE'. | -| `payer_note` | Text which will be printed on payer's debit note. Supported by SIX Acquiring. No guarantee that it will show up on the payer's debit note, because his bank has to support it too. Please note that maximum allowed characters are rarely supported. It's usually around 10-12. | +| Key | Description | +|------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `config_set` | This parameter let you define your payment page config (PPConfig) by name. If this parameters is not set, your default PPConfig will be applied if available. When the PPConfig can't be found (e.g. wrong name), the Saferpay basic style will be applied to the payment page. | +| `payment_methods` | Used to restrict the means of payment which are available to the payer for this transaction. If only one payment method id is set, the payment selection step will be skipped. | +| `styling_css_url` | Deprecated | +| `styling_content_security_enabled` | When enabled, then ContentSecurity/SAQ-A is requested, which leads to the CSS being loaded from the saferpay server. | +| `styling_theme` | This parameter let you customize the appearance of the displayed payment pages. Per default a lightweight responsive styling will be applied. If you don't want any styling use 'NONE'. | +| `payer_note` | Text which will be printed on payer's debit note. Supported by SIX Acquiring. No guarantee that it will show up on the payer's debit note, because his bank has to support it too. Please note that maximum allowed characters are rarely supported. It's usually around 10-12. | ## Testing ``` diff --git a/SaferpayGatewayFactory.php b/SaferpayGatewayFactory.php index 3758295..7c9591a 100644 --- a/SaferpayGatewayFactory.php +++ b/SaferpayGatewayFactory.php @@ -64,7 +64,7 @@ protected function populateConfig(ArrayObject $config): void $prependActions[] = 'payum.action.insert_card_alias'; $config['payum.prepend_actions'] = $prependActions; - if (false == $config['payum.api']) { + if (!$config['payum.api']) { $config['payum.default_options'] = [ 'sandbox' => true, 'instantCapturing' => true, @@ -72,7 +72,7 @@ protected function populateConfig(ArrayObject $config): void $config->defaults($config['payum.default_options']); $config['payum.required_options'] = ['username', 'password', 'customerId', 'terminalId']; - $config['payum.api'] = function (ArrayObject $config) { + $config['payum.api'] = static function (ArrayObject $config) { $config->validateNotEmpty($config['payum.required_options']); return new Api((array) $config, $config['payum.http_client'], $config['httplug.message_factory']); diff --git a/Tests/Functional/AbstractSaferpayTest.php b/Tests/Functional/AbstractSaferpayTest.php index e9958e9..98fd9e8 100644 --- a/Tests/Functional/AbstractSaferpayTest.php +++ b/Tests/Functional/AbstractSaferpayTest.php @@ -23,7 +23,6 @@ use Payum\Core\Storage\FilesystemStorage; use Payum\Core\Storage\StorageInterface; use PHPUnit\Framework\TestCase; -use Symfony\Component\BrowserKit\Exception\BadMethodCallException; use Symfony\Component\BrowserKit\Response; use Symfony\Component\DomCrawler\Crawler; @@ -42,20 +41,11 @@ abstract class AbstractSaferpayTest extends TestCase protected const CARD_SUCCESS = '9030101152000007'; protected const CARD_FAILED = '9030100152000009'; //'9010100152000003'; - /** @var Payum */ - protected $payum; - - /** @var GatewayInterface */ - protected $gateway; - - /** @var StorageInterface */ - protected $storage; - - /** @var StorageInterface */ - protected $cardAliasStorage; - - /** @var Client */ - protected $client; + protected Payum $payum; + protected GatewayInterface $gateway; + protected StorageInterface $storage; + protected StorageInterface $cardAliasStorage; + protected Client $client; public function setUp(): void { @@ -97,9 +87,6 @@ protected function getGatewayConfig(): array protected function submitForm(string $buttonSel, array $fieldValues = [], string $method = 'POST', array $serverParameters = []): Crawler { $crawler = $this->client->getCrawler(); - if (null === $crawler) { - throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__)); - } $buttonNode = $crawler->filter($buttonSel)->first(); $form = $buttonNode->form($fieldValues, $method); @@ -110,9 +97,6 @@ protected function submitForm(string $buttonSel, array $fieldValues = [], string protected function clickLink(string $linkSelector): Crawler { $crawler = $this->client->getCrawler(); - if (null === $crawler) { - throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__)); - } return $this->client->click($crawler->filter($linkSelector)->link()); } @@ -120,9 +104,6 @@ protected function clickLink(string $linkSelector): Crawler protected function clickButton(string $buttonSelector): Crawler { $crawler = $this->client->getCrawler(); - if (null === $crawler) { - throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__)); - } $buttonNode = $crawler->filter($buttonSelector)->first(); $form = $buttonNode->form([], 'POST'); @@ -161,7 +142,7 @@ protected function createPayment(array $details = []): Payment { /** @var Payment $payment */ $payment = $this->storage->create(); - $payment->setNumber(uniqid()); + $payment->setNumber(uniqid('', true)); $payment->setCurrencyCode(self::CURRENCY); $payment->setTotalAmount(self::AMOUNT); $payment->setDescription(self::DESCRIPTION); @@ -173,20 +154,20 @@ protected function createPayment(array $details = []): Payment protected function getThroughCheckout(string $url, array $formData, string $action = 'submit'): string { $this->client->request('GET', $url); - if (false !== strpos($url, '/vt2/api/PaymentPage')) { + if (str_contains($url, '/vt2/api/PaymentPage')) { $this->client->followRedirect(); $this->client->submitForm('MasterCard'); $this->client->followRedirect(); } if ( - false !== strpos($this->client->getCrawler()->getUri(), '/VT2/mpp/PaymentDataEntry/Index') - || false !== strpos($this->client->getCrawler()->getUri(), '/vt2/Api/Post') - || false !== strpos($this->client->getCrawler()->getUri(), '/vt2/api/register/card') + str_contains($this->client->getCrawler()->getUri(), '/VT2/mpp/PaymentDataEntry/Index') + || str_contains($this->client->getCrawler()->getUri(), '/vt2/Api/Post') + || str_contains($this->client->getCrawler()->getUri(), '/vt2/api/register/card') ) { if ($action === 'abort') { $location = $this->client->getCrawler()->filter('button.btn-abort')->attr('formaction'); - if (0 === strpos($location, self::HOST)) { + if (str_starts_with($location, self::HOST)) { return $location; } $this->clickButton('button.btn-abort'); @@ -197,22 +178,22 @@ protected function getThroughCheckout(string $url, array $formData, string $acti $response = $this->client->getResponse(); if ($response->getStatusCode() === 302) { $location = $response->getHeader('Location'); - if (0 === strpos($location, self::HOST)) { + if (str_starts_with($location, self::HOST)) { return $location; } $this->client->followRedirect(); } } - if (false !== strpos($this->client->getCrawler()->getUri(), '/VT2/mpp/PaymentDataEntry/Index')) { + if (str_contains($this->client->getCrawler()->getUri(), '/VT2/mpp/PaymentDataEntry/Index')) { self::assertSame(200, $this->client->getResponse()->getStatusCode()); $this->client->submitForm( $action === 'submit' ? 'Buy' : 'Cancel'); self::assertSame(302, $this->client->getResponse()->getStatusCode()); $this->client->followRedirect(); } if ( - false !== strpos($this->client->getCrawler()->getUri(), '/VT2/mpp/ThreeDS/Index') - || false !== strpos($this->client->getCrawler()->getUri(), '/VT2/api/ThreeDs') + str_contains($this->client->getCrawler()->getUri(), '/VT2/mpp/ThreeDS/Index') + || str_contains($this->client->getCrawler()->getUri(), '/VT2/api/ThreeDs') ) { self::assertSame(200, $this->client->getResponse()->getStatusCode()); $this->submitForm('[type="submit"]'); @@ -228,18 +209,18 @@ protected function getThroughCheckout(string $url, array $formData, string $acti $response = $this->client->getResponse(); self::assertSame(302, $response->getStatusCode()); $location = $response->getHeader('Location'); - if (0 === strpos($location, self::HOST)) { + if (str_starts_with($location, self::HOST)) { return $location; } $this->client->followRedirect(); } - if (false !== strpos($this->client->getCrawler()->getUri(), '/VT2/mpp/Error/System')) { + if (str_contains($this->client->getCrawler()->getUri(), '/VT2/mpp/Error/System')) { $this->client->submitForm('Cancel'); $response = $this->client->getResponse(); self::assertSame(302, $response->getStatusCode()); $location = $response->getHeader('Location'); - if (0 === strpos($location, self::HOST)) { + if (str_starts_with($location, self::HOST)) { return $location; } $this->client->followRedirect(); @@ -316,7 +297,7 @@ protected function createInsertedCardAlias(array $options): CardAliasInterface $reply = $this->insertCardAlias($token, $cardAlias); # submit form - $iframeRedirect = $this->getThroughCheckout($reply->getUrl(), $this->composeFormData(self::CARD_SUCCESS, $cvc = false)); + $iframeRedirect = $this->getThroughCheckout($reply->getUrl(), $this->composeFormData(self::CARD_SUCCESS, cvc: false)); parse_str(parse_url($iframeRedirect, PHP_URL_QUERY), $_GET); $this->insertCardAlias($token, $cardAlias); diff --git a/Tests/Functional/CardAliasTest.php b/Tests/Functional/CardAliasTest.php index 6b88bff..7f2f42a 100644 --- a/Tests/Functional/CardAliasTest.php +++ b/Tests/Functional/CardAliasTest.php @@ -30,10 +30,10 @@ public function insertAlias(): void #assert redirected self::assertInstanceOf(HttpRedirect::class, $reply); - self::assertStringStartsWith('https://test.saferpay.com/', $iframeUrl = $reply->getUrl()); + self::assertStringStartsWith('https://test.saferpay.com/', $reply->getUrl()); # submit form - $iframeRedirect = $this->getThroughCheckout($reply->getUrl(), $formData = $this->composeFormData(self::CARD_SUCCESS, $cvc = false)); + $iframeRedirect = $this->getThroughCheckout($reply->getUrl(), $formData = $this->composeFormData(self::CARD_SUCCESS, false)); self::assertStringStartsWith(self::HOST, $iframeRedirect); self::assertStringContainsString('payum_token='.$token->getHash(), $iframeRedirect); diff --git a/Tests/Unit/Action/Api/AssertInsertAliasActionTest.php b/Tests/Unit/Action/Api/AssertInsertAliasActionTest.php index 77d49f6..0b7a873 100644 --- a/Tests/Unit/Action/Api/AssertInsertAliasActionTest.php +++ b/Tests/Unit/Action/Api/AssertInsertAliasActionTest.php @@ -7,6 +7,6 @@ class AssertInsertAliasActionTest extends BaseApiActionTest { - protected $actionClass = AssertInsertAliasAction::class; - protected $requestClass = AssertInsertAlias::class; + protected string $actionClass = AssertInsertAliasAction::class; + protected string $requestClass = AssertInsertAlias::class; } diff --git a/Tests/Unit/Action/Api/AssertPaymentPageActionTest.php b/Tests/Unit/Action/Api/AssertPaymentPageActionTest.php index 808e1e0..a3e2869 100644 --- a/Tests/Unit/Action/Api/AssertPaymentPageActionTest.php +++ b/Tests/Unit/Action/Api/AssertPaymentPageActionTest.php @@ -7,6 +7,6 @@ class AssertPaymentPageActionTest extends BaseApiActionTest { - protected $actionClass = AssertPaymentPageAction::class; - protected $requestClass = AssertPaymentPage::class; + protected string $actionClass = AssertPaymentPageAction::class; + protected string $requestClass = AssertPaymentPage::class; } diff --git a/Tests/Unit/Action/Api/AuthorizeReferencedTransactionActionTest.php b/Tests/Unit/Action/Api/AuthorizeReferencedTransactionActionTest.php index e2359ed..e2024a7 100644 --- a/Tests/Unit/Action/Api/AuthorizeReferencedTransactionActionTest.php +++ b/Tests/Unit/Action/Api/AuthorizeReferencedTransactionActionTest.php @@ -9,8 +9,8 @@ class AuthorizeReferencedTransactionActionTest extends BaseApiActionTest { - protected $actionClass = AuthorizeReferencedTransactionAction::class; - protected $requestClass = AuthorizeReferencedTransaction::class; + protected string $actionClass = AuthorizeReferencedTransactionAction::class; + protected string $requestClass = AuthorizeReferencedTransaction::class; /** diff --git a/Tests/Unit/Action/Api/AuthorizeTransactionActionTest.php b/Tests/Unit/Action/Api/AuthorizeTransactionActionTest.php index f76656f..fc08732 100644 --- a/Tests/Unit/Action/Api/AuthorizeTransactionActionTest.php +++ b/Tests/Unit/Action/Api/AuthorizeTransactionActionTest.php @@ -9,8 +9,8 @@ class AuthorizeTransactionActionTest extends BaseApiActionTest { - protected $actionClass = AuthorizeTransactionAction::class; - protected $requestClass = AuthorizeTransaction::class; + protected string $actionClass = AuthorizeTransactionAction::class; + protected string $requestClass = AuthorizeTransaction::class; /** * @test diff --git a/Tests/Unit/Action/Api/BaseApiActionTest.php b/Tests/Unit/Action/Api/BaseApiActionTest.php index b8d2813..603c420 100644 --- a/Tests/Unit/Action/Api/BaseApiActionTest.php +++ b/Tests/Unit/Action/Api/BaseApiActionTest.php @@ -12,10 +12,10 @@ abstract class BaseApiActionTest extends TestCase { - protected $actionClass; - protected $requestClass; + protected string $actionClass; + protected string $requestClass; - protected $model = [ + protected array $model = [ 'Payment' => [ 'Amount' => [ 'Value' => 123, @@ -98,17 +98,12 @@ public function throwIfNotSupportedRequestGivenAsArgumentForExecute(): void $action->execute(new \stdClass()); } - /** - * @return MockObject|Api - */ - protected function createApiMock() + protected function createApiMock(): Api|MockObject { return $this->getMockBuilder(Api::class)->disableOriginalConstructor()->getMock(); } - /** - * @return MockObject|GatewayInterface - */ - protected function createGatewayMock() + + protected function createGatewayMock(): GatewayInterface|MockObject { return $this->createMock(GatewayInterface::class); } diff --git a/Tests/Unit/Action/Api/CaptureTransactionActionTest.php b/Tests/Unit/Action/Api/CaptureTransactionActionTest.php index 1918041..45b99fd 100644 --- a/Tests/Unit/Action/Api/CaptureTransactionActionTest.php +++ b/Tests/Unit/Action/Api/CaptureTransactionActionTest.php @@ -9,8 +9,8 @@ class CaptureTransactionActionTest extends BaseApiActionTest { - protected $actionClass = CaptureTransactionAction::class; - protected $requestClass = CaptureTransaction::class; + protected string $actionClass = CaptureTransactionAction::class; + protected string $requestClass = CaptureTransaction::class; /** * @test diff --git a/Tests/Unit/Action/Api/DeleteAliasActionTest.php b/Tests/Unit/Action/Api/DeleteAliasActionTest.php index 523a9d7..65cc149 100644 --- a/Tests/Unit/Action/Api/DeleteAliasActionTest.php +++ b/Tests/Unit/Action/Api/DeleteAliasActionTest.php @@ -7,6 +7,6 @@ class DeleteAliasActionTest extends BaseApiActionTest { - protected $actionClass = DeleteAliasAction::class; - protected $requestClass = DeleteAlias::class; + protected string $actionClass = DeleteAliasAction::class; + protected string $requestClass = DeleteAlias::class; } diff --git a/Tests/Unit/Action/Api/InitPaymentPageActionTest.php b/Tests/Unit/Action/Api/InitPaymentPageActionTest.php index 2026207..68ee2bd 100644 --- a/Tests/Unit/Action/Api/InitPaymentPageActionTest.php +++ b/Tests/Unit/Action/Api/InitPaymentPageActionTest.php @@ -7,6 +7,6 @@ class InitPaymentPageActionTest extends BaseApiActionTest { - protected $actionClass = InitPaymentPageAction::class; - protected $requestClass = InitPaymentPage::class; + protected string $actionClass = InitPaymentPageAction::class; + protected string $requestClass = InitPaymentPage::class; } diff --git a/Tests/Unit/Action/Api/InitTransactionActionTest.php b/Tests/Unit/Action/Api/InitTransactionActionTest.php index 6dd6ab7..3aed284 100644 --- a/Tests/Unit/Action/Api/InitTransactionActionTest.php +++ b/Tests/Unit/Action/Api/InitTransactionActionTest.php @@ -7,8 +7,8 @@ class InitTransactionActionTest extends BaseApiActionTest { - protected $actionClass = InitTransactionAction::class; - protected $requestClass = InitTransaction::class; + protected string $actionClass = InitTransactionAction::class; + protected string $requestClass = InitTransaction::class; /** * @test diff --git a/Tests/Unit/Action/Api/InsertAliasActionTest.php b/Tests/Unit/Action/Api/InsertAliasActionTest.php index b12f74e..1873eae 100644 --- a/Tests/Unit/Action/Api/InsertAliasActionTest.php +++ b/Tests/Unit/Action/Api/InsertAliasActionTest.php @@ -7,6 +7,6 @@ class InsertAliasActionTest extends BaseApiActionTest { - protected $actionClass = InsertAliasAction::class; - protected $requestClass = InsertAlias::class; + protected string $actionClass = InsertAliasAction::class; + protected string $requestClass = InsertAlias::class; } diff --git a/Tests/Unit/Action/Api/RefundTransactionActionTest.php b/Tests/Unit/Action/Api/RefundTransactionActionTest.php index 084c4b4..48f2809 100644 --- a/Tests/Unit/Action/Api/RefundTransactionActionTest.php +++ b/Tests/Unit/Action/Api/RefundTransactionActionTest.php @@ -7,7 +7,7 @@ class RefundTransactionActionTest extends BaseApiActionTest { - protected $actionClass = RefundTransactionAction::class; - protected $requestClass = RefundTransaction::class; + protected string $actionClass = RefundTransactionAction::class; + protected string $requestClass = RefundTransaction::class; } diff --git a/Tests/Unit/Action/AuthorizeActionTest.php b/Tests/Unit/Action/AuthorizeActionTest.php index aa91a7d..d1cb9a1 100644 --- a/Tests/Unit/Action/AuthorizeActionTest.php +++ b/Tests/Unit/Action/AuthorizeActionTest.php @@ -13,7 +13,6 @@ class AuthorizeActionTest extends GenericActionTest protected $requestClass = Authorize::class; protected $actionClass = AuthorizeAction::class; - /** * @test */ diff --git a/Tests/Unit/Action/CancelActionTest.php b/Tests/Unit/Action/CancelActionTest.php index c11bdb6..9049d31 100644 --- a/Tests/Unit/Action/CancelActionTest.php +++ b/Tests/Unit/Action/CancelActionTest.php @@ -4,7 +4,6 @@ use Karser\PayumSaferpay\Action\CancelAction; use Payum\Core\Action\ActionInterface; -use Payum\Core\GatewayAwareInterface; use Payum\Core\Request\Cancel; use Payum\Core\Tests\GenericActionTest; @@ -13,7 +12,6 @@ class CancelActionTest extends GenericActionTest protected $requestClass = Cancel::class; protected $actionClass = CancelAction::class; - /** * @test */ diff --git a/Tests/Unit/Action/CaptureReferencedActionTest.php b/Tests/Unit/Action/CaptureReferencedActionTest.php index 4aab56d..9cf6a61 100644 --- a/Tests/Unit/Action/CaptureReferencedActionTest.php +++ b/Tests/Unit/Action/CaptureReferencedActionTest.php @@ -14,7 +14,6 @@ class CaptureReferencedActionTest extends GenericActionTest protected $requestClass = CaptureReferenced::class; protected $actionClass = CaptureReferencedAction::class; - /** * @test */ diff --git a/Tests/Unit/Action/ConvertPaymentActionTest.php b/Tests/Unit/Action/ConvertPaymentActionTest.php index a986673..4d72409 100644 --- a/Tests/Unit/Action/ConvertPaymentActionTest.php +++ b/Tests/Unit/Action/ConvertPaymentActionTest.php @@ -10,6 +10,7 @@ use Payum\Core\Request\Generic; use Payum\Core\Tests\GenericActionTest; use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts; +use Payum\Core\Security\TokenInterface; class ConvertPaymentActionTest extends GenericActionTest { @@ -17,7 +18,6 @@ class ConvertPaymentActionTest extends GenericActionTest protected $requestClass = Convert::class; protected $actionClass = ConvertPaymentAction::class; - /** * @test */ @@ -39,7 +39,7 @@ public function provideSupportedRequests(): \Iterator { yield [new $this->requestClass(new Payment(), 'array')]; yield [new $this->requestClass($this->createMock(PaymentInterface::class), 'array')]; - yield [new $this->requestClass(new Payment(), 'array', $this->createMock('Payum\Core\Security\TokenInterface'))]; + yield [new $this->requestClass(new Payment(), 'array', $this->createMock(TokenInterface::class))]; } diff --git a/Tests/Unit/Action/InsertCardAliasActionTest.php b/Tests/Unit/Action/InsertCardAliasActionTest.php index 70b7e16..0d7f7c0 100644 --- a/Tests/Unit/Action/InsertCardAliasActionTest.php +++ b/Tests/Unit/Action/InsertCardAliasActionTest.php @@ -15,7 +15,6 @@ class InsertCardAliasActionTest extends GenericActionTest protected $requestClass = InsertCardAlias::class; protected $actionClass = InsertCardAliasAction::class; - /** * @test */ @@ -44,7 +43,8 @@ public function couldBeConstructedWithoutAnyArguments(): void public function provideSupportedRequests(): \Iterator { - function getRequest($details) { + function getRequest($details): InsertCardAlias + { $alias = new CardAlias(); $alias->setDetails($details); $request = new InsertCardAlias(new Token()); diff --git a/Tests/Unit/Action/NotifyActionTest.php b/Tests/Unit/Action/NotifyActionTest.php index 15c466b..4df5fc2 100644 --- a/Tests/Unit/Action/NotifyActionTest.php +++ b/Tests/Unit/Action/NotifyActionTest.php @@ -13,7 +13,6 @@ class NotifyActionTest extends GenericActionTest protected $requestClass = Notify::class; protected $actionClass = NotifyAction::class; - /** * @test */ diff --git a/Tests/Unit/Action/RefundActionTest.php b/Tests/Unit/Action/RefundActionTest.php index c94508a..8cad693 100644 --- a/Tests/Unit/Action/RefundActionTest.php +++ b/Tests/Unit/Action/RefundActionTest.php @@ -13,7 +13,6 @@ class RefundActionTest extends GenericActionTest protected $requestClass = Refund::class; protected $actionClass = RefundAction::class; - /** * @test */ diff --git a/Tests/Unit/Action/StatusActionTest.php b/Tests/Unit/Action/StatusActionTest.php index 50cb734..7d8d993 100644 --- a/Tests/Unit/Action/StatusActionTest.php +++ b/Tests/Unit/Action/StatusActionTest.php @@ -12,7 +12,6 @@ class StatusActionTest extends GenericActionTest protected $requestClass = GetHumanStatus::class; protected $actionClass = StatusAction::class; - /** * @test */ diff --git a/Tests/Unit/Action/SyncActionTest.php b/Tests/Unit/Action/SyncActionTest.php index bd3ec9a..87f52d9 100644 --- a/Tests/Unit/Action/SyncActionTest.php +++ b/Tests/Unit/Action/SyncActionTest.php @@ -13,7 +13,6 @@ class SyncActionTest extends GenericActionTest protected $requestClass = Sync::class; protected $actionClass = SyncAction::class; - /** * @test */ diff --git a/Tests/Unit/ApiTest.php b/Tests/Unit/ApiTest.php index 7bcb83a..1f581d1 100644 --- a/Tests/Unit/ApiTest.php +++ b/Tests/Unit/ApiTest.php @@ -1,4 +1,5 @@ -options = array( + $this->options = [ 'username' => 'test', 'password' => 'test', 'customerId' => 'test', 'terminalId' => 'test', 'sandbox' => true, - 'instantCapturing' => true, - ); + 'instantCapturing' => true + ]; } /** @@ -110,7 +111,7 @@ public function shouldComposeRequestHeader(): void { $api = new Api($this->options, $this->createSuccessHttpClientStub(), $this->createHttpMessageFactory()); $result = $api->initTransaction(['Payment' => [], 'ReturnUrls' => []]); - $this->assertArraySubset([ + self::assertArraySubset([ 'RequestHeader' => [ 'SpecVersion' => '1.10', 'CustomerId' => 'test', @@ -141,7 +142,7 @@ public function shouldComposeInitTransactionRequest(): void ] ]); - $this->assertArraySubset([ + self::assertArraySubset([ 'Payment' => [ 'Amount' => [ 'value' => 123, @@ -173,7 +174,7 @@ public function shouldComposeAuthorizeTransactionRequest(): void 'Alias' => ['Id' => 'aliasId'], ]); - $this->assertArraySubset([ + self::assertArraySubset([ 'Token' => 'this-is-token', 'Condition' => 'WITH_LIABILITY_SHIFT', 'RegisterAlias' => [ @@ -193,7 +194,7 @@ public function shouldComposeCaptureTransactionRequest(): void $api = new Api($this->options, $this->createSuccessHttpClientStub(), $this->createHttpMessageFactory()); $result = $api->captureTransaction('transaction-id'); - $this->assertArraySubset([ + self::assertArraySubset([ 'TransactionReference' => [ 'TransactionId' => 'transaction-id', ], @@ -213,7 +214,7 @@ public function shouldComposeRefundTransactionRequest(): void ], ], 'transaction-id'); - $this->assertArraySubset([ + self::assertArraySubset([ 'Refund' => [ 'Amount' => [ 'value' => 123, @@ -239,7 +240,7 @@ public function shouldComposeAuthorizeReferencedTransactionRequest(): void ], ], 'transaction-id'); - $this->assertArraySubset([ + self::assertArraySubset([ 'Payment' => [ 'Amount' => [ 'value' => 123, @@ -275,7 +276,7 @@ public function shouldComposeInitPaymentPageRequest(): void ] ]); - $this->assertArraySubset([ + self::assertArraySubset([ 'Payment' => [ 'Amount' => [ 'value' => 123, @@ -303,7 +304,7 @@ public function shouldComposeAssertPaymentPageRequest(): void $api = new Api($this->options, $this->createSuccessHttpClientStub(), $this->createHttpMessageFactory()); $result = $api->assertPaymentPage('token'); - $this->assertArraySubset([ + self::assertArraySubset([ 'Token' => 'token', ], $result); } @@ -321,7 +322,7 @@ public function shouldComposeInsertAliasRequest(): void 'IdGenerator' => 'RANDOM', ], 'CARD'); - $this->assertArraySubset([ + self::assertArraySubset([ 'RegisterAlias' => [ 'IdGenerator' => 'RANDOM', ], @@ -342,7 +343,7 @@ public function shouldComposeAssertInsertAliasRequest(): void $api = new Api($this->options, $this->createSuccessHttpClientStub(), $this->createHttpMessageFactory()); $result = $api->assertInsertAlias('token'); - $this->assertArraySubset([ + self::assertArraySubset([ 'Token' => 'token', ], $result); } @@ -355,7 +356,7 @@ public function shouldComposeDeleteAliasRequest(): void $api = new Api($this->options, $this->createSuccessHttpClientStub(), $this->createHttpMessageFactory()); $result = $api->deleteAlias('alias-id'); - $this->assertArraySubset([ + self::assertArraySubset([ 'AliasId' => 'alias-id', ], $result); } @@ -395,9 +396,7 @@ public function throwIfResponseStatusNotOk(): void } } - /** - * @return MockObject|HttpClientInterface - */ + /** @return MockObject&HttpClientInterface */ protected function createSuccessHttpClientStub() { $clientMock = $this->createHttpClientMock(); @@ -410,9 +409,7 @@ protected function createSuccessHttpClientStub() return $clientMock; } - /** - * @return MockObject|HttpClientInterface - */ + /** @return MockObject&HttpClientInterface */ protected function createHttpClientMock() { return $this->getMockBuilder(HttpClientInterface::class)->getMock(); diff --git a/composer.json b/composer.json index 455dfaf..21038a8 100644 --- a/composer.json +++ b/composer.json @@ -20,12 +20,12 @@ } ], "require": { - "php": "^7.3 || ^8.0", - "payum/core": "^1.6" + "php": "^8.0", + "payum/core": "^1.7.3" }, "require-dev": { "fabpot/goutte": "^4.0", - "php-http/guzzle6-adapter": "^2.0", + "php-http/guzzle7-adapter": "^1.0", "phpunit/phpunit": "^9.5", "dms/phpunit-arraysubset-asserts": "^0.4.0" }, diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 7a79e42..41502e6 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,9 @@ - + .