Skip to content

Commit 0de3625

Browse files
authored
Merge pull request #123 from swlodarski-sumoheavy/10.2.x
SP-1184 - Add support for Magento 2.4.8-beta2
2 parents f7f9b8b + 40b2464 commit 0de3625

11 files changed

+242
-44
lines changed

.github/2.4.8/php-8.4/Dockerfile

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
FROM php:8.4
2+
3+
COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer
4+
5+
RUN apt-get update && apt-get -y install \
6+
mariadb-client \
7+
apt-transport-https \
8+
git \
9+
zlib1g-dev \
10+
zip \
11+
libjpeg62-turbo-dev \
12+
libfreetype6-dev \
13+
libzip-dev \
14+
libpng-dev \
15+
libjpeg-dev \
16+
libsodium-dev \
17+
libicu-dev \
18+
libxml2-dev \
19+
libxslt-dev \
20+
xmlstarlet \
21+
netcat-openbsd \
22+
&& apt-get -y autoremove \
23+
&& apt-get clean autoclean \
24+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
25+
26+
RUN docker-php-ext-install pdo pdo_mysql
27+
RUN docker-php-ext-install xsl
28+
RUN docker-php-ext-install soap
29+
RUN docker-php-ext-configure gd --with-freetype --with-jpeg
30+
RUN docker-php-ext-install -j$(nproc) gd
31+
RUN docker-php-ext-install bcmath
32+
RUN docker-php-ext-install sodium
33+
RUN docker-php-ext-install zip
34+
RUN docker-php-ext-install intl
35+
RUN docker-php-ext-install sockets
36+
RUN docker-php-ext-install ftp
37+
RUN docker-php-ext-enable ftp
38+
39+
ENV MODULE_NAME=$MODULE_NAME
40+
ENV MODULE_SOURCE=$MODULE_SOURCE
41+
ENV COMPOSER_NAME=$COMPOSER_NAME
42+
ENV MAGENTO_VERSION=$MAGENTO_VERSION
43+
ENV PROJECT_NAME=$PROJECT_NAME
44+
ENV PHPUNIT_FILE=$PHPUNIT_FILE
45+
ENV GITHUB_WORKSPACE=$GITHUB_WORKSPACE
46+
ENV MAGENTO_MARKETPLACE_USERNAME=$MAGENTO_MARKETPLACE_USERNAME
47+
ENV MAGENTO_MARKETPLACE_PASSWORD=$MAGENTO_MARKETPLACE_PASSWORD
48+
49+
COPY .github/2.4.8/php-8.4/entrypoint.sh /entrypoint.sh
50+
RUN chmod 755 /entrypoint.sh
51+
52+
# COPY . $GITHUB_WORKSPACE
53+
COPY . /home/runner/work/bitpay-checkout-magento2/bitpay-checkout-magento2
54+
55+
ENTRYPOINT ["bash", "/entrypoint.sh"]

