Skip to content
Open
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
46 changes: 44 additions & 2 deletions Gateway/Request/APMBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -93,6 +94,11 @@ class APMBuilder implements BuilderInterface
*/
const RETURN_URI = 'return_uri';

/**
* @var string
*/
const DESCRIPTION = 'description';

/**
* @var string
*/
Expand All @@ -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
*/
Expand All @@ -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
Comment on lines +177 to +178
) {
$this->returnUrl = $returnUrl;
$this->config = $config;
$this->capability = $capability;
$this->money = $money;
$this->omiseHelper = $omiseHelper;
$this->requestHelper = $requestHelper;
$this->deploymentConfig = $deploymentConfig;
}

/**
Expand Down Expand Up @@ -194,6 +224,18 @@ public function build(array $buildSubject)
if ($source !== null) {
$paymentInfo[self::SOURCE] = $source;
}

if ($this->config->isSandboxEnabled()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: ‏Not sure why should it be only sandbox. Should this also work for live keys on staging as well? 💡

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I add this condition because we face the issue only on sandbox mode. So for production/live mode no need to get env variable value and manipulate description.

$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
);
Comment on lines +228 to +236
}
}
break;
case Truemoney::CODE:
$paymentInfo[self::SOURCE] = $this->getTruemoneySourceData($method);
Expand Down
12 changes: 10 additions & 2 deletions Gateway/Request/PaymentDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -67,11 +73,13 @@ class PaymentDataBuilder implements BuilderInterface
public function __construct(
Cc $ccConfig,
OmiseMoney $money,
Capability $capability
Capability $capability,
OmiseHelper $omiseHelper
Comment on lines 73 to +77
) {
$this->money = $money;
$this->ccConfig = $ccConfig;
$this->capability = $capability;
$this->omiseHelper = $omiseHelper;
}

/**
Expand All @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion Gateway/Request/UPAPaymentDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
11 changes: 11 additions & 0 deletions Helper/OmiseHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions Test/Unit/Gateway/Request/APMBuilders/APMBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,12 +19,16 @@
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();

Check warning on line 31 in Test/Unit/Gateway/Request/APMBuilders/APMBuilderTest.php

View workflow job for this annotation

GitHub Actions / M2 Coding Standard

Line exceeds 120 characters; contains 122 characters
$this->returnUrlHelper = $this->getMockBuilder(ReturnUrlHelper::class)->disableOriginalConstructor()->getMock();
$this->config = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock();
$this->capability = $this->getMockBuilder(Capability::class)->disableOriginalConstructor()->getMock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 5 additions & 0 deletions Test/Unit/Gateway/Request/UPAPaymentDataBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Loading