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

SP-1184 - Add support for Magento 2.4.8-beta2 #123

Merged
merged 2 commits into from
Mar 7, 2025
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
55 changes: 55 additions & 0 deletions .github/2.4.8/php-8.4/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
FROM php:8.4

COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer

RUN apt-get update && apt-get -y install \
mariadb-client \
apt-transport-https \
git \
zlib1g-dev \
zip \
libjpeg62-turbo-dev \
libfreetype6-dev \
libzip-dev \
libpng-dev \
libjpeg-dev \
libsodium-dev \
libicu-dev \
libxml2-dev \
libxslt-dev \
xmlstarlet \
netcat-openbsd \
&& apt-get -y autoremove \
&& apt-get clean autoclean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN docker-php-ext-install pdo pdo_mysql
RUN docker-php-ext-install xsl
RUN docker-php-ext-install soap
RUN docker-php-ext-configure gd --with-freetype --with-jpeg
RUN docker-php-ext-install -j$(nproc) gd
RUN docker-php-ext-install bcmath
RUN docker-php-ext-install sodium
RUN docker-php-ext-install zip
RUN docker-php-ext-install intl
RUN docker-php-ext-install sockets
RUN docker-php-ext-install ftp
RUN docker-php-ext-enable ftp

ENV MODULE_NAME=$MODULE_NAME
ENV MODULE_SOURCE=$MODULE_SOURCE
ENV COMPOSER_NAME=$COMPOSER_NAME
ENV MAGENTO_VERSION=$MAGENTO_VERSION
ENV PROJECT_NAME=$PROJECT_NAME
ENV PHPUNIT_FILE=$PHPUNIT_FILE
ENV GITHUB_WORKSPACE=$GITHUB_WORKSPACE
ENV MAGENTO_MARKETPLACE_USERNAME=$MAGENTO_MARKETPLACE_USERNAME
ENV MAGENTO_MARKETPLACE_PASSWORD=$MAGENTO_MARKETPLACE_PASSWORD

COPY .github/2.4.8/php-8.4/entrypoint.sh /entrypoint.sh
RUN chmod 755 /entrypoint.sh

# COPY . $GITHUB_WORKSPACE
COPY . /home/runner/work/bitpay-checkout-magento2/bitpay-checkout-magento2

ENTRYPOINT ["bash", "/entrypoint.sh"]
89 changes: 89 additions & 0 deletions .github/2.4.8/php-8.4/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/bin/bash

set -e

test -z "${MODULE_NAME}" && MODULE_NAME=$INPUT_MODULE_NAME
test -z "${MODULE_SOURCE}" && MODULE_SOURCE=$INPUT_MODULE_SOURCE
test -z "${COMPOSER_NAME}" && COMPOSER_NAME=$INPUT_COMPOSER_NAME
test -z "${MAGENTO_VERSION}" && MAGENTO_VERSION=$INPUT_MAGENTO_VERSION
test -z "${PROJECT_NAME}" && PROJECT_NAME=$INPUT_PROJECT_NAME
test -z "${PHPUNIT_FILE}" && PHPUNIT_FILE=$INPUT_PHPUNIT_FILE

test -z "$MAGENTO_VERSION" && MAGENTO_VERSION="2.4.4"
test -z "$COMPOSER_VERSION" && [[ "$MAGENTO_VERSION" =~ ^2.4.* ]] && COMPOSER_VERSION=2
test -z "$COMPOSER_VERSION" && COMPOSER_VERSION=1
test -z "$PROJECT_NAME" && PROJECT_NAME="magento/project-community-edition"

test -z "${MODULE_NAME}" && (echo "'module_name' is not set" && exit 1)
test -z "${COMPOSER_NAME}" && (echo "'composer_name' is not set" && exit 1)
test -z "${MAGENTO_VERSION}" && (echo "'magento_version' is not set" && exit 1)

MAGENTO_ROOT=/tmp/m2
PROJECT_PATH=$GITHUB_WORKSPACE
test -z "${REPOSITORY_URL}" && REPOSITORY_URL="https://repo-magento-mirror.fooman.co.nz/"

echo "Setup Magento credentials"
test -z "${MAGENTO_MARKETPLACE_USERNAME}" || composer global config http-basic.repo.magento.com $MAGENTO_MARKETPLACE_USERNAME $MAGENTO_MARKETPLACE_PASSWORD

echo "Prepare composer installation"
composer create-project --repository=$REPOSITORY_URL ${PROJECT_NAME}:${MAGENTO_VERSION} $MAGENTO_ROOT --no-install --no-interaction --no-progress

