From 9200f586adb29b2f38bc98d62017061fed5ddd79 Mon Sep 17 00:00:00 2001 From: Pratik Bharodiya Date: Thu, 17 Sep 2026 15:07:34 +0530 Subject: [PATCH 1/4] Fix the WLB redirection issue for stage --- Gateway/Request/APMBuilder.php | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/Gateway/Request/APMBuilder.php b/Gateway/Request/APMBuilder.php index 693bf9f5..d9eb7a89 100644 --- a/Gateway/Request/APMBuilder.php +++ b/Gateway/Request/APMBuilder.php @@ -27,10 +27,10 @@ use Omise\Payment\Model\Config\Rabbitlinepay; use Omise\Payment\Model\Config\PayPay; use Omise\Payment\Model\Config\WeChatPay; - use Omise\Payment\Helper\OmiseMoney; use Omise\Payment\Model\Config\Conveniencestore; use Magento\Payment\Gateway\Helper\SubjectReader; +use Magento\Framework\App\DeploymentConfig; use Omise\Payment\Observer\FpxDataAssignObserver; use Omise\Payment\Observer\AtomeDataAssignObserver; use Magento\Payment\Gateway\Request\BuilderInterface; @@ -93,6 +93,11 @@ class APMBuilder implements BuilderInterface */ const RETURN_URI = 'return_uri'; + /** + * @var string + */ + const DESCRIPTION = 'description'; + /** * @var string */ @@ -113,6 +118,11 @@ class APMBuilder implements BuilderInterface */ const SOURCE_IP = 'ip'; + /** + * @var string + */ + const OMISE_CUSTOM_WLB_DESCRIPTION = 'omise_custom_wlb_description'; + /** * @var \Omise\Payment\Helper\ReturnUrlHelper */ @@ -138,22 +148,34 @@ class APMBuilder implements BuilderInterface */ private $requestHelper; + /** + * @var DeploymentConfig + */ + private $deploymentConfig; + /** * @param $helper \Omise\Payment\Helper\OmiseHelper * @param $returnUrl \Omise\Payment\Helper\ReturnUrl + * @param $config \Omise\Payment\Model\Config\Config + * @param $capability \Omise\Payment\Model\Capability + * @param $money OmiseMoney + * @param $requestHelper \Omise\Payment\Helper\RequestHelper + * @param $deploymentConfig \Magento\Framework\App\DeploymentConfig */ public function __construct( ReturnUrlHelper $returnUrl, Config $config, Capability $capability, OmiseMoney $money, - RequestHelper $requestHelper + RequestHelper $requestHelper, + DeploymentConfig $deploymentConfig ) { $this->returnUrl = $returnUrl; $this->config = $config; $this->capability = $capability; $this->money = $money; $this->requestHelper = $requestHelper; + $this->deploymentConfig = $deploymentConfig; } /** @@ -194,6 +216,14 @@ public function build(array $buildSubject) if ($source !== null) { $paymentInfo[self::SOURCE] = $source; } + + if($this->config->isSandboxEnabled()) { + $paymentInfo[self::DESCRIPTION] = 'Magento 2 Order id ' . $order->getOrderIncrementId(); + $customWlbDescription = $this->deploymentConfig->get(self::OMISE_CUSTOM_WLB_DESCRIPTION); + if(!empty($customWlbDescription) && !empty($paymentInfo[self::DESCRIPTION])) { + $paymentInfo[self::DESCRIPTION] = str_replace('{original_description}', $paymentInfo[self::DESCRIPTION], $customWlbDescription); + } + } break; case Truemoney::CODE: $paymentInfo[self::SOURCE] = $this->getTruemoneySourceData($method); From a1a0047c6da70565b6049d4ece32f7d68c5586fc Mon Sep 17 00:00:00 2001 From: Pratik Bharodiya Date: Thu, 17 Sep 2026 15:16:10 +0530 Subject: [PATCH 2/4] Resolve codee formating issue --- Gateway/Request/APMBuilder.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Gateway/Request/APMBuilder.php b/Gateway/Request/APMBuilder.php index d9eb7a89..96a25259 100644 --- a/Gateway/Request/APMBuilder.php +++ b/Gateway/Request/APMBuilder.php @@ -216,12 +216,16 @@ public function build(array $buildSubject) if ($source !== null) { $paymentInfo[self::SOURCE] = $source; } - - if($this->config->isSandboxEnabled()) { + + if ($this->config->isSandboxEnabled()) { $paymentInfo[self::DESCRIPTION] = 'Magento 2 Order id ' . $order->getOrderIncrementId(); $customWlbDescription = $this->deploymentConfig->get(self::OMISE_CUSTOM_WLB_DESCRIPTION); - if(!empty($customWlbDescription) && !empty($paymentInfo[self::DESCRIPTION])) { - $paymentInfo[self::DESCRIPTION] = str_replace('{original_description}', $paymentInfo[self::DESCRIPTION], $customWlbDescription); + if (!empty($customWlbDescription) && !empty($paymentInfo[self::DESCRIPTION])) { + $paymentInfo[self::DESCRIPTION] = str_replace( + '{original_description}', + $paymentInfo[self::DESCRIPTION], + $customWlbDescription + ); } } break; From 8d78164f2b0102d3e72c6182ccb041377e376736 Mon Sep 17 00:00:00 2001 From: Pratik Bharodiya Date: Fri, 25 Sep 2026 15:03:31 +0530 Subject: [PATCH 3/4] Create a common fucntion for order description --- Gateway/Request/APMBuilder.php | 10 +++++++++- Gateway/Request/PaymentDataBuilder.php | 12 ++++++++++-- Gateway/Request/UPAPaymentDataBuilder.php | 2 +- Helper/OmiseHelper.php | 11 +++++++++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/Gateway/Request/APMBuilder.php b/Gateway/Request/APMBuilder.php index 96a25259..aaf332fe 100644 --- a/Gateway/Request/APMBuilder.php +++ b/Gateway/Request/APMBuilder.php @@ -28,6 +28,7 @@ use Omise\Payment\Model\Config\PayPay; use Omise\Payment\Model\Config\WeChatPay; use Omise\Payment\Helper\OmiseMoney; +use Omise\Payment\Helper\OmiseHelper; use Omise\Payment\Model\Config\Conveniencestore; use Magento\Payment\Gateway\Helper\SubjectReader; use Magento\Framework\App\DeploymentConfig; @@ -143,6 +144,11 @@ class APMBuilder implements BuilderInterface */ protected $config; + /** + * @var \Omise\Payment\Helper\OmiseHelper + */ + private $omiseHelper; + /** * @var \Omise\Payment\Helper\RequestHelper */ @@ -167,6 +173,7 @@ public function __construct( Config $config, Capability $capability, OmiseMoney $money, + OmiseHelper $omiseHelper, RequestHelper $requestHelper, DeploymentConfig $deploymentConfig ) { @@ -174,6 +181,7 @@ public function __construct( $this->config = $config; $this->capability = $capability; $this->money = $money; + $this->omiseHelper = $omiseHelper; $this->requestHelper = $requestHelper; $this->deploymentConfig = $deploymentConfig; } @@ -218,7 +226,7 @@ public function build(array $buildSubject) } if ($this->config->isSandboxEnabled()) { - $paymentInfo[self::DESCRIPTION] = 'Magento 2 Order id ' . $order->getOrderIncrementId(); + $paymentInfo[self::DESCRIPTION] = $this->omiseHelper->getDescription($order); $customWlbDescription = $this->deploymentConfig->get(self::OMISE_CUSTOM_WLB_DESCRIPTION); if (!empty($customWlbDescription) && !empty($paymentInfo[self::DESCRIPTION])) { $paymentInfo[self::DESCRIPTION] = str_replace( diff --git a/Gateway/Request/PaymentDataBuilder.php b/Gateway/Request/PaymentDataBuilder.php index 979a1068..97e45669 100644 --- a/Gateway/Request/PaymentDataBuilder.php +++ b/Gateway/Request/PaymentDataBuilder.php @@ -5,6 +5,7 @@ use Magento\Payment\Gateway\Helper\SubjectReader; use Magento\Payment\Gateway\Request\BuilderInterface; use Omise\Payment\Helper\OmiseMoney; +use Omise\Payment\Helper\OmiseHelper; use Omise\Payment\Observer\InstallmentDataAssignObserver; use Omise\Payment\Model\Config\Installment; use Omise\Payment\Model\Config\Cc; @@ -59,6 +60,11 @@ class PaymentDataBuilder implements BuilderInterface */ private $capability; + /** + * @var OmiseHelper + */ + private $omiseHelper; + /** * @param \Omise\Payment\Helper\OmiseHelper $omiseHelper * @param Omise\Payment\Model\Config\Cc $ccConfig @@ -67,11 +73,13 @@ class PaymentDataBuilder implements BuilderInterface public function __construct( Cc $ccConfig, OmiseMoney $money, - Capability $capability + Capability $capability, + OmiseHelper $omiseHelper ) { $this->money = $money; $this->ccConfig = $ccConfig; $this->capability = $capability; + $this->omiseHelper = $omiseHelper; } /** @@ -96,7 +104,7 @@ public function build(array $buildSubject) $currency )->toSubunit(), self::CURRENCY => $currency, - self::DESCRIPTION => 'Magento 2 Order id ' . $order->getOrderIncrementId(), + self::DESCRIPTION => $this->omiseHelper->getDescription($order), self::METADATA => [ 'order_id' => $order->getOrderIncrementId(), 'store_id' => $order->getStoreId(), diff --git a/Gateway/Request/UPAPaymentDataBuilder.php b/Gateway/Request/UPAPaymentDataBuilder.php index af9a909e..76fde53d 100644 --- a/Gateway/Request/UPAPaymentDataBuilder.php +++ b/Gateway/Request/UPAPaymentDataBuilder.php @@ -87,7 +87,7 @@ public function build(array $buildSubject) )->toSubunit(), 'currency' => $currency, 'order_id' => (string) $order->getOrderIncrementId(), - 'description' => 'Magento Order id ' . $order->getOrderIncrementId(), + 'description' => $this->omiseHelper->getDescription($order), 'payment_methods' => [$methodId], 'redirect_urls' => [ 'complete_url' => $this->urlBuilder->getUrl( diff --git a/Helper/OmiseHelper.php b/Helper/OmiseHelper.php index d47b12e1..f535b805 100644 --- a/Helper/OmiseHelper.php +++ b/Helper/OmiseHelper.php @@ -274,6 +274,17 @@ public function checkoutSessionEndpoint() { return "https://checkout-page.omise.co/"; } + + /** + * Get the description used for an Omise request. + * + * @param mixed $order + * @return string + */ + public function getDescription($order) + { + return 'Magento 2 Order id ' . $order->getOrderIncrementId(); + } /** * @var string From f7036b353e4312a403b25280e110bb10f9a5680c Mon Sep 17 00:00:00 2001 From: Pratik Bharodiya Date: Fri, 25 Sep 2026 15:15:44 +0530 Subject: [PATCH 4/4] Unit Test class upadte --- Test/Unit/Gateway/Request/APMBuilders/APMBuilderTest.php | 6 ++++++ .../Gateway/Request/APMBuilders/AlipayAPMBuilderTest.php | 4 +++- Test/Unit/Gateway/Request/UPAPaymentDataBuilderTest.php | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Test/Unit/Gateway/Request/APMBuilders/APMBuilderTest.php b/Test/Unit/Gateway/Request/APMBuilders/APMBuilderTest.php index 8eb6d7e4..ad8590ac 100644 --- a/Test/Unit/Gateway/Request/APMBuilders/APMBuilderTest.php +++ b/Test/Unit/Gateway/Request/APMBuilders/APMBuilderTest.php @@ -2,7 +2,9 @@ namespace Omise\Payment\Test\Unit\Gateway\Request\APMBuilders; +use Magento\Framework\App\DeploymentConfig; use Magento\Payment\Gateway\Data\OrderAdapterInterface; +use Omise\Payment\Helper\OmiseHelper; use Omise\Payment\Helper\RequestHelper; use Omise\Payment\Helper\ReturnUrlHelper; use Omise\Payment\Model\Capability; @@ -17,12 +19,16 @@ abstract class APMBuilderTest extends TestCase protected $returnUrlHelper; protected $config; protected $capability; + protected $omiseHelper; + protected $deploymentConfig; protected $orderMock; protected $infoMock; protected function setUp(): void { $this->requestHelper = $this->getMockBuilder(RequestHelper::class)->disableOriginalConstructor()->getMock(); + $this->omiseHelper = $this->getMockBuilder(OmiseHelper::class)->disableOriginalConstructor()->getMock(); + $this->deploymentConfig = $this->getMockBuilder(DeploymentConfig::class)->disableOriginalConstructor()->getMock(); $this->returnUrlHelper = $this->getMockBuilder(ReturnUrlHelper::class)->disableOriginalConstructor()->getMock(); $this->config = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock(); $this->capability = $this->getMockBuilder(Capability::class)->disableOriginalConstructor()->getMock(); diff --git a/Test/Unit/Gateway/Request/APMBuilders/AlipayAPMBuilderTest.php b/Test/Unit/Gateway/Request/APMBuilders/AlipayAPMBuilderTest.php index a743d4b4..1a145406 100644 --- a/Test/Unit/Gateway/Request/APMBuilders/AlipayAPMBuilderTest.php +++ b/Test/Unit/Gateway/Request/APMBuilders/AlipayAPMBuilderTest.php @@ -35,7 +35,9 @@ private function initialize($code) $this->config, $this->capability, new OmiseMoney(), - $this->requestHelper + $this->omiseHelper, + $this->requestHelper, + $this->deploymentConfig ); return $this->builder->build(['payment' => new PaymentDataObject( diff --git a/Test/Unit/Gateway/Request/UPAPaymentDataBuilderTest.php b/Test/Unit/Gateway/Request/UPAPaymentDataBuilderTest.php index 4ff9b43d..ba0fd07a 100644 --- a/Test/Unit/Gateway/Request/UPAPaymentDataBuilderTest.php +++ b/Test/Unit/Gateway/Request/UPAPaymentDataBuilderTest.php @@ -79,6 +79,11 @@ public function testBuildReturnsPayload(): void ->with('omise_upa') ->willReturn('promptpay'); + $this->omiseHelper->expects($this->once()) + ->method('getDescription') + ->with($order) + ->willReturn('Magento Order id 100000001'); + $this->localeResolver->expects($this->once()) ->method('getLocale') ->willReturn('en_US');