Skip to content

Commit

Permalink
Release 2.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
vttn committed Jan 26, 2021
1 parent 25f1ece commit 7be5584
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 2.1.1
- Round amounts
- Redirect if the cart can not be recreated

# 2.1.0
- Fix email issues

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG_de-DE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 2.1.1
- Runde Beträge
- Weiterleiten, wenn der Wagen nicht neu erstellt werden kann

# 2.1.0
- E-Mail-Probleme behoben

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ tail -f var/log/postfinancecheckout_payment*.log

## Documentation

[Documentation](https://plugin-documentation.postfinance-checkout.ch/pfpayments/shopware-6/2.1.0/docs/en/documentation.html)
[Documentation](https://plugin-documentation.postfinance-checkout.ch/pfpayments/shopware-6/2.1.1/docs/en/documentation.html)

## License

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@
"postfinancecheckout/sdk": "2.1.6"
},
"type": "shopware-platform-plugin",
"version": "2.1.0"
"version": "2.1.1"
}
2 changes: 1 addition & 1 deletion docs/en/documentation.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h2>Documentation</h2> </div>
</a>
</li>
<li>
<a href="https://github.com/pfpayments/shopware-6/releases/tag/2.1.0/">
<a href="https://github.com/pfpayments/shopware-6/releases/tag/2.1.1/">
Source
</a>
</li>
Expand Down
25 changes: 12 additions & 13 deletions src/Core/Storefront/Checkout/Controller/CheckoutController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
Checkout\Cart\LineItemFactoryRegistry,
Checkout\Cart\SalesChannel\CartService,
Checkout\Order\OrderEntity,
Content\Product\Exception\ProductNotFoundException,
Framework\Context,
Framework\DataAbstractionLayer\Search\Criteria,
Framework\Routing\Annotation\RouteScope,
Expand Down Expand Up @@ -303,9 +302,6 @@ private function getOrder(string $orderId, Context $context): OrderEntity
* @param \Shopware\Core\System\SalesChannel\SalesChannelContext $salesChannelContext
*
* @return \Symfony\Component\HttpFoundation\Response
* @throws \PostFinanceCheckout\Sdk\ApiException
* @throws \PostFinanceCheckout\Sdk\Http\ConnectionException
* @throws \PostFinanceCheckout\Sdk\VersioningException
*
* @Route(
* "/postfinancecheckout/checkout/recreate-cart",
Expand All @@ -322,13 +318,18 @@ public function recreateCart(Cart $cart, Request $request, SalesChannelContext $
throw new MissingRequestParameterException('orderId');
}

// Configuration
$this->settings = $this->settingsService->getSettings($salesChannelContext->getSalesChannel()->getId());
try {
// Configuration
$this->settings = $this->settingsService->getSettings($salesChannelContext->getSalesChannel()->getId());

$orderEntity = $this->getOrder($orderId, $salesChannelContext->getContext());
$orderEntity = $this->getOrder($orderId, $salesChannelContext->getContext());

try {
$transaction = $this->getTransaction($orderId, $salesChannelContext->getContext());
if (!empty($transaction->getUserFailureMessage())) {
$this->addFlash('danger', $transaction->getUserFailureMessage());
}
foreach ($orderEntity->getLineItems() as $orderLineItemEntity) {

$lineItem = $this->lineItemFactoryRegistry->create([
'id' => $orderLineItemEntity->getId(),
'quantity' => $orderLineItemEntity->getQuantity(),
Expand All @@ -337,13 +338,11 @@ public function recreateCart(Cart $cart, Request $request, SalesChannelContext $
], $salesChannelContext);
$cart = $this->cartService->add($cart, $lineItem, $salesChannelContext);
}
$transaction = $this->getTransaction($orderId, $salesChannelContext->getContext());
if (!empty($transaction->getUserFailureMessage())) {
$this->addFlash('danger', $transaction->getUserFailureMessage());
}

} catch (ProductNotFoundException $exception) {
} catch (\Exception $exception) {
$this->addFlash('danger', $this->trans('error.addToCartError'));
$this->logger->critical($exception->getMessage());
return $this->redirectToRoute('frontend.home.page');
}

return $this->redirectToRoute('frontend.checkout.confirm.page');
Expand Down
10 changes: 10 additions & 0 deletions src/Core/Util/Payload/AbstractPayload.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,14 @@ protected function fixLength(string $string, int $maxLength): string
return mb_substr($string, 0, $maxLength, 'UTF-8');
}

/**
* @param $amount
* @param int $precision
*
* @return float
*/
public static function round(float $amount, int $precision = 2): float {
return \round($amount, $precision);
}

}
2 changes: 1 addition & 1 deletion src/Core/Util/Payload/RefundPayload.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function get(Transaction $transaction, float $amount): ?RefundCreate
($amount <= floatval($transaction->getAuthorizationAmount()))
) {
$refund = (new RefundCreate())
->setAmount($amount)
->setAmount(self::round($amount))
->setTransaction($transaction->getId())
->setMerchantReference($this->fixLength($transaction->getMerchantReference(), 100))
->setExternalId($this->fixLength(uniqid('refund_', true), 100))
Expand Down
12 changes: 8 additions & 4 deletions src/Core/Util/Payload/TransactionPayload.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,15 @@ protected function getLineItems(): array
if (!empty($payLoad) && !empty($payLoad['productNumber'])) {
$sku = $payLoad['productNumber'];
}
$sku = $this->fixLength($sku, 200);
$sku = $this->fixLength($sku, 200);
$amount = $shopLineItem->getTotalPrice() ? self::round($shopLineItem->getTotalPrice()) : 0;

$lineItem = (new LineItemCreate())
->setName($this->fixLength($shopLineItem->getLabel(), 150))
->setUniqueId($uniqueId)
->setSku($sku)
->setQuantity($shopLineItem->getQuantity() ?? 1)
->setAmountIncludingTax($shopLineItem->getTotalPrice() ?? 0)
->setAmountIncludingTax($amount)
->setTaxes($taxes);

$productAttributes = $this->getProductAttributes($shopLineItem);
Expand Down Expand Up @@ -296,6 +297,7 @@ protected function getShippingLineItem(): ?LineItemCreate
try {

$amount = $this->transaction->getOrder()->getShippingTotal();
$amount = self::round($amount);

if ($amount > 0) {

Expand Down Expand Up @@ -345,7 +347,8 @@ protected function getAdjustmentLineItem(array &$lineItems): ?LineItemCreate
return $lineItem->getAmountIncludingTax();
}, $lineItems));

$adjustmentPrice = round($this->transaction->getOrder()->getAmountTotal(), 2) - round($lineItemPriceTotal, 2);
$adjustmentPrice = $this->transaction->getOrder()->getAmountTotal() - $lineItemPriceTotal;
$adjustmentPrice = self::round($adjustmentPrice);

if (abs($adjustmentPrice) != 0) {
if ($this->settings->isLineItemConsistencyEnabled()) {
Expand All @@ -363,7 +366,8 @@ protected function getAdjustmentLineItem(array &$lineItems): ?LineItemCreate
->setSku('Adjustment-Line-Item')
->setQuantity(1);
/** @noinspection PhpParamsInspection */
$lineItem->setAmountIncludingTax($adjustmentPrice)->setType(($adjustmentPrice > 0) ? LineItemType::FEE : LineItemType::DISCOUNT);
$lineItem->setAmountIncludingTax($adjustmentPrice)
->setType(($adjustmentPrice > 0) ? LineItemType::FEE : LineItemType::DISCOUNT);

if (!$lineItem->valid()) {
$this->logger->critical('Adjustment LineItem payload invalid:', $lineItem->listInvalidProperties());
Expand Down

0 comments on commit 7be5584

Please sign in to comment.