Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drop support of php 7.x, prepartion of payum/core v2 #19

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions .github/workflows/code_checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Action/CaptureReferencedAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion Action/InsertCardAliasAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
61 changes: 28 additions & 33 deletions Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,57 +10,52 @@

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,
'terminalId' => null,
'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<string, mixed> $fields
* @return array<string, mixed>
*/
protected function doRequest(string $path, array $fields): array
{
$headers = [
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down
42 changes: 21 additions & 21 deletions Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
18 changes: 8 additions & 10 deletions Exception/SaferpayHttpException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 2 additions & 6 deletions Model/CardAlias.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@

class CardAlias extends CreditCard implements CardAliasInterface
{
/**
* @var array
*/
protected $details;

protected array $details;

public function __construct()
{
Expand All @@ -24,7 +20,7 @@ public function getDetails(): array
}

/**
* @param array $details
* @param array|\Traversable $details
*/
public function setDetails($details): void
{
Expand Down
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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+

Expand Down Expand Up @@ -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
```
Expand Down
4 changes: 2 additions & 2 deletions SaferpayGatewayFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ 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,
];
$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']);
Expand Down
Loading
Loading