echo "Setup extension source folder within Magento root"
cd $MAGENTO_ROOT
mkdir -p local-source/
cd local-source/
cp -R ${GITHUB_WORKSPACE}/${MODULE_SOURCE} $MODULE_NAME

echo "Configure extension source in composer"
cd $MAGENTO_ROOT
composer config --unset repo.0
composer config repositories.local-source path local-source/\*
composer config repositories.magento composer $REPOSITORY_URL
composer config repositories.base composer https://repo.magento.com/
composer require $COMPOSER_NAME:@dev --no-update --no-interaction

echo "Pre Install Script [magento_pre_install_script]: $INPUT_MAGENTO_PRE_INSTALL_SCRIPT"
if [[ ! -z "$INPUT_MAGENTO_PRE_INSTALL_SCRIPT" && -f "${GITHUB_WORKSPACE}/$INPUT_MAGENTO_PRE_INSTALL_SCRIPT" ]] ; then
echo "Running custom pre-installation script: ${INPUT_MAGENTO_PRE_INSTALL_SCRIPT}"
. ${GITHUB_WORKSPACE}/$INPUT_MAGENTO_PRE_INSTALL_SCRIPT
fi

if [[ "$COMPOSER_VERSION" -eq "2" ]] ; then
echo "Allow composer plugins"
composer config --no-plugins allow-plugins true
fi

echo "Run installation"
COMPOSER_MEMORY_LIMIT=-1 composer install --prefer-dist --no-interaction --no-progress

echo "Determine which phpunit.xml file to use"

echo "Trying phpunit.xml file $PHPUNIT_FILE"
if [[ ! -z "$PHPUNIT_FILE" && ! -f "$PHPUNIT_FILE" ]] ; then
PHPUNIT_FILE=${GITHUB_WORKSPACE}/${PHPUNIT_FILE}
fi

# if [[ ! -f "$PHPUNIT_FILE" ]] ; then
# PHPUNIT_FILE=/docker-files/phpunit.xml
# fi

echo "Using PHPUnit file: $PHPUNIT_FILE"
echo "Prepare for unit tests"
cd $MAGENTO_ROOT

sed "s#%COMPOSER_NAME%#$COMPOSER_NAME#g" $PHPUNIT_FILE > dev/tests/unit/phpunit.xml

for TESTSFOLDER in $(xmlstarlet select -t -v '/phpunit/testsuites/testsuite/directory/text()' dev/tests/unit/phpunit.xml)
do
if [[ ! -d "$MAGENTO_ROOT/dev/tests/unit/$TESTSFOLDER" ]]
then
echo "Optional $TESTSFOLDER location does not exist on your filesystem - removing it from phpunit.xml"
xmlstarlet ed --inplace -d "//phpunit/testsuites/testsuite/directory[contains(text(),'$TESTSFOLDER')]" dev/tests/unit/phpunit.xml
fi
done

echo "Current unit test file"
cat $MAGENTO_ROOT/dev/tests/unit/phpunit.xml

echo "Run the unit tests"
cd $MAGENTO_ROOT/dev/tests/unit && ../../../vendor/bin/phpunit -c phpunit.xml
20 changes: 20 additions & 0 deletions .github/2.4.8/phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.2/phpunit.xsd"
colors="true"
beStrictAboutTestsThatDoNotTestAnything="false"
bootstrap="./framework/bootstrap.php"
stderr="true"
>
<testsuites>
<testsuite name="UnitTests">
<directory suffix="Test.php">../../../vendor/%COMPOSER_NAME%/Test/Unit</directory>
<directory suffix="Test.php">../../../vendor/%COMPOSER_NAME%/tests/Unit</directory>
<directory suffix="Test.php">../../../vendor/%COMPOSER_NAME%/tests/unit</directory>
</testsuite>
</testsuites>
<php>
<ini name="date.timezone" value="America/Los_Angeles"/>
<ini name="xdebug.max_nesting_level" value="200"/>
</php>
</phpunit>
4 changes: 4 additions & 0 deletions .github/2.4.8/test-pre-install-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
docker-php-ext-install ftp
docker-php-ext-enable ftp

