### Example API Response for Map Information Source: https://github.com/sp-worlds/api-docs/wiki/Информация-о-карте This is an example of the JSON response you can expect when successfully querying the public card information endpoint. It includes the 'balance' and 'webhook' fields. The actual values will vary based on the user's account. ```json { "balance": 16, "webhook": "https://example.ru/webhook" } ``` -------------------------------- ### GET /api/public/card Source: https://github.com/sp-worlds/api-docs/wiki/Информация-о-карте Retrieves the current balance and webhook configuration for the authenticated user's card. ```APIDOC ## GET /api/public/card ### Description Retrieves the current balance and the registered webhook URL for the authenticated user's card. ### Method GET ### Endpoint https://spworlds.ru/api/public/card ### Parameters None ### Request Example N/A (Requires Authentication Header) ### Response #### Success Response (200) - **balance** (integer) - The current balance on the card. - **webhook** (string) - The URL configured for webhooks. #### Response Example { "balance": 16, "webhook": "https://example.ru/webhook" } ``` -------------------------------- ### GET /api/public/card Source: https://context7.com/sp-worlds/api-docs/llms.txt Retrieves the current balance and webhook configuration for the authenticated card. ```APIDOC ## GET /api/public/card ### Description Returns the current balance of the authenticated card and the URL of the configured webhook. ### Method GET ### Endpoint https://spworlds.ru/api/public/card ### Response #### Success Response (200) - **balance** (integer) - Current card balance in AP - **webhook** (string) - URL for transaction notifications #### Response Example { "balance": 16, "webhook": "https://example.ru/webhook" } ``` -------------------------------- ### GET /api/public/accounts/me Source: https://github.com/sp-worlds/api-docs/wiki/Получение-аккаунта-владельца-токена Retrieves the account information for the authenticated token owner. Requires authentication. ```APIDOC ## GET /api/public/accounts/me ### Description Retrieves the account information for the authenticated token owner. This endpoint requires authentication. ### Method GET ### Endpoint https://spworlds.ru/api/public/accounts/me ### Parameters #### Query Parameters None #### Request Body None ### Response #### Success Response (200) - **id** (string) - Unique account ID. - **username** (string) - Player's nickname. - **minecraftUUID** (string) - Player's Minecraft UUID. - **status** (string) - Player's status. - **roles** (array) - An array containing the account's roles. - **city** (object or null) - Information about the city the player belongs to. Returns null if the player is not in a city. - **cards** (array) - An array containing the player's cards. - **createdAt** (string) - The date the account was created. **City Object:** - **id** (string) - Unique city ID. - **name** (string) - City name. - **description** (string) - City description. - **x** (number) - X coordinate of the city in the overworld. - **z** (number) - Z coordinate of the city in the overworld. - **netherX** (number) - X coordinate of the city in the nether. - **netherZ** (number) - Z coordinate of the city in the nether. - **isMayor** (boolean) - Whether the player is the mayor of the city. **Card Object:** - **id** (string) - Unique card ID. - **name** (string) - Card name. - **number** (string) - Card number. - **color** (number) - Card color. #### Response Example ```json { "id": "60d5f4b3b3f3b3f3b3f3b3f3", "username": "PlayerName", "minecraftUUID": "a1b2c3d4-e5f6-7890-1234-567890abcdef", "status": "online", "roles": ["admin", "moderator"], "city": { "id": "city123", "name": "Example City", "description": "A great city", "x": 100, "z": 200, "netherX": -50, "netherZ": -100, "isMayor": true }, "cards": [ { "id": "card001", "name": "First Card", "number": "12345", "color": 16711680 } ], "createdAt": "2023-01-01T10:00:00Z" } ``` ``` -------------------------------- ### GET Request for Map Information Source: https://github.com/sp-worlds/api-docs/wiki/Информация-о-карте This snippet shows the HTTP GET request to retrieve public card information from the spworlds.ru API. Ensure you have proper authentication headers included in your request. The response is a JSON object containing the user's balance and a webhook URL. ```http GET https://spworlds.ru/api/public/card ``` -------------------------------- ### Get Owner Account Details Source: https://context7.com/sp-worlds/api-docs/llms.txt Retrieves comprehensive information about the authenticated account owner, including roles, city data, and card details. ```bash curl -X GET "https://spworlds.ru/api/public/accounts/me" \ -H "Authorization: Bearer ${AUTH_KEY}" \ -H "Content-Type: application/json" ``` -------------------------------- ### GET /api/public/users/{DISCORD_ID} Source: https://github.com/sp-worlds/api-docs/wiki/Получение-ника-пользователя Retrieves the nickname and Minecraft UUID of a user based on their Discord ID. Authentication is required. ```APIDOC ## GET /api/public/users/{DISCORD_ID} ### Description Retrieves the nickname and Minecraft UUID of a user based on their Discord ID. Ensure you have proper authentication before making this request. ### Method GET ### Endpoint `https://spworlds.ru/api/public/users/DISCORD_ID` ### Parameters #### Path Parameters - **DISCORD_ID** (string) - Required - The Discord ID of the user. ### Request Example ``` GET https://spworlds.ru/api/public/users/123456789012345678 ``` ### Response #### Success Response (200) - **username** (string or null) - The user's nickname or null if they haven't logged into the server. - **uuid** (string or null) - The user's Minecraft UUID or null if they haven't logged into the server. This field may not be present for Bedrock servers. #### Response Example ```json { "username": "ExampleUser", "uuid": "a1b2c3d4-e5f6-7890-1234-567890abcdef" } ``` #### Response Example (No Login) ```json { "username": null, "uuid": null } ``` ``` -------------------------------- ### GET /api/public/users/{discordId} Source: https://context7.com/sp-worlds/api-docs/llms.txt Fetches the Minecraft username and UUID associated with a specific Discord ID. ```APIDOC ## GET /api/public/users/{discordId} ### Description Retrieves the player's Minecraft username and UUID using their Discord ID. ### Method GET ### Endpoint https://spworlds.ru/api/public/users/{discordId} ### Parameters #### Path Parameters - **discordId** (string) - Required - The Discord ID of the user ### Response #### Success Response (200) - **username** (string) - Minecraft username or null if not found - **uuid** (string) - Minecraft UUID or null if not found/Bedrock user #### Response Example { "username": "PlayerName", "uuid": "550e8400-e29b-41d4-a716-446655440000" } ``` -------------------------------- ### GET /api/public/accounts/{username}/cards Source: https://github.com/sp-worlds/api-docs/wiki/Получение-карт-игрока Retrieves a list of all cards associated with a specific player account identified by their username. ```APIDOC ## GET /api/public/accounts/{username}/cards ### Description Fetches a JSON array of cards belonging to the specified player account. Requires authentication. ### Method GET ### Endpoint https://spworlds.ru/api/public/accounts/{username}/cards ### Parameters #### Path Parameters - **username** (string) - Required - The username of the player whose cards are being requested. ### Request Example GET https://spworlds.ru/api/public/accounts/exampleUser/cards ### Response #### Success Response (200) - **name** (string) - The name of the card. - **number** (string) - The unique number of the card. #### Response Example [ { "name": "Standard Card", "number": "1234-5678-9012-3456" } ] ``` -------------------------------- ### Get User Information via Discord ID Source: https://github.com/sp-worlds/api-docs/wiki/Получение-ника-пользователя Retrieves the Minecraft username and UUID associated with a given Discord ID. The request requires a valid Discord ID and returns a JSON object containing the username and UUID, or null values if the user has not joined the server. ```http GET https://spworlds.ru/api/public/users/DISCORD_ID ``` -------------------------------- ### Get Player Username by Discord ID Source: https://context7.com/sp-worlds/api-docs/llms.txt Retrieves the Minecraft username and UUID for a user based on their Discord ID. Returns null values if the user is not found or lacks server access. ```bash DISCORD_ID="123456789012345678" curl -X GET "https://spworlds.ru/api/public/users/${DISCORD_ID}" \ -H "Authorization: Bearer ${AUTH_KEY}" \ -H "Content-Type: application/json" ``` -------------------------------- ### Authenticate API Requests Source: https://context7.com/sp-worlds/api-docs/llms.txt Demonstrates how to generate a Base64-encoded Bearer token using a card ID and token, and how to include it in the Authorization header for API requests. ```bash CARD_ID="your_card_id" CARD_TOKEN="your_card_token" AUTH_KEY=$(echo -n "${CARD_ID}:${CARD_TOKEN}" | base64) curl -X GET "https://spworlds.ru/api/public/card" \ -H "Authorization: Bearer ${AUTH_KEY}" \ -H "Content-Type: application/json" ``` -------------------------------- ### Retrieve Card Information Source: https://context7.com/sp-worlds/api-docs/llms.txt Fetches the current balance and webhook URL associated with the authenticated card. ```bash curl -X GET "https://spworlds.ru/api/public/card" \ -H "Authorization: Bearer ${AUTH_KEY}" \ -H "Content-Type: application/json" ``` -------------------------------- ### POST /webhook Source: https://github.com/sp-worlds/api-docs/wiki/Оплата-на-вашем-сайте Handles the webhook notification sent by the server upon successful payment completion. ```APIDOC ## POST [webhookUrl] ### Description Receives a notification when a payment is successfully completed. Must verify the `X-Body-Hash` header using HMAC SHA256 with the API token as the key. ### Method POST ### Parameters #### Request Body - **payer** (String) - Nickname of the player who paid. - **amount** (Number) - Total purchase amount. - **data** (String) - Custom data provided during request creation. ### Request Example { "payer": "PlayerName", "amount": 500, "data": "order_id_123" } ### Response #### Success Response (200) - No specific body required, acknowledge receipt. ``` -------------------------------- ### POST /api/public/payments Source: https://github.com/sp-worlds/api-docs/wiki/Оплата-на-вашем-сайте Creates a new payment request for AR currency. Returns a URL to redirect the user for payment completion. ```APIDOC ## POST https://spworlds.ru/api/public/payments ### Description Creates a transaction request for AR currency. The total amount must not exceed 10,000 AR. ### Method POST ### Endpoint https://spworlds.ru/api/public/payments ### Parameters #### Request Body - **items** (Array) - Required - List of transaction items. - **redirectUrl** (String) - Required - URL to redirect the user after payment. - **webhookUrl** (String) - Required - URL to receive payment success notifications (must be HTTPS on port 443). - **data** (String) - Optional - Custom metadata (max 100 characters). ### Request Example { "items": [{"name": "Sword", "count": 1, "price": 500}], "redirectUrl": "https://example.com/success", "webhookUrl": "https://example.com/api/webhook", "data": "order_id_123" } ### Response #### Success Response (200) - **url** (String) - Payment page URL. - **code** (String) - Transaction payment code. - **card** (String) - Recipient card name. #### Response Example { "url": "https://spworlds.ru/pay/123", "code": "ABC-123", "card": "MyShop" } ``` -------------------------------- ### Handle Payment Webhook with Signature Verification Source: https://context7.com/sp-worlds/api-docs/llms.txt Demonstrates how to securely process incoming payment webhooks. It verifies the X-Body-Hash header using HMAC-SHA256 with the card's API token to ensure request authenticity. ```python import hmac import hashlib import base64 from flask import Flask, request, jsonify app = Flask(__name__) CARD_TOKEN = "your_card_token" @app.route('/api/payment/webhook', methods=['POST']) def payment_webhook(): received_hash = request.headers.get('X-Body-Hash') if not received_hash: return jsonify({"error": "Missing signature"}), 401 body = request.get_data() computed_hash = base64.b64encode( hmac.new(CARD_TOKEN.encode(), body, hashlib.sha256).digest() ).decode() if not hmac.compare_digest(received_hash, computed_hash): return jsonify({"error": "Invalid signature"}), 401 data = request.json print(f"Получен платёж от {data['payer']} на сумму {data['amount']} АР") return jsonify({"status": "ok"}), 200 ``` -------------------------------- ### List Player Cards Source: https://context7.com/sp-worlds/api-docs/llms.txt Returns a list of all cards associated with a specific player identified by their username. ```bash USERNAME="PlayerName" curl -X GET "https://spworlds.ru/api/public/accounts/${USERNAME}/cards" \ -H "Authorization: Bearer ${AUTH_KEY}" \ -H "Content-Type: application/json" ``` -------------------------------- ### Create Payment Request via SP Worlds API Source: https://context7.com/sp-worlds/api-docs/llms.txt Initiates a new payment request by sending a POST request to the SP Worlds API. Requires an authorization bearer token and a JSON body containing items, redirect URLs, and optional metadata. ```bash curl -X POST "https://spworlds.ru/api/public/payments" \ -H "Authorization: Bearer ${AUTH_KEY}" \ -H "Content-Type: application/json" \ -d '{ "items": [ { "name": "VIP статус", "count": 1, "price": 500, "comment": "Премиум доступ на 30 дней" }, { "name": "Бонусные монеты", "count": 10, "price": 50 } ], "redirectUrl": "https://mysite.ru/payment/success", "webhookUrl": "https://mysite.ru/api/payment/webhook", "data": "order_12345_user_67890" }' ``` -------------------------------- ### POST /api/public/payments Source: https://context7.com/sp-worlds/api-docs/llms.txt Creates a payment request for in-game items or services. This endpoint allows users to initiate a payment process by providing details about the items being purchased. ```APIDOC ## POST /api/public/payments ### Description Creates a payment request for in-game items or services. This endpoint allows users to initiate a payment process by providing details about the items being purchased. ### Method POST ### Endpoint /api/public/payments ### Parameters #### Query Parameters None #### Request Body - **items** (array) - Required - An array of objects, where each object represents an item to be purchased. - **name** (string) - Required - The name of the item. - **count** (integer) - Required - The quantity of the item. - **price** (integer) - Required - The price of a single unit of the item. - **comment** (string) - Optional - A comment for the item. - **redirectUrl** (string) - Required - The URL to redirect the user to after a successful payment. - **webhookUrl** (string) - Required - The URL to send payment status notifications to. - **data** (string) - Optional - Additional data to be passed with the payment request, such as an order ID. ### Request Example ```json { "items": [ { "name": "VIP статус", "count": 1, "price": 500, "comment": "Премиум доступ на 30 дней" }, { "name": "Бонусные монеты", "count": 10, "price": 50 } ], "redirectUrl": "https://mysite.ru/payment/success", "webhookUrl": "https://mysite.ru/api/payment/webhook", "data": "order_12345_user_67890" } ``` ### Response #### Success Response (200) - **url** (string) - The URL to redirect the user to for payment. - **code** (string) - A unique code for the payment. - **card** (string) - The name of the merchant or card. #### Response Example ```json { "url": "https://spworlds.ru/pay/abc123xyz", "code": "abc123xyz", "card": "Магазин игрока" } ``` ``` -------------------------------- ### POST /api/public/transactions Source: https://github.com/sp-worlds/api-docs/wiki/Банковские-переводы Initiates a translation (transfer) from one card to another. Requires authentication. ```APIDOC ## POST /api/public/transactions ### Description Initiates a translation (transfer) of funds between cards. Authentication is required for this operation. ### Method POST ### Endpoint https://spworlds.ru/api/public/transactions ### Parameters #### Request Body - **receiver** (string) - Required - The recipient's card number. - **amount** (number) - Required - The amount of ARs (currency) to transfer. - **comment** (string) - Optional - A comment for the translation. ### Request Example ```json { "receiver": "RECIPIENT_CARD_NUMBER", "amount": 100.50, "comment": "Transfer for services" } ``` ### Response #### Success Response (200) - **balance** (number) - The updated balance of the sender's card after the transaction. #### Response Example ```json { "balance": 500.75 } ``` ``` -------------------------------- ### Update Card Webhook URL Source: https://context7.com/sp-worlds/api-docs/llms.txt Configures the destination URL for transaction notifications related to a specific card. This is a PUT request requiring authentication. ```bash curl -X PUT "https://spworlds.ru/api/public/card/webhook" \ -H "Authorization: Bearer ${AUTH_KEY}" \ -H "Content-Type: application/json" \ -d '{ "url": "https://mysite.ru/api/transactions/webhook" }' ``` -------------------------------- ### Execute Bank Transfer Source: https://context7.com/sp-worlds/api-docs/llms.txt Transfers a specified amount of currency to another card using its number. Returns the updated balance of the sender's card. ```bash curl -X POST "https://spworlds.ru/api/public/transactions" \ -H "Authorization: Bearer ${AUTH_KEY}" \ -H "Content-Type: application/json" \ -d '{ "receiver": "9876-5432-1098", "amount": 100, "comment": "Оплата за услуги" }' ``` -------------------------------- ### POST /api/public/transactions Source: https://context7.com/sp-worlds/api-docs/llms.txt Executes a bank transfer of AP currency from the authenticated card to a target card. ```APIDOC ## POST /api/public/transactions ### Description Transfers a specified amount of AP to another card by its number. ### Method POST ### Endpoint https://spworlds.ru/api/public/transactions ### Request Body - **receiver** (string) - Required - The card number of the recipient - **amount** (integer) - Required - Amount of AP to transfer - **comment** (string) - Optional - Transaction description ### Response #### Success Response (200) - **balance** (integer) - New balance after transaction #### Response Example { "balance": 916 } ``` -------------------------------- ### Payment Webhook Processing Source: https://context7.com/sp-worlds/api-docs/llms.txt Handles incoming payment status notifications from SP Worlds. This endpoint should verify the request signature and process the payment data. ```APIDOC ## Payment Webhook Processing ### Description Handles incoming payment status notifications from SP Worlds. This endpoint should verify the request signature and process the payment data. ### Method POST ### Endpoint /api/payment/webhook ### Parameters #### Headers - **X-Body-Hash** (string) - Required - The base64-encoded SHA256 HMAC hash of the request body, used for signature verification. #### Request Body - **payer** (string) - The username of the player who made the payment. - **amount** (integer) - The amount paid. - **data** (string) - Additional data passed with the payment request. ### Request Example ```json { "payer": "PlayerName", "amount": 1000, "data": "order_12345_user_67890" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the status of the webhook processing, typically 'ok'. #### Response Example ```json { "status": "ok" } ``` ### Security Verify the `X-Body-Hash` header using HMAC-SHA256 with your API token as the key. The computed hash should match the received hash. ``` -------------------------------- ### Handle Transaction Webhook with Signature Verification Source: https://context7.com/sp-worlds/api-docs/llms.txt Processes transaction notifications using Node.js. It captures the raw request body to verify the HMAC signature against the X-Body-Hash header before processing the transaction data. ```javascript const crypto = require('crypto'); const express = require('express'); const app = express(); const CARD_TOKEN = 'your_card_token'; app.use(express.json({ verify: (req, res, buf) => { req.rawBody = buf; } })); app.post('/api/transactions/webhook', (req, res) => { const receivedHash = req.headers['x-body-hash']; const computedHash = crypto .createHmac('sha256', CARD_TOKEN) .update(req.rawBody) .digest('base64'); if (!crypto.timingSafeEqual(Buffer.from(receivedHash), Buffer.from(computedHash))) { return res.status(401).json({ error: 'Invalid signature' }); } const transaction = req.body; console.log(`Транзакция ${transaction.id}: ${transaction.amount} АР от ${transaction.sender?.username}`); res.json({ status: 'ok' }); }); ``` -------------------------------- ### Transaction Webhook Processing Source: https://context7.com/sp-worlds/api-docs/llms.txt Handles incoming transaction notifications from SP Worlds. This endpoint should verify the request signature and process the transaction details. ```APIDOC ## Transaction Webhook Processing ### Description Handles incoming transaction notifications from SP Worlds. This endpoint should verify the request signature and process the transaction details. ### Method POST ### Endpoint /api/transactions/webhook ### Parameters #### Headers - **x-body-hash** (string) - Required - The base64-encoded SHA256 HMAC hash of the request body, used for signature verification. #### Request Body - **id** (string) - The transaction ID. - **amount** (integer) - The transaction amount. - **type** (string) - The type of transaction ('incoming' or 'outgoing'). - **sender** (object) - Information about the sender. - **username** (string) - The sender's username. - **number** (string) - The sender's card number. - **receiver** (object) - Information about the receiver. - **username** (string) - The receiver's username. - **number** (string) - The receiver's card number. - **comment** (string) - A comment for the transaction. - **createdAt** (string) - The timestamp when the transaction occurred. ### Request Example ```json { "id": "tx_789012", "amount": 250, "type": "incoming", "sender": { "username": "OtherPlayer", "number": "1111-2222-3333" }, "receiver": { "username": "MyPlayer", "number": "1234-5678-9012" }, "comment": "За строительство", "createdAt": "2024-01-20T15:45:00Z" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the status of the webhook processing, typically 'ok'. #### Response Example ```json { "status": "ok" } ``` ### Security Verify the `x-body-hash` header using HMAC-SHA256 with your API token as the key. The computed hash should match the received hash. ``` -------------------------------- ### Update Card Webhook Source: https://github.com/sp-worlds/api-docs/wiki/Изменение-вебхука-карты This endpoint allows you to set or update the webhook URL for a specific card. All new transactions associated with the card will be sent to this URL via POST requests. ```APIDOC ## PUT /api/public/card/webhook ### Description Sets or updates the webhook URL for a card. Transactions related to the card will be sent to this URL via POST requests. ### Method PUT ### Endpoint /api/public/card/webhook ### Parameters #### Request Body - **url** (string) - Required - The URL where transaction notifications will be sent. ### Request Example ```json { "url": "https://example.ru/webhook" } ``` ### Response #### Success Response (200) - **id** (string) - The unique ID of the card. - **webhook** (string) - The updated webhook URL for the card. #### Response Example ```json { "id": "card_123abc", "webhook": "https://example.ru/webhook" } ``` ``` -------------------------------- ### Update card webhook via API Source: https://github.com/sp-worlds/api-docs/wiki/Изменение-вебхука-карты Updates the webhook URL for a specific card using a PUT request. The request requires a JSON body containing the new URL, and the response returns the card ID and the updated webhook. ```http PUT https://spworlds.ru/api/public/card/webhook Content-Type: application/json { "url": "https://example.ru/webhook" } ``` -------------------------------- ### Transaction Data Notification Source: https://github.com/sp-worlds/api-docs/wiki/Изменение-вебхука-карты When a new transaction occurs for your card, our server sends a POST request to your specified webhook URL. This section details the structure of the transaction data payload and important security considerations. ```APIDOC ## Transaction Data Notification (POST) ### Description Receives details about new transactions associated with your card. The data is sent via a POST request to your configured webhook URL. ### Method POST ### Endpoint [Your configured webhook URL] ### Parameters #### Request Body - **id** (string) - Required - The unique ID of the transaction. - **amount** (number) - Required - The transaction amount. - **type** (string) - Required - The type of transaction. - **sender.username** (string or undefined) - Optional - The username of the sender, if available. - **sender.number** (string or undefined) - Optional - The card number of the sender, if available. - **receiver.username** (string or undefined) - Optional - The username of the receiver, if available. - **receiver.number** (string or undefined) - Optional - The card number of the receiver, if available. - **comment** (string) - Required - A comment associated with the transaction. - **createdAt** (string) - Required - The date and time the transaction was created. ### Request Example ```json { "id": "txn_456def", "amount": 100.50, "type": "transfer", "sender": { "username": "john_doe", "number": "**** **** **** 1111" }, "receiver": { "username": "jane_smith", "number": "**** **** **** 2222" }, "comment": "Payment for services", "createdAt": "2023-10-27T10:00:00Z" } ``` ### Security **Important:** Verify the authenticity of the incoming request. The `X-Body-Hash` header contains a base64 encoded SHA256 HMAC hash of the request body, using your card's API token as the key. Generate your own hash using the received body and your API token, and compare it with the `X-Body-Hash` header before processing the transaction data. ``` -------------------------------- ### Transaction notification payload structure Source: https://github.com/sp-worlds/api-docs/wiki/Изменение-вебхука-карты Describes the JSON structure of the POST request sent to your webhook when a new transaction occurs. The payload includes transaction details such as ID, amount, sender/receiver information, and timestamps. ```json { "id": "string", "amount": 0, "type": "string", "sender": { "username": "string", "number": "string" }, "receiver": { "username": "string", "number": "string" }, "comment": "string", "createdAt": "string" } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.