Skip to content

Commit 21273d8

Browse files
chore: add custom block and API endpoints for user state management
1 parent 9c28f25 commit 21273d8

File tree

15 files changed

+20179
-3
lines changed

15 files changed

+20179
-3
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,7 @@ tools/*
3131
.env
3232
svn-directory
3333
svn-directory/*
34+
node_modules
35+
node_modules/*
36+
blocks/dist
37+
blocks/dist/*

.svnignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ tests/
1010
tools/
1111
vendor/
1212
docker/
13+
node_modules/
14+
package.json
15+
package-lock.json

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ repo-check:
8888

8989
pre-deployment:
9090
#make run-phpcbf
91+
@npm run build
9192
@echo "$(BLUE)Preparing build directory...$(NC)"
9293
if [ -d "$(BUILD_DIR)" ]; then \
9394
if [ "$(BUILD_DIR)" != "/" ]; then \
@@ -101,7 +102,7 @@ pre-deployment:
101102
@cd $(BUILD_DIR) && composer install --no-dev --optimize-autoloader --prefer-dist --no-interaction || { echo "$(RED)Composer install failed!$(NC)"; exit 1; }
102103
@cd $(BUILD_DIR) && composer clear-cache
103104
@echo "$(BLUE)Removing unnecessary files from build directory...$(NC)"
104-
@cd $(BUILD_DIR) && rm -rf README.md .git Makefile tools .env.sample .gitignore Dockerfile .env.sample .gitignore docker-compose.yml codeception.yml Dockerfile loadenv.sh Makefile .php-cs-fixer.cache .phpunit.result.cache .travis.yml phpunit.xml psalm.xml .DS_STORE .svnignore loadenv.sh
105+
@cd $(BUILD_DIR) && rm -rf README.md .git Makefile tools .env.sample .gitignore Dockerfile .env.sample .gitignore docker-compose.yml codeception.yml Dockerfile loadenv.sh Makefile .php-cs-fixer.cache .phpunit.result.cache .travis.yml phpunit.xml psalm.xml .DS_STORE .svnignore loadenv.sh package.json package-lock.json
105106
@rm -rf $(BUILD_DIR)/vendor/bluem-development/bluem-php/examples $(BUILD_DIR)/vendor/bluem-development/bluem-php/tests $(BUILD_DIR)/vendor/bluem-development/bluem-php/.github
106107
@rm $(BUILD_DIR)/vendor/bluem-development/bluem-php/.env.example
107108
@rm $(BUILD_DIR)/vendor/bluem-development/bluem-php/.gitignore

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The stable, production-ready version of the plug-in is available from the WordPr
88
Use this repository to get insight and possibly contribute to the development of this plug-in.
99

1010
# Requirements
11-
This plug-in requires PHP >= 8.0.
11+
This plug-in requires PHP >= 8.2.
1212

1313
If you use our plug-in files or databases in your own custom development, please disable auto-update and check each update manually before installing.
1414
Our plug-in files or database tables structure may change during time.

blocks/editor.css

Whitespace-only changes.

blocks/idin-block/block.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"apiVersion": 2,
3+
"name": "bluem/custom-block",
4+
"title": "Custom Block",
5+
"category": "widgets",
6+
"icon": "smiley",
7+
"description": "A simple custom block.",
8+
"editorScript": "file:./build/index.js",
9+
"style": "file:./style.css",
10+
"editorStyle": "file:./editor.css",
11+
"attributes": {
12+
"message": {
13+
"type": "string",
14+
"default": "Hello world!"
15+
}
16+
}
17+
}

blocks/idin-block/index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { registerBlockType } from '@wordpress/blocks';
2+
import { useBlockProps } from '@wordpress/block-editor';
3+
4+
registerBlockType('bluem/custom-block', {
5+
edit({ attributes, setAttributes }) {
6+
return (
7+
<div {...useBlockProps()}>
8+
<input
9+
value={attributes.message}
10+
onChange={(e) => setAttributes({ message: e.target.value })}
11+
/>
12+
</div>
13+
);
14+
},
15+
save({ attributes }) {
16+
return (
17+
<div {...useBlockProps.save()}>
18+
{attributes.message}
19+
</div>
20+
);
21+
}
22+
});

blocks/index.js

Whitespace-only changes.

blocks/style.css

Whitespace-only changes.

bluem-api.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
if ( ! defined( 'ABSPATH' ) ) {
4+
exit;
5+
}
6+
7+
add_action('rest_api_init', function () {
8+
register_rest_route('bluem/v1', '/user-state', [
9+
'methods' => 'GET',
10+
'callback' => function () {
11+
return [
12+
'userIdentified' => bluem_get_idin_state(),
13+
];
14+
},
15+
'permission_callback' => '__return_true',
16+
]);
17+
});
18+
19+
20+
function bluem_get_idin_state(): array {
21+
$bluem_config = bluem_woocommerce_get_config();
22+
23+
$entranceCode = get_user_meta( get_current_user_id(), 'bluem_idin_entrance_code', true );
24+
$transactionID = get_user_meta( get_current_user_id(), 'bluem_idin_transaction_id', true );
25+
$transactionURL = get_user_meta( get_current_user_id(), 'bluem_idin_transaction_url', true );
26+
27+
return [
28+
'entranceCode' => $entranceCode,
29+
'transactionID' => $transactionID,
30+
'transactionURL' => $transactionURL,
31+
'config' => $bluem_config,
32+
'userIdentified' => !empty($entranceCode) && !empty($transactionID) && !empty($transactionURL),
33+
];
34+
}
35+
36+
37+
add_action('rest_api_init', function () {
38+
register_rest_route('bluem/v1', '/identify-start', [
39+
'methods' => 'GET',
40+
'callback' => function () {
41+
$redirectUrl = 'https://example.com/idin/start'; // you get this from your service
42+
return new WP_REST_Response(['redirectUrl' => $redirectUrl], 200);
43+
},
44+
]);
45+
});

0 commit comments

Comments
 (0)