Skip to content

Commit

Permalink
Merge branch 'release/7.3.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaymo committed Apr 12, 2023
2 parents e41de50 + a6210c2 commit 1824904
Show file tree
Hide file tree
Showing 16 changed files with 183 additions and 49 deletions.
1 change: 0 additions & 1 deletion .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions mollie-payments-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
* Plugin Name: Mollie Payments for WooCommerce
* Plugin URI: https://www.mollie.com
* Description: Accept payments in WooCommerce with the official Mollie plugin
* Version: 7.3.6-beta2
* Version: 7.3.6
* Author: Mollie
* Author URI: https://www.mollie.com
* Requires at least: 5.0
* Tested up to: 6.1
* Tested up to: 6.2
* Text Domain: mollie-payments-for-woocommerce
* Domain Path: /languages
* License: GPLv2 or later
* WC requires at least: 3.0
* WC tested up to: 7.3
* WC tested up to: 7.5
* Requires PHP: 7.2
*/
declare(strict_types=1);
Expand Down
10 changes: 8 additions & 2 deletions resources/js/paypalButton.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {maybeShowButton} from "./maybeShowApplePayButton";

(
function ({_, molliepaypalbutton, jQuery}) {
Expand All @@ -6,7 +7,7 @@
return
}

const {product: {id, needShipping = true, isVariation = false, price, minFee}, ajaxUrl} = molliepaypalbutton
const {product: {id, needShipping = true, isVariation = false, price, minFee, stock}, ajaxUrl} = molliepaypalbutton

if (!id || !price || !ajaxUrl) {
return
Expand Down Expand Up @@ -59,6 +60,11 @@
let sibling = buttonParentNode.children[positionKey]
buttonParentNode.insertBefore(payPalButton, sibling)
}
let outOfStock = stock === 'outofstock'
if (outOfStock) {
hideButton()
return
}
const nonce = payPalButton.children[0].value
let productId = id
let productQuantity = 1
Expand All @@ -80,7 +86,7 @@
fadeButton();
// Fired when the user selects all the required dropdowns / attributes
// and a final variation is selected / shown
if (variation.is_virtual && variation.variation_id) {
if (variation.is_virtual && variation.is_in_stock && variation.variation_id) {
productId = variation.variation_id
payPalButton.disabled = false;
payPalButton.classList.remove("buttonDisabled");
Expand Down
18 changes: 18 additions & 0 deletions resources/scss/mollie-gateway-icons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,21 @@ label .mollie-gateway-icon{
#mol-paypal-settings-icon{
margin-left:1em;
}
#mol-icons-container{
background:white;
}
.mol-responsive-table-3{
display:flex;
flex-wrap:wrap;
background: white;
padding: 10px;
}
.mol-responsive-table-3 > * {
width:100%;
padding-top: 8px;
}
@media (min-width:768px) {
.mol-responsive-table-3 > * {
width:calc(100% / 3);
}
}
5 changes: 4 additions & 1 deletion src/Assets/AssetsModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -515,11 +515,14 @@ protected function getPluginPath(string $pluginPath, string $path = ''): string
*/
protected function enqueueIconSettings(?string $current_section): void
{
$uri = isset($_SERVER['REQUEST_URI']) ? wc_clean(wp_unslash($_SERVER['REQUEST_URI'])) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
if (is_string($uri) && strpos($uri, 'tab=mollie_settings')) {
wp_enqueue_style('mollie-gateway-icons');
}
if (!$current_section || strpos($current_section, 'mollie_wc_gateway_') === false) {
return;
}
wp_enqueue_script('mollie_wc_gateway_settings');
wp_enqueue_style('mollie-gateway-icons');
$settingsName = "{$current_section}_settings";
$gatewaySettings = get_option($settingsName, false);
$message = __('No custom logo selected', 'mollie-payments-for-woocommerce');
Expand Down
4 changes: 2 additions & 2 deletions src/Buttons/ApplePayButton/ApplePayDirectHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public function bootstrap($buttonEnabledProduct, $buttonEnabledCart)
}

if ($buttonEnabledProduct) {
$renderPlaceholder = apply_filters('mollie_wc_gateway_applepay_render_hook_product', 'woocommerce_before_add_to_cart_quantity');
$renderPlaceholder = is_string($renderPlaceholder) ? $renderPlaceholder : 'woocommerce_before_add_to_cart_quantity';
$renderPlaceholder = apply_filters('mollie_wc_gateway_applepay_render_hook_product', 'woocommerce_after_add_to_cart_form');
$renderPlaceholder = is_string($renderPlaceholder) ? $renderPlaceholder : 'woocommerce_after_add_to_cart_form';
add_action(
$renderPlaceholder,
function () {
Expand Down
2 changes: 2 additions & 0 deletions src/Buttons/PayPalButton/DataToPayPal.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ protected function dataForProductPage($minAmount)
$productNeedShipping = mollieWooCommerceCheckIfNeedShipping($product);
$productId = get_the_id();
$productPrice = $product->get_price();
$productStock = $product->get_stock_status();

return [
'product' => [
Expand All @@ -105,6 +106,7 @@ protected function dataForProductPage($minAmount)
'price' => $productPrice,
'isVariation' => $isVariation,
'minFee' => $minAmount,
'stock' => $productStock,
],
'ajaxUrl' => admin_url('admin-ajax.php'),
];
Expand Down
4 changes: 2 additions & 2 deletions src/Buttons/PayPalButton/PayPalButtonHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public function __construct(PayPalAjaxRequests $ajaxRequests, DataToPayPal $data
public function bootstrap($enabledInProduct, $enabledInCart)
{
if ($enabledInProduct) {
$renderPlaceholder = apply_filters('mollie_wc_gateway_paypal_render_hook_product', 'woocommerce_before_add_to_cart_quantity');
$renderPlaceholder = is_string($renderPlaceholder) ? $renderPlaceholder : 'woocommerce_before_add_to_cart_quantity';
$renderPlaceholder = apply_filters('mollie_wc_gateway_paypal_render_hook_product', 'woocommerce_after_add_to_cart_form');
$renderPlaceholder = is_string($renderPlaceholder) ? $renderPlaceholder : 'woocommerce_after_add_to_cart_form';
add_action(
$renderPlaceholder,
function () {
Expand Down
76 changes: 63 additions & 13 deletions src/Gateway/GatewayModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@ public function services(): array
}
return $enabledMethods;
},
'gateway.listAllMethodsAvailable' => static function (ContainerInterface $container): array {
$dataHelper = $container->get('settings.data_helper');
assert($dataHelper instanceof Data);
$settings = $container->get('settings.settings_helper');
assert($settings instanceof Settings);
$apiKey = $settings->getApiKey();
$methods = $apiKey ? $dataHelper->getAllAvailablePaymentMethods() : [];
$availableMethods = [];
$implementedMethods = $container->get('gateway.classnames');
foreach ($methods as $method) {
if (in_array('Mollie_WC_Gateway_' . ucfirst($method['id']), $implementedMethods, true)) {
$availableMethods[] = $method;
}
}
return $availableMethods;
},
'gateway.isSDDGatewayEnabled' => static function (ContainerInterface $container): bool {
$enabledMethods = $container->get('gateway.paymentMethodsEnabledAtMollie');
return in_array('directdebit', $enabledMethods, true);
Expand Down Expand Up @@ -601,7 +617,7 @@ public function instantiatePaymentMethodGateways(ContainerInterface $container):
protected function instantiatePaymentMethods($container): array
{
$paymentMethods = [];
$paymentMethodsNames = SharedDataDictionary::GATEWAY_CLASSNAMES;
$listAllAvailabePaymentMethods = $container->get('gateway.listAllMethodsAvailable');
$iconFactory = $container->get(IconFactory::class);
assert($iconFactory instanceof IconFactory);
$settingsHelper = $container->get('settings.settings_helper');
Expand All @@ -610,24 +626,30 @@ protected function instantiatePaymentMethods($container): array
assert($surchargeService instanceof Surcharge);
$paymentFieldsService = $container->get(PaymentFieldsService::class);
assert($paymentFieldsService instanceof PaymentFieldsService);
//I need DirectDebit to create SEPA gateway
if (!in_array('directdebit', $paymentMethodsNames, true)) {
$paymentMethodsNames[] = 'directdebit';
}
foreach ($paymentMethodsNames as $paymentMethodName) {
$paymentMethodName = strtolower($paymentMethodName);
$paymentMethodName = str_replace('mollie_wc_gateway_', '', $paymentMethodName);
$paymentMethodClassName = 'Mollie\\WooCommerce\\PaymentMethods\\' . ucfirst($paymentMethodName);
$paymentMethod = new $paymentMethodClassName(
foreach ($listAllAvailabePaymentMethods as $paymentMethodAvailable) {
$paymentMethodId = $paymentMethodAvailable['id'];
$paymentMethods[$paymentMethodId] = $this->buildPaymentMethod(
$paymentMethodId,
$iconFactory,
$settingsHelper,
$paymentFieldsService,
$surchargeService
$surchargeService,
$paymentMethods
);
$paymentMethodId = $paymentMethod->getIdFromConfig();
$paymentMethods[$paymentMethodId] = $paymentMethod;
}

//I need DirectDebit to create SEPA gateway
if (!in_array('directdebit', array_keys($paymentMethods), true)) {
$paymentMethodId = 'directdebit';
$paymentMethods[$paymentMethodId] = $this->buildPaymentMethod(
$paymentMethodId,
$iconFactory,
$settingsHelper,
$paymentFieldsService,
$surchargeService,
$paymentMethods
);
}
return $paymentMethods;
}

Expand Down Expand Up @@ -662,4 +684,32 @@ public function organizationBillingFieldMandatory($fields, $errors)

return $fields;
}

/**
* @param string $id
* @param IconFactory $iconFactory
* @param Settings $settingsHelper
* @param PaymentFieldsService $paymentFieldsService
* @param Surcharge $surchargeService
* @param array $paymentMethods
* @return PaymentMethodI
*/
public function buildPaymentMethod(
string $id,
IconFactory $iconFactory,
Settings $settingsHelper,
PaymentFieldsService $paymentFieldsService,
Surcharge $surchargeService,
array $paymentMethods
): PaymentMethodI {
$paymentMethodClassName = 'Mollie\\WooCommerce\\PaymentMethods\\' . ucfirst($id);
$paymentMethod = new $paymentMethodClassName(
$iconFactory,
$settingsHelper,
$paymentFieldsService,
$surchargeService
);

return $paymentMethod;
}
}
3 changes: 3 additions & 0 deletions src/Payment/PaymentCheckoutRedirectService.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public function setStrategy($paymentMethod)
$this->strategy = class_exists($className) ? new $className() : new DefaultRedirectStrategy();
}

/**
* @throws \Exception
*/
public function executeStrategy($paymentMethod, $order, $paymentObject, $redirectUrl)
{
return $this->strategy->execute($paymentMethod, $order, $paymentObject, $redirectUrl);
Expand Down
8 changes: 4 additions & 4 deletions src/Payment/PaymentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ protected function correctSurchargeFee($order, $paymentMethod)
$gatewaySettings = $paymentMethod->getMergedProperties();
$totalAmount = (float) $order->get_total();
$aboveMaxLimit = $surcharge->aboveMaxLimit($totalAmount, $gatewaySettings);
$amount = $aboveMaxLimit ? 0 : $surcharge->calculateFeeAmountOrder($order, $gatewaySettings);
$gatewayHasSurcharge = $amount !== 0;
$amount = $aboveMaxLimit ? 0.0 : $surcharge->calculateFeeAmountOrder($order, $gatewaySettings);
$gatewayHasSurcharge = $amount !== 0.0;
$gatewayFeeLabel = get_option(
'mollie-payments-for-woocommerce_gatewayFeeLabel',
$surcharge->defaultFeeLabel()
Expand Down Expand Up @@ -220,14 +220,14 @@ protected function orderAddFee($order, $amount, $surchargeName)
* @param WC_Order $order
* @param MollieOrder|MolliePayment $paymentObject
*
* @return string
*
*/
public function getProcessPaymentRedirect(
PaymentMethodI $paymentMethod,
$order,
$paymentObject,
string $redirectUrl
): string {
) {

$this->paymentCheckoutRedirectService->setStrategy($paymentMethod);
return $this->paymentCheckoutRedirectService->executeStrategy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class BanktransferRedirectStrategy implements PaymentRedirectStrategyI
* Redirect location after successfully completing process_payment
*
* @param PaymentMethodI $paymentMethod
* @param WC_Order $order
* @param MollieOrder|MolliePayment $payment_object
*
* @return string
* @param WC_Order $order
* @param $paymentObject
* @param string $redirectUrl
* @return string|null
*/
public function execute(PaymentMethodI $paymentMethod, $order, $paymentObject, string $redirectUrl): string
public function execute(PaymentMethodI $paymentMethod, $order, $paymentObject, string $redirectUrl)
{
if ($paymentMethod->getProperty('skip_mollie_payment_screen') === 'yes') {
return add_query_arg(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ class DefaultRedirectStrategy implements PaymentRedirectStrategyI
/**
* Redirect location after successfully completing process_payment
*
* @param WC_Order $order
* @param WC_Order $order
* @param MollieOrder|MolliePayment $payment_object
*
*/
public function execute(PaymentMethodI $paymentMethod, $order, $paymentObject, string $redirectUrl): string
public function execute(PaymentMethodI $paymentMethod, $order, $paymentObject, string $redirectUrl)
{
return $paymentObject->getCheckoutUrl();
return $paymentObject->getCheckoutUrl();
}
}
8 changes: 4 additions & 4 deletions src/Settings/Page/MollieSettingsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public function getMollieMethods(): string
) . '">' . strtolower(__('Disabled', 'mollie-payments-for-woocommerce')) . '</span>';

$content .= '<br /><br />';
$content .= '<div style="width:1000px;height:350px; background:white; padding:10px; margin-top:10px;">';
$content .= '<div id="mol-icons-container">';

if ($testMode) {
$content .= '<strong>' . __('Test mode enabled.', 'mollie-payments-for-woocommerce') . '</strong> ';
Expand All @@ -333,12 +333,12 @@ public function getMollieMethods(): string
__('Refresh', 'mollie-payments-for-woocommerce')
) . '</a>)';

$content .= '<ul style="width: 1000px; padding:20px 0 0 10px">';
$content .= '<ul class="mol-responsive-table-3">';

$mollieGateways = $this->registeredGateways;//this are the gateways enabled
$paymentMethods = $this->paymentMethods;
if (empty($mollieGateways)) {
$content .= '<li style="float: left; width: 32%; height:32px;">';
$content .= '<li>';
$content .= __("No payment methods available", "mollie-payments-for-woocommerce");
$content .= '</li></ul></div>';
$content .= '<div class="clear"></div>';
Expand All @@ -348,7 +348,7 @@ public function getMollieMethods(): string
$paymentMethodId = $paymentMethod->getProperty('id');
$gatewayKey = 'mollie_wc_gateway_' . $paymentMethodId;
$paymentMethodEnabledAtMollie = array_key_exists($gatewayKey, $mollieGateways);
$content .= '<li style="float: left; width: 32%; height:32px;">';
$content .= '<li>';
$content .= $paymentMethod->getIconUrl();
$content .= ' ' . esc_html($paymentMethod->getProperty('defaultTitle'));
if ($paymentMethodEnabledAtMollie) {
Expand Down
Loading

0 comments on commit 1824904

Please sign in to comment.