.github/2.4.8/php-8.4/entrypoint.sh

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
test -z "${MODULE_NAME}" && MODULE_NAME=$INPUT_MODULE_NAME
6+
test -z "${MODULE_SOURCE}" && MODULE_SOURCE=$INPUT_MODULE_SOURCE
7+
test -z "${COMPOSER_NAME}" && COMPOSER_NAME=$INPUT_COMPOSER_NAME
8+
test -z "${MAGENTO_VERSION}" && MAGENTO_VERSION=$INPUT_MAGENTO_VERSION
9+
test -z "${PROJECT_NAME}" && PROJECT_NAME=$INPUT_PROJECT_NAME
10+
test -z "${PHPUNIT_FILE}" && PHPUNIT_FILE=$INPUT_PHPUNIT_FILE
11+
12+
test -z "$MAGENTO_VERSION" && MAGENTO_VERSION="2.4.4"
13+
test -z "$COMPOSER_VERSION" && [[ "$MAGENTO_VERSION" =~ ^2.4.* ]] && COMPOSER_VERSION=2
14+
test -z "$COMPOSER_VERSION" && COMPOSER_VERSION=1
15+
test -z "$PROJECT_NAME" && PROJECT_NAME="magento/project-community-edition"
16+
17+
test -z "${MODULE_NAME}" && (echo "'module_name' is not set" && exit 1)
18+
test -z "${COMPOSER_NAME}" && (echo "'composer_name' is not set" && exit 1)
19+
test -z "${MAGENTO_VERSION}" && (echo "'magento_version' is not set" && exit 1)
20+
21+
MAGENTO_ROOT=/tmp/m2
22+
PROJECT_PATH=$GITHUB_WORKSPACE
23+
test -z "${REPOSITORY_URL}" && REPOSITORY_URL="https://repo-magento-mirror.fooman.co.nz/"
24+
25+
echo "Setup Magento credentials"
26+
test -z "${MAGENTO_MARKETPLACE_USERNAME}" || composer global config http-basic.repo.magento.com $MAGENTO_MARKETPLACE_USERNAME $MAGENTO_MARKETPLACE_PASSWORD
27+
28+
echo "Prepare composer installation"
29+
composer create-project --repository=$REPOSITORY_URL ${PROJECT_NAME}:${MAGENTO_VERSION} $MAGENTO_ROOT --no-install --no-interaction --no-progress
30+
31+
echo "Setup extension source folder within Magento root"
32+
cd $MAGENTO_ROOT
33+
mkdir -p local-source/
34+
cd local-source/
35+
cp -R ${GITHUB_WORKSPACE}/${MODULE_SOURCE} $MODULE_NAME
36+
37+
echo "Configure extension source in composer"
38+
cd $MAGENTO_ROOT
39+
composer config --unset repo.0
40+
composer config repositories.local-source path local-source/\*
41+
composer config repositories.magento composer $REPOSITORY_URL
42+
composer config repositories.base composer https://repo.magento.com/
43+
composer require $COMPOSER_NAME:@dev --no-update --no-interaction
44+
45+
echo "Pre Install Script [magento_pre_install_script]: $INPUT_MAGENTO_PRE_INSTALL_SCRIPT"
46+
if [[ ! -z "$INPUT_MAGENTO_PRE_INSTALL_SCRIPT" && -f "${GITHUB_WORKSPACE}/$INPUT_MAGENTO_PRE_INSTALL_SCRIPT" ]] ; then
47+
echo "Running custom pre-installation script: ${INPUT_MAGENTO_PRE_INSTALL_SCRIPT}"
48+
. ${GITHUB_WORKSPACE}/$INPUT_MAGENTO_PRE_INSTALL_SCRIPT
49+
fi
50+
51+
if [[ "$COMPOSER_VERSION" -eq "2" ]] ; then
52+
echo "Allow composer plugins"
53+
composer config --no-plugins allow-plugins true
54+
fi
55+
56+
echo "Run installation"
57+
COMPOSER_MEMORY_LIMIT=-1 composer install --prefer-dist --no-interaction --no-progress
58+
59+
echo "Determine which phpunit.xml file to use"
60+
61+
echo "Trying phpunit.xml file $PHPUNIT_FILE"
62+
if [[ ! -z "$PHPUNIT_FILE" && ! -f "$PHPUNIT_FILE" ]] ; then
63+
PHPUNIT_FILE=${GITHUB_WORKSPACE}/${PHPUNIT_FILE}
64+
fi
65+
66+
# if [[ ! -f "$PHPUNIT_FILE" ]] ; then
67+
# PHPUNIT_FILE=/docker-files/phpunit.xml
68+
# fi
69+
70+
echo "Using PHPUnit file: $PHPUNIT_FILE"
71+
echo "Prepare for unit tests"
72+
cd $MAGENTO_ROOT
73+
74+
sed "s#%COMPOSER_NAME%#$COMPOSER_NAME#g" $PHPUNIT_FILE > dev/tests/unit/phpunit.xml
75+
76+
for TESTSFOLDER in $(xmlstarlet select -t -v '/phpunit/testsuites/testsuite/directory/text()' dev/tests/unit/phpunit.xml)
77+
do
78+
if [[ ! -d "$MAGENTO_ROOT/dev/tests/unit/$TESTSFOLDER" ]]
79+
then
80+
echo "Optional $TESTSFOLDER location does not exist on your filesystem - removing it from phpunit.xml"
81+
xmlstarlet ed --inplace -d "//phpunit/testsuites/testsuite/directory[contains(text(),'$TESTSFOLDER')]" dev/tests/unit/phpunit.xml
82+
fi
83+
done
84+
85+
echo "Current unit test file"
86+
cat $MAGENTO_ROOT/dev/tests/unit/phpunit.xml
87+
88+
echo "Run the unit tests"
89+
cd $MAGENTO_ROOT/dev/tests/unit && ../../../vendor/bin/phpunit -c phpunit.xml

