Skip to content

Commit 247d2cb

Browse files
Merge pull request #805 from mollie/release/2.40.1
Release/2.40.1
2 parents 49565b2 + 83a53ac commit 247d2cb

File tree

17 files changed

+262
-90
lines changed

17 files changed

+262
-90
lines changed

.github/workflows/end-2-end-test.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ jobs:
7373
- name: Start the Magento container
7474
run: |
7575
openssl req -x509 -newkey rsa:4096 -keyout .github/workflows/templates/nginx-proxy/magento.test.key -out .github/workflows/templates/nginx-proxy/magento.test.crt -days 365 -nodes -subj "/CN=magento.test" && \
76-
docker-compose -f .github/workflows/templates/docker-compose.yml up -d
76+
docker compose -f .github/workflows/templates/docker-compose.yml up -d
7777
# Get the URL from ngrok
78-
docker-compose -f .github/workflows/templates/docker-compose.yml logs ngrok
78+
docker compose -f .github/workflows/templates/docker-compose.yml logs ngrok
7979
MAGENTO_URL=$(docker exec magento-project-community-edition /bin/bash -c "curl -s ngrok:4040/api/tunnels |jq -r \".tunnels[0].public_url\"")
8080
echo "magento_url=$MAGENTO_URL" >> $GITHUB_ENV
8181
@@ -118,9 +118,9 @@ jobs:
118118
- name: Dump docker-compose logs
119119
if: always()
120120
run: |
121-
docker-compose -f .github/workflows/templates/docker-compose.yml logs magento > magento.log && \
122-
docker-compose -f .github/workflows/templates/docker-compose.yml logs ngrok > ngrok.log && \
123-
docker-compose -f .github/workflows/templates/docker-compose.yml logs e2e > e2e.log
121+
docker compose -f .github/workflows/templates/docker-compose.yml logs magento > magento.log && \
122+
docker compose -f .github/workflows/templates/docker-compose.yml logs ngrok > ngrok.log && \
123+
docker compose -f .github/workflows/templates/docker-compose.yml logs e2e > e2e.log
124124
125125
- name: Upload artifacts
126126
uses: actions/upload-artifact@v3

Controller/ApplePay/PlaceOrder.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,16 @@ public function execute()
8686

8787
$cart->setCustomerEmail($this->getRequest()->getParam('shippingAddress')['emailAddress']);
8888

89-
$shippingAddress->setShippingMethod(
90-
str_replace(
91-
'__SPLIT__',
92-
'_',
93-
$this->getRequest()->getParam('shippingMethod')['identifier']
94-
)
95-
);
89+
// Orders with digital products can't have a shipping method
90+
if ($this->getRequest()->getParam('shippingMethod')) {
91+
$shippingAddress->setShippingMethod(
92+
str_replace(
93+
'__SPLIT__',
94+
'_',
95+
$this->getRequest()->getParam('shippingMethod')['identifier']
96+
)
97+
);
98+
}
9699

97100
$cart->setPaymentMethod('mollie_methods_applepay');
98101
$cart->setCustomerIsGuest(true);

Model/Client/Orders/Processors/SuccessfulPayment.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ public function __construct(
104104
}
105105

106106
/**
107-
* @param OrderInterface|\Magento\Sales\Model\Order $order
107+
* @param OrderInterface|MagentoOrder $order
108108
* @param MollieOrder $mollieOrder
109109
* @param string $type
110110
* @param ProcessTransactionResponse $response
111-
* @throws \Magento\Framework\Exception\LocalizedException
112111
* @return ProcessTransactionResponse|null
112+
* @throws \Magento\Framework\Exception\LocalizedException
113113
*/
114114
public function process(OrderInterface $order, Order $mollieOrder, string $type, ProcessTransactionResponse $response): ?ProcessTransactionResponse
115115
{
@@ -173,7 +173,9 @@ private function handleWebhookCall(OrderInterface $order, MollieOrder $mollieOrd
173173
$payment->setTransactionId($paymentId);
174174
$payment->setCurrencyCode($order->getBaseCurrencyCode());
175175

176-
if ($order->getState() != \Magento\Sales\Model\Order::STATE_PROCESSING && $mollieOrder->isPaid()) {
176+
if (!in_array($order->getState(), [MagentoOrder::STATE_PROCESSING, MagentoOrder::STATE_COMPLETE]) &&
177+
$mollieOrder->isPaid()
178+
) {
177179
$payment->setIsTransactionClosed(true);
178180
$payment->registerCaptureNotification($order->getBaseGrandTotal(), true);
179181
}
@@ -230,7 +232,7 @@ public function checkCheckoutSession(
230232
}
231233

232234
/**
233-
* @param OrderInterface|\Magento\Sales\Model\Order $order
235+
* @param OrderInterface|MagentoOrder $order
234236
*/
235237
protected function sendOrderEmails(OrderInterface $order): void
236238
{

Model/Client/Payments.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,9 @@ public function processTransaction(Order $order, $mollieApi, $type = 'webhook',
406406
);
407407
}
408408

409-
$payment->registerCaptureNotification($order->getBaseGrandTotal(), true);
409+
if (!in_array($order->getState(), [Order::STATE_PROCESSING, Order::STATE_COMPLETE])) {
410+
$payment->registerCaptureNotification($order->getBaseGrandTotal(), true);
411+
}
410412
}
411413

412414
$order->setState(Order::STATE_PROCESSING);

Service/Magento/PaymentLinkRedirect.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function execute(string $orderId): PaymentLinkRedirectResult
7575
]);
7676
}
7777

