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

Pspaypal 866 #371

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- [0007719](https://bugs.oxid-esales.com/view.php?id=7719): Tracking code also be stored in standard DB field for backwards compatibility
- add possibility to ignore cached tokens. It helps e.g. for webhook registration
- use PayPal-Client v2.0.17
- [0007744](https://bugs.oxid-esales.com/view.php?id=7744): : When using vouchers shop jumps back to payment selection

### NEW

Expand Down Expand Up @@ -49,7 +50,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- [0007675](https://bugs.oxid-esales.com/view.php?id=7675): fix the possibility to finish order without redirect and login to Paypal
- [0007676](https://bugs.oxid-esales.com/view.php?id=7676): If we have a corrupted generated_services.yaml and try to deactivate the module via the admin, we will display a more understandable error message about what happened.
- introduce ActionHash to make the PayPal-Request-ID more unique
- [0007695](https://bugs.oxid-esales.com/view.php?id=7695): Fix: if DeliverySet is set in Frontend, then do not add any PseudoDeliveryCosts for PPExpress

### NEW
- PayPal-Request-Id based on serialized body, no extra PayPal-Request-Id necessary anymore
Expand Down
48 changes: 17 additions & 31 deletions src/Core/PatchRequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,50 +67,36 @@ public function getRequest(

protected function getShippingAddressPatch(): void
{
$addressObj = false;
$address = new AddressPortable();
$session = Registry::getSession();
$deliveryId = Registry::getSession()->getVariable("deladrid");
$deliveryAddress = oxNew(Address::class);

$deliveryId = $session->getVariable("deladrid");
if ($deliveryId && $deliveryAddress->load($deliveryId)) {
$patch = new Patch();
$patch->op = Patch::OP_REPLACE;
$patch->path = "/purchase_units/@reference_id=='"
. Constants::PAYPAL_ORDER_REFERENCE_ID
. "'/shipping/address";

if ($deliveryId) {
$deliveryAddress = oxNew(Address::class);
if ($deliveryAddress->load($deliveryId)) {
$addressObj = $deliveryAddress;
}
}
else {
$user = $this->basket->getUser();
if ($user) {
$addressObj = $user;
}
}
$address = new AddressPortable();

if ($addressObj) {
$state = oxNew(State::class);
$country = oxNew(Country::class);
$state->load($deliveryAddress->getFieldData('oxstateid'));

$state->load($addressObj->getFieldData('oxstateid'));
$country->load($addressObj->getFieldData('oxcountryid'));
$country = oxNew(Country::class);
$country->load($deliveryAddress->getFieldData('oxcountryid'));

$addressLine =
$addressObj->getFieldData('oxstreet') . " " . $addressObj->getFieldData('oxstreetnr');
$deliveryAddress->getFieldData('oxstreet') . " " . $deliveryAddress->getFieldData('oxstreetnr');
$address->address_line_1 = $addressLine;

$addinfoLine = $addressObj->getFieldData('oxcompany') . " " .
$addressObj->getFieldData('oxaddinfo');
$addinfoLine = $deliveryAddress->getFieldData('oxcompany') . " " .
$deliveryAddress->getFieldData('oxaddinfo');
$address->address_line_2 = $addinfoLine;

$address->admin_area_1 = $state->getFieldData('oxtitle');
$address->admin_area_2 = $addressObj->getFieldData('oxcity');
$address->admin_area_2 = $deliveryAddress->getFieldData('oxcity');
$address->country_code = $country->oxcountry__oxisoalpha2->value;
$address->postal_code = $addressObj->getFieldData('oxzip');

$patch = new Patch();
$patch->op = Patch::OP_REPLACE;
$patch->path = "/purchase_units/@reference_id=='"
. Constants::PAYPAL_ORDER_REFERENCE_ID
. "'/shipping/address";
$address->postal_code = $deliveryAddress->getFieldData('oxzip');

$patch->value = $address;

Expand Down
9 changes: 4 additions & 5 deletions src/Core/PayPalRequestAmountFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,16 @@ public function getAmount(Basket $basket): AmountWithBreakdown
}

if ($netMode) {
$total = $brutBasketTotal - $shipping;
$total = $itemTotal - $shipping;
} else {
$total = $itemTotal - $discount + $itemTotalAdditionalCosts;
}
$total_with_shipping = $total + $shipping;

$total = PriceToMoney::convert($total, $currency);
$total_with_shipping = PriceToMoney::convert($total_with_shipping, $currency);

//Total amount
$amount = new AmountWithBreakdown();
$amount->value = $total_with_shipping->value;
$amount->value = $brutBasketTotal;
$amount->currency_code = $total->currency_code;

//Cost breakdown
Expand All @@ -68,7 +66,8 @@ public function getAmount(Basket $basket): AmountWithBreakdown
$breakdown->discount = PriceToMoney::convert($netMode ? $brutDiscountValue : $discount, $currency);
}

$breakdown->item_total = PriceToMoney::convert($total->value, $currency);
$breakDownItemTotal = $netMode ? $total->value : $itemTotal;
$breakdown->item_total = PriceToMoney::convert($breakDownItemTotal, $currency);
//Item tax sum - we use 0% and calculate with brutto to avoid rounding errors
$breakdown->tax_total = PriceToMoney::convert(0, $currency);

Expand Down
1 change: 0 additions & 1 deletion src/Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,6 @@ public function setPayPalTracking(string $trackingCarrier, string $trackingCode)
'oxtrackcode' => $trackingCode
]
);
$this->save();
$payPalOrder = $this->getPayPalRepository();
$payPalOrder->setTrackingCode($trackingCode);
$payPalOrder->setTrackingCarrier($trackingCarrier);
Expand Down
Loading