| 1 |
|
| 2 |
import { __ } from '@wordpress/i18n'; |
| 3 |
import { registerPaymentMethod } from '@woocommerce/blocks-registry'; |
| 4 |
import { decodeEntities } from '@wordpress/html-entities'; |
| 5 |
import { getSetting } from '@woocommerce/settings'; |
| 6 |
import IntegratedPayment from "./wc-payplug-integratedPayment-blocks"; |
| 7 |
import Popup from "./wc-payplug-popup-blocks"; |
| 8 |
const settings = getSetting( 'payplug_data', {} ); |
| 9 |
const defaultLabel = __('Gateway method title', 'payplug'); |
| 10 |
const label = decodeEntities( settings?.title ) || defaultLabel; |
| 11 |
|
| 12 |
/** |
| 13 |
* Content component |
| 14 |
*/ |
| 15 |
const Content = (props) => { |
| 16 |
|
| 17 |
if(settings?.IP === true){ |
| 18 |
return ( |
| 19 |
<IntegratedPayment settings={settings} props={props} /> |
| 20 |
) |
| 21 |
} |
| 22 |
|
| 23 |
if(settings?.popup === true){ |
| 24 |
return ( |
| 25 |
<Popup settings={settings} props={props} /> |
| 26 |
) |
| 27 |
} |
| 28 |
|
| 29 |
return window.wp.htmlEntities.decodeEntities( settings?.description || '' ); |
| 30 |
|
| 31 |
}; |
| 32 |
/** |
| 33 |
* Label component |
| 34 |
* |
| 35 |
*/ |
| 36 |
const Label = () => { |
| 37 |
return ( |
| 38 |
<span style={{ width: '100%' }}> |
| 39 |
{label} |
| 40 |
<Icon /> |
| 41 |
</span> |
| 42 |
) |
| 43 |
} |
| 44 |
|
| 45 |
const Icon = () => { |
| 46 |
return ( |
| 47 |
<img src={settings?.icon.src} alt={settings?.icon.icon_alt} className="payplug-payment-icon" style={{float: 'right'}}/> |
| 48 |
) |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Payplug payment method config object. |
| 53 |
*/ |
| 54 |
const Payplug = { |
| 55 |
name: "payplug", |
| 56 |
label: <Label />, |
| 57 |
content: <Content />, |
| 58 |
edit: <Content />, |
| 59 |
canMakePayment: () => true, |
| 60 |
ariaLabel: label, |
| 61 |
supports: { |
| 62 |
features: settings.supports, |
| 63 |
showSaveOption: settings?.showSaveOption && settings?.IP, |
| 64 |
showSavedCards: settings.showSaveOption ?? false |
| 65 |
}, |
| 66 |
}; |
| 67 |
|
| 68 |
registerPaymentMethod( Payplug ); |
| 69 |
|
| 70 |
|