78-
if ($this->isPaymentLinkExpired->execute($order) || !$order->canReorder()) {
78+
if ($this->isPaymentLinkExpired->execute($order)) {
7979
return $this->paymentLinkRedirectResultFactory->create([
8080
'redirectUrl' => null,
8181
'isExpired' => true,

Service/Mollie/GetMollieStatusResult.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public function shouldRedirectToSuccessPage(): bool
5050
'pending',
5151
'paid',
5252
'authorized',
53+
'shipping', // When having free or virtual products orders might go into shipping status real quick
5354
'completed', // Completed is mainly to support digital products
5455
]);
5556
}

Service/Mollie/Order/IsPaymentLinkExpired.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public function __construct(
4040

4141
public function execute(OrderInterface $order): bool
4242
{
43-
$methodCode = $this->methodCode->execute($order);
44-
$this->methodCode->getExpiresAtMethod();
43+
$this->methodCode->execute($order);
44+
$methodCode = $this->methodCode->getExpiresAtMethod();
4545
if (!$this->expires->availableForMethod($methodCode, $order->getStoreId())) {
4646
return $this->checkWithDefaultDate($order);
4747
}
@@ -51,11 +51,15 @@ public function execute(OrderInterface $order): bool
5151
return $expiresAt < $order->getCreatedAt();
5252
}
5353

54+
/**
55+
* Default for when no expiry date is set on the chosen method.
56+
*/
5457
private function checkWithDefaultDate(OrderInterface $order): bool
5558
{
56-
$date = $this->timezone->scopeDate($order->getStoreId());
57-
$date = $date->add(new \DateInterval('P28D'));
59+
$now = $this->timezone->scopeDate($order->getStoreId());
60+
$orderDate = $this->timezone->scopeDate($order->getStoreId(), new \DateTime($order->getCreatedAt()));
61+
$diff = $now->diff($orderDate);
5862

59-
return $date->format('Y-m-d H:i:s') < $order->getCreatedAt();
63+
return $diff->days >= 28;
6064
}
6165
}

Service/Order/MethodCode.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ private function paymentLinkMethod(OrderInterface $order): string
5151
}
5252

5353
if (!is_array($additionalInformation['limited_methods']) || count($additionalInformation['limited_methods']) !== 1) {
54+
$this->expiresAtMethod = 'paymentlink';
5455
return '';
5556
}
5657

Test/End-2-end/cypress/e2e/magento/checkout.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('Checkout usage', () => {
2828

2929
const availableMethods = Cypress.env('mollie_available_methods');
3030
[
31-
'alma',
31+
// 'alma', Disabled, not available in NL
3232
'bancomatpay',
3333
'bancontact',
3434
'banktransfer',
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/*
3+
* Copyright Magmodules.eu. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Mollie\Payment\Test\Integration\Service\Magento;
10+
11+
use Magento\Framework\Encryption\EncryptorInterface;
12+
use Magento\Sales\Api\OrderRepositoryInterface;
13+
use Magento\Sales\Model\Order;
14+
use Mollie\Payment\Model\Mollie;
15+
use Mollie\Payment\Service\Magento\PaymentLinkRedirect;
16+
use Mollie\Payment\Test\Integration\IntegrationTestCase;
17+
18+
class PaymentLinkRedirectTest extends IntegrationTestCase
19+
{
20+
public function testThrowsExceptionWhenOrderDoesNotExists(): void
21+
{
22+
$this->expectException(\Magento\Framework\Exception\NotFoundException::class);
23+
24+
$encryptor = $this->objectManager->get(EncryptorInterface::class);
25+
$orderId = base64_encode($encryptor->encrypt('random string'));
26+
27+
/** @var PaymentLinkRedirect $instance */
28+
$instance = $this->objectManager->create(PaymentLinkRedirect::class);
29+
30+
$instance->execute($orderId);
31+
}
32+
33+
/**
34+
* @magentoDataFixture Magento/Sales/_files/order.php
35+
*
36+
* @return void
37+
*/
38+
public function testDoesNotRedirectWhenOrderAlreadyPaid(): void
39+
{
40+
$order = $this->loadOrder('100000001');
41+
$order->setState(Order::STATE_PROCESSING);
42+
43+
$encryptor = $this->objectManager->get(EncryptorInterface::class);
44+
$orderId = base64_encode($encryptor->encrypt($order->getEntityId()));
45+
46+
/** @var PaymentLinkRedirect $instance */
47+
$instance = $this->objectManager->create(PaymentLinkRedirect::class);
48+
$result = $instance->execute($orderId);
49+
50+
$this->assertTrue($result->isAlreadyPaid());
51+
}
52+
53+
/**
54+
* @magentoDataFixture Magento/Sales/_files/order.php
55+
*
56+
* @return void
57+
*/
58+
public function testDoesNotRedirectWhenExpired(): void
59+
{
60+
$orderRepository = $this->objectManager->get(OrderRepositoryInterface::class);
61+
62+
$order = $this->loadOrder('100000001');
63+
$order->setState(Order::STATE_PENDING_PAYMENT);
64+
$order->setCreatedAt(date('Y-m-d H:i:s', strtotime('-31 days')));
65+
$orderRepository->save($order);
66+
67+
$encryptor = $this->objectManager->get(EncryptorInterface::class);
68+
$orderId = base64_encode($encryptor->encrypt($order->getEntityId()));
69+
70+
/** @var PaymentLinkRedirect $instance */
71+
$instance = $this->objectManager->create(PaymentLinkRedirect::class);
72+
$result = $instance->execute($orderId);
73+
74+
$this->assertTrue($result->isExpired());
75+
}
76+
}

0 commit comments

Comments
 (0)