composer config repositories.base composer https://repo.magento.com/
34 changes: 32 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@ jobs:
strategy:
fail-fast: false
matrix:
MAGENTO_VERSION: ["2.4.6", "2.4.7"]
MAGENTO_VERSION: ["2.4.6", "2.4.7", "2.4.8-beta2"]
steps:
- uses: actions/checkout@v4
- uses: extdn/github-actions-m2/magento-unit-tests/8.2@master
with:
magento_pre_install_script: "./.github/2.4.8/test-pre-install-script.sh"
env:
PHPUNIT_FILE: ".github/2.4.8/phpunit.xml"
MAGENTO_MARKETPLACE_USERNAME: ${{ secrets.MAGENTO_MARKETPLACE_USERNAME }}
MAGENTO_MARKETPLACE_PASSWORD: ${{ secrets.MAGENTO_MARKETPLACE_PASSWORD }}
MAGENTO_VERSION: ${{ matrix.MAGENTO_VERSION }}

unit-tests-83:
Expand All @@ -40,12 +45,37 @@ jobs:
strategy:
fail-fast: false
matrix:
MAGENTO_VERSION: ["2.4.7"]
MAGENTO_VERSION: ["2.4.7", "2.4.8-beta2"]
steps:
- uses: actions/checkout@v4
- uses: extdn/github-actions-m2/magento-unit-tests/8.3@master
with:
magento_pre_install_script: "./.github/2.4.8/test-pre-install-script.sh"
env:
PHPUNIT_FILE: ".github/2.4.8/phpunit.xml"
MAGENTO_MARKETPLACE_USERNAME: ${{ secrets.MAGENTO_MARKETPLACE_USERNAME }}
MAGENTO_MARKETPLACE_PASSWORD: ${{ secrets.MAGENTO_MARKETPLACE_PASSWORD }}
MAGENTO_VERSION: ${{ matrix.MAGENTO_VERSION }}

unit-tests-84:
name: Unit Tests (PHP 8.4)
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
MAGENTO_VERSION: ["2.4.8-beta2"]
steps:
- uses: actions/checkout@v4
- name: Build docker image
run: docker build -f .github/2.4.8/php-8.4/Dockerfile -t local .
- name: Run docker image
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
env:
PHPUNIT_FILE: ".github/2.4.8/phpunit.xml"
MAGENTO_MARKETPLACE_USERNAME: ${{ secrets.MAGENTO_MARKETPLACE_USERNAME }}
MAGENTO_MARKETPLACE_PASSWORD: ${{ secrets.MAGENTO_MARKETPLACE_PASSWORD }}
MAGENTO_VERSION: ${{ matrix.MAGENTO_VERSION }}
GITHUB_WORKSPACE: ${{ github.workspace }}

lint:
name: ESLint
Expand Down
27 changes: 18 additions & 9 deletions Model/BPRedirect.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Bitpay\BPCheckout\Model;

use BitPaySDK\Model\Invoice\Invoice as BitPayInvoice;
use Bitpay\BPCheckout\Helper\ReturnHash;
use Bitpay\BPCheckout\Logger\Logger;
use Magento\Checkout\Model\Session;
Expand All @@ -14,6 +15,7 @@
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Controller\ResultInterface;
use Magento\Sales\Model\OrderRepository;
use Magento\Framework\Controller\Result\Redirect;
use Magento\Framework\Encryption\EncryptorInterface;

