Skip to content

Commit

Permalink
Merge pull request #307 from OXID-eSales/bugfix/UNZER-446-cancellatio…
Browse files Browse the repository at this point in the history
…n-amount

UNZER-446 add bugfix showing correct amount when cancelling in admin
  • Loading branch information
mariolorenz authored Aug 15, 2024
2 parents 6573f2c + aacaf18 commit b43174a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- fix provide ShopMetadata for UnzerPayment
- fix show multiple vouchers separately
- fix: only OK, NOT_FINISHED or CANCEL in oxorder->oxtranstatus allowed
- fix showing correct amount when cancelling in admin

## [1.1.3] - 2023-11-14

Expand Down
4 changes: 3 additions & 1 deletion src/Service/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,9 @@ public function doUnzerAuthorizationCancel($oOrder, $unzerid, $amount)
$this->transactionService->writeTransactionToDB(
$oOrder->getId(),
$oxuserid,
$unzerPayment
$unzerPayment,
null,
$cancellation
);
} catch (UnzerApiException $e) {
return $e;
Expand Down
23 changes: 16 additions & 7 deletions src/Service/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ public function writeTransactionToDB(
string $orderid,
string $userId,
?Payment $unzerPayment,
?Shipment $unzerShipment = null
?Shipment $unzerShipment = null,
?AbstractTransactionType $transaction = null
): bool {

$oOrder = oxNew(Order::class);
Expand All @@ -114,7 +115,7 @@ public function writeTransactionToDB(
if ($unzerPayment) {
$unzerPaymentData = $unzerShipment !== null ?
$this->getUnzerShipmentData($unzerShipment, $unzerPayment) :
$this->getUnzerPaymentData($unzerPayment);
$this->getUnzerPaymentData($unzerPayment, $transaction);
$params = array_merge($params, $unzerPaymentData);

// for PaylaterInvoice, store the customer type
Expand Down Expand Up @@ -266,20 +267,20 @@ protected function getInitOrderOxid(array $params): string
}

/**
* @param Payment $unzerPayment
* @return array
* @throws UnzerApiException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
protected function getUnzerPaymentData(Payment $unzerPayment): array
{
protected function getUnzerPaymentData(
Payment $unzerPayment,
?AbstractTransactionType $transaction = null
): array {
$oxaction = preg_replace(
'/[^a-z]/',
'',
strtolower($unzerPayment->getStateName())
);
$params = [
'amount' => $unzerPayment->getAmount()->getTotal(),
'amount' => $this->getTransactionAmount($unzerPayment, $transaction),
'remaining' => $unzerPayment->getAmount()->getRemaining(),
'currency' => $unzerPayment->getCurrency(),
'typeid' => $unzerPayment->getId(),
Expand Down Expand Up @@ -654,4 +655,12 @@ private function prepareTransActionConstForSql(bool $withoutCancel = false): str
}
return implode(',', DatabaseProvider::getDb()->quoteArray($transActionConst));
}

private function getTransactionAmount(
Payment $unzerPayment,
?AbstractTransactionType $transaction = null
): ?float {
return $transaction instanceof Cancellation ?
$transaction->getAmount() : $unzerPayment->getAmount()->getTotal();
}
}

0 comments on commit b43174a

Please sign in to comment.