Skip to content

Commit

Permalink
Show button only if enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaymo committed Oct 16, 2024
1 parent 84e1681 commit 673d4b9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
9 changes: 6 additions & 3 deletions resources/js/mollieBlockIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,24 @@ import ApplePayButtonComponent from './blocks/ApplePayButtonComponent'
gatewayData.forEach(item => {
let register = () => registerPaymentMethod(molliePaymentMethod(useEffect, ajaxUrl, filters, gatewayData, availableGateways, item, jQuery, requiredFields, isCompanyFieldVisible, isPhoneFieldVisible));
if (item.name === 'mollie_wc_gateway_applepay' && !isBlockEditor) {
const isExpressEnabled = item.isExpressEnabled;
if ((isAppleSession && window.ApplePaySession.canMakePayments())) {
register();
if (isExpressEnabled !== true) {
return;
}
const {registerExpressPaymentMethod} = wc.wcBlocksRegistry;
registerExpressPaymentMethod({
name: 'mollie_wc_gateway_applepay_express',
content: <ApplePayButtonComponent />,
edit: <ApplePayButtonComponent />,
content: < ApplePayButtonComponent />,
edit: < ApplePayButtonComponent />,
ariaLabel: 'Apple Pay',
canMakePayment: () => true,
paymentMethodId: 'mollie_wc_gateway_applepay',
supports: {
features: ['products'],
},
})

}
return;
}
Expand Down
35 changes: 18 additions & 17 deletions src/Assets/MollieCheckoutBlocksSupport.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,26 +113,26 @@ public static function gatewayDataForWCBlocks(Data $dataService, array $gatewayI
$isSepaEnabled = isset($gatewayInstances['mollie_wc_gateway_directdebit']) && $gatewayInstances['mollie_wc_gateway_directdebit']->enabled === 'yes';
/** @var MolliePaymentGateway $gateway */
foreach ($gatewayInstances as $gatewayKey => $gateway) {
$gatewayId = is_string($gateway->paymentMethod()->getProperty('id')) ? $gateway->paymentMethod(
)->getProperty('id') : "";
$method = $gateway->paymentMethod();
$gatewayId = is_string($method->getProperty('id')) ? $method->getProperty('id') : "";

if ($gateway->enabled !== 'yes' || ($gatewayId === 'directdebit' && !is_admin())) {
continue;
}
$content = $gateway->paymentMethod()->getProcessedDescriptionForBlock();
$content = $method->getProcessedDescriptionForBlock();
$issuers = false;
if ($gateway->paymentMethod()->getProperty('paymentFields') === true) {
$paymentFieldsService = $gateway->paymentMethod()->paymentFieldsService();
$paymentFieldsService->setStrategy($gateway->paymentMethod());
$issuers = $gateway->paymentMethod()->paymentFieldsService()->getStrategyMarkup($gateway);
if ($method->getProperty('paymentFields') === true) {
$paymentFieldsService = $method->paymentFieldsService();
$paymentFieldsService->setStrategy($method);
$issuers = $method->paymentFieldsService()->getStrategyMarkup($gateway);
}
if ($gatewayId === 'creditcard') {
$content .= $issuers;
$issuers = false;
}
$title = $gateway->paymentMethod()->title();
$title = $method->title();
$labelMarkup = "<span style='margin-right: 1em'>{$title}</span>{$gateway->icon}";
$hasSurcharge = $gateway->paymentMethod()->hasSurcharge();
$hasSurcharge = $method->hasSurcharge();
$countryCodes = [
'BE' => '+32xxxxxxxxx',
'NL' => '+316xxxxxxxx',
Expand All @@ -155,15 +155,16 @@ public static function gatewayDataForWCBlocks(Data $dataService, array $gatewayI
'edit' => $content,
'paymentMethodId' => $gatewayKey,
'allowedCountries' => is_array(
$gateway->paymentMethod()->getProperty('allowed_countries')
) ? $gateway->paymentMethod()->getProperty('allowed_countries') : [],
'ariaLabel' => $gateway->paymentMethod()->getProperty('defaultDescription'),
'supports' => self::gatewaySupportsFeatures($gateway->paymentMethod(), $isSepaEnabled),
'errorMessage' => $gateway->paymentMethod()->getProperty('errorMessage'),
'companyPlaceholder' => $gateway->paymentMethod()->getProperty('companyPlaceholder'),
'phoneLabel' => $gateway->paymentMethod()->getProperty('phoneLabel'),
$method->getProperty('allowed_countries')
) ? $method->getProperty('allowed_countries') : [],
'ariaLabel' => $method->getProperty('defaultDescription'),
'supports' => self::gatewaySupportsFeatures($method, $isSepaEnabled),
'errorMessage' => $method->getProperty('errorMessage'),
'companyPlaceholder' => $method->getProperty('companyPlaceholder'),
'phoneLabel' => $method->getProperty('phoneLabel'),
'phonePlaceholder' => $phonePlaceholder,
'birthdatePlaceholder' => $gateway->paymentMethod()->getProperty('birthdatePlaceholder'),
'birthdatePlaceholder' => $method->getProperty('birthdatePlaceholder'),
'isExpressEnabled' => $gatewayId === 'applepay' && $method->getProperty('mollie_apple_pay_button_enabled_express_checkout') === 'yes',
];
}
$dataToScript['gatewayData'] = $gatewayData;
Expand Down

0 comments on commit 673d4b9

Please sign in to comment.