Skip to content

Commit

Permalink
Require ecommerce framework bundle to fix PHPStan and fix Pimcore 11 …
Browse files Browse the repository at this point in the history
…bugs (#8)

* Require ecommerce framework bundle to fix PHPStan

* Update composer.json

* Pimcore 11 compatibility fixes (#6)

* fix(pimcore-11): Fix type declarations

* fix(pimcore-11): Fix incorrect Authorization attribute for Guzzle

* fix(pimcore-11): PHP 8: Check for keys that may not be present in response

* feat(pimcore-11): rename config files

* Fix PHPStan autoload

* Fix PHPStan autoload

* Fix PHPStan autoload

---------

Co-authored-by: Lukas B <theill182@gmail.com>
  • Loading branch information
markus-moser and GNi33 committed Mar 29, 2024
1 parent ad1781e commit 1c0d04e
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 10 deletions.
31 changes: 31 additions & 0 deletions .github/ci/files/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "pimcore/payment-provider-hobex",
"license": "GPL-3.0+",
"type": "pimcore-bundle",
"description": "Pimcore Payment Provider - Hobex",
"config": {
"sort-packages": true
},
"prefer-stable": true,
"minimum-stability": "dev",
"require": {
"pimcore/pimcore": "^11.0",
"pimcore/ecommerce-framework-bundle": "^1.0"
},
"require-dev": {
"phpstan/phpstan": "^1.9"
},
"autoload": {
"psr-4": {
"Pimcore\\Bundle\\EcommerceFrameworkBundle\\": "src/",
"Pimcore\\Model\\DataObject\\": "var/classes/DataObject"
}
},
"extra": {
"pimcore": {
"bundles": [
"Pimcore\\Bundle\\EcommerceFrameworkBundle\\PimcorePaymentProviderHobexBundle"
]
}
}
}
3 changes: 2 additions & 1 deletion .github/ci/scripts/setup-pimcore-environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
set -eu -o xtrace

cp -rv .github/ci/files/var .
cp .github/ci/files/.env .
cp .github/ci/files/.env .
cp -rf .github/ci/files/composer.json .
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"prefer-stable": true,
"minimum-stability": "dev",
"require": {
"pimcore/pimcore": "^11.0"
"pimcore/pimcore": "^11.0",
"pimcore/ecommerce-framework-bundle": "^1.0"
},
"require-dev": {
"phpstan/phpstan": "^1.9"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public function load(array $configs, ContainerBuilder $container)
new FileLocator(__DIR__ . '/../Resources/config')
);

$loader->load('services.yml');
$loader->load('services.yaml');
}
}
4 changes: 2 additions & 2 deletions src/Hobex/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

class Installer extends PaymentProviderInstaller
{
protected $bricksPath = __DIR__ . '/../../install/objectbrick_sources/';
protected string $bricksPath = __DIR__ . '/../../install/objectbrick_sources/';

protected $bricksToInstall = [
protected array $bricksToInstall = [
'PaymentProviderHobex' => 'objectbrick_PaymentProviderHobex_export.json'
];
}
14 changes: 9 additions & 5 deletions src/PaymentManager/Payment/Hobex.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function startPayment(OrderAgentInterface $orderAgent, PriceInterface $pr
$client = new Client([
'base_uri' => $this->getStartPaymentURL(),
'headers' => [
'Authorization:Bearer' => $this->config->getAuthorizationBearer(),
'Authorization' => 'Bearer ' . $this->config->getAuthorizationBearer(),
],
]
);
Expand Down Expand Up @@ -266,9 +266,10 @@ public function handleResponse(StatusInterface | array $response): StatusInterfa

try {
$jsonResponse = null;
if ($response['base64Content']) {
if (array_key_exists('base64Content', $response) && $response['base64Content']) {
$jsonResponse = $this->handleWebhookResponse($response);
}

if (!$jsonResponse) {
$transactionId = $this->getExistingTransactionId($checkoutId);
if ($transactionId) {
Expand All @@ -282,22 +283,25 @@ public function handleResponse(StatusInterface | array $response): StatusInterfa
$client = new Client([
'base_uri' => $this->config->getHostURL() . $resourcePath,
'headers' => [
'Authorization:Bearer' => $this->config->getAuthorizationBearer(),
'Authorization' => 'Bearer: ' . $this->config->getAuthorizationBearer(),
],
]
);
$response = $client->request('get', '?entityId=' . $this->config->getEntityId());
$jsonResponse = json_decode($response->getBody()->getContents(), true);
}

$this->logger->debug('Received JSON response in ' . self::class . '::handleResponse', $jsonResponse);

$internalPaymentId = $jsonResponse['customParameters']['internalTransactionId'];

$merchantMemo = array_key_exists('merchantMemo', $jsonResponse) ? $jsonResponse['merchantMemo'] : '';

$clearedParams = [
'paymentType' => $jsonResponse['paymentBrand'],
'amount' => $jsonResponse['amount'],
'currency' => $jsonResponse['currency'],
'merchantMemo' => $jsonResponse['merchantMemo'],
'merchantMemo' => $merchantMemo,
'paymentState' => $jsonResponse['result']['code'],
'extId' => $jsonResponse['id'],
'checkoutId' => $jsonResponse['ndc'],
Expand Down Expand Up @@ -349,7 +353,7 @@ public function getAuthorizedData(): array
/**
* @inheritdoc
*/
public function setAuthorizedData(array $authorizedData)
public function setAuthorizedData(array $authorizedData): void
{
$this->authorizedData = $authorizedData;
}
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 1c0d04e

Please sign in to comment.