$order->get_id() ); // Mollie payment not found or invalid gateway if ( !$payment || $payment->method !== $this->paymentMethod->getProperty('id') ) { return; } $this->orderInstructionsService->setStrategy($this); $instructions = $this->orderInstructionsService->executeStrategy( $this, $payment, $order, $admin_instructions ); if (!empty($instructions)) { $instructions = wptexturize($instructions); //save instructions in order meta $order->update_meta_data( '_mollie_payment_instructions', $instructions ); $order->save(); if ($plain_text) { echo esc_html($instructions) . PHP_EOL; } else { echo '
'; echo wp_kses(wpautop($instructions), ['p' => [], 'strong' => []]) . PHP_EOL; echo '
'; } } } if ($admin_instructions && !$this::$alreadyDisplayedAdminInstructions) { $this::$alreadyDisplayedAdminInstructions = true; } if (!$admin_instructions && !$this::$alreadyDisplayedCustomerInstructions) { $this::$alreadyDisplayedCustomerInstructions = true; } } /** * @param $title * @param null $id * * @return string|void */ public function onOrderReceivedTitle($title, $id = null) { if (is_order_received_page() && get_the_ID() === $id) { global $wp; $order = false; $order_id = apply_filters( 'woocommerce_thankyou_order_id', absint($wp->query_vars['order-received']) ); $order_key = apply_filters( 'woocommerce_thankyou_order_key', empty($_GET['key']) ? '' : wc_clean(filter_input(INPUT_GET, 'key', FILTER_SANITIZE_SPECIAL_CHARS))// WPCS: input var ok, CSRF ok. ); if ($order_id > 0) { $order = wc_get_order($order_id); if (!is_a($order, 'WC_Order')) { return $title; } $order_key_db = $order->get_order_key(); if ($order_key_db !== $order_key) { $order = false; } } if ($order === false) { return $title; } $order_payment_method = $order->get_payment_method(); // Invalid gateway if ($this->id !== $order_payment_method) { return $title; } // Title for cancelled orders if ($order->has_status('cancelled')) { return __( 'Order cancelled', 'mollie-payments-for-woocommerce' ); } // Checks and title for pending/open orders $payment = $this->paymentObject()->getActiveMolliePayment( $order->get_id() ); // Mollie payment not found or invalid gateway if (!$payment || $payment->method !== $this->paymentMethod->getProperty('id')) { return $title; } if ($payment->isOpen()) { // Add a message to log and order explaining a payment with status "open", only if it hasn't been added already if ($order->get_meta('_mollie_open_status_note') !== '1') { // Get payment method title $payment_method_title = $this->method_title; // Add message to log $this->logger->debug( $this->id . ': Customer returned to store, but payment still pending for order #' . $order_id . '. Status should be updated automatically in the future, if it doesn\'t this might indicate a communication issue between the site and Mollie.' ); // Add message to order as order note $order->add_order_note( sprintf( /* translators: Placeholder 1: payment method title, placeholder 2: payment ID */ __( '%1$s payment still pending (%2$s) but customer already returned to the store. Status should be updated automatically in the future, if it doesn\'t this might indicate a communication issue between the site and Mollie.', 'mollie-payments-for-woocommerce' ), $payment_method_title, $payment->id . ($payment->mode === 'test' ? (' - ' . __( 'test mode', 'mollie-payments-for-woocommerce' )) : '') ) ); $order->update_meta_data('_mollie_open_status_note', '1'); $order->save(); } // Update the title on the Order received page to better communicate that the payment is pending. $title .= __( ', payment pending.', 'mollie-payments-for-woocommerce' ); return $title; } } return $title; } /** * @param $text * @param WC_Order| null $order * * @return string|void */ public function onOrderReceivedText($text, $order) { if (!is_a($order, 'WC_Order')) { return $text; } $order_payment_method = $order->get_payment_method(); // Invalid gateway if ($this->id !== $order_payment_method) { return $text; } if ($order->has_status('cancelled')) { return __( 'Your order has been cancelled.', 'mollie-payments-for-woocommerce' ); } return $text; } /** * @return string|NULL */ public function getSelectedIssuer(): ?string { $issuer_id = $this->pluginId . '_issuer_' . $this->id; //phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized $postedIssuer = wc_clean(wp_unslash($_POST[$issuer_id] ?? '')); return !empty($postedIssuer) ? $postedIssuer : null; } /** * Get the transaction URL. * * @param WC_Order $order * * @return string */ public function get_transaction_url($order): string { $isPaymentApi = substr($order->get_meta('_mollie_order_id', true), 0, 3) === 'tr_' ; $resource = ($order->get_meta('_mollie_order_id', true) && !$isPaymentApi) ? 'orders' : 'payments'; $this->view_transaction_url = 'https://my.mollie.com/dashboard/' . $resource . '/%s?utm_source=woocommerce&utm_medium=plugin&utm_campaign=partner'; return parent::get_transaction_url($order); } protected function gatewayHasFields(): void { if ($this->paymentMethod->getProperty('paymentFields')) { $this->has_fields = true; } /* Override show issuers dropdown? */ $dropdownDisabled = $this->paymentMethod->hasProperty('issuers_dropdown_shown') && $this->paymentMethod->getProperty('issuers_dropdown_shown') === 'no'; if ($dropdownDisabled) { $this->has_fields = false; } } /** * Get the correct currency for this payment or order * On order-pay page, order is already created and has an order currency * On checkout, order is not created, use get_woocommerce_currency * * @return string */ public function getCurrencyFromOrder() { global $wp; if (!empty($wp->query_vars['order-pay'])) { $order_id = $wp->query_vars['order-pay']; $order = wc_get_order($order_id); $currency = $this->dataService->getOrderCurrency($order); } else { $currency = get_woocommerce_currency(); } return $currency; } /** * Retrieve the customer's billing country * or fallback to the shop country * * @return mixed|void|null */ public function getBillingCountry() { $customerExistsAndHasCountry = WC()->customer && !empty(WC()->customer->get_billing_country()); $fallbackToShopCountry = wc_get_base_location()['country']; $billingCountry = $customerExistsAndHasCountry ? WC()->customer->get_billing_country() : $fallbackToShopCountry; return apply_filters( $this->pluginId . '_is_available_billing_country_for_payment_gateways', $billingCountry ); } /** * Check the 'allowed_countries' setting * and return false if $billingCountry is in the list of not allowed. * * @param string $billingCountry * @param bool $status * @return bool */ protected function isAllowedBillingCountry($billingCountry, $status) { $allowedCountries = $this->paymentMethod->getProperty('allowed_countries'); //if no country is selected then this does not apply $bCountryIsAllowed = empty($allowedCountries) || in_array( $billingCountry, $allowedCountries, true ); if (!$bCountryIsAllowed) { $status = false; } return $status; } /** * In WooCommerce check if the gateway is available for use (WooCommerce settings) * but also check if is not direct debit as this should not be shown in checkout * * @return bool */ protected function checkEnabledNorDirectDebit(): bool { if ($this->enabled !== 'yes') { return false; } if ($this->id === SharedDataDictionary::DIRECTDEBIT) { return false; } return true; } /** * Check if the cart amount is available and > 0 * * @return bool */ protected function cartAmountAvailable() { return WC()->cart && $this->get_order_total() > 0; } } tern ) ) { continue; } if ( $pattern['slug'] === $slug ) { return $pattern; } } return null; } }