/**
Expand Down Expand Up @@ -100,7 +102,7 @@ public function __construct(
* @throws LocalizedException
* @throws NoSuchEntityException|\Exception
*/
public function execute(ResultInterface $defaultResult, string $returnId = null): ResultInterface
public function execute(ResultInterface $defaultResult, ?string $returnId = null): ResultInterface
{
$orderId = $this->checkoutSession->getData('last_order_id');
if (!$orderId) {
Expand Down Expand Up @@ -147,6 +149,9 @@ public function execute(ResultInterface $defaultResult, string $returnId = null)
$billingAddressData = $order->getBillingAddress()->getData();
$this->setSessionCustomerData($billingAddressData, $order->getCustomerEmail(), $incrementId);
$client = $this->client->initialize();
/**
* @var BitPayInvoice
*/
$invoice = $this->invoice->BPCCreateInvoice($client, $params);
$invoiceID = $invoice->getId();
$order = $this->orderRepository->save($order);
Expand Down Expand Up @@ -193,15 +198,15 @@ private function setSessionCustomerData(array $billingAddressData, string $email
* Sets pending order status
*
* @param OrderInterface $order
* @return void
* @return OrderInterface
* @throws \Exception
*/
private function setToPendingAndOverrideMagentoStatus(OrderInterface $order): OrderInterface
{
$order->setState('new', true);
$order->setState('new');
$order_status = $this->config->getBPCheckoutOrderStatus();
$order_status = !isset($order_status) ? 'pending' : $order_status;
$order->setStatus($order_status, true);
$order->setStatus($order_status);

return $order;
}
Expand Down Expand Up @@ -241,9 +246,9 @@ private function getParams(
/**
* Delete order and redirect to cart when error
*
* @param \Exception $exception
* @param \Exception|\Error $exception
* @param OrderInterface $order
* @return void
* @return ResultInterface
* @throws \Exception
*/
private function deleteOrderAndRedirectToCart($exception, OrderInterface $order): ResultInterface
Expand All @@ -255,9 +260,13 @@ private function deleteOrderAndRedirectToCart($exception, OrderInterface $order)
$this->registry->unregister('isSecureArea');
$this->messageManager->addErrorMessage('We are unable to place your Order at this time');

return $this->resultFactory->create(
/**
* @var Redirect
* */
$redirect = $this->resultFactory->create(
\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT
)
->setUrl($this->url->getUrl('checkout/cart'));
);

return $redirect->setUrl($this->url->getUrl('checkout/cart'));
}
}
8 changes: 4 additions & 4 deletions Model/BitPayRefundOnline.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace Bitpay\BPCheckout\Model;

use BitPaySDK\Exceptions\BitPayException;
use Bitpay\BPCheckout\Logger\Logger;
use Bitpay\BPCheckout\Model\BitpayInvoiceRepository;
use Bitpay\BPCheckout\Model\BitpayRefundRepository;
use Bitpay\BPCheckout\Model\Client;
use Bitpay\BPCheckout\Model\Config;
use BitPaySDK\Exceptions\BitPayApiException;
use Magento\Directory\Model\PriceCurrency;

class BitPayRefundOnline
Expand Down Expand Up @@ -55,7 +55,7 @@ public function execute(\Magento\Sales\Model\Order\Creditmemo $creditMemo): void
$currency = $bitPayInvoice->getCurrency();
try {
$refund = $client->createRefund($invoiceId, $baseOrderRefund, $currency);
} catch (BitPayException $e) {
} catch (BitPayApiException $e) {
$this->handleRefundCreationException($e);
}
$this->bitpayRefundRepository->add($orderId, $refund->getId(), $refund->getAmount());
Expand All @@ -65,9 +65,9 @@ public function execute(\Magento\Sales\Model\Order\Creditmemo $creditMemo): void
$order->getPayment()->setData('message', $message);
}

private function handleRefundCreationException(BitPayException $e): void
private function handleRefundCreationException(BitPayApiException $e): void
{
$apiCode = $e->getApiCode();
$apiCode = $e->getBitPayCode();
$this->logger->error($e->getMessage());

$message = match ($apiCode) {
Expand Down
2 changes: 1 addition & 1 deletion Observer/BitPayPaymentRefund.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
return;
}

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

if (!$doOffline) {
Expand Down
24 changes: 14 additions & 10 deletions Test/Unit/Model/BPRedirectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,13 @@ public function testExecute(): void
)->method(
'getUrl'
)
->withConsecutive(['bitpay-invoice', ['_query' => ['order_id' => $incrementId]]], ['checkout/cart'])
->willReturnOnConsecutiveCalls(
'http://localhost/bitpay-invoice?order_id=' . $incrementId,
'http://localhost/checkout/cart'
);
->willReturnCallback(function($routePath, $routeParams) use ($incrementId) {
if ($routePath === 'bitpay-invoice' && $routeParams === ['_query' => ['order_id' => $incrementId]]) {
return 'http://localhost/bitpay-invoice?order_id=' . $incrementId;
}

return 'http://localhost/checkout/cart';
});

$billingAddress->expects($this->once())->method('getData')
->willReturn(['first_name' => 'test', 'last_name' => 'test1']);
Expand Down Expand Up @@ -281,11 +283,13 @@ public function testExecuteException($exceptionType): void
)->method(
'getUrl'
)
->withConsecutive(['bitpay-invoice', ['_query' => ['order_id' => $incrementId]]], ['checkout/cart'])
->willReturnOnConsecutiveCalls(
'http://localhost/bitpay-invoice?order_id=' . $incrementId,
'http://localhost/checkout/cart'
);
->willReturnCallback(function($routePath, $routeParams) use ($incrementId) {
if ($routePath === 'bitpay-invoice' && $routeParams === ['_query' => ['order_id' => $incrementId]]) {
return 'http://localhost/bitpay-invoice?order_id=' . $incrementId;
}

return 'http://localhost/checkout/cart';
});

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