-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from degica/fix/pluginConflicts3.1.0
Fix plugin conflicts in 3.1.0
- Loading branch information
Showing
5 changed files
with
115 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
* | ||
* @extends WC_Payment_Gateway | ||
* | ||
* @version 3.1.0 | ||
* @version 3.1.2 | ||
* | ||
* @author Komoju | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
* | ||
* @extends WC_Settings_Page | ||
* | ||
* @version 3.1.0 | ||
* @version 3.1.2 | ||
* | ||
* @author Komoju | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,113 @@ | ||
const { useEffect, useCallback, useRef, createElement } = window.wp.element; | ||
const KomojuPaymentModule = (() => { | ||
const { useEffect, useCallback, useRef, createElement } = window.wp.element; | ||
|
||
function registerPaymentMethod(paymentMethod) { | ||
let name = `${paymentMethod.id}` | ||
const settings = window.wc.wcSettings.getSetting(`${name}_data`, {}); | ||
function registerPaymentMethod(paymentMethod) { | ||
let name = `${paymentMethod.id}` | ||
const settings = window.wc.wcSettings.getSetting(`${name}_data`, {}); | ||
|
||
const komojuFields = createElement('komoju-fields', { | ||
'token': '', | ||
'name': 'komoju_payment_token', | ||
'komoju-api': settings.komojuApi, | ||
'publishable-key': settings.publishableKey, | ||
'session': settings.session, | ||
'payment-type': settings.paymentType, | ||
'locale': settings.locale, | ||
style: { display: 'none' }, | ||
}); | ||
const komojuFields = createElement('komoju-fields', { | ||
'token': '', | ||
'name': 'komoju_payment_token', | ||
'komoju-api': settings.komojuApi, | ||
'publishable-key': settings.publishableKey, | ||
'session': settings.session, | ||
'payment-type': settings.paymentType, | ||
'locale': settings.locale, | ||
style: { display: 'none' }, | ||
}); | ||
|
||
const label = createElement('div', { | ||
style: { display: 'block', alignItems: 'center', justifyContent: 'center', width: '100%' } | ||
}, | ||
window.wp.htmlEntities.decodeEntities(settings.title || window.wp.i18n.__('NULL GATEWAY', 'test_komoju_gateway')), | ||
settings.icon ? | ||
createElement('img', { | ||
src: settings.icon, | ||
alt: settings.title || 'Payment Method Icon', | ||
style: { display: 'flex', alignItems: 'center', justifyContent: 'center', marginLeft: '10px' } | ||
}) : null, | ||
komojuFields | ||
); | ||
const label = createElement('div', { | ||
style: { display: 'block', alignItems: 'center', justifyContent: 'center', width: '100%' } | ||
}, | ||
window.wp.htmlEntities.decodeEntities(settings.title || window.wp.i18n.__('NULL GATEWAY', 'test_komoju_gateway')), | ||
settings.icon ? | ||
createElement('img', { | ||
src: settings.icon, | ||
alt: settings.title || 'Payment Method Icon', | ||
style: { display: 'flex', alignItems: 'center', justifyContent: 'center', marginLeft: '10px' } | ||
}) : null, | ||
komojuFields | ||
); | ||
|
||
const KomojuComponent = ({ activePaymentMethod, emitResponse, eventRegistration }) => { | ||
const { onPaymentSetup } = eventRegistration; | ||
const komojuFieldEnabledMethods = ['komoju_credit_card', 'komoju_konbini', 'komoju_bank_transfer'] | ||
const KomojuComponent = ({ activePaymentMethod, emitResponse, eventRegistration }) => { | ||
const { onPaymentSetup } = eventRegistration; | ||
const komojuFieldEnabledMethods = ['komoju_credit_card', 'komoju_konbini', 'komoju_bank_transfer'] | ||
|
||
useEffect(() => { | ||
const komojuField = document.querySelector(`komoju-fields[payment-type='${paymentMethod.paymentType}']`); | ||
komojuField.style.display = 'block'; | ||
useEffect(() => { | ||
const komojuField = document.querySelector(`komoju-fields[payment-type='${paymentMethod.paymentType}']`); | ||
komojuField.style.display = 'block'; | ||
|
||
const unsubscribe = onPaymentSetup(async () => { | ||
if (paymentMethod.id != activePaymentMethod) return; | ||
if (!komojuFieldEnabledMethods.includes(paymentMethod.id)) return; | ||
const unsubscribe = onPaymentSetup(async () => { | ||
if (paymentMethod.id != activePaymentMethod) return; | ||
if (!komojuFieldEnabledMethods.includes(paymentMethod.id)) return; | ||
|
||
if (!(komojuField || typeof komojuField.submit === 'function')) { | ||
return { | ||
type: emitResponse.responseTypes.ERROR, | ||
message: 'There was an error', | ||
}; | ||
} | ||
if (!(komojuField || typeof komojuField.submit === 'function')) { | ||
return { | ||
type: emitResponse.responseTypes.ERROR, | ||
message: 'There was an error', | ||
}; | ||
} | ||
|
||
function submitFields(fields) { | ||
return new Promise(async (resolve, reject) => { | ||
fields.addEventListener("komoju-invalid", reject); | ||
const token = await fields.submit(); | ||
fields.removeEventListener("komoju-invalid", reject); | ||
if (token) resolve(token); | ||
}); | ||
} | ||
function submitFields(fields) { | ||
return new Promise(async (resolve, reject) => { | ||
fields.addEventListener("komoju-invalid", reject); | ||
const token = await fields.submit(); | ||
fields.removeEventListener("komoju-invalid", reject); | ||
if (token) resolve(token); | ||
}); | ||
} | ||
|
||
try { | ||
const token = await submitFields(komojuField); | ||
return { | ||
type: emitResponse.responseTypes.SUCCESS, | ||
meta: { | ||
paymentMethodData: { | ||
komoju_payment_token: token.id | ||
try { | ||
const token = await submitFields(komojuField); | ||
return { | ||
type: emitResponse.responseTypes.SUCCESS, | ||
meta: { | ||
paymentMethodData: { | ||
komoju_payment_token: token.id | ||
}, | ||
}, | ||
}, | ||
}; | ||
} catch (e) { | ||
return { | ||
type: emitResponse.responseTypes.ERROR, | ||
message: e.detail.errors[0].message, | ||
}; | ||
} | ||
}); | ||
}; | ||
} catch (e) { | ||
return { | ||
type: emitResponse.responseTypes.ERROR, | ||
message: e.detail.errors[0].message, | ||
}; | ||
} | ||
}); | ||
|
||
return () => { | ||
komojuField.style.display = 'none'; | ||
unsubscribe(); | ||
}; | ||
}, [ | ||
activePaymentMethod, | ||
emitResponse.responseTypes.ERROR, | ||
emitResponse.responseTypes.SUCCESS | ||
]); | ||
}; | ||
return () => { | ||
komojuField.style.display = 'none'; | ||
unsubscribe(); | ||
}; | ||
}, [ | ||
activePaymentMethod, | ||
emitResponse.responseTypes.ERROR, | ||
emitResponse.responseTypes.SUCCESS | ||
]); | ||
}; | ||
|
||
const Block_Gateway = { | ||
name: name, | ||
label: label, | ||
content: createElement(KomojuComponent, null), | ||
edit: createElement(KomojuComponent, null), | ||
canMakePayment: () => true, | ||
ariaLabel: settings.title || 'Payment Method', | ||
supports: { | ||
features: settings.supports || ['products'], | ||
}, | ||
const Block_Gateway = { | ||
name: name, | ||
label: label, | ||
content: createElement(KomojuComponent, null), | ||
edit: createElement(KomojuComponent, null), | ||
canMakePayment: () => true, | ||
ariaLabel: settings.title || 'Payment Method', | ||
supports: { | ||
features: settings.supports || ['products'], | ||
}, | ||
}; | ||
window.wc.wcBlocksRegistry.registerPaymentMethod(Block_Gateway); | ||
} | ||
|
||
return { | ||
init: () => { | ||
const paymentMethodData = window.wc.wcSettings.getSetting('paymentMethodData', {}); | ||
Object.values(paymentMethodData).forEach((value) => { | ||
registerPaymentMethod(value); | ||
}); | ||
} | ||
}; | ||
window.wc.wcBlocksRegistry.registerPaymentMethod(Block_Gateway); | ||
} | ||
})(); | ||
|
||
paymentMethodData = window.wc.wcSettings.getSetting('paymentMethodData', {}); | ||
Object.values(paymentMethodData).forEach((value) => { | ||
registerPaymentMethod(value); | ||
}); | ||
KomojuPaymentModule.init(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters