Skip to content

Commit

Permalink
Merge pull request #31 from OXID-eSales/TC-9-32_PayPreAuth
Browse files Browse the repository at this point in the history
Tc 9 32 pay pre auth
  • Loading branch information
mariolorenz authored Nov 28, 2024
2 parents e2519f7 + 61d7eae commit d0e5e63
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 9 deletions.
12 changes: 11 additions & 1 deletion src/Application/Model/TeleCashConnectData.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\StandardException;
use OxidSolutionCatalysts\TeleCash\Application\Model\Interface\TeleCashConnectDataInterface;
use OxidSolutionCatalysts\TeleCash\Core\Service\Logger;
use OxidSolutionCatalysts\TeleCash\Core\Service\OxNewService;
use OxidSolutionCatalysts\TeleCash\Core\Service\Price;
use OxidSolutionCatalysts\TeleCash\IPG\TeleCashConnect;
use OxidSolutionCatalysts\TeleCash\Traits\Json;

/**
* Class TeleCashConnectData - Provider for TeleCashData
Expand All @@ -31,6 +33,8 @@
*/
class TeleCashConnectData implements TeleCashConnectDataInterface
{
use Json;

protected ?User $user = null;

protected ?Address $address = null;
Expand Down Expand Up @@ -60,7 +64,8 @@ class TeleCashConnectData implements TeleCashConnectDataInterface
*/
public function __construct(
private readonly TeleCashConnect $teleCashConnect,
private readonly OxNewService $oxNewService
private readonly OxNewService $oxNewService,
private readonly Logger $logger
) {
}

Expand Down Expand Up @@ -141,6 +146,11 @@ public function getTeleCashConnectData(): array
$extHash = $this->teleCashConnect->calculateExtendedHashFromArray($allFields);
$allFields['hashExtended'] = $extHash;

$this->logger->log(
'debug',
'Debug: getTeleCashConnectData: ' . $this->arrayToJson($allFields)
);

return $allFields;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Core/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ final class Module
];

public const TELECASH_TXN_TYPE_SALE = 'sale';
public const TELECASH_TXN_TYPE_POSTAUTH = 'postauth';
public const TELECASH_TXN_TYPE_POSTAUTH = 'preauth';