.github/2.4.8/phpunit.xml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.2/phpunit.xsd"
4+
colors="true"
5+
beStrictAboutTestsThatDoNotTestAnything="false"
6+
bootstrap="./framework/bootstrap.php"
7+
stderr="true"
8+
>
9+
<testsuites>
10+
<testsuite name="UnitTests">
11+
<directory suffix="Test.php">../../../vendor/%COMPOSER_NAME%/Test/Unit</directory>
12+
<directory suffix="Test.php">../../../vendor/%COMPOSER_NAME%/tests/Unit</directory>
13+
<directory suffix="Test.php">../../../vendor/%COMPOSER_NAME%/tests/unit</directory>
14+
</testsuite>
15+
</testsuites>
16+
<php>
17+
<ini name="date.timezone" value="America/Los_Angeles"/>
18+
<ini name="xdebug.max_nesting_level" value="200"/>
19+
</php>
20+
</phpunit>
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
docker-php-ext-install ftp
2+
docker-php-ext-enable ftp
3+
4+
composer config repositories.base composer https://repo.magento.com/

.github/workflows/test.yml

+32-2
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,16 @@ jobs:
2727
strategy:
2828
fail-fast: false
2929
matrix:
30-
MAGENTO_VERSION: ["2.4.6", "2.4.7"]
30+
MAGENTO_VERSION: ["2.4.6", "2.4.7", "2.4.8-beta2"]
3131
steps:
3232
- uses: actions/checkout@v4
3333
- uses: extdn/github-actions-m2/magento-unit-tests/8.2@master
34+
with:
35+
magento_pre_install_script: "./.github/2.4.8/test-pre-install-script.sh"
3436
env:
37+
PHPUNIT_FILE: ".github/2.4.8/phpunit.xml"
38+
MAGENTO_MARKETPLACE_USERNAME: ${{ secrets.MAGENTO_MARKETPLACE_USERNAME }}
39+
MAGENTO_MARKETPLACE_PASSWORD: ${{ secrets.MAGENTO_MARKETPLACE_PASSWORD }}
3540
MAGENTO_VERSION: ${{ matrix.MAGENTO_VERSION }}
3641

3742
unit-tests-83:
@@ -40,12 +45,37 @@ jobs:
4045
strategy:
4146
fail-fast: false
4247
matrix:
43-
MAGENTO_VERSION: ["2.4.7"]
48+
MAGENTO_VERSION: ["2.4.7", "2.4.8-beta2"]
4449
steps:
4550
- uses: actions/checkout@v4
4651
- uses: extdn/github-actions-m2/magento-unit-tests/8.3@master
52+
with:
53+
magento_pre_install_script: "./.github/2.4.8/test-pre-install-script.sh"
54+
env:
55+
PHPUNIT_FILE: ".github/2.4.8/phpunit.xml"
56+
MAGENTO_MARKETPLACE_USERNAME: ${{ secrets.MAGENTO_MARKETPLACE_USERNAME }}
57+
MAGENTO_MARKETPLACE_PASSWORD: ${{ secrets.MAGENTO_MARKETPLACE_PASSWORD }}
58+
MAGENTO_VERSION: ${{ matrix.MAGENTO_VERSION }}
59+
60+
unit-tests-84:
61+
name: Unit Tests (PHP 8.4)
62+
runs-on: ubuntu-latest
63+
strategy:
64+
fail-fast: false
65+
matrix:
66+
MAGENTO_VERSION: ["2.4.8-beta2"]
67+
steps:
68+
- uses: actions/checkout@v4
69+
- name: Build docker image
70+
run: docker build -f .github/2.4.8/php-8.4/Dockerfile -t local .
71+
- name: Run docker image
72+
run: docker run -e GITHUB_WORKSPACE=$GITHUB_WORKSPACE -e MODULE_NAME=$MODULE_NAME -e MODULE_SOURCE=$MODULE_SOURCE -e COMPOSER_NAME=$COMPOSER_NAME -e MAGENTO_VERSION=$MAGENTO_VERSION -e PROJECT_NAME=$PROJECT_NAME -e PHPUNIT_FILE=$PHPUNIT_FILE -e MAGENTO_MARKETPLACE_USERNAME=$MAGENTO_MARKETPLACE_USERNAME -e MAGENTO_MARKETPLACE_PASSWORD=$MAGENTO_MARKETPLACE_PASSWORD local
4773
env:
74+
PHPUNIT_FILE: ".github/2.4.8/phpunit.xml"
75+
MAGENTO_MARKETPLACE_USERNAME: ${{ secrets.MAGENTO_MARKETPLACE_USERNAME }}
76+
MAGENTO_MARKETPLACE_PASSWORD: ${{ secrets.MAGENTO_MARKETPLACE_PASSWORD }}
4877
MAGENTO_VERSION: ${{ matrix.MAGENTO_VERSION }}
78+
GITHUB_WORKSPACE: ${{ github.workspace }}
4979

