diff --git a/.svnignore b/.svnignore
index 35474a7..124dab8 100644
--- a/.svnignore
+++ b/.svnignore
@@ -9,3 +9,4 @@ svn-directory/
tests/
tools/
vendor/
+docker/
diff --git a/Makefile b/Makefile
index c9347f0..251a9e8 100644
--- a/Makefile
+++ b/Makefile
@@ -163,7 +163,16 @@ clean-up:
@#rm -rf $(BUILD_DIR)
copy-to-docker:
- make pre-deployment; cp -r build/* ../plugins/bluem/.
+ make pre-deployment;
+ @echo "$(BLUE)Preparing `docker/plugins/bluem` directory...$(NC)"
+ if [ -d "docker/plugins/bluem" ]; then \
+ if [ "docker/plugins/bluem" != "/" ]; then \
+ rm -rf "docker/plugins/bluem"/*; \
+ fi \
+ else \
+ mkdir -p "docker/plugins/bluem"; \
+ fi; \
+ cp -r build/* docker/plugins/bluem
run-phpcs:
diff --git a/bluem-db.php b/bluem-db.php
index bfbef2a..d555843 100644
--- a/bluem-db.php
+++ b/bluem-db.php
@@ -1,8 +1,8 @@
get_charset_collate();
+ if ( empty( $installed_ver ) || $installed_ver < $bluem_db_version ) {
+ $charset_collate = $wpdb->get_charset_collate();
- include_once ABSPATH . 'wp-admin/includes/upgrade.php';
+ include_once ABSPATH . 'wp-admin/includes/upgrade.php';
- // Define table names
- $table_name_storage = $wpdb->prefix . 'bluem_storage';
- $table_name_requests = $wpdb->prefix . 'bluem_requests';
- $table_name_links = $wpdb->prefix . 'bluem_requests_links';
- $table_name_logs = $wpdb->prefix . 'bluem_requests_log';
+ // Define table names
+ $table_name_storage = $wpdb->prefix . 'bluem_storage';
+ $table_name_requests = $wpdb->prefix . 'bluem_requests';
+ $table_name_links = $wpdb->prefix . 'bluem_requests_links';
+ $table_name_logs = $wpdb->prefix . 'bluem_requests_log';
- /**
- * Create tables.
- */
- $sql = "CREATE TABLE IF NOT EXISTS `$table_name_requests` (
+ /**
+ * Create tables.
+ */
+ $sql = "CREATE TABLE IF NOT EXISTS `$table_name_requests` (
id mediumint(9) NOT NULL AUTO_INCREMENT,
user_id mediumint(9) NOT NULL,
transaction_id varchar(64) NOT NULL,
@@ -45,9 +44,9 @@ function bluem_db_create_requests_table(): void
payload text NOT NULL,
PRIMARY KEY (id)
) $charset_collate;";
- dbDelta($sql);
+ dbDelta( $sql );
- $sql = "CREATE TABLE IF NOT EXISTS `$table_name_logs` (
+ $sql = "CREATE TABLE IF NOT EXISTS `$table_name_logs` (
id mediumint(9) NOT NULL AUTO_INCREMENT,
request_id mediumint(9) NOT NULL,
timestamp timestamp DEFAULT NOW() NOT NULL,
@@ -55,9 +54,9 @@ function bluem_db_create_requests_table(): void
user_id mediumint(9) NULL,
PRIMARY KEY (id)
) $charset_collate;";
- dbDelta($sql);
+ dbDelta( $sql );
- $sql = "CREATE TABLE IF NOT EXISTS `$table_name_links` (
+ $sql = "CREATE TABLE IF NOT EXISTS `$table_name_links` (
id mediumint(9) NOT NULL AUTO_INCREMENT,
request_id mediumint(9) NOT NULL,
item_id mediumint(9) NOT NULL,
@@ -65,9 +64,9 @@ function bluem_db_create_requests_table(): void
timestamp timestamp DEFAULT NOW() NOT NULL,
PRIMARY KEY (id)
) $charset_collate;";
- dbDelta($sql);
+ dbDelta( $sql );
- $sql = "CREATE TABLE IF NOT EXISTS `$table_name_storage` (
+ $sql = "CREATE TABLE IF NOT EXISTS `$table_name_storage` (
id mediumint(9) NOT NULL AUTO_INCREMENT,
token varchar(191) NOT NULL,
secret varchar(191) NOT NULL,
@@ -75,137 +74,133 @@ function bluem_db_create_requests_table(): void
timestamp timestamp DEFAULT NOW() NOT NULL,
PRIMARY KEY (id)
) $charset_collate;";
- dbDelta($sql);
-
- // Check for previous installed versions
- if (!empty($installed_ver)) {
- /**
- * Migrate old tables to new tables including wp-prefix.
- * Old tables in the release version <= 1.3.
- */
- if ($installed_ver <= '1.3') {
- $bluem_requests_table_exists = $wpdb->get_var("SHOW TABLES LIKE 'bluem_requests'") === 'bluem_requests';
- $bluem_requests_links_table_exists = $wpdb->get_var("SHOW TABLES LIKE 'bluem_requests_log'") === 'bluem_requests_log';
- $bluem_requests_log_table_exists = $wpdb->get_var("SHOW TABLES LIKE 'bluem_requests_links'") === 'bluem_requests_links';
-
- if ($bluem_requests_table_exists) {
- $sql = "INSERT INTO `$table_name_requests` SELECT * FROM bluem_requests;";
- dbDelta($sql);
- }
-
- if ($bluem_requests_log_table_exists) {
- $sql = "INSERT INTO `$table_name_logs` SELECT * FROM bluem_requests_log;";
- dbDelta($sql);
- }
-
- if ($bluem_requests_links_table_exists) {
- $sql = "INSERT INTO `$table_name_links` SELECT * FROM bluem_requests_links;";
- dbDelta($sql);
- }
- }
- }
-
- // @todo: Should be deprecated from a future version
-
- update_option(
- 'bluem_db_version',
- $bluem_db_version
- );
- }
+ dbDelta( $sql );
+
+ // Check for previous installed versions
+ if ( ! empty( $installed_ver ) ) {
+ /**
+ * Migrate old tables to new tables including wp-prefix.
+ * Old tables in the release version <= 1.3.
+ */
+ if ( $installed_ver <= '1.3' ) {
+ $bluem_requests_table_exists = $wpdb->get_var( "SHOW TABLES LIKE 'bluem_requests'" ) === 'bluem_requests';
+ $bluem_requests_links_table_exists = $wpdb->get_var( "SHOW TABLES LIKE 'bluem_requests_log'" ) === 'bluem_requests_log';
+ $bluem_requests_log_table_exists = $wpdb->get_var( "SHOW TABLES LIKE 'bluem_requests_links'" ) === 'bluem_requests_links';
+
+ if ( $bluem_requests_table_exists ) {
+ $sql = "INSERT INTO `$table_name_requests` SELECT * FROM bluem_requests;";
+ dbDelta( $sql );
+ }
+
+ if ( $bluem_requests_log_table_exists ) {
+ $sql = "INSERT INTO `$table_name_logs` SELECT * FROM bluem_requests_log;";
+ dbDelta( $sql );
+ }
+
+ if ( $bluem_requests_links_table_exists ) {
+ $sql = "INSERT INTO `$table_name_links` SELECT * FROM bluem_requests_links;";
+ dbDelta( $sql );
+ }
+ }
+ }
+
+ // @todo: Should be deprecated from a future version
+
+ update_option(
+ 'bluem_db_version',
+ $bluem_db_version
+ );
+ }
}
-function bluem_db_check(): void
-{
- global $bluem_db_version;
+function bluem_db_check(): void {
+ global $bluem_db_version;
- if ((float)get_site_option('bluem_db_version') !== $bluem_db_version) {
- bluem_db_create_requests_table();
- }
+ if ( (float) get_site_option( 'bluem_db_version' ) !== $bluem_db_version ) {
+ bluem_db_create_requests_table();
+ }
}
-add_action('plugins_loaded', 'bluem_db_check');
+add_action( 'plugins_loaded', 'bluem_db_check' );
// request specific functions
-function bluem_db_create_request($request_object): int
-{
- global $wpdb;
-
- // date_default_timezone_set('Europe/Amsterdam');
- // $wpdb->time_zone = 'Europe/Amsterdam';
-
- if (!bluem_db_validated_request($request_object)) {
- return -1;
- }
-
- $insert_result = $wpdb->insert(
- $wpdb->prefix . 'bluem_requests',
- $request_object
- );
-
- if ($insert_result) {
- $request_id = $wpdb->insert_id;
-
- $request_object = (object)$request_object;
-
- if (isset($request_object->order_id)
- && !is_null($request_object->order_id)
- && $request_object->order_id != ''
- ) {
- bluem_db_create_link(
- $request_id,
- $request_object->order_id,
- 'order'
- );
- }
- bluem_db_request_log(
- $request_id,
- esc_html__('Verzoek aangemaakt', 'bluem')
- );
-
- return $wpdb->insert_id;
- }
-
- return -1;
+function bluem_db_create_request( $request_object ): int {
+ global $wpdb;
+
+ // date_default_timezone_set('Europe/Amsterdam');
+ // $wpdb->time_zone = 'Europe/Amsterdam';
+
+ if ( ! bluem_db_validated_request( $request_object ) ) {
+ return -1;
+ }
+
+ $insert_result = $wpdb->insert(
+ $wpdb->prefix . 'bluem_requests',
+ $request_object
+ );
+
+ if ( $insert_result ) {
+ $request_id = $wpdb->insert_id;
+
+ $request_object = (object) $request_object;
+
+ if ( isset( $request_object->order_id )
+ && ! is_null( $request_object->order_id )
+ && $request_object->order_id != ''
+ ) {
+ bluem_db_create_link(
+ $request_id,
+ $request_object->order_id,
+ 'order'
+ );
+ }
+ bluem_db_request_log(
+ $request_id,
+ esc_html__( 'Verzoek aangemaakt', 'bluem' )
+ );
+
+ return $wpdb->insert_id;
+ }
+
+ return -1;
}
-function bluem_db_request_log($request_id, $description, $log_data = array())
-{
- global $wpdb, $current_user;
-
- // date_default_timezone_set('Europe/Amsterdam');
- // $wpdb->time_zone = 'Europe/Amsterdam';
-
- return $wpdb->insert(
- $wpdb->prefix . 'bluem_requests_log',
- array(
- 'request_id' => $request_id,
- 'description' => $description,
- 'timestamp' => gmdate(
- 'Y-m-d H:i:s',
- ),
- 'user_id' => $current_user->ID,
- )
- );
+function bluem_db_request_log( $request_id, $description, $log_data = array() ) {
+ global $wpdb, $current_user;
+
+ // date_default_timezone_set('Europe/Amsterdam');
+ // $wpdb->time_zone = 'Europe/Amsterdam';
+
+ return $wpdb->insert(
+ $wpdb->prefix . 'bluem_requests_log',
+ array(
+ 'request_id' => $request_id,
+ 'description' => $description,
+ 'timestamp' => gmdate(
+ 'Y-m-d H:i:s',
+ ),
+ 'user_id' => $current_user->ID,
+ )
+ );
}
-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;
- }
+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 32-character token
+ $token = bin2hex( random_bytes( 16 ) );
- // Generate a 64-character secret
- $secret = bin2hex(random_bytes(32));
+ // Generate a 64-character secret
+ $secret = bin2hex( random_bytes( 32 ) );
- $path = sanitize_text_field(wp_unslash($_SERVER['SERVER_NAME']));
+ $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);
+ setcookie( 'bluem_storage_token', $token, 0, '/', $path, false, true );
+ setcookie( 'bluem_storage_secret', $secret, 0, '/', $path, false, true );
- return [$token, $secret];
+ return array( $token, $secret );
}
/**
@@ -215,75 +210,73 @@ function bluem_db_initialize_session_storage(): array|false
* @return bool
* @throws Exception
*/
-function bluem_db_insert_storage($object)
-{
- global $wpdb;
-
- $table_name = $wpdb->prefix . 'bluem_storage';
-
- $token = !empty($_COOKIE['bluem_storage_token']) ? sanitize_text_field(wp_unslash($_COOKIE['bluem_storage_token'])) : '';
- $secret = !empty($_COOKIE['bluem_storage_secret']) ? sanitize_text_field(wp_unslash($_COOKIE['bluem_storage_secret'])) : '';
-
- if (!empty($token) && !empty($secret)) {
-
- $result = $wpdb->get_results($wpdb->prepare("SELECT id, data FROM $table_name WHERE token = %s AND secret = %s", $token, $secret));
-
- if ($result) {
- 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;
-
- $new_object = array();
-
- if ($decoded_data !== null) {
- // Loop through current data
- foreach ($decoded_data as $key => $value) {
- $new_object[$key] = $value;
- }
- }
-
- // Loop through new data
- foreach ($object as $key => $value) {
- $new_object[$key] = $value;
- }
-
- return bluem_db_update_storage(
- $record_id,
- array(
- 'data' => wp_json_encode($new_object),
- )
- );
- }
- }
-
-
- $db_result = $wpdb->insert(
- $wpdb->prefix . 'bluem_storage',
- array(
- 'token' => $token,
- 'secret' => $secret,
- 'data' => wp_json_encode($object),
- 'timestamp' => gmdate(
- 'Y-m-d H:i:s',
- ),
- )
- );
-
- $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, $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;
+function bluem_db_insert_storage( $object ) {
+ global $wpdb;
+
+ $table_name = $wpdb->prefix . 'bluem_storage';
+
+ $token = ! empty( $_COOKIE['bluem_storage_token'] ) ? sanitize_text_field( wp_unslash( $_COOKIE['bluem_storage_token'] ) ) : '';
+ $secret = ! empty( $_COOKIE['bluem_storage_secret'] ) ? sanitize_text_field( wp_unslash( $_COOKIE['bluem_storage_secret'] ) ) : '';
+
+ if ( ! empty( $token ) && ! empty( $secret ) ) {
+
+ $result = $wpdb->get_results( $wpdb->prepare( "SELECT id, data FROM $table_name WHERE token = %s AND secret = %s", $token, $secret ) );
+
+ if ( $result ) {
+ 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;
+
+ $new_object = array();
+
+ if ( $decoded_data !== null ) {
+ // Loop through current data
+ foreach ( $decoded_data as $key => $value ) {
+ $new_object[ $key ] = $value;
+ }
+ }
+
+ // Loop through new data
+ foreach ( $object as $key => $value ) {
+ $new_object[ $key ] = $value;
+ }
+
+ return bluem_db_update_storage(
+ $record_id,
+ array(
+ 'data' => wp_json_encode( $new_object ),
+ )
+ );
+ }
+ }
+
+ $db_result = $wpdb->insert(
+ $wpdb->prefix . 'bluem_storage',
+ array(
+ 'token' => $token,
+ 'secret' => $secret,
+ 'data' => wp_json_encode( $object ),
+ 'timestamp' => gmdate(
+ 'Y-m-d H:i:s',
+ ),
+ )
+ );
+
+ $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, $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;
}
/**
@@ -292,38 +285,37 @@ function bluem_db_insert_storage($object)
* @param $key
* @return false|mixed|void
*/
-function bluem_db_get_storage($key = null)
-{
- global $wpdb;
-
- $table_name = $wpdb->prefix . 'bluem_storage';
-
- $token = !empty($_COOKIE['bluem_storage_token']) ? sanitize_text_field(wp_unslash($_COOKIE['bluem_storage_token'])) : '';
-
- $secret = !empty($_COOKIE['bluem_storage_secret']) ? sanitize_text_field(wp_unslash($_COOKIE['bluem_storage_secret'])) : '';
-
- if (!empty($token) && !empty($secret)) {
- $result = $wpdb->get_var(
- $wpdb->prepare("SELECT data FROM $table_name WHERE token = %s AND secret = %s", $token, $secret)
- );
-
- if ($result) {
- 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 $decoded_data;
- }
- }
- }
- return false;
+function bluem_db_get_storage( $key = null ) {
+ global $wpdb;
+
+ $table_name = $wpdb->prefix . 'bluem_storage';
+
+ $token = ! empty( $_COOKIE['bluem_storage_token'] ) ? sanitize_text_field( wp_unslash( $_COOKIE['bluem_storage_token'] ) ) : '';
+
+ $secret = ! empty( $_COOKIE['bluem_storage_secret'] ) ? sanitize_text_field( wp_unslash( $_COOKIE['bluem_storage_secret'] ) ) : '';
+
+ if ( ! empty( $token ) && ! empty( $secret ) ) {
+ $result = $wpdb->get_var(
+ $wpdb->prepare( "SELECT data FROM $table_name WHERE token = %s AND secret = %s", $token, $secret )
+ );
+
+ if ( $result ) {
+ 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 $decoded_data;
+ }
+ }
+ }
+ return false;
}
/**
@@ -334,25 +326,24 @@ function bluem_db_get_storage($key = null)
*
* @return bool
*/
-function bluem_db_update_storage($id, $object): bool
-{
- global $wpdb;
+function bluem_db_update_storage( $id, $object ): bool {
+ global $wpdb;
- $table_name = $wpdb->prefix . 'bluem_storage';
+ $table_name = $wpdb->prefix . 'bluem_storage';
- $update_result = $wpdb->update(
- $table_name,
- $object,
- array(
- 'id' => $id,
- )
- );
+ $update_result = $wpdb->update(
+ $table_name,
+ $object,
+ array(
+ 'id' => $id,
+ )
+ );
- if ($update_result) {
- return true;
- }
+ if ( $update_result ) {
+ return true;
+ }
- return false;
+ return false;
}
/**
@@ -361,40 +352,39 @@ function bluem_db_update_storage($id, $object): bool
*
* @return bool
*/
-function bluem_db_update_request($request_id, $request_object): bool
-{
- global $wpdb;
-
- // date_default_timezone_set('Europe/Amsterdam');
- // $wpdb->time_zone = 'Europe/Amsterdam';
-
- if (!bluem_db_validated_request_well_formed($request_object)) {
- return false;
- }
- $update_result = $wpdb->update(
- $wpdb->prefix . 'bluem_requests',
- $request_object,
- array(
- 'id' => $request_id,
- )
- );
-
- if ($update_result) {
- bluem_db_request_log(
- $request_id,
- wp_kses_post(
- sprintf(
- /* translators: %s: data in JSON */
- esc_html__('Transactie bijgewerkt. Nieuwe data: %s', 'bluem'),
- esc_js(wp_json_encode($request_object))
- )
- )
- );
-
- return true;
- }
-
- return false;
+function bluem_db_update_request( $request_id, $request_object ): bool {
+ global $wpdb;
+
+ // date_default_timezone_set('Europe/Amsterdam');
+ // $wpdb->time_zone = 'Europe/Amsterdam';
+
+ if ( ! bluem_db_validated_request_well_formed( $request_object ) ) {
+ return false;
+ }
+ $update_result = $wpdb->update(
+ $wpdb->prefix . 'bluem_requests',
+ $request_object,
+ array(
+ 'id' => $request_id,
+ )
+ );
+
+ if ( $update_result ) {
+ bluem_db_request_log(
+ $request_id,
+ wp_kses_post(
+ sprintf(
+ /* translators: %s: data in JSON */
+ esc_html__( 'Transactie bijgewerkt. Nieuwe data: %s', 'bluem' ),
+ esc_js( wp_json_encode( $request_object ) )
+ )
+ )
+ );
+
+ return true;
+ }
+
+ return false;
}
/**
@@ -404,10 +394,9 @@ function bluem_db_update_request($request_id, $request_object): bool
*
* @return bool
*/
-function bluem_db_validated_request_well_formed($request): bool
-{
- // @todo: check all available fields on their format
- return true;
+function bluem_db_validated_request_well_formed( $request ): bool {
+ // @todo: check all available fields on their format
+ return true;
}
/**
@@ -417,28 +406,27 @@ function bluem_db_validated_request_well_formed($request): bool
*
* @return void
*/
-function bluem_db_validated_request($request): bool
-{
- // check if present
- // entrance_code
- // transaction_id
- // transaction_url
- // user_id
- // timestamp
- // description
- // type
-
- // optional fields
- // debtor_reference
- // order_id
- // payload
-
- // and well-formed
- if (!bluem_db_validated_request_well_formed($request)) {
- return false;
- }
-
- return true;
+function bluem_db_validated_request( $request ): bool {
+ // check if present
+ // entrance_code
+ // transaction_id
+ // transaction_url
+ // user_id
+ // timestamp
+ // description
+ // type
+
+ // optional fields
+ // debtor_reference
+ // order_id
+ // payload
+
+ // and well-formed
+ if ( ! bluem_db_validated_request_well_formed( $request ) ) {
+ return false;
+ }
+
+ return true;
}
/**
@@ -446,21 +434,20 @@ function bluem_db_validated_request($request): bool
*
* @return string[]
*/
-function bluem_db_get_request_fields()
-{
- return array(
- 'id',
- 'entrance_code',
- 'transaction_id',
- 'transaction_url',
- 'user_id',
- 'timestamp',
- 'description',
- 'type',
- 'debtor_reference',
- 'order_id',
- 'payload',
- );
+function bluem_db_get_request_fields() {
+ return array(
+ 'id',
+ 'entrance_code',
+ 'transaction_id',
+ 'transaction_url',
+ 'user_id',
+ 'timestamp',
+ 'description',
+ 'type',
+ 'debtor_reference',
+ 'order_id',
+ 'payload',
+ );
}
/**
@@ -470,306 +457,291 @@ function bluem_db_get_request_fields()
*
* @return bool|object
*/
-function bluem_db_get_request_by_id(string $request_id)
-{
- // @todo change to only accept int for $request_id
+function bluem_db_get_request_by_id( string $request_id ) {
+ // @todo change to only accept int for $request_id
- $res = bluem_db_get_requests_by_keyvalue(
- 'id',
- $request_id
- );
+ $res = bluem_db_get_requests_by_keyvalue(
+ 'id',
+ $request_id
+ );
- return $res[0] ?? false;
+ return $res[0] ?? false;
}
-function bluem_db_delete_request_by_id($request_id)
-{
- global $wpdb;
+function bluem_db_delete_request_by_id( $request_id ) {
+ global $wpdb;
- // date_default_timezone_set('Europe/Amsterdam');
- // $wpdb->time_zone = 'Europe/Amsterdam';
+ // date_default_timezone_set('Europe/Amsterdam');
+ // $wpdb->time_zone = 'Europe/Amsterdam';
- $wpdb->show_errors();
+ $wpdb->show_errors();
- $query = $wpdb->delete($wpdb->prefix . 'bluem_requests', array('id' => $request_id));
- $query2 = $wpdb->delete($wpdb->prefix . 'bluem_requests_log', array('request_id' => $request_id));
+ $query = $wpdb->delete( $wpdb->prefix . 'bluem_requests', array( 'id' => $request_id ) );
+ $query2 = $wpdb->delete( $wpdb->prefix . 'bluem_requests_log', array( 'request_id' => $request_id ) );
- return $query && $query2;
+ return $query && $query2;
}
-function bluem_db_get_request_by_debtor_reference($debtor_reference)
-{
- $res = bluem_db_get_requests_by_keyvalue(
- 'debtor_reference',
- $debtor_reference
- );
+function bluem_db_get_request_by_debtor_reference( $debtor_reference ) {
+ $res = bluem_db_get_requests_by_keyvalue(
+ 'debtor_reference',
+ $debtor_reference
+ );
- return $res !== false && count($res) > 0 ? $res[0] : false;
+ return $res !== false && count( $res ) > 0 ? $res[0] : false;
}
-function bluem_db_get_request_by_transaction_id($transaction_id)
-{
- $res = bluem_db_get_requests_by_keyvalue(
- 'transaction_id',
- $transaction_id
- );
+function bluem_db_get_request_by_transaction_id( $transaction_id ) {
+ $res = bluem_db_get_requests_by_keyvalue(
+ 'transaction_id',
+ $transaction_id
+ );
- return $res !== false && count($res) > 0 ? $res[0] : false;
+ return $res !== false && count( $res ) > 0 ? $res[0] : false;
}
-function bluem_db_get_request_by_transaction_id_and_type($transaction_id, $type)
-{
- $res = bluem_db_get_requests_by_keyvalues(
- array(
- 'transaction_id' => $transaction_id,
- 'type' => $type,
- )
- );
+function bluem_db_get_request_by_transaction_id_and_type( $transaction_id, $type ) {
+ $res = bluem_db_get_requests_by_keyvalues(
+ array(
+ 'transaction_id' => $transaction_id,
+ 'type' => $type,
+ )
+ );
- return $res !== false && count($res) > 0 ? $res[0] : false;
+ return $res !== false && count( $res ) > 0 ? $res[0] : false;
}
-function bluem_db_get_request_by_transaction_id_and_entrance_code($transaction_id, $entrance_code)
-{
- $res = bluem_db_get_requests_by_keyvalues(
- array(
- 'transaction_id' => $transaction_id,
- 'entrance_code' => $entrance_code,
- )
- );
+function bluem_db_get_request_by_transaction_id_and_entrance_code( $transaction_id, $entrance_code ) {
+ $res = bluem_db_get_requests_by_keyvalues(
+ array(
+ 'transaction_id' => $transaction_id,
+ 'entrance_code' => $entrance_code,
+ )
+ );
- return $res !== false && count($res) > 0 ? $res[0] : false;
+ return $res !== false && count( $res ) > 0 ? $res[0] : false;
}
function bluem_db_get_requests_by_keyvalue(
- $key,
- $value,
- $sort_key = null,
- $sort_dir = 'ASC',
- $limit = 0
-)
-{
- return bluem_db_get_requests_by_keyvalues(
- array($key => $value),
- $sort_key,
- $sort_dir,
- $limit
- );
+ $key,
+ $value,
+ $sort_key = null,
+ $sort_dir = 'ASC',
+ $limit = 0
+) {
+ return bluem_db_get_requests_by_keyvalues(
+ array( $key => $value ),
+ $sort_key,
+ $sort_dir,
+ $limit
+ );
}
function bluem_db_get_requests_by_keyvalues(
- $keyvalues = array(),
- $sort_key = null,
- $sort_dir = 'ASC',
- $limit = 0
-)
-{
- global $wpdb;
-
- $wpdb->show_errors(); // Show or display errors
-
- // Start building the query
- $query = 'SELECT * FROM `' . $wpdb->prefix . 'bluem_requests`';
- $where_clauses = array();
- $query_values = array();
-
- // Add conditions if key-value pairs are provided
- if (count($keyvalues) > 0) {
- foreach ($keyvalues as $key => $value) {
- if (!empty($key) && $value !== '') {
- $where_clauses[] = "`{$key}` = %s";
- $query_values[] = $value;
- }
- }
-
- if (!empty($where_clauses)) {
- $query .= ' WHERE ' . implode(' AND ', $where_clauses);
- }
- }
-
- // Add sorting if sort_key is provided
- if (!is_null($sort_key) && $sort_key !== '' && in_array(strtoupper($sort_dir), array('ASC', 'DESC'))) {
- $query .= " ORDER BY `{$sort_key}` " . strtoupper($sort_dir);
- }
-
- // Add limit if provided
- if (is_numeric($limit) && $limit > 0) {
- $query .= ' LIMIT %d';
- $query_values[] = $limit;
- }
-
- // Prepare the query with the provided values
- if (!empty($query_values)) {
- $query = $wpdb->prepare($query, ...$query_values);
- }
-
- try {
- return $wpdb->get_results($query);
- } catch (Throwable $th) {
- return false;
- }
+ $keyvalues = array(),
+ $sort_key = null,
+ $sort_dir = 'ASC',
+ $limit = 0
+) {
+ global $wpdb;
+
+ $wpdb->show_errors(); // Show or display errors
+
+ // Start building the query
+ $query = 'SELECT * FROM `' . $wpdb->prefix . 'bluem_requests`';
+ $where_clauses = array();
+ $query_values = array();
+
+ // Add conditions if key-value pairs are provided
+ if ( count( $keyvalues ) > 0 ) {
+ foreach ( $keyvalues as $key => $value ) {
+ if ( ! empty( $key ) && $value !== '' ) {
+ $where_clauses[] = "`{$key}` = %s";
+ $query_values[] = $value;
+ }
+ }
+
+ if ( ! empty( $where_clauses ) ) {
+ $query .= ' WHERE ' . implode( ' AND ', $where_clauses );
+ }
+ }
+
+ // Add sorting if sort_key is provided
+ if ( ! is_null( $sort_key ) && $sort_key !== '' && in_array( strtoupper( $sort_dir ), array( 'ASC', 'DESC' ) ) ) {
+ $query .= " ORDER BY `{$sort_key}` " . strtoupper( $sort_dir );
+ }
+
+ // Add limit if provided
+ if ( is_numeric( $limit ) && $limit > 0 ) {
+ $query .= ' LIMIT %d';
+ $query_values[] = $limit;
+ }
+
+ // Prepare the query with the provided values
+ if ( ! empty( $query_values ) ) {
+ $query = $wpdb->prepare( $query, ...$query_values );
+ }
+
+ try {
+ return $wpdb->get_results( $query );
+ } catch ( Throwable $th ) {
+ return false;
+ }
}
-function bluem_db_get_requests_by_user_id($user_id = null)
-{
- global $current_user;
+function bluem_db_get_requests_by_user_id( $user_id = null ) {
+ global $current_user;
- if (is_null($user_id)) {
- $user_id = $current_user->ID;
- }
+ if ( is_null( $user_id ) ) {
+ $user_id = $current_user->ID;
+ }
- $res = bluem_db_get_requests_by_keyvalue(
- 'user_id',
- $user_id
- );
+ $res = bluem_db_get_requests_by_keyvalue(
+ 'user_id',
+ $user_id
+ );
- return $res !== false && count($res) > 0 ? $res : array();
+ return $res !== false && count( $res ) > 0 ? $res : array();
}
-function bluem_db_get_requests_by_user_id_and_type($user_id = null, $type = '')
-{
- global $current_user;
+function bluem_db_get_requests_by_user_id_and_type( $user_id = null, $type = '' ) {
+ global $current_user;
- if (is_null($user_id)) {
- $user_id = $current_user->ID;
- }
+ if ( is_null( $user_id ) ) {
+ $user_id = $current_user->ID;
+ }
- // @todo Throw an error when type is not given, or default to wildcard
+ // @todo Throw an error when type is not given, or default to wildcard
- $res = bluem_db_get_requests_by_keyvalues(
- array(
- 'user_id' => $user_id,
- 'type' => $type,
- ),
- 'timestamp',
- 'DESC'
- );
+ $res = bluem_db_get_requests_by_keyvalues(
+ array(
+ 'user_id' => $user_id,
+ 'type' => $type,
+ ),
+ 'timestamp',
+ 'DESC'
+ );
- return $res !== false && count($res) > 0 ? $res : array();
+ return $res !== false && count( $res ) > 0 ? $res : array();
}
-function bluem_db_get_most_recent_request($user_id = null, $type = 'mandates')
-{
- global $current_user, $wpdb;
+function bluem_db_get_most_recent_request( $user_id = null, $type = 'mandates' ) {
+ global $current_user, $wpdb;
- // Use current user's ID if no user ID is provided
- if (is_null($user_id)) {
- $user_id = $current_user->ID;
- }
+ // Use current user's ID if no user ID is provided
+ if ( is_null( $user_id ) ) {
+ $user_id = $current_user->ID;
+ }
- // Validate the type against allowed values
- if (!in_array($type, array('mandates', 'payments', 'identity'))) {
- return false;
- }
+ // Validate the type against allowed values
+ if ( ! in_array( $type, array( 'mandates', 'payments', 'identity' ) ) ) {
+ return false;
+ }
- $wpdb->show_errors(); // Enable error display
+ $wpdb->show_errors(); // Enable error display
- try {
- $results = $wpdb->get_results($wpdb->prepare(
- 'SELECT *
+ try {
+ $results = $wpdb->get_results(
+ $wpdb->prepare(
+ 'SELECT *
FROM `' . $wpdb->prefix . 'bluem_requests`
WHERE `user_id` = %d
AND `type` = %s
ORDER BY `timestamp` DESC
LIMIT 1',
- $user_id,
- $type
- )
- );
-
- if (count($results) > 0) {
- return $results[0];
- }
-
- return false;
- } catch (Throwable $th) {
- return false;
- }
+ $user_id,
+ $type
+ )
+ );
+
+ if ( count( $results ) > 0 ) {
+ return $results[0];
+ }
+
+ return false;
+ } catch ( Throwable $th ) {
+ return false;
+ }
}
-function bluem_db_put_request_payload($request_id, $data)
-{
- $request = bluem_db_get_request_by_id($request_id);
-
- if ($request->payload !== '') {
- try {
- $newPayload = json_decode($request->payload);
- } catch (Throwable $th) {
- $newPayload = new Stdclass();
- }
- } else {
- $newPayload = new Stdclass();
- }
- foreach ($data as $k => $v) {
- $newPayload->$k = $v;
- }
-
- bluem_db_update_request(
- $request_id,
- array(
- 'payload' => wp_json_encode($newPayload),
- )
- );
+function bluem_db_put_request_payload( $request_id, $data ) {
+ $request = bluem_db_get_request_by_id( $request_id );
+
+ if ( $request->payload !== '' ) {
+ try {
+ $newPayload = json_decode( $request->payload );
+ } catch ( Throwable $th ) {
+ $newPayload = new Stdclass();
+ }
+ } else {
+ $newPayload = new Stdclass();
+ }
+ foreach ( $data as $k => $v ) {
+ $newPayload->$k = $v;
+ }
+
+ bluem_db_update_request(
+ $request_id,
+ array(
+ 'payload' => wp_json_encode( $newPayload ),
+ )
+ );
}
-function bluem_db_get_logs_for_request($id)
-{
- global $wpdb;
+function bluem_db_get_logs_for_request( $id ) {
+ global $wpdb;
- return $wpdb->get_results(
- $wpdb->prepare(
- 'SELECT * FROM `' . $wpdb->prefix . 'bluem_requests_log` WHERE `request_id` = %d ORDER BY `timestamp` DESC',
- $id
- )
- );
+ return $wpdb->get_results(
+ $wpdb->prepare(
+ 'SELECT * FROM `' . $wpdb->prefix . 'bluem_requests_log` WHERE `request_id` = %d ORDER BY `timestamp` DESC',
+ $id
+ )
+ );
}
-function bluem_db_get_links_for_order($id)
-{
- global $wpdb;
+function bluem_db_get_links_for_order( $id ) {
+ global $wpdb;
- return $wpdb->get_results(
- $wpdb->prepare(
- 'SELECT * FROM `' . $wpdb->prefix . "bluem_requests_links` WHERE `item_id` = %d AND `item_type` = 'order' ORDER BY `timestamp` DESC",
- $id
- )
- );
+ return $wpdb->get_results(
+ $wpdb->prepare(
+ 'SELECT * FROM `' . $wpdb->prefix . "bluem_requests_links` WHERE `item_id` = %d AND `item_type` = 'order' ORDER BY `timestamp` DESC",
+ $id
+ )
+ );
}
-function bluem_db_get_links_for_request($id)
-{
- global $wpdb;
+function bluem_db_get_links_for_request( $id ) {
+ global $wpdb;
- return $wpdb->get_results(
- $wpdb->prepare(
- 'SELECT * FROM `' . $wpdb->prefix . 'bluem_requests_links` WHERE `request_id` = %d ORDER BY `timestamp` DESC',
- $id
- )
- );
+ return $wpdb->get_results(
+ $wpdb->prepare(
+ 'SELECT * FROM `' . $wpdb->prefix . 'bluem_requests_links` WHERE `request_id` = %d ORDER BY `timestamp` DESC',
+ $id
+ )
+ );
}
-function bluem_db_create_link($request_id, $item_id, $item_type = 'order'): int
-{
- global $wpdb;
-
- $installed_ver = (float)get_option('bluem_db_version');
- if ($installed_ver <= 1.2) {
- return -1;
- }
-
- $insert_result = $wpdb->insert(
- $wpdb->prefix . 'bluem_requests_links',
- array(
- 'request_id' => $request_id,
- 'item_id' => $item_id,
- 'item_type' => $item_type,
- )
- );
-
- if ($insert_result) {
- return $wpdb->insert_id;
- }
-
- return -1;
+function bluem_db_create_link( $request_id, $item_id, $item_type = 'order' ): int {
+ global $wpdb;
+
+ $installed_ver = (float) get_option( 'bluem_db_version' );
+ if ( $installed_ver <= 1.2 ) {
+ return -1;
+ }
+
+ $insert_result = $wpdb->insert(
+ $wpdb->prefix . 'bluem_requests_links',
+ array(
+ 'request_id' => $request_id,
+ 'item_id' => $item_id,
+ 'item_type' => $item_type,
+ )
+ );
+
+ if ( $insert_result ) {
+ return $wpdb->insert_id;
+ }
+
+ return -1;
}
diff --git a/bluem-idin.php b/bluem-idin.php
index 3169953..cce971c 100644
--- a/bluem-idin.php
+++ b/bluem-idin.php
@@ -1,7 +1,7 @@
| Invulveld | Voorbeeld invulling |
|---|
- ' . esc_html__('Mogelijke invulvelden: ', 'bluem') .
- $idinDescriptionTable .
- '
' .
- esc_html__('Let op: maximaal 128 tekens. Toegestane karakters:', 'bluem') .
- '
-0-9a-zA-ZéëïôóöüúÉËÏÔÓÖÜÚ€ ()+,.@&=%"'/:;?$'
- .
- esc_html__(
- 'Geef het format waaraan de beschrijving van
+ ' . esc_html__( 'Mogelijke invulvelden: ', 'bluem' ) .
+ $idinDescriptionTable .
+ '
' .
+ esc_html__( 'Let op: maximaal 128 tekens. Toegestane karakters:', 'bluem' ) .
+ '
-0-9a-zA-ZéëïôóöüúÉËÏÔÓÖÜÚ€ ()+,.@&=%"'/:;?$'
+ .
+ esc_html__(
+ 'Geef het format waaraan de beschrijving van
een identificatie request moet voldoen, met automatisch ingevulde velden. Dit gegeven wordt ook weergegeven in de Bluem portal als de \'Inzake\' tekst.',
- 'bluem'
- ) .
- '
' . esc_html__('Voorbeeld huidige waarde', 'bluem') . ':
' .
- $idinDescriptionCurrentValue . '',
- 'default' =>
- /* translators: %s: username tag template */
- sprintf(esc_html__('Identificatie %s', 'bluem'), '{gebruikersnaam}'),
- ),
- 'idin_add_field_in_order_emails' => array(
- 'key' => 'idin_add_field_in_order_emails',
- 'title' => 'bluem_idin_add_field_in_order_emails',
- 'name' => esc_html__('Identificatie status in emails', 'bluem'),
- 'description' => esc_html__(
- 'Moet de status van identificatie worden weergegeven
+ 'bluem'
+ ) .
+ '
' . esc_html__( 'Voorbeeld huidige waarde', 'bluem' ) . ':
' .
+ $idinDescriptionCurrentValue . '',
+ 'default' =>
+ /* translators: %s: username tag template */
+ sprintf( esc_html__( 'Identificatie %s', 'bluem' ), '{gebruikersnaam}' ),
+ ),
+ 'idin_add_field_in_order_emails' => array(
+ 'key' => 'idin_add_field_in_order_emails',
+ 'title' => 'bluem_idin_add_field_in_order_emails',
+ 'name' => esc_html__( 'Identificatie status in emails', 'bluem' ),
+ 'description' => esc_html__(
+ 'Moet de status van identificatie worden weergegeven
in de order notificatie email naar de klant en naar jezelf?
Let op: dit werkt op het moment alleen voor ingelogde klanten',
- 'bluem'
- ),
- 'type' => 'bool',
- 'default' => '1',
- ),
- 'idin_add_address_in_order_emails' => array(
- 'key' => 'idin_add_address_in_order_emails',
- 'title' => 'bluem_idin_add_address_in_order_emails',
- 'name' => esc_html__('Identificatie adres in emails', 'bluem'),
- 'description' => esc_html__(
- 'Moet het adres van identificatie worden weergegeven
+ 'bluem'
+ ),
+ 'type' => 'bool',
+ 'default' => '1',
+ ),
+ 'idin_add_address_in_order_emails' => array(
+ 'key' => 'idin_add_address_in_order_emails',
+ 'title' => 'bluem_idin_add_address_in_order_emails',
+ 'name' => esc_html__( 'Identificatie adres in emails', 'bluem' ),
+ 'description' => esc_html__(
+ 'Moet het adres van identificatie worden weergegeven
in de order notificatie email naar de klant en naar jezelf?
Let op: dit werkt op het moment alleen voor ingelogde klanten',
- 'bluem'
- ),
- 'type' => 'bool',
- 'default' => '1',
- ),
- 'idin_add_name_in_order_emails' => array(
- 'key' => 'idin_add_name_in_order_emails',
- 'title' => 'bluem_idin_add_name_in_order_emails',
- 'name' => esc_html__('Identificatie naam in emails', 'bluem'),
- 'description' => esc_html__(
- 'Moet de naam van identificatie worden weergegeven
+ 'bluem'
+ ),
+ 'type' => 'bool',
+ 'default' => '1',
+ ),
+ 'idin_add_name_in_order_emails' => array(
+ 'key' => 'idin_add_name_in_order_emails',
+ 'title' => 'bluem_idin_add_name_in_order_emails',
+ 'name' => esc_html__( 'Identificatie naam in emails', 'bluem' ),
+ 'description' => esc_html__(
+ 'Moet de naam van identificatie worden weergegeven
in de order notificatie email naar de klant en naar jezelf?
Let op: dit werkt op het moment alleen voor ingelogde klanten',
- 'bluem'
- ),
- 'type' => 'bool',
- 'default' => '1',
- ),
- 'idin_add_birthdate_in_order_emails' => array(
- 'key' => 'idin_add_birthdate_in_order_emails',
- 'title' => 'bluem_idin_add_birthdate_in_order_emails',
- 'name' => esc_html__('Identificatie geboortedatum in emails', 'bluem'),
- 'description' => esc_html__(
- 'Moet de geboortedatum van identificatie worden weergegeven
+ 'bluem'
+ ),
+ 'type' => 'bool',
+ 'default' => '1',
+ ),
+ 'idin_add_birthdate_in_order_emails' => array(
+ 'key' => 'idin_add_birthdate_in_order_emails',
+ 'title' => 'bluem_idin_add_birthdate_in_order_emails',
+ 'name' => esc_html__( 'Identificatie geboortedatum in emails', 'bluem' ),
+ 'description' => esc_html__(
+ 'Moet de geboortedatum van identificatie worden weergegeven
in de order notificatie email naar de klant en naar jezelf?
Let op: dit werkt op het moment alleen voor ingelogde klanten',
- 'bluem'
- ),
- 'type' => 'bool',
- 'default' => '1',
- ),
- 'idin_identify_button_inner' => array(
- 'key' => 'idin_identify_button_inner',
- 'title' => 'bluem_idin_identify_button_inner',
- 'name' => esc_html__('Tekst op Identificeren knop', 'bluem'),
- 'description' => esc_html__('Wat moet er op de knop staan in kaders waar de identificatie wordt vereist.', 'bluem'),
- 'default' => esc_html__('Klik hier om je te identificeren', 'bluem'),
- ),
- 'idin_identity_dialog_no_verification_text' => array(
- 'key' => 'idin_identity_dialog_no_verification_text',
- 'title' => 'bluem_idin_identity_dialog_no_verification_text',
- 'name' => esc_html__('Tekst in kader Identificeren (onder checkout) als er nog GEEN geldige identificatie bekend is maar deze wel vereist is', 'bluem'),
- 'description' => esc_html__('Wat moet er op de knop staan in kaders waar de identificatie wordt vereist.', 'bluem'),
- 'default' => esc_html__('Uw leeftijd is niet bekend of niet toereikend. U kan dus niet deze bestelling afronden. Neem bij vragen contact op met de webshop support.', 'bluem'),
- ),
- 'idin_identity_topbar_no_verification_text' => array(
- 'key' => 'idin_identity_topbar_no_verification_text',
- 'title' => 'bluem_idin_identity_topbar_no_verification_text',
- 'name' => esc_html__('Tekst in Pop-up boven checkout als er nog GEEN geldige identificatie bekend is maar deze wel vereist is', 'bluem'),
- 'description' => esc_html__('Wat moet er op de knop staan in kaders waar de identificatie wordt vereist.', 'bluem'),
- 'default' => esc_html__('We hebben uw leeftijd (nog) niet kunnen opvragen. Voltooi eerst de identificatie procedure.', 'bluem'),
- ),
- 'idin_identity_topbar_invalid_verification_text' => array(
- 'key' => 'idin_identity_topbar_invalid_verification_text',
- 'title' => 'bluem_idin_identity_topbar_invalid_verification_text',
- 'name' => esc_html__('Tekst in Pop-up boven checkout als er een ongeldige identificatie terugkomt na opvragen hiervan', 'bluem'),
- 'description' => esc_html__('Wat moet er op de knop staan in kaders waar de identificatie wordt vereist.', 'bluem'),
- 'default' => esc_html__('Uw leeftijd is niet toereikend. U kan dus niet deze bestelling afronden.', 'bluem'),
- ),
- 'idin_identity_dialog_thank_you_message' => array(
- 'key' => 'idin_identity_dialog_thank_you_message',
- 'title' => 'bluem_idin_identity_dialog_thank_you_message',
- 'name' => esc_html__('Tekst in kader onder checkout zodra er een geldige identificatie procedure is voltooid', 'bluem'),
- 'description' => esc_html__('Wat moet er op de knop staan in kaders waar de identificatie wordt vereist.', 'bluem'),
- 'default' => esc_html__('Je leeftijd is geverifieerd, bedankt.', 'bluem'),
- ),
- 'idin_identity_popup_thank_you_message' => array(
- 'key' => 'idin_identity_popup_thank_you_message',
- 'title' => 'bluem_idin_identity_popup_thank_you_message',
- 'name' => esc_html__('Tekst in Pop-up boven checkout zodra er een geldige identificatie procedure is voltooid', 'bluem'),
- 'description' => esc_html__('Wat moet er op de knop staan in kaders waar de identificatie wordt vereist.', 'bluem'),
- 'default' => esc_html__('Je leeftijd is geverifieerd.', 'bluem'),
- ),
- 'idin_identity_more_information_popup' => array(
- 'key' => 'idin_identity_more_information_popup',
- 'title' => 'bluem_idin_identity_more_information_popup',
- 'name' => esc_html__('Uitleg kader over identificeren', 'bluem'),
- 'type' => 'textarea',
- 'description' => esc_html__('Schrijf hier een toelichting met eventuele doorklik links om klanten/gebruikers te vertellen over iDIN en het belang hiervan.', 'bluem'),
- 'default' => esc_html__(
- '**Identificeren is per 1 juli 2021 verplicht in winkels waar producten verkocht worden met een identiteitsplicht van de klant.**
+ 'bluem'
+ ),
+ 'type' => 'bool',
+ 'default' => '1',
+ ),
+ 'idin_identify_button_inner' => array(
+ 'key' => 'idin_identify_button_inner',
+ 'title' => 'bluem_idin_identify_button_inner',
+ 'name' => esc_html__( 'Tekst op Identificeren knop', 'bluem' ),
+ 'description' => esc_html__( 'Wat moet er op de knop staan in kaders waar de identificatie wordt vereist.', 'bluem' ),
+ 'default' => esc_html__( 'Klik hier om je te identificeren', 'bluem' ),
+ ),
+ 'idin_identity_dialog_no_verification_text' => array(
+ 'key' => 'idin_identity_dialog_no_verification_text',
+ 'title' => 'bluem_idin_identity_dialog_no_verification_text',
+ 'name' => esc_html__( 'Tekst in kader Identificeren (onder checkout) als er nog GEEN geldige identificatie bekend is maar deze wel vereist is', 'bluem' ),
+ 'description' => esc_html__( 'Wat moet er op de knop staan in kaders waar de identificatie wordt vereist.', 'bluem' ),
+ 'default' => esc_html__( 'Uw leeftijd is niet bekend of niet toereikend. U kan dus niet deze bestelling afronden. Neem bij vragen contact op met de webshop support.', 'bluem' ),
+ ),
+ 'idin_identity_topbar_no_verification_text' => array(
+ 'key' => 'idin_identity_topbar_no_verification_text',
+ 'title' => 'bluem_idin_identity_topbar_no_verification_text',
+ 'name' => esc_html__( 'Tekst in Pop-up boven checkout als er nog GEEN geldige identificatie bekend is maar deze wel vereist is', 'bluem' ),
+ 'description' => esc_html__( 'Wat moet er op de knop staan in kaders waar de identificatie wordt vereist.', 'bluem' ),
+ 'default' => esc_html__( 'We hebben uw leeftijd (nog) niet kunnen opvragen. Voltooi eerst de identificatie procedure.', 'bluem' ),
+ ),
+ 'idin_identity_topbar_invalid_verification_text' => array(
+ 'key' => 'idin_identity_topbar_invalid_verification_text',
+ 'title' => 'bluem_idin_identity_topbar_invalid_verification_text',
+ 'name' => esc_html__( 'Tekst in Pop-up boven checkout als er een ongeldige identificatie terugkomt na opvragen hiervan', 'bluem' ),
+ 'description' => esc_html__( 'Wat moet er op de knop staan in kaders waar de identificatie wordt vereist.', 'bluem' ),
+ 'default' => esc_html__( 'Uw leeftijd is niet toereikend. U kan dus niet deze bestelling afronden.', 'bluem' ),
+ ),
+ 'idin_identity_dialog_thank_you_message' => array(
+ 'key' => 'idin_identity_dialog_thank_you_message',
+ 'title' => 'bluem_idin_identity_dialog_thank_you_message',
+ 'name' => esc_html__( 'Tekst in kader onder checkout zodra er een geldige identificatie procedure is voltooid', 'bluem' ),
+ 'description' => esc_html__( 'Wat moet er op de knop staan in kaders waar de identificatie wordt vereist.', 'bluem' ),
+ 'default' => esc_html__( 'Je leeftijd is geverifieerd, bedankt.', 'bluem' ),
+ ),
+ 'idin_identity_popup_thank_you_message' => array(
+ 'key' => 'idin_identity_popup_thank_you_message',
+ 'title' => 'bluem_idin_identity_popup_thank_you_message',
+ 'name' => esc_html__( 'Tekst in Pop-up boven checkout zodra er een geldige identificatie procedure is voltooid', 'bluem' ),
+ 'description' => esc_html__( 'Wat moet er op de knop staan in kaders waar de identificatie wordt vereist.', 'bluem' ),
+ 'default' => esc_html__( 'Je leeftijd is geverifieerd.', 'bluem' ),
+ ),
+ 'idin_identity_more_information_popup' => array(
+ 'key' => 'idin_identity_more_information_popup',
+ 'title' => 'bluem_idin_identity_more_information_popup',
+ 'name' => esc_html__( 'Uitleg kader over identificeren', 'bluem' ),
+ 'type' => 'textarea',
+ 'description' => esc_html__( 'Schrijf hier een toelichting met eventuele doorklik links om klanten/gebruikers te vertellen over iDIN en het belang hiervan.', 'bluem' ),
+ 'default' => esc_html__(
+ '**Identificeren is per 1 juli 2021 verplicht in winkels waar producten verkocht worden met een identiteitsplicht van de klant.**
De methode die hier gebruikt wordt is veilig, snel en makkelijk - net zoals iDEAL. Het duurt hoogstens twee minuten en het resultaat wordt opgeslagen voor vervolgtransacties als je ingelogd bent als terugkerende klant.',
- 'bluem'
- ),
- ),
- 'idin_enable_ip_country_filtering' => array(
- 'key' => 'idin_enable_ip_country_filtering',
- 'title' => 'bluem_idin_enable_ip_country_filtering',
- 'name' => esc_html__('Identificatie filteren om alleen in Nederland plaats te vinden', 'bluem'),
- 'description' => esc_html__("Indien dit gegeven op ja staat, wordt er bij afrekenen gekeken naar de locatie van de gebruiker (gebaseerd op IP) en alleen gecheckt voor iDIN gegevens voor Nederlandse IP's.", 'bluem'),
- 'type' => 'bool',
- 'default' => '1',
- ),
- 'idin_show_notice_in_checkout' => array(
- 'key' => 'idin_show_notice_in_checkout',
- 'title' => 'bluem_idin_show_notice_in_checkout',
- 'name' => esc_html__('Wil je de identificatie melding bovenin de checkout weergeven?', 'bluem'),
- 'description' => esc_html__('Wil je de melding van identificatie nodig ook bovenaan de checkout als melding weergeven?', 'bluem'),
- 'type' => 'bool',
- 'default' => '1',
- ),
- );
+ 'bluem'
+ ),
+ ),
+ 'idin_enable_ip_country_filtering' => array(
+ 'key' => 'idin_enable_ip_country_filtering',
+ 'title' => 'bluem_idin_enable_ip_country_filtering',
+ 'name' => esc_html__( 'Identificatie filteren om alleen in Nederland plaats te vinden', 'bluem' ),
+ 'description' => esc_html__( "Indien dit gegeven op ja staat, wordt er bij afrekenen gekeken naar de locatie van de gebruiker (gebaseerd op IP) en alleen gecheckt voor iDIN gegevens voor Nederlandse IP's.", 'bluem' ),
+ 'type' => 'bool',
+ 'default' => '1',
+ ),
+ 'idin_show_notice_in_checkout' => array(
+ 'key' => 'idin_show_notice_in_checkout',
+ 'title' => 'bluem_idin_show_notice_in_checkout',
+ 'name' => esc_html__( 'Wil je de identificatie melding bovenin de checkout weergeven?', 'bluem' ),
+ 'description' => esc_html__( 'Wil je de melding van identificatie nodig ook bovenaan de checkout als melding weergeven?', 'bluem' ),
+ 'type' => 'bool',
+ 'default' => '1',
+ ),
+ );
}
-function bluem_woocommerce_idin_settings_section(): void
-{
- $options = function_exists('get_option') ? get_option('bluem_woocommerce_options') : array(); ?>
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
- = 1) {
- ?>
-
-
-
-
- ';
- }
- ?>
-
-
-
-
-
-
-
-
-
-
- [bluem_identificatieformulier].
-
-
-
-
-
-
+
+
+
+
+ = 1 ) {
+ ?>
+
+
+
+
+ ';
+ }
+ ?>
+
+
+
+
+
+
+
+
+
+
+ [bluem_identificatieformulier].
+
+
+
+
+
+
-
-
-
- ).
-
-
-
-
-
-
-
+
+
+
+ ).
+
+
+
+
+
+
+
-
-
-
- .
-
-
-
-
-
-
+
+
+
+ .
+
+
+
+
+
+ 'Voer geen identiteitscheck uit voor de checkout procedure', dus we overschrijven hier geen categoriëen
- * '1' => 'Check op de minimumleeftijd door een AgeCheckRequest'
- * '2' => 'Voer een volledige identiteitscontrole uit en sla dit op, maar blokkeer de checkout NIET, als minimumleeftijd niet bereikt is'
- * '3' => 'Voer een volledige identiteitscontrole uit, sla dit op EN blokkeer de checkout WEL, als minimumleeftijd niet bereikt is'
- */
- if ($scenario === 1) {
- if (method_exists($catListObject, 'Add')) {
- $catListObject->Add('AgeCheckRequest');
- } elseif (method_exists($catListObject, 'addCat')) {
- $catListObject->addCat('AgeCheckRequest');
- }
-
- if (method_exists($catListObject, 'getCategories')) {
- return $catListObject->getCategories();
- }
-
- if (method_exists($catListObject, 'getCats')) {
- return $catListObject->getCats();
- }
-
- return array();
- }
-
- if ($scenario === 2 || $scenario === 3) {
- if (method_exists($catListObject, 'Add')) {
- $catListObject->Add('CustomerIDRequest');
- } elseif (method_exists($catListObject, 'addCat')) {
- $catListObject->addCat('CustomerIDRequest');
- }
-
- if ($scenario === 3) {
- if (method_exists($catListObject, 'Add')) {
- $catListObject->Add('BirthDateRequest');
- } elseif (method_exists($catListObject, 'addCat')) {
- $catListObject->addCat('BirthDateRequest');
- }
- }
- }
-
- /**
- * Check which data to get.
- */
- if (isset($options['idin_request_name']) && $options['idin_request_name'] == '1') {
- if (method_exists($catListObject, 'Add')) {
- $catListObject->Add('NameRequest');
- } else {
- $catListObject->addCat('NameRequest');
- }
- }
- if (isset($options['idin_request_address']) && $options['idin_request_address'] == '1') {
- if (method_exists($catListObject, 'Add')) {
- $catListObject->Add('AddressRequest');
- } else {
- $catListObject->addCat('AddressRequest');
- }
- }
- if (isset($options['idin_request_birthdate']) && $options['idin_request_birthdate'] == '1') {
- if (method_exists($catListObject, 'Add')) {
- $catListObject->Add('BirthDateRequest');
- } else {
- $catListObject->addCat('BirthDateRequest');
- }
- }
- if (isset($options['idin_request_gender']) && $options['idin_request_gender'] == '1') {
- if (method_exists($catListObject, 'Add')) {
- $catListObject->Add('GenderRequest');
- } else {
- $catListObject->addCat('GenderRequest');
- }
- }
- if (isset($options['idin_request_telephone']) && $options['idin_request_telephone'] == '1') {
- if (method_exists($catListObject, 'Add')) {
- $catListObject->Add('TelephoneRequest');
- } else {
- $catListObject->addCat('TelephoneRequest');
- }
- }
- if (isset($options['idin_request_email']) && $options['idin_request_email'] == '1') {
- if (method_exists($catListObject, 'Add')) {
- $catListObject->Add('EmailRequest');
- } else {
- $catListObject->addCat('EmailRequest');
- }
- }
- return $catListObject->getCategories();
+function bluem_idin_get_categories( int $preset_scenario = null ) {
+ $catListObject = new BluemIdentityCategoryList();
+ $options = get_option( 'bluem_woocommerce_options' );
+
+ // if you want to infer the scenario from the settings and not override it.
+ if ( is_null( $preset_scenario ) ) {
+ if ( isset( $options['idin_scenario_active'] ) && $options['idin_scenario_active'] !== '' ) {
+ $scenario = (int) $options['idin_scenario_active'];
+ } else {
+ $scenario = 0;
+ }
+ } else {
+ $scenario = $preset_scenario;
+ }
+
+ /**
+ * Check the scenario
+ *
+ * '0' => 'Voer geen identiteitscheck uit voor de checkout procedure', dus we overschrijven hier geen categoriëen
+ * '1' => 'Check op de minimumleeftijd door een AgeCheckRequest'
+ * '2' => 'Voer een volledige identiteitscontrole uit en sla dit op, maar blokkeer de checkout NIET, als minimumleeftijd niet bereikt is'
+ * '3' => 'Voer een volledige identiteitscontrole uit, sla dit op EN blokkeer de checkout WEL, als minimumleeftijd niet bereikt is'
+ */
+ if ( $scenario === 1 ) {
+ if ( method_exists( $catListObject, 'Add' ) ) {
+ $catListObject->Add( 'AgeCheckRequest' );
+ } elseif ( method_exists( $catListObject, 'addCat' ) ) {
+ $catListObject->addCat( 'AgeCheckRequest' );
+ }
+
+ if ( method_exists( $catListObject, 'getCategories' ) ) {
+ return $catListObject->getCategories();
+ }
+
+ if ( method_exists( $catListObject, 'getCats' ) ) {
+ return $catListObject->getCats();
+ }
+
+ return array();
+ }
+
+ if ( $scenario === 2 || $scenario === 3 ) {
+ if ( method_exists( $catListObject, 'Add' ) ) {
+ $catListObject->Add( 'CustomerIDRequest' );
+ } elseif ( method_exists( $catListObject, 'addCat' ) ) {
+ $catListObject->addCat( 'CustomerIDRequest' );
+ }
+
+ if ( $scenario === 3 ) {
+ if ( method_exists( $catListObject, 'Add' ) ) {
+ $catListObject->Add( 'BirthDateRequest' );
+ } elseif ( method_exists( $catListObject, 'addCat' ) ) {
+ $catListObject->addCat( 'BirthDateRequest' );
+ }
+ }
+ }
+
+ /**
+ * Check which data to get.
+ */
+ if ( isset( $options['idin_request_name'] ) && $options['idin_request_name'] == '1' ) {
+ if ( method_exists( $catListObject, 'Add' ) ) {
+ $catListObject->Add( 'NameRequest' );
+ } else {
+ $catListObject->addCat( 'NameRequest' );
+ }
+ }
+ if ( isset( $options['idin_request_address'] ) && $options['idin_request_address'] == '1' ) {
+ if ( method_exists( $catListObject, 'Add' ) ) {
+ $catListObject->Add( 'AddressRequest' );
+ } else {
+ $catListObject->addCat( 'AddressRequest' );
+ }
+ }
+ if ( isset( $options['idin_request_birthdate'] ) && $options['idin_request_birthdate'] == '1' ) {
+ if ( method_exists( $catListObject, 'Add' ) ) {
+ $catListObject->Add( 'BirthDateRequest' );
+ } else {
+ $catListObject->addCat( 'BirthDateRequest' );
+ }
+ }
+ if ( isset( $options['idin_request_gender'] ) && $options['idin_request_gender'] == '1' ) {
+ if ( method_exists( $catListObject, 'Add' ) ) {
+ $catListObject->Add( 'GenderRequest' );
+ } else {
+ $catListObject->addCat( 'GenderRequest' );
+ }
+ }
+ if ( isset( $options['idin_request_telephone'] ) && $options['idin_request_telephone'] == '1' ) {
+ if ( method_exists( $catListObject, 'Add' ) ) {
+ $catListObject->Add( 'TelephoneRequest' );
+ } else {
+ $catListObject->addCat( 'TelephoneRequest' );
+ }
+ }
+ if ( isset( $options['idin_request_email'] ) && $options['idin_request_email'] == '1' ) {
+ if ( method_exists( $catListObject, 'Add' ) ) {
+ $catListObject->Add( 'EmailRequest' );
+ } else {
+ $catListObject->addCat( 'EmailRequest' );
+ }
+ }
+ return $catListObject->getCategories();
}
/* ********* RENDERING THE STATIC FORM *********** */
-add_shortcode('bluem_identificatieformulier', 'bluem_idin_form');
+add_shortcode( 'bluem_identificatieformulier', 'bluem_idin_form' );
/**
* Shortcode: `[bluem_identificatieformulier]`
*
* @return string
*/
-function bluem_idin_form(): string
-{
- $bluem_config = bluem_woocommerce_get_config();
-
- if (isset($bluem_config->IDINShortcodeOnlyAfterLogin)
- && $bluem_config->IDINShortcodeOnlyAfterLogin == '1'
- && !is_user_logged_in()
- ) {
- return '';
- }
-
- $html = '';
-
- $validated = false;
-
- $storage = bluem_db_get_storage();
-
- if (is_user_logged_in()) {
- $validated = get_user_meta(get_current_user_id(), 'bluem_idin_validated', true) == '1';
- } else {
- if (isset($storage['bluem_idin_validated']) && $storage['bluem_idin_validated'] === true) {
- $validated = true;
- }
- // @todo: handle $storage['bluem_idin_report_agecheckresponse'] if necessary
- }
-
- if ($validated) {
- if (isset($bluem_config->IDINSuccessMessage)) {
- $html .= '
' . $bluem_config->IDINSuccessMessage . '
';
- } else {
- $html .= sprintf('
%s
', esc_html__('Uw identificatieverzoek is ontvangen. Hartelijk dank.', 'bluem'));
- }
-
- // $html.= "Je hebt de identificatieprocedure eerder voltooid. Bedankt
";
- // $results = bluem_idin_retrieve_results();
- // $html.= "
";
- // foreach ($results as $k => $v) {
- // if (!is_object($v)) {
- // $html.= "$k: $v";
- // } else {
- // foreach ($v as $vk => $vv) {
- // $html.= "\t$vk: $vv";
- // $html.="
";
- // }
- // }
- // $html.="
";
- // }
- // // var_dump($results);
- // $html.= "";
- // return;
- return $html;
- }
-
- if (isset($_GET['result']) && sanitize_text_field(wp_unslash($_GET['result'])) === 'false') {
- $html .= '
';
-
- if (isset($bluem_config->IDINErrorMessage)) {
- $html .= '
' . $bluem_config->IDINErrorMessage . '
';
- } else {
- $html .= sprintf('
%s
', esc_html__('Er is een fout opgetreden. Uw verzoek is geannuleerd.', 'bluem'));
- }
-
- if (!empty($storage['bluem_idin_transaction_url'])) {
- $retryURL = $storage['bluem_idin_transaction_url'];
- $html .= sprintf(
- "
+function bluem_idin_form(): string {
+ $bluem_config = bluem_woocommerce_get_config();
+
+ if ( isset( $bluem_config->IDINShortcodeOnlyAfterLogin )
+ && $bluem_config->IDINShortcodeOnlyAfterLogin == '1'
+ && ! is_user_logged_in()
+ ) {
+ return '';
+ }
+
+ $html = '';
+
+ $validated = false;
+
+ $storage = bluem_db_get_storage();
+
+ if ( is_user_logged_in() ) {
+ $validated = get_user_meta( get_current_user_id(), 'bluem_idin_validated', true ) == '1';
+ } else {
+ if ( isset( $storage['bluem_idin_validated'] ) && $storage['bluem_idin_validated'] === true ) {
+ $validated = true;
+ }
+ // @todo: handle $storage['bluem_idin_report_agecheckresponse'] if necessary
+ }
+
+ if ( $validated ) {
+ if ( isset( $bluem_config->IDINSuccessMessage ) ) {
+ $html .= '' . $bluem_config->IDINSuccessMessage . '
';
+ } else {
+ $html .= sprintf( '%s
', esc_html__( 'Uw identificatieverzoek is ontvangen. Hartelijk dank.', 'bluem' ) );
+ }
+
+ // $html.= "Je hebt de identificatieprocedure eerder voltooid. Bedankt
";
+ // $results = bluem_idin_retrieve_results();
+ // $html.= "";
+ // foreach ($results as $k => $v) {
+ // if (!is_object($v)) {
+ // $html.= "$k: $v";
+ // } else {
+ // foreach ($v as $vk => $vv) {
+ // $html.= "\t$vk: $vv";
+ // $html.="
";
+ // }
+ // }
+ // $html.="
";
+ // }
+ // // var_dump($results);
+ // $html.= "";
+ // return;
+ return $html;
+ }
+
+ if ( isset( $_GET['result'] ) && sanitize_text_field( wp_unslash( $_GET['result'] ) ) === 'false' ) {
+ $html .= '';
+
+ if ( isset( $bluem_config->IDINErrorMessage ) ) {
+ $html .= '
' . $bluem_config->IDINErrorMessage . '
';
+ } else {
+ $html .= sprintf( '
%s
', esc_html__( 'Er is een fout opgetreden. Uw verzoek is geannuleerd.', 'bluem' ) );
+ }
+
+ if ( ! empty( $storage['bluem_idin_transaction_url'] ) ) {
+ $retryURL = $storage['bluem_idin_transaction_url'];
+ $html .= sprintf(
+ "
%s
",
- esc_html__('Probeer het opnieuw', 'bluem')
- );
- }
- $html .= '
';
- } else {
- $html .= esc_html__('Je hebt de identificatieprocedure nog niet voltooid.', 'bluem') . '
';
- $html .= '';
- }
- return $html;
+ esc_html__( 'Probeer het opnieuw', 'bluem' )
+ );
+ }
+ $html .= '
';
+ } else {
+ $html .= esc_html__( 'Je hebt de identificatieprocedure nog niet voltooid.', 'bluem' ) . '
';
+ $html .= '
';
+ }
+ return $html;
}
/**
@@ -900,357 +865,355 @@ function bluem_idin_form(): string
*
* @return void
*/
-function bluem_idin_shortcode_idin_execute(): void
-{
- $goto = false;
- if (!empty($_GET['redirect_to_checkout'])
- && sanitize_text_field(wp_unslash($_GET['redirect_to_checkout'])) === 'true'
- ) {
- // v1.2.6: added cart url instead of static cart as this is front-end language dependent
- // $goto = wc_get_cart_url();
- // v1.2.8: added checkout url instead of cart url :)
- $goto = wc_get_checkout_url();
- }
-
- bluem_idin_execute(null, true, $goto);
+function bluem_idin_shortcode_idin_execute(): void {
+ $goto = false;
+ if ( ! empty( $_GET['redirect_to_checkout'] )
+ && sanitize_text_field( wp_unslash( $_GET['redirect_to_checkout'] ) ) === 'true'
+ ) {
+ // v1.2.6: added cart url instead of static cart as this is front-end language dependent
+ // $goto = wc_get_cart_url();
+ // v1.2.8: added checkout url instead of cart url :)
+ $goto = wc_get_checkout_url();
+ }
+
+ bluem_idin_execute( null, true, $goto );
}
/**
* 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
-{
- $bluem_config = bluem_woocommerce_get_config();
-
- // fallback until this is corrected in bluem-php
- $bluem_config->brandID = $bluem_config->IDINBrandID ?? $bluem_config->brandID ?? '';
-
- try {
- $bluem = new Bluem($bluem_config);
- } catch (Exception $e) {
- return;
- // @todo: deal with incorrectly configured Bluem here
- }
-
- $request_by_debtor_ref = false;
-
- if (isset($_GET['debtorReference']) && $_GET['debtorReference'] !== '') {
- $debtorReference = sanitize_text_field(wp_unslash($_GET['debtorReference']));
- $request_by_debtor_ref = bluem_db_get_request_by_debtor_reference($debtorReference);
- }
-
- if (is_user_logged_in()) {
- $entranceCode = get_user_meta(get_current_user_id(), 'bluem_idin_entrance_code', true);
- $transactionID = get_user_meta(get_current_user_id(), 'bluem_idin_transaction_id', true);
- $transactionURL = get_user_meta(get_current_user_id(), 'bluem_idin_transaction_url', true);
- } else {
- $storage = bluem_db_get_storage();
-
- if (!empty($storage['bluem_idin_entrance_code'])) {
- $entranceCode = $storage['bluem_idin_entrance_code'];
- } elseif ($request_by_debtor_ref !== false
- && isset($request_by_debtor_ref->entrance_code)
- && $request_by_debtor_ref->entrance_code !== ''
- ) {
-
- $entranceCode = $request_by_debtor_ref->entrance_code;
- } else {
- $errormessage = esc_html__(
- 'Fout: bluem_idin_entrance_code van gebruiker of Bluem-sessieopslag ontbreekt -”.
+function bluem_idin_shortcode_callback(): void {
+ $bluem_config = bluem_woocommerce_get_config();
+
+ // fallback until this is corrected in bluem-php
+ $bluem_config->brandID = $bluem_config->IDINBrandID ?? $bluem_config->brandID ?? '';
+
+ try {
+ $bluem = new Bluem( $bluem_config );
+ } catch ( Exception $e ) {
+ return;
+ // @todo: deal with incorrectly configured Bluem here
+ }
+
+ $request_by_debtor_ref = false;
+
+ if ( isset( $_GET['debtorReference'] ) && $_GET['debtorReference'] !== '' ) {
+ $debtorReference = sanitize_text_field( wp_unslash( $_GET['debtorReference'] ) );
+ $request_by_debtor_ref = bluem_db_get_request_by_debtor_reference( $debtorReference );
+ }
+
+ if ( is_user_logged_in() ) {
+ $entranceCode = get_user_meta( get_current_user_id(), 'bluem_idin_entrance_code', true );
+ $transactionID = get_user_meta( get_current_user_id(), 'bluem_idin_transaction_id', true );
+ $transactionURL = get_user_meta( get_current_user_id(), 'bluem_idin_transaction_url', true );
+ } else {
+ $storage = bluem_db_get_storage();
+
+ if ( ! empty( $storage['bluem_idin_entrance_code'] ) ) {
+ $entranceCode = $storage['bluem_idin_entrance_code'];
+ } elseif ( $request_by_debtor_ref !== false
+ && isset( $request_by_debtor_ref->entrance_code )
+ && $request_by_debtor_ref->entrance_code !== ''
+ ) {
+
+ $entranceCode = $request_by_debtor_ref->entrance_code;
+ } else {
+ $errormessage = esc_html__(
+ 'Fout: bluem_idin_entrance_code van gebruiker of Bluem-sessieopslag ontbreekt -”.
deze is nodig voordat u een identificatie kunt voltooien.
Ga terug naar de winkel en probeer het opnieuw.',
- 'bluem'
- );
-
- bluem_error_report_email(
- array(
- 'service' => 'idin',
- 'function' => 'shortcode_callback',
- 'message' => $errormessage,
- )
- );
- bluem_dialogs_render_prompt($errormessage);
- exit;
- }
-
- if (!empty($storage['bluem_idin_transaction_id'])) {
- $transactionID = $storage['bluem_idin_transaction_id'];
- } elseif ($request_by_debtor_ref !== false
- && isset($request_by_debtor_ref->transaction_id)
- && $request_by_debtor_ref->transaction_id !== ''
- ) {
-
- $transactionID = $request_by_debtor_ref->transaction_id;
- } else {
- $errormessage = esc_html__('Fout: bluem_idin_transaction_id van gebruiker of Bluem-sessieopslag ontbreekt - dit is nodig voordat u een identificatie kunt voltooien. Ga terug naar de winkel en probeer het opnieuw.', 'bluem');
- bluem_error_report_email(
- array(
- 'service' => 'idin',
- 'function' => 'shortcode_callback',
- 'message' => $errormessage,
- )
- );
- bluem_dialogs_render_prompt($errormessage);
- exit;
- }
- }
-
- $statusResponse = null;
-
- try {
- $statusResponse = $bluem->IdentityStatus(
- $transactionID,
- $entranceCode
- );
- } catch (Exception $e) {
- // @todo: deal with Exception here
- }
-
- if (!$statusResponse || !$statusResponse->ReceivedResponse()) {
- $errormessage = sprintf(
- /* translators: %1$s: transaction ID %2$s: entranceCode */
- esc_html__('Error: kon verzoek met %1$s en entranceCode %2$s niet vinden', 'bluem'),
- $transactionID,
- $entranceCode
- );
- bluem_error_report_email(
- array(
- 'service' => 'idin',
- 'function' => 'shortcode_callback',
- 'message' => esc_html($errormessage),
- )
- );
- bluem_dialogs_render_prompt($errormessage);
- exit;
- }
-
- $statusCode = ($statusResponse->GetStatusCode());
-
- $request_from_db = bluem_db_get_request_by_transaction_id($transactionID);
-
- if ($request_from_db->status !== $statusCode) {
- bluem_db_update_request(
- $request_from_db->id,
- array(
- 'status' => $statusCode,
- )
- );
- }
-
- if (is_user_logged_in()) {
- update_user_meta(
- get_current_user_id(),
- 'bluem_idin_validated',
- false
- );
- } else {
- bluem_db_insert_storage(
- array(
- 'bluem_idin_validated' => false,
- )
- );
- }
-
- /**
- * Determining the right callback.
- */
- $goto = $bluem_config->IDINPageURL;
-
- if (str_contains(sanitize_url(wp_unslash($_SERVER['REQUEST_URI'])), 'bluem-woocommerce/idin_shortcode_callback/go_to_cart')) {
- $goto = wc_get_checkout_url();
- } elseif (!empty($goto)) {
- $goto = home_url($bluem_config->IDINPageURL);
- } else {
- $goto = home_url();
- }
-
- switch ($statusCode) {
- case 'Success': // in case of success...
- // ..retrieve a report that contains the information based on the request type:
- $identityReport = $statusResponse->GetIdentityReport();
-
- if (is_user_logged_in()) {
- update_user_meta(get_current_user_id(), 'bluem_idin_results', wp_json_encode($identityReport));
- update_user_meta(get_current_user_id(), 'bluem_idin_validated', true);
- } else {
- try {
- bluem_db_insert_storage(
- array(
- 'bluem_idin_validated' => true,
- 'bluem_idin_results' => wp_json_encode($identityReport),
- )
- );
- } catch (Exception $e) {
- // not inserted.
- }
- }
-
- // update an age check response field if that sccenario is active.
- $verification_scenario = bluem_idin_get_verification_scenario();
-
- if (isset($identityReport->AgeCheckResponse) && $verification_scenario === 1
- ) {
- $agecheckresponse = $identityReport->AgeCheckResponse . '';
- if (is_user_logged_in()) {
- update_user_meta(get_current_user_id(), 'bluem_idin_report_agecheckresponse', $agecheckresponse);
- } else {
- bluem_db_insert_storage(
- array(
- 'bluem_idin_report_agecheckresponse' => $agecheckresponse,
- )
- );
- }
- }
- if (isset($identityReport->CustomerIDResponse)) {
- $customeridresponse = $identityReport->CustomerIDResponse . '';
- if (is_user_logged_in()) {
- update_user_meta(get_current_user_id(), 'bluem_idin_report_customeridresponse', $customeridresponse);
- } else {
- bluem_db_insert_storage(
- array(
- 'bluem_idin_report_customeridresponse' => $customeridresponse,
- )
- );
- }
- }
- if (isset($identityReport->DateTime)) {
- $datetime = $identityReport->DateTime . '';
- if (is_user_logged_in()) {
- update_user_meta(get_current_user_id(), 'bluem_idin_report_last_verification_timestamp', $datetime);
- } else {
- bluem_db_insert_storage(
- array(
- 'bluem_idin_report_last_verification_timestamp' => $datetime,
- )
- );
- }
- }
-
- if (isset($identityReport->BirthdateResponse)) {
- $birthdate = $identityReport->BirthdateResponse . '';
- if (is_user_logged_in()) {
- update_user_meta(
- get_current_user_id(),
- 'bluem_idin_report_birthdate',
- $birthdate
- );
- } else {
- bluem_db_insert_storage(
- array(
- 'bluem_idin_report_birthdate' => $birthdate,
- )
- );
- }
- }
- if (isset($identityReport->TelephoneResponse)) {
- $telephone = $identityReport->TelephoneResponse . '';
- if (is_user_logged_in()) {
- update_user_meta(
- get_current_user_id(),
- 'bluem_idin_report_telephone',
- $telephone
- );
- }
- }
- if (isset($identityReport->EmailResponse)) {
- $email = $identityReport->EmailResponse . '';
- if (is_user_logged_in()) {
- update_user_meta(
- get_current_user_id(),
- 'bluem_idin_report_email',
- $email
- );
- }
- }
-
- $min_age = bluem_idin_get_min_age();
-
- if ($verification_scenario === 3
- && isset($identityReport->BirthDateResponse)
- ) {
- $user_age = bluem_idin_get_age_based_on_date(
- $identityReport->BirthDateResponse
- );
-
- if ($user_age >= $min_age) {
- if (is_user_logged_in()) {
- update_user_meta(
- get_current_user_id(),
- 'bluem_idin_report_agecheckresponse',
- 'true'
- );
- } else {
- bluem_db_insert_storage(
- array(
- 'bluem_idin_report_agecheckresponse' => true,
- )
- );
- }
- }
- }
-
- if (isset($request_from_db) && $request_from_db !== false) {
- if ($request_from_db->payload !== '') {
- try {
- $oldPayload = json_decode($request_from_db->payload);
- } catch (Throwable $th) {
- $oldPayload = new Stdclass();
- }
- } else {
- $oldPayload = new Stdclass();
- }
- $oldPayload->report = $identityReport;
-
- bluem_db_update_request(
- $request_from_db->id,
- array(
- 'status' => $statusCode,
- 'payload' => wp_json_encode($oldPayload),
- )
- );
- }
-
- bluem_transaction_notification_email(
- $request_from_db->id
- );
-
- wp_safe_redirect($goto);
- exit;
- case 'Processing':
- case 'Pending':
- // @todo: improve this flow
- // no break
-
- // @todo: improve this flow
- // do something when the request is still processing (for example tell the user to come back later to this page)
- break;
- case 'Cancelled':
- // @todo: improve this flow
- // do something when the request has been canceled by the user
- break;
- case 'Open':
- // @todo: improve this flow
- // do something when the request has not yet been completed by the user, redirecting to the transactionURL again
- break;
- case 'Expired':
- // @todo: improve this flow
- // do something when the request has expired
- break;
- case 'New':
- // @todo: improve this flow
- // do something when the request is still new
- break;
- default:
- // unexpected status returned, show an error
- break;
- }
-
- bluem_transaction_notification_email(
- $request_from_db->id
- );
-
- wp_safe_redirect(location: sprintf('%s?result=false&status=%s', $goto, $statusCode));
- exit;
+ 'bluem'
+ );
+
+ bluem_error_report_email(
+ array(
+ 'service' => 'idin',
+ 'function' => 'shortcode_callback',
+ 'message' => $errormessage,
+ )
+ );
+ bluem_dialogs_render_prompt( $errormessage );
+ exit;
+ }
+
+ if ( ! empty( $storage['bluem_idin_transaction_id'] ) ) {
+ $transactionID = $storage['bluem_idin_transaction_id'];
+ } elseif ( $request_by_debtor_ref !== false
+ && isset( $request_by_debtor_ref->transaction_id )
+ && $request_by_debtor_ref->transaction_id !== ''
+ ) {
+
+ $transactionID = $request_by_debtor_ref->transaction_id;
+ } else {
+ $errormessage = esc_html__( 'Fout: bluem_idin_transaction_id van gebruiker of Bluem-sessieopslag ontbreekt - dit is nodig voordat u een identificatie kunt voltooien. Ga terug naar de winkel en probeer het opnieuw.', 'bluem' );
+ bluem_error_report_email(
+ array(
+ 'service' => 'idin',
+ 'function' => 'shortcode_callback',
+ 'message' => $errormessage,
+ )
+ );
+ bluem_dialogs_render_prompt( $errormessage );
+ exit;
+ }
+ }
+
+ $statusResponse = null;
+
+ try {
+ $statusResponse = $bluem->IdentityStatus(
+ $transactionID,
+ $entranceCode
+ );
+ } catch ( Exception $e ) {
+ // @todo: deal with Exception here
+ }
+
+ if ( ! $statusResponse || ! $statusResponse->ReceivedResponse() ) {
+ $errormessage = sprintf(
+ /* translators: %1$s: transaction ID %2$s: entranceCode */
+ esc_html__( 'Error: kon verzoek met %1$s en entranceCode %2$s niet vinden', 'bluem' ),
+ $transactionID,
+ $entranceCode
+ );
+ bluem_error_report_email(
+ array(
+ 'service' => 'idin',
+ 'function' => 'shortcode_callback',
+ 'message' => esc_html( $errormessage ),
+ )
+ );
+ bluem_dialogs_render_prompt( $errormessage );
+ exit;
+ }
+
+ $statusCode = ( $statusResponse->GetStatusCode() );
+
+ $request_from_db = bluem_db_get_request_by_transaction_id( $transactionID );
+
+ if ( $request_from_db->status !== $statusCode ) {
+ bluem_db_update_request(
+ $request_from_db->id,
+ array(
+ 'status' => $statusCode,
+ )
+ );
+ }
+
+ if ( is_user_logged_in() ) {
+ update_user_meta(
+ get_current_user_id(),
+ 'bluem_idin_validated',
+ false
+ );
+ } else {
+ bluem_db_insert_storage(
+ array(
+ 'bluem_idin_validated' => false,
+ )
+ );
+ }
+
+ /**
+ * Determining the right callback.
+ */
+ $goto = $bluem_config->IDINPageURL;
+
+ if ( str_contains( sanitize_url( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 'bluem-woocommerce/idin_shortcode_callback/go_to_cart' ) ) {
+ $goto = wc_get_checkout_url();
+ } elseif ( ! empty( $goto ) ) {
+ $goto = home_url( $bluem_config->IDINPageURL );
+ } else {
+ $goto = home_url();
+ }
+
+ switch ( $statusCode ) {
+ case 'Success': // in case of success...
+ // ..retrieve a report that contains the information based on the request type:
+ $identityReport = $statusResponse->GetIdentityReport();
+
+ if ( is_user_logged_in() ) {
+ update_user_meta( get_current_user_id(), 'bluem_idin_results', wp_json_encode( $identityReport ) );
+ update_user_meta( get_current_user_id(), 'bluem_idin_validated', true );
+ } else {
+ try {
+ bluem_db_insert_storage(
+ array(
+ 'bluem_idin_validated' => true,
+ 'bluem_idin_results' => wp_json_encode( $identityReport ),
+ )
+ );
+ } catch ( Exception $e ) {
+ // not inserted.
+ }
+ }
+
+ // update an age check response field if that sccenario is active.
+ $verification_scenario = bluem_idin_get_verification_scenario();
+
+ if ( isset( $identityReport->AgeCheckResponse ) && $verification_scenario === 1
+ ) {
+ $agecheckresponse = $identityReport->AgeCheckResponse . '';
+ if ( is_user_logged_in() ) {
+ update_user_meta( get_current_user_id(), 'bluem_idin_report_agecheckresponse', $agecheckresponse );
+ } else {
+ bluem_db_insert_storage(
+ array(
+ 'bluem_idin_report_agecheckresponse' => $agecheckresponse,
+ )
+ );
+ }
+ }
+ if ( isset( $identityReport->CustomerIDResponse ) ) {
+ $customeridresponse = $identityReport->CustomerIDResponse . '';
+ if ( is_user_logged_in() ) {
+ update_user_meta( get_current_user_id(), 'bluem_idin_report_customeridresponse', $customeridresponse );
+ } else {
+ bluem_db_insert_storage(
+ array(
+ 'bluem_idin_report_customeridresponse' => $customeridresponse,
+ )
+ );
+ }
+ }
+ if ( isset( $identityReport->DateTime ) ) {
+ $datetime = $identityReport->DateTime . '';
+ if ( is_user_logged_in() ) {
+ update_user_meta( get_current_user_id(), 'bluem_idin_report_last_verification_timestamp', $datetime );
+ } else {
+ bluem_db_insert_storage(
+ array(
+ 'bluem_idin_report_last_verification_timestamp' => $datetime,
+ )
+ );
+ }
+ }
+
+ if ( isset( $identityReport->BirthdateResponse ) ) {
+ $birthdate = $identityReport->BirthdateResponse . '';
+ if ( is_user_logged_in() ) {
+ update_user_meta(
+ get_current_user_id(),
+ 'bluem_idin_report_birthdate',
+ $birthdate
+ );
+ } else {
+ bluem_db_insert_storage(
+ array(
+ 'bluem_idin_report_birthdate' => $birthdate,
+ )
+ );
+ }
+ }
+ if ( isset( $identityReport->TelephoneResponse ) ) {
+ $telephone = $identityReport->TelephoneResponse . '';
+ if ( is_user_logged_in() ) {
+ update_user_meta(
+ get_current_user_id(),
+ 'bluem_idin_report_telephone',
+ $telephone
+ );
+ }
+ }
+ if ( isset( $identityReport->EmailResponse ) ) {
+ $email = $identityReport->EmailResponse . '';
+ if ( is_user_logged_in() ) {
+ update_user_meta(
+ get_current_user_id(),
+ 'bluem_idin_report_email',
+ $email
+ );
+ }
+ }
+
+ $min_age = bluem_idin_get_min_age();
+
+ if ( $verification_scenario === 3
+ && isset( $identityReport->BirthDateResponse )
+ ) {
+ $user_age = bluem_idin_get_age_based_on_date(
+ $identityReport->BirthDateResponse
+ );
+
+ if ( $user_age >= $min_age ) {
+ if ( is_user_logged_in() ) {
+ update_user_meta(
+ get_current_user_id(),
+ 'bluem_idin_report_agecheckresponse',
+ 'true'
+ );
+ } else {
+ bluem_db_insert_storage(
+ array(
+ 'bluem_idin_report_agecheckresponse' => true,
+ )
+ );
+ }
+ }
+ }
+
+ if ( isset( $request_from_db ) && $request_from_db !== false ) {
+ if ( $request_from_db->payload !== '' ) {
+ try {
+ $oldPayload = json_decode( $request_from_db->payload );
+ } catch ( Throwable $th ) {
+ $oldPayload = new Stdclass();
+ }
+ } else {
+ $oldPayload = new Stdclass();
+ }
+ $oldPayload->report = $identityReport;
+
+ bluem_db_update_request(
+ $request_from_db->id,
+ array(
+ 'status' => $statusCode,
+ 'payload' => wp_json_encode( $oldPayload ),
+ )
+ );
+ }
+
+ bluem_transaction_notification_email(
+ $request_from_db->id
+ );
+
+ wp_safe_redirect( $goto );
+ exit;
+ case 'Processing':
+ case 'Pending':
+ // @todo: improve this flow
+ // no break
+
+ // @todo: improve this flow
+ // do something when the request is still processing (for example tell the user to come back later to this page)
+ break;
+ case 'Cancelled':
+ // @todo: improve this flow
+ // do something when the request has been canceled by the user
+ break;
+ case 'Open':
+ // @todo: improve this flow
+ // do something when the request has not yet been completed by the user, redirecting to the transactionURL again
+ break;
+ case 'Expired':
+ // @todo: improve this flow
+ // do something when the request has expired
+ break;
+ case 'New':
+ // @todo: improve this flow
+ // do something when the request is still new
+ break;
+ default:
+ // unexpected status returned, show an error
+ break;
+ }
+
+ bluem_transaction_notification_email(
+ $request_from_db->id
+ );
+
+ wp_safe_redirect( location: sprintf( '%s?result=false&status=%s', $goto, $statusCode ) );
+ exit;
}
/**
@@ -1258,586 +1221,577 @@ function bluem_idin_shortcode_callback(): void
*
* @return void
*/
-function bluem_idin_webhook(): void
-{
- http_response_code(200);
- exit;
+function bluem_idin_webhook(): void {
+ http_response_code( 200 );
+ exit;
}
-add_action('show_user_profile', 'bluem_woocommerce_idin_show_extra_profile_fields', 2);
-add_action('edit_user_profile', 'bluem_woocommerce_idin_show_extra_profile_fields');
-
-function bluem_woocommerce_idin_show_extra_profile_fields($user): void
-{
- $bluem_requests = bluem_db_get_requests_by_user_id_and_type($user->ID . '', 'identity');
- ?>
-
-
+ brandID = $bluem_config->IDINBrandID ?? $bluem_config->brandID ?? '';
-
- if (empty($bluem_config->brandID)) {
- return false;
- }
-
- try {
- $bluem = new Bluem($bluem_config);
- } catch (Exception $e) {
- // @todo: deal with non-configured bluem brandID, or assert that is has been configured on a higher level
- return false;
- }
-
- // Check if IP filtering is enabled
- if ($idin_enable_ip_country_filtering) {
- // override international IP's - don't validate idin when not NL
- if (!$bluem->VerifyIPIsNetherlands()) {
- return false;
- }
- }
-
- /**
- * Check if age verification is needed.
- */
- if (isset($options['idin_woocommerce_age_verification']) && $options['idin_woocommerce_age_verification'] === '1') {
- if (bluem_is_woocommerce_activated() && !$age_verification_needed) {
- return false;
- }
- }
-
- return true;
+function bluem_idin_validation_needed(): bool {
+ global $current_user;
+
+ $age_verification_needed = bluem_checkout_age_verification_needed();
+
+ $options = get_option( 'bluem_woocommerce_options' );
+
+ if ( isset( $options['idin_enable_ip_country_filtering'] )
+ && $options['idin_enable_ip_country_filtering'] !== ''
+ ) {
+ $idin_enable_ip_country_filtering = $options['idin_enable_ip_country_filtering'];
+ } else {
+ $idin_enable_ip_country_filtering = true;
+ }
+
+ $bluem_config = bluem_woocommerce_get_config();
+
+ $bluem_config->brandID = $bluem_config->IDINBrandID ?? $bluem_config->brandID ?? '';
+
+ if ( empty( $bluem_config->brandID ) ) {
+ return false;
+ }
+
+ try {
+ $bluem = new Bluem( $bluem_config );
+ } catch ( Exception $e ) {
+ // @todo: deal with non-configured bluem brandID, or assert that is has been configured on a higher level
+ return false;
+ }
+
+ // Check if IP filtering is enabled
+ if ( $idin_enable_ip_country_filtering ) {
+ // override international IP's - don't validate idin when not NL
+ if ( ! $bluem->VerifyIPIsNetherlands() ) {
+ return false;
+ }
+ }
+
+ /**
+ * Check if age verification is needed.
+ */
+ if ( isset( $options['idin_woocommerce_age_verification'] ) && $options['idin_woocommerce_age_verification'] === '1' ) {
+ if ( bluem_is_woocommerce_activated() && ! $age_verification_needed ) {
+ return false;
+ }
+ }
+
+ return true;
}
/**
* Retrieves the user validation status
*/
-function bluem_idin_user_validated(): bool
-{
- global $current_user;
-
- $storage = bluem_db_get_storage();
-
- if (is_user_logged_in()) {
- return get_user_meta(get_current_user_id(), 'bluem_idin_validated', true) == '1';
- }
- // or as a guest:
- if (isset($storage['bluem_idin_validated']) && $storage['bluem_idin_validated'] === true) {
- return true;
- }
- return false;
+function bluem_idin_user_validated(): bool {
+ global $current_user;
+
+ $storage = bluem_db_get_storage();
+
+ if ( is_user_logged_in() ) {
+ return get_user_meta( get_current_user_id(), 'bluem_idin_validated', true ) == '1';
+ }
+ // or as a guest:
+ if ( isset( $storage['bluem_idin_validated'] ) && $storage['bluem_idin_validated'] === true ) {
+ return true;
+ }
+ return false;
}
-function bluem_get_IDINDescription_tags(): array
-{
- return array(
- '{gebruikersnaam}',
- '{email}',
- '{klantnummer}',
- '{datum}',
- '{datumtijd}',
- );
+function bluem_get_IDINDescription_tags(): array {
+ return array(
+ '{gebruikersnaam}',
+ '{email}',
+ '{klantnummer}',
+ '{datum}',
+ '{datumtijd}',
+ );
}
-function bluem_get_IDINDescription_replaces(): array
-{
- global $current_user;
+function bluem_get_IDINDescription_replaces(): array {
+ global $current_user;
- // with fallbacks if user is not logged in
+ // with fallbacks if user is not logged in
- return array(
- $current_user->display_name ?? '', // '{gebruikersnaam}',
- $current_user->user_email ?? '', // '{email}',
- (string)($current_user->ID ?? ''), // {klantnummer}
- gmdate('d-m-Y'), // '{datum}',
- gmdate('d-m-Y H:i'), // '{datumtijd}',
- );
+ return array(
+ $current_user->display_name ?? '', // '{gebruikersnaam}',
+ $current_user->user_email ?? '', // '{email}',
+ (string) ( $current_user->ID ?? '' ), // {klantnummer}
+ gmdate( 'd-m-Y' ), // '{datum}',
+ gmdate( 'd-m-Y H:i' ), // '{datumtijd}',
+ );
}
-function bluem_parse_IDINDescription($input): string
-{
- // input description tags
- $tags = bluem_get_IDINDescription_tags();
- $replaces = bluem_get_IDINDescription_replaces();
- $result = str_replace($tags, $replaces, $input);
+function bluem_parse_IDINDescription( $input ): string {
+ // input description tags
+ $tags = bluem_get_IDINDescription_tags();
+ $replaces = bluem_get_IDINDescription_replaces();
+ $result = str_replace( $tags, $replaces, $input );
- // filter based on full list of invalid chars for description based on XSD
- // Wel toegestaan: -0-9a-zA-ZéëïôóöüúÉËÏÔÓÖÜÚ€ ()+,.@&=%"'/:;?$
- $result = preg_replace('/[^-0-9a-zA-ZéëïôóöüúÉËÏÔÓÖÜÚ€ ()+,.@&=%\"\'\/:;?$]/u', '', $result);
+ // filter based on full list of invalid chars for description based on XSD
+ // Wel toegestaan: -0-9a-zA-ZéëïôóöüúÉËÏÔÓÖÜÚ€ ()+,.@&=%"'/:;?$
+ $result = preg_replace( '/[^-0-9a-zA-ZéëïôóöüúÉËÏÔÓÖÜÚ€ ()+,.@&=%\"\'\/:;?$]/u', '', $result );
- // also adhere to char limit
- return substr($result, 0, 128);
+ // also adhere to char limit
+ return substr( $result, 0, 128 );
}
-function bluem_idin_execute($callback = null, $redirect = true, $redirect_page = false)
-{
- global $current_user;
-
- $bluem_config = bluem_woocommerce_get_config();
-
- if (isset($bluem_config->IDINDescription)) {
- $description = bluem_parse_IDINDescription($bluem_config->IDINDescription);
- } else {
- $description = 'Identificatie ' . $current_user->display_name;
- }
-
- if (is_user_logged_in()) {
- $debtorReference = $current_user->ID;
- } else {
- $debtorReference = 'guest' . gmdate('Ymdhisu');
- }
-
- // fallback until this is corrected in bluem-php
- $bluem_config->brandID = $bluem_config->IDINBrandID;
-
- try {
- $bluem = new Bluem($bluem_config);
- } catch (InvalidBluemConfigurationException $e) {
- printf(
- /* translators: %s: Error message */
- esc_html__('Fout: De Bluem Plug-in is niet goed ingesteld. Neem contact op met je systeembeheerder. Foutmelding: %s', 'bluem'),
- esc_html($e->getMessage())
- );
-
- exit;
- }
-
- $cats = bluem_idin_get_categories();
-
- if (count($cats) === 0) {
- $errormessage = esc_html__('Geen juiste iDIN categories ingesteld', 'bluem');
- // bluem_error_report_email(
- // [
- // 'service' => 'idin',
- // 'function' => 'idin_execute',
- // 'message' => $errormessage
- // ]
- // );
- bluem_dialogs_render_prompt($errormessage);
- exit();
- }
-
- if (is_null($callback)) {
- $callback = home_url('bluem-woocommerce/idin_shortcode_callback');
- }
-
- if ($redirect_page !== false) {
- $callback .= '/go_to_cart';
- }
-
- // To create AND perform a request:
- $request = $bluem->CreateIdentityRequest(
- $cats,
- $description,
- $debtorReference,
- '', // Entrance code
- $callback // Return URL
- );
-
- // allow the testing admin to alter the response status themselves.
- if ($bluem_config->environment === 'test') {
- $request->enableStatusGUI();
- }
-
- try {
- $response = $bluem->PerformRequest($request);
-
- if ($response->ReceivedResponse() && $response->Status() === true && !isset($response->IdentityTransactionResponse->Error)) {
-
- $entranceCode = $response->GetEntranceCode();
- $transactionID = $response->GetTransactionID();
- $transactionURL = $response->GetTransactionURL();
-
- bluem_db_create_request(
- array(
- 'entrance_code' => $entranceCode,
- 'transaction_id' => $transactionID,
- 'transaction_url' => $transactionURL,
- 'user_id' => is_user_logged_in() ? $current_user->ID : 0,
- 'timestamp' => gmdate('Y-m-d H:i:s'),
- 'description' => $description,
- 'debtor_reference' => $debtorReference,
- 'type' => 'identity',
- 'order_id' => null,
- 'payload' => wp_json_encode(
- array(
- 'environment' => $bluem_config->environment,
- )
- ),
- )
- );
-
- // save this in our user metadata store
- if (is_user_logged_in()) {
- update_user_meta(
- get_current_user_id(),
- 'bluem_idin_entrance_code',
- $entranceCode
- );
- update_user_meta(
- get_current_user_id(),
- 'bluem_idin_transaction_id',
- $transactionID
- );
- update_user_meta(
- get_current_user_id(),
- 'bluem_idin_transaction_url',
- $transactionURL
- );
- } else {
- bluem_db_insert_storage(
- array(
- 'bluem_idin_entrance_code' => $entranceCode,
- 'bluem_idin_transaction_id' => $transactionID,
- 'bluem_idin_transaction_url' => $transactionURL,
- )
- );
- }
-
- if ($redirect) {
- if (ob_get_length() !== false && ob_get_length() > 0) {
- ob_clean();
- }
- ob_start();
- wp_redirect($transactionURL);
- exit;
- } else {
- return array(
- 'result' => true,
- 'url' => $transactionURL,
- );
- }
- } else {
- $msg = esc_html__('Er ging iets mis bij het aanmaken van de transactie. Vermeld onderstaande informatie aan het websitebeheer:', 'bluem');
-
- if ($response->Error() !== '') {
- $msg .= '
Response: ' .
- $response->Error();
- } elseif (!empty($response->IdentityTransactionResponse->Error->ErrorMessage)) {
- $msg .= '
' . sprintf(
- /* translators: %s: Error message */
- esc_html__('iDIN fout: %s', 'bluem'), $response->IdentityTransactionResponse->Error->ErrorMessage . ""
- );
- } else {
- $msg .= '
' . esc_html__('Algemene fout', 'bluem');
- }
-
- // bluem_error_report_email(
- // [
- // 'service' => 'idin',
- // 'function' => 'idin_execute',
- // 'message' => $msg
- // ]
- // );
- bluem_dialogs_render_prompt($msg);
- exit;
- }
- } catch (\Exception $e) {
- $msg = esc_html__('Er ging iets mis bij het aanmaken van de transactie. Vermeld onderstaande informatie aan het websitebeheer:', 'bluem');
-
- if (!empty($e->getMessage())) {
- $msg .= '
Response: ' . esc_html($e->getMessage());
- } else {
- $msg .= '
' . esc_html__('Algemene fout', 'bluem');
- }
- //
- // bluem_error_report_email(
- // [
- // 'service' => 'idin',
- // 'function' => 'idin_execute',
- // 'message' => $e->getMessage()
- // ]
- // );
- bluem_dialogs_render_prompt($msg);
- exit;
- }
+function bluem_idin_execute( $callback = null, $redirect = true, $redirect_page = false ) {
+ global $current_user;
+
+ $bluem_config = bluem_woocommerce_get_config();
+
+ if ( isset( $bluem_config->IDINDescription ) ) {
+ $description = bluem_parse_IDINDescription( $bluem_config->IDINDescription );
+ } else {
+ $description = 'Identificatie ' . $current_user->display_name;
+ }
+
+ if ( is_user_logged_in() ) {
+ $debtorReference = $current_user->ID;
+ } else {
+ $debtorReference = 'guest' . gmdate( 'Ymdhisu' );
+ }
+
+ // fallback until this is corrected in bluem-php
+ $bluem_config->brandID = $bluem_config->IDINBrandID;
+
+ try {
+ $bluem = new Bluem( $bluem_config );
+ } catch ( InvalidBluemConfigurationException $e ) {
+ printf(
+ /* translators: %s: Error message */
+ esc_html__( 'Fout: De Bluem Plug-in is niet goed ingesteld. Neem contact op met je systeembeheerder. Foutmelding: %s', 'bluem' ),
+ esc_html( $e->getMessage() )
+ );
+
+ exit;
+ }
+
+ $cats = bluem_idin_get_categories();
+
+ if ( count( $cats ) === 0 ) {
+ $errormessage = esc_html__( 'Geen juiste iDIN categories ingesteld', 'bluem' );
+ // bluem_error_report_email(
+ // [
+ // 'service' => 'idin',
+ // 'function' => 'idin_execute',
+ // 'message' => $errormessage
+ // ]
+ // );
+ bluem_dialogs_render_prompt( $errormessage );
+ exit();
+ }
+
+ if ( is_null( $callback ) ) {
+ $callback = home_url( 'bluem-woocommerce/idin_shortcode_callback' );
+ }
+
+ if ( $redirect_page !== false ) {
+ $callback .= '/go_to_cart';
+ }
+
+ // To create AND perform a request:
+ $request = $bluem->CreateIdentityRequest(
+ $cats,
+ $description,
+ $debtorReference,
+ '', // Entrance code
+ $callback // Return URL
+ );
+
+ // allow the testing admin to alter the response status themselves.
+ if ( $bluem_config->environment === 'test' ) {
+ $request->enableStatusGUI();
+ }
+
+ try {
+ $response = $bluem->PerformRequest( $request );
+
+ if ( $response->ReceivedResponse() && $response->Status() === true && ! isset( $response->IdentityTransactionResponse->Error ) ) {
+
+ $entranceCode = $response->GetEntranceCode();
+ $transactionID = $response->GetTransactionID();
+ $transactionURL = $response->GetTransactionURL();
+
+ bluem_db_create_request(
+ array(
+ 'entrance_code' => $entranceCode,
+ 'transaction_id' => $transactionID,
+ 'transaction_url' => $transactionURL,
+ 'user_id' => is_user_logged_in() ? $current_user->ID : 0,
+ 'timestamp' => gmdate( 'Y-m-d H:i:s' ),
+ 'description' => $description,
+ 'debtor_reference' => $debtorReference,
+ 'type' => 'identity',
+ 'order_id' => null,
+ 'payload' => wp_json_encode(
+ array(
+ 'environment' => $bluem_config->environment,
+ )
+ ),
+ )
+ );
+
+ // save this in our user metadata store
+ if ( is_user_logged_in() ) {
+ update_user_meta(
+ get_current_user_id(),
+ 'bluem_idin_entrance_code',
+ $entranceCode
+ );
+ update_user_meta(
+ get_current_user_id(),
+ 'bluem_idin_transaction_id',
+ $transactionID
+ );
+ update_user_meta(
+ get_current_user_id(),
+ 'bluem_idin_transaction_url',
+ $transactionURL
+ );
+ } else {
+ bluem_db_insert_storage(
+ array(
+ 'bluem_idin_entrance_code' => $entranceCode,
+ 'bluem_idin_transaction_id' => $transactionID,
+ 'bluem_idin_transaction_url' => $transactionURL,
+ )
+ );
+ }
+
+ if ( $redirect ) {
+ if ( ob_get_length() !== false && ob_get_length() > 0 ) {
+ ob_clean();
+ }
+ ob_start();
+ wp_redirect( $transactionURL );
+ exit;
+ } else {
+ return array(
+ 'result' => true,
+ 'url' => $transactionURL,
+ );
+ }
+ } else {
+ $msg = esc_html__( 'Er ging iets mis bij het aanmaken van de transactie. Vermeld onderstaande informatie aan het websitebeheer:', 'bluem' );
+
+ if ( $response->Error() !== '' ) {
+ $msg .= '
Response: ' .
+ $response->Error();
+ } elseif ( ! empty( $response->IdentityTransactionResponse->Error->ErrorMessage ) ) {
+ $msg .= '
' . sprintf(
+ /* translators: %s: Error message */
+ esc_html__( 'iDIN fout: %s', 'bluem' ),
+ $response->IdentityTransactionResponse->Error->ErrorMessage . ''
+ );
+ } else {
+ $msg .= '
' . esc_html__( 'Algemene fout', 'bluem' );
+ }
+
+ // bluem_error_report_email(
+ // [
+ // 'service' => 'idin',
+ // 'function' => 'idin_execute',
+ // 'message' => $msg
+ // ]
+ // );
+ bluem_dialogs_render_prompt( $msg );
+ exit;
+ }
+ } catch ( \Exception $e ) {
+ $msg = esc_html__( 'Er ging iets mis bij het aanmaken van de transactie. Vermeld onderstaande informatie aan het websitebeheer:', 'bluem' );
+
+ if ( ! empty( $e->getMessage() ) ) {
+ $msg .= '
Response: ' . esc_html( $e->getMessage() );
+ } else {
+ $msg .= '
' . esc_html__( 'Algemene fout', 'bluem' );
+ }
+ //
+ // bluem_error_report_email(
+ // [
+ // 'service' => 'idin',
+ // 'function' => 'idin_execute',
+ // 'message' => $e->getMessage()
+ // ]
+ // );
+ bluem_dialogs_render_prompt( $msg );
+ exit;
+ }
}
// https://www.businessbloomer.com/woocommerce-visual-hook-guide-checkout-page/
@@ -1849,192 +1803,190 @@ function bluem_idin_execute($callback = null, $redirect = true, $redirect_page =
/**
* Check if age verification is needed by checkout.
*/
-function bluem_checkout_age_verification_needed(): bool
-{
- $verification_needed = false;
-
- // Get the products in the cart
- $products = WC()->cart->get_cart();
-
- // Loop through the products
- foreach ($products as $cart_item_key => $cart_item) {
- $product_id = $cart_item['product_id'];
- $product = wc_get_product($product_id);
-
- // Retrieve custom attribute value
- $age_verification = $product->get_meta('pa_age_verification');
-
- // Check if age verification is enabled by user
- if (!empty($age_verification) && $age_verification === 'enable') {
- $verification_needed = true;
- }
- }
- return $verification_needed;
+function bluem_checkout_age_verification_needed(): bool {
+ $verification_needed = false;
+
+ // Get the products in the cart
+ $products = WC()->cart->get_cart();
+
+ // Loop through the products
+ foreach ( $products as $cart_item_key => $cart_item ) {
+ $product_id = $cart_item['product_id'];
+ $product = wc_get_product( $product_id );
+
+ // Retrieve custom attribute value
+ $age_verification = $product->get_meta( 'pa_age_verification' );
+
+ // Check if age verification is enabled by user
+ if ( ! empty( $age_verification ) && $age_verification === 'enable' ) {
+ $verification_needed = true;
+ }
+ }
+ return $verification_needed;
}
// CHECKOUT review message
-add_action('woocommerce_review_order_before_payment', 'bluem_checkout_idin_notice');
-function bluem_checkout_idin_notice(): void
-{
- global $current_user;
-
- // if no woo
- if (!function_exists('is_checkout') || !function_exists('is_wc_endpoint_url')) {
- return;
- }
-
- // use a setting if this check has to be incurred
- if (function_exists('is_checkout') && !is_checkout()) {
- return;
- }
-
- if (!function_exists('bluem_idin_user_validated')) {
- return;
- }
-
- // don't show this notice on the my-account page (DrankStunter Request, 22-04-2021)
- if (is_page('my-account')
- || is_page('mijn-account')
- ) {
- return;
- }
-
- $validation_needed = bluem_idin_validation_needed();
-
- $options = get_option('bluem_woocommerce_options');
-
- if (isset($options['idin_scenario_active']) && $options['idin_scenario_active'] !== '') {
- $scenario = (int)$options['idin_scenario_active'];
- }
-
- if (isset($options['idin_identity_dialog_no_verification_text']) && $options['idin_identity_dialog_no_verification_text'] !== '') {
- $identity_dialog_no_verification_text = $options['idin_identity_dialog_no_verification_text'];
- } else {
- $identity_dialog_no_verification_text = esc_html__('Uw leeftijd is niet bekend of niet toereikend. U kan dus niet deze bestelling afronden. Neem bij vragen contact op met de webshop support.', 'bluem');
- }
-
- if (isset($options['idin_identity_dialog_thank_you_message']) && $options['idin_identity_dialog_thank_you_message'] !== '') {
- $idin_identity_dialog_thank_you_message = $options['idin_identity_dialog_thank_you_message'];
- } else {
- $idin_identity_dialog_thank_you_message = esc_html__('Je leeftijd is geverifieerd, bedankt.', 'bluem');
- }
-
- if (isset($options['idin_identity_topbar_no_verification_text']) && $options['idin_identity_topbar_no_verification_text'] !== '') {
- $idin_identity_topbar_no_verification_text = $options['idin_identity_topbar_no_verification_text'];
- } else {
- $idin_identity_topbar_no_verification_text = esc_html__('We hebben uw leeftijd (nog) niet kunnen opvragen. Voltooi eerst de identificatie procedure.', 'bluem');
- }
-
- if ($validation_needed && $scenario > 0) {
- echo '
' . esc_html__('Identificatie', 'bluem') . '
';
-
- $validated = bluem_idin_user_validated();
-
- $validation_message = $idin_identity_topbar_no_verification_text;
-
- if (!$validated) {
- bluem_idin_generate_notice_e($validation_message, true);
-
- return;
- }
-
- // get report from user metadata
- // $results = bluem_idin_retrieve_results();
- // identified? but is this person OK of age?
- if ($scenario === 1 || $scenario === 3) {
- // we gaan er standaard vanuit dat de leeftijd NIET toereikend is
- $age_valid = false;
-
- if (is_user_logged_in()) {
- $ageCheckResponse = get_user_meta(
- $current_user->ID,
- 'bluem_idin_report_agecheckresponse',
- true
- );
- } else {
- $storage = bluem_db_get_storage();
-
- $ageCheckResponse = $storage['bluem_idin_report_agecheckresponse'] ?? '';
- }
-
- // var_dump($ageCheckResponse);
- // check on age based on response of AgeCheckRequest in user meta
- // if ($scenario == 1)
- // {
- if (isset($ageCheckResponse)) {
- if ($ageCheckResponse === 'true') {
-
- // TRUE Teruggekregen van de bank
- $age_valid = true;
- } else {
- // ERROR KON BIRTHDAY NIET INLEZEN, WEL INGEVULD BIJ DE BANK? nIET VALIDE DUS
- $validation_message = $identity_dialog_no_verification_text;
- // /"Uw leeftijd is niet bekend of niet toereikend. U kan dus niet deze bestelling afronden. Neem bij vragen contact op met de webshop support.";
-
- $age_valid = false;
- }
- } else {
- // ERROR KON BIRTHDAY NIET INLEZEN, WEL INGEVULD BIJ DE BANK? nIET VALIDE DUS
- $validation_message = $identity_dialog_no_verification_text;
- // "We hebben uw leeftijd nog niet kunnen opvragen bij de identificatie.
- // Neem contact op met de webshop support.";
-
- $age_valid = false;
- }
- // }
-
- // check on age based on response of BirthDateRequest in user meta
- // if ($scenario == 3)
- // {
- // $min_age = bluem_idin_get_min_age();
-
- // echo $results->BirthDateResponse; // prints 1975-07-25
- // if (isset($results->BirthDateResponse) && $results->BirthDateResponse!=="") {
-
- // $user_age = bluem_idin_get_age_based_on_date($results->BirthDateResponse);
- // if ($user_age < $min_age) {
- // $validation_message = "Je leeftijd, $user_age, is niet toereikend. De minimumleeftijd is {$min_age} jaar.
- //
Identificeer jezelf opnieuw of neem contact op.";
- // $age_valid = false;
- // } else {
- // $age_valid = true;
- // }
- // } else {
-
- // ERROR KON BIRTHDAY NIET INLEZEN, WEL INGEVULD BIJ DE BANK? nIET VALIDE DUS
- // $validation_message = "We hebben je leeftijd niet kunnen opvragen bij de identificatie.
- // Neem contact op met de webshop support.";
- // $age_valid =false;
- // }
- // }
-
- if (!$age_valid) {
- bluem_idin_generate_notice_e($validation_message, true);
- } else {
- bluem_idin_generate_notice_e($idin_identity_dialog_thank_you_message);
- }
-
- return;
- }
- }
-
- //
Identificatie is vereist alvorens je deze bestelling kan plaatsen
";
-
- if ($validation_needed && bluem_checkout_check_idin_validated_filter() == false) {
- bluem_idin_generate_notice_e('Verifieer eerst je identiteit.', true);
- // esc_html_e(
- // "Verifieer eerst je identiteit via de mijn account pagina",
- // "woocommerce"
- // );
- // return;
- }
+add_action( 'woocommerce_review_order_before_payment', 'bluem_checkout_idin_notice' );
+function bluem_checkout_idin_notice(): void {
+ global $current_user;
+
+ // if no woo
+ if ( ! function_exists( 'is_checkout' ) || ! function_exists( 'is_wc_endpoint_url' ) ) {
+ return;
+ }
+
+ // use a setting if this check has to be incurred
+ if ( function_exists( 'is_checkout' ) && ! is_checkout() ) {
+ return;
+ }
+
+ if ( ! function_exists( 'bluem_idin_user_validated' ) ) {
+ return;
+ }
+
+ // don't show this notice on the my-account page (DrankStunter Request, 22-04-2021)
+ if ( is_page( 'my-account' )
+ || is_page( 'mijn-account' )
+ ) {
+ return;
+ }
+
+ $validation_needed = bluem_idin_validation_needed();
+
+ $options = get_option( 'bluem_woocommerce_options' );
+
+ if ( isset( $options['idin_scenario_active'] ) && $options['idin_scenario_active'] !== '' ) {
+ $scenario = (int) $options['idin_scenario_active'];
+ }
+
+ if ( isset( $options['idin_identity_dialog_no_verification_text'] ) && $options['idin_identity_dialog_no_verification_text'] !== '' ) {
+ $identity_dialog_no_verification_text = $options['idin_identity_dialog_no_verification_text'];
+ } else {
+ $identity_dialog_no_verification_text = esc_html__( 'Uw leeftijd is niet bekend of niet toereikend. U kan dus niet deze bestelling afronden. Neem bij vragen contact op met de webshop support.', 'bluem' );
+ }
+
+ if ( isset( $options['idin_identity_dialog_thank_you_message'] ) && $options['idin_identity_dialog_thank_you_message'] !== '' ) {
+ $idin_identity_dialog_thank_you_message = $options['idin_identity_dialog_thank_you_message'];
+ } else {
+ $idin_identity_dialog_thank_you_message = esc_html__( 'Je leeftijd is geverifieerd, bedankt.', 'bluem' );
+ }
+
+ if ( isset( $options['idin_identity_topbar_no_verification_text'] ) && $options['idin_identity_topbar_no_verification_text'] !== '' ) {
+ $idin_identity_topbar_no_verification_text = $options['idin_identity_topbar_no_verification_text'];
+ } else {
+ $idin_identity_topbar_no_verification_text = esc_html__( 'We hebben uw leeftijd (nog) niet kunnen opvragen. Voltooi eerst de identificatie procedure.', 'bluem' );
+ }
+
+ if ( $validation_needed && $scenario > 0 ) {
+ echo '
' . esc_html__( 'Identificatie', 'bluem' ) . '
';
+
+ $validated = bluem_idin_user_validated();
+
+ $validation_message = $idin_identity_topbar_no_verification_text;
+
+ if ( ! $validated ) {
+ bluem_idin_generate_notice_e( $validation_message, true );
+
+ return;
+ }
+
+ // get report from user metadata
+ // $results = bluem_idin_retrieve_results();
+ // identified? but is this person OK of age?
+ if ( $scenario === 1 || $scenario === 3 ) {
+ // we gaan er standaard vanuit dat de leeftijd NIET toereikend is
+ $age_valid = false;
+
+ if ( is_user_logged_in() ) {
+ $ageCheckResponse = get_user_meta(
+ $current_user->ID,
+ 'bluem_idin_report_agecheckresponse',
+ true
+ );
+ } else {
+ $storage = bluem_db_get_storage();
+
+ $ageCheckResponse = $storage['bluem_idin_report_agecheckresponse'] ?? '';
+ }
+
+ // var_dump($ageCheckResponse);
+ // check on age based on response of AgeCheckRequest in user meta
+ // if ($scenario == 1)
+ // {
+ if ( isset( $ageCheckResponse ) ) {
+ if ( $ageCheckResponse === 'true' ) {
+
+ // TRUE Teruggekregen van de bank
+ $age_valid = true;
+ } else {
+ // ERROR KON BIRTHDAY NIET INLEZEN, WEL INGEVULD BIJ DE BANK? nIET VALIDE DUS
+ $validation_message = $identity_dialog_no_verification_text;
+ // /"Uw leeftijd is niet bekend of niet toereikend. U kan dus niet deze bestelling afronden. Neem bij vragen contact op met de webshop support.";
+
+ $age_valid = false;
+ }
+ } else {
+ // ERROR KON BIRTHDAY NIET INLEZEN, WEL INGEVULD BIJ DE BANK? nIET VALIDE DUS
+ $validation_message = $identity_dialog_no_verification_text;
+ // "We hebben uw leeftijd nog niet kunnen opvragen bij de identificatie.
+ // Neem contact op met de webshop support.";
+
+ $age_valid = false;
+ }
+ // }
+
+ // check on age based on response of BirthDateRequest in user meta
+ // if ($scenario == 3)
+ // {
+ // $min_age = bluem_idin_get_min_age();
+
+ // echo $results->BirthDateResponse; // prints 1975-07-25
+ // if (isset($results->BirthDateResponse) && $results->BirthDateResponse!=="") {
+
+ // $user_age = bluem_idin_get_age_based_on_date($results->BirthDateResponse);
+ // if ($user_age < $min_age) {
+ // $validation_message = "Je leeftijd, $user_age, is niet toereikend. De minimumleeftijd is {$min_age} jaar.
+ //
Identificeer jezelf opnieuw of neem contact op.";
+ // $age_valid = false;
+ // } else {
+ // $age_valid = true;
+ // }
+ // } else {
+
+ // ERROR KON BIRTHDAY NIET INLEZEN, WEL INGEVULD BIJ DE BANK? nIET VALIDE DUS
+ // $validation_message = "We hebben je leeftijd niet kunnen opvragen bij de identificatie.
+ // Neem contact op met de webshop support.";
+ // $age_valid =false;
+ // }
+ // }
+
+ if ( ! $age_valid ) {
+ bluem_idin_generate_notice_e( $validation_message, true );
+ } else {
+ bluem_idin_generate_notice_e( $idin_identity_dialog_thank_you_message );
+ }
+
+ return;
+ }
+ }
+
+ //
Identificatie is vereist alvorens je deze bestelling kan plaatsen
";
+
+ if ( $validation_needed && bluem_checkout_check_idin_validated_filter() == false ) {
+ bluem_idin_generate_notice_e( 'Verifieer eerst je identiteit.', true );
+ // esc_html_e(
+ // "Verifieer eerst je identiteit via de mijn account pagina",
+ // "woocommerce"
+ // );
+ // return;
+ }
}
// add_action('woocommerce_check_cart_items', 'bluem_checkout_check_idin_validated'); // Cart and Checkout
-add_action('woocommerce_after_checkout_validation', 'bluem_validate_idin_at_checkout', 10, 2);
+add_action( 'woocommerce_after_checkout_validation', 'bluem_validate_idin_at_checkout', 10, 2 );
/**
* @param $fields
@@ -2042,10 +1994,9 @@ function bluem_checkout_idin_notice(): void
*
* @return void
*/
-function bluem_validate_idin_at_checkout($fields, $errors): void
-{
- bluem_checkout_check_idin_validated();
- // $errors->add( 'validation', 'Your first or last name contains a number. Really?' );
+function bluem_validate_idin_at_checkout( $fields, $errors ): void {
+ bluem_checkout_check_idin_validated();
+ // $errors->add( 'validation', 'Your first or last name contains a number. Really?' );
}
@@ -2054,222 +2005,217 @@ function bluem_validate_idin_at_checkout($fields, $errors): void
*/
// @todo: this is partially redundant with bluem_checkout_idin_notice
-add_action('template_redirect', 'bluem_checkout_check_idin_validated');
-function bluem_checkout_check_idin_validated(): bool
-{
- global $current_user;
-
- // ! is_user_logged_in() &&
-
- if (!function_exists('is_checkout') || !function_exists('is_wc_endpoint_url')) {
- return true;
- }
-
- // only run this check in Woo & checkout
- if (!is_checkout() || is_wc_endpoint_url()) {
- return true;
- }
-
- // don't show this notice on the my-account page (DrankStunter Request, 22-04-2021)
- if (is_page('my-account')
- || is_page('mijn-account')
- ) {
- return true;
- }
-
- if (!function_exists('bluem_idin_user_validated')) {
- return true;
- }
-
- $validation_needed = bluem_idin_validation_needed();
-
- $options = get_option('bluem_woocommerce_options');
-
- if (isset($options['idin_identify_button_inner']) && $options['idin_identify_button_inner'] !== '') {
- $identify_button_inner = $options['idin_identify_button_inner'];
- } else {
- $identify_button_inner = esc_html__('Klik hier om je te identificeren', 'bluem');
- }
-
- if (isset($options['idin_identity_topbar_invalid_verification_text']) && $options['idin_identity_topbar_invalid_verification_text'] !== '') {
- $idin_identity_topbar_invalid_verification_text = $options['idin_identity_topbar_invalid_verification_text'];
- } else {
- $idin_identity_topbar_invalid_verification_text = esc_html__('Uw leeftijd is niet toereikend. U kan dus niet deze bestelling afronden.', 'bluem');
- }
- if (isset($options['idin_identity_topbar_no_verification_text']) && $options['idin_identity_topbar_no_verification_text'] !== '') {
- $idin_identity_topbar_no_verification_text = $options['idin_identity_topbar_no_verification_text'];
- } else {
- $idin_identity_topbar_no_verification_text = esc_html__('We hebben uw leeftijd (nog) niet kunnen opvragen. Voltooi eerst de identificatie procedure.', 'bluem');
- }
-
- if (isset($options['idin_identity_popup_thank_you_message']) && $options['idin_identity_popup_thank_you_message'] !== '') {
- $idin_identity_popup_thank_you_message = $options['idin_identity_popup_thank_you_message'];
- } else {
- $idin_identity_popup_thank_you_message = esc_html__('Je leeftijd is geverifieerd.', 'bluem');
- }
-
- // @todo: implement this later to allow the notice to be hidden
- // but the checkout still be blocked. Right now this is
- // connected due to the design of WooCOmmerce.
- // Further research is needed to see if this is possible.
- $idin_show_notice_in_checkout = true;
-
- if (isset($options['idin_scenario_active']) && $options['idin_scenario_active'] !== '') {
- $scenario = (int)$options['idin_scenario_active'];
- }
-
- if ($validation_needed && $scenario > 0) {
- $validated = bluem_idin_user_validated();
- $idin_logo_html = bluem_get_idin_logo_html();
- $validation_message = $idin_identity_topbar_no_verification_text;
-
- // above 0: any form of verification is required
- if (!$validated) {
- if ($idin_show_notice_in_checkout) {
- wc_add_notice(
- bluem_idin_generate_notice($validation_message, true, false, false),
- 'error'
- );
- }
-
- return false;
- } else {
-
- // get report from user metadata
- // $results = bluem_idin_retrieve_results();
- // identified? but is this person OK of age?
- if ($scenario == 1 || $scenario == 3) {
- // we gaan er standaard vanuit dat de leeftijd NIET toereikend is
- $age_valid = false;
-
- if (is_user_logged_in()) {
- $ageCheckResponse = get_user_meta(
- $current_user->ID,
- 'bluem_idin_report_agecheckresponse',
- true
- );
- } else {
- $storage = bluem_db_get_storage();
-
- $ageCheckResponse = $storage['bluem_idin_report_agecheckresponse'] ?? '';
- }
-
- // check on age based on response of AgeCheckRequest in user meta
- // if ($scenario == 1)
- // {
- $age_valid = false;
- if (isset($ageCheckResponse) && $ageCheckResponse != '') {
- if ($ageCheckResponse === 'true') {
-
- // TRUE Teruggekregen van de bank
- $age_valid = true;
- } else {
- // error: kon birthday niet inlezen, wel ingevuld bij de bank? niet geldig dus
- $validation_message = $idin_identity_topbar_invalid_verification_text;
- $age_valid = false;
- }
- } else {
- // error: kon birthday niet inlezen, wel ingevuld bij de bank? niet geldig dus.
- $validation_message = $idin_identity_topbar_no_verification_text;
-
- $age_valid = false;
- }
-
- if (!$age_valid) {
- if ($idin_show_notice_in_checkout) {
- wc_add_notice(
- bluem_idin_generate_notice($validation_message, true, false, false),
- 'error'
- );
- }
-
- return false;
- } else {
- wc_add_notice(
- $idin_identity_popup_thank_you_message,
- 'success'
- );
- }
- }
- }
- }
-
- // custom user-based checks:
- if ($validation_needed && bluem_checkout_check_idin_validated_filter() == false) {
- if ($idin_show_notice_in_checkout) {
- wc_add_notice(
- bluem_idin_generate_notice($validation_message, true, false, false),
- 'error'
- );
- }
-
- return false;
- }
-
- return true;
+add_action( 'template_redirect', 'bluem_checkout_check_idin_validated' );
+function bluem_checkout_check_idin_validated(): bool {
+ global $current_user;
+
+ // ! is_user_logged_in() &&
+
+ if ( ! function_exists( 'is_checkout' ) || ! function_exists( 'is_wc_endpoint_url' ) ) {
+ return true;
+ }
+
+ // only run this check in Woo & checkout
+ if ( ! is_checkout() || is_wc_endpoint_url() ) {
+ return true;
+ }
+
+ // don't show this notice on the my-account page (DrankStunter Request, 22-04-2021)
+ if ( is_page( 'my-account' )
+ || is_page( 'mijn-account' )
+ ) {
+ return true;
+ }
+
+ if ( ! function_exists( 'bluem_idin_user_validated' ) ) {
+ return true;
+ }
+
+ $validation_needed = bluem_idin_validation_needed();
+
+ $options = get_option( 'bluem_woocommerce_options' );
+
+ if ( isset( $options['idin_identify_button_inner'] ) && $options['idin_identify_button_inner'] !== '' ) {
+ $identify_button_inner = $options['idin_identify_button_inner'];
+ } else {
+ $identify_button_inner = esc_html__( 'Klik hier om je te identificeren', 'bluem' );
+ }
+
+ if ( isset( $options['idin_identity_topbar_invalid_verification_text'] ) && $options['idin_identity_topbar_invalid_verification_text'] !== '' ) {
+ $idin_identity_topbar_invalid_verification_text = $options['idin_identity_topbar_invalid_verification_text'];
+ } else {
+ $idin_identity_topbar_invalid_verification_text = esc_html__( 'Uw leeftijd is niet toereikend. U kan dus niet deze bestelling afronden.', 'bluem' );
+ }
+ if ( isset( $options['idin_identity_topbar_no_verification_text'] ) && $options['idin_identity_topbar_no_verification_text'] !== '' ) {
+ $idin_identity_topbar_no_verification_text = $options['idin_identity_topbar_no_verification_text'];
+ } else {
+ $idin_identity_topbar_no_verification_text = esc_html__( 'We hebben uw leeftijd (nog) niet kunnen opvragen. Voltooi eerst de identificatie procedure.', 'bluem' );
+ }
+
+ if ( isset( $options['idin_identity_popup_thank_you_message'] ) && $options['idin_identity_popup_thank_you_message'] !== '' ) {
+ $idin_identity_popup_thank_you_message = $options['idin_identity_popup_thank_you_message'];
+ } else {
+ $idin_identity_popup_thank_you_message = esc_html__( 'Je leeftijd is geverifieerd.', 'bluem' );
+ }
+
+ // @todo: implement this later to allow the notice to be hidden
+ // but the checkout still be blocked. Right now this is
+ // connected due to the design of WooCOmmerce.
+ // Further research is needed to see if this is possible.
+ $idin_show_notice_in_checkout = true;
+
+ if ( isset( $options['idin_scenario_active'] ) && $options['idin_scenario_active'] !== '' ) {
+ $scenario = (int) $options['idin_scenario_active'];
+ }
+
+ if ( $validation_needed && $scenario > 0 ) {
+ $validated = bluem_idin_user_validated();
+ $idin_logo_html = bluem_get_idin_logo_html();
+ $validation_message = $idin_identity_topbar_no_verification_text;
+
+ // above 0: any form of verification is required
+ if ( ! $validated ) {
+ if ( $idin_show_notice_in_checkout ) {
+ wc_add_notice(
+ bluem_idin_generate_notice( $validation_message, true, false, false ),
+ 'error'
+ );
+ }
+
+ return false;
+ } else {
+
+ // get report from user metadata
+ // $results = bluem_idin_retrieve_results();
+ // identified? but is this person OK of age?
+ if ( $scenario == 1 || $scenario == 3 ) {
+ // we gaan er standaard vanuit dat de leeftijd NIET toereikend is
+ $age_valid = false;
+
+ if ( is_user_logged_in() ) {
+ $ageCheckResponse = get_user_meta(
+ $current_user->ID,
+ 'bluem_idin_report_agecheckresponse',
+ true
+ );
+ } else {
+ $storage = bluem_db_get_storage();
+
+ $ageCheckResponse = $storage['bluem_idin_report_agecheckresponse'] ?? '';
+ }
+
+ // check on age based on response of AgeCheckRequest in user meta
+ // if ($scenario == 1)
+ // {
+ $age_valid = false;
+ if ( isset( $ageCheckResponse ) && $ageCheckResponse != '' ) {
+ if ( $ageCheckResponse === 'true' ) {
+
+ // TRUE Teruggekregen van de bank
+ $age_valid = true;
+ } else {
+ // error: kon birthday niet inlezen, wel ingevuld bij de bank? niet geldig dus
+ $validation_message = $idin_identity_topbar_invalid_verification_text;
+ $age_valid = false;
+ }
+ } else {
+ // error: kon birthday niet inlezen, wel ingevuld bij de bank? niet geldig dus.
+ $validation_message = $idin_identity_topbar_no_verification_text;
+
+ $age_valid = false;
+ }
+
+ if ( ! $age_valid ) {
+ if ( $idin_show_notice_in_checkout ) {
+ wc_add_notice(
+ bluem_idin_generate_notice( $validation_message, true, false, false ),
+ 'error'
+ );
+ }
+
+ return false;
+ } else {
+ wc_add_notice(
+ $idin_identity_popup_thank_you_message,
+ 'success'
+ );
+ }
+ }
+ }
+ }
+
+ // custom user-based checks:
+ if ( $validation_needed && bluem_checkout_check_idin_validated_filter() == false ) {
+ if ( $idin_show_notice_in_checkout ) {
+ wc_add_notice(
+ bluem_idin_generate_notice( $validation_message, true, false, false ),
+ 'error'
+ );
+ }
+
+ return false;
+ }
+
+ return true;
}
// @todo: simplify and merge above two functions bluem_checkout_check_idin_validated and bluem_checkout_idin_notice
add_filter(
- 'bluem_checkout_check_idin_validated_filter',
- 'bluem_checkout_check_idin_validated_filter_function',
- 10,
- 1
+ 'bluem_checkout_check_idin_validated_filter',
+ 'bluem_checkout_check_idin_validated_filter_function',
+ 10,
+ 1
);
-function bluem_checkout_check_idin_validated_filter(): bool
-{
- // override this function if you want to add a filter to block the checkout procedure based on the iDIN validation procedure being completed.
- // if you return true, the checkout is enabled. If you return false, the checkout is blocked and a notice is shown.
+function bluem_checkout_check_idin_validated_filter(): bool {
+ // override this function if you want to add a filter to block the checkout procedure based on the iDIN validation procedure being completed.
+ // if you return true, the checkout is enabled. If you return false, the checkout is blocked and a notice is shown.
- /*
+ /*
for example:
if (!bluem_idin_user_validated_extra_function()) {
return false;
}
*/
- return true;
+ return true;
}
-function bluem_idin_get_age_based_on_date($birthday_string): int
-{
- $birthdate_seconds = strtotime($birthday_string);
- $now_seconds = time();
+function bluem_idin_get_age_based_on_date( $birthday_string ): int {
+ $birthdate_seconds = strtotime( $birthday_string );
+ $now_seconds = time();
- return (int)floor(($now_seconds - $birthdate_seconds) / 60 / 60 / 24 / 365);
+ return (int) floor( ( $now_seconds - $birthdate_seconds ) / 60 / 60 / 24 / 365 );
}
-function bluem_idin_get_verification_scenario(): int
-{
- $options = get_option('bluem_woocommerce_options');
- $scenario = 0;
+function bluem_idin_get_verification_scenario(): int {
+ $options = get_option( 'bluem_woocommerce_options' );
+ $scenario = 0;
- if (isset($options['idin_scenario_active'])
- && $options['idin_scenario_active'] !== ''
- ) {
- $scenario = (int)$options['idin_scenario_active'];
- }
+ if ( isset( $options['idin_scenario_active'] )
+ && $options['idin_scenario_active'] !== ''
+ ) {
+ $scenario = (int) $options['idin_scenario_active'];
+ }
- return $scenario;
+ return $scenario;
}
-function bluem_idin_get_min_age()
-{
- $options = get_option('bluem_woocommerce_options');
+function bluem_idin_get_min_age() {
+ $options = get_option( 'bluem_woocommerce_options' );
- if (isset($options['idin_check_age_minimum_age'])
- && $options['idin_check_age_minimum_age'] !== ''
- ) {
- $min_age = $options['idin_check_age_minimum_age'];
- } else {
- $min_age = 18;
- }
+ if ( isset( $options['idin_check_age_minimum_age'] )
+ && $options['idin_check_age_minimum_age'] !== ''
+ ) {
+ $min_age = $options['idin_check_age_minimum_age'];
+ } else {
+ $min_age = 18;
+ }
- return $min_age;
+ return $min_age;
}
// https://wordpress.stackexchange.com/questions/314955/add-custom-order-meta-to-order-completed-email
-add_filter('woocommerce_email_order_meta_fields', 'bluem_order_email_identity_meta_data', 10, 3);
+add_filter( 'woocommerce_email_order_meta_fields', 'bluem_order_email_identity_meta_data', 10, 3 );
/**
* Add identity-related metadata fields to an order confirmation email
@@ -2279,156 +2225,155 @@ function bluem_idin_get_min_age()
* @param $sent_to_admin
* @param $order
*/
-function bluem_order_email_identity_meta_data($fields, $sent_to_admin, $order): bool|array
-{
- global $current_user;
-
- $options = get_option('bluem_woocommerce_options');
-
- if (is_user_logged_in()) {
- $request = bluem_db_get_most_recent_request($current_user->ID, 'identity');
- } else {
- $request = false;
-
- // for now, don't add any information to an email if we can't find the request - for example if the guest session was not securely stored in an account
-
- // TODO DAAN
- // $order_id = $order->ID;
- // $requests_links = bluem_db_get_links_for_order($order_id);
- // $requests = [];
- // foreach ($requests_links as $rql) {
- // $requests[] = bluem_db_get_request_by_id($rql->request_id);
- // }
-
- // if (isset($requests) && count($requests)>0) {
- // $request = $requests[0];
- // } else {
- // echo "No requests yet";
- // $pl = false;
- // }
- }
- if ($request == false) {
- return false;
- }
-
- $pl = json_decode($request->payload);
-
- if (!array_key_exists('idin_add_field_in_order_emails', $options)
- || (array_key_exists('idin_add_field_in_order_emails', $options)
- && $options['idin_add_field_in_order_emails'] == '1')
- ) {
- if (is_user_logged_in()) {
- $validation_text = '';
- if (get_user_meta($current_user->ID, 'bluem_idin_validated', true)) {
- $validation_text = esc_html__('Ja', 'bluem');
- // $validation_text .= " (Transactie ". get_user_meta($current_user->ID, 'bluem_idin_transaction_id', true).")";
- } else {
- $validation_text = esc_html__('Ja, als gastgebruiker', 'bluem');
- }
- }
-
- $fields['bluem_idin_validated'] = array(
- 'label' => esc_html__('Identiteit geverifieerd', 'bluem'),
- 'value' => $validation_text,
- );
- }
-
- if (!array_key_exists('idin_add_address_in_order_emails', $options)
- || (array_key_exists('idin_add_address_in_order_emails', $options)
- && $options['idin_add_address_in_order_emails'] == '1')
- ) {
- if (is_user_logged_in()) {
- if ($request !== false) {
- $address_text = '';
- if (isset($pl->report->AddressResponse->Street)) {
- $address_text .= $pl->report->AddressResponse->Street . ' ';
- }
- if (isset($pl->report->AddressResponse->HouseNumber)) {
- $address_text .= $pl->report->AddressResponse->HouseNumber . ' ';
- }
- $address_text .= '
';
- if (isset($pl->report->AddressResponse->PostalCode)) {
- $address_text .= $pl->report->AddressResponse->PostalCode . ' ';
- }
- if (isset($pl->report->AddressResponse->City)) {
- $address_text .= $pl->report->AddressResponse->City . ' ';
- }
- if (isset($pl->report->AddressResponse->CountryCode)) {
- $address_text .= $pl->report->AddressResponse->CountryCode . '';
- }
-
- $fields['bluem_idin_address'] = array(
- 'label' => esc_html__('Adres afkomstig uit verificatie', 'bluem'),
- 'value' => $address_text,
- );
- } else {
- $fields['bluem_idin_address'] = array(
- 'label' => esc_html__('Adres afkomstig uit verificatie', 'bluem'),
- 'value' => esc_html__('Onbekend', 'bluem'),
- );
- }
- }
- }
-
- if (!array_key_exists('idin_add_name_in_order_emails', $options)
- || (array_key_exists('idin_add_name_in_order_emails', $options)
- && $options['idin_add_name_in_order_emails'] == '1')
- ) {
- if ($request !== false) {
- $name_text = '';
- if (isset($pl->report->NameResponse->Initials)
- && $pl->report->NameResponse->Initials !== ''
- ) {
- $name_text .= $pl->report->NameResponse->Initials . ' ';
- }
- if (isset($pl->report->NameResponse->LegalLastNamePrefix)
- && $pl->report->NameResponse->LegalLastNamePrefix !== ''
- ) {
- $name_text .= $pl->report->NameResponse->LegalLastNamePrefix . ' ';
- }
- if (isset($pl->report->NameResponse->LegalLastName)
- && $pl->report->NameResponse->LegalLastName !== ''
- ) {
- $name_text .= $pl->report->NameResponse->LegalLastName . ' ';
- }
-
- $fields['bluem_idin_name'] = array(
- 'label' => esc_html__('Naam afkomstig van verificatie', 'bluem'),
- 'value' => $name_text,
- );
- } else {
- $fields['bluem_idin_name'] = array(
- 'label' => esc_html__('Naam afkomstig uit verificatie', 'bluem'),
- 'value' => esc_html__('Onbekend', 'bluem'),
- );
- }
- }
-
- if (!array_key_exists('idin_add_birthdate_in_order_emails', $options)
- || (array_key_exists('idin_add_birthdate_in_order_emails', $options)
- && $options['idin_add_birthdate_in_order_emails'] == '1')
- ) {
- if ($request !== false) {
- $birthdate_text = '';
- if (isset($pl->report->BirthDateResponse)
- && $pl->report->BirthDateResponse !== ''
- ) {
- $birthdate_text .= $pl->report->BirthDateResponse . ' ';
- }
-
- $fields['bluem_idin_birthdate'] = array(
- 'label' => esc_html__('Geboortedatum uit verificatie', 'bluem'),
- 'value' => $birthdate_text,
- );
- } else {
- $fields['bluem_idin_birthdate'] = array(
- 'label' => esc_html__('Geboortedatum uit verificatie', 'bluem'),
- 'value' => esc_html__('Onbekend', 'bluem'),
- );
- }
- }
-
- return $fields;
+function bluem_order_email_identity_meta_data( $fields, $sent_to_admin, $order ): bool|array {
+ global $current_user;
+
+ $options = get_option( 'bluem_woocommerce_options' );
+
+ if ( is_user_logged_in() ) {
+ $request = bluem_db_get_most_recent_request( $current_user->ID, 'identity' );
+ } else {
+ $request = false;
+
+ // for now, don't add any information to an email if we can't find the request - for example if the guest session was not securely stored in an account
+
+ // TODO DAAN
+ // $order_id = $order->ID;
+ // $requests_links = bluem_db_get_links_for_order($order_id);
+ // $requests = [];
+ // foreach ($requests_links as $rql) {
+ // $requests[] = bluem_db_get_request_by_id($rql->request_id);
+ // }
+
+ // if (isset($requests) && count($requests)>0) {
+ // $request = $requests[0];
+ // } else {
+ // echo "No requests yet";
+ // $pl = false;
+ // }
+ }
+ if ( $request == false ) {
+ return false;
+ }
+
+ $pl = json_decode( $request->payload );
+
+ if ( ! array_key_exists( 'idin_add_field_in_order_emails', $options )
+ || ( array_key_exists( 'idin_add_field_in_order_emails', $options )
+ && $options['idin_add_field_in_order_emails'] == '1' )
+ ) {
+ if ( is_user_logged_in() ) {
+ $validation_text = '';
+ if ( get_user_meta( $current_user->ID, 'bluem_idin_validated', true ) ) {
+ $validation_text = esc_html__( 'Ja', 'bluem' );
+ // $validation_text .= " (Transactie ". get_user_meta($current_user->ID, 'bluem_idin_transaction_id', true).")";
+ } else {
+ $validation_text = esc_html__( 'Ja, als gastgebruiker', 'bluem' );
+ }
+ }
+
+ $fields['bluem_idin_validated'] = array(
+ 'label' => esc_html__( 'Identiteit geverifieerd', 'bluem' ),
+ 'value' => $validation_text,
+ );
+ }
+
+ if ( ! array_key_exists( 'idin_add_address_in_order_emails', $options )
+ || ( array_key_exists( 'idin_add_address_in_order_emails', $options )
+ && $options['idin_add_address_in_order_emails'] == '1' )
+ ) {
+ if ( is_user_logged_in() ) {
+ if ( $request !== false ) {
+ $address_text = '';
+ if ( isset( $pl->report->AddressResponse->Street ) ) {
+ $address_text .= $pl->report->AddressResponse->Street . ' ';
+ }
+ if ( isset( $pl->report->AddressResponse->HouseNumber ) ) {
+ $address_text .= $pl->report->AddressResponse->HouseNumber . ' ';
+ }
+ $address_text .= '
';
+ if ( isset( $pl->report->AddressResponse->PostalCode ) ) {
+ $address_text .= $pl->report->AddressResponse->PostalCode . ' ';
+ }
+ if ( isset( $pl->report->AddressResponse->City ) ) {
+ $address_text .= $pl->report->AddressResponse->City . ' ';
+ }
+ if ( isset( $pl->report->AddressResponse->CountryCode ) ) {
+ $address_text .= $pl->report->AddressResponse->CountryCode . '';
+ }
+
+ $fields['bluem_idin_address'] = array(
+ 'label' => esc_html__( 'Adres afkomstig uit verificatie', 'bluem' ),
+ 'value' => $address_text,
+ );
+ } else {
+ $fields['bluem_idin_address'] = array(
+ 'label' => esc_html__( 'Adres afkomstig uit verificatie', 'bluem' ),
+ 'value' => esc_html__( 'Onbekend', 'bluem' ),
+ );
+ }
+ }
+ }
+
+ if ( ! array_key_exists( 'idin_add_name_in_order_emails', $options )
+ || ( array_key_exists( 'idin_add_name_in_order_emails', $options )
+ && $options['idin_add_name_in_order_emails'] == '1' )
+ ) {
+ if ( $request !== false ) {
+ $name_text = '';
+ if ( isset( $pl->report->NameResponse->Initials )
+ && $pl->report->NameResponse->Initials !== ''
+ ) {
+ $name_text .= $pl->report->NameResponse->Initials . ' ';
+ }
+ if ( isset( $pl->report->NameResponse->LegalLastNamePrefix )
+ && $pl->report->NameResponse->LegalLastNamePrefix !== ''
+ ) {
+ $name_text .= $pl->report->NameResponse->LegalLastNamePrefix . ' ';
+ }
+ if ( isset( $pl->report->NameResponse->LegalLastName )
+ && $pl->report->NameResponse->LegalLastName !== ''
+ ) {
+ $name_text .= $pl->report->NameResponse->LegalLastName . ' ';
+ }
+
+ $fields['bluem_idin_name'] = array(
+ 'label' => esc_html__( 'Naam afkomstig van verificatie', 'bluem' ),
+ 'value' => $name_text,
+ );
+ } else {
+ $fields['bluem_idin_name'] = array(
+ 'label' => esc_html__( 'Naam afkomstig uit verificatie', 'bluem' ),
+ 'value' => esc_html__( 'Onbekend', 'bluem' ),
+ );
+ }
+ }
+
+ if ( ! array_key_exists( 'idin_add_birthdate_in_order_emails', $options )
+ || ( array_key_exists( 'idin_add_birthdate_in_order_emails', $options )
+ && $options['idin_add_birthdate_in_order_emails'] == '1' )
+ ) {
+ if ( $request !== false ) {
+ $birthdate_text = '';
+ if ( isset( $pl->report->BirthDateResponse )
+ && $pl->report->BirthDateResponse !== ''
+ ) {
+ $birthdate_text .= $pl->report->BirthDateResponse . ' ';
+ }
+
+ $fields['bluem_idin_birthdate'] = array(
+ 'label' => esc_html__( 'Geboortedatum uit verificatie', 'bluem' ),
+ 'value' => $birthdate_text,
+ );
+ } else {
+ $fields['bluem_idin_birthdate'] = array(
+ 'label' => esc_html__( 'Geboortedatum uit verificatie', 'bluem' ),
+ 'value' => esc_html__( 'Onbekend', 'bluem' ),
+ );
+ }
+ }
+
+ return $fields;
}
@@ -2437,111 +2382,110 @@ function bluem_order_email_identity_meta_data($fields, $sent_to_admin, $order):
// {
// }
-$allowedTags = [
- 'a' => [
- 'href' => [],
- 'class' => [],
- 'target' => [],
- ],
- 'div' => [
- 'class' => [],
- 'id' => [],
- 'style' => [],
- ],
- 'img' => [
- 'src' => [],
- 'class' => [],
- 'width' => [],
- 'height' => [],
- 'style' => []
- ],
- 'h4' => [],
- 'hr' => [],
- 'span' => [
- 'class' => [],
- ],
-];
+$allowedTags = array(
+ 'a' => array(
+ 'href' => array(),
+ 'class' => array(),
+ 'target' => array(),
+ ),
+ 'div' => array(
+ 'class' => array(),
+ 'id' => array(),
+ 'style' => array(),
+ ),
+ 'img' => array(
+ 'src' => array(),
+ 'class' => array(),
+ 'width' => array(),
+ 'height' => array(),
+ 'style' => array(),
+ ),
+ 'h4' => array(),
+ 'hr' => array(),
+ 'span' => array(
+ 'class' => array(),
+ ),
+);
/**
* Generate the necessary HTML to show a notice concerning iDIN status
*
- * @param String $message
+ * @param String $message
* @param boolean $button
- * @param bool $logo
- * @param bool $border
+ * @param bool $logo
+ * @param bool $border
*
* @return String
*/
-function bluem_idin_generate_notice(string $message = '', bool $button = false, bool $logo = true, bool $border = true): string
-{
- global $allowedTags;
+function bluem_idin_generate_notice( string $message = '', bool $button = false, bool $logo = true, bool $border = true ): string {
+ global $allowedTags;
- $idin_logo_html = "
 . )
";
- $options = get_option('bluem_woocommerce_options');
- if (isset($options['idin_identify_button_inner']) && $options['idin_identify_button_inner'] !== '') {
- $identify_button_inner = $options['idin_identify_button_inner'];
- } else {
- $identify_button_inner = esc_html__('Klik hier om je te identificeren', 'bluem');
- }
- if (isset($options['idin_identify_button_inner']) && $options['idin_identify_button_inner'] !== '') {
- $identify_button_inner = $options['idin_identify_button_inner'];
- } else {
- $identify_button_inner = esc_html__('Klik hier om je te identificeren', 'bluem');
- }
-
- if (isset($options['idin_identity_more_information_popup']) && $options['idin_identity_more_information_popup'] !== '') {
- $more_information_popup = $options['idin_identity_more_information_popup'];
- } else {
- $more_information_popup = esc_html__('iDIN is een essentieel onderdeel van het winkelproces voor onze webwinkel. Zie je dit kader? Dan is het identificeren voor je aankoop of interactie essentieel.', 'bluem');
- }
-
- $html = "
";
- if ($logo) {
- $html .= $idin_logo_html;
- }
+ border:1px solid #50afed;' : '' ) . "'>";
+ if ( $logo ) {
+ $html .= $idin_logo_html;
+ }
- $html .= "
+ $html .= "
$message";
- if ($button) {
- $html .= "
';
- }
-
- $checkout_url = esc_url(wc_get_checkout_url());
- $html .= '
+ if ( $button ) {
+ $html .= "
';
+ }
+
+ $checkout_url = esc_url( wc_get_checkout_url() );
+ $html .= '
';
- $html .= sprintf(
- wp_kses(
- /* translators: %1$s: checkout url %2$s: more information popup %3$s: checkout url */
- __(
- '
',
- 'bluem'
- ),
- $allowedTags
- ),
- esc_url($checkout_url),
- wp_kses_post($more_information_popup),
- esc_url($checkout_url)
- );
-
- return $html;
+ 'bluem'
+ ),
+ $allowedTags
+ ),
+ esc_url( $checkout_url ),
+ wp_kses_post( $more_information_popup ),
+ esc_url( $checkout_url )
+ );
+
+ return $html;
}
-function bluem_idin_generate_notice_e(string $message = '', bool $button = false, bool $logo = true, bool $border = true): void
-{
- global $allowedTags;
- echo wp_kses(
- bluem_idin_generate_notice($message, $button, $logo, $border),
- $allowedTags
- );
+function bluem_idin_generate_notice_e( string $message = '', bool $button = false, bool $logo = true, bool $border = true ): void {
+ global $allowedTags;
+ echo wp_kses(
+ bluem_idin_generate_notice( $message, $button, $logo, $border ),
+ $allowedTags
+ );
}
/*
* Add identity request if it was already created but first decoupled form a user, based on sesh
**/
-add_action('user_register', 'bluem_link_idin_request_to_sesh', 10, 1);
-function bluem_link_idin_request_to_sesh($user_id): void
-{
- $storage = bluem_db_get_storage();
-
- if (!isset($storage['bluem_idin_transaction_id'])) {
- return;
- }
-
- $tid = $storage['bluem_idin_transaction_id'];
-
- $req = bluem_db_get_request_by_transaction_id($tid);
-
- // only if the current response from the Bluem session storage
- // IS NOT YET linked to any user, i.e. user_id == 0
- if ($req->user_id == '0') {
- bluem_db_update_request(
- $req->id,
- array('user_id' => $user_id)
- );
- bluem_db_request_log($req->id, esc_html__('Identiteit gekoppeld aan gebruiker door in te loggen', 'bluem'));
-
- $pl = json_decode($req->payload);
-
- // also update some user data if applicable
- if (isset($pl->report->AgeCheckResponse)) {
- update_user_meta(
- $user_id,
- 'bluem_idin_report_agecheckresponse',
- $pl->report->AgeCheckResponse
- );
- }
- if (isset($pl->report->CustomerIDResponse)) {
- update_user_meta(
- $user_id,
- 'bluem_idin_report_customeridresponse',
- $pl->report->CustomerIDResponse
- );
- }
-
- update_user_meta(
- $user_id,
- 'bluem_idin_validated',
- ($req->status === 'Success' ? '1' : '0')
- );
- }
+add_action( 'user_register', 'bluem_link_idin_request_to_sesh', 10, 1 );
+function bluem_link_idin_request_to_sesh( $user_id ): void {
+ $storage = bluem_db_get_storage();
+
+ if ( ! isset( $storage['bluem_idin_transaction_id'] ) ) {
+ return;
+ }
+
+ $tid = $storage['bluem_idin_transaction_id'];
+
+ $req = bluem_db_get_request_by_transaction_id( $tid );
+
+ // only if the current response from the Bluem session storage
+ // IS NOT YET linked to any user, i.e. user_id == 0
+ if ( $req->user_id == '0' ) {
+ bluem_db_update_request(
+ $req->id,
+ array( 'user_id' => $user_id )
+ );
+ bluem_db_request_log( $req->id, esc_html__( 'Identiteit gekoppeld aan gebruiker door in te loggen', 'bluem' ) );
+
+ $pl = json_decode( $req->payload );
+
+ // also update some user data if applicable
+ if ( isset( $pl->report->AgeCheckResponse ) ) {
+ update_user_meta(
+ $user_id,
+ 'bluem_idin_report_agecheckresponse',
+ $pl->report->AgeCheckResponse
+ );
+ }
+ if ( isset( $pl->report->CustomerIDResponse ) ) {
+ update_user_meta(
+ $user_id,
+ 'bluem_idin_report_customeridresponse',
+ $pl->report->CustomerIDResponse
+ );
+ }
+
+ update_user_meta(
+ $user_id,
+ 'bluem_idin_validated',
+ ( $req->status === 'Success' ? '1' : '0' )
+ );
+ }
}
diff --git a/bluem-integrations.php b/bluem-integrations.php
index 6c9ef86..34e3fc9 100644
--- a/bluem-integrations.php
+++ b/bluem-integrations.php
@@ -1,97 +1,90 @@
';
+function bluem_woocommerce_integrations_settings_section() {
+ echo '
';
}
-function bluem_woocommerce_get_integration_option($key)
-{
- $options = bluem_woocommerce_get_integrations_options();
- if (array_key_exists($key, $options)) {
- return $options[$key];
- }
+function bluem_woocommerce_get_integration_option( $key ) {
+ $options = bluem_woocommerce_get_integrations_options();
+ if ( array_key_exists( $key, $options ) ) {
+ return $options[ $key ];
+ }
- return false;
+ return false;
}
-function bluem_woocommerce_get_integrations_options()
-{
- return array(
- 'gformActive' => array(
- 'key' => 'gformActive',
- 'title' => 'bluem_gformActive',
- 'name' => 'Gravity Forms',
- 'description' => 'Activeer de Gravity Forms integratie',
- 'type' => 'select',
- 'default' => 'N',
- 'options' => array(
- 'N' => 'Niet actief',
- 'Y' => 'Actief',
- ),
- ),
- 'gformResultpage' => array(
- 'key' => 'gformResultpage',
- 'title' => 'bluem_gformResultpage',
- 'name' => 'Slug resultaatpagina',
- 'description' => 'De slug van de resultaatpagina',
- 'default' => '',
- ),
- 'wpcf7Active' => array(
- 'key' => 'wpcf7Active',
- 'title' => 'bluem_wpcf7Active',
- 'name' => 'ContactForm 7',
- 'description' => 'Activeer de ContactForm 7 integratie',
- 'type' => 'select',
- 'default' => 'N',
- 'options' => array(
- 'N' => 'Niet actief',
- 'Y' => 'Actief',
- ),
- ),
- 'wpcf7Resultpage' => array(
- 'key' => 'wpcf7Resultpage',
- 'title' => 'bluem_wpcf7Resultpage',
- 'name' => 'Slug resultaatpagina',
- 'description' => 'De slug van de resultaatpagina',
- 'default' => '',
- ),
- );
+function bluem_woocommerce_get_integrations_options() {
+ return array(
+ 'gformActive' => array(
+ 'key' => 'gformActive',
+ 'title' => 'bluem_gformActive',
+ 'name' => 'Gravity Forms',
+ 'description' => 'Activeer de Gravity Forms integratie',
+ 'type' => 'select',
+ 'default' => 'N',
+ 'options' => array(
+ 'N' => 'Niet actief',
+ 'Y' => 'Actief',
+ ),
+ ),
+ 'gformResultpage' => array(
+ 'key' => 'gformResultpage',
+ 'title' => 'bluem_gformResultpage',
+ 'name' => 'Slug resultaatpagina voor Gravity Forms',
+ 'description' => 'De slug van de resultaatpagina',
+ 'default' => '',
+ ),
+ 'wpcf7Active' => array(
+ 'key' => 'wpcf7Active',
+ 'title' => 'bluem_wpcf7Active',
+ 'name' => 'ContactForm 7',
+ 'description' => 'Activeer de ContactForm 7 integratie',
+ 'type' => 'select',
+ 'default' => 'N',
+ 'options' => array(
+ 'N' => 'Niet actief',
+ 'Y' => 'Actief',
+ ),
+ ),
+ 'wpcf7Resultpage' => array(
+ 'key' => 'wpcf7Resultpage',
+ 'title' => 'bluem_wpcf7Resultpage',
+ 'name' => 'Slug resultaatpagina',
+ 'description' => 'De slug van de resultaatpagina voor ContactForm 7',
+ 'default' => '',
+ ),
+ );
}
-function bluem_woocommerce_settings_render_gformActive()
-{
- bluem_woocommerce_settings_render_input(
- bluem_woocommerce_get_integration_option('gformActive')
- );
+function bluem_woocommerce_settings_render_gformActive() {
+ bluem_woocommerce_settings_render_input(
+ bluem_woocommerce_get_integration_option( 'gformActive' )
+ );
}
-function bluem_woocommerce_settings_render_gformResultpage()
-{
- bluem_woocommerce_settings_render_input(
- bluem_woocommerce_get_integration_option('gformResultpage')
- );
+function bluem_woocommerce_settings_render_gformResultpage() {
+ bluem_woocommerce_settings_render_input(
+ bluem_woocommerce_get_integration_option( 'gformResultpage' )
+ );
}
-function bluem_woocommerce_settings_render_wpcf7Active()
-{
- bluem_woocommerce_settings_render_input(
- bluem_woocommerce_get_integration_option('wpcf7Active')
- );
+function bluem_woocommerce_settings_render_wpcf7Active() {
+ bluem_woocommerce_settings_render_input(
+ bluem_woocommerce_get_integration_option( 'wpcf7Active' )
+ );
}
-function bluem_woocommerce_settings_render_wpcf7Resultpage()
-{
- bluem_woocommerce_settings_render_input(
- bluem_woocommerce_get_integration_option('wpcf7Resultpage')
- );
+function bluem_woocommerce_settings_render_wpcf7Resultpage() {
+ bluem_woocommerce_settings_render_input(
+ bluem_woocommerce_get_integration_option( 'wpcf7Resultpage' )
+ );
}
/**
@@ -99,17 +92,16 @@ function bluem_woocommerce_settings_render_wpcf7Resultpage()
*
* Javascript code in footer.
*/
-add_action('wp_footer', 'bluem_woocommerce_integration_wpcf7_javascript');
+add_action( 'wp_footer', 'bluem_woocommerce_integration_wpcf7_javascript' );
-function bluem_woocommerce_integration_wpcf7_javascript()
-{
- $bluem_config = bluem_woocommerce_get_config();
+function bluem_woocommerce_integration_wpcf7_javascript() {
+ $bluem_config = bluem_woocommerce_get_config();
- if ($bluem_config->wpcf7Active !== 'Y') {
- return;
- }
+ if ( $bluem_config->wpcf7Active !== 'Y' ) {
+ return;
+ }
- echo '
+ echo '