Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: AmountPatch only if Amount != 0,0 #348

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading