Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/omise/omise-magento into…
Browse files Browse the repository at this point in the history
… support_php_8.2_8.3
  • Loading branch information
aashishgurung committed Jul 24, 2024
2 parents 6ddf508 + d936ae8 commit eb864ed
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 378 deletions.
21 changes: 7 additions & 14 deletions Gateway/Request/APMBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@

class APMBuilder implements BuilderInterface
{
/**
* @var string
*/
const CARD = 'card';

/**
* @var string
*/
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 0 additions & 12 deletions Gateway/Request/PaymentDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 1 addition & 5 deletions Model/Ui/CcConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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' => [
Expand All @@ -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
],
]
];
Expand Down
6 changes: 1 addition & 5 deletions Observer/InstallmentDataAssignObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
];
}

This file was deleted.

10 changes: 2 additions & 8 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -222,19 +222,13 @@
<comment>This controls the title which the user sees during checkout.</comment>
<config_path>payment/omise_offsite_installment/title</config_path>
</field>
<field id="enable_wlb_installment" translate="label" type="select" sortOrder="271" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enable WLB installments</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>payment/omise_offsite_installment/enable_wlb_installment</config_path>
<comment>This controls whether you want to enable WLB installments or non-WLB installments.</comment>
</field>
<field id="allowspecific" translate="label comment" type="select" sortOrder="272" showInDefault="1" showInWebsite="1" showInStore="1">
<field id="allowspecific" translate="label comment" type="select" sortOrder="271" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Allowed Countries</label>
<config_path>payment/omise_offsite_installment/allowspecific</config_path>
<source_model>Magento\Payment\Model\Config\Source\Allspecificcountries</source_model>
<comment>If not set to all, guest customers will not have a billing country and may not be able to check out.</comment>
</field>
<field id="specificcountry" translate="label" type="multiselect" sortOrder="273" showInDefault="1" showInWebsite="1" showInStore="1">
<field id="specificcountry" translate="label" type="multiselect" sortOrder="272" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Payment from specific countries</label>
<config_path>payment/omise_offsite_installment/specificcountry</config_path>
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
Expand Down
1 change: 0 additions & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
<payment_action>authorize_capture</payment_action>
<can_refund_partial_per_invoice>1</can_refund_partial_per_invoice>
<can_refund>1</can_refund>
<enable_wlb_installment>0</enable_wlb_installment>
</omise_offsite_internetbanking>

<omise_offsite_alipay>
Expand Down
152 changes: 65 additions & 87 deletions view/frontend/web/js/view/payment/method-renderer/omise-cc-method.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -21,9 +19,7 @@ define(
validator,
fullScreenLoader,
redirectOnSuccessAction,
quote,
checkoutData,
selectPaymentMethodAction
quote
) {
'use strict'

Expand Down Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit eb864ed

Please sign in to comment.