From 234b58c3c654c4194650ad75a3ac6482cd7f4ea5 Mon Sep 17 00:00:00 2001 From: pynkittisak Date: Fri, 21 Jun 2024 14:20:20 +0700 Subject: [PATCH 01/11] [MIT-1911] Whitelabel installment --- Gateway/Request/APMBuilder.php | 21 +- Gateway/Request/PaymentDataBuilder.php | 12 ++ Observer/InstallmentDataAssignObserver.php | 6 +- .../omise-offsite-installment-method.js | 181 +++++++++++++++++- .../payment/offsite-installment-form.html | 30 ++- 5 files changed, 233 insertions(+), 17 deletions(-) diff --git a/Gateway/Request/APMBuilder.php b/Gateway/Request/APMBuilder.php index e855febf8..9e5d98ec8 100644 --- a/Gateway/Request/APMBuilder.php +++ b/Gateway/Request/APMBuilder.php @@ -45,6 +45,11 @@ class APMBuilder implements BuilderInterface { + /** + * @var string + */ + const CARD = 'card'; + /** * @var string */ @@ -187,13 +192,15 @@ public function build(array $buildSubject) ]; break; case Installment::CODE: - $installmentId = $method->getAdditionalInformation(InstallmentDataAssignObserver::OFFSITE); - $paymentInfo[self::SOURCE] = [ - self::SOURCE_TYPE => $installmentId, - self::SOURCE_INSTALLMENT_TERMS => $method->getAdditionalInformation( - InstallmentDataAssignObserver::TERMS - ) - ]; + $card = $method->getAdditionalInformation(InstallmentDataAssignObserver::CARD); + if ($card !== null) { + $paymentInfo[self::CARD] = $card; + } + + $source = $method->getAdditionalInformation(InstallmentDataAssignObserver::SOURCE); + if ($source !== null) { + $paymentInfo[self::SOURCE] = $source; + } break; case Truemoney::CODE: $paymentInfo[self::SOURCE] = $this->getTruemoneySourceData($method); diff --git a/Gateway/Request/PaymentDataBuilder.php b/Gateway/Request/PaymentDataBuilder.php index 94496e251..8512aa188 100644 --- a/Gateway/Request/PaymentDataBuilder.php +++ b/Gateway/Request/PaymentDataBuilder.php @@ -115,6 +115,18 @@ public function build(array $buildSubject) $requestBody[self::METADATA]['secure_form_enabled'] = $this->ccConfig->getSecureForm(); } + if (Installment::CODE === $method->getMethod()) { + $card = $method->getAdditionalInformation(InstallmentDataAssignObserver::CARD); + if ($card !== null) { + $requestBody['card'] = $card; + } + + $source = $method->getAdditionalInformation(InstallmentDataAssignObserver::SOURCE); + if ($source !== null) { + $requestBody['source'] = $source; + } + } + return $requestBody; } diff --git a/Observer/InstallmentDataAssignObserver.php b/Observer/InstallmentDataAssignObserver.php index f49efe790..09c20fa06 100644 --- a/Observer/InstallmentDataAssignObserver.php +++ b/Observer/InstallmentDataAssignObserver.php @@ -16,12 +16,16 @@ class InstallmentDataAssignObserver extends OffsiteDataAssignObserver * @var string */ const TERMS = 'terms'; + const CARD = 'card'; + const SOURCE = 'source'; /** * @var array */ protected $additionalInformationList = [ self::OFFSITE, - self::TERMS + self::TERMS, + self::CARD, + self::SOURCE, ]; } diff --git a/view/frontend/web/js/view/payment/method-renderer/omise-offsite-installment-method.js b/view/frontend/web/js/view/payment/method-renderer/omise-offsite-installment-method.js index aa5da1611..09034d54a 100644 --- a/view/frontend/web/js/view/payment/method-renderer/omise-offsite-installment-method.js +++ b/view/frontend/web/js/view/payment/method-renderer/omise-offsite-installment-method.js @@ -6,6 +6,8 @@ define( 'Magento_Checkout/js/view/payment/default', 'Magento_Checkout/js/model/quote', 'Magento_Catalog/js/price-utils', + 'Magento_Checkout/js/model/full-screen-loader', + 'mage/storage', ], function ( $, @@ -13,7 +15,9 @@ define( Base, Component, quote, - priceUtils + priceUtils, + fullScreenLoader, + storage ) { 'use strict'; const CAPTION = $.mage.__('Choose number of monthly payments'); @@ -83,15 +87,28 @@ define( }, ] + function convertToCents(dollarAmount) { + return Math.round(parseFloat(dollarAmount) * 100); + } + return Component.extend(Base).extend({ defaults: { template: 'Omise_Payment/payment/offsite-installment-form' }, code: 'omise_offsite_installment', restrictedToCurrencies: ['thb', 'myr'], - + isPlaceOrderActionAllowed: ko.observable(quote.billingAddress() != null), capabilities: null, + billingAddressCountries: ["US", "GB", "CA"], + /** + * Get Omise public key + * + * @return {string} + */ + getPublicKey: function () { + return window.checkoutConfig.payment.omise_cc.publicKey + }, /** * Initiate observable fields * @@ -110,16 +127,133 @@ define( 'installmentTermsUOB', 'installmentTermsMBB', 'installmentTermsTTB', + 'omiseInstallmentError', + 'omiseInstallmentToken', + 'omiseInstallmentSource', ]); this.capabilities = checkoutConfig.omise_payment_list[this.code]; // filter provider for checkout page this.providers = this.get_available_providers() - + this.openOmiseJs(); return this; }, + selectPaymentMethod: function () { + this._super(); + OmiseCard.destroy(); + setTimeout(() => this.openOmiseJs(), 1000); + return this + }, + + openOmiseJs: function () { + const self = this + ko.bindingHandlers.omiseInstallmentForm = { + init: function (element) { + const iframeHeightMatching = { + '40px': 258, + '44px': 270, + '48px': 282, + '52px': 295, + } + + const localeMatching = { + en_US: 'en', + ja_JP: 'ja', + th_TH: 'th' + } + + const { theme, locale, formDesign } = window.checkoutConfig.payment.omise_cc + const { font, input, checkbox } = formDesign + let iframeElementHeight = iframeHeightMatching[input.height] + element.style.height = 500 + 'px'; + + OmiseCard.configure({ + publicKey: self.getPublicKey(), + amount: convertToCents(window.checkoutConfig.quoteData.grand_total), + element, + iframeAppId: 'omise-checkout-installment-form', + customCardForm: false, + customInstallmentForm: true, + locale: localeMatching[locale] ?? 'en', + defaultPaymentMethod: 'installment' + }); + + OmiseCard.open({ + onCreateSuccess: (payload) => { + console.log('payload: ', payload); + self.createOrder(self, payload) + }, + onError: (err) => { + if (err.length > 0) { + self.omiseInstallmentError(err.length == 1 ? err[0] : 'Please enter required card information.') + } + else { + self.omiseInstallmentError('Something went wrong. Please refresh the page and try again.') + } + self.stopPerformingPlaceOrderAction() + } + }); + } + } + }, + + createOrder: function (self, payload) { + console.log('in createOrder'); + self.omiseInstallmentToken(payload.token) + self.omiseInstallmentSource(payload.source) + const failHandler = self.buildFailHandler(this, 300) + self.getPlaceOrderDeferredObject() + .fail(failHandler) + .done((order_id) => { + let serviceUrl = self.getMagentoReturnUrl(order_id) + storage.get(serviceUrl, false) + .fail(failHandler) + .done(function (response) { + if (response) { + $.mage.redirect(response.authorize_uri) + } else { + failHandler(response) + } + }) + }) + }, + + /** + * Hook the placeOrder function. + * Original source: placeOrder(data, event); @ module-checkout/view/frontend/web/js/view/payment/default.js + * + * @return {boolean} + */ + placeOrder: function (data, event) { + this.omiseInstallmentError(null) + event && event.preventDefault() + + if (typeof Omise === 'undefined') { + alert($.mage.__('Unable to process the payment, loading the external card processing library is failed. Please contact the merchant.')) + return false + } + + this.generateTokenWithEmbeddedFormAndPerformPlaceOrderAction() + return true + }, + + /** + * Generate Omise token with embedded form before proceed the placeOrder process. + * + * @return {void} + */ + generateTokenWithEmbeddedFormAndPerformPlaceOrderAction: function () { + this.startPerformingPlaceOrderAction() + let billingAddress = {} + let selectedBillingAddress = quote.billingAddress() + if (this.billingAddressCountries.indexOf(selectedBillingAddress.countryId) > -1) { + Object.assign(billingAddress, this.getSelectedTokenBillingAddress(selectedBillingAddress)) + } + OmiseCard.requestCardToken(billingAddress) + }, + /** * Get installment min amount from capability * @@ -312,11 +446,12 @@ define( * @return {Object} */ getData: function () { + console.log('in get data', this.item.method, this.omiseInstallmentToken(), this.omiseInstallmentSource()); return { 'method': this.item.method, 'additional_data': { - 'offsite': this.omiseOffsite(), - 'terms': this.getTerms() + 'card': this.omiseInstallmentToken(), + 'source': this.omiseInstallmentSource() } }; }, @@ -380,8 +515,42 @@ define( } } ))) - } + }, + /** + * Start performing place order action, + * by disable a place order button and show full screen loader component. + */ + startPerformingPlaceOrderAction: function () { + this.isPlaceOrderActionAllowed(false) + fullScreenLoader.startLoader() + }, + + /** + * Stop performing place order action, + * by disable a place order button and show full screen loader component. + */ + stopPerformingPlaceOrderAction: function () { + fullScreenLoader.stopLoader() + this.isPlaceOrderActionAllowed(true) + }, + + getSelectedTokenBillingAddress: function (selectedBillingAddress) { + let address = { + state: selectedBillingAddress.region, + postal_code: selectedBillingAddress.postcode, + phone_number: selectedBillingAddress.telephone, + country: selectedBillingAddress.countryId, + city: selectedBillingAddress.city, + street1: selectedBillingAddress.street[0] + } + + if (selectedBillingAddress.street[1]) { + address.street2 = selectedBillingAddress.street[1] + } + + return address + } }); } ); diff --git a/view/frontend/web/template/payment/offsite-installment-form.html b/view/frontend/web/template/payment/offsite-installment-form.html index 50c004e35..e16d0d7ce 100644 --- a/view/frontend/web/template/payment/offsite-installment-form.html +++ b/view/frontend/web/template/payment/offsite-installment-form.html @@ -39,8 +39,17 @@ + + +
+ +
+ + -
+ + + +
@@ -96,7 +120,7 @@ click: placeOrder, attr: {title: $t('Place Order')}, css: {disabled: !isPlaceOrderActionAllowed()}, - enable: (getCode() == isChecked()) && omiseOffsite() && getTerms() "> + enable: (getCode() == isChecked())">
From 55a95cef48e5c991d4f71257a7c2e612b458a585 Mon Sep 17 00:00:00 2001 From: pynkittisak Date: Fri, 28 Jun 2024 15:19:18 +0700 Subject: [PATCH 02/11] fix re-init js --- .../method-renderer/omise-cc-method.js | 142 ++++++++++-------- .../omise-offsite-installment-method.js | 99 ++++++------ 2 files changed, 130 insertions(+), 111 deletions(-) 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 6a53345fc..af0dcc21e 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 @@ -85,80 +85,96 @@ define( return this }, + selectPaymentMethod: function () { + this._super(); + OmiseCard.destroy(); + setTimeout(() => { + if (this.isSecureForm()) { + const element = document.querySelector('.omise-card-form') + if(element) { + this.applyOmiseJsToElement(this, element) + } + } + }, 300); + + return this + }, + isSecureForm: function () { return window.checkoutConfig.payment.omise_cc.secureForm === 'yes' }, openOmiseJs: function () { - const self = this ko.bindingHandlers.omiseCardForm = { - init: function (element) { - const hideRememberCard = !self.isCustomerLoggedIn() - const iframeHeightMatching = { - '40px': 258, - '44px': 270, - '48px': 282, - '52px': 295, - } + init: (element) => this.applyOmiseJsToElement(this, element) + } + }, + + applyOmiseJsToElement: function (self, element) { + const hideRememberCard = !self.isCustomerLoggedIn() + const iframeHeightMatching = { + '40px': 258, + '44px': 270, + '48px': 282, + '52px': 295, + } - const localeMatching = { - en_US: 'en', - ja_JP: 'ja', - th_TH: 'th' + const localeMatching = { + en_US: 'en', + ja_JP: 'ja', + th_TH: 'th' + } + + const { theme, locale, formDesign } = window.checkoutConfig.payment.omise_cc + const { font, input, checkbox } = formDesign + let iframeElementHeight = iframeHeightMatching[input.height] + if (hideRememberCard) { + iframeElementHeight = iframeElementHeight - 25 + } + element.style.height = iframeElementHeight + 'px' + + OmiseCard.configure({ + publicKey: self.getPublicKey(), + element, + locale: localeMatching[locale] ?? 'en', + customCardForm: true, + customCardFormTheme: theme, + style: { + fontFamily: font.name, + fontSize: font.size, + input: { + height: input.height, + borderRadius: input.border_radius, + border: `1.2px solid ${input.border_color}`, + focusBorder: `1.2px solid ${input.active_border_color}`, + background: input.background_color, + color: input.text_color, + labelColor: input.label_color, + placeholderColor: input.placeholder_color, + }, + checkBox: { + textColor: checkbox.text_color, + themeColor: checkbox.theme_color, + border: `1.2px solid ${input.border_color}`, } + }, + customCardFormHideRememberCard: hideRememberCard + }) - const { theme, locale, formDesign } = window.checkoutConfig.payment.omise_cc - const { font, input, checkbox } = formDesign - let iframeElementHeight = iframeHeightMatching[input.height] - if (hideRememberCard) { - iframeElementHeight = iframeElementHeight - 25 + OmiseCard.open({ + onCreateTokenSuccess: (payload) => { + self.createOrder(self, payload) + }, + onError: (err) => { + if (err.length > 0) { + self.omiseCardError(err.length == 1 ? err[0] : 'Please enter required card information.') } - element.style.height = iframeElementHeight + 'px' - - OmiseCard.configure({ - publicKey: self.getPublicKey(), - element, - locale: localeMatching[locale] ?? 'en', - customCardForm: true, - customCardFormTheme: theme, - style: { - fontFamily: font.name, - fontSize: font.size, - input: { - height: input.height, - borderRadius: input.border_radius, - border: `1.2px solid ${input.border_color}`, - focusBorder: `1.2px solid ${input.active_border_color}`, - background: input.background_color, - color: input.text_color, - labelColor: input.label_color, - placeholderColor: input.placeholder_color, - }, - checkBox: { - textColor: checkbox.text_color, - themeColor: checkbox.theme_color, - border: `1.2px solid ${input.border_color}`, - } - }, - customCardFormHideRememberCard: hideRememberCard - }) - - OmiseCard.open({ - onCreateTokenSuccess: (payload) => { - self.createOrder(self, payload) - }, - onError: (err) => { - if (err.length > 0) { - self.omiseCardError(err.length == 1 ? err[0] : 'Please enter required card information.') - } - else { - self.omiseCardError('Something went wrong. Please refresh the page and try again.') - } - self.stopPerformingPlaceOrderAction() - } - }) + else { + self.omiseCardError('Something went wrong. Please refresh the page and try again.') + } + self.stopPerformingPlaceOrderAction() } - } + }) }, createOrder: function (self, payload) { diff --git a/view/frontend/web/js/view/payment/method-renderer/omise-offsite-installment-method.js b/view/frontend/web/js/view/payment/method-renderer/omise-offsite-installment-method.js index 09034d54a..510afb64f 100644 --- a/view/frontend/web/js/view/payment/method-renderer/omise-offsite-installment-method.js +++ b/view/frontend/web/js/view/payment/method-renderer/omise-offsite-installment-method.js @@ -143,64 +143,68 @@ define( selectPaymentMethod: function () { this._super(); OmiseCard.destroy(); - setTimeout(() => this.openOmiseJs(), 1000); + setTimeout(() => { + const element = document.querySelector('.omise-installment-form') + if(element) { + this.applyOmiseJsToElement(this, element); + } + }, 300); return this }, openOmiseJs: function () { - const self = this ko.bindingHandlers.omiseInstallmentForm = { - init: function (element) { - const iframeHeightMatching = { - '40px': 258, - '44px': 270, - '48px': 282, - '52px': 295, - } + init: (element) => this.applyOmiseJsToElement(this, element) + } + }, - const localeMatching = { - en_US: 'en', - ja_JP: 'ja', - th_TH: 'th' - } + applyOmiseJsToElement: function (self, element) { + const iframeHeightMatching = { + '40px': 258, + '44px': 270, + '48px': 282, + '52px': 295, + } - const { theme, locale, formDesign } = window.checkoutConfig.payment.omise_cc - const { font, input, checkbox } = formDesign - let iframeElementHeight = iframeHeightMatching[input.height] - element.style.height = 500 + 'px'; - - OmiseCard.configure({ - publicKey: self.getPublicKey(), - amount: convertToCents(window.checkoutConfig.quoteData.grand_total), - element, - iframeAppId: 'omise-checkout-installment-form', - customCardForm: false, - customInstallmentForm: true, - locale: localeMatching[locale] ?? 'en', - defaultPaymentMethod: 'installment' - }); - - OmiseCard.open({ - onCreateSuccess: (payload) => { - console.log('payload: ', payload); - self.createOrder(self, payload) - }, - onError: (err) => { - if (err.length > 0) { - self.omiseInstallmentError(err.length == 1 ? err[0] : 'Please enter required card information.') - } - else { - self.omiseInstallmentError('Something went wrong. Please refresh the page and try again.') - } - self.stopPerformingPlaceOrderAction() - } - }); - } + const localeMatching = { + en_US: 'en', + ja_JP: 'ja', + th_TH: 'th' } + + const { theme, locale, formDesign } = window.checkoutConfig.payment.omise_cc + const { font, input, checkbox } = formDesign + let iframeElementHeight = iframeHeightMatching[input.height] + element.style.height = 500 + 'px'; + + OmiseCard.configure({ + publicKey: self.getPublicKey(), + amount: convertToCents(window.checkoutConfig.quoteData.grand_total), + element, + iframeAppId: 'omise-checkout-installment-form', + customCardForm: false, + customInstallmentForm: true, + locale: localeMatching[locale] ?? 'en', + defaultPaymentMethod: 'installment' + }); + + OmiseCard.open({ + onCreateSuccess: (payload) => { + self.createOrder(self, payload) + }, + onError: (err) => { + if (err.length > 0) { + self.omiseInstallmentError(err.length == 1 ? err[0] : 'Please enter required card information.') + } + else { + self.omiseInstallmentError('Something went wrong. Please refresh the page and try again.') + } + self.stopPerformingPlaceOrderAction() + } + }); }, createOrder: function (self, payload) { - console.log('in createOrder'); self.omiseInstallmentToken(payload.token) self.omiseInstallmentSource(payload.source) const failHandler = self.buildFailHandler(this, 300) @@ -446,7 +450,6 @@ define( * @return {Object} */ getData: function () { - console.log('in get data', this.item.method, this.omiseInstallmentToken(), this.omiseInstallmentSource()); return { 'method': this.item.method, 'additional_data': { From fa3e7a17ebd996b865a60fc49758a39cec73362c Mon Sep 17 00:00:00 2001 From: pynkittisak Date: Fri, 28 Jun 2024 16:13:28 +0700 Subject: [PATCH 03/11] fix radio button --- .../view/payment/method-renderer/omise-cc-method.js | 12 +++++++++--- .../omise-offsite-installment-method.js | 10 ++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) 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 af0dcc21e..3be8be395 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 @@ -8,7 +8,9 @@ define( 'Magento_Payment/js/model/credit-card-validation/validator', 'Magento_Checkout/js/model/full-screen-loader', 'Magento_Checkout/js/action/redirect-on-success', - 'Magento_Checkout/js/model/quote' + 'Magento_Checkout/js/model/quote', + 'Magento_Checkout/js/checkout-data', + 'Magento_Checkout/js/action/select-payment-method' ], function ( ko, @@ -19,7 +21,9 @@ define( validator, fullScreenLoader, redirectOnSuccessAction, - quote + quote, + checkoutData, + selectPaymentMethodAction ) { 'use strict' @@ -87,6 +91,8 @@ define( selectPaymentMethod: function () { this._super(); + selectPaymentMethodAction(this.getData()); + checkoutData.setSelectedPaymentMethod(this.item.method); OmiseCard.destroy(); setTimeout(() => { if (this.isSecureForm()) { @@ -97,7 +103,7 @@ define( } }, 300); - return this + return true }, isSecureForm: function () { diff --git a/view/frontend/web/js/view/payment/method-renderer/omise-offsite-installment-method.js b/view/frontend/web/js/view/payment/method-renderer/omise-offsite-installment-method.js index 510afb64f..7911bed05 100644 --- a/view/frontend/web/js/view/payment/method-renderer/omise-offsite-installment-method.js +++ b/view/frontend/web/js/view/payment/method-renderer/omise-offsite-installment-method.js @@ -8,6 +8,8 @@ define( 'Magento_Catalog/js/price-utils', 'Magento_Checkout/js/model/full-screen-loader', 'mage/storage', + 'Magento_Checkout/js/checkout-data', + 'Magento_Checkout/js/action/select-payment-method' ], function ( $, @@ -17,7 +19,9 @@ define( quote, priceUtils, fullScreenLoader, - storage + storage, + checkoutData, + selectPaymentMethodAction ) { 'use strict'; const CAPTION = $.mage.__('Choose number of monthly payments'); @@ -142,6 +146,8 @@ define( selectPaymentMethod: function () { this._super(); + selectPaymentMethodAction(this.getData()); + checkoutData.setSelectedPaymentMethod(this.item.method); OmiseCard.destroy(); setTimeout(() => { const element = document.querySelector('.omise-installment-form') @@ -149,7 +155,7 @@ define( this.applyOmiseJsToElement(this, element); } }, 300); - return this + return true }, openOmiseJs: function () { From 88eac04154f7761bbe5bd0dc22543b939f6c704f Mon Sep 17 00:00:00 2001 From: pynkittisak Date: Mon, 1 Jul 2024 10:27:43 +0700 Subject: [PATCH 04/11] Update test --- .../APMBuilders/InstallmentAPMBuilderTest.php | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Test/Unit/Gateway/Request/APMBuilders/InstallmentAPMBuilderTest.php diff --git a/Test/Unit/Gateway/Request/APMBuilders/InstallmentAPMBuilderTest.php b/Test/Unit/Gateway/Request/APMBuilders/InstallmentAPMBuilderTest.php new file mode 100644 index 000000000..635e9c916 --- /dev/null +++ b/Test/Unit/Gateway/Request/APMBuilders/InstallmentAPMBuilderTest.php @@ -0,0 +1,45 @@ +infoMock->method('getMethod')->willReturn(Installment::CODE); + $this->returnUrlHelper->method('create')->willReturn([ + 'url' => 'https://omise.co/complete', + 'card' => 'mock_card', + 'source' => 'mock_source', + 'token' => 'mock_token' + ]); + $this->infoMock->method('getAdditionalInformation')->willReturn('mock_source'); + + $this->builder = new APMBuilder( + $this->returnUrlHelper, + $this->config, + $this->capabilities, + new OmiseMoney(), + $this->requestHelper + ); + + $result = $this->builder->build(['payment' => new PaymentDataObject( + $this->orderMock, + $this->infoMock + )]); + + $this->assertEquals('mock_source', $result['source']); + $this->assertEquals('https://omise.co/complete', $result['return_uri']); + } + + +} From 54579a47979013279c9b1d95b51a64088977149d Mon Sep 17 00:00:00 2001 From: pynkittisak Date: Mon, 1 Jul 2024 10:31:05 +0700 Subject: [PATCH 05/11] fix empty line --- .../Gateway/Request/APMBuilders/InstallmentAPMBuilderTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/Test/Unit/Gateway/Request/APMBuilders/InstallmentAPMBuilderTest.php b/Test/Unit/Gateway/Request/APMBuilders/InstallmentAPMBuilderTest.php index 635e9c916..20c520935 100644 --- a/Test/Unit/Gateway/Request/APMBuilders/InstallmentAPMBuilderTest.php +++ b/Test/Unit/Gateway/Request/APMBuilders/InstallmentAPMBuilderTest.php @@ -40,6 +40,4 @@ public function testApmBuilderForInstallment() $this->assertEquals('mock_source', $result['source']); $this->assertEquals('https://omise.co/complete', $result['return_uri']); } - - } From f1cd4cb799b2d785067902da877b982bde47bdbb Mon Sep 17 00:00:00 2001 From: pynkittisak Date: Mon, 1 Jul 2024 17:54:44 +0700 Subject: [PATCH 06/11] Fix grand_total --- .../payment/method-renderer/omise-offsite-installment-method.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view/frontend/web/js/view/payment/method-renderer/omise-offsite-installment-method.js b/view/frontend/web/js/view/payment/method-renderer/omise-offsite-installment-method.js index 7911bed05..2a0a6b779 100644 --- a/view/frontend/web/js/view/payment/method-renderer/omise-offsite-installment-method.js +++ b/view/frontend/web/js/view/payment/method-renderer/omise-offsite-installment-method.js @@ -185,7 +185,7 @@ define( OmiseCard.configure({ publicKey: self.getPublicKey(), - amount: convertToCents(window.checkoutConfig.quoteData.grand_total), + amount: convertToCents(quote.totals().grand_total), element, iframeAppId: 'omise-checkout-installment-form', customCardForm: false, From b2e977669a333e86667e6f1660e75a5ee766a942 Mon Sep 17 00:00:00 2001 From: Aashish Gurung <101558497+aashishgurung@users.noreply.github.com> Date: Wed, 10 Jul 2024 09:34:36 +0700 Subject: [PATCH 07/11] Add an option to enabled/disable WLB installment. (#484) Co-authored-by: Aashish --- Model/Ui/CcConfigProvider.php | 6 +++++- etc/adminhtml/system.xml | 10 ++++++++-- etc/config.xml | 1 + .../omise-offsite-installment-method.js | 18 +++++------------- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/Model/Ui/CcConfigProvider.php b/Model/Ui/CcConfigProvider.php index 98a00a541..8d0ce886a 100644 --- a/Model/Ui/CcConfigProvider.php +++ b/Model/Ui/CcConfigProvider.php @@ -6,6 +6,7 @@ use Magento\Payment\Model\CcConfig as MagentoCcConfig; use Omise\Payment\Block\Adminhtml\System\Config\CardFormCustomization\Theme; use Omise\Payment\Model\Config\Cc as OmiseCcConfig; +use Omise\Payment\Model\Config\Installment; use Omise\Payment\Model\Customer; class CcConfigProvider implements ConfigProviderInterface @@ -45,6 +46,8 @@ public function getConfig() $theme = new Theme(); $customDesign = $this->omiseCcConfig->getCardThemeConfig(); $selectedTheme = $this->omiseCcConfig->getCardTheme(); + $enableWlbInstallment = $this->omiseCcConfig->getValue('enable_wlb_installment', Installment::CODE); + return [ 'payment' => [ 'ccform' => [ @@ -58,7 +61,8 @@ public function getConfig() 'locale' => $this->omiseCcConfig->getStoreLocale(), 'secureForm' => $this->omiseCcConfig->getSecureForm(), 'formDesign' => $theme->getFormDesign($selectedTheme, $customDesign), - 'theme' => $selectedTheme + 'theme' => $selectedTheme, + 'enableWlbInstallment' => $enableWlbInstallment ], ] ]; diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 94bcc458d..89d2f5950 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -222,13 +222,19 @@ This controls the title which the user sees during checkout. payment/omise_offsite_installment/title - + + + Magento\Config\Model\Config\Source\Yesno + payment/omise_offsite_installment/enable_wlb_installment + This controls whether you want to enable WLB installments or non-WLB installments. + + payment/omise_offsite_installment/allowspecific Magento\Payment\Model\Config\Source\Allspecificcountries If not set to all, guest customers will not have a billing country and may not be able to check out. - + payment/omise_offsite_installment/specificcountry Magento\Directory\Model\Config\Source\Country diff --git a/etc/config.xml b/etc/config.xml index 6ab5366a1..90febfe66 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -45,6 +45,7 @@ authorize_capture 1 1 + 0 diff --git a/view/frontend/web/js/view/payment/method-renderer/omise-offsite-installment-method.js b/view/frontend/web/js/view/payment/method-renderer/omise-offsite-installment-method.js index 2a0a6b779..4741b4e3b 100644 --- a/view/frontend/web/js/view/payment/method-renderer/omise-offsite-installment-method.js +++ b/view/frontend/web/js/view/payment/method-renderer/omise-offsite-installment-method.js @@ -165,23 +165,14 @@ define( }, applyOmiseJsToElement: function (self, element) { - const iframeHeightMatching = { - '40px': 258, - '44px': 270, - '48px': 282, - '52px': 295, - } - const localeMatching = { en_US: 'en', ja_JP: 'ja', th_TH: 'th' } - const { theme, locale, formDesign } = window.checkoutConfig.payment.omise_cc - const { font, input, checkbox } = formDesign - let iframeElementHeight = iframeHeightMatching[input.height] - element.style.height = 500 + 'px'; + const { locale, enableWlbInstallment } = window.checkoutConfig.payment.omise_cc + element.style.height = enableWlbInstallment === '1' ? '450px' : '200px' OmiseCard.configure({ publicKey: self.getPublicKey(), @@ -191,9 +182,10 @@ define( customCardForm: false, customInstallmentForm: true, locale: localeMatching[locale] ?? 'en', - defaultPaymentMethod: 'installment' + defaultPaymentMethod: 'installment', + enableWlbInstallment: enableWlbInstallment === '1' }); - + OmiseCard.open({ onCreateSuccess: (payload) => { self.createOrder(self, payload) From f2b015f056c99c7504f077f995476f808946585b Mon Sep 17 00:00:00 2001 From: Aashish Gurung <101558497+aashishgurung@users.noreply.github.com> Date: Wed, 24 Jul 2024 11:23:49 +0700 Subject: [PATCH 08/11] Revert "Add an option to enabled/disable WLB installment. (#484)" (#486) This reverts commit b2e977669a333e86667e6f1660e75a5ee766a942. --- Model/Ui/CcConfigProvider.php | 6 +----- etc/adminhtml/system.xml | 10 ++-------- etc/config.xml | 1 - .../omise-offsite-installment-method.js | 18 +++++++++++++----- 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/Model/Ui/CcConfigProvider.php b/Model/Ui/CcConfigProvider.php index 8d0ce886a..98a00a541 100644 --- a/Model/Ui/CcConfigProvider.php +++ b/Model/Ui/CcConfigProvider.php @@ -6,7 +6,6 @@ use Magento\Payment\Model\CcConfig as MagentoCcConfig; use Omise\Payment\Block\Adminhtml\System\Config\CardFormCustomization\Theme; use Omise\Payment\Model\Config\Cc as OmiseCcConfig; -use Omise\Payment\Model\Config\Installment; use Omise\Payment\Model\Customer; class CcConfigProvider implements ConfigProviderInterface @@ -46,8 +45,6 @@ public function getConfig() $theme = new Theme(); $customDesign = $this->omiseCcConfig->getCardThemeConfig(); $selectedTheme = $this->omiseCcConfig->getCardTheme(); - $enableWlbInstallment = $this->omiseCcConfig->getValue('enable_wlb_installment', Installment::CODE); - return [ 'payment' => [ 'ccform' => [ @@ -61,8 +58,7 @@ public function getConfig() 'locale' => $this->omiseCcConfig->getStoreLocale(), 'secureForm' => $this->omiseCcConfig->getSecureForm(), 'formDesign' => $theme->getFormDesign($selectedTheme, $customDesign), - 'theme' => $selectedTheme, - 'enableWlbInstallment' => $enableWlbInstallment + 'theme' => $selectedTheme ], ] ]; diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 89d2f5950..94bcc458d 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -222,19 +222,13 @@ This controls the title which the user sees during checkout. payment/omise_offsite_installment/title - - - Magento\Config\Model\Config\Source\Yesno - payment/omise_offsite_installment/enable_wlb_installment - This controls whether you want to enable WLB installments or non-WLB installments. - - + payment/omise_offsite_installment/allowspecific Magento\Payment\Model\Config\Source\Allspecificcountries If not set to all, guest customers will not have a billing country and may not be able to check out. - + payment/omise_offsite_installment/specificcountry Magento\Directory\Model\Config\Source\Country diff --git a/etc/config.xml b/etc/config.xml index 90febfe66..6ab5366a1 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -45,7 +45,6 @@ authorize_capture 1 1 - 0 diff --git a/view/frontend/web/js/view/payment/method-renderer/omise-offsite-installment-method.js b/view/frontend/web/js/view/payment/method-renderer/omise-offsite-installment-method.js index 4741b4e3b..2a0a6b779 100644 --- a/view/frontend/web/js/view/payment/method-renderer/omise-offsite-installment-method.js +++ b/view/frontend/web/js/view/payment/method-renderer/omise-offsite-installment-method.js @@ -165,14 +165,23 @@ define( }, applyOmiseJsToElement: function (self, element) { + const iframeHeightMatching = { + '40px': 258, + '44px': 270, + '48px': 282, + '52px': 295, + } + const localeMatching = { en_US: 'en', ja_JP: 'ja', th_TH: 'th' } - const { locale, enableWlbInstallment } = window.checkoutConfig.payment.omise_cc - element.style.height = enableWlbInstallment === '1' ? '450px' : '200px' + const { theme, locale, formDesign } = window.checkoutConfig.payment.omise_cc + const { font, input, checkbox } = formDesign + let iframeElementHeight = iframeHeightMatching[input.height] + element.style.height = 500 + 'px'; OmiseCard.configure({ publicKey: self.getPublicKey(), @@ -182,10 +191,9 @@ define( customCardForm: false, customInstallmentForm: true, locale: localeMatching[locale] ?? 'en', - defaultPaymentMethod: 'installment', - enableWlbInstallment: enableWlbInstallment === '1' + defaultPaymentMethod: 'installment' }); - + OmiseCard.open({ onCreateSuccess: (payload) => { self.createOrder(self, payload) From d936ae8779ecb6b44f56d908d4f4a1d26353e408 Mon Sep 17 00:00:00 2001 From: Aashish Gurung <101558497+aashishgurung@users.noreply.github.com> Date: Wed, 24 Jul 2024 11:27:09 +0700 Subject: [PATCH 09/11] Revert "[MIT-1911] Whitelabel installment" (#487) --- Gateway/Request/APMBuilder.php | 21 +- Gateway/Request/PaymentDataBuilder.php | 12 -- Observer/InstallmentDataAssignObserver.php | 6 +- .../APMBuilders/InstallmentAPMBuilderTest.php | 43 ---- .../method-renderer/omise-cc-method.js | 152 ++++++-------- .../omise-offsite-installment-method.js | 190 +----------------- .../payment/offsite-installment-form.html | 30 +-- 7 files changed, 82 insertions(+), 372 deletions(-) delete mode 100644 Test/Unit/Gateway/Request/APMBuilders/InstallmentAPMBuilderTest.php diff --git a/Gateway/Request/APMBuilder.php b/Gateway/Request/APMBuilder.php index 9e5d98ec8..e855febf8 100644 --- a/Gateway/Request/APMBuilder.php +++ b/Gateway/Request/APMBuilder.php @@ -45,11 +45,6 @@ class APMBuilder implements BuilderInterface { - /** - * @var string - */ - const CARD = 'card'; - /** * @var string */ @@ -192,15 +187,13 @@ public function build(array $buildSubject) ]; break; case Installment::CODE: - $card = $method->getAdditionalInformation(InstallmentDataAssignObserver::CARD); - if ($card !== null) { - $paymentInfo[self::CARD] = $card; - } - - $source = $method->getAdditionalInformation(InstallmentDataAssignObserver::SOURCE); - if ($source !== null) { - $paymentInfo[self::SOURCE] = $source; - } + $installmentId = $method->getAdditionalInformation(InstallmentDataAssignObserver::OFFSITE); + $paymentInfo[self::SOURCE] = [ + self::SOURCE_TYPE => $installmentId, + self::SOURCE_INSTALLMENT_TERMS => $method->getAdditionalInformation( + InstallmentDataAssignObserver::TERMS + ) + ]; break; case Truemoney::CODE: $paymentInfo[self::SOURCE] = $this->getTruemoneySourceData($method); diff --git a/Gateway/Request/PaymentDataBuilder.php b/Gateway/Request/PaymentDataBuilder.php index 8512aa188..94496e251 100644 --- a/Gateway/Request/PaymentDataBuilder.php +++ b/Gateway/Request/PaymentDataBuilder.php @@ -115,18 +115,6 @@ public function build(array $buildSubject) $requestBody[self::METADATA]['secure_form_enabled'] = $this->ccConfig->getSecureForm(); } - if (Installment::CODE === $method->getMethod()) { - $card = $method->getAdditionalInformation(InstallmentDataAssignObserver::CARD); - if ($card !== null) { - $requestBody['card'] = $card; - } - - $source = $method->getAdditionalInformation(InstallmentDataAssignObserver::SOURCE); - if ($source !== null) { - $requestBody['source'] = $source; - } - } - return $requestBody; } diff --git a/Observer/InstallmentDataAssignObserver.php b/Observer/InstallmentDataAssignObserver.php index 09c20fa06..f49efe790 100644 --- a/Observer/InstallmentDataAssignObserver.php +++ b/Observer/InstallmentDataAssignObserver.php @@ -16,16 +16,12 @@ class InstallmentDataAssignObserver extends OffsiteDataAssignObserver * @var string */ const TERMS = 'terms'; - const CARD = 'card'; - const SOURCE = 'source'; /** * @var array */ protected $additionalInformationList = [ self::OFFSITE, - self::TERMS, - self::CARD, - self::SOURCE, + self::TERMS ]; } diff --git a/Test/Unit/Gateway/Request/APMBuilders/InstallmentAPMBuilderTest.php b/Test/Unit/Gateway/Request/APMBuilders/InstallmentAPMBuilderTest.php deleted file mode 100644 index 20c520935..000000000 --- a/Test/Unit/Gateway/Request/APMBuilders/InstallmentAPMBuilderTest.php +++ /dev/null @@ -1,43 +0,0 @@ -infoMock->method('getMethod')->willReturn(Installment::CODE); - $this->returnUrlHelper->method('create')->willReturn([ - 'url' => 'https://omise.co/complete', - 'card' => 'mock_card', - 'source' => 'mock_source', - 'token' => 'mock_token' - ]); - $this->infoMock->method('getAdditionalInformation')->willReturn('mock_source'); - - $this->builder = new APMBuilder( - $this->returnUrlHelper, - $this->config, - $this->capabilities, - new OmiseMoney(), - $this->requestHelper - ); - - $result = $this->builder->build(['payment' => new PaymentDataObject( - $this->orderMock, - $this->infoMock - )]); - - $this->assertEquals('mock_source', $result['source']); - $this->assertEquals('https://omise.co/complete', $result['return_uri']); - } -} 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..6a53345fc 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 @@ -8,9 +8,7 @@ define( 'Magento_Payment/js/model/credit-card-validation/validator', 'Magento_Checkout/js/model/full-screen-loader', 'Magento_Checkout/js/action/redirect-on-success', - 'Magento_Checkout/js/model/quote', - 'Magento_Checkout/js/checkout-data', - 'Magento_Checkout/js/action/select-payment-method' + 'Magento_Checkout/js/model/quote' ], function ( ko, @@ -21,9 +19,7 @@ define( validator, fullScreenLoader, redirectOnSuccessAction, - quote, - checkoutData, - selectPaymentMethodAction + quote ) { 'use strict' @@ -89,98 +85,80 @@ define( return this }, - selectPaymentMethod: function () { - this._super(); - selectPaymentMethodAction(this.getData()); - checkoutData.setSelectedPaymentMethod(this.item.method); - OmiseCard.destroy(); - setTimeout(() => { - if (this.isSecureForm()) { - 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 () { + const self = this ko.bindingHandlers.omiseCardForm = { - init: (element) => this.applyOmiseJsToElement(this, element) - } - }, - - applyOmiseJsToElement: function (self, element) { - const hideRememberCard = !self.isCustomerLoggedIn() - const iframeHeightMatching = { - '40px': 258, - '44px': 270, - '48px': 282, - '52px': 295, - } - - const localeMatching = { - en_US: 'en', - ja_JP: 'ja', - th_TH: 'th' - } - - const { theme, locale, formDesign } = window.checkoutConfig.payment.omise_cc - const { font, input, checkbox } = formDesign - let iframeElementHeight = iframeHeightMatching[input.height] - if (hideRememberCard) { - iframeElementHeight = iframeElementHeight - 25 - } - element.style.height = iframeElementHeight + 'px' - - OmiseCard.configure({ - publicKey: self.getPublicKey(), - element, - locale: localeMatching[locale] ?? 'en', - customCardForm: true, - customCardFormTheme: theme, - style: { - fontFamily: font.name, - fontSize: font.size, - input: { - height: input.height, - borderRadius: input.border_radius, - border: `1.2px solid ${input.border_color}`, - focusBorder: `1.2px solid ${input.active_border_color}`, - background: input.background_color, - color: input.text_color, - labelColor: input.label_color, - placeholderColor: input.placeholder_color, - }, - checkBox: { - textColor: checkbox.text_color, - themeColor: checkbox.theme_color, - border: `1.2px solid ${input.border_color}`, + init: function (element) { + const hideRememberCard = !self.isCustomerLoggedIn() + const iframeHeightMatching = { + '40px': 258, + '44px': 270, + '48px': 282, + '52px': 295, } - }, - customCardFormHideRememberCard: hideRememberCard - }) - OmiseCard.open({ - onCreateTokenSuccess: (payload) => { - self.createOrder(self, payload) - }, - onError: (err) => { - if (err.length > 0) { - self.omiseCardError(err.length == 1 ? err[0] : 'Please enter required card information.') + const localeMatching = { + en_US: 'en', + ja_JP: 'ja', + th_TH: 'th' } - else { - self.omiseCardError('Something went wrong. Please refresh the page and try again.') + + const { theme, locale, formDesign } = window.checkoutConfig.payment.omise_cc + const { font, input, checkbox } = formDesign + let iframeElementHeight = iframeHeightMatching[input.height] + if (hideRememberCard) { + iframeElementHeight = iframeElementHeight - 25 } - self.stopPerformingPlaceOrderAction() + element.style.height = iframeElementHeight + 'px' + + OmiseCard.configure({ + publicKey: self.getPublicKey(), + element, + locale: localeMatching[locale] ?? 'en', + customCardForm: true, + customCardFormTheme: theme, + style: { + fontFamily: font.name, + fontSize: font.size, + input: { + height: input.height, + borderRadius: input.border_radius, + border: `1.2px solid ${input.border_color}`, + focusBorder: `1.2px solid ${input.active_border_color}`, + background: input.background_color, + color: input.text_color, + labelColor: input.label_color, + placeholderColor: input.placeholder_color, + }, + checkBox: { + textColor: checkbox.text_color, + themeColor: checkbox.theme_color, + border: `1.2px solid ${input.border_color}`, + } + }, + customCardFormHideRememberCard: hideRememberCard + }) + + OmiseCard.open({ + onCreateTokenSuccess: (payload) => { + self.createOrder(self, payload) + }, + onError: (err) => { + if (err.length > 0) { + self.omiseCardError(err.length == 1 ? err[0] : 'Please enter required card information.') + } + else { + self.omiseCardError('Something went wrong. Please refresh the page and try again.') + } + self.stopPerformingPlaceOrderAction() + } + }) } - }) + } }, createOrder: function (self, payload) { diff --git a/view/frontend/web/js/view/payment/method-renderer/omise-offsite-installment-method.js b/view/frontend/web/js/view/payment/method-renderer/omise-offsite-installment-method.js index 2a0a6b779..aa5da1611 100644 --- a/view/frontend/web/js/view/payment/method-renderer/omise-offsite-installment-method.js +++ b/view/frontend/web/js/view/payment/method-renderer/omise-offsite-installment-method.js @@ -6,10 +6,6 @@ define( 'Magento_Checkout/js/view/payment/default', 'Magento_Checkout/js/model/quote', 'Magento_Catalog/js/price-utils', - 'Magento_Checkout/js/model/full-screen-loader', - 'mage/storage', - 'Magento_Checkout/js/checkout-data', - 'Magento_Checkout/js/action/select-payment-method' ], function ( $, @@ -17,11 +13,7 @@ define( Base, Component, quote, - priceUtils, - fullScreenLoader, - storage, - checkoutData, - selectPaymentMethodAction + priceUtils ) { 'use strict'; const CAPTION = $.mage.__('Choose number of monthly payments'); @@ -91,28 +83,15 @@ define( }, ] - function convertToCents(dollarAmount) { - return Math.round(parseFloat(dollarAmount) * 100); - } - return Component.extend(Base).extend({ defaults: { template: 'Omise_Payment/payment/offsite-installment-form' }, code: 'omise_offsite_installment', restrictedToCurrencies: ['thb', 'myr'], - isPlaceOrderActionAllowed: ko.observable(quote.billingAddress() != null), + capabilities: null, - billingAddressCountries: ["US", "GB", "CA"], - /** - * Get Omise public key - * - * @return {string} - */ - getPublicKey: function () { - return window.checkoutConfig.payment.omise_cc.publicKey - }, /** * Initiate observable fields * @@ -131,137 +110,14 @@ define( 'installmentTermsUOB', 'installmentTermsMBB', 'installmentTermsTTB', - 'omiseInstallmentError', - 'omiseInstallmentToken', - 'omiseInstallmentSource', ]); this.capabilities = checkoutConfig.omise_payment_list[this.code]; // filter provider for checkout page this.providers = this.get_available_providers() - this.openOmiseJs(); - return this; - }, - - selectPaymentMethod: function () { - this._super(); - selectPaymentMethodAction(this.getData()); - checkoutData.setSelectedPaymentMethod(this.item.method); - OmiseCard.destroy(); - setTimeout(() => { - const element = document.querySelector('.omise-installment-form') - if(element) { - this.applyOmiseJsToElement(this, element); - } - }, 300); - return true - }, - - openOmiseJs: function () { - ko.bindingHandlers.omiseInstallmentForm = { - init: (element) => this.applyOmiseJsToElement(this, element) - } - }, - - applyOmiseJsToElement: function (self, element) { - const iframeHeightMatching = { - '40px': 258, - '44px': 270, - '48px': 282, - '52px': 295, - } - - const localeMatching = { - en_US: 'en', - ja_JP: 'ja', - th_TH: 'th' - } - - const { theme, locale, formDesign } = window.checkoutConfig.payment.omise_cc - const { font, input, checkbox } = formDesign - let iframeElementHeight = iframeHeightMatching[input.height] - element.style.height = 500 + 'px'; - - OmiseCard.configure({ - publicKey: self.getPublicKey(), - amount: convertToCents(quote.totals().grand_total), - element, - iframeAppId: 'omise-checkout-installment-form', - customCardForm: false, - customInstallmentForm: true, - locale: localeMatching[locale] ?? 'en', - defaultPaymentMethod: 'installment' - }); - - OmiseCard.open({ - onCreateSuccess: (payload) => { - self.createOrder(self, payload) - }, - onError: (err) => { - if (err.length > 0) { - self.omiseInstallmentError(err.length == 1 ? err[0] : 'Please enter required card information.') - } - else { - self.omiseInstallmentError('Something went wrong. Please refresh the page and try again.') - } - self.stopPerformingPlaceOrderAction() - } - }); - }, - - createOrder: function (self, payload) { - self.omiseInstallmentToken(payload.token) - self.omiseInstallmentSource(payload.source) - const failHandler = self.buildFailHandler(this, 300) - self.getPlaceOrderDeferredObject() - .fail(failHandler) - .done((order_id) => { - let serviceUrl = self.getMagentoReturnUrl(order_id) - storage.get(serviceUrl, false) - .fail(failHandler) - .done(function (response) { - if (response) { - $.mage.redirect(response.authorize_uri) - } else { - failHandler(response) - } - }) - }) - }, - - /** - * Hook the placeOrder function. - * Original source: placeOrder(data, event); @ module-checkout/view/frontend/web/js/view/payment/default.js - * - * @return {boolean} - */ - placeOrder: function (data, event) { - this.omiseInstallmentError(null) - event && event.preventDefault() - - if (typeof Omise === 'undefined') { - alert($.mage.__('Unable to process the payment, loading the external card processing library is failed. Please contact the merchant.')) - return false - } - - this.generateTokenWithEmbeddedFormAndPerformPlaceOrderAction() - return true - }, - /** - * Generate Omise token with embedded form before proceed the placeOrder process. - * - * @return {void} - */ - generateTokenWithEmbeddedFormAndPerformPlaceOrderAction: function () { - this.startPerformingPlaceOrderAction() - let billingAddress = {} - let selectedBillingAddress = quote.billingAddress() - if (this.billingAddressCountries.indexOf(selectedBillingAddress.countryId) > -1) { - Object.assign(billingAddress, this.getSelectedTokenBillingAddress(selectedBillingAddress)) - } - OmiseCard.requestCardToken(billingAddress) + return this; }, /** @@ -459,8 +315,8 @@ define( return { 'method': this.item.method, 'additional_data': { - 'card': this.omiseInstallmentToken(), - 'source': this.omiseInstallmentSource() + 'offsite': this.omiseOffsite(), + 'terms': this.getTerms() } }; }, @@ -524,42 +380,8 @@ define( } } ))) - }, - - /** - * Start performing place order action, - * by disable a place order button and show full screen loader component. - */ - startPerformingPlaceOrderAction: function () { - this.isPlaceOrderActionAllowed(false) - fullScreenLoader.startLoader() - }, - - /** - * Stop performing place order action, - * by disable a place order button and show full screen loader component. - */ - stopPerformingPlaceOrderAction: function () { - fullScreenLoader.stopLoader() - this.isPlaceOrderActionAllowed(true) - }, - - getSelectedTokenBillingAddress: function (selectedBillingAddress) { - let address = { - state: selectedBillingAddress.region, - postal_code: selectedBillingAddress.postcode, - phone_number: selectedBillingAddress.telephone, - country: selectedBillingAddress.countryId, - city: selectedBillingAddress.city, - street1: selectedBillingAddress.street[0] - } - - if (selectedBillingAddress.street[1]) { - address.street2 = selectedBillingAddress.street[1] - } - - return address } + }); } ); diff --git a/view/frontend/web/template/payment/offsite-installment-form.html b/view/frontend/web/template/payment/offsite-installment-form.html index e16d0d7ce..50c004e35 100644 --- a/view/frontend/web/template/payment/offsite-installment-form.html +++ b/view/frontend/web/template/payment/offsite-installment-form.html @@ -39,17 +39,8 @@ - - -
- -
- - - - - -
+
@@ -120,7 +96,7 @@ click: placeOrder, attr: {title: $t('Place Order')}, css: {disabled: !isPlaceOrderActionAllowed()}, - enable: (getCode() == isChecked())"> + enable: (getCode() == isChecked()) && omiseOffsite() && getTerms() ">
From 46b850681fc9f1f1c2427b5ba5bfae12159f2594 Mon Sep 17 00:00:00 2001 From: Aashish Gurung <101558497+aashishgurung@users.noreply.github.com> Date: Wed, 24 Jul 2024 14:28:28 +0700 Subject: [PATCH 10/11] Resolve dynamic property deprecation error for PHP 8.2 and 8.3 (#485) * Add AllowDynamicProperties attribute to resolve deprecation error for dynamic property. * Update omise-php version * Add AllowDynamicProperties in Model/Data/Email.php file. * Add AllowDynamicProperties to some more files. --- Block/Adminhtml/System/Config/Fieldset/Payment.php | 1 + Block/Adminhtml/System/Config/Form/Field/Webhook.php | 1 + Block/Checkout/Onepage/Success/AdditionalInformation.php | 1 + Controller/Adminhtml/Ordersync/Index.php | 1 + Controller/Callback/Offsite.php | 1 + Controller/Callback/Threedsecure.php | 1 + Controller/Cards/DeleteAction.php | 1 + Controller/Cards/ListAction.php | 1 + Controller/Payment/Complete.php | 1 + Cron/OrderSyncStatus.php | 1 + Helper/ReturnUrlHelper.php | 1 + Model/Api/Customer.php | 1 + Model/Api/Event.php | 1 + Model/Config/Config.php | 1 + Model/Data/Email.php | 1 + Model/RefundSyncStatus.php | 1 + Model/SyncStatus.php | 1 + Observer/WebhookObserver/WebhookObserver.php | 1 + Plugin/ConfigSectionPaymentPlugin.php | 1 + Service/CreditMemoService.php | 1 + composer.json | 2 +- 21 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Block/Adminhtml/System/Config/Fieldset/Payment.php b/Block/Adminhtml/System/Config/Fieldset/Payment.php index 0162ac465..875c30a8f 100644 --- a/Block/Adminhtml/System/Config/Fieldset/Payment.php +++ b/Block/Adminhtml/System/Config/Fieldset/Payment.php @@ -4,6 +4,7 @@ /** * Fieldset renderer for Omise solution */ +#[\AllowDynamicProperties] class Payment extends \Magento\Config\Block\System\Config\Form\Fieldset { /** diff --git a/Block/Adminhtml/System/Config/Form/Field/Webhook.php b/Block/Adminhtml/System/Config/Form/Field/Webhook.php index 524ce938e..cef5a7d73 100644 --- a/Block/Adminhtml/System/Config/Form/Field/Webhook.php +++ b/Block/Adminhtml/System/Config/Form/Field/Webhook.php @@ -8,6 +8,7 @@ use Magento\Store\Model\StoreManagerInterface; use Magento\Framework\App\Request\Http; +#[\AllowDynamicProperties] class Webhook extends Field { /** diff --git a/Block/Checkout/Onepage/Success/AdditionalInformation.php b/Block/Checkout/Onepage/Success/AdditionalInformation.php index f457ebb59..c861e0dec 100644 --- a/Block/Checkout/Onepage/Success/AdditionalInformation.php +++ b/Block/Checkout/Onepage/Success/AdditionalInformation.php @@ -1,6 +1,7 @@ =5.6", "magento/magento-composer-installer": ">=0.3.0", - "omise/omise-php": "2.16.1" + "omise/omise-php": "2.18.0" }, "require-dev": { "phpunit/phpunit": "^5.7 || ^9.5", From 2af112aa8c021d6427f00a91401d829579fdc03c Mon Sep 17 00:00:00 2001 From: Aashish Date: Wed, 24 Jul 2024 15:01:02 +0700 Subject: [PATCH 11/11] Update metadata for v3.8.0 --- CHANGELOG.md | 3 +++ composer.json | 2 +- etc/module.xml | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6465167a7..c2bab26ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # CHANGELOG +## [v3.8.0 _(Jul, 24, 2024)_](https://github.com/omise/omise-magento/releases/tag/v3.8.0) +- Resolve dynamic property deprecation error for PHP 8.2 and above (PR: [#485](https://github.com/omise/omise-magento/pull/485)) + ## [v3.7.1 _(May, 8, 2024)_](https://github.com/omise/omise-magento/releases/tag/v3.7.1) - Fixed minimum installment amount for installment_bay and installment_kbank (PR: [#479](https://github.com/omise/omise-magento/pull/479)) - Remove OCBC PAO (PR: [#480](https://github.com/omise/omise-magento/pull/480)) diff --git a/composer.json b/composer.json index 8c2da1af9..d623b0616 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "email": "support@omise.co" } ], - "version": "3.7.1", + "version": "3.8.0", "minimum-stability": "stable", "type": "magento2-module", "license": "MIT", diff --git a/etc/module.xml b/etc/module.xml index 246d3d644..67af4b33b 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,6 +1,6 @@ - +