From d3125f2f320bce2cb0cfee32c3fd4dacb13cdd9b Mon Sep 17 00:00:00 2001 From: Aashish Gurung <101558497+aashishgurung@users.noreply.github.com> Date: Thu, 17 Oct 2024 13:38:09 +0700 Subject: [PATCH] Make secure form mandatory (#493) * Made secure form mandatory. * Fix failing test. --- .../SecureFormBannerMessage.php | 86 ------------- Gateway/Request/PaymentDataBuilder.php | 4 - Model/Config/Cc.php | 5 - Model/Source/SecureForm.php | 22 ---- Model/Ui/CcConfigProvider.php | 1 - Test/Unit/PaymentDataBuilderTest.php | 1 - Test/Unit/SecureFormBannerMessageTest.php | 80 ------------ etc/adminhtml/di.xml | 8 -- etc/adminhtml/system.xml | 11 -- etc/config.xml | 1 - .../method-renderer/omise-cc-method.js | 81 +----------- .../web/template/payment/omise-cc-form.html | 116 +----------------- 12 files changed, 8 insertions(+), 408 deletions(-) delete mode 100644 Block/Adminhtml/System/Config/CardFormCustomization/SecureFormBannerMessage.php delete mode 100644 Model/Source/SecureForm.php delete mode 100644 Test/Unit/SecureFormBannerMessageTest.php diff --git a/Block/Adminhtml/System/Config/CardFormCustomization/SecureFormBannerMessage.php b/Block/Adminhtml/System/Config/CardFormCustomization/SecureFormBannerMessage.php deleted file mode 100644 index 5da32523d..000000000 --- a/Block/Adminhtml/System/Config/CardFormCustomization/SecureFormBannerMessage.php +++ /dev/null @@ -1,86 +0,0 @@ -omiseCcConfig = $omiseCcConfig; - } - - /** - * Retrieve unique system message identity - * - * @return string - */ - public function getIdentity() - { - return 'opn_payments_secure_form_message'; - } - - /** - * Whether the system message should be shown - * - * @return bool - */ - public function isDisplayed() - { - $secureForm = $this->omiseCcConfig->getSecureForm(); - return $secureForm == 'yes' ? false : true; - } - - /** - * Retrieve system message text - * - * @return \Magento\Framework\Phrase - */ - public function getText() - { - $defaultMessage = "Opn Payments : Update your plugin to the latest version to enable - Secure Form and maximize the security of your customers’ information. - You will need to re-customize the credit card checkout form after the upgrade. - - Learn how to enable Secure Form."; - - return $this->localize('secure_form_banner_message', $defaultMessage); - } - - /** - * Retrieve system message severity - * - * @return int - */ - public function getSeverity() - { - return self::SEVERITY_CRITICAL; - } - - /** - * localize using translation key - * - * @param string $key - * @param string $default - * @return string - */ - public function localize($key, $default) - { - $result = __($key); - return $result == $key ? $default : $result; - } -} diff --git a/Gateway/Request/PaymentDataBuilder.php b/Gateway/Request/PaymentDataBuilder.php index 8512aa188..5e145126e 100644 --- a/Gateway/Request/PaymentDataBuilder.php +++ b/Gateway/Request/PaymentDataBuilder.php @@ -111,10 +111,6 @@ public function build(array $buildSubject) $requestBody[self::ZERO_INTEREST_INSTALLMENTS] = true; } - if (Cc::CODE === $method->getMethod()) { - $requestBody[self::METADATA]['secure_form_enabled'] = $this->ccConfig->getSecureForm(); - } - if (Installment::CODE === $method->getMethod()) { $card = $method->getAdditionalInformation(InstallmentDataAssignObserver::CARD); if ($card !== null) { diff --git a/Model/Config/Cc.php b/Model/Config/Cc.php index 334b1a44e..b0f2f84d0 100644 --- a/Model/Config/Cc.php +++ b/Model/Config/Cc.php @@ -26,9 +26,4 @@ public function getCardTheme() { return $this->getValue('card_form_theme', self::CODE); } - - public function getSecureForm() - { - return $this->getValue('secure_form', self::CODE); - } } diff --git a/Model/Source/SecureForm.php b/Model/Source/SecureForm.php deleted file mode 100644 index 7d9e238cf..000000000 --- a/Model/Source/SecureForm.php +++ /dev/null @@ -1,22 +0,0 @@ - 'yes', - 'label' => __('Yes'), - ], - [ - 'value' => 'no', - 'label' => __('No') - ] - ]; - } -} diff --git a/Model/Ui/CcConfigProvider.php b/Model/Ui/CcConfigProvider.php index 98a00a541..1883e216c 100644 --- a/Model/Ui/CcConfigProvider.php +++ b/Model/Ui/CcConfigProvider.php @@ -56,7 +56,6 @@ public function getConfig() 'isCustomerLoggedIn' => $this->customer->isLoggedIn(), 'cards' => $this->getCards(), 'locale' => $this->omiseCcConfig->getStoreLocale(), - 'secureForm' => $this->omiseCcConfig->getSecureForm(), 'formDesign' => $theme->getFormDesign($selectedTheme, $customDesign), 'theme' => $selectedTheme ], diff --git a/Test/Unit/PaymentDataBuilderTest.php b/Test/Unit/PaymentDataBuilderTest.php index 383bc7b51..59217b4a5 100644 --- a/Test/Unit/PaymentDataBuilderTest.php +++ b/Test/Unit/PaymentDataBuilderTest.php @@ -131,7 +131,6 @@ public function buildDataProvider() 'order_id' => 123, 'store_id' => 1, 'store_name' => 'opn-store', - 'secure_form_enabled' => true ], ], [ diff --git a/Test/Unit/SecureFormBannerMessageTest.php b/Test/Unit/SecureFormBannerMessageTest.php deleted file mode 100644 index 21800a4d0..000000000 --- a/Test/Unit/SecureFormBannerMessageTest.php +++ /dev/null @@ -1,80 +0,0 @@ -_omiseCcConfigMock = $this->createStub(Cc::class); - $this->_messageModel = new SecureFormBannerMessage($this->_omiseCcConfigMock); - } - - /** - * test get identity - * - * @covers Omise\Payment\Block\Adminhtml\System\Config\CardFormCustomization\SecureFormBannerMessage - */ - public function testGetIdentity() - { - $this->assertEquals('opn_payments_secure_form_message', $this->_messageModel->getIdentity()); - } - - /** - * test text is display when secure form is off - * - * @covers Omise\Payment\Block\Adminhtml\System\Config\CardFormCustomization\SecureFormBannerMessage - */ - public function testIsDisplayed() - { - $this->_omiseCcConfigMock->method('getSecureForm')->willReturn(false); - $this->assertEquals(true, $this->_messageModel->isDisplayed()); - } - - /** - * test text is not display when secure form is on - * - * @covers Omise\Payment\Block\Adminhtml\System\Config\CardFormCustomization\SecureFormBannerMessage - */ - public function testIsNotDisplayed() - { - $this->_omiseCcConfigMock->method('getSecureForm')->willReturn(true); - $this->assertEquals(false, $this->_messageModel->isDisplayed()); - } - - /** - * test that get severity should return MessageInterface:SEVERITY_CRITICAL - * - * @covers Omise\Payment\Block\Adminhtml\System\Config\CardFormCustomization\SecureFormBannerMessage - */ - public function testGetSeverity() - { - $this->assertEquals(MessageInterface::SEVERITY_CRITICAL, $this->_messageModel->getSeverity()); - } - - /** - * test getText return valid html - * - * @covers Omise\Payment\Block\Adminhtml\System\Config\CardFormCustomization\SecureFormBannerMessage - */ - public function testGetText() - { - $text = 'Update your plugin to the latest version to enable'; - $this->assertStringContainsString($text, $this->_messageModel->getText()); - } -} diff --git a/etc/adminhtml/di.xml b/etc/adminhtml/di.xml index 556095977..f06fce9f8 100644 --- a/etc/adminhtml/di.xml +++ b/etc/adminhtml/di.xml @@ -8,12 +8,4 @@ - - - - - Omise\Payment\Block\Adminhtml\System\Config\CardFormCustomization\SecureFormBannerMessage - - - diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 94bcc458d..6cbafcbe3 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -85,21 +85,10 @@ This controls the title which the user sees during checkout. payment/omise_cc/title - - - payment/omise_cc/secure_form - Omise\Payment\Model\Source\SecureForm - - mandatory in a future release.]]> - - payment/omise_cc/card_form_theme Omise\Payment\Model\Source\CardFormTheme - - yes - Click here for more secure card form customization.]]> diff --git a/etc/config.xml b/etc/config.xml index 6ab5366a1..bdf2fe671 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -28,7 +28,6 @@ 1 1 authorize - no light diff --git a/view/frontend/web/js/view/payment/method-renderer/omise-cc-method.js b/view/frontend/web/js/view/payment/method-renderer/omise-cc-method.js index 3be8be395..32804e6d7 100644 --- a/view/frontend/web/js/view/payment/method-renderer/omise-cc-method.js +++ b/view/frontend/web/js/view/payment/method-renderer/omise-cc-method.js @@ -83,9 +83,7 @@ define( 'omiseSaveCard', 'omiseCardError' ]) - if (this.isSecureForm()) { - this.openOmiseJs() - } + this.openOmiseJs() return this }, @@ -95,21 +93,15 @@ define( checkoutData.setSelectedPaymentMethod(this.item.method); OmiseCard.destroy(); setTimeout(() => { - if (this.isSecureForm()) { - const element = document.querySelector('.omise-card-form') - if(element) { - this.applyOmiseJsToElement(this, element) - } + const element = document.querySelector('.omise-card-form') + if(element) { + this.applyOmiseJsToElement(this, element) } }, 300); return true }, - isSecureForm: function () { - return window.checkoutConfig.payment.omise_cc.secureForm === 'yes' - }, - openOmiseJs: function () { ko.bindingHandlers.omiseCardForm = { init: (element) => this.applyOmiseJsToElement(this, element) @@ -287,43 +279,6 @@ define( OmiseCard.requestCardToken(billingAddress) }, - /** - * Generate Omise token with omise.js before proceed the placeOrder process. - * - * @return {void} - */ - generateTokenWithOmiseJsAndPerformPlaceOrderAction: function () { - if (! this.validate()) { - return false; - } - - const self = this - this.startPerformingPlaceOrderAction() - - let card = { - number: this.omiseCardNumber(), - name: this.omiseCardHolderName(), - expiration_month: this.omiseCardExpirationMonth(), - expiration_year: this.omiseCardExpirationYear(), - security_code: this.omiseCardSecurityCode() - } - let selectedBillingAddress = quote.billingAddress() - - if (self.billingAddressCountries.indexOf(selectedBillingAddress.countryId) > -1) { - Object.assign(card, this.getSelectedTokenBillingAddress(selectedBillingAddress)) - } - - Omise.setPublicKey(this.getPublicKey()) - Omise.createToken('card', card, function (statusCode, response) { - if (statusCode === 200) { - self.createOrder(self, {token : response.id}) - } else { - self.omiseCardError(response.message) - self.stopPerformingPlaceOrderAction() - } - }) - }, - /** * Hook the placeOrder function. * Original source: placeOrder(data, event); @ module-checkout/view/frontend/web/js/view/payment/default.js @@ -346,36 +301,10 @@ define( return true } - if (this.isSecureForm()) { - this.generateTokenWithEmbeddedFormAndPerformPlaceOrderAction() - } else { - this.generateTokenWithOmiseJsAndPerformPlaceOrderAction() - } - + this.generateTokenWithEmbeddedFormAndPerformPlaceOrderAction() return true }, - /** - * Hook the validate function. - * Original source: validate(); @ module-checkout/view/frontend/web/js/view/payment/default.js - * - * @return {boolean} - */ - validate: function () { - let prefix = '#' + this.getCode(), - fields = [ - 'CardNumber', - 'CardHolderName', - 'CardExpirationMonth', - 'CardExpirationYear', - 'CardSecurityCode' - ] - - - $(prefix + 'Form').validation() - return fields.map(f => $(prefix + f).valid()).every(valid => valid) - }, - processOrderWithCard: function () { const self = this const failHandler = this.buildFailHandler(self, 300) diff --git a/view/frontend/web/template/payment/omise-cc-form.html b/view/frontend/web/template/payment/omise-cc-form.html index 06dc199c5..a534fdb58 100644 --- a/view/frontend/web/template/payment/omise-cc-form.html +++ b/view/frontend/web/template/payment/omise-cc-form.html @@ -71,119 +71,9 @@

- -
-
-
- - - -
-
- -
- -
-
-
- -
- -
-
-
- -
-
-
-
- -
-
-
-
- -
-
-
-
-
-
- -
- -
-
- - -
- - -
- -
- +
+
+