Skip to content

Commit

Permalink
UNZER-508 Remove automatic charge
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniil Tkachev committed Oct 22, 2024
1 parent b27e94f commit 87141f7
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 84 deletions.
19 changes: 0 additions & 19 deletions src/Controller/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,11 @@ public function unzerExecuteAfterRedirect(): void

if (stripos($nextStep, 'thankyou') !== false) {
$connectionProvider->commit();
$unzerPaymentId = $this->getUnzerPaymentIdFromSession();

if ($this->isPaymentCancelled($paymentService)) {
$this->cleanUpCancelledPayments();
}

if (!empty($unzerPaymentId) && $unzerService->ifImmediatePostAuthCollect($paymentService)) {
$paymentService->doUnzerCollect(
$oOrder,
$unzerPaymentId,
(float)$oOrder->getTotalOrderSum()
);
}

$session = $this->getSession();
$session->deleteVariable('oscunzersavepayment');
$session->deleteVariable('oscunzersavepayment_paypal');
Expand Down Expand Up @@ -521,16 +512,6 @@ private function setSavePaymentFlag(User $oUser, PaymentService $paymentService)
}
}

private function getUnzerPaymentIdFromSession(): string
{
$paymentId = $this->getSession()->getVariable('UnzerPaymentId');
if (is_string($paymentId)) {
return $paymentId;
}

return '';
}

private function getSession(): Session
{
return Registry::getSession();
Expand Down
37 changes: 0 additions & 37 deletions src/Service/Unzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -655,43 +655,6 @@ public function isAjaxPayment(): bool
return (bool)$this->session->getVariable('UzrAjaxRedirect');
}

public function ifImmediatePostAuthCollect(Payment $paymentService): bool
{
$paymentMethod = $this->getPaymentMethodFromOrder((string)$paymentService->getUnzerOrderId());
$paymentProcedure = $this->getPaymentProcedure(str_replace('oscunzer_', '', $paymentMethod));
return $paymentProcedure === ModuleSettings::PAYMENT_CHARGE;
}

private function getPaymentMethodFromOrder(string $oxUnzerOrderNr): string
{
/** @var QueryBuilderFactoryInterface $queryBuilderFactory */
$queryBuilderFactory = $this->getServiceFromContainer(QueryBuilderFactoryInterface::class);

$queryBuilder = $queryBuilderFactory->create();

$query = $queryBuilder
->select('OXPAYMENTTYPE')
->from('oxorder')
->where("OXUNZERORDERNR = :oxunzerordernr");

$parameters = [
':oxunzerordernr' => $oxUnzerOrderNr,
];

$result = $query->setParameters($parameters)->execute();

if ($result instanceof ResultStatement) {
/** @var string $value */
$value = $result->fetchColumn();
if (empty($value)) {
$value = '';
}
return $value;
}

return '';
}

private function getPaymentDataArrayFromRequest(): array
{
/** @var string $jsonPaymentData */
Expand Down
28 changes: 0 additions & 28 deletions tests/Unit/Service/UnzerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,34 +101,6 @@ public function getPaymentProcedureDataProvider(): array
];
}

public function testIfImmediatePostAuthCollectTrue(): void
{
$moduleSettings = $this->createPartialMock(ModuleSettings::class, ['getPaymentProcedureSetting']);
$moduleSettings->method('getPaymentProcedureSetting')
->willReturn(ModuleSettings::PAYMENT_CHARGE);
$sut = $this->getSut([ModuleSettings::class => $moduleSettings]);
$paymentService = $this->getPaymentServiceMock($sut);

$this->assertTrue($sut->ifImmediatePostAuthCollect($paymentService));
}

public function testIfImmediatePostAuthCollectFalse(): void
{
$moduleSettings = $this->createPartialMock(ModuleSettings::class, ['getPaymentProcedureSetting']);
$moduleSettings->method('getPaymentProcedureSetting')
->willReturn(ModuleSettings::PAYMENT_AUTHORIZE);
$sut = $this->getSut([ModuleSettings::class => $moduleSettings]);
$paymentService = $this->getPaymentServiceMock($sut);

$paymentService->method('getUnzerOrderId')
->willReturn('666');

$sql = "INSERT INTO oxorder SET OXID=9999, OXPAYMENTTYPE='oscunzer_paypal', OXUNZERORDERNR='666'";
DatabaseProvider::getDb()->execute($sql);

$this->assertFalse($sut->ifImmediatePostAuthCollect($paymentService));
}

private function getPaymentServiceMock($sut)
{
return $this->getMockBuilder(Payment::class)
Expand Down

0 comments on commit 87141f7

Please sign in to comment.