Skip to content

Commit

Permalink
Merge pull request #316 from OXID-eSales/PSPAYPAL-808_ErrorPatchOrder…
Browse files Browse the repository at this point in the history
…WithZeroAmount

fix: AmountPatch only if Amount != 0,0
  • Loading branch information
mariolorenz authored Jul 19, 2024
2 parents 85633e9 + a142684 commit e9b4baa
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/Core/PatchRequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use OxidEsales\Eshop\Application\Model\Country;
use OxidEsales\Eshop\Application\Model\State;
use OxidEsales\Eshop\Core\Registry;
use OxidSolutionCatalysts\PayPal\Core\PayPalRequestAmountFactory;
use OxidSolutionCatalysts\PayPalApi\Model\Orders\AddressPortable;
use OxidSolutionCatalysts\PayPalApi\Model\Orders\Item;
use OxidSolutionCatalysts\PayPalApi\Model\Orders\Patch;
Expand Down Expand Up @@ -127,12 +126,15 @@ protected function getShippingNamePatch(): void

protected function getAmountPatch(): void
{
$patch = new Patch();
$patch->op = Patch::OP_REPLACE;
$patch->path = "/purchase_units/@reference_id=='" . Constants::PAYPAL_ORDER_REFERENCE_ID . "'/amount";
$patch->value = (Registry::get(PayPalRequestAmountFactory::class))->getAmount($this->basket);
$value = (Registry::get(PayPalRequestAmountFactory::class))->getAmount($this->basket);
if ((float)$value->value !== 0.00) {
$patch = new Patch();
$patch->op = Patch::OP_REPLACE;
$patch->path = "/purchase_units/@reference_id=='" . Constants::PAYPAL_ORDER_REFERENCE_ID . "'/amount";
$patch->value = $value;

$this->request[] = $patch;
$this->request[] = $patch;
}
}

/**
Expand All @@ -152,7 +154,7 @@ protected function getPurchaseUnitsPatch(
$item = new Item();
$item->name = $basketItem->getTitle();
$itemUnitPrice = $basketItem->getUnitPrice();
$item->unit_amount = PriceToMoney::convert((float)$itemUnitPrice->getBruttoPrice(), $currency);
$item->unit_amount = PriceToMoney::convert($itemUnitPrice->getBruttoPrice(), $currency);

//Item tax sum - we use 0% and calculate with brutto to avoid rounding errors
$item->tax = PriceToMoney::convert(0, $currency);
Expand Down

0 comments on commit e9b4baa

Please sign in to comment.