E‑TALKdocumentation
IKỌBỌ Marketplacedocumentation
Home

Legacy integration reference. This retained guide describes an earlier integration. Its examples are preserved for reference.

Blockchain Integration API

Secure WooCommerce order recording on Polygon

Introduction

This API enables direct blockchain transaction recording for WooCommerce orders through MetaMask integration, eliminating the need for third-party RPC providers.

Base URL: https://yourdomain.com/wp-json/wc-blockchain/v1/

Authentication

All API requests require:

  • X-WP-Nonce header (WordPress REST API nonce)
  • User with edit_shop_orders capability

API Endpoints

GET /order/{order_id}

Retrieves order details for blockchain transaction processing.

Parameters

Parameter Type Required Description
order_id integer Yes WooCommerce order ID

Response

{
  "success": true,
  "data": {
    "orderId": 123,
    "customerWallet": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
    "productDetails": "Premium Widget (Qty: 2)",
    "totalPrice": "54.53"
  }
}
POST /save-tx

Records a completed blockchain transaction and triggers notifications.

Request

{
  "order_id": 123,
  "tx_hash": "0x5f3759df00f15d07217b65b5a3a4f0c1b8278d97a3c9e4e8b..."
}

Response

{
  "success": true,
  "message": "Transaction recorded",
  "data": {
    "order_id": 123,
    "tx_hash": "0x5f3759df...",
    "tx_link": "https://amoy.polygonscan.com/tx/0x5f3759df..."
  }
}

Webhook

Optional event triggered on successful transaction recording:

// Example webhook payload
{
  "event": "transaction_recorded",
  "data": {
    "order_id": 123,
    "tx_hash": "0x5f3759df...",
    "timestamp": "2024-03-30T12:00:00Z",
    "amount": "54.53"
  }
}

Example Implementation

// 1. Fetch order data
const response = await fetch('/wp-json/wc-blockchain/v1/order/123', {
  headers: {
    'X-WP-Nonce': '<?php echo wp_create_nonce("wp_rest"); ?>'
  }
});

// 2. After MetaMask transaction
const saveResponse = await fetch('/wp-json/wc-blockchain/v1/save-tx', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-WP-Nonce': '<?php echo wp_create_nonce("wp_rest"); ?>'
  },
  body: JSON.stringify({
    order_id: 123,
    tx_hash: txHash
  })
});

Error Reference

Code Type Resolution
403 invalid_nonce Refresh nonce value
404 order_not_found Verify order ID
409 tx_exists Transaction already recorded
AI