From b787ee8dac586058cccf6e7ba2ef3d523476ab44 Mon Sep 17 00:00:00 2001 From: yanoandri Date: Tue, 25 Feb 2025 10:44:53 +0700 Subject: [PATCH] Feat/update laminas (#186) * use only serializer json * remove xendit serializer all at once * Update to laminas and remove XenditSerializer class * Modify testing environment for 8.2 PHP * Add change log --- .gitignore | 2 +- CHANGELOG.md | 3 +++ Controller/Checkout/Invoice.php | 2 +- Controller/Checkout/InvoiceMultishipping.php | 2 +- Controller/Checkout/Notification.php | 4 ++-- Helper/ApiRequest.php | 2 +- Helper/Metric.php | 2 +- Model/Adminhtml/Source/CartRule.php | 12 ++---------- Model/Payment/AbstractInvoice.php | 12 ++---------- Model/Payment/CC.php | 2 +- bin/copy-plugin.sh | 9 +++++++-- setup-compile.sh => bin/setup-compile.sh | 0 composer.json | 2 +- {docker => docker-magento}/README.md | 6 +++++- {docker => docker-magento}/docker-compose-M23.yml | 0 {docker => docker-magento}/docker-compose.yml | 10 ++++++---- 16 files changed, 34 insertions(+), 36 deletions(-) rename setup-compile.sh => bin/setup-compile.sh (100%) rename {docker => docker-magento}/README.md (96%) rename {docker => docker-magento}/docker-compose-M23.yml (100%) rename {docker => docker-magento}/docker-compose.yml (87%) diff --git a/.gitignore b/.gitignore index 123dc605..fd223c04 100644 --- a/.gitignore +++ b/.gitignore @@ -91,4 +91,4 @@ telepresence.log .DS_Store -docker/magento2 \ No newline at end of file +docker-magento/magento2 \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index a23c5e8c..2608582d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ # CHANGELOG +## 12.0.4 (2025-02-25) +- Fix Undefined variable $xenditSerializerJson +- Upgrade using Laminas\Http\Request from previous Zend\Http\Request on several class ## 12.0.3 (2024-11-25) - Remove UangMe as a payment method (regular & invoice multishipping) diff --git a/Controller/Checkout/Invoice.php b/Controller/Checkout/Invoice.php index c54a3e9f..b6f13c81 100644 --- a/Controller/Checkout/Invoice.php +++ b/Controller/Checkout/Invoice.php @@ -7,7 +7,7 @@ use Magento\Framework\Phrase; use Magento\Sales\Api\Data\OrderItemInterface; use Magento\Sales\Model\Order; -use Zend\Http\Request; +use Laminas\Http\Request; /** * Class Invoice diff --git a/Controller/Checkout/InvoiceMultishipping.php b/Controller/Checkout/InvoiceMultishipping.php index 4360ff59..a0b4593f 100644 --- a/Controller/Checkout/InvoiceMultishipping.php +++ b/Controller/Checkout/InvoiceMultishipping.php @@ -7,7 +7,7 @@ use Magento\Framework\Phrase; use Magento\Sales\Api\Data\OrderItemInterface; use Magento\Sales\Model\Order; -use Zend\Http\Request; +use Laminas\Http\Request; /** * Class InvoiceMultishipping diff --git a/Controller/Checkout/Notification.php b/Controller/Checkout/Notification.php index 1a8f54a4..f8d46e5c 100644 --- a/Controller/Checkout/Notification.php +++ b/Controller/Checkout/Notification.php @@ -23,7 +23,7 @@ use Xendit\M2Invoice\Helper\Data; use Xendit\M2Invoice\Logger\Logger as XenditLogger; use Xendit\M2Invoice\Model\Payment\Xendit; -use Zend\Http\Request; +use Laminas\Http\Request; /** * Class Notification @@ -146,7 +146,7 @@ public function execute() { $post = $this->getRequest()->getContent(); $callbackPayload = json_decode($post, true); - $this->logger->info("callbackPayload", $callbackPayload); + $this->logger->info("callbackPayload", array('payload' => $callbackPayload)); try { // Invoice: Regular CC, Ewallet, Retail Outlet, PayLater diff --git a/Helper/ApiRequest.php b/Helper/ApiRequest.php index 41887611..d9fd3145 100644 --- a/Helper/ApiRequest.php +++ b/Helper/ApiRequest.php @@ -6,7 +6,7 @@ use Magento\Framework\Phrase; use Xendit\M2Invoice\Logger\Logger as XenditLogger; use Xendit\M2Invoice\Model\Payment\Xendit; -use Zend\Http\Request; +use Laminas\Http\Request; /** * Class ApiRequest diff --git a/Helper/Metric.php b/Helper/Metric.php index d8794df2..d5b28b7f 100644 --- a/Helper/Metric.php +++ b/Helper/Metric.php @@ -78,7 +78,7 @@ public function trackMetricCount(array $requestData) try { return $this->apiRequestHelper->request( $this->dataHelper->getXenditApiUrl() . "/tpi/log/metrics/count", - \Zend\Http\Request::METHOD_POST, + \Laminas\Http\Request::METHOD_POST, $requestData ); } catch (LocalizedException $e) { diff --git a/Model/Adminhtml/Source/CartRule.php b/Model/Adminhtml/Source/CartRule.php index 0d5e5f97..b3d53472 100644 --- a/Model/Adminhtml/Source/CartRule.php +++ b/Model/Adminhtml/Source/CartRule.php @@ -5,7 +5,6 @@ use Magento\Framework\Model\Context; use Magento\SalesRule\Model\ResourceModel\Rule\CollectionFactory; use Magento\Framework\Serialize\Serializer\Json as MagentoSerializerJson; -use Xendit\M2Invoice\External\Serialize\Serializer\Json as XenditSerializerJson; /** * Class CartRule @@ -48,23 +47,16 @@ class CartRule implements \Magento\Framework\Option\ArrayInterface * @param Context $context * @param CollectionFactory $ruleCollectionFactory * @param MagentoSerializerJson $magentoSerializerJson - * @param XenditSerializerJson $xenditSerializerJson */ public function __construct( Context $context, CollectionFactory $ruleCollectionFactory, - MagentoSerializerJson $magentoSerializerJson, - XenditSerializerJson $xenditSerializerJson + MagentoSerializerJson $magentoSerializerJson ) { $this->ruleCollectionFactory = $ruleCollectionFactory; $this->cache = $context->getCacheManager(); $this->magentoSerializerJson = $magentoSerializerJson; - $this->xenditSerializerJson = $xenditSerializerJson; - if (interface_exists("Magento\Framework\Serialize\Serializer\Json")) { - $this->serializer = $this->magentoSerializerJson; - } else { - $this->serializer = $this->xenditSerializerJson; - } + $this->serializer = $this->magentoSerializerJson; } /** diff --git a/Model/Payment/AbstractInvoice.php b/Model/Payment/AbstractInvoice.php index f1e50079..7e112ef5 100755 --- a/Model/Payment/AbstractInvoice.php +++ b/Model/Payment/AbstractInvoice.php @@ -16,7 +16,6 @@ use Xendit\M2Invoice\Helper\ApiRequest; use Magento\Quote\Api\CartRepositoryInterface; use Magento\Framework\Serialize\Serializer\Json as MagentoSerializerJson; -use Xendit\M2Invoice\External\Serialize\Serializer\Json as XenditSerializerJson; use Magento\Quote\Api\Data\CartInterface; use Magento\Customer\Model\Session as CustomerSession; use Xendit\M2Invoice\Helper\Metric; @@ -109,7 +108,6 @@ class AbstractInvoice extends AbstractMethod * @param RuleRepository $ruleRepo * @param CartRepositoryInterface $quoteRepository * @param MagentoSerializerJson $magentoSerializerJson - * @param XenditSerializerJson $xenditSerializerJson * @param CustomerSession $customerSession */ public function __construct( @@ -126,7 +124,7 @@ public function __construct( RuleRepository $ruleRepo, CartRepositoryInterface $quoteRepository, MagentoSerializerJson $magentoSerializerJson, - XenditSerializerJson $xenditSerializerJson, + // XenditSerializerJson $xenditSerializerJson, CustomerSession $customerSession, Metric $metricHelper ) { @@ -147,15 +145,9 @@ public function __construct( $this->ruleRepo = $ruleRepo; $this->quoteRepository = $quoteRepository; $this->magentoSerializerJson = $magentoSerializerJson; - $this->xenditSerializerJson = $xenditSerializerJson; $this->customerSession = $customerSession; $this->metricHelper = $metricHelper; - - if (interface_exists("Magento\Framework\Serialize\Serializer\Json")) { - $this->serializer = $this->magentoSerializerJson; - } else { - $this->serializer = $this->xenditSerializerJson; - } + $this->serializer = $this->magentoSerializerJson; } /** diff --git a/Model/Payment/CC.php b/Model/Payment/CC.php index 84e7dfb3..30e6f0f7 100644 --- a/Model/Payment/CC.php +++ b/Model/Payment/CC.php @@ -107,7 +107,7 @@ private function handleRefundResult($payment, $refund, $canRefundMore) private function requestRefund($chargeId, $requestData) { $refundUrl = $this->dataHelper->getXenditApiUrl() . "/tpi/payment/xendit/credit-card/charges/$chargeId/refund"; - $refundMethod = \Zend\Http\Request::METHOD_POST; + $refundMethod = \Laminas\Http\Request::METHOD_POST; try { $refund = $this->apiHelper->request($refundUrl, $refundMethod, $requestData); diff --git a/bin/copy-plugin.sh b/bin/copy-plugin.sh index 27fa139a..16bf34a1 100644 --- a/bin/copy-plugin.sh +++ b/bin/copy-plugin.sh @@ -10,12 +10,14 @@ fi SOURCE_DIR="$1" # Define the files and directories to zip -FILES_TO_COPY="Block Controller etc External Gateway Helper Logger Model Plugin Setup Test view CHANGELOG.md LICENSE README.md registration.php composer.json setup-compile.sh" +FILES_TO_COPY="Block Controller etc External Gateway Helper Logger Model Plugin Setup Test view CHANGELOG.md LICENSE README.md registration.php composer.json" if [ "$SOURCE_DIR" = "devilbox" ]; then DESTINATION="../devilbox/data/www/magento/magento2/app/code/Xendit/M2Invoice" elif [ "$SOURCE_DIR" = "demosites" ]; then DESTINATION="../public_html/app/code/Xendit/M2Invoice" +elif [ "$SOURCE_DIR" = "local-74" ]; then + DESTINATION="./docker-magento/magento2/app/code/Xendit/M2Invoice" else echo "Invalid source directory" exit 1 @@ -28,7 +30,10 @@ cp -r $FILES_TO_COPY $DESTINATION || mkdir -p $DESTINATION && cp -r $FILES_TO_CO # Check if the copy was successful if [ $? -eq 0 ]; then - echo "Files copied successfully, please run 'bash setup-compile.sh' to compile the module" + echo "Files copied successfully, please run 'bash setup-compile.sh' under folder \"app\" to compile the module" + if [ "$SOURCE_DIR" = "local-74" ]; then + docker exec web bash -c "cd /app && bash setup-compile.sh" + fi else echo "Failed to copy files" proxit 1 diff --git a/setup-compile.sh b/bin/setup-compile.sh similarity index 100% rename from setup-compile.sh rename to bin/setup-compile.sh diff --git a/composer.json b/composer.json index 965920d7..19333884 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "xendit/m2invoice", "description": "Xendit Payment Gateway Module", "type": "magento2-module", - "version": "12.0.3", + "version": "12.0.4", "license": [ "GPL-3.0" ], diff --git a/docker/README.md b/docker-magento/README.md similarity index 96% rename from docker/README.md rename to docker-magento/README.md index 72dfeabf..b63c1c85 100644 --- a/docker/README.md +++ b/docker-magento/README.md @@ -89,7 +89,9 @@ php bin/magento setup:install \ --admin-use-security-key=1 \ --session-save=files \ --use-sample-data \ ---elasticsearch-host=elasticsearch +--search-engine=elasticsearch7 \ +--elasticsearch-host=elasticsearch \ +--elasticsearch-port=9200 ``` To include Xendit_M2Invoice module without composer, copy the inner `Xendit` folder into your `MAGENTO_DIR/app/code` @@ -117,6 +119,8 @@ Install sample data: php bin/magento sampledata:deploy ``` +After that run setup & compile command again + ### Alternative (Non auth) You can also get the sample data by adding several package from composer, add this package into your `composer.json` installation diff --git a/docker/docker-compose-M23.yml b/docker-magento/docker-compose-M23.yml similarity index 100% rename from docker/docker-compose-M23.yml rename to docker-magento/docker-compose-M23.yml diff --git a/docker/docker-compose.yml b/docker-magento/docker-compose.yml similarity index 87% rename from docker/docker-compose.yml rename to docker-magento/docker-compose.yml index 890bb50c..d413ac4c 100644 --- a/docker/docker-compose.yml +++ b/docker-magento/docker-compose.yml @@ -1,10 +1,10 @@ version: '3' services: web: - image: webdevops/php-apache-dev:7.4 + image: webdevops/php-apache-dev:8.2 container_name: web restart: always - user: application + user: root environment: - WEB_ALIAS_DOMAIN=magento24.local - WEB_DOCUMENT_ROOT=/app/pub @@ -15,7 +15,7 @@ services: - PHP_POST_MAX_SIZE=500M - PHP_UPLOAD_MAX_FILESIZE=1024M volumes: - - ./magento2:/app:cached + - ./magento2:/app ports: - "80:80" - "443:443" @@ -53,9 +53,11 @@ services: container_name: elasticsearch ports: - "9200:9200" - - "9300:9300" environment: - discovery.type=single-node + - network.host=0.0.0.0 # Changed from localhost + - http.port=9200 + - cluster.name=elasticsearch volumes: - elasticsearch_data:/var/lib/elastisearch volumes: