| 1 |
(function () { |
| 2 |
registerVippsRecurringGateway() |
| 3 |
}()); |
| 4 |
|
| 5 |
function registerVippsRecurringGateway() { |
| 6 |
const {decodeEntities} = window.wp.htmlEntities; |
| 7 |
const {getSetting} = window.wc.wcSettings; |
| 8 |
const {registerPaymentMethod} = window.wc.wcBlocksRegistry; |
| 9 |
const {applyFilters} = window.wp.hooks; |
| 10 |
|
| 11 |
const settings = getSetting('vipps_recurring_data', {}); |
| 12 |
const ariaLabel = decodeEntities(settings.title); |
| 13 |
const logo = settings.logo; |
| 14 |
|
| 15 |
const Content = () => { |
| 16 |
const content = React.createElement('div', null, decodeEntities(settings.description || '')); |
| 17 |
return applyFilters('wc_vipps_recurring_checkout_description', content, settings); |
| 18 |
}; |
| 19 |
|
| 20 |
const Label = props => { |
| 21 |
const { PaymentMethodLabel } = props.components; |
| 22 |
|
| 23 |
const title = decodeEntities(settings.title || '') |
| 24 |
let label; |
| 25 |
|
| 26 |
if (logo && logo.length > 0) { |
| 27 |
label = React.createElement('img', { alt: title, title: title, className: 'vipps-recurring-payment-logo', src: logo }); |
| 28 |
} else { |
| 29 |
label = React.createElement(PaymentMethodLabel, { |
| 30 |
text: React.createElement('span', null, title) |
| 31 |
}); |
| 32 |
} |
| 33 |
|
| 34 |
return applyFilters('wc_vipps_recurring_checkout_label', label, settings); |
| 35 |
}; |
| 36 |
|
| 37 |
const canMakePayment = () => { |
| 38 |
return applyFilters('wc_vipps_recurring_checkout_show_gateway', true, settings); |
| 39 |
}; |
| 40 |
|
| 41 |
/** |
| 42 |
* Vipps/MobilePay Recurring payment method config object. |
| 43 |
*/ |
| 44 |
const paymentMethod = { |
| 45 |
name: 'vipps_recurring', |
| 46 |
// translators: %s: brand name, Vipps or MobilePay |
| 47 |
placeOrderButtonLabel: wp.i18n.sprintf(wp.i18n.__("Continue with %s", 'woo-vipps'), settings.title), |
| 48 |
supports: { |
| 49 |
features: settings.supports || [] |
| 50 |
}, |
| 51 |
label: React.createElement(Label, null), |
| 52 |
content: React.createElement(Content, null), |
| 53 |
edit: React.createElement(Content, null), |
| 54 |
icons: null, |
| 55 |
canMakePayment, |
| 56 |
ariaLabel |
| 57 |
}; |
| 58 |
|
| 59 |
registerPaymentMethod(paymentMethod); |
| 60 |
} |
| 61 |
|