Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/apple express piwoo 319 #949

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
8 changes: 8 additions & 0 deletions inc/settings/mollie_applepay_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@
'value' => isset($applePayOption['mollie_apple_pay_button_enabled_product']) ? $applePayOption['mollie_apple_pay_button_enabled_product'] : 'no',

],
[
'id' => 'mollie_apple_pay_button_enabled_express_checkout',
'title' => __('Enable Apple Pay Express Button on Checkout page', 'mollie-payments-for-woocommerce'),
'desc' => __('Enable the Apple Pay direct buy button on the Express Buttons section of the Checkout page', 'mollie-payments-for-woocommerce'),
'type' => 'checkbox',
'default' => 'no',
'value' => isset($applePayOption['mollie_apple_pay_button_enabled_express_checkout']) ? $applePayOption['mollie_apple_pay_button_enabled_express_checkout'] : 'no',
],
[
'id' => $pluginName . '_' . 'sectionend',
'type' => 'sectionend',
Expand Down
5 changes: 4 additions & 1 deletion resources/js/blocks/ApplePayButtonComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ export const ApplePayButtonComponent = ({cart, extensions}) => {
<button
id="mollie_applepay_button"
className="apple-pay-button apple-pay-button-black"
onClick={applePaySession}
onClick={(event) => {
event.preventDefault();
applePaySession();
}}
>
</button>
);
Expand Down
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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a new variable has the same name as the object property, you can do just that:

const {isExpressEnabled} = item;

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 />,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This extra space can cause problems. Do these components still work?

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
8 changes: 6 additions & 2 deletions src/PaymentMethods/Applepay.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public function getFormFields($generalFormFields): array
$paymentMethodFormFieds = [
'mollie_apple_pay_button_enabled_cart' => [
'title' => __('Enable Apple Pay Button on Cart page', 'mollie-payments-for-woocommerce'),
/* translators: Placeholder 1: enabled or disabled */
'desc' => __(
'Enable the Apple Pay direct buy button on the Cart page',
'mollie-payments-for-woocommerce'
Expand All @@ -42,14 +41,19 @@ public function getFormFields($generalFormFields): array
],
'mollie_apple_pay_button_enabled_product' => [
'title' => __('Enable Apple Pay Button on Product page', 'mollie-payments-for-woocommerce'),
/* translators: Placeholder 1: enabled or disabled */
'desc' => __(
'Enable the Apple Pay direct buy button on the Product page',
'mollie-payments-for-woocommerce'
),
'type' => 'checkbox',
'default' => 'no',
],
'mollie_apple_pay_button_enabled_express_checkout' => [
'title' => __('Enable Apple Pay Express Button on Checkout page', 'mollie-payments-for-woocommerce'),
'desc' => __('Enable the Apple Pay direct buy button on the Express Buttons section of the Checkout page', 'mollie-payments-for-woocommerce'),
'type' => 'checkbox',
'default' => 'no',
],
];
return array_merge($generalFormFields, $paymentMethodFormFieds);
}
Expand Down
Loading