mollie-payments-for-woocommerce') ], [ 'name' => 'cardNumber', 'label' => esc_html__('Card Number', 'mollie-payments-for-woocommerce') ], [ 'name' => 'expiryDate', 'label' => esc_html__('Expiry Date', 'mollie-payments-for-woocommerce') ], [ 'name' => 'verificationCode', 'label' => esc_html__( 'Verification Code', 'mollie-payments-for-woocommerce' ) ], ], 'messages' => [ 'defaultErrorMessage' => esc_html__( 'An unknown error occurred, please check the card fields.', 'mollie-payments-for-woocommerce' ), ], 'isCheckout' => is_checkout(), 'isCheckoutPayPage' => is_checkout_pay_page() ] ); } /** * Returns the order from the Request first by Id, if not by Key * * @return bool|WC_Order */ public static function orderByRequest() { $orderId = filter_input(INPUT_GET, 'order_id', FILTER_SANITIZE_NUMBER_INT) ?: null; $key = filter_input(INPUT_GET, 'key', FILTER_SANITIZE_STRING) ?: null; $order = wc_get_order($orderId); if (!$order) { $order = wc_get_order(wc_get_order_id_by_order_key($key)); } if (!$order) { throw new RuntimeException( "Could not find order by order Id {$orderId}", 404 ); } if (!$order->key_is_valid($key)) { throw new RuntimeException( "Invalid key given. Key {$key} does not match the order id: {$orderId}", 401 ); } return $order; } /** * Old Payment return url callback * */ public static function onMollieReturn () { try { $order = self::orderByRequest(); } catch (RuntimeException $exc) { self::setHttpResponseCode($exc->getCode()); mollieWooCommerceDebug(__METHOD__ . ": {$exc->getMessage()}"); return; } $gateway = wc_get_payment_gateway_by_order($order); $orderId = $order->get_id(); if (!$gateway) { $gatewayName = $order->get_payment_method(); self::setHttpResponseCode(404); mollieWooCommerceDebug( __METHOD__ . ": Could not find gateway {$gatewayName} for order {$orderId}." ); return; } if (!($gateway instanceof Mollie_WC_Gateway_Abstract)) { self::setHttpResponseCode(400); mollieWooCommerceDebug(__METHOD__ . ": Invalid gateway {get_class($gateway)} for this plugin. Order {$orderId}."); return; } $redirect_url = $gateway->getReturnRedirectUrlForOrder($order); // Add utm_nooverride query string $redirect_url = add_query_arg(['utm_nooverride' => 1], $redirect_url); mollieWooCommerceDebug(__METHOD__ . ": Redirect url on return order {$gateway->id}, order {$orderId}: {$redirect_url}"); wp_safe_redirect($redirect_url); die; } /** * New Payment return url callback * */ public static function mollieReturnRedirect() { if (isset($_GET['filter_flag'])) { $filterFlag = filter_input(INPUT_GET, 'filter_flag', FILTER_SANITIZE_STRING); if ($filterFlag === 'onMollieReturn') { self::onMollieReturn(); } } } /** * @param WC_Order $order */ public static function onOrderDetails (WC_Order $order) { if (is_order_received_page()) { /** * Do not show instruction again below details on order received page * Instructions already displayed on top of order received page by $gateway->thankyou_page() * * @see Mollie_WC_Gateway_Abstract::thankyou_page */ return; } $gateway = wc_get_payment_gateway_by_order($order); if (!$gateway || !($gateway instanceof Mollie_WC_Gateway_Abstract)) { return; } /** @var Mollie_WC_Gateway_Abstract $gateway */ $gateway->displayInstructions($order); } /** * Set HTTP status code * * @param int $status_code */ public static function setHttpResponseCode ($status_code) { if (PHP_SAPI !== 'cli' && !headers_sent()) { if (function_exists("http_response_code")) { http_response_code($status_code); } else { header(" ", TRUE, $status_code); } } } /** * Add Mollie gateways * * @param array $gateways * @return array */ public static function addGateways( array $gateways ) { $gateways = array_merge( $gateways, self::$GATEWAYS ); // Return if function get_current_screen() is not defined if ( ! function_exists( 'get_current_screen' ) ) { return $gateways; } // Try getting get_current_screen() $current_screen = get_current_screen(); // Return if get_current_screen() isn't set if ( ! $current_screen ) { return $gateways; } // Remove old MisterCash (only) from WooCommerce Payment settings if ( is_admin() && ! empty( $current_screen->base ) && $current_screen->base == 'woocommerce_page_wc-settings' ) { if ( ( $key = array_search( 'Mollie_WC_Gateway_MisterCash', $gateways ) ) !== false ) { unset( $gateways[ $key ] ); } } return $gateways; } /** * Disable Bank Transfer Gateway * * @param array $gateways * @return array */ public static function maybeDisableBankTransferGateway(array $gateways) { $isWcApiRequest = (bool)filter_input(INPUT_GET, 'wc-api', FILTER_SANITIZE_STRING); $bankTransferSettings = get_option('mollie_wc_gateway_banktransfer_settings', false); $isSettingActivated = false; if($bankTransferSettings && isset($bankTransferSettings['activate_expiry_days_setting'])){ $expiryDays = $bankTransferSettings['activate_expiry_days_setting']; $isSettingActivated = mollieWooCommerceStringToBoolOption($expiryDays); } /* * There is only one case where we want to filter the gateway and it's when the * pay-page render the available payments methods AND the setting is enabled * * For any other case we want to be sure bank transfer gateway is included. */ if ($isWcApiRequest || !$isSettingActivated || is_checkout() && ! is_wc_endpoint_url( 'order-pay' )|| !wp_doing_ajax() && ! is_wc_endpoint_url( 'order-pay' )|| is_admin() ) { return $gateways; } $bankTransferGatewayClassName = Mollie_WC_Gateway_BankTransfer::class; $bankTransferGatewayIndex = array_search($bankTransferGatewayClassName, $gateways, true); if ($bankTransferGatewayIndex !== false) { unset($gateways[$bankTransferGatewayIndex]); } return $gateways; } /** * Disable Apple Pay Gateway * * @param array $gateways * @return array */ public static function maybeDisableApplePayGateway(array $gateways) { $isWcApiRequest = (bool)filter_input(INPUT_GET, 'wc-api', FILTER_SANITIZE_STRING); $wooCommerceSession = mollieWooCommerceSession(); /* * There is only one case where we want to filter the gateway and it's when the checkout * page render the available payments methods. * * For any other case we want to be sure apple pay gateway is included. */ if ($isWcApiRequest || !$wooCommerceSession instanceof WC_Session || !doing_action('woocommerce_payment_gateways') || !wp_doing_ajax() && ! is_wc_endpoint_url( 'order-pay' )|| is_admin() ) { return $gateways; } if ($wooCommerceSession->get(self::APPLE_PAY_METHOD_ALLOWED_KEY, false)) { return $gateways; } $applePayGatewayClassName = Mollie_WC_Gateway_Applepay::class; $applePayGatewayIndex = array_search($applePayGatewayClassName, $gateways, true); $postData = (string)filter_input( INPUT_POST, self::POST_DATA_KEY, FILTER_SANITIZE_STRING ) ?: ''; parse_str($postData, $postData); $applePayAllowed = isset($postData[self::APPLE_PAY_METHOD_ALLOWED_KEY]) && $postData[self::APPLE_PAY_METHOD_ALLOWED_KEY]; if ($applePayGatewayIndex !== false && !$applePayAllowed) { unset($gateways[$applePayGatewayIndex]); } if ($applePayGatewayIndex !== false && $applePayAllowed) { $wooCommerceSession->set(self::APPLE_PAY_METHOD_ALLOWED_KEY, true); } return $gateways; } /** * Add a WooCommerce notification message * * @param string $message Notification message * @param string $type One of notice, error or success (default notice) * * @return $this */ public static function addNotice( $message, $type = 'notice' ) { $type = in_array( $type, array ( 'notice', 'error', 'success' ) ) ? $type : 'notice'; // Check for existence of new notification api (WooCommerce >= 2.1) if ( function_exists( 'wc_add_notice' ) ) { wc_add_notice( $message, $type ); } else { $woocommerce = WooCommerce::instance(); switch ( $type ) { case 'error' : $woocommerce->add_error( $message ); break; default : $woocommerce->add_message( $message ); break; } } } /** * Log messages to WooCommerce log * * @param mixed $message * @param bool $set_debug_header Set X-Mollie-Debug header (default false) */ public static function debug ($message, $set_debug_header = false) { // Convert message to string if (!is_string($message)) { $message = wc_print_r($message, true); } // Set debug header if ($set_debug_header && PHP_SAPI !== 'cli' && !headers_sent()) { header("X-Mollie-Debug: $message"); } // Log message if ( self::getSettingsHelper()->isDebugEnabled() ) { $logger = wc_get_logger(); $context = array ( 'source' => self::PLUGIN_ID . '-' . date( 'Y-m-d' ) ); $logger->debug( $message, $context ); } } /** * Get location of main plugin file * * @return string */ public static function getPluginFile () { return plugin_basename(self::PLUGIN_ID . '/' . self::PLUGIN_ID . '.php'); } /** * Get plugin URL * * @param string $path * @return string */ public static function getPluginUrl ($path = '') { return untrailingslashit(M4W_PLUGIN_URL) . '/' . ltrim($path, '/'); } public static function getPluginPath($path = '') { return untrailingslashit(M4W_PLUGIN_DIR) . '/' . ltrim($path, '/'); } /** * Add plugin action links * @param array $links * @return array */ public static function addPluginActionLinks (array $links) { $action_links = array( // Add link to global Mollie settings '' . __('Mollie settings', 'mollie-payments-for-woocommerce') . '', ); // Add link to WooCommerce logs $action_links[] = '' . __('Logs', 'mollie-payments-for-woocommerce') . ''; return array_merge($action_links, $links); } /** * @return Mollie_WC_Helper_Settings */ public static function getSettingsHelper () { static $settings_helper; if (!$settings_helper) { $settings_helper = new Mollie_WC_Helper_Settings(); } return $settings_helper; } /** * @return Mollie_WC_Helper_Api */ public static function getApiHelper () { static $api_helper; if (!$api_helper) { $api_helper = new Mollie_WC_Helper_Api(self::getSettingsHelper()); } return $api_helper; } /** * @return Mollie_WC_Helper_Data */ public static function getDataHelper () { static $data_helper; if (!$data_helper) { $data_helper = new Mollie_WC_Helper_Data(self::getApiHelper()); } return $data_helper; } /** * @return Mollie_WC_Helper_Status */ public static function getStatusHelper () { static $status_helper; if (!$status_helper) { $status_helper = new Mollie_WC_Helper_Status(new CompatibilityChecker()); } return $status_helper; } /** * @return Mollie_WC_Helper_PaymentFactory */ public static function getPaymentFactoryHelper() { static $payment_helper; if ( ! $payment_helper ) { $payment_helper = new Mollie_WC_Helper_PaymentFactory(); } return $payment_helper; } /** * @return Mollie_WC_Payment_Object */ public static function getPaymentObject() { static $payment_parent; if ( ! $payment_parent ) { $payment_parent = new Mollie_WC_Payment_Object( null ); } return $payment_parent; } /** * @return Mollie_WC_Helper_OrderLines */ public static function getOrderLinesHelper ( $shop_country, WC_Order $order ) { static $order_lines_helper; if (!$order_lines_helper) { $order_lines_helper = new Mollie_WC_Helper_OrderLines( $shop_country, $order ); } return $order_lines_helper; } /** * Ship all order lines and capture an order at Mollie. * */ public static function shipAndCaptureOrderAtMollie( $order_id ) { $order = wc_get_order( $order_id ); // Does WooCommerce order contain a Mollie payment? if ( strstr( $order->get_payment_method(), 'mollie_wc_gateway_') == FALSE ) { return; } // To disable automatic shipping and capturing of the Mollie order when a WooCommerce order status is updated to completed, // store an option 'mollie-payments-for-woocommerce_disableShipOrderAtMollie' with value 1 if ( get_option(Mollie_WC_Plugin::PLUGIN_ID . '_' . 'disableShipOrderAtMollie', '0' ) == '1' ) { return; } Mollie_WC_Plugin::debug( __METHOD__ . ' - ' . $order_id . ' - Try to process completed order for a potential capture at Mollie.' ); // Does WooCommerce order contain a Mollie Order? $mollie_order_id = ( $mollie_order_id = $order->get_meta( '_mollie_order_id', true ) ) ? $mollie_order_id : false; // Is it a payment? you cannot ship a payment if ( $mollie_order_id == false || substr($mollie_order_id,0,3) == 'tr_') { $order->add_order_note( 'Order contains Mollie payment method, but not a Mollie Order ID. Processing capture canceled.' ); Mollie_WC_Plugin::debug( __METHOD__ . ' - ' . $order_id . ' - Order contains Mollie payment method, but not a Mollie Order ID. Processing capture cancelled.' ); return; } // Is test mode enabled? $test_mode = mollieWooCommerceIsTestModeEnabled(); try { // Get the order from the Mollie API $mollie_order = Mollie_WC_Plugin::getApiHelper()->getApiClient( $test_mode )->orders->get( $mollie_order_id ); // Check that order is Paid or Authorized and can be captured if ( $mollie_order->isCanceled() ) { $order->add_order_note( 'Order already canceled at Mollie, can not be shipped/captured.' ); Mollie_WC_Plugin::debug( __METHOD__ . ' - ' . $order_id . ' - Order already canceled at Mollie, can not be shipped/captured.' ); return; } if ( $mollie_order->isCompleted() ) { $order->add_order_note( 'Order already completed at Mollie, can not be shipped/captured.' ); Mollie_WC_Plugin::debug( __METHOD__ . ' - ' . $order_id . ' - Order already completed at Mollie, can not be shipped/captured.' ); return; } if ( $mollie_order->isPaid() || $mollie_order->isAuthorized() ) { Mollie_WC_Plugin::getApiHelper()->getApiClient( $test_mode )->orders->get( $mollie_order_id )->shipAll(); $order->add_order_note( 'Order successfully updated to shipped at Mollie, capture of funds underway.' ); Mollie_WC_Plugin::debug( __METHOD__ . ' - ' . $order_id . ' - Order successfully updated to shipped at Mollie, capture of funds underway.' ); return; } $order->add_order_note( 'Order not paid or authorized at Mollie yet, can not be shipped.' ); Mollie_WC_Plugin::debug( __METHOD__ . ' - ' . $order_id . ' - Order not paid or authorized at Mollie yet, can not be shipped.' ); } catch ( Mollie\Api\Exceptions\ApiException $e ) { Mollie_WC_Plugin::debug( __METHOD__ . ' - ' . $order_id . ' - Processing shipment & capture failed, error: ' . $e->getMessage() ); } return; } /** * Cancel an order at Mollie. * */ public static function cancelOrderAtMollie( $order_id ) { $order = wc_get_order( $order_id ); // Does WooCommerce order contain a Mollie payment? if ( strstr( $order->get_payment_method(), 'mollie_wc_gateway_') == FALSE ) { return; } // To disable automatic canceling of the Mollie order when a WooCommerce order status is updated to canceled, // store an option 'mollie-payments-for-woocommerce_disableCancelOrderAtMollie' with value 1 if ( get_option(Mollie_WC_Plugin::PLUGIN_ID . '_' . 'disableCancelOrderAtMollie', '0' ) == '1' ) { return; } Mollie_WC_Plugin::debug( __METHOD__ . ' - ' . $order_id . ' - Try to process cancelled order at Mollie.' ); $mollie_order_id = ( $mollie_order_id = $order->get_meta( '_mollie_order_id', true ) ) ? $mollie_order_id : false; if ( $mollie_order_id == false ) { $order->add_order_note( 'Order contains Mollie payment method, but not a valid Mollie Order ID. Canceling order failed.' ); Mollie_WC_Plugin::debug( __METHOD__ . ' - ' . $order_id . ' - Order contains Mollie payment method, but not a valid Mollie Order ID. Canceling order failed.' ); return; } // Is test mode enabled? $test_mode = mollieWooCommerceIsTestModeEnabled(); try { // Get the order from the Mollie API $mollie_order = Mollie_WC_Plugin::getApiHelper()->getApiClient( $test_mode )->orders->get( $mollie_order_id ); // Check that order is not already canceled at Mollie if ( $mollie_order->isCanceled() ) { $order->add_order_note( 'Order already canceled at Mollie, can not be canceled again.' ); Mollie_WC_Plugin::debug( __METHOD__ . ' - ' . $order_id . ' - Order already canceled at Mollie, can not be canceled again.' ); return; } // Check that order has the correct status to be canceled if ( $mollie_order->isCreated() || $mollie_order->isAuthorized() || $mollie_order->isShipping() ) { Mollie_WC_Plugin::getApiHelper()->getApiClient( $test_mode )->orders->get( $mollie_order_id )->cancel(); $order->add_order_note( 'Order also cancelled at Mollie.' ); Mollie_WC_Plugin::debug( __METHOD__ . ' - ' . $order_id . ' - Order cancelled in WooCommerce, also cancelled at Mollie.' ); return; } $order->add_order_note( 'Order could not be canceled at Mollie, because order status is ' . $mollie_order->status . '.' ); Mollie_WC_Plugin::debug( __METHOD__ . ' - ' . $order_id . ' - Order could not be canceled at Mollie, because order status is ' . $mollie_order->status . '.' ); } catch ( Mollie\Api\Exceptions\ApiException $e ) { Mollie_WC_Plugin::debug( __METHOD__ . ' - ' . $order_id . ' - Updating order to canceled at Mollie failed, error: ' . $e->getMessage() ); } return; } /** * Don't show SEPA Direct Debit in WooCommerce Checkout */ public static function disableSEPAInCheckout( $available_gateways ) { if ( is_checkout() ) { unset( $available_gateways['mollie_wc_gateway_directdebit'] ); } return $available_gateways; } /** * Don't show old MisterCash in WooCommerce Checkout */ public static function disableMisterCashInCheckout( $available_gateways ) { if ( is_checkout() ) { unset( $available_gateways['mollie_wc_gateway_mistercash'] ); } return $available_gateways; } /** * Don't show Mollie Payment Methods in WooCommerce Account > Subscriptions */ public static function disableMollieOnPaymentMethodChange( $available_gateways ) { // Can't use $wp->request or is_wc_endpoint_url() to check if this code only runs on /subscriptions and /view-subscriptions, // because slugs/endpoints can be translated (with WPML) and other plugins. // So disabling on is_account_page (if not checkout, bug in WC) and $_GET['change_payment_method'] for now. // Only disable payment methods if WooCommerce Subscriptions is installed if ( class_exists( 'WC_Subscription' ) ) { // Do not disable if account page is also checkout (workaround for bug in WC), do disable on change payment method page (param) if ( ( ! is_checkout() && is_account_page() ) || ! empty( $_GET['change_payment_method'] ) ) { foreach ( $available_gateways as $key => $value ) { if ( strpos( $key, 'mollie_' ) !== false ) { unset( $available_gateways[ $key ] ); } } } } return $available_gateways; } /** * If an order is paid with another payment method (gateway) after a first payment was * placed with Mollie, set a flag, so status updates (like expired) aren't processed by * Mollie Payments for WooCommerce. */ public static function setOrderPaidByOtherGateway( $order_id ) { $order = wc_get_order( $order_id ); $mollie_payment_id = $order->get_meta( '_mollie_payment_id', $single = true ); $order_payment_method = $order->get_payment_method(); if ( $mollie_payment_id !== '' && ( strpos( $order_payment_method, 'mollie' ) === false ) ) { $order->update_meta_data( '_mollie_paid_by_other_gateway', '1' ); $order->save(); } return true; } private static function extractRemoteItemsIds(array $data) { if (empty($data['lines'])) { return []; } return implode(',', wp_list_pluck($data['lines'], 'id')); } } Winkel - Suskes Baby & Kinderproducten

Winkel

Home/Winkel

Toont alle 4 resultaten

Sort by:
Shopping Cart
Close

Geen producten in de winkelwagen.