public const TELECASH_TRANSACTION_TYPES = [
self::TELECASH_CAPTURE_TYPE_DIRECT => self::TELECASH_TXN_TYPE_SALE,
Expand Down
2 changes: 2 additions & 0 deletions src/Core/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ services:
OxidSolutionCatalysts\TeleCash\Core\Service\Logger:
class: OxidSolutionCatalysts\TeleCash\Core\Service\Logger
public: true
arguments:
Psr\Log\LoggerInterface: '@OxidSolutionCatalysts\TeleCash\Logger'

OxidSolutionCatalysts\TeleCash\Core\Service\Context:
class: OxidSolutionCatalysts\TeleCash\Core\Service\Context
Expand Down
22 changes: 20 additions & 2 deletions src/IPG/TeleCashConnect.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,24 @@

use DateTime;
use InvalidArgumentException;
use OxidSolutionCatalysts\TeleCash\Core\Service\Logger;
use OxidSolutionCatalysts\TeleCash\IPG\Model\BillingAddress;
use OxidSolutionCatalysts\TeleCash\IPG\Model\CreditCardData;
use OxidSolutionCatalysts\TeleCash\IPG\Model\CustomData;
use OxidSolutionCatalysts\TeleCash\IPG\Model\DirectDebitData;
use OxidSolutionCatalysts\TeleCash\IPG\Model\ShippingAddress;
use OxidSolutionCatalysts\TeleCash\IPG\Model\TransactionResult;
use OxidSolutionCatalysts\TeleCash\Traits\Json;
use OxidSolutionCatalysts\TeleCash\Traits\ServiceContainer;

/**
* Base class for handling TeleCash Connect integration
*/
class TeleCashConnect
{
use Json;
use ServiceContainer;

private string $hashMethod;
private string $secretKey;
private string $storeName;
Expand Down Expand Up @@ -53,12 +59,20 @@ class TeleCashConnect
*/
private TeleCashCurrency $teleCashCurrency;

public function __construct(string $storeName, string $secretKey, string $hashMethod = 'HMACSHA256')
{
private ?Logger $logger;

public function __construct(
string $storeName,
string $secretKey,
string $hashMethod = 'HMACSHA256'
) {
$this->setContainer($this->getContainer());

$this->hashMethod = $hashMethod;
$this->secretKey = $secretKey;
$this->storeName = $storeName;
$this->teleCashCurrency = new TeleCashCurrency();
$this->logger = $this->getServiceFromContainer(Logger::class);
}

/**
Expand Down Expand Up @@ -324,6 +338,10 @@ public function isValidResponse(array $data = []): bool
public function setResponseData(array $data): void
{
$this->responseData = $data;
$this->logger?->log(
'debug',
'Debug: setResponseData: ' . $this->arrayToJson($data)
);
}

/**
Expand Down
7 changes: 6 additions & 1 deletion src/Traits/ModelGetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use OxidEsales\Eshop\Core\Price;
use OxidSolutionCatalysts\TeleCash\Application\Model\TeleCashOrder;
use OxidSolutionCatalysts\TeleCash\Application\Model\TeleCashPayment;
use OxidSolutionCatalysts\TeleCash\Core\Service\Logger;
use OxidSolutionCatalysts\TeleCash\Core\Service\OxNewService;
use OxidSolutionCatalysts\TeleCash\Core\Service\TeleCashPaymentValidatorServiceInterface;
use OxidSolutionCatalysts\TeleCash\Exception\TeleCashException;
Expand Down Expand Up @@ -58,6 +59,7 @@ private function getTeleCashOrderModel(string $oxOrderId): TeleCashOrder
return $this->getOxNewService()->oxNew(TeleCashOrder::class, [$oxOrderId]);
}


/**
* @throws TeleCashException
*/
Expand Down Expand Up @@ -114,11 +116,14 @@ private function getTeleCashConnect(): TeleCashConnect
*/
private function getTeleCashConnectData(): TeleCashConnectData
{
$logger = $this->getServiceFromContainer(Logger::class);

return $this->getOxNewService()->oxNew(
TeleCashConnectData::class,
[
$this->getTeleCashConnect(),
$this->getOxNewService()
$this->getOxNewService(),
$logger
]
);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Integration/Application/Model/TeleCashPaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public function testGetTeleCashPaymentMethod(): void

/**
* Test getting the TeleCash transaction type based on capture type.
* This test verifies that the correct transaction type ('sale'/'postauth')
* This test verifies that the correct transaction type ('sale'/'preauth')
* is returned for each capture type according to the TELECASH_TRANSACTION_TYPES mapping.
*/
public function testGetTeleCashTransactionType(): void
Expand All @@ -287,15 +287,15 @@ public function testGetTeleCashTransactionType(): void
Module::TELECASH_PAYMENT_IDENT_CC_VISA,
Module::TELECASH_CAPTURE_TYPE_ONDELIVERY
);
$this->assertEquals('postauth', $teleCashPaymentReal->getTeleCashTransactionType());
$this->assertEquals('preauth', $teleCashPaymentReal->getTeleCashTransactionType());

// Test manually capture type
$teleCashPaymentReal->setTestValues(
'test_payment',
Module::TELECASH_PAYMENT_IDENT_CC_VISA,
Module::TELECASH_CAPTURE_TYPE_MANUALLY
);
$this->assertEquals('postauth', $teleCashPaymentReal->getTeleCashTransactionType());
$this->assertEquals('preauth', $teleCashPaymentReal->getTeleCashTransactionType());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion views/admin_twig/en/module_options.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# Module settings
'SHOP_MODULE_GROUP_' . ModuleSettingsServiceInterface::MODULE_CONFIG_API_VARGROUP => 'API',
'SHOP_MODULE_GROUP_' . ModuleSettingsServiceInterface::MODULE_CONFIG_API_FRONTEND_VARGROUP => 'API for OXID Frontend',
'SHOP_MODULE_GROUP_' . ModuleSettingsServiceInterface::MODULE_CONFIG_API_BACKEND_VARGROUP => 'API für OXID Backend',
'SHOP_MODULE_GROUP_' . ModuleSettingsServiceInterface::MODULE_CONFIG_API_BACKEND_VARGROUP => 'API for OXID Backend',
'SHOP_MODULE_GROUP_' . ModuleSettingsServiceInterface::MODULE_CONFIG_LANGUAGE => 'Languages',
'SHOP_MODULE_GROUP_' . ModuleSettingsServiceInterface::MODULE_CONFIG_DEBUG_VARGROUP => 'Debugging',

Expand Down

0 comments on commit d0e5e63

Please sign in to comment.