diff --git a/bluem-db.php b/bluem-db.php index 2fbc2f2..bfbef2a 100644 --- a/bluem-db.php +++ b/bluem-db.php @@ -188,6 +188,26 @@ function bluem_db_request_log($request_id, $description, $log_data = array()) ); } +function bluem_db_initialize_session_storage(): array|false +{ + if (!empty($_COOKIE['bluem_storage_token']) || !empty($_COOKIE['bluem_storage_secret']) || !isset($_SERVER['SERVER_NAME'])) { + return false; + } + + // Generate a 32-character token + $token = bin2hex(random_bytes(16)); + + // Generate a 64-character secret + $secret = bin2hex(random_bytes(32)); + + $path = sanitize_text_field(wp_unslash($_SERVER['SERVER_NAME'])); + + setcookie('bluem_storage_token', $token, 0, '/', $path, false, true); + setcookie('bluem_storage_secret', $secret, 0, '/', $path, false, true); + + return [$token, $secret]; +} + /** * Insert data into storage * @@ -209,7 +229,11 @@ function bluem_db_insert_storage($object) $result = $wpdb->get_results($wpdb->prepare("SELECT id, data FROM $table_name WHERE token = %s AND secret = %s", $token, $secret)); if ($result) { - $decoded_data = json_decode($result[0]->data, true); + try { + $decoded_data = json_decode($result[0]->data, true, 512, JSON_THROW_ON_ERROR); + } catch (JsonException $e) { + $decoded_data = null; + } $record_id = $result[0]->id; @@ -224,7 +248,7 @@ function bluem_db_insert_storage($object) // Loop through new data foreach ($object as $key => $value) { - $new_object[$key] = $value; // Overwrite if key exists + $new_object[$key] = $value; } return bluem_db_update_storage( @@ -236,11 +260,6 @@ function bluem_db_insert_storage($object) } } - // Generate a 32-character token - $token = bin2hex(random_bytes(16)); - - // Generate a 64-character secret - $secret = bin2hex(random_bytes(32)); $db_result = $wpdb->insert( $wpdb->prefix . 'bluem_storage', @@ -254,13 +273,16 @@ function bluem_db_insert_storage($object) ) ); + $expiration = time() + (7 * 24 * 60 * 60); // 7 days + if ($db_result !== false && isset($_SERVER['SERVER_NAME'])) { // Set cookies for token and secret for - setcookie('bluem_storage_token', $token, 0, '/', sanitize_text_field(wp_unslash($_SERVER['SERVER_NAME'])), false, true); - setcookie('bluem_storage_secret', $secret, 0, '/', sanitize_text_field(wp_unslash($_SERVER['SERVER_NAME'])), false, true); + setcookie('bluem_storage_token', $token, $expiration, '/', sanitize_text_field(wp_unslash($_SERVER['SERVER_NAME'])), false, true); + setcookie('bluem_storage_secret', $secret, $expiration, '/', sanitize_text_field(wp_unslash($_SERVER['SERVER_NAME'])), false, true); return true; } + return false; } @@ -286,15 +308,18 @@ function bluem_db_get_storage($key = null) ); if ($result) { - // Decode the JSON data - $decoded_data = json_decode($result, true); + try { + $decoded_data = json_decode($result, true, 512, JSON_THROW_ON_ERROR); + } catch (JsonException $e) { + $decoded_data = null; + } if ($decoded_data !== null) { if ($key !== null && isset($decoded_data[$key])) { - return $decoded_data[$key]; // Return the specific key's value + return $decoded_data[$key]; } - return $decoded_data; // Return the entire decoded JSON data as an array + return $decoded_data; } } } diff --git a/bluem-idin.php b/bluem-idin.php index 79b22e6..3169953 100644 --- a/bluem-idin.php +++ b/bluem-idin.php @@ -895,7 +895,6 @@ function bluem_idin_form(): string return $html; } -add_action('parse_request', 'bluem_idin_shortcode_idin_execute'); /** * This function is called POST from the form rendered on a page or post * @@ -903,13 +902,6 @@ function bluem_idin_form(): string */ function bluem_idin_shortcode_idin_execute(): void { - $shortcode_execution_url = 'bluem-woocommerce/idin_execute'; - - if (!isset($_SERVER['REQUEST_URI']) || !str_contains(sanitize_url(wp_unslash($_SERVER['REQUEST_URI'])), $shortcode_execution_url)) { - // any other request - return; - } - $goto = false; if (!empty($_GET['redirect_to_checkout']) && sanitize_text_field(wp_unslash($_GET['redirect_to_checkout'])) === 'true' @@ -923,16 +915,11 @@ function bluem_idin_shortcode_idin_execute(): void bluem_idin_execute(null, true, $goto); } -add_action('parse_request', 'bluem_idin_shortcode_callback'); /** * This function is executed at a callback GET request with a given mandateId. This is then, together with the entranceCode in user or Bluem session storage, sent for a SUD to the Bluem API. */ function bluem_idin_shortcode_callback(): void { - if (!str_contains(sanitize_url(wp_unslash($_SERVER['REQUEST_URI'])), 'bluem-woocommerce/idin_shortcode_callback')) { - return; - } - $bluem_config = bluem_woocommerce_get_config(); // fallback until this is corrected in bluem-php @@ -1266,7 +1253,6 @@ function bluem_idin_shortcode_callback(): void exit; } -add_action('parse_request', 'bluem_idin_webhook'); /** * Identity webhook action * @@ -1274,9 +1260,6 @@ function bluem_idin_shortcode_callback(): void */ function bluem_idin_webhook(): void { - if (strpos(sanitize_url(wp_unslash($_SERVER['REQUEST_URI'])), 'bluem-woocommerce/bluem_idin_webhook') === false) { - return; - } http_response_code(200); exit; } diff --git a/bluem-integrations.php b/bluem-integrations.php index d90c63e..39f8032 100644 --- a/bluem-integrations.php +++ b/bluem-integrations.php @@ -183,16 +183,11 @@ function bluem_woocommerce_integration_gform_javascript() * ContactForm 7 integration. * AJAX Form submissions. */ -add_action('parse_request', 'bluem_woocommerce_integration_wpcf7_ajax'); function bluem_woocommerce_integration_wpcf7_ajax() { $bluem_config = bluem_woocommerce_get_config(); - if (!isset($_SERVER['REQUEST_URI']) || strpos(sanitize_url(wp_unslash($_SERVER['REQUEST_URI'])), 'bluem-woocommerce/bluem-integrations/wpcf7_mandate') === false) { - return; - } - $bluem_mandate_approve = !empty($_POST['bluem_mandate_approve']) ? sanitize_text_field(wp_unslash($_POST['bluem_mandate_approve'])) : ''; if ($bluem_config->wpcf7Active !== 'Y' || empty($bluem_mandate_approve)) { @@ -541,18 +536,12 @@ function bluem_woocommerce_integration_wpcf7_submit() * ContactForm 7 integration. * Callback for requests. */ -add_action('parse_request', 'bluem_woocommerce_integration_wpcf7_callback'); - function bluem_woocommerce_integration_wpcf7_callback() { $bluem_config = bluem_woocommerce_get_config(); $storage = bluem_db_get_storage(); - if (empty($_SERVER['REQUEST_URI']) || strpos(sanitize_url(wp_unslash($_SERVER['REQUEST_URI'])), 'bluem-woocommerce/bluem-integrations/wpcf7_callback') === false) { - return; - } - if ($bluem_config->wpcf7Active !== 'Y') { return; } @@ -1025,7 +1014,6 @@ function bluem_woocommerce_integration_gform_submit($entry, $form) * Gravity Forms integration. * Callback after request */ -add_action('parse_request', 'bluem_woocommerce_integration_gform_callback'); function bluem_woocommerce_integration_gform_callback() { @@ -1033,10 +1021,6 @@ function bluem_woocommerce_integration_gform_callback() $storage = bluem_db_get_storage(); - if (strpos(sanitize_url(wp_unslash($_SERVER['REQUEST_URI'])), 'bluem-woocommerce/bluem-integrations/gform_callback') === false) { - return; - } - if ($bluem_config->gformActive !== 'Y') { return; } diff --git a/bluem-interface.php b/bluem-interface.php index f360c6b..87feb74 100644 --- a/bluem-interface.php +++ b/bluem-interface.php @@ -29,7 +29,7 @@ function bluem_render_request_table($categoryName, $requests, $users_by_id = arr echo '

'; printf( /* translators: %s: Name of the category (Bluem service) */ - esc_html__('No transactions yet for %s', 'bluem'), + esc_html__('Nog geen transacties voor %s', 'bluem'), esc_attr($categoryName) ); echo '

'; diff --git a/bluem-mandates-instant.php b/bluem-mandates-instant.php index dccc41c..84a5af1 100644 --- a/bluem-mandates-instant.php +++ b/bluem-mandates-instant.php @@ -1,335 +1,340 @@ $debtorReference, - 'status' => 'Success', - ) - ); - - // Check the sequence type or previous success results - if ( $bluem_config->sequenceType === 'OOFF' || sizeof( $db_results ) === 0 ) { - $bluem_config->merchantReturnURLBase = home_url( - 'bluem-woocommerce/mandates_instant_callback' - ); - - $preferences = get_option( 'bluem_woocommerce_options' ); - - // Convert UTF-8 to ISO - if ( ! empty( $bluem_config->eMandateReason ) ) { - $bluem_config->eMandateReason = mb_convert_encoding( $bluem_config->eMandateReason, 'ISO-8859-1', 'UTF-8' ); - } else { - $bluem_config->eMandateReason = esc_html__( 'Incasso machtiging ', 'bluem' ) . $debtorReference; - } - - $bluem = new Bluem( $bluem_config ); - - $mandate_id_counter = get_option( 'bluem_woocommerce_mandate_id_counter' ); - - if ( ! isset( $mandate_id_counter ) ) { - $mandate_id_counter = $preferences['mandate_id_counter']; - } - - $mandate_id = $mandate_id_counter + 1; - - update_option( 'bluem_woocommerce_mandate_id_counter', $mandate_id ); - - $request = $bluem->CreateMandateRequest( - $debtorReference, - $debtorReference, - $mandate_id - ); - - // Actually perform the request. - try { - $response = $bluem->PerformRequest( $request ); - - if ( ! isset( $response->EMandateTransactionResponse->TransactionURL ) ) { - $msg = esc_html__( - 'Er ging iets mis bij het aanmaken van de transactie.
- Vermeld onderstaande informatie aan het websitebeheer:', - 'bluem' - ); - - if ( isset( $response->EMandateTransactionResponse->Error->ErrorMessage ) ) { - $msg .= '
' . - $response->EMandateTransactionResponse->Error->ErrorMessage; - } elseif ( $response instanceof \Bluem\BluemPHP\ErrorBluemResponse ) { - $msg .= '
' . - $response->Error(); - } else { - $msg .= '
Algemene fout'; - } - bluem_error_report_email( - array( - 'service' => 'mandates', - 'function' => 'shortcode_execute', - 'message' => $msg, - ) - ); - bluem_dialogs_render_prompt( $msg ); - exit; - } - - $mandate_id = $response->EMandateTransactionResponse->MandateID . ''; - - // redirect cast to string, necessary for AJAX response handling - $transactionURL = ( $response->EMandateTransactionResponse->TransactionURL . '' ); - - bluem_db_insert_storage( - array( - 'bluem_mandate_transaction_id' => $mandate_id, - 'bluem_mandate_transaction_url' => $transactionURL, - 'bluem_mandate_entrance_code' => $request->entranceCode, - ) - ); - - $db_creation_result = bluem_db_create_request( - array( - 'entrance_code' => $request->entranceCode, - 'transaction_id' => $request->mandateID, - 'transaction_url' => $transactionURL, - 'user_id' => 0, - 'timestamp' => gmdate( 'Y-m-d H:i:s' ), - 'description' => 'Mandate request', - 'debtor_reference' => $debtorReference, - 'type' => 'mandates', - 'order_id' => '', - 'payload' => wp_json_encode( - array( - 'created_via' => 'instant_request', - 'environment' => $bluem->getConfig( 'environment' ), - 'created_mandate_id' => $mandate_id, - ) - ), - ) - ); - - if ( ob_get_length() !== false && ob_get_length() > 0 ) { - ob_clean(); - } - - ob_start(); - wp_redirect( $transactionURL ); - exit; - } catch ( \Exception $e ) { - - } - } else { - wp_redirect( $bluem_config->instantMandatesResponseURI . '?result=true' ); - exit; - } - } - exit; -} -add_action( 'parse_request', 'bluem_mandates_instant_callback' ); +function bluem_mandates_instant_request(): void +{ + $bluem_config = bluem_woocommerce_get_config(); + + $debtorReference = !empty($_GET['debtorreference']) ? sanitize_text_field(wp_unslash($_GET['debtorreference'])) : ''; + // get from either casing for the key + if (empty($debtorReference)) { + $debtorReference = !empty($_GET['debtorReference']) ? sanitize_text_field(wp_unslash($_GET['debtorReference'])) : ''; + } + + if (empty($debtorReference)) { + $errormessage = esc_html__('Fout: geen debtorReferentie opgegeven', 'bluem'); + bluem_error_report_email( + array( + 'service' => 'mandates', + 'function' => 'shortcode_execute', + 'message' => $errormessage, + ) + ); + bluem_dialogs_render_prompt($errormessage); + exit; + } + + $debtorReference = sanitize_text_field($debtorReference); + + $db_results = bluem_db_get_requests_by_keyvalues( + array( + 'debtor_reference' => $debtorReference, + 'status' => 'Success', + ) + ); + + // Check the sequence type or previous success results + if ($bluem_config->sequenceType === 'OOFF' || sizeof($db_results) === 0) { + $bluem_config->merchantReturnURLBase = home_url( + 'bluem-woocommerce/mandates_instant_callback' + ); + + $preferences = get_option('bluem_woocommerce_options'); + + // Convert UTF-8 to ISO + if (!empty($bluem_config->eMandateReason)) { + $bluem_config->eMandateReason = mb_convert_encoding($bluem_config->eMandateReason, 'ISO-8859-1', 'UTF-8'); + } else { + $bluem_config->eMandateReason = esc_html__('Incasso machtiging ', 'bluem') . $debtorReference; + } + + $bluem = new Bluem($bluem_config); + + $mandate_id_counter = get_option('bluem_woocommerce_mandate_id_counter'); + + if (!isset($mandate_id_counter)) { + $mandate_id_counter = $preferences['mandate_id_counter']; + } + + $mandate_id = $mandate_id_counter + 1; + + update_option('bluem_woocommerce_mandate_id_counter', $mandate_id); + + $request = $bluem->CreateMandateRequest( + $debtorReference, + $debtorReference, + $mandate_id + ); + + // Actually perform the request. + try { + $response = $bluem->PerformRequest($request); + + if (!isset($response->EMandateTransactionResponse->TransactionURL)) { + $msg = esc_html__( + 'Er ging iets mis bij het aanmaken van de transactie.
+ Vermeld onderstaande informatie aan het websitebeheer:', + 'bluem' + ); + + if (isset($response->EMandateTransactionResponse->Error->ErrorMessage)) { + $msg .= '
' . + $response->EMandateTransactionResponse->Error->ErrorMessage; + } elseif ($response instanceof \Bluem\BluemPHP\ErrorBluemResponse) { + $msg .= '
' . + $response->Error(); + } else { + $msg .= '
Algemene fout'; + } + bluem_error_report_email( + array( + 'service' => 'mandates', + 'function' => 'shortcode_execute', + 'message' => $msg, + ) + ); + bluem_dialogs_render_prompt($msg); + exit; + } + + $mandate_id = $response->EMandateTransactionResponse->MandateID . ''; + + // redirect cast to string, necessary for AJAX response handling + $transactionURL = ($response->EMandateTransactionResponse->TransactionURL . ''); + + bluem_db_insert_storage( + array( + 'bluem_mandate_transaction_id' => $mandate_id, + 'bluem_mandate_transaction_url' => $transactionURL, + 'bluem_mandate_entrance_code' => $request->entranceCode, + ) + ); + + $db_creation_result = bluem_db_create_request( + array( + 'entrance_code' => $request->entranceCode, + 'transaction_id' => $request->mandateID, + 'transaction_url' => $transactionURL, + 'user_id' => 0, + 'timestamp' => gmdate('Y-m-d H:i:s'), + 'description' => 'Mandate request', + 'debtor_reference' => $debtorReference, + 'type' => 'mandates', + 'order_id' => '', + 'payload' => wp_json_encode( + array( + 'created_via' => 'instant_request', + 'environment' => $bluem->getConfig('environment'), + 'created_mandate_id' => $mandate_id, + ) + ), + ) + ); + + if (ob_get_length() !== false && ob_get_length() > 0) { + ob_clean(); + } + + ob_start(); + wp_redirect($transactionURL); + exit; + } catch (\Exception $e) { + + } + } else { + wp_redirect($bluem_config->instantMandatesResponseURI . '?result=true'); + exit; + } +} /** * This function is executed at a callback GET request with a given mandateId. This is then, together with the entranceCode in Cookie, sent for a SUD to the Bluem API. * * @return void */ -function bluem_mandates_instant_callback() { - if ( empty( $_SERVER['REQUEST_URI'] ) || ( strpos( sanitize_url( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 'bluem-woocommerce/mandates_instant_callback' ) === false ) ) { - return; - } - - $bluem_config = bluem_woocommerce_get_config(); - - try { - $bluem = new Bluem( $bluem_config ); - } catch ( Exception $e ) { - // @todo: deal with incorrectly setup Bluem - } - - $storage = bluem_db_get_storage(); - - $mandateID = $storage['bluem_mandate_transaction_id'] ?? 0; - - $entranceCode = $storage['bluem_mandate_entrance_code'] ?? ''; - - if ( empty( $mandateID ) ) { - if ( ! empty( $bluem_config->instantMandatesResponseURI ) ) { - wp_redirect( $bluem_config->instantMandatesResponseURI . '?result=false&reason=error' ); - exit; - } - $errormessage = esc_html__( 'Fout: geen juist mandaat id teruggekregen bij callback. Neem contact op met de webshop en vermeld je contactgegevens.', 'bluem' ); - bluem_error_report_email( - array( - 'service' => 'mandates', - 'function' => 'shortcode_callback', - 'message' => $errormessage, - ) - ); - bluem_dialogs_render_prompt( $errormessage ); - exit; - } - - if ( empty( $entranceCode ) ) { - $errormessage = esc_html__( 'Fout: Entrancecode is niet set; kan dus geen mandaat opvragen', 'bluem' ); - bluem_error_report_email( - array( - 'service' => 'mandates', - 'function' => 'shortcode_callback', - 'message' => $errormessage, - ) - ); - bluem_dialogs_render_prompt( $errormessage ); - exit; - } - - $response = $bluem->MandateStatus( $mandateID, $entranceCode ); - - if ( ! $response->Status() ) { - $errormessage = sprintf( - /* translators: %s: status code */ - esc_html__( 'Fout bij opvragen status: %s. Neem contact op met de webshop en vermeld deze status', 'bluem' ), - $response->Error() - ); - bluem_error_report_email( - array( - 'service' => 'mandates', - 'function' => 'shortcode_callback', - 'message' => $errormessage, - ) - ); - bluem_dialogs_render_prompt( $errormessage ); - exit; - } - $statusUpdateObject = $response->EMandateStatusUpdate; - $statusCode = $statusUpdateObject->EMandateStatus->Status . ''; - - $request_from_db = bluem_db_get_request_by_transaction_id_and_type( - $mandateID, - 'mandates' - ); - - if ( $statusCode !== $request_from_db->status ) { - bluem_db_update_request( - $request_from_db->id, - array( - 'status' => $statusCode, - ) - ); - // also update locally for email notification - $request_from_db->status = $statusCode; - } - - bluem_transaction_notification_email( - $request_from_db->id - ); - - // Handling the response. - if ( $statusCode === 'Success' ) { - if ( ! empty( $request_from_db->payload ) ) { - try { - $newPayload = json_decode( $request_from_db->payload ); - } catch ( Throwable $th ) { - $newPayload = new Stdclass(); - } - } else { - $newPayload = new Stdclass(); - } - - if ( isset( $response->EMandateStatusUpdate->EMandateStatus->AcceptanceReport ) ) { - $newPayload->purchaseID = $response->EMandateStatusUpdate->EMandateStatus->PurchaseID . ''; - $newPayload->report = $response->EMandateStatusUpdate->EMandateStatus->AcceptanceReport; - - bluem_db_update_request( - $request_from_db->id, - array( - 'payload' => wp_json_encode( $newPayload ), - ) - ); - } - - $request_from_db = bluem_db_get_request_by_transaction_id_and_type( - $mandateID, - 'mandates' - ); - - // "De ondertekening is geslaagd"; - if ( ! empty( $bluem_config->instantMandatesResponseURI ) ) { - wp_redirect( $bluem_config->instantMandatesResponseURI . '?result=true' ); - exit; - } - $errormessage = esc_html__( 'Fout: de ondertekening is geslaagd maar er is geen response URI opgegeven. Neem contact op met de website om dit technisch probleem aan te geven.', 'bluem' ); - bluem_error_report_email( - array( - 'service' => 'mandates', - 'function' => 'instant_callback', - 'message' => $errormessage, - ) - ); - bluem_dialogs_render_prompt( $errormessage ); - exit; - } - - if ( $statusCode === 'Cancelled' ) { - // "Je hebt de mandaat ondertekening geannuleerd"; - if ( ! empty( $bluem_config->instantMandatesResponseURI ) ) { - wp_redirect( $bluem_config->instantMandatesResponseURI . '?result=false&reason=cancelled' ); - exit; - } - $errormessage = esc_html__( 'Fout: de transactie is geannuleerd. Probeer het opnieuw.', 'bluem' ); - bluem_dialogs_render_prompt( $errormessage ); - exit; - } - - if ( $statusCode === 'Open' || $statusCode === 'Pending' ) { - // "De mandaat ondertekening is nog niet bevestigd. Dit kan even duren maar gebeurt automatisch." - if ( ! empty( $bluem_config->instantMandatesResponseURI ) ) { - wp_redirect( $bluem_config->instantMandatesResponseURI . '?result=false&reason=open' ); - exit; - } - $errormessage = esc_html__( 'Fout: de transactie staat nog open. Dit kan even duren. Vernieuw deze pagina regelmatig voor de status.', 'bluem' ); - bluem_dialogs_render_prompt( $errormessage ); - exit; - } - - if ( $statusCode === 'Expired' ) { - // "Fout: De mandaat of het verzoek daartoe is verlopen"; - if ( ! empty( $bluem_config->instantMandatesResponseURI ) ) { - wp_redirect( $bluem_config->instantMandatesResponseURI . '?result=false&reason=expired' ); - exit; - } - $errormessage = esc_html__( 'Fout: de transactie is verlopen. Probeer het opnieuw.', 'bluem' ); - bluem_dialogs_render_prompt( $errormessage ); - exit; - } - - bluem_error_report_email( - array( - 'service' => 'mandates', - 'function' => 'shortcode_callback', - 'message' => sprintf( - /* translators: %s: status code */ - esc_html__( 'Fout: Onbekende of foutieve status teruggekregen: %s
Neem contact op met de webshop en vermeld deze status; gebruiker wel doorverwezen terug naar site', 'bluem' ), - $statusCode - ), - ) - ); - wp_redirect( $bluem_config->instantMandatesResponseURI . '?result=false&reason=error' ); - exit; +function bluem_mandates_instant_callback() +{ + $bluem_config = bluem_woocommerce_get_config(); + + try { + $bluem = new Bluem($bluem_config); + } catch (Exception $e) { + // @todo: deal with incorrectly setup Bluem + } + + $storage = bluem_db_get_storage(); + + $mandateID = $storage['bluem_mandate_transaction_id'] ?? 0; + + $entranceCode = $storage['bluem_mandate_entrance_code'] ?? ''; + + if (empty($mandateID)) { + if (!empty($bluem_config->instantMandatesResponseURI)) { + wp_redirect($bluem_config->instantMandatesResponseURI . '?result=false&reason=error'); + exit; + } + $errormessage = esc_html__('Fout: geen juist mandaat id teruggekregen bij callback. Neem contact op met de webshop en vermeld je contactgegevens.', 'bluem'); + bluem_error_report_email( + array( + 'service' => 'mandates', + 'function' => 'shortcode_callback', + 'message' => $errormessage, + ) + ); + bluem_dialogs_render_prompt($errormessage); + exit; + } + + if (empty($entranceCode)) { + $errormessage = esc_html__('Fout: Entrancecode is niet set; kan dus geen mandaat opvragen', 'bluem'); + bluem_error_report_email( + array( + 'service' => 'mandates', + 'function' => 'shortcode_callback', + 'message' => $errormessage, + ) + ); + bluem_dialogs_render_prompt($errormessage); + exit; + } + + $response = $bluem->MandateStatus($mandateID, $entranceCode); + + if (!$response->Status()) { + $errormessage = sprintf( + /* translators: %s: status code */ + esc_html__('Fout bij opvragen status: %s. Neem contact op met de webshop en vermeld deze status', 'bluem'), + $response->Error() + ); + bluem_error_report_email( + array( + 'service' => 'mandates', + 'function' => 'shortcode_callback', + 'message' => $errormessage, + ) + ); + bluem_dialogs_render_prompt($errormessage); + exit; + } + $statusUpdateObject = $response->EMandateStatusUpdate; + $statusCode = $statusUpdateObject->EMandateStatus->Status . ''; + + $request_from_db = bluem_db_get_request_by_transaction_id_and_type( + $mandateID, + 'mandates' + ); + + if ($statusCode !== $request_from_db->status) { + bluem_db_update_request( + $request_from_db->id, + array( + 'status' => $statusCode, + ) + ); + // also update locally for email notification + $request_from_db->status = $statusCode; + } + + bluem_transaction_notification_email( + $request_from_db->id + ); + + // Handling the response. + if ($statusCode === 'Success') { + if (!empty($request_from_db->payload)) { + try { + $newPayload = json_decode($request_from_db->payload); + } catch (Throwable $th) { + $newPayload = new Stdclass(); + } + } else { + $newPayload = new Stdclass(); + } + + if (isset($response->EMandateStatusUpdate->EMandateStatus->AcceptanceReport)) { + $newPayload->purchaseID = $response->EMandateStatusUpdate->EMandateStatus->PurchaseID . ''; + $newPayload->report = $response->EMandateStatusUpdate->EMandateStatus->AcceptanceReport; + + bluem_db_update_request( + $request_from_db->id, + array( + 'payload' => wp_json_encode($newPayload), + ) + ); + } + + $request_from_db = bluem_db_get_request_by_transaction_id_and_type( + $mandateID, + 'mandates' + ); + + // "De ondertekening is geslaagd"; + if (!empty($bluem_config->instantMandatesResponseURI)) { + wp_redirect($bluem_config->instantMandatesResponseURI . '?result=true'); + exit; + } + $errormessage = esc_html__('Fout: de ondertekening is geslaagd maar er is geen response URI opgegeven. Neem contact op met de website om dit technisch probleem aan te geven.', 'bluem'); + bluem_error_report_email( + array( + 'service' => 'mandates', + 'function' => 'instant_callback', + 'message' => $errormessage, + ) + ); + bluem_dialogs_render_prompt($errormessage); + exit; + } + + if ($statusCode === 'Cancelled') { + // "Je hebt de mandaat ondertekening geannuleerd"; + if (!empty($bluem_config->instantMandatesResponseURI)) { + wp_redirect($bluem_config->instantMandatesResponseURI . '?result=false&reason=cancelled'); + exit; + } + $errormessage = esc_html__('Fout: de transactie is geannuleerd. Probeer het opnieuw.', 'bluem'); + bluem_dialogs_render_prompt($errormessage); + exit; + } + + if ($statusCode === 'Open' || $statusCode === 'Pending') { + // "De mandaat ondertekening is nog niet bevestigd. Dit kan even duren maar gebeurt automatisch." + if (!empty($bluem_config->instantMandatesResponseURI)) { + wp_redirect($bluem_config->instantMandatesResponseURI . '?result=false&reason=open'); + exit; + } + $errormessage = esc_html__('Fout: de transactie staat nog open. Dit kan even duren. Vernieuw deze pagina regelmatig voor de status.', 'bluem'); + bluem_dialogs_render_prompt($errormessage); + exit; + } + + if ($statusCode === 'Expired') { + // "Fout: De mandaat of het verzoek daartoe is verlopen"; + if (!empty($bluem_config->instantMandatesResponseURI)) { + wp_redirect($bluem_config->instantMandatesResponseURI . '?result=false&reason=expired'); + exit; + } + $errormessage = esc_html__('Fout: de transactie is verlopen. Probeer het opnieuw.', 'bluem'); + bluem_dialogs_render_prompt($errormessage); + exit; + } + + bluem_error_report_email( + array( + 'service' => 'mandates', + 'function' => 'shortcode_callback', + 'message' => sprintf( + /* translators: %s: status code */ + esc_html__('Fout: Onbekende of foutieve status teruggekregen: %s
Neem contact op met de webshop en vermeld deze status; gebruiker wel doorverwezen terug naar site', 'bluem'), + $statusCode + ), + ) + ); + wp_redirect($bluem_config->instantMandatesResponseURI . '?result=false&reason=error'); + exit; } diff --git a/bluem-mandates-shortcode.php b/bluem-mandates-shortcode.php index 5a85c23..0773a10 100644 --- a/bluem-mandates-shortcode.php +++ b/bluem-mandates-shortcode.php @@ -1,13 +1,11 @@ merchantReturnURLBase = home_url( - 'bluem-woocommerce/mandate_shortcode_callback' - ); - - // Check for recurring mode - if ( $bluem_config->sequenceType === 'RCUR' ) { - if ( ! empty( $storage['bluem_mandate_debtorreference'] ) ) { - $debtorReference = $storage['bluem_mandate_debtorreference']; - - $db_query = array( - 'debtor_reference' => $debtorReference, - 'user_id' => get_current_user_id(), - 'status' => 'Success', - ); - - // Check for a successful transaction - $db_results = bluem_db_get_requests_by_keyvalues( $db_query ); - - if ( $db_results !== false && is_array( $db_results ) && sizeof( $db_results ) > 0 ) { - $mandateID = $db_results[0]->transaction_id; - - bluem_db_insert_storage( - array( - 'bluem_mandate_transaction_id' => $mandateID, - ) - ); - - if ( ! empty( $current_user ) ) { - if ( current_user_can( 'edit_user', $current_user->ID ) ) { - update_user_meta( $current_user->ID, 'bluem_mandates_validated', true ); - update_user_meta( $current_user->ID, 'bluem_latest_mandate_id', $mandateID ); - } - } - - wp_redirect( home_url( $bluem_config->thanksPageURL ) . '?result=true' ); - exit; - } - } elseif ( ! empty( $_POST['bluem_debtorReference'] ) ) { - $debtorReference = sanitize_text_field( $_POST['bluem_debtorReference'] ); - - bluem_db_insert_storage( - array( - 'bluem_mandate_debtorreference' => $debtorReference, - ) - ); - - $db_query = array( - 'debtor_reference' => $debtorReference, - 'user_id' => get_current_user_id(), - 'status' => 'Success', - ); - - // Check for a successful transaction - $db_results = bluem_db_get_requests_by_keyvalues( $db_query ); - - if ( $db_results !== false && is_array( $db_results ) && sizeof( $db_results ) > 0 ) { - $mandateID = $db_results[0]->transaction_id; - - bluem_db_insert_storage( - array( - 'bluem_mandate_transaction_id' => $mandateID, - ) - ); - - if ( ! empty( $current_user ) ) { - if ( current_user_can( 'edit_user', $current_user->ID ) ) { - update_user_meta( $current_user->ID, 'bluem_mandates_validated', true ); - update_user_meta( $current_user->ID, 'bluem_latest_mandate_id', $mandateID ); - } - } - - wp_redirect( home_url( $bluem_config->thanksPageURL ) . '?result=true' ); - - exit; - } - } elseif ( is_user_logged_in() ) { - $debtorReference = $current_user->user_nicename(); - - bluem_db_insert_storage( - array( - 'bluem_mandate_debtorreference' => $debtorReference, - ) - ); - } - } elseif ( $bluem_config->sequenceType === 'OOFF' ) { - if ( ! empty( $_POST['bluem_debtorReference'] ) ) { - $debtorReference = sanitize_text_field( $_POST['bluem_debtorReference'] ); - - bluem_db_insert_storage( - array( - 'bluem_mandate_debtorreference' => $debtorReference, - ) - ); - } elseif ( is_user_logged_in() ) { - $debtorReference = $current_user->user_nicename(); - - bluem_db_insert_storage( - array( - 'bluem_mandate_debtorreference' => $debtorReference, - ) - ); - } - } - - $preferences = get_option( 'bluem_woocommerce_options' ); - - // Convert UTF-8 to ISO - if ( ! empty( $bluem_config->eMandateReason ) ) { - $bluem_config->eMandateReason = mb_convert_encoding( $bluem_config->eMandateReason, 'ISO-8859-1', 'UTF-8' ); - } else { - $bluem_config->eMandateReason = 'Incasso machtiging ' . $debtorReference; - } - - $bluem = new Bluem( $bluem_config ); - - $mandate_id_counter = get_option( 'bluem_woocommerce_mandate_id_counter' ); - - if ( ! isset( $mandate_id_counter ) ) { - $mandate_id_counter = $preferences['mandate_id_counter']; - } - - $mandate_id = $mandate_id_counter + 1; - - update_option( 'bluem_woocommerce_mandate_id_counter', $mandate_id ); - - $request = $bluem->CreateMandateRequest( - $debtorReference, - $current_user->ID, - $mandate_id - ); - - // Save the necessary data to later request more information and refer to this transaction - bluem_db_insert_storage( - array( - 'bluem_mandate_transaction_id' => $request->mandateID, - 'bluem_mandate_entrance_code' => $request->entranceCode, - ) - ); - - if ( ! empty( $current_user ) ) { - if ( current_user_can( 'edit_user', $current_user->ID ) ) { - update_user_meta( - $current_user->ID, - 'bluem_latest_mandate_entrance_code', - $request->entranceCode - ); - } - } - - // Actually perform the request. - $response = $bluem->PerformRequest( $request ); - - if ( ! isset( $response->EMandateTransactionResponse->TransactionURL ) ) { - $msg = esc_html__( - 'Er ging iets mis bij het aanmaken van de transactie.
+function bluem_mandate_shortcode_execute(): void +{ + $nonce = $_REQUEST['_wpnonce']; + if (!wp_verify_nonce($nonce, 'bluem-nonce')) { + die('Did not pass security check'); + } + + global $current_user; + + $storage = bluem_db_get_storage(); + + if (isset($_POST['bluem-submitted'])) { + $debtorReference = ''; + + $bluem_config = bluem_woocommerce_get_config(); + + $bluem_config->merchantReturnURLBase = home_url( + 'bluem-woocommerce/mandate_shortcode_callback' + ); + + // Check for recurring mode + if ($bluem_config->sequenceType === 'RCUR') { + if (!empty($storage['bluem_mandate_debtorreference'])) { + $debtorReference = $storage['bluem_mandate_debtorreference']; + + $db_query = array( + 'debtor_reference' => $debtorReference, + 'user_id' => get_current_user_id(), + 'status' => 'Success', + ); + + // Check for a successful transaction + $db_results = bluem_db_get_requests_by_keyvalues($db_query); + + if ($db_results !== false && is_array($db_results) && sizeof($db_results) > 0) { + $mandateID = $db_results[0]->transaction_id; + + bluem_db_insert_storage( + array( + 'bluem_mandate_transaction_id' => $mandateID, + ) + ); + + if (!empty($current_user)) { + if (current_user_can('edit_user', $current_user->ID)) { + update_user_meta($current_user->ID, 'bluem_mandates_validated', true); + update_user_meta($current_user->ID, 'bluem_latest_mandate_id', $mandateID); + } + } + + wp_redirect(home_url($bluem_config->thanksPageURL) . '?result=true'); + exit; + } + } elseif (!empty($_POST['bluem_debtorReference'])) { + $debtorReference = sanitize_text_field($_POST['bluem_debtorReference']); + + bluem_db_insert_storage( + array( + 'bluem_mandate_debtorreference' => $debtorReference, + ) + ); + + $db_query = array( + 'debtor_reference' => $debtorReference, + 'user_id' => get_current_user_id(), + 'status' => 'Success', + ); + + // Check for a successful transaction + $db_results = bluem_db_get_requests_by_keyvalues($db_query); + + if ($db_results !== false && is_array($db_results) && sizeof($db_results) > 0) { + $mandateID = $db_results[0]->transaction_id; + + bluem_db_insert_storage( + array( + 'bluem_mandate_transaction_id' => $mandateID, + ) + ); + + if (!empty($current_user)) { + if (current_user_can('edit_user', $current_user->ID)) { + update_user_meta($current_user->ID, 'bluem_mandates_validated', true); + update_user_meta($current_user->ID, 'bluem_latest_mandate_id', $mandateID); + } + } + + wp_redirect(home_url($bluem_config->thanksPageURL) . '?result=true'); + + exit; + } + } elseif (is_user_logged_in()) { + $debtorReference = $current_user->user_nicename(); + + bluem_db_insert_storage( + array( + 'bluem_mandate_debtorreference' => $debtorReference, + ) + ); + } + } elseif ($bluem_config->sequenceType === 'OOFF') { + if (!empty($_POST['bluem_debtorReference'])) { + $debtorReference = sanitize_text_field($_POST['bluem_debtorReference']); + + bluem_db_insert_storage( + array( + 'bluem_mandate_debtorreference' => $debtorReference, + ) + ); + } elseif (is_user_logged_in()) { + $debtorReference = $current_user->user_nicename(); + + bluem_db_insert_storage( + array( + 'bluem_mandate_debtorreference' => $debtorReference, + ) + ); + } + } + + $preferences = get_option('bluem_woocommerce_options'); + + // Convert UTF-8 to ISO + if (!empty($bluem_config->eMandateReason)) { + $bluem_config->eMandateReason = mb_convert_encoding($bluem_config->eMandateReason, 'ISO-8859-1', 'UTF-8'); + } else { + $bluem_config->eMandateReason = 'Incasso machtiging ' . $debtorReference; + } + + $bluem = new Bluem($bluem_config); + + $mandate_id_counter = get_option('bluem_woocommerce_mandate_id_counter'); + + if (!isset($mandate_id_counter)) { + $mandate_id_counter = $preferences['mandate_id_counter']; + } + + $mandate_id = $mandate_id_counter + 1; + + update_option('bluem_woocommerce_mandate_id_counter', $mandate_id); + + $request = $bluem->CreateMandateRequest( + $debtorReference, + $current_user->ID, + $mandate_id + ); + + // Save the necessary data to later request more information and refer to this transaction + bluem_db_insert_storage( + array( + 'bluem_mandate_transaction_id' => $request->mandateID, + 'bluem_mandate_entrance_code' => $request->entranceCode, + ) + ); + + if (!empty($current_user)) { + if (current_user_can('edit_user', $current_user->ID)) { + update_user_meta( + $current_user->ID, + 'bluem_latest_mandate_entrance_code', + $request->entranceCode + ); + } + } + + // Actually perform the request. + $response = $bluem->PerformRequest($request); + + if (!isset($response->EMandateTransactionResponse->TransactionURL)) { + $msg = esc_html__( + 'Er ging iets mis bij het aanmaken van de transactie.
Vermeld onderstaande informatie aan het websitebeheer:', - 'bluem' - ); - - if ( isset( $response->EMandateTransactionResponse->Error->ErrorMessage ) ) { - $msg .= '
' . - esc_html( $response->EMandateTransactionResponse->Error->ErrorMessage ); - } elseif ( get_class( $response ) == 'Bluem\BluemPHP\ErrorBluemResponse' ) { - $msg .= '
' . - esc_html( $response->Error() ); - } else { - $msg .= '
' . esc_html( 'Algemene fout', 'bluem' ); - } - bluem_error_report_email( - array( - 'service' => 'mandates', - 'function' => 'shortcode_execute', - 'message' => $msg, - ) - ); - bluem_dialogs_render_prompt( $msg ); - exit; - } - - $mandate_id = $response->EMandateTransactionResponse->MandateID . ''; - - // redirect cast to string, necessary for AJAX response handling - $transactionURL = ( $response->EMandateTransactionResponse->TransactionURL . '' ); - - bluem_db_insert_storage( - array( - 'bluem_mandate_transaction_id' => $mandate_id, - 'bluem_mandate_transaction_url' => $transactionURL, - ) - ); - - if ( ! empty( $current_user ) ) { - if ( current_user_can( 'edit_user', $current_user->ID ) ) { - update_user_meta( - $current_user->ID, - 'bluem_latest_mandate_id', - $mandate_id - ); - } - } - - bluem_db_create_request( - array( - 'entrance_code' => $request->entranceCode, - 'transaction_id' => $request->mandateID, - 'transaction_url' => $transactionURL, - 'user_id' => get_current_user_id(), - 'timestamp' => gmdate( 'Y-m-d H:i:s' ), - 'description' => 'Mandate request', - 'debtor_reference' => $debtorReference, - 'type' => 'mandates', - 'order_id' => '', - 'payload' => wp_json_encode( - array( - 'created_via' => 'shortcode', - 'environment' => $bluem->getConfig( 'environment' ), - 'created_mandate_id' => $mandate_id, - ) - ), - ) - ); - - if ( ob_get_length() !== false && ob_get_length() > 0 ) { - ob_clean(); - } - - ob_start(); - wp_redirect( $transactionURL ); - exit; - } - exit; + 'bluem' + ); + + if (isset($response->EMandateTransactionResponse->Error->ErrorMessage)) { + $msg .= '
' . + esc_html($response->EMandateTransactionResponse->Error->ErrorMessage); + } elseif (get_class($response) == 'Bluem\BluemPHP\ErrorBluemResponse') { + $msg .= '
' . + esc_html($response->Error()); + } else { + $msg .= '
' . esc_html('Algemene fout', 'bluem'); + } + bluem_error_report_email( + array( + 'service' => 'mandates', + 'function' => 'shortcode_execute', + 'message' => $msg, + ) + ); + bluem_dialogs_render_prompt($msg); + exit; + } + + $mandate_id = $response->EMandateTransactionResponse->MandateID . ''; + + // redirect cast to string, necessary for AJAX response handling + $transactionURL = ($response->EMandateTransactionResponse->TransactionURL . ''); + + bluem_db_insert_storage( + array( + 'bluem_mandate_transaction_id' => $mandate_id, + 'bluem_mandate_transaction_url' => $transactionURL, + ) + ); + + if (!empty($current_user)) { + if (current_user_can('edit_user', $current_user->ID)) { + update_user_meta( + $current_user->ID, + 'bluem_latest_mandate_id', + $mandate_id + ); + } + } + + bluem_db_create_request( + array( + 'entrance_code' => $request->entranceCode, + 'transaction_id' => $request->mandateID, + 'transaction_url' => $transactionURL, + 'user_id' => get_current_user_id(), + 'timestamp' => gmdate('Y-m-d H:i:s'), + 'description' => 'Mandate request', + 'debtor_reference' => $debtorReference, + 'type' => 'mandates', + 'order_id' => '', + 'payload' => wp_json_encode( + array( + 'created_via' => 'shortcode', + 'environment' => $bluem->getConfig('environment'), + 'created_mandate_id' => $mandate_id, + ) + ), + ) + ); + + if (ob_get_length() !== false && ob_get_length() > 0) { + ob_clean(); + } + + ob_start(); + wp_redirect($transactionURL); + exit; + } + exit; } -add_action( 'parse_request', 'bluem_mandate_mandate_shortcode_callback' ); /** * This function is executed at a callback GET request with a given mandateId. This is then, together with the entranceCode in Cookie, sent for a SUD to the Bluem API. * * @return void */ -function bluem_mandate_mandate_shortcode_callback(): void { - if ( strpos( sanitize_url( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 'bluem-woocommerce/mandate_shortcode_callback' ) === false ) { - return; - } - - global $current_user; - - $bluem_config = bluem_woocommerce_get_config(); - - $bluem_config->merchantReturnURLBase = home_url( 'wc-api/bluem_mandates_callback' ); - - $storage = bluem_db_get_storage(); - - try { - $bluem = new Bluem( $bluem_config ); - } catch ( Exception $e ) { - // @todo: deal with incorrectly setup Bluem - // $e->getMessage(); - } - - // @todo: .. then use request-based approach soon as first check, then fallback to user meta check. - if ( ! empty( $current_user->ID ) ) { - $mandateID = get_user_meta( $current_user->ID, 'bluem_latest_mandate_id', true ); - $entranceCode = get_user_meta( $current_user->ID, 'bluem_latest_mandate_entrance_code', true ); - } else { - $mandateID = $storage['bluem_mandate_transaction_id'] ?? 0; - $entranceCode = $storage['bluem_mandate_entrance_code'] ?? ''; - } - - if ( ! isset( $_GET['mandateID'] ) ) { - if ( $bluem_config->thanksPageURL !== '' ) { - wp_redirect( home_url( $bluem_config->thanksPageURL ) . '?result=false&reason=error' ); - // echo "

Er is een fout opgetreden. De incassomachtiging is geannuleerd.

"; - return; - } - $errormessage = esc_html__( 'Fout: geen juist mandaat id teruggekregen bij callback. Neem contact op met de webshop en vermeld je contactgegevens.', 'bluem' ); - bluem_error_report_email( - array( - 'service' => 'mandates', - 'function' => 'shortcode_callback', - 'message' => $errormessage, - ) - ); - bluem_dialogs_render_prompt( $errormessage ); - exit; - } - - if ( empty( $entranceCode ) ) { - $errormessage = esc_html__( 'Fout: Entrancecode is niet set; kan dus geen mandaat opvragen', 'bluem' ); - bluem_error_report_email( - array( - 'service' => 'mandates', - 'function' => 'shortcode_callback', - 'message' => $errormessage, - ) - ); - bluem_dialogs_render_prompt( $errormessage ); - exit; - } - - $response = $bluem->MandateStatus( $mandateID, $entranceCode ); - - if ( ! $response->Status() ) { - $errormessage = - sprintf( - /* translators: %s: Error message */ - esc_html__( 'Fout bij opvragen status: %s. Neem contact op met de webshop en vermeld deze status', 'bluem' ), - $response->Error() - ); - bluem_error_report_email( - array( - 'service' => 'mandates', - 'function' => 'shortcode_callback', - 'message' => $errormessage, - ) - ); - bluem_dialogs_render_prompt( $errormessage ); - exit; - } - - $statusUpdateObject = $response->EMandateStatusUpdate; - $statusCode = $statusUpdateObject->EMandateStatus->Status . ''; - - $request_from_db = bluem_db_get_request_by_transaction_id_and_type( - $mandateID, - 'mandates' - ); - - if ( $statusCode !== $request_from_db->status ) { - bluem_db_update_request( - $request_from_db->id, - array( - 'status' => $statusCode, - ) - ); - // also update locally for email notification - $request_from_db->status = $statusCode; - } - - bluem_transaction_notification_email( - $request_from_db->id - ); - - // Handling the response. - if ( $statusCode === 'Success' ) { - // Define a cookie so that this will be recognised the next time - bluem_db_insert_storage( - array( - 'bluem_mandate_transaction_id' => $mandateID, - ) - ); - - if ( ! empty( $current_user ) ) { - if ( current_user_can( 'edit_user', $current_user->ID ) ) { - update_user_meta( $current_user->ID, 'bluem_mandates_validated', true ); - } - } - - if ( $request_from_db->payload !== '' ) { - try { - $newPayload = json_decode( $request_from_db->payload ); - } catch ( Throwable $th ) { - $newPayload = new Stdclass(); - } - } else { - $newPayload = new Stdclass(); - } - - if ( isset( $response->EMandateStatusUpdate->EMandateStatus->AcceptanceReport ) ) { - $newPayload->purchaseID = $response->EMandateStatusUpdate->EMandateStatus->PurchaseID . ''; - $newPayload->report = $response->EMandateStatusUpdate->EMandateStatus->AcceptanceReport; - - bluem_db_update_request( - $request_from_db->id, - array( - 'payload' => wp_json_encode( $newPayload ), - ) - ); - } - wp_redirect( home_url( $bluem_config->thanksPageURL ) . '?result=true' ); - exit; - } elseif ( $statusCode === 'Cancelled' ) { - // "Je hebt de mandaat ondertekening geannuleerd"; - wp_redirect( home_url( $bluem_config->thanksPageURL ) . '?result=false&reason=cancelled' ); - exit; - } elseif ( $statusCode === 'Open' || $statusCode == 'Pending' ) { - // "De mandaat ondertekening is nog niet bevestigd. Dit kan even duren maar gebeurt automatisch." - wp_redirect( home_url( $bluem_config->thanksPageURL ) . '?result=false&reason=open' ); - exit; - } elseif ( $statusCode === 'Expired' ) { - // "Fout: De mandaat of het verzoek daartoe is verlopen"; - wp_redirect( home_url( $bluem_config->thanksPageURL ) . '?result=false&reason=expired' ); - exit; - } else { - // "Fout: Onbekende of foutieve status"; - bluem_error_report_email( - array( - 'service' => 'mandates', - 'function' => 'shortcode_callback', - 'message' => - sprintf( - /* translators: %s: error status */ - esc_html__( 'Fout: Onbekende of foutieve status teruggekregen: %s. Neem contact op met de webshop en vermeld deze status; gebruiker wel doorverwezen terug naar site', 'bluem' ), - $statusCode - ), - ) - ); - wp_redirect( home_url( $bluem_config->thanksPageURL ) . '?result=false&reason=error' ); - exit; - } +function bluem_mandate_shortcode_callback(): void +{ + global $current_user; + + $bluem_config = bluem_woocommerce_get_config(); + + $bluem_config->merchantReturnURLBase = home_url('wc-api/bluem_mandates_callback'); + + $storage = bluem_db_get_storage(); + + try { + $bluem = new Bluem($bluem_config); + } catch (Exception $e) { + // @todo: deal with incorrectly setup Bluem + // $e->getMessage(); + } + + // @todo: .. then use request-based approach soon as first check, then fallback to user meta check. + if (!empty($current_user->ID)) { + $mandateID = get_user_meta($current_user->ID, 'bluem_latest_mandate_id', true); + $entranceCode = get_user_meta($current_user->ID, 'bluem_latest_mandate_entrance_code', true); + } else { + $mandateID = $storage['bluem_mandate_transaction_id'] ?? 0; + $entranceCode = $storage['bluem_mandate_entrance_code'] ?? ''; + } + + if (!isset($_GET['mandateID'])) { + if ($bluem_config->thanksPageURL !== '') { + wp_redirect(home_url($bluem_config->thanksPageURL) . '?result=false&reason=error'); + // echo "

Er is een fout opgetreden. De incassomachtiging is geannuleerd.

"; + return; + } + $errormessage = esc_html__('Fout: geen juist mandaat id teruggekregen bij callback. Neem contact op met de webshop en vermeld je contactgegevens.', 'bluem'); + bluem_error_report_email( + array( + 'service' => 'mandates', + 'function' => 'shortcode_callback', + 'message' => $errormessage, + ) + ); + bluem_dialogs_render_prompt($errormessage); + exit; + } + + if (empty($entranceCode)) { + $errormessage = esc_html__('Fout: Entrancecode is niet set; kan dus geen mandaat opvragen', 'bluem'); + bluem_error_report_email( + array( + 'service' => 'mandates', + 'function' => 'shortcode_callback', + 'message' => $errormessage, + ) + ); + bluem_dialogs_render_prompt($errormessage); + exit; + } + + $response = $bluem->MandateStatus($mandateID, $entranceCode); + + if (!$response->Status()) { + $errormessage = + sprintf( + /* translators: %s: Error message */ + esc_html__('Fout bij opvragen status: %s. Neem contact op met de webshop en vermeld deze status', 'bluem'), + $response->Error() + ); + bluem_error_report_email( + array( + 'service' => 'mandates', + 'function' => 'shortcode_callback', + 'message' => $errormessage, + ) + ); + bluem_dialogs_render_prompt($errormessage); + exit; + } + + $statusUpdateObject = $response->EMandateStatusUpdate; + $statusCode = $statusUpdateObject->EMandateStatus->Status . ''; + + $request_from_db = bluem_db_get_request_by_transaction_id_and_type( + $mandateID, + 'mandates' + ); + + if ($statusCode !== $request_from_db->status) { + bluem_db_update_request( + $request_from_db->id, + array( + 'status' => $statusCode, + ) + ); + // also update locally for email notification + $request_from_db->status = $statusCode; + } + + bluem_transaction_notification_email( + $request_from_db->id + ); + + // Handling the response. + if ($statusCode === 'Success') { + // Define a cookie so that this will be recognised the next time + bluem_db_insert_storage( + array( + 'bluem_mandate_transaction_id' => $mandateID, + ) + ); + + if (!empty($current_user)) { + if (current_user_can('edit_user', $current_user->ID)) { + update_user_meta($current_user->ID, 'bluem_mandates_validated', true); + } + } + + if ($request_from_db->payload !== '') { + try { + $newPayload = json_decode($request_from_db->payload); + } catch (Throwable $th) { + $newPayload = new Stdclass(); + } + } else { + $newPayload = new Stdclass(); + } + + if (isset($response->EMandateStatusUpdate->EMandateStatus->AcceptanceReport)) { + $newPayload->purchaseID = $response->EMandateStatusUpdate->EMandateStatus->PurchaseID . ''; + $newPayload->report = $response->EMandateStatusUpdate->EMandateStatus->AcceptanceReport; + + bluem_db_update_request( + $request_from_db->id, + array( + 'payload' => wp_json_encode($newPayload), + ) + ); + } + wp_redirect(home_url($bluem_config->thanksPageURL) . '?result=true'); + exit; + } elseif ($statusCode === 'Cancelled') { + // "Je hebt de mandaat ondertekening geannuleerd"; + wp_redirect(home_url($bluem_config->thanksPageURL) . '?result=false&reason=cancelled'); + exit; + } elseif ($statusCode === 'Open' || $statusCode == 'Pending') { + // "De mandaat ondertekening is nog niet bevestigd. Dit kan even duren maar gebeurt automatisch." + wp_redirect(home_url($bluem_config->thanksPageURL) . '?result=false&reason=open'); + exit; + } elseif ($statusCode === 'Expired') { + // "Fout: De mandaat of het verzoek daartoe is verlopen"; + wp_redirect(home_url($bluem_config->thanksPageURL) . '?result=false&reason=expired'); + exit; + } else { + // "Fout: Onbekende of foutieve status"; + bluem_error_report_email( + array( + 'service' => 'mandates', + 'function' => 'shortcode_callback', + 'message' => + sprintf( + /* translators: %s: error status */ + esc_html__('Fout: Onbekende of foutieve status teruggekregen: %s. Neem contact op met de webshop en vermeld deze status; gebruiker wel doorverwezen terug naar site', 'bluem'), + $statusCode + ), + ) + ); + wp_redirect(home_url($bluem_config->thanksPageURL) . '?result=false&reason=error'); + exit; + } } -add_shortcode( 'bluem_machtigingsformulier', 'bluem_mandateform' ); +add_shortcode('bluem_machtigingsformulier', 'bluem_mandateform'); /** * Rendering the static form @@ -454,130 +445,132 @@ function bluem_mandate_mandate_shortcode_callback(): void { * * @return string */ -function bluem_mandateform(): string { - global $current_user; - - $bluem_config = bluem_woocommerce_get_config(); - - $storage = bluem_db_get_storage(); - - $bluem_config->merchantReturnURLBase = home_url( - 'wc-api/bluem_mandates_callback' - ); - - $user_allowed = apply_filters( - 'bluem_woocommerce_mandate_shortcode_allow_user', - true - ); - - if ( ! $user_allowed ) { - return ''; - } - - $mandateID = 0; - - $validated = false; - - /** - * Check if user is logged in. - */ - if ( is_user_logged_in() ) { - $mandateID = get_user_meta( $current_user->ID, 'bluem_latest_mandate_id', true ); - - $validated_db = get_user_meta( $current_user->ID, 'bluem_mandates_validated', true ); - - // While be zero (string) when disabled - if ( ! empty( $mandateID ) && $validated_db !== '0' ) { - // Check for recurring mode - if ( $bluem_config->sequenceType === 'RCUR' ) { - $db_query = array( - 'transaction_id' => $mandateID, - 'user_id' => get_current_user_id(), - 'status' => 'Success', - ); - - $db_results = bluem_db_get_requests_by_keyvalues( $db_query ); - - if ( $db_results !== false && is_array( $db_results ) && sizeof( $db_results ) > 0 ) { - $mandateID = $db_results[0]->transaction_id; - - $validated = true; - } - } - } - } else { - /** - * Visitor not logged in. Check other storages. - */ - if ( ! empty( $storage['bluem_mandate_transaction_id'] ) ) { - $mandateID = $storage['bluem_mandate_transaction_id']; - - // Check for recurring mode - if ( $bluem_config->sequenceType === 'RCUR' ) { - $db_query = array( - 'transaction_id' => $mandateID, - 'user_id' => get_current_user_id(), - 'status' => 'Success', - ); - - $db_results = bluem_db_get_requests_by_keyvalues( $db_query ); - - if ( $db_results !== false && is_array( $db_results ) && sizeof( $db_results ) > 0 ) { - $mandateID = $db_results[0]->transaction_id; - - $validated = true; - } - } - } elseif ( ! empty( $storage['bluem_mandate_debtorreference'] ) ) { - $debtorReference = $storage['bluem_mandate_debtorreference']; - - // Check for recurring mode - if ( $bluem_config->sequenceType === 'RCUR' ) { - $db_query = array( - 'debtor_reference' => $debtorReference, - 'user_id' => get_current_user_id(), - 'status' => 'Success', - ); - - $db_results = bluem_db_get_requests_by_keyvalues( $db_query ); - - if ( $db_results !== false && is_array( $db_results ) && sizeof( $db_results ) > 0 ) { - $mandateID = $db_results[0]->transaction_id; - - $validated = true; - } - } - } - } - - /** - * Check if eMandate is valid.. - */ - if ( $validated !== false ) { - return '

' . esc_html__( 'Bedankt voor je machtiging met machtiging ID:', 'bluem' ) . " " . esc_attr( $mandateID ) . '

'; - } else { - $nonce = wp_create_nonce( 'bluem-nonce' ); - $html = '
'; - $html .= '

' . esc_html__( 'Je moet nog een automatische incasso machtiging afgeven.', 'bluem' ) . '

'; - - if ( ! empty( $bluem_config->debtorReferenceFieldName ) ) { - $html .= '

' . $bluem_config->debtorReferenceFieldName . ' (' . esc_html__( 'verplicht', 'bluem' ) . ')
'; - $html .= '

'; - } else { - $html .= ''; - } - - $html .= '

'; - $html .= '
'; - - return $html; - } +function bluem_mandateform(): string +{ + global $current_user; + + $bluem_config = bluem_woocommerce_get_config(); + + $storage = bluem_db_get_storage(); + + $bluem_config->merchantReturnURLBase = home_url( + 'wc-api/bluem_mandates_callback' + ); + + $user_allowed = apply_filters( + 'bluem_woocommerce_mandate_shortcode_allow_user', + true + ); + + if (!$user_allowed) { + return ''; + } + + $mandateID = 0; + + $validated = false; + + /** + * Check if user is logged in. + */ + if (is_user_logged_in()) { + $mandateID = get_user_meta($current_user->ID, 'bluem_latest_mandate_id', true); + + $validated_db = get_user_meta($current_user->ID, 'bluem_mandates_validated', true); + + // While be zero (string) when disabled + if (!empty($mandateID) && $validated_db !== '0') { + // Check for recurring mode + if ($bluem_config->sequenceType === 'RCUR') { + $db_query = array( + 'transaction_id' => $mandateID, + 'user_id' => get_current_user_id(), + 'status' => 'Success', + ); + + $db_results = bluem_db_get_requests_by_keyvalues($db_query); + + if ($db_results !== false && is_array($db_results) && sizeof($db_results) > 0) { + $mandateID = $db_results[0]->transaction_id; + + $validated = true; + } + } + } + } else { + /** + * Visitor not logged in. Check other storages. + */ + if (!empty($storage['bluem_mandate_transaction_id'])) { + $mandateID = $storage['bluem_mandate_transaction_id']; + + // Check for recurring mode + if ($bluem_config->sequenceType === 'RCUR') { + $db_query = array( + 'transaction_id' => $mandateID, + 'user_id' => get_current_user_id(), + 'status' => 'Success', + ); + + $db_results = bluem_db_get_requests_by_keyvalues($db_query); + + if ($db_results !== false && is_array($db_results) && sizeof($db_results) > 0) { + $mandateID = $db_results[0]->transaction_id; + + $validated = true; + } + } + } elseif (!empty($storage['bluem_mandate_debtorreference'])) { + $debtorReference = $storage['bluem_mandate_debtorreference']; + + // Check for recurring mode + if ($bluem_config->sequenceType === 'RCUR') { + $db_query = array( + 'debtor_reference' => $debtorReference, + 'user_id' => get_current_user_id(), + 'status' => 'Success', + ); + + $db_results = bluem_db_get_requests_by_keyvalues($db_query); + + if ($db_results !== false && is_array($db_results) && sizeof($db_results) > 0) { + $mandateID = $db_results[0]->transaction_id; + + $validated = true; + } + } + } + } + + /** + * Check if eMandate is valid.. + */ + if ($validated !== false) { + return '

' . esc_html__('Bedankt voor je machtiging met machtiging ID:', 'bluem') . " " . esc_attr($mandateID) . '

'; + } else { + $nonce = wp_create_nonce('bluem-nonce'); + $html = '
'; + $html .= '

' . esc_html__('Je moet nog een automatische incasso machtiging afgeven.', 'bluem') . '

'; + + if (!empty($bluem_config->debtorReferenceFieldName)) { + $html .= '

' . $bluem_config->debtorReferenceFieldName . ' (' . esc_html__('verplicht', 'bluem') . ')
'; + $html .= '

'; + } else { + $html .= ''; + } + + $html .= '

'; + $html .= '
'; + + return $html; + } } -add_filter( 'bluem_woocommerce_mandate_shortcode_allow_user', 'bluem_woocommerce_mandate_shortcode_allow_user_function', 10, 1 ); +add_filter('bluem_woocommerce_mandate_shortcode_allow_user', 'bluem_woocommerce_mandate_shortcode_allow_user_function', 10, 1); -function bluem_woocommerce_mandate_shortcode_allow_user_function( $valid = true ) { - // do something with the response, use this in third-party extensions of this system - return $valid; +function bluem_woocommerce_mandate_shortcode_allow_user_function($valid = true) +{ + // do something with the response, use this in third-party extensions of this system + return $valid; } diff --git a/bluem-mandates.php b/bluem-mandates.php index 4d46237..bbd5046 100644 --- a/bluem-mandates.php +++ b/bluem-mandates.php @@ -4,8 +4,6 @@ exit; } -use Bluem\BluemPHP\Bluem; - /* * This action hook registers our PHP class as a WooCommerce payment gateway */ diff --git a/bluem-payments.php b/bluem-payments.php index 2b28ab2..e713f59 100644 --- a/bluem-payments.php +++ b/bluem-payments.php @@ -4,8 +4,6 @@ exit; } -use Bluem\BluemPHP\Bluem; - /* * This action hook registers our PHP class as a WooCommerce payment gateway */ diff --git a/bluem.php b/bluem.php index 648792d..738555c 100644 --- a/bluem.php +++ b/bluem.php @@ -2,13 +2,13 @@ /** * Plugin Name: Bluem ePayments, iDIN, eMandates services and integration for WooCommerce - * Version: 1.3.22 + * Version: 1.3.23 * Plugin URI: https://bluem.nl/en/ * Description: Bluem integration for WordPress and WooCommerce for Payments, eMandates, iDIN identity verification and more * Author: Bluem Payment Services * Author URI: https://bluem.nl * Requires at least: 5.0 - * Tested up to: 6.5 + * Tested up to: 6.6 * Requires PHP: 8.0 * * License: GPL v3 @@ -143,10 +143,96 @@ function bluem_is_permalinks_enabled(): bool function bluem_woocommerce_plugin_activate() { update_option('bluem_plugin_registration', false); + + // Rewrite rules: + add_rewrite_rule('^bluem-woocommerce/idin_execute/?$', 'index.php?bluem_idin_shortcode_execute=1', 'top'); + add_rewrite_rule('^bluem-woocommerce/idin_shortcode_callback/?$', 'index.php?bluem_idin_shortcode_callback=1', 'top'); + + add_rewrite_rule('^bluem-woocommerce/mandate_shortcode_execute/?$', 'index.php?bluem_mandate_shortcode_execute=1', 'top'); + add_rewrite_rule('^bluem-woocommerce/mandate_shortcode_callback/?$', 'index.php?bluem_mandate_shortcode_callback=1', 'top'); + + add_rewrite_rule('^bluem-woocommerce/mandate_instant_request/?$', 'index.php?bluem_mandates_instant_request=1', 'top'); + add_rewrite_rule('^bluem-woocommerce/mandates_instant_callback/?$', 'index.php?bluem_mandates_instant_callback=1', 'top'); + + add_rewrite_rule('^bluem-woocommerce/bluem_idin_webhook/?$', 'index.php?bluem_idin_webhook=1', 'top'); + + // Integrations + add_rewrite_rule('^bluem-woocommerce/bluem-integrations/wpcf7_mandate/?$', 'index.php?bluem_woocommerce_integration_wpcf7_ajax=1', 'top'); + add_rewrite_rule('^bluem-woocommerce/bluem-integrations/wpcf7_callback/?$', 'index.php?bluem_woocommerce_integration_wpcf7_callback=1', 'top'); + add_rewrite_rule('^bluem-woocommerce/bluem-integrations/gform_callback/?$', 'index.php?bluem_woocommerce_integration_gform_callback=1', 'top'); + + // Flush the rules after adding them + flush_rewrite_rules(); } register_activation_hook(__FILE__, 'bluem_woocommerce_plugin_activate'); +add_filter('query_vars', function ($vars) { + $bluem_vars = [ + 'bluem_idin_shortcode_execute', + 'bluem_mandate_shortcode_execute', + 'bluem_mandates_instant_request', + 'bluem_idin_shortcode_callback', + 'bluem_mandate_shortcode_callback', + 'bluem_mandates_instant_callback', + 'bluem_idin_webhook', + 'bluem_woocommerce_integration_wpcf7_ajax', + 'bluem_woocommerce_integration_wpcf7_callback', + 'bluem_woocommerce_integration_gform_callback', + ]; + + return array_merge($vars, $bluem_vars); +}); + + +add_action('template_redirect', function () { + // POST requests + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST') { + + if (get_query_var('bluem_idin_shortcode_execute') == 1) { + bluem_idin_shortcode_idin_execute(); + } elseif (get_query_var('bluem_mandate_shortcode_execute') == 1) { + bluem_mandate_shortcode_execute(); + } + return; + } + + // GET requests + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'GET') { + if (get_query_var('bluem_mandates_instant_request') == 1) { + bluem_mandates_instant_request(); + } elseif (get_query_var('bluem_mandates_instant_callback') == 1) { + bluem_mandates_instant_callback(); + } elseif (get_query_var('bluem_idin_shortcode_callback') == 1) { + bluem_idin_shortcode_callback(); + } elseif (get_query_var('bluem_mandate_shortcode_callback') == 1) { + bluem_mandate_shortcode_callback(); + } elseif (get_query_var('bluem_idin_webhook') == 1) { + bluem_idin_webhook(); + } + + if (get_query_var('bluem_woocommerce_integration_wpcf7_ajax') == 1) { + bluem_woocommerce_integration_wpcf7_ajax(); + } + if (get_query_var('bluem_woocommerce_integration_wpcf7_callback') == 1) { + bluem_woocommerce_integration_wpcf7_callback(); + } + if (get_query_var('bluem_woocommerce_integration_gform_callback') == 1) { + bluem_woocommerce_integration_gform_callback(); + } + } +}); + +// Plug-in deactivation +function bluem_woocommerce_plugin_deactivate() +{ + // Flush to remove custom rules added by us + flush_rewrite_rules(); +} + +register_deactivation_hook(__FILE__, 'bluem_woocommerce_plugin_deactivate'); + + // Update CSS within in Admin function bluem_add_admin_style() { @@ -1063,20 +1149,16 @@ function bluem_woocommerce_register_settings() // Only executed on admin pages and AJAX requests. add_action('admin_init', 'bluem_woocommerce_register_settings'); -function bluem_woocommerce_init() +function bluem_woocommerce_init(): void { - - /** - * Register error logging - */ bluem_register_error_logging(); /** - * Create session storage. + * Initialize session for public pages */ - bluem_db_insert_storage([ - 'bluem_storage_init' => true, - ]); + if (!is_admin()) { + bluem_db_initialize_session_storage(); + } } // Always executed while plug-in is activated @@ -1468,7 +1550,7 @@ function bluem_error_report_email($data = []): bool $subject = "[" . get_bloginfo('name') . "] "; $subject .= esc_html__("Notificatie Error in Bluem ", 'bluem'); - $message = printf( + $message = sprintf( /* translators: %1$s: admin name %2$s: admin email address @@ -1507,6 +1589,7 @@ function bluem_error_report_email($data = []): bool esc_html__("Sent error report mail to %s", 'bluem'), $to)); } + // or no mail sent return $mailing; @@ -2036,7 +2119,7 @@ function bluem_admin_import_execute($data): array * Render the admin Import / Export page * @return void */ -function bluem_admin_importexport(): void +function bluem_admin_importexport() { $import_data = null; $messages = []; @@ -2081,6 +2164,8 @@ function bluem_admin_importexport(): void $options_json = wp_json_encode($options); } + $form_nonce = wp_create_nonce('bluem_importexport_nonce'); + // @todo: improve this by creating a renderer function and passing the renderdata // @todo: then generalise this to other parts of the plugin include_once 'views/importexport.php'; @@ -2103,7 +2188,7 @@ function bluem_woocommerce_is_woocommerce_active(): bool } -function bluem_register_error_logging() +function bluem_register_error_logging(): void { $settings = get_option('bluem_woocommerce_options'); @@ -2120,8 +2205,5 @@ function bluem_register_error_logging() $bluem_options['bluem_plugin_version'] = $bluem['Version'] ?? '0'; update_option('bluem_woocommerce_options', $bluem_options); } - -// $logger = new SentryLogger(); -// $logger->initialize(); } } diff --git a/gateways/Bluem_Bank_Based_Payment_Gateway.php b/gateways/Bluem_Bank_Based_Payment_Gateway.php index d3766a7..84f2953 100644 --- a/gateways/Bluem_Bank_Based_Payment_Gateway.php +++ b/gateways/Bluem_Bank_Based_Payment_Gateway.php @@ -354,9 +354,6 @@ private function getOrder(string $transactionID) */ public function bluem_bank_payments_callback(): void { - - echo "Called bluem_bank_payments_callback"; - die(); if (!isset($_GET['entranceCode'])) { $errormessage = esc_html__("Fout: geen juiste entranceCode teruggekregen bij payment_callback. Neem contact op met de webshop en vermeld je contactgegevens.", 'bluem'); bluem_error_report_email( diff --git a/readme.txt b/readme.txt index c0edcd7..877ffc0 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: Bluem,Payments,iDIN,iDEAL,eMandates Requires at least: 5.0 Tested up to: 6.6 Requires PHP: 8.0 -Stable tag: 1.3.22 +Stable tag: 1.3.23 License: GPLv3 License URI: http://www.gnu.org/licenses/gpl-3.0.html diff --git a/views/activate.php b/views/activate.php index cf31978..bf23b49 100644 --- a/views/activate.php +++ b/views/activate.php @@ -11,8 +11,13 @@

-

-

+

+ + +

+

+ +

@@ -91,8 +96,22 @@ class="form-control" style="width: 425px;">

- - Kijk voor meer informatie op de Bluem website, bel +31(0)85-2220400 of e-mail naar info@bluem.nl.", 'bluem')); ?> + +
+
+ ' target='_blank'> + +
+ '> + +31(0)85-2220400
+ '>info@bluem.nl.

Neem voor meer informatie contact op met uw accountmanager.
Laat velden leeg om dit later op te geven.', 'bluem')); ?> @@ -159,7 +178,7 @@ class="form-control" required="required">

-

In geval van belangrijke updates brengen wij dit persoon op de hoogte.', 'bluem')); ?>

+

diff --git a/views/importexport.php b/views/importexport.php index e0abe47..01c1ed1 100644 --- a/views/importexport.php +++ b/views/importexport.php @@ -67,8 +67,12 @@
+ action=""> + + + + diff --git a/views/status.php b/views/status.php index 58e580f..6c82e83 100644 --- a/views/status.php +++ b/views/status.php @@ -39,7 +39,7 @@ function bluem_display_php_errors(): string && $log_contents = @file_get_contents($error_log_path)) { $content = '
' . esc_html($log_contents) . '
'; } else { - $content = esc_html__('Unable to access the PHP error log. Either the log does not exist, logging has been disabled, or the necessary read permissions are lacking.', 'bluem'); + $content = esc_html__('Geen toegang tot PHP-foutenlogboek. Of het log bestaat niet, loggen is uitgeschakeld of de benodigde leesrechten ontbreken.', 'bluem'); } return $content; } @@ -57,10 +57,10 @@ function bluem_display_wordpress_debug_log() if ($log_contents = @file_get_contents($error_log_path)) { $content = '
' . esc_html($log_contents) . '
'; } else { - $content = esc_html__('Unable to access the WordPress debug log. Either the log does not exist, logging has been disabled, or the necessary read permissions are lacking.', 'bluem'); + $content = esc_html__('Geen toegang tot het WordPress debug-logboek. Of het log bestaat niet, loggen is uitgeschakeld of de benodigde leesrechten ontbreken.', 'bluem'); } } else { - $content = esc_html__('Unable to access the WordPress debug log. Either the log does not exist, logging has been disabled, or the necessary read permissions are lacking.', 'bluem'); + $content = esc_html__('Geen toegang tot het WordPress debug-logboek. Of het log bestaat niet, loggen is uitgeschakeld of de benodigde leesrechten ontbreken.', 'bluem'); } return $content; } @@ -79,13 +79,13 @@ function bluem_display_woocommerce_logs(): string $content = ''; - if (is_array($woocommerce_logs)) { + if (is_array($woocommerce_logs) && count($woocommerce_logs) > 0) { foreach ($woocommerce_logs as $log) { - $content .= '

' . basename($log) . '

'; + $content .= '

' . esc_attr(basename($log)) . '

'; $content .= '
' . esc_html(file_get_contents($log)) . '
'; } } else { - $content = esc_html__('Unable to access the WooCommerce logs. Either the log does not exist, logging has been disabled, or the necessary read permissions are lacking.', 'bluem'); + $content = esc_html__('Geen toegang tot de WooCommerce logboeken. Of het log bestaat niet, loggen is uitgeschakeld of de benodigde leesrechten ontbreken.', 'bluem'); } return $content;