5080
lint:
5181
name: ESLint

Model/BPRedirect.php

+18-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace Bitpay\BPCheckout\Model;
33

4+
use BitPaySDK\Model\Invoice\Invoice as BitPayInvoice;
45
use Bitpay\BPCheckout\Helper\ReturnHash;
56
use Bitpay\BPCheckout\Logger\Logger;
67
use Magento\Checkout\Model\Session;
@@ -14,6 +15,7 @@
1415
use Magento\Framework\Controller\ResultFactory;
1516
use Magento\Framework\Controller\ResultInterface;
1617
use Magento\Sales\Model\OrderRepository;
18+
use Magento\Framework\Controller\Result\Redirect;
1719
use Magento\Framework\Encryption\EncryptorInterface;
1820

1921
/**
@@ -100,7 +102,7 @@ public function __construct(
100102
* @throws LocalizedException
101103
* @throws NoSuchEntityException|\Exception
102104
*/
103-
public function execute(ResultInterface $defaultResult, string $returnId = null): ResultInterface
105+
public function execute(ResultInterface $defaultResult, ?string $returnId = null): ResultInterface
104106
{
105107
$orderId = $this->checkoutSession->getData('last_order_id');
106108
if (!$orderId) {
@@ -147,6 +149,9 @@ public function execute(ResultInterface $defaultResult, string $returnId = null)
147149
$billingAddressData = $order->getBillingAddress()->getData();
148150
$this->setSessionCustomerData($billingAddressData, $order->getCustomerEmail(), $incrementId);
149151
$client = $this->client->initialize();
152+
/**
153+
* @var BitPayInvoice
154+
*/
150155
$invoice = $this->invoice->BPCCreateInvoice($client, $params);
151156
$invoiceID = $invoice->getId();
152157
$order = $this->orderRepository->save($order);
@@ -193,15 +198,15 @@ private function setSessionCustomerData(array $billingAddressData, string $email
193198
* Sets pending order status
194199
*
195200
* @param OrderInterface $order
196-
* @return void
201+
* @return OrderInterface
197202
* @throws \Exception
198203
*/
199204
private function setToPendingAndOverrideMagentoStatus(OrderInterface $order): OrderInterface
200205
{
201-
$order->setState('new', true);
206+
$order->setState('new');
202207
$order_status = $this->config->getBPCheckoutOrderStatus();
203208
$order_status = !isset($order_status) ? 'pending' : $order_status;
204-
$order->setStatus($order_status, true);
209+
$order->setStatus($order_status);
205210

206211
return $order;
207212
}
@@ -241,9 +246,9 @@ private function getParams(
241246
/**
242247
* Delete order and redirect to cart when error
243248
*
244-
* @param \Exception $exception
249+
* @param \Exception|\Error $exception
245250
* @param OrderInterface $order
246-
* @return void
251+
* @return ResultInterface
247252
* @throws \Exception
248253
*/
249254
private function deleteOrderAndRedirectToCart($exception, OrderInterface $order): ResultInterface
@@ -255,9 +260,13 @@ private function deleteOrderAndRedirectToCart($exception, OrderInterface $order)
255260
$this->registry->unregister('isSecureArea');
256261
$this->messageManager->addErrorMessage('We are unable to place your Order at this time');
257262

258-
return $this->resultFactory->create(
263+
/**
264+
* @var Redirect
265+
* */
266+
$redirect = $this->resultFactory->create(
259267
\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT
260-
)
261-
->setUrl($this->url->getUrl('checkout/cart'));
268+
);
269+
270+
return $redirect->setUrl($this->url->getUrl('checkout/cart'));
262271
}
263272
}

Model/BitPayRefundOnline.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
namespace Bitpay\BPCheckout\Model;
66

7-
use BitPaySDK\Exceptions\BitPayException;
87
use Bitpay\BPCheckout\Logger\Logger;
98
use Bitpay\BPCheckout\Model\BitpayInvoiceRepository;
109
use Bitpay\BPCheckout\Model\BitpayRefundRepository;
1110
use Bitpay\BPCheckout\Model\Client;
1211
use Bitpay\BPCheckout\Model\Config;
12+
use BitPaySDK\Exceptions\BitPayApiException;
1313
use Magento\Directory\Model\PriceCurrency;
1414

1515
class BitPayRefundOnline
@@ -55,7 +55,7 @@ public function execute(\Magento\Sales\Model\Order\Creditmemo $creditMemo): void
5555
$currency = $bitPayInvoice->getCurrency();
5656
try {
5757
$refund = $client->createRefund($invoiceId, $baseOrderRefund, $currency);
58-
} catch (BitPayException $e) {
58+
} catch (BitPayApiException $e) {
5959
$this->handleRefundCreationException($e);
6060
}
6161
$this->bitpayRefundRepository->add($orderId, $refund->getId(), $refund->getAmount());
@@ -65,9 +65,9 @@ public function execute(\Magento\Sales\Model\Order\Creditmemo $creditMemo): void
6565
$order->getPayment()->setData('message', $message);
6666
}
6767

68-
private function handleRefundCreationException(BitPayException $e): void
68+
private function handleRefundCreationException(BitPayApiException $e): void
6969
{
70-
$apiCode = $e->getApiCode();
70+
$apiCode = $e->getBitPayCode();
7171
$this->logger->error($e->getMessage());
7272

7373
$message = match ($apiCode) {

Observer/BitPayPaymentRefund.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
3535
return;
3636
}
3737

38-
$data = $this->request->getPost('creditmemo');
38+
$data = $this->request->getParam('creditmemo');
3939
$doOffline = isset($data['do_offline']) && (bool)$data['do_offline'];
4040

4141
if (!$doOffline) {

Test/Unit/Model/BPRedirectTest.php

+14-10
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,13 @@ public function testExecute(): void
171171
)->method(
172172
'getUrl'
173173
)
174-
->withConsecutive(['bitpay-invoice', ['_query' => ['order_id' => $incrementId]]], ['checkout/cart'])
175-
->willReturnOnConsecutiveCalls(
176-
'http://localhost/bitpay-invoice?order_id=' . $incrementId,
177-
'http://localhost/checkout/cart'
178-
);
174+
->willReturnCallback(function($routePath, $routeParams) use ($incrementId) {
175+
if ($routePath === 'bitpay-invoice' && $routeParams === ['_query' => ['order_id' => $incrementId]]) {
176+
return 'http://localhost/bitpay-invoice?order_id=' . $incrementId;
177+
}
178+
179+
return 'http://localhost/checkout/cart';
180+
});
179181

180182
$billingAddress->expects($this->once())->method('getData')
181183
->willReturn(['first_name' => 'test', 'last_name' => 'test1']);
@@ -281,11 +283,13 @@ public function testExecuteException($exceptionType): void
281283
)->method(
282284
'getUrl'
283285
)
284-
->withConsecutive(['bitpay-invoice', ['_query' => ['order_id' => $incrementId]]], ['checkout/cart'])
285-
->willReturnOnConsecutiveCalls(
286-
'http://localhost/bitpay-invoice?order_id=' . $incrementId,
287-
'http://localhost/checkout/cart'
288-
);
286+
->willReturnCallback(function($routePath, $routeParams) use ($incrementId) {
287+
if ($routePath === 'bitpay-invoice' && $routeParams === ['_query' => ['order_id' => $incrementId]]) {
288+
return 'http://localhost/bitpay-invoice?order_id=' . $incrementId;
289+
}
290+
291+
return 'http://localhost/checkout/cart';
292+
});
289293

290294
$billingAddress->expects($this->once())->method('getData')
291295
->willReturn(['first_name' => 'test', 'last_name' => 'test1']);

0 commit comments

Comments
 (0)