diff --git a/Gateway/Request/APMBuilder.php b/Gateway/Request/APMBuilder.php index 693bf9f5..aaf332fe 100644 --- a/Gateway/Request/APMBuilder.php +++ b/Gateway/Request/APMBuilder.php @@ -27,10 +27,11 @@ 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\Helper\OmiseHelper; 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 +94,11 @@ class APMBuilder implements BuilderInterface */ const RETURN_URI = 'return_uri'; + /** + * @var string + */ + const DESCRIPTION = 'description'; + /** * @var string */ @@ -113,6 +119,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 */ @@ -133,27 +144,46 @@ class APMBuilder implements BuilderInterface */ protected $config; + /** + * @var \Omise\Payment\Helper\OmiseHelper + */ + private $omiseHelper; + /** * @var \Omise\Payment\Helper\RequestHelper */ 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 + OmiseHelper $omiseHelper, + RequestHelper $requestHelper, + DeploymentConfig $deploymentConfig ) { $this->returnUrl = $returnUrl; $this->config = $config; $this->capability = $capability; $this->money = $money; + $this->omiseHelper = $omiseHelper; $this->requestHelper = $requestHelper; + $this->deploymentConfig = $deploymentConfig; } /** @@ -194,6 +224,18 @@ public function build(array $buildSubject) if ($source !== null) { $paymentInfo[self::SOURCE] = $source; } + + if ($this->config->isSandboxEnabled()) { + $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( + '{original_description}', + $paymentInfo[self::DESCRIPTION], + $customWlbDescription + ); + } + } break; case Truemoney::CODE: $paymentInfo[self::SOURCE] = $this->getTruemoneySourceData($method); 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 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');