Skip to content

Commit

Permalink
Merge pull request #35 from OXID-eSales/TC-9-35_CommunicationViaAPI
Browse files Browse the repository at this point in the history
Tc 9 35 communication via api
  • Loading branch information
mariolorenz authored Dec 12, 2024
2 parents e28cf22 + e0302cf commit e447a46
Show file tree
Hide file tree
Showing 114 changed files with 3,743 additions and 1,517 deletions.
6 changes: 6 additions & 0 deletions metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/

use OxidEsales\Eshop\Application\Controller\Admin\ModuleConfiguration as oxModuleConfiguration;
use OxidEsales\Eshop\Application\Controller\Admin\OrderMain as oxOrderMain;
use OxidEsales\Eshop\Application\Controller\Admin\OrderOverview as oxOrderOverview;
use OxidEsales\Eshop\Application\Controller\Admin\PaymentMain as oxPaymentMain;
use OxidEsales\Eshop\Application\Controller\OrderController as oxOrderController;
use OxidEsales\Eshop\Application\Controller\PaymentController as oxPaymentController;
Expand All @@ -22,6 +24,8 @@
use OxidSolutionCatalysts\TeleCash\Application\Controller\FrontendTeleCashNotificationEndpoint;
use OxidSolutionCatalysts\TeleCash\Core\Module;
use OxidSolutionCatalysts\TeleCash\Extension\Application\Controller\Admin\ModuleConfiguration;
use OxidSolutionCatalysts\TeleCash\Extension\Application\Controller\Admin\OrderMain;
use OxidSolutionCatalysts\TeleCash\Extension\Application\Controller\Admin\OrderOverview;
use OxidSolutionCatalysts\TeleCash\Extension\Application\Controller\Admin\PaymentMain;
use OxidSolutionCatalysts\TeleCash\Extension\Application\Controller\OrderController;
use OxidSolutionCatalysts\TeleCash\Extension\Application\Controller\PaymentController;
Expand Down Expand Up @@ -76,6 +80,8 @@
// Controller Admin
oxModuleConfiguration::class => ModuleConfiguration::class,
oxPaymentMain::class => PaymentMain::class,
oxOrderMain::class => OrderMain::class,
oxOrderOverview::class => OrderOverview::class,
// Controller Frontend
oxOrderController::class => OrderController::class,
oxPaymentController::class => PaymentController::class,
Expand Down
6 changes: 3 additions & 3 deletions migration/data/Version20241122134700.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ private function createTeleCashOrderHistoryTable(Schema $schema): void
$teleCashOrderHistoryTable->setPrimaryKey(['OXID']);
}

if (!$teleCashOrderHistoryTable->hasIndex('UNIQUE_ENTRY')) {
$teleCashOrderHistoryTable->addUniqueIndex(
if (!$teleCashOrderHistoryTable->hasIndex('INDEX_ENTRY')) {
$teleCashOrderHistoryTable->addIndex(
[$oxOidColName],
'UNIQUE_ENTRY'
'INDEX_ENTRY'
);
}
}
Expand Down
7 changes: 4 additions & 3 deletions migration/data/Version20241129122600.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ private function createTeleCashOrderTable(Schema $schema): void
$teleCashOrderTable = $schema->getTable(Module::TELECASH_ORDER_EXTENSION_TABLE);
}

