@@ -127,8 +128,9 @@ public function voucherBulkEditSave($product)
{
$post_id = $product->get_id();
$optionName = Voucher::MOLLIE_VOUCHER_CATEGORY_OPTION;
+ check_ajax_referer('inlineeditnonce', '_inline_edit');
if (isset($_REQUEST[$optionName])) {
- $option = $_REQUEST[$optionName];
+ $option = filter_var(wp_unslash($_REQUEST[$optionName]), FILTER_SANITIZE_SPECIAL_CHARS);
update_post_meta($post_id, $optionName, wc_clean($option));
}
}
@@ -140,15 +142,15 @@ public function voucherTaxonomyFieldOnCreatePage()
{
?>
- |
+ |
-
@@ -201,7 +203,7 @@ public function voucherTaxonomyFieldOnEditPage($term)
public function voucherTaxonomyCustomMetaSave($term_id)
{
- $metaOption = sanitize_text_field(wp_unslash($_POST(['_mollie_voucher_category'])));
+ $metaOption = filter_input(INPUT_POST, '_mollie_voucher_category', FILTER_SANITIZE_SPECIAL_CHARS);
update_term_meta($term_id, '_mollie_voucher_category', $metaOption);
}
@@ -212,43 +214,47 @@ public function voucherTaxonomyCustomMetaSave($term_id)
public function mollieOptionsProductTabContent()
{
?>
- voucherDefaultCategory;
- woocommerce_wp_select(
- [
- 'id' => Voucher::MOLLIE_VOUCHER_CATEGORY_OPTION,
- 'title' => __(
- 'Select the default products category',
- 'mollie-payments-for-woocommerce'
- ),
- 'label' => __(
- 'Products voucher category',
- 'mollie-payments-for-woocommerce'
- ),
+
+
+ voucherDefaultCategory;
+ woocommerce_wp_select(
+ [
+ 'id' => Voucher::MOLLIE_VOUCHER_CATEGORY_OPTION,
+ 'title' => __(
+ 'Select the default products category',
+ 'mollie-payments-for-woocommerce'
+ ),
+ 'label' => __(
+ 'Products voucher category',
+ 'mollie-payments-for-woocommerce'
+ ),
- 'type' => 'select',
- 'options' => [
- $defaultCategory => __('Same as default category', 'mollie-payments-for-woocommerce'),
- Voucher::NO_CATEGORY => __('No Category', 'mollie-payments-for-woocommerce'),
- Voucher::MEAL => __('Meal', 'mollie-payments-for-woocommerce'),
- Voucher::ECO => __('Eco', 'mollie-payments-for-woocommerce'),
- Voucher::GIFT => __('Gift', 'mollie-payments-for-woocommerce'),
+ 'type' => 'select',
+ 'options' => [
+ $defaultCategory => __(
+ 'Same as default category',
+ 'mollie-payments-for-woocommerce'
+ ),
+ Voucher::NO_CATEGORY => __('No Category', 'mollie-payments-for-woocommerce'),
+ Voucher::MEAL => __('Meal', 'mollie-payments-for-woocommerce'),
+ Voucher::ECO => __('Eco', 'mollie-payments-for-woocommerce'),
+ Voucher::GIFT => __('Gift', 'mollie-payments-for-woocommerce'),
- ],
- 'default' => $defaultCategory,
- /* translators: Placeholder 1: Default order status, placeholder 2: Link to 'Hold Stock' setting */
- 'description' => sprintf(
- __(
- 'In order to process it, all products in the order must have a category. To disable the product from voucher selection select "No category" option.',
- 'mollie-payments-for-woocommerce'
- )
- ),
- 'desc_tip' => true,
- ]
- ); ?>
+ ],
+ 'default' => $defaultCategory,
+ /* translators: Placeholder 1: Default order status, placeholder 2: Link to 'Hold Stock' setting */
+ 'description' => __(
+ 'In order to process it, all products in the order must have a category. To disable the product from voucher selection select "No category" option.',
+ 'mollie-payments-for-woocommerce'
+ ),
+ 'desc_tip' => true,
+ ]
+ );
+ ?>
+
-
- data;
+ }
+
+ public function customerId()
+ {
+ return self::$customerId;
+ }
+
/**
* Get Mollie payment from cache or load from Mollie
* Skip cache by setting $use_cache to false
@@ -200,7 +213,7 @@ class_exists('WC_Subscriptions')
} elseif (wcs_order_contains_renewal($order_id)) {
$subscriptions = wcs_get_subscriptions_for_renewal_order($order_id);
} else {
- $subscriptions = array();
+ $subscriptions = [];
}
foreach ($subscriptions as $subscription) {
@@ -499,7 +512,7 @@ protected function onWebhookExpired(WC_Order $order, $payment, $paymentMethodTit
/**
* Process a payment object refund
*
- * @param object $order
+ * @param WC_Order $order
* @param int $orderId
* @param object $paymentObject
* @param null $amount
@@ -571,11 +584,10 @@ protected function addMandateIdMetaToFirstPaymentSubscriptionOrder(
}
}
-
protected function addSequenceTypeForSubscriptionsFirstPayments($orderId, $gateway, $paymentRequestData): array
{
if ($this->dataHelper->isSubscription($orderId)) {
- $disable_automatic_payments = apply_filters( $this->pluginId . '_is_automatic_payment_disabled', false );
+ $disable_automatic_payments = apply_filters($this->pluginId . '_is_automatic_payment_disabled', false);
$supports_subscriptions = $gateway->supports('subscriptions');
if ($supports_subscriptions == true && $disable_automatic_payments == false) {
@@ -641,7 +653,7 @@ function_exists('wcs_order_contains_renewal')
&& wcs_order_contains_renewal($orderId)
) {
if ($gateway instanceof MolliePaymentGateway) {
- $gateway->paymentService->updateOrderStatus(
+ $gateway->paymentService()->updateOrderStatus(
$order,
$newOrderStatus,
sprintf(
@@ -673,7 +685,7 @@ function_exists('wcs_order_contains_renewal')
$emails['WC_Email_Failed_Order']->trigger($orderId);
}
} elseif ($gateway instanceof MolliePaymentGateway) {
- $gateway->paymentService->updateOrderStatus(
+ $gateway->paymentService()->updateOrderStatus(
$order,
$newOrderStatus,
sprintf(
@@ -804,17 +816,17 @@ public function getWebhookUrl($order, $gatewayId)
protected function asciiDomainName($url): string
{
$parsed = parse_url($url);
- $scheme = isset($parsed['scheme'])?$parsed['scheme']:'';
- $domain = isset($parsed['host'])?$parsed['host']:false;
- $query = isset($parsed['query'])?$parsed['query']:'';
- $path = isset($parsed['path'])?$parsed['path']:'';
- if(!$domain){
+ $scheme = isset($parsed['scheme']) ? $parsed['scheme'] : '';
+ $domain = isset($parsed['host']) ? $parsed['host'] : false;
+ $query = isset($parsed['query']) ? $parsed['query'] : '';
+ $path = isset($parsed['path']) ? $parsed['path'] : '';
+ if (!$domain) {
return $url;
}
if (function_exists('idn_to_ascii')) {
$domain = $this->idnEncodeDomain($domain);
- $url = $scheme . "://". $domain . $path . '?' . $query;
+ $url = $scheme . "://" . $domain . $path . '?' . $query;
}
return $url;
@@ -846,7 +858,8 @@ protected function appendOrderArgumentsToUrl($order_id, $order_key, $webhook_url
*/
protected function idnEncodeDomain($domain)
{
- if (defined('IDNA_NONTRANSITIONAL_TO_ASCII')
+ if (
+ defined('IDNA_NONTRANSITIONAL_TO_ASCII')
&& defined(
'INTL_IDNA_VARIANT_UTS46'
)
@@ -865,6 +878,7 @@ protected function idnEncodeDomain($domain)
}
return $domain;
}
+
protected function getPaymentDescription($order, $option)
{
$description = !$option ? '' : trim($option);
@@ -931,7 +945,7 @@ protected function getPaymentDescription($order, $option)
}
// Fall back on default if description turns out empty.
- return !$description ? __('Order', 'woocommerce' ) . ' ' . $order->get_order_number() : $description;
+ return !$description ? __('Order', 'woocommerce') . ' ' . $order->get_order_number() : $description;
}
/**
diff --git a/src/Payment/MollieOrder.php b/src/Payment/MollieOrder.php
index 9d913fae5..ce21ffa68 100644
--- a/src/Payment/MollieOrder.php
+++ b/src/Payment/MollieOrder.php
@@ -6,11 +6,13 @@
use Exception;
use Mollie\Api\Exceptions\ApiException;
+use Mollie\Api\Resources\Payment;
use Mollie\Api\Resources\Order;
use Mollie\Api\Resources\Refund;
use Mollie\WooCommerce\Gateway\MolliePaymentGateway;
use Mollie\WooCommerce\PaymentMethods\Voucher;
use Mollie\WooCommerce\SDK\Api;
+use Mollie\WooCommerce\Shared\SharedDataDictionary;
use Psr\Log\LogLevel;
use stdClass;
use WC_Order;
@@ -25,11 +27,11 @@ class MollieOrder extends MollieObject
public const MAXIMAL_LENGHT_CITY = 200;
public const MAXIMAL_LENGHT_REGION = 200;
- static $paymentId;
- public static $customerId;
- public static $order;
- public static $payment;
- public static $shop_country;
+ protected static $paymentId;
+ protected static $customerId;
+ protected static $order;
+ protected static $payment;
+ protected static $shop_country;
/**
* @var OrderLines
*/
@@ -39,7 +41,7 @@ class MollieOrder extends MollieObject
* @var OrderItemsRefunder
*/
private $orderItemsRefunder;
- public $pluginId;
+ protected $pluginId;
/**
* MollieOrder constructor.
@@ -96,11 +98,9 @@ public function getPaymentRequestData($order, $customerId, $voucherDefaultCatego
$returnUrl = $gateway->get_return_url($order);
$returnUrl = $this->getReturnUrl($order, $returnUrl);
$webhookUrl = $this->getWebhookUrl($order, $gatewayId);
- if (
- $gatewayId !== 'mollie_wc_gateway_paypal'
- || ($gatewayId === 'mollie_wc_gateway_paypal'
- && $order->get_billing_first_name() !== '')
- ) {
+ $isPayPalExpressOrder = $order->get_meta('_mollie_payment_method_button') === 'PayPalButton';
+ $billingAddress = null;
+ if (!$isPayPalExpressOrder) {
$billingAddress = $this->createBillingAddress($order);
$shippingAddress = $this->createShippingAddress($order);
}
@@ -120,12 +120,12 @@ public function getPaymentRequestData($order, $customerId, $voucherDefaultCatego
],
'redirectUrl' => $returnUrl,
'webhookUrl' => $webhookUrl,
- 'method' => $gateway->paymentMethod->getProperty('id'),
+ 'method' => $gateway->paymentMethod()->getProperty('id'),
'payment' => [
'issuer' => $selectedIssuer,
],
'locale' => $paymentLocale,
- 'billingAddress' => $billingAddress ?: null,
+ 'billingAddress' => $billingAddress,
'metadata' => apply_filters(
$this->pluginId . '_payment_object_metadata',
[
@@ -159,7 +159,7 @@ public function getPaymentRequestData($order, $customerId, $voucherDefaultCatego
$paymentRequestData['payment']['cardToken'] = $cardToken;
}
- $applePayToken = isset($_POST['token'])? sanitize_text_field(wp_unslash($_POST['token'])) : false;
+ $applePayToken = filter_input(INPUT_POST, 'token', FILTER_SANITIZE_SPECIAL_CHARS) ?? false;
if ($applePayToken && isset($paymentRequestData['payment'])) {
$encodedApplePayToken = json_encode($applePayToken);
$paymentRequestData['payment']['applePayPaymentToken'] = $encodedApplePayToken;
@@ -225,9 +225,11 @@ public function getMollieCustomerIbanDetailsFromPaymentObject($payment = null)
$ibanDetails = [];
if (isset($payment->_embedded->payments[0]->id)) {
- $actualPayment = new MolliePayment($payment->_embedded->payments[0]->id, $this->pluginId, $this->apiHelper, $this->settingsHelper, $this->dataHelper);
+ $actualPayment = new MolliePayment($payment->_embedded->payments[0]->id, $this->pluginId, $this->apiHelper, $this->settingsHelper, $this->dataHelper, $this->logger);
$actualPayment = $actualPayment->getPaymentObject($actualPayment->data);
-
+ /**
+ * @var Payment $actualPayment
+ */
$ibanDetails['consumerName'] = $actualPayment->details->consumerName;
$ibanDetails['consumerAccount'] = $actualPayment->details->consumerAccount;
}
@@ -254,7 +256,6 @@ public function onWebhookPaid(WC_Order $order, $payment, $paymentMethodTitle)
$this->logger->debug(__METHOD__ . " called for order {$orderId}");
if ($payment->method === 'paypal') {
- $this->addAddressToPaypalOrder($payment, $order);
$this->addPaypalTransactionIdToOrder($order);
}
@@ -364,7 +365,6 @@ public function onWebhookCompleted(WC_Order $order, $payment, $paymentMethodTitl
$this->logger->debug(__METHOD__ . ' called for order ' . $orderId);
if ($payment->method === 'paypal') {
- $this->addAddressToPaypalOrder($payment, $order);
$this->addPaypalTransactionIdToOrder($order);
}
$order->payment_complete($payment->id);
@@ -428,13 +428,13 @@ public function onWebhookCanceled(WC_Order $order, $payment, $paymentMethodTitle
// New order status
if ($orderStatusCancelledPayments === 'pending' || $orderStatusCancelledPayments === null) {
- $newOrderStatus = MolliePaymentGateway::STATUS_PENDING;
+ $newOrderStatus = SharedDataDictionary::STATUS_PENDING;
} elseif ($orderStatusCancelledPayments === 'cancelled') {
- $newOrderStatus = MolliePaymentGateway::STATUS_CANCELLED;
+ $newOrderStatus = SharedDataDictionary::STATUS_CANCELLED;
}
// if I cancel manually the order is canceled in Woo before calling Mollie
if ($order->get_status() === 'cancelled') {
- $newOrderStatus = MolliePaymentGateway::STATUS_CANCELLED;
+ $newOrderStatus = SharedDataDictionary::STATUS_CANCELLED;
}
// Overwrite plugin-wide
@@ -474,7 +474,7 @@ public function onWebhookFailed(WC_Order $order, $payment, $paymentMethodTitle)
$this->logger->debug(__METHOD__ . ' called for order ' . $orderId);
// New order status
- $newOrderStatus = MolliePaymentGateway::STATUS_FAILED;
+ $newOrderStatus = SharedDataDictionary::STATUS_FAILED;
// Overwrite plugin-wide
$newOrderStatus = apply_filters($this->pluginId . '_order_status_failed', $newOrderStatus);
@@ -535,7 +535,7 @@ public function onWebhookExpired(WC_Order $order, $payment, $paymentMethodTitle)
}
// New order status
- $newOrderStatus = MolliePaymentGateway::STATUS_CANCELLED;
+ $newOrderStatus = SharedDataDictionary::STATUS_CANCELLED;
// Overwrite plugin-wide
$newOrderStatus = apply_filters($this->pluginId . '_order_status_expired', $newOrderStatus);
@@ -617,7 +617,7 @@ public function refund(WC_Order $order, $orderId, $paymentObject, $amount = null
}
$totals = number_format(abs($totals), 2); // WooCommerce - sum of all refund items
- $checkAmount = $amount? number_format((float)$amount, 2):0; // WooCommerce - refund amount
+ $checkAmount = $amount ? number_format((float)$amount, 2) : 0; // WooCommerce - refund amount
if ($checkAmount !== $totals) {
$errorMessage = _x('The sum of refunds for all order lines is not identical to the refund amount, so this refund will be processed as a payment amount refund, not an order line refund.', 'Order note error', 'mollie-payments-for-woocommerce');
@@ -710,91 +710,16 @@ public function refund_order_items($order, $orderId, $amount, $items, $paymentOb
throw new Exception($noteMessage);
}
- $apiKey = $this->settingsHelper->getApiKey();
-
- // Get the Mollie order
- $mollieOrder = $this->apiHelper->getApiClient($apiKey)->orders->get($paymentObject->id);
-
- $itemTotalAmount = abs(number_format($item->get_total() + $item->get_total_tax(), 2));
-
- // Prepare the order line to update
- if (!empty($line->discountAmount)) {
- $lines = [
- 'lines' => [
- [
- 'id' => $line->id,
- 'quantity' => abs($item->get_quantity()),
- 'amount' => [
- 'value' => $this->dataHelper->formatCurrencyValue($itemTotalAmount, $this->dataHelper->getOrderCurrency($order)),
- 'currency' => $this->dataHelper->getOrderCurrency($order),
- ],
- ],
- ],
- ];
- } else {
- $lines = [
- 'lines' => [
- [
- 'id' => $line->id,
- 'quantity' => abs($item->get_quantity()),
- ],
- ],
- ];
- }
-
- if ($line->status === 'created' || $line->status === 'authorized') {
- // Returns null if successful.
- $refund = $mollieOrder->cancelLines($lines);
-
- $this->logger->debug(__METHOD__ . ' - Cancelled order line: ' . abs($item->get_quantity()) . 'x ' . $item->get_name() . '. Mollie order line: ' . $line->id . ', payment object: ' . $paymentObject->id . ', order: ' . $orderId . ', amount: ' . $this->data->getOrderCurrency($order) . wc_format_decimal($itemRefundAmount) . ( ! empty($reason) ? ', reason: ' . $reason : '' ));
-
- if ($refund === null) {
- /* translators: Placeholder 1: Number of items. Placeholder 2: Name of item. Placeholder 3: Currency. Placeholder 4: Amount.*/
- $noteMessage = sprintf(
- __('%1$sx %2$s cancelled for %3$s%4$s in WooCommerce and at Mollie.', 'mollie-payments-for-woocommerce'),
- abs($item->get_quantity()),
- $item->get_name(),
- $this->dataHelper->getOrderCurrency($order),
- $itemRefundAmount
- );
- }
- }
-
- if ($line->status === 'paid' || $line->status === 'shipping' || $line->status === 'completed') {
- $lines['description'] = $reason;
- $refund = $mollieOrder->refund($lines);
-
- $this->logger->debug(__METHOD__ . ' - Refunded order line: ' . abs($item->get_quantity()) . 'x ' . $item->get_name() . '. Mollie order line: ' . $line->id . ', payment object: ' . $paymentObject->id . ', order: ' . $orderId . ', amount: ' . $this->data->getOrderCurrency($order) . wc_format_decimal($itemRefundAmount) . ( ! empty($reason) ? ', reason: ' . $reason : '' ));
- /* translators: Placeholder 1: Number of items. Placeholder 2: Name of item. Placeholder 3: Currency. Placeholder 4: Amount. Placeholder 5: Reason. Placeholder 6: Refund Id. */
- $noteMessage = sprintf(
- __('%1$sx %2$s refunded for %3$s%4$s in WooCommerce and at Mollie.%5$s Refund ID: %6$s.', 'mollie-payments-for-woocommerce'),
- abs($item->get_quantity()),
- $item->get_name(),
- $this->dataHelper->getOrderCurrency($order),
- $itemRefundAmount,
- ( ! empty($reason) ? ' Reason: ' . $reason . '.' : '' ),
- $refund->id
- );
- }
-
- do_action(
- self::ACTION_AFTER_REFUND_ORDER_CREATED,
- $refund,
- $order
- );
-
- do_action_deprecated(
- $this->pluginId . '_refund_created',
- [$refund, $order],
- '5.3.1',
- self::ACTION_AFTER_REFUND_PAYMENT_CREATED
+ $this->processOrderItemsRefund(
+ $paymentObject,
+ $item,
+ $line,
+ $order,
+ $orderId,
+ $itemRefundAmount,
+ $reason,
+ $items
);
-
- $order->add_order_note($noteMessage);
- $this->logger->debug($noteMessage);
-
- // drop item from array
- unset($items[ $item->get_id() ]);
}
}
}
@@ -929,9 +854,10 @@ protected function maybeUpdateStatus(
$paymentMethodTitle,
Order $payment
) {
+
$gateway = wc_get_payment_gateway_by_order($order);
- if (!$this->isOrderPaymentStartedByOtherGateway($order) && is_a($gateway, MolliePaymentGateway::class) ) {
- $gateway->paymentService->updateOrderStatus($order, $newOrderStatus);
+ if (!$this->isOrderPaymentStartedByOtherGateway($order) && is_a($gateway, MolliePaymentGateway::class)) {
+ $gateway->paymentService()->updateOrderStatus($order, $newOrderStatus);
} else {
$this->informNotUpdatingStatus($gateway->id, $order);
}
@@ -1013,6 +939,7 @@ protected function createBillingAddress($order)
$order->get_billing_country(),
self::MAXIMAL_LENGHT_REGION
);
+ $billingAddress->organizationName = $this->billingCompanyField($order);
return $billingAddress;
}
@@ -1084,25 +1011,164 @@ protected function createShippingAddress($order)
}
/**
- * @param Order $payment
- * @param WC_Order $order
+ * @param $paymentObject
+ * @param $item
+ * @param $line
+ * @param $order
+ * @param $orderId
+ * @param $itemRefundAmount
+ * @param $reason
+ * @param $items
+ *
+ * @throws ApiException
*/
- protected function addAddressToPaypalOrder(
- Order $payment,
- WC_Order $order
- ) {
+ protected function processOrderItemsRefund(
+ $paymentObject,
+ $item,
+ $line,
+ $order,
+ $orderId,
+ $itemRefundAmount,
+ $reason,
+ $items
+ ): void {
- $address = $payment->shippingAddress;
- $shippingAddress = [
- 'first_name' => sanitize_text_field(wp_unslash($address->givenName)),
- 'last_name' => sanitize_text_field(wp_unslash($address->familyName)),
- 'email' => sanitize_text_field(wp_unslash($address->email)),
- 'postcode' => sanitize_text_field(wp_unslash($address->postalCode)),
- 'country' => strtoupper(sanitize_text_field(wp_unslash($address->country))),
- 'city' => sanitize_text_field(wp_unslash($address->city)),
- 'address_1' => sanitize_text_field(wp_unslash($address->streetAndNumber)),
- ];
+ $apiKey = $this->settingsHelper->getApiKey();
- $order->set_address($shippingAddress, 'shipping');
+ // Get the Mollie order
+ $mollieOrder = $this->apiHelper->getApiClient($apiKey)->orders->get($paymentObject->id);
+
+ $itemTotalAmount = abs(number_format($item->get_total() + $item->get_total_tax(), 2));
+
+ // Prepare the order line to update
+ if (!empty($line->discountAmount)) {
+ $lines = [
+ 'lines' => [
+ [
+ 'id' => $line->id,
+ 'quantity' => abs($item->get_quantity()),
+ 'amount' => [
+ 'value' => $this->dataHelper->formatCurrencyValue(
+ $itemTotalAmount,
+ $this->dataHelper->getOrderCurrency(
+ $order
+ )
+ ),
+ 'currency' => $this->dataHelper->getOrderCurrency($order),
+ ],
+ ],
+ ],
+ ];
+ } else {
+ $lines = [
+ 'lines' => [
+ [
+ 'id' => $line->id,
+ 'quantity' => abs($item->get_quantity()),
+ ],
+ ],
+ ];
+ }
+
+ if ($line->status === 'created' || $line->status === 'authorized') {
+ // Returns null if successful.
+ $refund = $mollieOrder->cancelLines($lines);
+
+ $this->logger->debug(
+ __METHOD__ . ' - Cancelled order line: ' . abs($item->get_quantity()) . 'x ' . $item->get_name(
+ ) . '. Mollie order line: ' . $line->id . ', payment object: ' . $paymentObject->id . ', order: ' . $orderId . ', amount: ' . $this->data->getOrderCurrency(
+ $order
+ ) . wc_format_decimal($itemRefundAmount) . (!empty($reason) ? ', reason: ' . $reason : '')
+ );
+
+ if ($refund === null) {
+ /* translators: Placeholder 1: Number of items. Placeholder 2: Name of item. Placeholder 3: Currency. Placeholder 4: Amount.*/
+ $noteMessage = sprintf(
+ __(
+ '%1$sx %2$s cancelled for %3$s%4$s in WooCommerce and at Mollie.',
+ 'mollie-payments-for-woocommerce'
+ ),
+ abs($item->get_quantity()),
+ $item->get_name(),
+ $this->dataHelper->getOrderCurrency($order),
+ $itemRefundAmount
+ );
+ }
+ }
+
+ if ($line->status === 'paid' || $line->status === 'shipping' || $line->status === 'completed') {
+ $lines['description'] = $reason;
+ $refund = $mollieOrder->refund($lines);
+
+ $this->logger->debug(
+ __METHOD__ . ' - Refunded order line: ' . abs($item->get_quantity()) . 'x ' . $item->get_name(
+ ) . '. Mollie order line: ' . $line->id . ', payment object: ' . $paymentObject->id . ', order: ' . $orderId . ', amount: ' . $this->data->getOrderCurrency(
+ $order
+ ) . wc_format_decimal($itemRefundAmount) . (!empty($reason) ? ', reason: ' . $reason : '')
+ );
+ /* translators: Placeholder 1: Number of items. Placeholder 2: Name of item. Placeholder 3: Currency. Placeholder 4: Amount. Placeholder 5: Reason. Placeholder 6: Refund Id. */
+ $noteMessage = sprintf(
+ __(
+ '%1$sx %2$s refunded for %3$s%4$s in WooCommerce and at Mollie.%5$s Refund ID: %6$s.',
+ 'mollie-payments-for-woocommerce'
+ ),
+ abs($item->get_quantity()),
+ $item->get_name(),
+ $this->dataHelper->getOrderCurrency($order),
+ $itemRefundAmount,
+ (!empty($reason) ? ' Reason: ' . $reason . '.' : ''),
+ $refund->id
+ );
+ }
+
+ do_action(
+ self::ACTION_AFTER_REFUND_ORDER_CREATED,
+ $refund,
+ $order
+ );
+
+ do_action_deprecated(
+ $this->pluginId . '_refund_created',
+ [$refund, $order],
+ '5.3.1',
+ self::ACTION_AFTER_REFUND_PAYMENT_CREATED
+ );
+
+ $order->add_order_note($noteMessage);
+ $this->logger->debug($noteMessage);
+
+ // drop item from array
+ unset($items[$item->get_id()]);
+ }
+
+ /**
+ * @param $order
+ * @return string|null
+ */
+ public function billingCompanyField($order): ?string
+ {
+ if (!trim($order->get_billing_company())) {
+ return $this->checkBillieCompanyField($order);
+ }
+ return $this->maximalFieldLengths(
+ $order->get_billing_company(),
+ self::MAXIMAL_LENGHT_ADDRESS
+ );
+ }
+
+ private function checkBillieCompanyField($order)
+ {
+ $gateway = wc_get_payment_gateway_by_order($order);
+ $isBillieMethodId = $gateway->id === 'mollie_wc_gateway_billie';
+ if ($isBillieMethodId) {
+ $companyFieldPosted = filter_input(INPUT_POST, 'billing_company', FILTER_SANITIZE_SPECIAL_CHARS) ?? false;
+ if ($companyFieldPosted) {
+ return $this->maximalFieldLengths(
+ $companyFieldPosted,
+ self::MAXIMAL_LENGHT_ADDRESS
+ );
+ }
+ }
+ return null;
}
}
diff --git a/src/Payment/MollieOrderService.php b/src/Payment/MollieOrderService.php
index 9eb0d5366..898c0686e 100644
--- a/src/Payment/MollieOrderService.php
+++ b/src/Payment/MollieOrderService.php
@@ -11,6 +11,7 @@
use Mollie\WooCommerce\Gateway\MolliePaymentGateway;
use Mollie\WooCommerce\SDK\HttpResponse;
use Mollie\WooCommerce\Shared\Data;
+use Mollie\WooCommerce\Shared\SharedDataDictionary;
use Psr\Log\LoggerInterface as Logger;
use Psr\Log\LogLevel;
use WC_Order;
@@ -73,8 +74,8 @@ public function onWebhookAction()
return;
}
- $order_id = sanitize_text_field($_GET['order_id']);
- $key = sanitize_text_field($_GET['key']);
+ $order_id = sanitize_text_field(wp_unslash($_GET['order_id']));
+ $key = sanitize_text_field(wp_unslash($_GET['key']));
$data_helper = $this->data;
$order = wc_get_order($order_id);
@@ -96,13 +97,14 @@ public function onWebhookAction()
}
$this->setGateway($gateway);
// No Mollie payment id provided
- if (empty($_POST['id'])) {
+ $paymentId = filter_input(INPUT_POST, 'id', FILTER_SANITIZE_SPECIAL_CHARS);
+ if (empty($paymentId)) {
$this->httpResponse->setHttpResponseCode(400);
$this->logger->debug(__METHOD__ . ': No payment object ID provided.', [true]);
return;
}
- $payment_object_id = sanitize_text_field($_POST['id']);
+ $payment_object_id = sanitize_text_field(wp_unslash($paymentId));
$test_mode = $data_helper->getActiveMolliePaymentMode($order_id) === 'test';
// Load the payment from Mollie, do not use cache
@@ -116,7 +118,7 @@ public function onWebhookAction()
return;
}
- $payment = $payment_object->getPaymentObject($payment_object->data, $test_mode, $use_cache = false);
+ $payment = $payment_object->getPaymentObject($payment_object->data(), $test_mode, $use_cache = false);
// Payment not found
if (!$payment) {
@@ -202,12 +204,16 @@ public function orderNeedsPayment(WC_Order $order)
}
// Has initial order status 'on-hold'
- if ($this->gateway->paymentMethod->getInitialOrderStatus() === MolliePaymentGateway::STATUS_ON_HOLD && $order->has_status(MolliePaymentGateway::STATUS_ON_HOLD)) {
- $this->logger->debug(__METHOD__ . ' ' . $this->gateway->id . ': Order ' . $order_id . ' orderNeedsPayment check: yes, has status On-Hold. ', [true]);
-
+ if (
+ $this->gateway->paymentMethod()->getInitialOrderStatus() === SharedDataDictionary::STATUS_ON_HOLD
+ && $order->has_status(SharedDataDictionary::STATUS_ON_HOLD)
+ ) {
+ $this->logger->debug(
+ __METHOD__ . ' ' . $this->gateway->id . ': Order ' . $order_id . ' orderNeedsPayment check: yes, has status On-Hold. ',
+ [true]
+ );
return true;
}
-
return false;
}
@@ -283,7 +289,7 @@ protected function processRefunds(WC_Order $order, $payment)
);
$order = wc_get_order($orderId);
- $processedRefundIds = $this->notifyProcessedRefunds($refundsToProcess, $logId, $order, $processedRefundIds);
+ $this->notifyProcessedRefunds($refundsToProcess, $logId, $order, $processedRefundIds);
$order->save();
$this->processUpdateStateRefund($order, $payment);
@@ -380,7 +386,6 @@ protected function processChargebacks(WC_Order $order, $payment)
return;
}
- $dataHelper = $this->data;
$order = wc_get_order($orderId);
// Update order notes, add message about chargeback
@@ -408,7 +413,7 @@ protected function processChargebacks(WC_Order $order, $payment)
//
// New order status
- $newOrderStatus = MolliePaymentGateway::STATUS_ON_HOLD;
+ $newOrderStatus = SharedDataDictionary::STATUS_ON_HOLD;
// Overwrite plugin-wide
$newOrderStatus = apply_filters($this->pluginId . '_order_status_on_hold', $newOrderStatus);
@@ -597,7 +602,7 @@ protected function findRefundIdsByLinks($payment): array
}
/**
- * @param Payment|Order $payment
+ * @param Order $payment
* @param WC_Order $order
*/
protected function setBillingAddressAfterPayment($payment, $order)
@@ -641,7 +646,7 @@ protected function processUpdateStateRefund(WC_Order $order, $payment)
$this->updateStateRefund(
$order,
$payment,
- MolliePaymentGateway::STATUS_REFUNDED,
+ SharedDataDictionary::STATUS_REFUNDED,
'_order_status_refunded'
);
}
@@ -724,7 +729,7 @@ protected function getPaymentMethodTitle($payment)
if (!($this->gateway instanceof MolliePaymentGateway)) {
return $payment_method_title;
}
- if ($payment->method === $this->gateway->paymentMethod->getProperty('id')) {
+ if ($payment->method === $this->gateway->paymentMethod()->getProperty('id')) {
$payment_method_title = $this->gateway->method_title;
}
return $payment_method_title;
@@ -740,7 +745,7 @@ public function updateOrderStatus(\WC_Order $order, $new_status, $note = '', $re
$order->update_status($new_status, $note);
switch ($new_status) {
- case MolliePaymentGateway::STATUS_ON_HOLD:
+ case SharedDataDictionary::STATUS_ON_HOLD:
if ($restore_stock === true) {
if (! $order->get_meta('_order_stock_reduced', true)) {
// Reduce order stock
@@ -752,9 +757,9 @@ public function updateOrderStatus(\WC_Order $order, $new_status, $note = '', $re
break;
- case MolliePaymentGateway::STATUS_PENDING:
- case MolliePaymentGateway::STATUS_FAILED:
- case MolliePaymentGateway::STATUS_CANCELLED:
+ case SharedDataDictionary::STATUS_PENDING:
+ case SharedDataDictionary::STATUS_FAILED:
+ case SharedDataDictionary::STATUS_CANCELLED:
if ($order->get_meta('_order_stock_reduced', true)) {
// Restore order stock
$this->data->restoreOrderStock($order);
@@ -830,6 +835,6 @@ protected function notifyProcessedRefunds(array $refundsToProcess, string $logId
protected function isOrderButtonPayment(WC_Order $order): bool
{
- return $order->get_meta('_mollie_payment_method_button', false) === 'PayPalButton';
+ return $order->get_meta('_mollie_payment_method_button') === 'PayPalButton';
}
}
diff --git a/src/Payment/MolliePayment.php b/src/Payment/MolliePayment.php
index e51359c6b..72d473ae2 100644
--- a/src/Payment/MolliePayment.php
+++ b/src/Payment/MolliePayment.php
@@ -5,10 +5,14 @@
namespace Mollie\WooCommerce\Payment;
use Mollie\Api\Exceptions\ApiException;
+use Mollie\Api\Resources\Order;
+use Mollie\Api\Resources\Payment;
use Mollie\Api\Resources\Refund;
use Mollie\WooCommerce\Gateway\MolliePaymentGateway;
+use Mollie\WooCommerce\Gateway\MolliePaymentGatewayI;
use Mollie\WooCommerce\PaymentMethods\Voucher;
use Mollie\WooCommerce\SDK\Api;
+use Mollie\WooCommerce\Shared\SharedDataDictionary;
use Psr\Log\LogLevel;
use WC_Order;
use WC_Payment_Gateway;
@@ -17,7 +21,6 @@
class MolliePayment extends MollieObject
{
-
public const ACTION_AFTER_REFUND_PAYMENT_CREATED = 'mollie-payments-for-woocommerce' . '_refund_payment_created';
protected $pluginId;
@@ -93,7 +96,7 @@ public function getPaymentRequestData($order, $customerId, $voucherDefaultCatego
'description' => $paymentDescription,
'redirectUrl' => $returnUrl,
'webhookUrl' => $webhookUrl,
- 'method' => $gateway->paymentMethod->getProperty('id'),
+ 'method' => $gateway->paymentMethod()->getProperty('id'),
'issuer' => $selectedIssuer,
'locale' => $paymentLocale,
'metadata' => apply_filters(
@@ -114,9 +117,8 @@ public function getPaymentRequestData($order, $customerId, $voucherDefaultCatego
if ($cardToken) {
$paymentRequestData['cardToken'] = $cardToken;
}
-
- if (isset($_POST['token'])) {
- $applePayToken = sanitize_text_field(wp_unslash($_POST['token']));
+ $applePayToken = filter_input(INPUT_POST, 'token', FILTER_SANITIZE_SPECIAL_CHARS) ?? false;
+ if ($applePayToken) {
$encodedApplePayToken = json_encode($applePayToken);
$paymentRequestData['applePayPaymentToken'] = $encodedApplePayToken;
}
@@ -129,6 +131,9 @@ public function addSequenceTypeFirst($paymentRequestData)
return $paymentRequestData;
}
+ /**
+ * @return void
+ */
public function setActiveMolliePayment($orderId)
{
self::$paymentId = $this->getMolliePaymentIdFromPaymentObject();
@@ -179,7 +184,10 @@ public function getSequenceTypeFromPaymentObject($payment = null)
return null;
}
-
+ /**
+ * @param Payment $payment
+ *
+ */
public function getMollieCustomerIbanDetailsFromPaymentObject($payment = null)
{
if ($payment === null) {
@@ -187,7 +195,9 @@ public function getMollieCustomerIbanDetailsFromPaymentObject($payment = null)
}
$payment = $this->getPaymentObject($payment);
-
+ /**
+ * @var Payment $payment
+ */
$ibanDetails['consumerName'] = $payment->details->consumerName;
$ibanDetails['consumerAccount'] = $payment->details->consumerAccount;
@@ -284,13 +294,13 @@ public function onWebhookCanceled(WC_Order $order, $payment, $paymentMethodTitle
// New order status
if ($orderStatusCancelledPayments === 'pending' || $orderStatusCancelledPayments === null) {
- $newOrderStatus = MolliePaymentGateway::STATUS_PENDING;
+ $newOrderStatus = SharedDataDictionary::STATUS_PENDING;
} elseif ($orderStatusCancelledPayments === 'cancelled') {
- $newOrderStatus = MolliePaymentGateway::STATUS_CANCELLED;
+ $newOrderStatus = SharedDataDictionary::STATUS_CANCELLED;
}
// if I cancel manually the order is canceled in Woo before calling Mollie
if ($order->get_status() === 'cancelled') {
- $newOrderStatus = MolliePaymentGateway::STATUS_CANCELLED;
+ $newOrderStatus = SharedDataDictionary::STATUS_CANCELLED;
}
// Get current gateway
@@ -332,7 +342,7 @@ public function onWebhookFailed(WC_Order $order, $payment, $paymentMethodTitle)
$gateway = wc_get_payment_gateway_by_order($order);
// New order status
- $newOrderStatus = MolliePaymentGateway::STATUS_FAILED;
+ $newOrderStatus = SharedDataDictionary::STATUS_FAILED;
// Overwrite plugin-wide
$newOrderStatus = apply_filters($this->pluginId . '_order_status_failed', $newOrderStatus);
@@ -393,7 +403,7 @@ public function onWebhookExpired(WC_Order $order, $payment, $paymentMethodTitle)
}
// New order status
- $newOrderStatus = MolliePaymentGateway::STATUS_CANCELLED;
+ $newOrderStatus = SharedDataDictionary::STATUS_CANCELLED;
//Get current gateway
$gateway = wc_get_payment_gateway_by_order($order);
// Overwrite plugin-wide
@@ -419,7 +429,7 @@ public function onWebhookExpired(WC_Order $order, $payment, $paymentMethodTitle)
/**
* Process a payment object refund
*
- * @param object $order
+ * @param WC_Order $order
* @param int $orderId
* @param object $paymentObject
* @param null $amount
@@ -499,7 +509,7 @@ public function refund(\WC_Order $order, $orderId, $paymentObject, $amount = nul
/**
* @param WC_Order $order
- * @param WC_Payment_Gateway|bool $gateway
+ * @param MolliePaymentGatewayI $gateway
* @param $newOrderStatus
* @param $orderId
*/
@@ -508,10 +518,11 @@ protected function maybeUpdateStatus(
$gateway,
$newOrderStatus
) {
+
if ($this->isOrderPaymentStartedByOtherGateway($order) || ! is_a($gateway, MolliePaymentGateway::class)) {
$this->informNotUpdatingStatus($gateway->id, $order);
return;
}
- $gateway->paymentService->updateOrderStatus($order, $newOrderStatus);
+ $gateway->paymentService()->updateOrderStatus($order, $newOrderStatus);
}
}
diff --git a/src/Payment/MollieSubscription.php b/src/Payment/MollieSubscription.php
index d1db878c2..1754bb619 100644
--- a/src/Payment/MollieSubscription.php
+++ b/src/Payment/MollieSubscription.php
@@ -1,9 +1,7 @@
pluginId = $pluginId;
$this->apiHelper = $apiHelper;
@@ -58,7 +56,7 @@ public function getRecurringPaymentRequestData($order, $customerId, $initialPaym
'description' => $paymentDescription,
'redirectUrl' => $returnUrl,
'webhookUrl' => $webhookUrl,
- 'method' => $gateway->paymentMethod->getProperty('id'),
+ 'method' => $gateway->paymentMethod()->getProperty('id'),
'issuer' => $selectedIssuer,
'locale' => $paymentLocale,
'metadata' => [
@@ -74,7 +72,7 @@ protected function getRecurringPaymentDescription($order, $option, $initialPayme
$description = !$option ? '' : trim($option);
// Also use default when Order API was used on initial payment to match payment descriptions.
- if ( !$description || $initialPaymentUsedOrderAPI ) {
+ if (!$description || $initialPaymentUsedOrderAPI) {
$description = sprintf(
/* translators: Placeholder 1: order number */
_x(
@@ -99,22 +97,22 @@ protected function getRecurringPaymentDescription($order, $option, $initialPayme
public function isAvailableForSubscriptions(bool $status, MollieSubscriptionGateway $subscriptionGateway, $orderTotal): bool
{
$subscriptionPluginActive = class_exists('WC_Subscriptions') && class_exists('WC_Subscriptions_Admin');
- if(!$subscriptionPluginActive){
+ if (!$subscriptionPluginActive) {
return $status;
}
$currency = $subscriptionGateway->getCurrencyFromOrder();
$billingCountry = $subscriptionGateway->getBillingCountry();
- $paymentLocale = $subscriptionGateway->dataService->getPaymentLocale();
+ $paymentLocale = $subscriptionGateway->dataService()->getPaymentLocale();
// Check recurring totals against recurring payment methods for future renewal payments
$recurringTotal = $subscriptionGateway->get_recurring_total();
// See get_available_payment_gateways() in woocommerce-subscriptions/includes/gateways/class-wc-subscriptions-payment-gateways.php
$acceptManualRenewals = 'yes' === get_option(
- \WC_Subscriptions_Admin::$option_prefix
+ \WC_Subscriptions_Admin::$option_prefix
. '_accept_manual_renewals',
- 'no'
- );
+ 'no'
+ );
$supportsSubscriptions = $subscriptionGateway->supports('subscriptions');
- if($acceptManualRenewals === true || !$supportsSubscriptions || empty($recurringTotal)){
+ if ($acceptManualRenewals === true || !$supportsSubscriptions || empty($recurringTotal)) {
return $status;
}
foreach ($recurringTotal as $recurring_total) {
@@ -130,7 +128,7 @@ public function isAvailableForSubscriptions(bool $status, MollieSubscriptionGate
}
// Check available first payment methods with today's order total, but ignore SSD gateway (not shown in checkout)
- if ($subscriptionGateway->id === 'mollie_wc_gateway_directdebit') {
+ if ($subscriptionGateway->paymentMethod()->getProperty('id') === 'mollie_wc_gateway_directdebit') {
return $status;
}
$filters = $this->buildFilters(
@@ -158,6 +156,7 @@ protected function buildFilters(
string $sequenceType,
string $paymentLocale
): array {
+
$filters = [
'amount' => [
'currency' => $currency,
diff --git a/src/Payment/OrderInstructionsService.php b/src/Payment/OrderInstructionsService.php
index 7ae4db7fe..bac70c4a4 100644
--- a/src/Payment/OrderInstructionsService.php
+++ b/src/Payment/OrderInstructionsService.php
@@ -4,7 +4,7 @@
namespace Mollie\WooCommerce\Payment;
-use Mollie\WooCommerce\Gateway\MolliePaymentGateway;
+use Mollie\WooCommerce\Gateway\MolliePaymentGatewayI;
use Mollie\WooCommerce\PaymentMethods\InstructionStrategies\DefaultInstructionStrategy;
class OrderInstructionsService
@@ -12,16 +12,16 @@ class OrderInstructionsService
protected $strategy;
public function setStrategy($gateway)
{
- if (!$gateway->paymentMethod->getProperty('instructions')) {
+ if (!$gateway->paymentMethod()->getProperty('instructions')) {
$this->strategy = new DefaultInstructionStrategy();
} else {
- $className = 'Mollie\\WooCommerce\\PaymentMethods\\InstructionStrategies\\' . ucfirst($gateway->paymentMethod->getProperty('id')) . 'InstructionStrategy';
+ $className = 'Mollie\\WooCommerce\\PaymentMethods\\InstructionStrategies\\' . ucfirst($gateway->paymentMethod()->getProperty('id')) . 'InstructionStrategy';
$this->strategy = class_exists($className) ? new $className() : new DefaultInstructionStrategy();
}
}
public function executeStrategy(
- MolliePaymentGateway $gateway,
+ MolliePaymentGatewayI $gateway,
$payment,
$order = null,
$admin_instructions = false
diff --git a/src/Payment/OrderLines.php b/src/Payment/OrderLines.php
index 3e7c88745..440bda158 100644
--- a/src/Payment/OrderLines.php
+++ b/src/Payment/OrderLines.php
@@ -12,7 +12,6 @@
class OrderLines
{
-
/**
* Formatted order lines.
*
@@ -89,10 +88,10 @@ private function get_order_lines()
*/
private function process_items($voucherDefaultCategory)
{
- $voucherSettings = get_option('mollie_wc_gateway_voucher_settings')?:get_option('mollie_wc_gateway_mealvoucher_settings');
+ $voucherSettings = get_option('mollie_wc_gateway_voucher_settings') ?: get_option('mollie_wc_gateway_mealvoucher_settings');
$isMealVoucherEnabled = $voucherSettings ? ($voucherSettings['enabled'] == 'yes') : false;
if (!$voucherSettings) {
- $isMealVoucherEnabled = $this->dataHelper->getPaymentMethod('voucher')?true:false;
+ $isMealVoucherEnabled = $this->dataHelper->getPaymentMethod('voucher') ? true : false;
}
foreach ($this->order->get_items() as $cart_item) {
@@ -379,12 +378,13 @@ private function get_item_quantity($cart_item)
*
* Returns SKU or product ID.
*
- * @since 1.0
+ * @since 1.0
+ *
* @access private
*
- * @param object $product Product object.
+ * @param object $product Product object.
*
- * @return string $item_reference Cart item reference.
+ * @return false|string $item_reference Cart item reference.
*/
private function get_item_reference($product)
{
@@ -534,12 +534,13 @@ private function get_shipping_id()
/**
* Get shipping method amount.
*
- * @since 1.0
+ * @since 1.0
+ *
* @access private
*
- * @return integer $shipping_amount Amount for selected shipping method.
+ * @return string $shipping_amount Amount for selected shipping method.
*/
- private function get_shipping_amount()
+ private function get_shipping_amount(): string
{
return number_format(( WC()->cart->shipping_total + WC()->cart->shipping_tax_total ), 2, '.', '');
}
@@ -547,10 +548,13 @@ private function get_shipping_amount()
/**
* Get shipping method tax rate.
*
- * @since 1.0
+ * @since 1.0
+ *
* @access private
*
- * @return integer $shipping_vat_rate Tax rate for selected shipping method.
+ * @return float|int $shipping_vat_rate Tax rate for selected shipping method.
+ *
+ * @psalm-return 0|float
*/
private function get_shipping_vat_rate()
{
diff --git a/src/Payment/PaymentCheckoutRedirectService.php b/src/Payment/PaymentCheckoutRedirectService.php
index 7b30722b2..7c50a2989 100644
--- a/src/Payment/PaymentCheckoutRedirectService.php
+++ b/src/Payment/PaymentCheckoutRedirectService.php
@@ -35,8 +35,8 @@ public function setStrategy($paymentMethod)
return;
}
$className = 'Mollie\\WooCommerce\\PaymentMethods\\PaymentRedirectStrategies\\' . ucfirst(
- $paymentMethod->getProperty('id')
- ) . 'RedirectStrategy';
+ $paymentMethod->getProperty('id')
+ ) . 'RedirectStrategy';
$this->strategy = class_exists($className) ? new $className() : new DefaultRedirectStrategy();
}
diff --git a/src/Payment/PaymentFactory.php b/src/Payment/PaymentFactory.php
index a9d516e17..051348158 100644
--- a/src/Payment/PaymentFactory.php
+++ b/src/Payment/PaymentFactory.php
@@ -54,10 +54,9 @@ public function getPaymentObject($data)
if (
(!is_object($data) && $data === 'order')
- || (!is_object($data) && strpos($data, 'ord_') !== false)
+ || (is_string($data) && strpos($data, 'ord_') !== false)
|| (is_object($data) && $data->resource === 'order')
) {
-
$refundLineItemsBuilder = new RefundLineItemsBuilder($this->dataHelper);
$apiKey = $this->settingsHelper->getApiKey();
$orderItemsRefunded = new OrderItemsRefunder(
diff --git a/src/Payment/PaymentModule.php b/src/Payment/PaymentModule.php
index 6ad1d2b0c..1bdef2705 100644
--- a/src/Payment/PaymentModule.php
+++ b/src/Payment/PaymentModule.php
@@ -12,10 +12,12 @@
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Refund;
use Mollie\WooCommerce\Gateway\MolliePaymentGateway;
+use Mollie\WooCommerce\Gateway\MolliePaymentGatewayI;
use Mollie\WooCommerce\SDK\Api;
use Mollie\WooCommerce\SDK\HttpResponse;
use Mollie\WooCommerce\Settings\Settings;
use Mollie\WooCommerce\Shared\Data;
+use Mollie\WooCommerce\Shared\SharedDataDictionary;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface as Logger;
use Psr\Log\LogLevel;
@@ -79,7 +81,7 @@ public function services(): array
$settingsHelper = $container->get('settings.settings_helper');
assert($settingsHelper instanceof Settings);
return new MollieObject($data, $logger, $paymentFactory, $apiHelper, $settingsHelper, $pluginId);
- }
+ },
];
}
@@ -189,7 +191,7 @@ public function cancelOrderOnExpiryDate()
foreach ($unpaid_orders as $unpaid_order) {
$order = wc_get_order($unpaid_order);
add_filter('mollie-payments-for-woocommerce_order_status_cancelled', static function ($newOrderStatus) {
- return MolliePaymentGateway::STATUS_CANCELLED;
+ return SharedDataDictionary::STATUS_CANCELLED;
});
$order->update_status('cancelled', __('Unpaid order cancelled - time limit reached.', 'woocommerce'), true);
$this->cancelOrderAtMollie($order->get_id());
@@ -318,7 +320,7 @@ public function onOrderDetails(WC_Order $order)
return;
}
- /** @var MolliePaymentGateway $gateway */
+ /** @var MolliePaymentGatewayI $gateway */
$gateway->displayInstructions($order);
}
@@ -513,12 +515,12 @@ public function IsExpiryDateEnabled($paymentMethods): bool
/**
* Returns the order from the Request first by Id, if not by Key
*
- * @return bool|WC_Order
+ * @return WC_Order|\WC_Order_Refund|true
*/
public function orderByRequest()
{
$orderId = filter_input(INPUT_GET, 'order_id', FILTER_SANITIZE_NUMBER_INT) ?: null;
- $key = sanitize_text_field(wp_unslash($_GET['key'])) ?: null;
+ $key = filter_input(INPUT_GET, 'key', FILTER_SANITIZE_SPECIAL_CHARS) ?? null;
$order = wc_get_order($orderId);
if (!$order) {
diff --git a/src/Payment/PaymentService.php b/src/Payment/PaymentService.php
index 1a46df963..2d015a2e3 100644
--- a/src/Payment/PaymentService.php
+++ b/src/Payment/PaymentService.php
@@ -7,12 +7,14 @@
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Payment;
use Mollie\WooCommerce\Gateway\MolliePaymentGateway;
+use Mollie\WooCommerce\Gateway\MolliePaymentGatewayI;
use Mollie\WooCommerce\Gateway\Surcharge;
use Mollie\WooCommerce\Notice\NoticeInterface;
use Mollie\WooCommerce\PaymentMethods\PaymentMethodI;
use Mollie\WooCommerce\SDK\Api;
use Mollie\WooCommerce\Settings\Settings;
use Mollie\WooCommerce\Shared\Data;
+use Mollie\WooCommerce\Shared\SharedDataDictionary;
use Psr\Log\LoggerInterface as Logger;
use Psr\Log\LogLevel;
use WC_Order;
@@ -22,7 +24,7 @@ class PaymentService
public const PAYMENT_METHOD_TYPE_ORDER = 'order';
public const PAYMENT_METHOD_TYPE_PAYMENT = 'payment';
/**
- * @var MolliePaymentGateway
+ * @var MolliePaymentGatewayI
*/
protected $gateway;
/**
@@ -53,10 +55,9 @@ class PaymentService
*/
protected $voucherDefaultCategory;
-
/**
- * PaymentService constructor.
- */
+ * PaymentService constructor.
+ */
public function __construct(
NoticeInterface $notice,
Logger $logger,
@@ -67,8 +68,8 @@ public function __construct(
string $pluginId,
PaymentCheckoutRedirectService $paymentCheckoutRedirectService,
string $voucherDefaultCategory
- )
- {
+ ) {
+
$this->notice = $notice;
$this->logger = $logger;
$this->paymentFactory = $paymentFactory;
@@ -92,15 +93,11 @@ public function processPayment($orderId, $order, $paymentMethod, $redirectUrl)
[true]
);
$initialOrderStatus = $this->processInitialOrderStatus($paymentMethod);
-
-
$customerId = $this->getUserMollieCustomerId($order);
-
$apiKey = $this->settingsHelper->getApiKey();
-
$hasBlocksEnabled = $this->dataHelper->isBlockPluginActive();
$isClassicCheckout = isset($_REQUEST["wc-ajax"]) && $_REQUEST["wc-ajax"] === "checkout";
- if($hasBlocksEnabled && !$isClassicCheckout){
+ if ($hasBlocksEnabled && !$isClassicCheckout) {
$order = $this->correctSurchargeFee($order, $paymentMethod);
}
@@ -140,7 +137,8 @@ public function processPayment($orderId, $order, $paymentMethod, $redirectUrl)
),
];
} catch (ApiException $error) {
- $this->reportPaymentCreationFailure($orderId, $error);
+ $paymentMethodId = $paymentMethod->getProperty('id');
+ $this->reportPaymentCreationFailure($orderId, $error, $paymentMethodId);
}
return ['result' => 'failure'];
}
@@ -156,7 +154,7 @@ 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);
+ $amount = $aboveMaxLimit ? 0 : $surcharge->calculateFeeAmountOrder($order, $gatewaySettings);
$gatewayHasSurcharge = $amount !== 0;
$gatewayFeeLabel = get_option(
'mollie-payments-for-woocommerce_gatewayFeeLabel',
@@ -169,11 +167,11 @@ protected function correctSurchargeFee($order, $paymentMethod)
$feeId = $fee->get_id();
$hasMollieFee = strpos($feeName, $gatewayFeeLabel) !== false;
if ($hasMollieFee) {
- if($amount == (float) $fee->get_amount('edit')){
+ if ($amount == (float)$fee->get_amount('edit')) {
$correctedFee = true;
continue;
}
- if(!$gatewayHasSurcharge){
+ if (!$gatewayHasSurcharge) {
$this->removeOrderFee($order, $feeId);
$correctedFee = true;
continue;
@@ -184,7 +182,7 @@ protected function correctSurchargeFee($order, $paymentMethod)
}
}
if (!$correctedFee) {
- if($gatewayHasSurcharge){
+ if ($gatewayHasSurcharge) {
$this->orderAddFee($order, $amount, $gatewayFeeLabel);
}
}
@@ -204,7 +202,6 @@ protected function removeOrderFee(\WC_Order $order, int $feeId): \WC_Order
return $order;
}
-
protected function orderAddFee($order, $amount, $surchargeName)
{
$item_fee = new \WC_Order_Item_Fee();
@@ -220,7 +217,7 @@ protected function orderAddFee($order, $amount, $surchargeName)
/**
* Redirect location after successfully completing process_payment
*
- * @param WC_Order $order
+ * @param WC_Order $order
* @param MollieOrder|MolliePayment $paymentObject
*
* @return string
@@ -231,6 +228,7 @@ public function getProcessPaymentRedirect(
$paymentObject,
string $redirectUrl
): string {
+
$this->paymentCheckoutRedirectService->setStrategy($paymentMethod);
return $this->paymentCheckoutRedirectService->executeStrategy(
$paymentMethod,
@@ -239,6 +237,7 @@ public function getProcessPaymentRedirect(
$redirectUrl
);
}
+
/**
* @param $order
* @param $test_mode
@@ -249,21 +248,22 @@ protected function getUserMollieCustomerId($order)
$order_customer_id = $order->get_customer_id();
$apiKey = $this->settingsHelper->getApiKey();
- return $this->dataHelper->getUserMollieCustomerId($order_customer_id, $apiKey);
+ return $this->dataHelper->getUserMollieCustomerId($order_customer_id, $apiKey);
}
protected function paymentTypeBasedOnGateway($paymentMethod)
{
- $optionName = $this->pluginId . '_' .'api_switch';
+ $optionName = $this->pluginId . '_' . 'api_switch';
$apiSwitchOption = get_option($optionName);
- $paymentType = $apiSwitchOption?: self::PAYMENT_METHOD_TYPE_ORDER;
+ $paymentType = $apiSwitchOption ?: self::PAYMENT_METHOD_TYPE_ORDER;
$isBankTransferGateway = $paymentMethod->getProperty('id') === 'banktransfer';
- if($isBankTransferGateway && $paymentMethod->isExpiredDateSettingActivated()){
+ if ($isBankTransferGateway && $paymentMethod->isExpiredDateSettingActivated()) {
$paymentType = self::PAYMENT_METHOD_TYPE_PAYMENT;
}
return $paymentType;
}
+
/**
* CHECK WOOCOMMERCE PRODUCTS
* Make sure all cart items are real WooCommerce products,
@@ -272,7 +272,7 @@ protected function paymentTypeBasedOnGateway($paymentMethod)
*
* @param \WC_Order $order
*
- * @param string $molliePaymentType
+ * @param string $molliePaymentType
*
* @return string
*/
@@ -310,11 +310,12 @@ protected function paymentTypeBasedOnProducts($order, $molliePaymentType)
}
return $molliePaymentType;
}
+
/**
* @param MollieOrder $paymentObject
- * @param \WC_Order $order
- * @param $customer_id
- * @param $test_mode
+ * @param \WC_Order $order
+ * @param $customer_id
+ * @param $test_mode
*
* @return array
* @throws ApiException
@@ -325,6 +326,7 @@ protected function processAsMollieOrder(
$customer_id,
$apiKey
) {
+
$molliePaymentType = self::PAYMENT_METHOD_TYPE_ORDER;
$paymentRequestData = $paymentObject->getPaymentRequestData(
$order,
@@ -367,29 +369,35 @@ protected function processAsMollieOrder(
: '',
'orderNumber' => isset($data['orderNumber'])
? $data['orderNumber'] : '',
- 'lines' => isset($data['lines']) ? $data['lines'] : ''
+ 'lines' => isset($data['lines']) ? $data['lines'] : '',
];
- $this->logger->debug( json_encode($apiCallLog));
+ $this->logger->debug(json_encode($apiCallLog));
$paymentOrder = $paymentObject;
$paymentObject = $this->apiHelper->getApiClient($apiKey)->orders->create($data);
- $this->logger->debug( json_encode($paymentObject));
+ $this->logger->debug(json_encode($paymentObject));
$settingsHelper = $this->settingsHelper;
- if($settingsHelper->getOrderStatusCancelledPayments() === 'cancelled'){
+ if ($settingsHelper->getOrderStatusCancelledPayments() === 'cancelled') {
$orderId = $order->get_id();
- $orderWithPayments = $this->apiHelper->getApiClient($apiKey)->orders->get( $paymentObject->id, [ "embed" => "payments" ] );
+ $orderWithPayments = $this->apiHelper->getApiClient($apiKey)->orders->get(
+ $paymentObject->id,
+ ["embed" => "payments"]
+ );
$paymentOrder->updatePaymentDataWithOrderData($orderWithPayments, $orderId);
}
} catch (ApiException $e) {
// Don't try to create a Mollie Payment for Klarna payment methods
$order_payment_method = $order->get_payment_method();
+ $orderMandatoryPaymentMethods = [
+ 'mollie_wc_gateway_klarnapaylater',
+ 'mollie_wc_gateway_klarnasliceit',
+ 'mollie_wc_gateway_klarnapaynow',
+ 'mollie_wc_gateway_billie',
+ ];
- if ($order_payment_method === 'mollie_wc_gateway_klarnapaylater'
- || $order_payment_method === 'mollie_wc_gateway_sliceit'
- || $order_payment_method === 'mollie_wc_gateway_klarnapaynow'
- ) {
+ if (in_array($order_payment_method, $orderMandatoryPaymentMethods)) {
$this->logger->debug(
- 'Creating payment object: type Order, failed for Klarna payment, stopping process.'
+ 'Creating payment object: type Order failed, stopping process.'
);
throw $e;
}
@@ -422,16 +430,13 @@ protected function processAsMollieOrder(
$molliePaymentType = self::PAYMENT_METHOD_TYPE_PAYMENT;
}
}
- return array(
- $paymentObject,
- $molliePaymentType
- );
+ return [$paymentObject, $molliePaymentType];
}
/**
- * @param \WC_Order $order
- * @param $customer_id
- * @param $test_mode
+ * @param \WC_Order $order
+ * @param $customer_id
+ * @param $test_mode
*
* @return Payment $paymentObject
* @throws ApiException
@@ -441,6 +446,7 @@ protected function processAsMolliePayment(
$customer_id,
$apiKey
) {
+
$paymentObject = $this->paymentFactory->getPaymentObject(
self::PAYMENT_METHOD_TYPE_PAYMENT
);
@@ -472,10 +478,10 @@ protected function processAsMolliePayment(
'locale' => isset($data['locale']) ? $data['locale'] : '',
'dueDate' => isset($data['dueDate']) ? $data['dueDate'] : '',
'metadata' => isset($data['metadata']) ? $data['metadata']
- : ''
+ : '',
];
- $this->logger->debug( $apiCallLog);
+ $this->logger->debug($apiCallLog);
// Try as simple payment
$paymentObject = $this->apiHelper->getApiClient(
@@ -483,19 +489,19 @@ protected function processAsMolliePayment(
)->payments->create($data);
} catch (ApiException $e) {
$message = $e->getMessage();
- $this->logger->debug( $message);
+ $this->logger->debug($message);
throw $e;
}
return $paymentObject;
}
/**
- * @param $molliePaymentType
- * @param $orderId
+ * @param $molliePaymentType
+ * @param $orderId
* @param MollieOrder|MolliePayment $paymentObject
- * @param \WC_Order $order
- * @param $customer_id
- * @param $test_mode
+ * @param \WC_Order $order
+ * @param $customer_id
+ * @param $test_mode
*
* @return mixed|Payment|MollieOrder
* @throws ApiException
@@ -517,11 +523,7 @@ protected function processPaymentForMollie(
[true]
);
- list(
- $paymentObject,
- $molliePaymentType
- )
- = $this->processAsMollieOrder(
+ list($paymentObject, $molliePaymentType) = $this->processAsMollieOrder(
$paymentObject,
$order,
$customer_id,
@@ -551,18 +553,19 @@ protected function processPaymentForMollie(
* @param $order
* @param $payment
*/
- protected function saveMollieInfo( $order, $payment ) {
+ protected function saveMollieInfo($order, $payment)
+ {
// Get correct Mollie Payment Object
- $payment_object = $this->paymentFactory->getPaymentObject( $payment );
+ $payment_object = $this->paymentFactory->getPaymentObject($payment);
// Set active Mollie payment
- $payment_object->setActiveMolliePayment( $order->get_id() );
+ $payment_object->setActiveMolliePayment($order->get_id());
// Get Mollie Customer ID
- $mollie_customer_id = $payment_object->getMollieCustomerIdFromPaymentObject( $payment_object->data->id );
+ $mollie_customer_id = $payment_object->getMollieCustomerIdFromPaymentObject($payment_object->data()->id);
// Set Mollie customer
- $this->dataHelper->setUserMollieCustomerId( $order->get_customer_id(), $mollie_customer_id );
+ $this->dataHelper->setUserMollieCustomerId($order->get_customer_id(), $mollie_customer_id);
}
/**
@@ -571,42 +574,37 @@ protected function saveMollieInfo( $order, $payment ) {
* @param string $note
* @param bool $restore_stock
*/
- public function updateOrderStatus (\WC_Order $order, $new_status, $note = '', $restore_stock = true )
+ public function updateOrderStatus(\WC_Order $order, $new_status, $note = '', $restore_stock = true)
{
$order->update_status($new_status, $note);
- switch ($new_status)
- {
- case MolliePaymentGateway::STATUS_ON_HOLD:
-
- if ( $restore_stock === true ) {
- if ( ! $order->get_meta( '_order_stock_reduced', true ) ) {
+ switch ($new_status) {
+ case SharedDataDictionary::STATUS_ON_HOLD:
+ if ($restore_stock === true) {
+ if (!$order->get_meta('_order_stock_reduced', true)) {
// Reduce order stock
- wc_reduce_stock_levels( $order->get_id() );
+ wc_reduce_stock_levels($order->get_id());
- $this->logger->debug( __METHOD__ . ": Stock for order {$order->get_id()} reduced." );
+ $this->logger->debug(__METHOD__ . ": Stock for order {$order->get_id()} reduced.");
}
}
break;
- case MolliePaymentGateway::STATUS_PENDING:
- case MolliePaymentGateway::STATUS_FAILED:
- case MolliePaymentGateway::STATUS_CANCELLED:
- if ( $order->get_meta( '_order_stock_reduced', true ) )
- {
+ case SharedDataDictionary::STATUS_PENDING:
+ case SharedDataDictionary::STATUS_FAILED:
+ case SharedDataDictionary::STATUS_CANCELLED:
+ if ($order->get_meta('_order_stock_reduced', true)) {
// Restore order stock
$this->dataHelper->restoreOrderStock($order);
- $this->logger->debug( __METHOD__ . " Stock for order {$order->get_id()} restored.");
+ $this->logger->debug(__METHOD__ . " Stock for order {$order->get_id()} restored.");
}
break;
}
}
-
-
/**
* @param $orderId
*/
@@ -627,19 +625,25 @@ protected function noValidMandateForSubsSwitchFailure($orderId): void
);
}
- protected function subsSwitchCompleted($order):array
+ protected function subsSwitchCompleted($order): array
{
$order->payment_complete();
- $order->add_order_note( sprintf(
- __( 'Order completed internally because of an existing valid mandate at Mollie.', 'mollie-payments-for-woocommerce' ) ) );
+ $order->add_order_note(
+ sprintf(
+ __(
+ 'Order completed internally because of an existing valid mandate at Mollie.',
+ 'mollie-payments-for-woocommerce'
+ )
+ )
+ );
- $this->logger->debug( $this->gateway->id . ': Subscription switch completed, valid mandate for order #' . $orderId );
+ $this->logger->debug($this->gateway->id . ': Subscription switch completed, valid mandate for order #' . $order->get_id());
- return array (
- 'result' => 'success',
- 'redirect' => $this->gateway->get_return_url( $order ),
- );
+ return [
+ 'result' => 'success',
+ 'redirect' => $this->gateway->get_return_url($order),
+ ];
}
/**
@@ -676,36 +680,36 @@ protected function processSubscriptionSwitch(WC_Order $order, int $orderId, ?str
// PROCESS SUBSCRIPTION SWITCH - If this is a subscription switch and customer has a valid mandate, process the order internally
//
try {
- $this->logger->debug( $this->gateway->id . ': Subscription switch started, fetching mandate(s) for order #' . $orderId);
+ $this->logger->debug($this->gateway->id . ': Subscription switch started, fetching mandate(s) for order #' . $orderId);
$validMandate = $this->processValidMandate($order, $customerId, $apiKey);
- if ( $validMandate ) {
+ if ($validMandate) {
return $this->subsSwitchCompleted($order);
} else {
$this->noValidMandateForSubsSwitchFailure($orderId);
}
- }
- catch ( ApiException $e ) {
- if ( $e->getField() ) {
+ } catch (ApiException $e) {
+ if ($e->getField()) {
throw $e;
}
}
- return array ( 'result' => 'failure' );
+ return ['result' => 'failure'];
}
/**
* @param $orderId
* @param $e
+ * @param $paymentMethodId
*/
- protected function reportPaymentCreationFailure($orderId, $e): void
+ protected function reportPaymentCreationFailure($orderId, $e, $paymentMethodId): void
{
$this->logger->debug(
- $this->id . ': Failed to create Mollie payment object for order ' . $orderId . ': ' . $e->getMessage(
- )
+ $paymentMethodId . ': Failed to create Mollie payment object for order ' . $orderId . ': ' . $e->getMessage(
+ )
);
/* translators: Placeholder 1: Payment method title */
- $message = sprintf(__('Could not create %s payment.', 'mollie-payments-for-woocommerce'), $this->title);
+ $message = sprintf(__('Could not create %s payment.', 'mollie-payments-for-woocommerce'), $paymentMethodId);
if (defined('WP_DEBUG') && WP_DEBUG) {
$message .= 'hii ' . $e->getMessage();
@@ -729,6 +733,7 @@ protected function saveSubscriptionMandateData(
$paymentObject,
$order
): void {
+
$dataHelper = $this->dataHelper;
if ($dataHelper->isSubscription($orderId)) {
$mandates = $this->apiHelper->getApiClient($apiKey)->customers->get($customerId)->mandates();
@@ -759,7 +764,7 @@ protected function updatePaymentStatusForDelayedMethods($paymentObject, $order,
$order_status = $order->get_status();
- if ($order_status != 'wc-partially-paid ') {
+ if ($order_status !== 'wc-partially-paid ') {
$this->updateOrderStatus(
$order,
$initialOrderStatus,
@@ -783,12 +788,12 @@ protected function reportPaymentSuccess($paymentObject, $orderId, $order, $payme
$order->add_order_note(
sprintf(
/* translators: Placeholder 1: Payment method title, placeholder 2: payment ID */
- __('%s payment started (%s).', 'mollie-payments-for-woocommerce'),
+ __('%1$s payment started (%2$s).', 'mollie-payments-for-woocommerce'),
$paymentMethodTitle,
$paymentObject->id . ($paymentObject->mode === 'test' ? (' - ' . __(
- 'test mode',
- 'mollie-payments-for-woocommerce'
- )) : '')
+ 'test mode',
+ 'mollie-payments-for-woocommerce'
+ )) : '')
)
);
@@ -817,7 +822,7 @@ protected function needsSubscriptionSwitch($order, $orderId): bool
protected function paymentObjectFailure($exception): array
{
$this->logger->debug($exception->getMessage());
- return array('result' => 'failure');
+ return ['result' => 'failure'];
}
/**
@@ -828,13 +833,13 @@ protected function processInitialOrderStatus($paymentMethod)
$initialOrderStatus = $paymentMethod->getInitialOrderStatus();
// Overwrite plugin-wide
$initialOrderStatus = apply_filters(
- $this->pluginId . '_initial_order_status', $initialOrderStatus
+ $this->pluginId . '_initial_order_status',
+ $initialOrderStatus
);
// Overwrite gateway-wide
- $initialOrderStatus = apply_filters(
+ return apply_filters(
$this->pluginId . '_initial_order_status_' . $paymentMethod->getProperty('id'),
$initialOrderStatus
);
- return $initialOrderStatus;
}
}
diff --git a/src/PaymentMethods/AbstractPaymentMethod.php b/src/PaymentMethods/AbstractPaymentMethod.php
index fc081f45c..359a83c9c 100644
--- a/src/PaymentMethods/AbstractPaymentMethod.php
+++ b/src/PaymentMethods/AbstractPaymentMethod.php
@@ -8,21 +8,22 @@
use Mollie\WooCommerce\Gateway\Surcharge;
use Mollie\WooCommerce\Payment\PaymentFieldsService;
use Mollie\WooCommerce\Settings\Settings;
+use Mollie\WooCommerce\Shared\SharedDataDictionary;
abstract class AbstractPaymentMethod implements PaymentMethodI
{
/**
* @var string
*/
- public $id;
+ protected $id;
/**
* @var string[]
*/
- public $config = [];
+ protected $config = [];
/**
* @var array
*/
- public $settings = [];
+ protected $settings = [];
/**
* @var IconFactory
*/
@@ -34,7 +35,7 @@ abstract class AbstractPaymentMethod implements PaymentMethodI
/**
* @var PaymentFieldsService
*/
- public $paymentFieldsService;
+ protected $paymentFieldsService;
/**
* @var Surcharge
*/
@@ -78,7 +79,7 @@ public function surcharge()
* Check if the payment method has surcharge applied
* @return bool
*/
- public function hasSurcharge()
+ public function hasSurcharge(): bool
{
return $this->getProperty('payment_surcharge')
&& $this->getProperty('payment_surcharge') !== Surcharge::NO_FEE;
@@ -100,7 +101,7 @@ public function hasPaymentFields(): bool
public function getIconUrl(): string
{
return $this->iconFactory->getIconUrl(
- $this->getProperty('id')
+ $this->getIdFromConfig()
);
}
@@ -147,6 +148,14 @@ public function paymentFieldsStrategy($gateway)
$this->paymentFieldsService->executeStrategy($gateway);
}
+ /**
+ * @return PaymentFieldsService
+ */
+ public function paymentFieldsService(): PaymentFieldsService
+ {
+ return $this->paymentFieldsService;
+ }
+
/**
* Access the payment method processed description, surcharge included
* @return mixed|string
@@ -161,9 +170,9 @@ public function getProcessedDescription()
/**
* Access the payment method description for the checkout blocks
- * @return false|string|void
+ * @return string
*/
- public function getProcessedDescriptionForBlock()
+ public function getProcessedDescriptionForBlock(): string
{
return $this->surcharge->buildDescriptionWithSurchargeForBlock($this);
}
@@ -202,10 +211,10 @@ public function getInitialOrderStatus(): string
{
if ($this->getProperty('confirmationDelayed')) {
return $this->getProperty('initial_order_status')
- ?: MolliePaymentGateway::STATUS_ON_HOLD;
+ ?: SharedDataDictionary::STATUS_ON_HOLD;
}
- return MolliePaymentGateway::STATUS_PENDING;
+ return SharedDataDictionary::STATUS_PENDING;
}
/**
@@ -250,6 +259,6 @@ public function defaultSettings(): array
$fields = array_filter($fields, static function ($key) {
return !is_numeric($key);
}, ARRAY_FILTER_USE_KEY);
- return array_combine(array_keys($fields), array_column($fields, 'default'));
+ return array_combine(array_keys($fields), array_column($fields, 'default')) ?: [];
}
}
diff --git a/src/PaymentMethods/Bancontact.php b/src/PaymentMethods/Bancontact.php
index 4709b043b..9d01c9d93 100644
--- a/src/PaymentMethods/Bancontact.php
+++ b/src/PaymentMethods/Bancontact.php
@@ -6,7 +6,6 @@
class Bancontact extends AbstractPaymentMethod implements PaymentMethodI
{
-
protected function getConfig(): array
{
return [
diff --git a/src/PaymentMethods/Banktransfer.php b/src/PaymentMethods/Banktransfer.php
index d35943e7d..a34ced8b4 100644
--- a/src/PaymentMethods/Banktransfer.php
+++ b/src/PaymentMethods/Banktransfer.php
@@ -8,7 +8,6 @@
class Banktransfer extends AbstractPaymentMethod implements PaymentMethodI
{
-
/**
* @var int
*/
diff --git a/src/PaymentMethods/Billie.php b/src/PaymentMethods/Billie.php
new file mode 100644
index 000000000..42ceab75d
--- /dev/null
+++ b/src/PaymentMethods/Billie.php
@@ -0,0 +1,44 @@
+ 'billie',
+ 'defaultTitle' => __('Billie', 'mollie-payments-for-woocommerce'),
+ 'settingsDescription' => __(
+ 'To accept payments via Billie, all default WooCommerce checkout fields should be enabled and required.',
+ 'mollie-payments-for-woocommerce'
+ ),
+ 'defaultDescription' => '',
+ 'paymentFields' => false,
+ 'instructions' => false,
+ 'supports' => [
+ 'products',
+ 'refunds',
+ ],
+ 'filtersOnBuild' => false,
+ 'confirmationDelayed' => false,
+ 'SEPA' => false,
+ 'orderMandatory' => true,
+ 'errorMessage' => __(
+ 'Company field is empty. To proceed with Billie payment the company field is required.',
+ 'mollie-payments-for-woocommerce'
+ ),
+ 'companyPlaceholder' => __('To proceed with Billie, please enter your company name here.', 'mollie-payments-for-woocommerce'),
+ ];
+ }
+
+ public function getFormFields($generalFormFields): array
+ {
+ unset($generalFormFields[1]);
+ unset($generalFormFields['allowed_countries']);
+
+ return $generalFormFields;
+ }
+}
diff --git a/src/PaymentMethods/InstructionStrategies/ApplepayInstructionStrategy.php b/src/PaymentMethods/InstructionStrategies/ApplepayInstructionStrategy.php
index 2976f21fd..5926c61d7 100644
--- a/src/PaymentMethods/InstructionStrategies/ApplepayInstructionStrategy.php
+++ b/src/PaymentMethods/InstructionStrategies/ApplepayInstructionStrategy.php
@@ -6,7 +6,6 @@
class ApplepayInstructionStrategy implements InstructionStrategyI
{
-
public function execute(
$gateway,
$payment,
@@ -15,17 +14,16 @@ public function execute(
) {
if ($payment->isPaid() && $payment->details) {
- return
- sprintf(
- __(
- /* translators: Placeholder 1: PayPal consumer name, placeholder 2: PayPal email, placeholder 3: PayPal transaction ID */
- 'Payment completed by %1$s - %2$s (Apple Pay transaction ID: %3$s)',
- 'mollie-payments-for-woocommerce'
- ),
- $payment->details->consumerName,
- $payment->details->consumerAccount,
- $payment->details->paypalReference
- );
+ return sprintf(
+ /* translators: Placeholder 1: PayPal consumer name, placeholder 2: PayPal email, placeholder 3: PayPal transaction ID */
+ __(
+ 'Payment completed by %1$s - %2$s (Apple Pay transaction ID: %3$s)',
+ 'mollie-payments-for-woocommerce'
+ ),
+ $payment->details->consumerName,
+ $payment->details->consumerAccount,
+ $payment->details->paypalReference
+ );
}
$defaultStrategy = new DefaultInstructionStrategy();
return $defaultStrategy->execute($gateway, $payment, $admin_instructions);
diff --git a/src/PaymentMethods/InstructionStrategies/BanktransferInstructionStrategy.php b/src/PaymentMethods/InstructionStrategies/BanktransferInstructionStrategy.php
index 5efe13439..c8f9f23d7 100644
--- a/src/PaymentMethods/InstructionStrategies/BanktransferInstructionStrategy.php
+++ b/src/PaymentMethods/InstructionStrategies/BanktransferInstructionStrategy.php
@@ -6,7 +6,6 @@
class BanktransferInstructionStrategy implements InstructionStrategyI
{
-
public function execute(
$gateway,
$payment,
@@ -21,16 +20,19 @@ public function execute(
}
if ($payment->isPaid()) {
+ $consumerName = $payment->details->consumerName ?? '';
+ $consumerAccount = $payment->details->consumerAccount ? substr($payment->details->consumerAccount, -4) : '';
+ $consumerBic = $payment->details->consumerBic ?? '';
$instructions .= sprintf(
/* translators: Placeholder 1: consumer name, placeholder 2: consumer IBAN, placeholder 3: consumer BIC */
__('Payment completed by %1$s (IBAN (last 4 digits): %2$s, BIC: %3$s)', 'mollie-payments-for-woocommerce'),
- $payment->details->consumerName,
- substr($payment->details->consumerAccount, -4),
- $payment->details->consumerBic
+ $consumerName,
+ $consumerAccount,
+ $consumerBic
);
return $instructions;
}
- if (is_object($order) && ($order->has_status('on-hold') || $order->has_status('pending')) ) {
+ if (is_object($order) && ($order->has_status('on-hold') || $order->has_status('pending'))) {
if (!$admin_instructions) {
$instructions .= __('Please complete your payment by transferring the total amount to the following bank account:', 'mollie-payments-for-woocommerce') . "\n\n\n";
}
diff --git a/src/PaymentMethods/InstructionStrategies/CreditcardInstructionStrategy.php b/src/PaymentMethods/InstructionStrategies/CreditcardInstructionStrategy.php
index 3d9b315fc..2d66824ef 100644
--- a/src/PaymentMethods/InstructionStrategies/CreditcardInstructionStrategy.php
+++ b/src/PaymentMethods/InstructionStrategies/CreditcardInstructionStrategy.php
@@ -6,7 +6,6 @@
class CreditcardInstructionStrategy implements InstructionStrategyI
{
-
public function execute(
$gateway,
$payment,
diff --git a/src/PaymentMethods/InstructionStrategies/DefaultInstructionStrategy.php b/src/PaymentMethods/InstructionStrategies/DefaultInstructionStrategy.php
index 8a8fc5a41..e1a47949c 100644
--- a/src/PaymentMethods/InstructionStrategies/DefaultInstructionStrategy.php
+++ b/src/PaymentMethods/InstructionStrategies/DefaultInstructionStrategy.php
@@ -6,7 +6,6 @@
class DefaultInstructionStrategy implements InstructionStrategyI
{
-
public function execute(
$gateway,
$payment,
diff --git a/src/PaymentMethods/InstructionStrategies/DirectDebitInstructionTrait.php b/src/PaymentMethods/InstructionStrategies/DirectDebitInstructionTrait.php
new file mode 100644
index 000000000..2f521b670
--- /dev/null
+++ b/src/PaymentMethods/InstructionStrategies/DirectDebitInstructionTrait.php
@@ -0,0 +1,29 @@
+isPaid() && $payment->details) {
+ $consumerName = $payment->details->consumerName ?? '';
+ $consumerAccount = $payment->details->consumerAccount ? substr($payment->details->consumerAccount, -4) : '';
+ $consumerBic = $payment->details->consumerBic ?? '';
+ return sprintf(
+ /* translators: Placeholder 1: consumer name, placeholder 2: consumer IBAN, placeholder 3: consumer BIC */
+ __('Payment completed by %1$s (IBAN (last 4 digits): %2$s, BIC: %3$s)', 'mollie-payments-for-woocommerce'),
+ $consumerName,
+ $consumerAccount,
+ $consumerBic
+ );
+ }
+ $defaultStrategy = new DefaultInstructionStrategy();
+ return $defaultStrategy->execute($gateway, $payment, $admin_instructions);
+ }
+}
diff --git a/src/PaymentMethods/InstructionStrategies/DirectdebitInstructionStrategy.php b/src/PaymentMethods/InstructionStrategies/DirectdebitInstructionStrategy.php
index 2e3cbe9da..50144c6a3 100644
--- a/src/PaymentMethods/InstructionStrategies/DirectdebitInstructionStrategy.php
+++ b/src/PaymentMethods/InstructionStrategies/DirectdebitInstructionStrategy.php
@@ -6,24 +6,10 @@
class DirectdebitInstructionStrategy implements InstructionStrategyI
{
+ use DirectDebitInstructionTrait;
- public function execute(
- $gateway,
- $payment,
- $order = null,
- $admin_instructions = false
- ) {
-
- if ($payment->isPaid() && $payment->details) {
- return sprintf(
- /* translators: Placeholder 1: consumer name, placeholder 2: consumer IBAN, placeholder 3: consumer BIC */
- __('Payment completed by %1$s (IBAN (last 4 digits): %2$s, BIC: %3$s)', 'mollie-payments-for-woocommerce'),
- $payment->details->consumerName,
- substr($payment->details->consumerAccount, -4),
- $payment->details->consumerBic
- );
- }
- $defaultStrategy = new DefaultInstructionStrategy();
- return $defaultStrategy->execute($gateway, $payment, $admin_instructions);
+ public function execute($gateway, $payment, $order = null, $admin_instructions = false)
+ {
+ return $this->executeDirectDebit($gateway, $payment, $order, $admin_instructions);
}
}
diff --git a/src/PaymentMethods/InstructionStrategies/IdealInstructionStrategy.php b/src/PaymentMethods/InstructionStrategies/IdealInstructionStrategy.php
index 33ee1e90c..9c9343e6f 100644
--- a/src/PaymentMethods/InstructionStrategies/IdealInstructionStrategy.php
+++ b/src/PaymentMethods/InstructionStrategies/IdealInstructionStrategy.php
@@ -6,27 +6,10 @@
class IdealInstructionStrategy implements InstructionStrategyI
{
+ use DirectDebitInstructionTrait;
- public function execute(
- $gateway,
- $payment,
- $order = null,
- $admin_instructions = false
- ) {
-
- if ($payment->isPaid() && $payment->details) {
- return sprintf(
- /* translators: Placeholder 1: consumer name, placeholder 2: consumer IBAN, placeholder 3: consumer BIC */
- __(
- 'Payment completed by %1$s (IBAN (last 4 digits): %2$s, BIC: %3$s)',
- 'mollie-payments-for-woocommerce'
- ),
- $payment->details->consumerName,
- substr($payment->details->consumerAccount, -4),
- $payment->details->consumerBic
- );
- }
- $defaultStrategy = new DefaultInstructionStrategy();
- return $defaultStrategy->execute($gateway, $payment, $admin_instructions);
+ public function execute($gateway, $payment, $order = null, $admin_instructions = false)
+ {
+ return $this->executeDirectDebit($gateway, $payment, $order, $admin_instructions);
}
}
diff --git a/src/PaymentMethods/InstructionStrategies/MybankInstructionStrategy.php b/src/PaymentMethods/InstructionStrategies/MybankInstructionStrategy.php
index 0d272e9b6..13f8deb0e 100644
--- a/src/PaymentMethods/InstructionStrategies/MybankInstructionStrategy.php
+++ b/src/PaymentMethods/InstructionStrategies/MybankInstructionStrategy.php
@@ -6,7 +6,6 @@
class MybankInstructionStrategy implements InstructionStrategyI
{
-
public function execute(
$gateway,
$payment,
diff --git a/src/PaymentMethods/InstructionStrategies/PaypalInstructionStrategy.php b/src/PaymentMethods/InstructionStrategies/PaypalInstructionStrategy.php
index c92fa02b0..18c7a3242 100644
--- a/src/PaymentMethods/InstructionStrategies/PaypalInstructionStrategy.php
+++ b/src/PaymentMethods/InstructionStrategies/PaypalInstructionStrategy.php
@@ -6,7 +6,6 @@
class PaypalInstructionStrategy implements InstructionStrategyI
{
-
public function execute(
$gateway,
$payment,
diff --git a/src/PaymentMethods/InstructionStrategies/Przelewy24InstructionStrategy.php b/src/PaymentMethods/InstructionStrategies/Przelewy24InstructionStrategy.php
index e511cc6ed..815bcd1cd 100644
--- a/src/PaymentMethods/InstructionStrategies/Przelewy24InstructionStrategy.php
+++ b/src/PaymentMethods/InstructionStrategies/Przelewy24InstructionStrategy.php
@@ -6,7 +6,6 @@
class Przelewy24InstructionStrategy implements InstructionStrategyI
{
-
public function execute(
$gateway,
$payment,
diff --git a/src/PaymentMethods/InstructionStrategies/SofortInstructionStrategy.php b/src/PaymentMethods/InstructionStrategies/SofortInstructionStrategy.php
index 103d41928..4959d8200 100644
--- a/src/PaymentMethods/InstructionStrategies/SofortInstructionStrategy.php
+++ b/src/PaymentMethods/InstructionStrategies/SofortInstructionStrategy.php
@@ -6,24 +6,10 @@
class SofortInstructionStrategy implements InstructionStrategyI
{
+ use DirectDebitInstructionTrait;
- public function execute(
- $gateway,
- $payment,
- $order = null,
- $admin_instructions = false
- ) {
-
- if ($payment->isPaid() && $payment->details) {
- return sprintf(
- /* translators: Placeholder 1: consumer name, placeholder 2: consumer IBAN, placeholder 3: consumer BIC */
- __('Payment completed by %1$s (IBAN (last 4 digits): %2$s, BIC: %3$s)', 'mollie-payments-for-woocommerce'),
- $payment->details->consumerName,
- substr($payment->details->consumerAccount, -4),
- $payment->details->consumerBic
- );
- }
- $defaultStrategy = new DefaultInstructionStrategy();
- return $defaultStrategy->execute($gateway, $payment, $admin_instructions);
+ public function execute($gateway, $payment, $order = null, $admin_instructions = false)
+ {
+ return $this->executeDirectDebit($gateway, $payment, $order, $admin_instructions);
}
}
diff --git a/src/PaymentMethods/Klarnasliceit.php b/src/PaymentMethods/Klarnasliceit.php
index 63fcfee75..9b97b3db3 100644
--- a/src/PaymentMethods/Klarnasliceit.php
+++ b/src/PaymentMethods/Klarnasliceit.php
@@ -6,7 +6,6 @@
class Klarnasliceit extends AbstractPaymentMethod implements PaymentMethodI
{
-
protected function getConfig(): array
{
return [
diff --git a/src/PaymentMethods/Mybank.php b/src/PaymentMethods/Mybank.php
index 4c59e3873..a2f38ba23 100644
--- a/src/PaymentMethods/Mybank.php
+++ b/src/PaymentMethods/Mybank.php
@@ -6,7 +6,6 @@
class Mybank extends AbstractPaymentMethod implements PaymentMethodI
{
-
protected function getConfig(): array
{
return [
diff --git a/src/PaymentMethods/PaymentFieldsStrategies/CreditcardFieldsStrategy.php b/src/PaymentMethods/PaymentFieldsStrategies/CreditcardFieldsStrategy.php
index 2cfae8fd2..caf56dbf5 100644
--- a/src/PaymentMethods/PaymentFieldsStrategies/CreditcardFieldsStrategy.php
+++ b/src/PaymentMethods/PaymentFieldsStrategies/CreditcardFieldsStrategy.php
@@ -8,13 +8,13 @@
class CreditcardFieldsStrategy implements PaymentFieldsStrategyI
{
-
public function execute($gateway, $dataHelper)
{
- if (!$this->isMollieComponentsEnabled($gateway->paymentMethod)) {
+ if (!$this->isMollieComponentsEnabled($gateway->paymentMethod())) {
return;
}
$gateway->has_fields = true;
+ $allowedHtml = $this->svgAllowedHtml()
?>
@@ -22,10 +22,12 @@ public function execute($gateway, $dataHelper)
lockIcon($dataHelper),
- $this->mollieLogo($dataHelper)
+ esc_html(__(
+ '%1$s Secure payments provided by %2$s',
+ 'mollie-payments-for-woocommerce'
+ )),
+ wp_kses($this->lockIcon($dataHelper), $allowedHtml),
+ wp_kses($this->mollieLogo($dataHelper), $allowedHtml)
);
?>
@@ -34,7 +36,7 @@ public function execute($gateway, $dataHelper)
public function getFieldMarkup($gateway, $dataHelper)
{
- if (!$this->isMollieComponentsEnabled($gateway->paymentMethod)) {
+ if (!$this->isMollieComponentsEnabled($gateway->paymentMethod())) {
return false;
}
$gateway->has_fields = true;
@@ -51,14 +53,51 @@ protected function isMollieComponentsEnabled(PaymentMethodI $paymentMethod): boo
protected function lockIcon($dataHelper)
{
return file_get_contents(
- $dataHelper->pluginPath . '/' . 'public/images/lock-icon.svg'
+ $dataHelper->pluginPath() . '/' . 'public/images/lock-icon.svg'
);
}
protected function mollieLogo($dataHelper)
{
return file_get_contents(
- $dataHelper->pluginPath . '/' . 'public/images/mollie-logo.svg'
+ $dataHelper->pluginPath() . '/' . 'public/images/mollie-logo.svg'
);
}
+
+ /**
+ * @return array
+ */
+ protected function svgAllowedHtml(): array
+ {
+ return [
+ 'svg' => [
+ 'class' => [],
+ 'width' => [],
+ 'height' => [],
+ 'viewbox' => [],
+ 'xmlns' => [],
+ 'aria-hidden' => [],
+ 'role' => [],
+ ],
+ 'g' => [
+ ],
+ 'defs' => [
+ ],
+ 'use' => [
+ 'xlink:href' => [],
+ 'clip-path' => [],
+ 'fill' => [],
+ 'stroke' => [],
+ 'stroke-width' => [],
+ ],
+ 'path' => [
+ 'fill' => [],
+ 'd' => [],
+ 'id' => [],
+ ],
+ 'clipPath' => [
+ 'id' => [],
+ ],
+ ];
+ }
}
diff --git a/src/PaymentMethods/PaymentFieldsStrategies/DefaultFieldsStrategy.php b/src/PaymentMethods/PaymentFieldsStrategies/DefaultFieldsStrategy.php
index 85358a2ce..15a54b5d8 100644
--- a/src/PaymentMethods/PaymentFieldsStrategies/DefaultFieldsStrategy.php
+++ b/src/PaymentMethods/PaymentFieldsStrategies/DefaultFieldsStrategy.php
@@ -6,7 +6,6 @@
class DefaultFieldsStrategy implements PaymentFieldsStrategyI
{
-
public function execute($gateway, $dataHelper)
{
}
diff --git a/src/PaymentMethods/PaymentFieldsStrategies/GiftcardFieldsStrategy.php b/src/PaymentMethods/PaymentFieldsStrategies/GiftcardFieldsStrategy.php
index e754108df..f9c52f32d 100644
--- a/src/PaymentMethods/PaymentFieldsStrategies/GiftcardFieldsStrategy.php
+++ b/src/PaymentMethods/PaymentFieldsStrategies/GiftcardFieldsStrategy.php
@@ -15,17 +15,20 @@ public function execute($gateway, $dataHelper)
}
$issuers = $this->getIssuers($gateway, $dataHelper);
-
+ if (empty($issuers)) {
+ return;
+ }
$selectedIssuer = $gateway->getSelectedIssuer();
$html = '';
// If only one gift card issuers is available, show it without a dropdown
if (count($issuers) === 1) {
+ $issuer = $issuers[0];
$issuerImageSvg = $this->checkSvgIssuers($issuers);
$issuerImageSvg && ($html .= ' ');
- $html .= $issuers->description;
- echo wpautop(wptexturize($html));
+ $html .= $issuer->name;
+ echo esc_html(wpautop(wptexturize($html)));
return;
}
diff --git a/src/PaymentMethods/PaymentFieldsStrategies/IssuersDropdownBehavior.php b/src/PaymentMethods/PaymentFieldsStrategies/IssuersDropdownBehavior.php
index a4e24fed7..3ccbd4564 100644
--- a/src/PaymentMethods/PaymentFieldsStrategies/IssuersDropdownBehavior.php
+++ b/src/PaymentMethods/PaymentFieldsStrategies/IssuersDropdownBehavior.php
@@ -7,10 +7,15 @@ trait IssuersDropdownBehavior
public function dropDownEnabled($gateway)
{
$defaultDropdownSetting = true;
- return $gateway->paymentMethod->getProperty('issuers_dropdown_shown') ?
- $gateway->paymentMethod->getProperty('issuers_dropdown_shown') === 'yes' :
+ return $gateway->paymentMethod()->getProperty('issuers_dropdown_shown') ?
+ $gateway->paymentMethod()->getProperty('issuers_dropdown_shown') === 'yes' :
$defaultDropdownSetting;
}
+ /**
+ * @param $gateway
+ * @param $dataHelper
+ * @return array
+ */
public function getIssuers($gateway, $dataHelper)
{
$testMode = $dataHelper->isTestModeEnabled();
@@ -19,7 +24,7 @@ public function getIssuers($gateway, $dataHelper)
return $dataHelper->getMethodIssuers(
$apiKey,
$testMode,
- $gateway->paymentMethod->getProperty('id')
+ $gateway->paymentMethod()->getProperty('id')
);
}
@@ -30,7 +35,17 @@ public function renderIssuers($gateway, $issuers, $selectedIssuer)
$issuers,
$selectedIssuer
);
- echo wpautop(wptexturize($html));
+ echo wp_kses($html, [
+ 'select' => [
+ 'name' => [],
+ 'id' => [],
+ 'class' => [],
+ ],
+ 'option' => [
+ 'value' => [],
+ 'selected' => [],
+ ],
+ ]);
}
/**
@@ -46,7 +61,7 @@ public function issuersDropdownMarkup(
$selectedIssuer
): string {
- $html = ' ';
@@ -67,9 +82,9 @@ public function dropdownOptions(
$selectedIssuer
): string {
- $description = $gateway->paymentMethod->getProperty(
+ $description = $gateway->paymentMethod()->getProperty(
'issuers_empty_option'
- ) ?: $gateway->paymentMethod->getProperty('defaultDescription');
+ ) ?: $gateway->paymentMethod()->getProperty('defaultDescription');
$html = ' ';
foreach ($issuers as $issuer) {
diff --git a/src/PaymentMethods/PaymentMethodI.php b/src/PaymentMethods/PaymentMethodI.php
index 43b600702..8b3ad1486 100644
--- a/src/PaymentMethods/PaymentMethodI.php
+++ b/src/PaymentMethods/PaymentMethodI.php
@@ -4,9 +4,14 @@
namespace Mollie\WooCommerce\PaymentMethods;
+use Mollie\WooCommerce\Payment\PaymentFieldsService;
+
interface PaymentMethodI
{
public function getProperty(string $propertyName);
- public function hasProperty(string $propertyName);
- public function hasPaymentFields();
+ public function hasProperty(string $propertyName): bool;
+ public function hasPaymentFields(): bool;
+ public function getProcessedDescriptionForBlock(): string;
+ public function paymentFieldsService(): PaymentFieldsService;
+ public function hasSurcharge(): bool;
}
diff --git a/src/PaymentMethods/PaymentMethodsIconUrl.php b/src/PaymentMethods/PaymentMethodsIconUrl.php
index ffa2720ce..0ca4eb621 100644
--- a/src/PaymentMethods/PaymentMethodsIconUrl.php
+++ b/src/PaymentMethods/PaymentMethodsIconUrl.php
@@ -84,7 +84,7 @@ public function svgUrlForPaymentMethod($paymentMethodName)
$svgUrl = $this->pluginUrl . '/' . sprintf('public/images/%s', $paymentMethodName) . self::SVG_FILE_EXTENSION;
}
- return ' ';
}
@@ -99,12 +99,12 @@ public function getCreditcardIcon()
$gatewaySettings = get_option('mollie_wc_gateway_creditcard_settings', false);
if ($this->canShowCustomLogo($gatewaySettings)) {
$url = $gatewaySettings["iconFileUrl"];
- return ' ';
}
$svgUrl = $this->pluginUrl . sprintf('public/images/%ss.svg', PaymentMethod::CREDITCARD);
return
- ' ';
}
@@ -171,16 +171,17 @@ public function buildSvgComposed()
{
$enabledCreditCards = $this->enabledCreditcards();
- $assetsImagesPath
- = $this->pluginPath . '/' . 'public/images/';
+ $assetsImagesPath = $this->pluginPath . '/' . 'public/images/';
$cardWidth = PaymentMethodsIconUrl::CREDIT_CARD_ICON_WIDTH;
$cardsNumber = count($enabledCreditCards);
$cardsWidth = $cardWidth * $cardsNumber;
$cardPositionX = 0;
$actual = get_transient('svg_creditcards_string');
if (!$actual) {
- $actual
- = sprintf(' |