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

37282 shipping cost #35

Merged
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 3.2.1
- Shipping cost as separated parameter

# 3.2.0
- New payment methods: Bank Transfer, P24, Twint, Carte Bancaire, PostFinane

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mediaopt/worldline",
"description": "Worldline Online Payments",
"version": "3.2.0",
"version": "3.2.1",
"type": "shopware-platform-plugin",
"license": "proprietary",
"config": {
Expand Down
25 changes: 17 additions & 8 deletions src/Adapter/WorldlineSDKAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use OnlinePayments\Sdk\Domain\MerchantAction;
use OnlinePayments\Sdk\Domain\Order;
use OnlinePayments\Sdk\Domain\OrderLineDetails;
use OnlinePayments\Sdk\Domain\OrderReferences;
use OnlinePayments\Sdk\Domain\PaymentDetailsResponse;
use OnlinePayments\Sdk\Domain\PaymentProductFilter;
use OnlinePayments\Sdk\Domain\PaymentProductFiltersHostedCheckout;
Expand All @@ -52,6 +53,7 @@
use OnlinePayments\Sdk\Domain\RefundResponse;
use OnlinePayments\Sdk\Domain\Shipping;
use OnlinePayments\Sdk\Domain\ShoppingCart;
use OnlinePayments\Sdk\Domain\ShoppingCartExtension;
use OnlinePayments\Sdk\Domain\ThreeDSecure;
use OnlinePayments\Sdk\Merchant\MerchantClient;
use Shopware\Core\Checkout\Cart\Price\Struct\CalculatedPrice;
Expand Down Expand Up @@ -121,6 +123,13 @@ public function getMerchantClient(array $credentials = []): MerchantClient
$credentials = $this->getCredentials();
}

$shoppingCartExtension = new ShoppingCartExtension(
MoptWorldline::PLUGIN_CREATOR,
MoptWorldline::PLUGIN_NAME,
MoptWorldline::PLUGIN_VERSION,
MoptWorldline::PLUGIN_ID
);

$communicatorConfiguration = new CommunicatorConfiguration(
$credentials['apiKey'],
$credentials['apiSecret'],
Expand All @@ -129,6 +138,8 @@ public function getMerchantClient(array $credentials = []): MerchantClient
null
);

$communicatorConfiguration->setShoppingCartExtension($shoppingCartExtension);

$connection = new DefaultConnection();
$communicator = new Communicator($connection, $communicatorConfiguration);
$client = new Client($communicator);
Expand Down Expand Up @@ -192,6 +203,9 @@ public function createPayment(

$order = new Order();
$order->setAmountOfMoney($amountOfMoney);
$orderRef = new OrderReferences();
$orderRef->setMerchantReference($orderEntity->getOrderNumber());
$order->setReferences($orderRef);

$hostedCheckoutSpecificInput = new HostedCheckoutSpecificInput();
$ReturnUrlController = new ReturnUrlController($this->systemConfigService);
Expand Down Expand Up @@ -376,7 +390,7 @@ public function createHostedTokenization(array $iframeData): GetHostedTokenizati
* @param string $currencyISO
* @param array $iframeData
* @param GetHostedTokenizationResponse $hostedTokenization
* @param OrderEntity $orderEntity
* @param ?OrderEntity $orderEntity
* @return CreatePaymentResponse
* @throws \Exception
*/
Expand All @@ -385,7 +399,7 @@ public function createHostedTokenizationPayment(
string $currencyISO,
array $iframeData,
GetHostedTokenizationResponse $hostedTokenization,
OrderEntity $orderEntity
?OrderEntity $orderEntity
): CreatePaymentResponse
{
$token = $hostedTokenization->getToken()->getId();
Expand Down Expand Up @@ -702,6 +716,7 @@ private function addCartToRequest(
$isNetPrice
)
);
$shipping->setShippingCost($orderEntity->getShippingCosts()->getTotalPrice() * 100);

$order->setShoppingCart($shoppingCart);
$order->setShipping($shipping);
Expand Down Expand Up @@ -806,12 +821,6 @@ private function createRequestLineItems(
if ($shippingPrice > 0) {
$grandPrice += $shippingPrice;
$grandCount++;
$shippingElementId = 'shipping_element';
if ($maxPrices['unit']['price'] < $shippingPrice) {
$maxPrices['unit']['price'] = $shippingPrice;
$maxPrices['unit']['id'] = $shippingElementId;
}
$requestLineItems[$shippingElementId] = self::createLineItem(self::SHIPPING_LABEL, $currencyISO, $shippingPrice, $shippingPrice, 1);
}

if ($discount > 0) {
Expand Down
4 changes: 3 additions & 1 deletion src/MoptWorldline.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
class MoptWorldline extends Plugin
{
const PLUGIN_NAME = 'MoptWorldline';
const PLUGIN_VERSION = '3.2.0';
const PLUGIN_VERSION = '3.2.1';
const PLUGIN_ID = 'MoptWorldline';
const PLUGIN_CREATOR = 'Mediaopt GmbH';

/**
* @param InstallContext $installContext
Expand Down

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/Service/PaymentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public function capturePayment(string $hostedCheckoutId, int $amount, array $ite
$amounts = [];
$log = [];
$isFinal = ($amount == $customFields[Form::CUSTOM_FIELD_WORLDLINE_PAYMENT_TRANSACTION_CAPTURE_AMOUNT]);
/* if ($amount != 0 && !OrderHelper::isOrderLocked($customFields)) {
if ($amount != 0 && !OrderHelper::isOrderLocked($customFields)) {
$captureResponse = $this->adapter->capturePayment($hostedCheckoutId, $amount, $isFinal);
$this->logger->paymentLog($this->order->getOrderNumber(), 'capturePayment', 0, $captureResponse->toJson());
$newStatus = $captureResponse->getStatusOutput()->getStatusCode();
Expand All @@ -264,14 +264,14 @@ public function capturePayment(string $hostedCheckoutId, int $amount, array $ite
$log,
$orderItemsStatus
);
$this->updateOrderTransactionState($newStatus, $hostedCheckoutId, $isFinal);*/
$this->updateOrderTransactionState($newStatus, $hostedCheckoutId, $isFinal);
$message = $this->getSuccessMessage($isFinal, $hostedCheckoutId, 'capturePayment');

/*if ((!in_array($newStatus, Payment::STATUS_CAPTURE_REQUESTED)
if ((!in_array($newStatus, Payment::STATUS_CAPTURE_REQUESTED)
&& !in_array($newStatus, Payment::STATUS_CAPTURED))
&& $amount > 0) {
return [false, 'failed'];
}*/
}
return [true, $message];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Subscriber/CheckoutSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function storefrontRenderEvent(StorefrontRenderEvent $event): void
private function isCheckoutPage($event): bool
{
$route = $event->getRequest()->attributes->get('_route');
if (in_array($route, ['frontend.checkout.confirm.page', 'frontend.checkout.cart.page'])) {
if (in_array($route, ['frontend.checkout.confirm.page', 'frontend.checkout.cart.page', 'frontend.account.edit-order.page'])) {
return true;
}
return false;
Expand Down