if (!$teleCashOrderTable->hasColumn('OXID')) {
$oxIdColName = 'OXID';
if (!$teleCashOrderTable->hasColumn($oxIdColName)) {
$teleCashOrderTable->addColumn(
'OXID',
$oxIdColName,
Types::STRING,
['columnDefinition' => 'char(32) collate latin1_general_ci']
);
Expand Down Expand Up @@ -98,7 +99,7 @@ private function createTeleCashOrderTable(Schema $schema): void
$oxPaymentMethodColName,
Types::STRING,
[
'columnDefinition' => 'char(8) collate latin1_general_ci',
'columnDefinition' => 'char(16) collate latin1_general_ci',
'comment' => 'Telecash PaymentMethod'
]
);
Expand Down
169 changes: 125 additions & 44 deletions src/Application/Controller/Admin/OrderTeleCash.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,51 @@

namespace OxidSolutionCatalysts\TeleCash\Application\Controller\Admin;

use Exception;
use OxidEsales\Eshop\Application\Controller\Admin\AdminController;
use OxidEsales\Eshop\Application\Model\Order as oxOrder;
use OxidSolutionCatalysts\TeleCash\Application\Model\TeleCashOrder;
use OxidSolutionCatalysts\TeleCash\Application\Model\TeleCashPayment;
use OxidSolutionCatalysts\TeleCash\Core\Module;
use OxidSolutionCatalysts\TeleCash\Core\Service\ErrorDisplayServiceInterface;
use OxidSolutionCatalysts\TeleCash\Core\Service\RegistryService;
use OxidSolutionCatalysts\TeleCash\Core\Service\TeleCashAfterProcessServiceInterface;
use OxidSolutionCatalysts\TeleCash\Exception\TeleCashException;
use OxidSolutionCatalysts\TeleCash\Extension\Application\Model\Order;
use OxidSolutionCatalysts\TeleCash\Extension\Application\Model\Payment;
use OxidSolutionCatalysts\TeleCash\Settings\Service\ModuleSettingsServiceInterface;
use OxidSolutionCatalysts\TeleCash\Traits\ModelGetter;
use OxidSolutionCatalysts\TeleCash\Traits\RequestGetter;
use OxidSolutionCatalysts\TeleCash\Traits\ServiceContainer;

class OrderTeleCash extends AdminController
{
use ModelGetter;
use RequestGetter;
use ServiceContainer;

protected $_sThisTemplate = '@' . Module::MODULE_ID . '/admin/order_telecash';

protected RegistryService $registryService;
protected TeleCashAfterProcessServiceInterface $afterProcessService;
private ErrorDisplayServiceInterface $errorDisplay;

protected ?string $oxid = null;
protected bool $isTeleCashOrder = false;
protected ?TeleCashOrder $teleCashOrder = null;
protected ?TeleCashPayment $teleCashPayment = null;
protected oxOrder $order;

/**
* Constructor for Order.
*
* Initializes a new instance of the OrderTeleCash class. This constructor can be used
* in both production and test environments due to its flexible parameter configuration.
*
* @param bool $initParent Whether to initialize the parent BaseModel.
* @param bool $initParent Whether to initialize the parent BaseModel.
* Set to false in test environment to avoid
* OXID framework dependencies. Default is true.
* @throws TeleCashException
*/
public function __construct(
bool $initParent = true
Expand All @@ -51,6 +67,37 @@ public function __construct(
RegistryService::class,
'RegistryService'
);

$this->afterProcessService = $this->getRequiredService(
TeleCashAfterProcessServiceInterface::class,
'TeleCashAfterProcessService'
);

$this->errorDisplay = $this->getRequiredService(
ErrorDisplayServiceInterface::class,
'ErrorDisplayService'
);

// initial oxID
$this->oxid = $this->getEditObjectId();

// initial possible TeleCashOrder
$this->order = $this->getOxidOrderModel();
$this->order->load($this->oxid);

/** @var Order $order */
$order = $this->order;

$this->isTeleCashOrder = $order->isTeleCashOrder();
$this->teleCashOrder = $order->getTeleCashOrder();

//initial possible TeleCashPayment
$payment = $this->getOxidPaymentModel();
$paymentId = $order->getFieldStringData('oxpaymenttype');

$payment->load($paymentId);
/** @var Payment $payment */
$this->teleCashPayment = $payment->getTeleCashPayment();
}

/** @inheritdoc
Expand All @@ -65,69 +112,103 @@ public function render()
return $this->getTemplateName();
}

/**
* do Charge triggered in Template as Controller fnc=doChargeOrder
* @throws Exception
*/
public function doChargeOrder(): void
{
$amount = $this->getFloatRequestData('chargeAmount');
if (
!is_null($this->teleCashOrder) &&
$this->isChargePossible($amount)
) {
$this->afterProcessService->doChargeOrder($this->teleCashOrder->getId(), $amount);
}
}

/**
* @throws TeleCashException
*/
private function addTeleCashToTemplate(): void
{
$oxId = $this->getEditObjectId();
// these variables are needed in any case
$this->addTplParam('oxid', $this->oxid);
$this->addTplParam('teleCashModuleId', Module::MODULE_ID);

/** @var Order $order */
$order = $this->getOxidOrderModel();
$order->load($oxId);
$isNettoMode = $order->isNettoMode();
if ($this->isTeleCashOrder && !is_null($this->teleCashOrder)) {
$this->addTeleCashOrderToTemplate();
return;
}

$isTeleCashOrder = $order->isTeleCashOrder();
$teleCashOrder = $order->getTeleCashOrder();
$this->errorDisplay->showErrorMessage('OSC_TELECASH_NO_TELECASH_ORDER');
}

$paymentId = $order->getFieldStringData('oxpaymenttype');
$payment = $this->getOxidPaymentModel();
/**
* @throws TeleCashException
*/
private function addTeleCashOrderToTemplate(): void
{
// bulletproof
if (is_null($this->teleCashOrder)) {
return;
}

$payment->load($paymentId);
/** @var Payment $payment */
$teleCashPayment = $payment->getTeleCashPayment();
$isNettoMode = $this->order->isNettoMode();
$chargeTotalFloat = $this->teleCashOrder->getOxidChargeTotal();
$currencyString = $this->teleCashOrder->getOxidCurrency();
$chargeTotalObject = $this->getPriceObj($chargeTotalFloat, $isNettoMode);
$currencyObject = $this->registryService->getConfig()->getCurrencyObject($currencyString);
$txnType = $this->teleCashOrder->getTxnType();
$chargeAmountFloat = $this->getPossibleCharge();

// these variables are needed in any case
$this->addTplParam('oxid', $oxId);
$this->addTplParam('teleCashModuleId', Module::MODULE_ID);
$this->addTplParam('isTeleCashOrder', $isTeleCashOrder);

if ($isTeleCashOrder && $teleCashOrder) {
$this->addTeleCashOrderToTemplate(
$teleCashOrder,
$isNettoMode,
$teleCashPayment
);
// History
$teleCashOrderHistoryList = $this->teleCashOrder->getTeleCashOrderHistoryList();

$this->addTplParam('isTeleCashOrder', true);
$this->addTplParam('isChargePossible', $this->isChargePossible());
$this->addTplParam('chargeTotalObject', $chargeTotalObject);
$this->addTplParam('chargeAmountFloat', $chargeAmountFloat);
$this->addTplParam('currencyString', $currencyString);
$this->addTplParam('currencyObject', $currencyObject);
$this->addTplParam('paymentMethod', $this->teleCashOrder->getPaymentMethod());
$this->addTplParam('status', $this->teleCashOrder->getStatus());
$this->addTplParam('txnType', $txnType);
$this->addTplParam('oId', $this->teleCashOrder->getOid());
$this->addTplParam('teleCashOrderHistoryList', $teleCashOrderHistoryList);

if ($this->teleCashPayment) {
$this->addTplParam('captureType', $this->teleCashPayment->getTeleCashCaptureType());
}
}

/**
* @throws TeleCashException
*/
private function addTeleCashOrderToTemplate(
TeleCashOrder $teleCashOrder,
bool $isNettoMode,
?TeleCashPayment $teleCashPayment
): void {

$chargeTotal = $teleCashOrder->getChargeTotal();
$currency = $teleCashOrder->getCurrency();
$priceChargeTotal = $this->getPriceObj($chargeTotal, $isNettoMode);
$currencyObj = $this->registryService->getConfig()->getCurrencyObject($currency);
private function isChargePossible(?float $amount = null): bool
{
$amount = !is_null($amount) ? $amount : $this->getPossibleCharge();

// History
$teleCashOrderHistoryList = $teleCashOrder->getTeleCashOrderHistoryList();
/** @var ModuleSettingsServiceInterface $moduleSettings */
$moduleSettings = $this->getServiceFromContainer(ModuleSettingsServiceInterface::class);

$this->addTplParam('priceChargeTotal', $priceChargeTotal);
$this->addTplParam('currencyObj', $currencyObj);
$this->addTplParam('paymentMethod', $teleCashOrder->getPaymentMethod());
$this->addTplParam('status', $teleCashOrder->getStatus());
$this->addTplParam('txnType', $teleCashOrder->getTxnType());
$this->addTplParam('teleCashOrderHistoryList', $teleCashOrderHistoryList);
return
$moduleSettings->isValidBackendConfiguration() &&
!is_null($this->teleCashOrder) &&
$this->teleCashOrder->getTxnType() !== Module::TELECASH_TXN_TYPE_SALE &&
$amount > 0 &&
$amount <= $this->getPossibleCharge();
}

if ($teleCashPayment) {
$this->addTplParam('captureType', $teleCashPayment->getTeleCashCaptureType());
/**
* @throws TeleCashException
*/
private function getPossibleCharge(): float
{
$result = 0.0;
if (!is_null($this->teleCashOrder)) {
$result = $this->teleCashOrder->getPossibleCharge();
}
return $result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,9 @@ public function receiveNotifications(): void
* The notification result contains new informations for the order.
*/
$notificationResult = $telecashConnect->getTransactionResult();

$teleCashOrderHistory = $this->getTeleCashOrderHistoryModel();
$teleCashOrderHistory->setTransactionResult($notificationResult);
$teleCashOrderHistory->save();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@ public function getIpgTransactionId(): string;
/** get the Currency */
public function getCurrency(): string;

/** get the EndpointTransactionId */
public function getChargeTotal(): float;
/** get the Currency in OXID-Style */
public function getOxidCurrency(): string;

/** get Charge Total */
public function getChargeTotal(): string;

/** get Charge Total in OXID Style */
public function getOxidChargeTotal(): float;

/** get the Status translated in transaction-language */
public function getStatus(): string;
Expand Down
13 changes: 11 additions & 2 deletions src/Application/Model/Interface/TeleCashOrderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,17 @@ public function getOid(): string;
/** get the Currency */
public function getCurrency(): string;

/** get the EndpointTransactionId */
public function getChargeTotal(): float;
/** get the Currency in OXID-Style */
public function getOxidCurrency(): string;

/** get Charge Total */
public function getChargeTotal(): string;

/** get Charge Total in OXID Style */
public function getOxidChargeTotal(): float;

/** get IpgTransactionId */
public function getIpgTransactionId(): string;

/** get the Status translated in transaction-language */
public function getStatus(): string;
Expand Down
3 changes: 1 addition & 2 deletions src/Application/Model/TeleCashConnectData.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace OxidSolutionCatalysts\TeleCash\Application\Model;

use DateTime;
use Doctrine\DBAL\Exception;
use OxidEsales\Eshop\Core\Price as oxPrice;
use OxidEsales\Eshop\Application\Model\Address;
Expand Down Expand Up @@ -195,7 +194,7 @@ private function getBasicFields(): array
'txntype' => $this->transactionType,
'chargetotal' => $oxidBasketTotal,
'currency' => $teleCashCurrency,
'txndatetime' => $this->teleCashConnect->formatDateTime(new DateTime()),
'txndatetime' => $this->teleCashConnect->formatDateTime(),
'responseFailURL' => $this->responseFailURL,
'responseSuccessURL' => $this->responseSuccessURL,
'transactionNotificationURL' => $this->transactionNotificationURL,
Expand Down
Loading

0 comments on commit e447a46

Please sign in to comment.