ডেভেলপার API ও ইন্টিগ্রেশন নির্দেশিকা Developer API & Integration Guide
আপনার কাস্টম ওয়েব অ্যাপ্লিকেশন বা উকমার্স (WooCommerce) স্টোরকে সরাসরি StockWhisk-এর সাথে যুক্ত করুন। লাইভ স্টক ব্যালেন্স সিঙ্ক করুন, ডাটাবেস রো-লকিং ব্যবহারের মাধ্যমে ফ্ল্যাশ সেলে অতিরিক্ত অর্ডার (ওভারসেলিং) রোধ করুন এবং স্বয়ংক্রিয়ভাবে রিটেল সেলস ইনভয়েস তৈরি করুন। Connect your custom web application or WooCommerce store directly to StockWhisk. Synchronize live stock balances, prevent flash-sale overselling using database row locks, and automate retail sales invoicing.
৫-মিনিটের কুইকস্টার্ট গাইড 5-Minute Quickstart Guide
যেকোনো ওয়েবসাইটকে ৫ মিনিটের মধ্যে যুক্ত করতে নিচের ৩টি ধাপ অনুসরণ করুন: Follow these 3 steps to connect any website in under 5 minutes:
StockWhisk-এ ওয়েবসাইট চ্যানেল তৈরি করুন Create Website Channel in StockWhisk
StockWhisk ড্যাশবোর্ডে লগইন করে ইন্টিগ্রেশন > ওয়েবসাইট ও ই-কমার্স (/app/integrations/websites)-এ গিয়ে "কানেক্ট ওয়েবসাইট"-এ ক্লিক করুন। এরপর "কাস্টম ওয়েবসাইট (API ও ওয়েব হুক প্রোভাইডার)" নির্বাচন করুন। Log in to StockWhisk, navigate to Integrations > Website & E-Commerce (/app/integrations/websites), and click "Connect Website". Choose "Custom Website (API & Webhook Provider)".
আপনার এন্ডপয়েন্ট URL ও সিক্রেট কি কপি করুন Copy Your Endpoint URL & Secret Key
StockWhisk তাৎক্ষণিকভাবে আপনার ডেডিকেটেড এন্ডপয়েন্ট তৈরি করবে:
StockWhisk will instantly provision your dedicated endpoint:
Webhook URL: https://stockwhisk.com/api/integrations/webhooks/{UUID}/
Secret Key: whsec_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
আপনার কোড বা উকমার্সে ওয়েবহুক কনফিগার করুন Configure Webhook in your Code or WooCommerce
আপনার ওয়েব অ্যাপের এনভায়রনমেন্ট ভেরিয়েবল বা উকমার্স ওয়েবহুক সেটিংসে এই URL এবং Secret Key যুক্ত করুন। এরপর একটি টেস্ট অর্ডার পাঠিয়ে যাচাই করুন! Paste the URL and Secret Key into your web app environment variables or WooCommerce webhook settings. Send a test order or execute a live stock check!
অথেনটিকেশন ও নিরাপত্তা Authentication & Security
StockWhisk ওয়েবহুক এন্ডপয়েন্টে পাঠানো প্রতিটি রিকোয়েস্টে আপনার সিক্রেট কি (Secret Key) দ্বারা অথেনটিকেশন নিশ্চিত করতে হবে। আপনি নিচের যেকোনো একটি HTTP হেডার ব্যবহার করে কি পাঠাতে পারেন: Every request made to your StockWhisk Webhook endpoint requires authentication via your secret key. You can pass the key using either of the following HTTP headers:
# Option 1: Dedicated Webhook Header (Recommended) X-Webhook-Secret: whsec_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # Option 2: Standard Bearer Token Authorization Authorization: Bearer whsec_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
রিয়েল-টাইম Available-to-Sell (ATS) স্টক যাচাই Real-Time Available-to-Sell (ATS) Stock Check
পণ্য প্রদর্শন বা চেকআউটের সময় লাইভ স্টক ব্যালেন্স পেতে এই এন্ডপয়েন্টটি ব্যবহার করুন। এটি স্বয়ংক্রিয়ভাবে হিসাব করে:
Use this endpoint during product viewing or checkout steps to retrieve live availability. It calculates:
available_stock = current_on_hand - active_reservations
| কুয়েরি প্যারামিটারQuery Parameter | টাইপType | আবশ্যকRequired | বিবরণDescription |
|---|---|---|---|
sku |
string |
Optional* | পণ্যের SKU (যেমন GDO-273540)। খালি রাখলে দোকানের সক্রিয় আইটেম রিটার্ন করবে।Product SKU (e.g. GDO-273540). If omitted, returns active items for the shop. |
barcode |
string |
Optional | আপনার ক্যাটালগে বারকোড দিয়ে সার্চ করতে চাইলে বারকোড স্ট্রিং।Barcode string if your catalog queries via barcode. |
curl -X GET "https://stockwhisk.com/api/integrations/webhooks/YOUR_ENDPOINT_UUID/?sku=GDO-273540" \ -H "X-Webhook-Secret: whsec_YOUR_SECRET_TOKEN"
// Next.js Route Handler / Node.js
export async function checkProductStock(sku) {
const endpoint = process.env.STOCKWHISK_WEBHOOK_URL;
const secret = process.env.STOCKWHISK_SECRET_TOKEN;
const res = await fetch(`${endpoint}?sku=${encodeURIComponent(sku)}`, {
method: "GET",
headers: {
"X-Webhook-Secret": secret,
},
cache: "no-store", // Ensure real-time query
});
if (!res.ok) throw new Error("Stock query failed");
const data = await res.json();
// Returns: { id, name, sku, selling_price, on_hand, reserved, available, in_stock }
return data;
}
// PHP / Laravel Http Client
use Illuminate\Support\Facades\Http;
function getStockWhiskAvailability($sku) {
$response = Http::withHeaders([
'X-Webhook-Secret' => config('services.stockwhisk.secret'),
])->get(config('services.stockwhisk.webhook_url'), [
'sku' => $sku,
]);
if ($response->successful()) {
$item = $response->json();
return $item['available'] > 0;
}
return false;
}
# Python (Requests / FastAPI / Django)
import requests
def check_stock(sku: str) -> dict:
url = "https://stockwhisk.com/api/integrations/webhooks/YOUR_ENDPOINT_UUID/"
headers = {"X-Webhook-Secret": "whsec_YOUR_SECRET_TOKEN"}
response = requests.get(url, params={"sku": sku}, headers=headers, timeout=5)
response.raise_for_status()
return response.json()
চূড়ান্ত API রেসপন্স (JSON রেজাল্ট): Final API Result (JSON Response):
{
"id": 81,
"name": "Anker 20W Fast Charger",
"sku": "GDO-273540",
"barcode": "",
"selling_price": 1450.00,
"on_hand": 15.0,
"reserved": 3.0,
"available": 12.0,
"in_stock": true
}
অর্ডার ইনজেশন ওয়েবহুক Order Ingestion Webhook
গ্রাহক যখন আপনার ওয়েবসাইটে অর্ডার প্লেস করবেন, তখন অর্ডারের বিস্তারিত তথ্য এই এন্ডপয়েন্টে POST করুন। StockWhisk স্বয়ংক্রিয়ভাবে অ্যাটমিক স্টক রিজার্ভেশন, ডুপ্লিকেট অর্ডার ফিল্টারিং এবং রিটেল সেলস ইনভয়েস তৈরি সম্পন্ন করবে। When a customer places an order on your website, send the order details to this endpoint. StockWhisk will automatically execute atomic stock reservation, deduplicate requests, and create the retail sale invoice.
?sync=true যুক্ত করলে StockWhisk তাৎক্ষণিকভাবে অর্ডার প্রসেস করে রেসপন্সে invoice_no এবং sale_id রিটার্ন করে। ?sync=true ছাড়া অর্ডারগুলো ব্যাকগ্রাউন্ডে কিউতে জমা হয়ে প্রসেস হয়।
Adding ?sync=true causes StockWhisk to process the order immediately and respond with the created invoice_no and sale_id. Without ?sync=true, orders are queued for high-throughput asynchronous processing.
{
"event": "order.created",
"id": "WEB-ORD-9005",
"order_number": "9005",
"total": 1450.00,
"customer": {
"name": "Mahmudul Hasan",
"phone": "01819998877",
"address": "House 12, Road 4, Banani, Dhaka"
},
"items": [
{
"sku": "GDO-273540",
"quantity": 1,
"unit_price": 1450.00
}
]
}
curl -X POST "https://stockwhisk.com/api/integrations/webhooks/YOUR_ENDPOINT_UUID/?sync=true" \
-H "X-Webhook-Secret: whsec_YOUR_SECRET_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"event": "order.created",
"id": "WEB-ORD-9005",
"order_number": "9005",
"total": 1450.00,
"customer": {
"name": "Mahmudul Hasan",
"phone": "01819998877",
"address": "House 12, Road 4, Banani, Dhaka"
},
"items": [
{
"sku": "GDO-273540",
"quantity": 1,
"unit_price": 1450.00
}
]
}'
// Next.js / Node.js Checkout Completion Handler
export async function pushOrderToStockWhisk(order) {
const endpoint = `${process.env.STOCKWHISK_WEBHOOK_URL}?sync=true`;
const secret = process.env.STOCKWHISK_SECRET_TOKEN;
const payload = {
event: "order.created",
id: String(order.id),
order_number: String(order.orderNumber),
total: Number(order.totalAmount),
customer: {
name: order.customerName,
phone: order.customerPhone,
address: order.shippingAddress,
},
items: order.lineItems.map(item => ({
sku: item.sku,
quantity: Number(item.qty),
unit_price: Number(item.price),
})),
};
const res = await fetch(endpoint, {
method: "POST",
headers: {
"X-Webhook-Secret": secret,
"Content-Type": "application/json",
},
body: JSON.stringify(payload),
});
const data = await res.json();
if (!res.ok) {
throw new Error(data.error || "Order placement failed");
}
// data = { status: "success", invoice_no: "INV-000005", sale_id: 215, ... }
return data;
}
// Laravel Controller or Order Observer
use Illuminate\Support\Facades\Http;
public function handleOrderPlaced($order) {
$webhookUrl = config('services.stockwhisk.url') . '?sync=true';
$secret = config('services.stockwhisk.secret');
$response = Http::withHeaders([
'X-Webhook-Secret' => $secret,
'Content-Type' => 'application/json',
])->post($webhookUrl, [
'event' => 'order.created',
'id' => (string) $order->id,
'order_number' => $order->order_number,
'total' => (float) $order->total,
'customer' => [
'name' => $order->shipping_name,
'phone' => $order->billing_phone,
'address' => $order->shipping_address,
],
'items' => collect($order->items)->map(fn($item) => [
'sku' => $item->sku,
'quantity' => $item->quantity,
'unit_price' => $item->price,
])->toArray(),
]);
if ($response->successful()) {
$result = $response->json();
// Save StockWhisk invoice number to local order record
$order->update(['stockwhisk_invoice' => $result['invoice_no']]);
}
}
চূড়ান্ত API রেসপন্স (ইনভয়েস তৈরি রেজাল্ট): Final API Result (JSON Invoicing Response):
{
"status": "success",
"event_id": 5,
"external_order_id": "WEB-ORD-9005",
"invoice_no": "INV-000006",
"sale_id": 216,
"total_amount": 1450.00,
"message": "Order successfully processed and sale created."
}
অর্ডার বাতিল ও স্বয়ংক্রিয় স্টক রিলিজ Order Cancellation & Automatic Stock Release
আপনার ওয়েবসাইট বা ড্যাশবোর্ডে কোনো অর্ডার বাতিল হলে StockWhisk স্বয়ংক্রিয়ভাবে রিজার্ভ করা ইনভেন্টরি অবমুক্ত করে এবং সংশ্লিষ্ট ইনভয়েসটি বাতিল করে দেয়। When an order is cancelled on your website or dashboard, StockWhisk automatically releases the reserved inventory and marks the associated invoice cancelled.
স্টক রিলিজ যেভাবে কাজ করে How Stock Release Works
-
ওয়েবহুক ইভেন্ট:Webhook Event:
আপনার ওয়েবসাইট যদি ওয়েবহুকে
order.cancelledইভেন্ট পাঠায়, তবে StockWhisk মূল রিজার্ভেশন চিহ্নিত করে তা অবমুক্ত করে। If your website sends anorder.cancelledevent to the webhook URL, StockWhisk instantly identifies the original reservation and releases it. -
API ট্রিগার:API Trigger:
বিকল্প হিসেবে মার্চেন্ট ক্রেডেনশিয়াল সহ
POST /api/integrations/orders/{id}/cancel/কল করে স্টক রিলিজ করা যায়। Alternatively, callPOST /api/integrations/orders/{id}/cancel/with merchant credentials to release stock programmatically. -
উপলব্ধ স্টক পুনরুদ্ধার:Available Stock Restoration:
কোনো ম্যানুয়াল লেজার সমন্বয় ছাড়াই
available_stockতৎক্ষণাৎ পূর্বের মূল মানে ফিরে আসে।available_stockimmediately increases back to its original pre-order value without manual ledger adjustments.
ওয়ার্ডপ্রেস ও উকমার্স ইন্টিগ্রেশন নির্দেশিকা WordPress & WooCommerce Integration Guide
আপনার ওয়েবসাইট যদি ওয়ার্ডপ্রেস এবং উকমার্স দিয়ে তৈরি হয়ে থাকে, তবে StockWhisk কানেক্ট করার জন্য দুটি সহজ পদ্ধতি রয়েছে: If your website is built on WordPress with WooCommerce, you have two flexible methods to connect StockWhisk:
নেটিভ উকমার্স ওয়েবহুকNative WooCommerce Webhooks
উকমার্সে বিল্ট-ইন ওয়েবহুক প্রেরণের ব্যবস্থা রয়েছে। কোনো PHP কোড লেখা ছাড়াই মাত্র ২ মিনিটে এটি কানেক্ট করা সম্ভব: WooCommerce has built-in webhook dispatching. You can connect it in 2 minutes without writing a single line of PHP:
- আপনার ওয়ার্ডপ্রেস অ্যাডমিন ড্যাশবোর্ডে লগইন করুন। Log in to your WordPress Admin dashboard.
- WooCommerce > Settings > Advanced > Webhooks-এ যান। Go to WooCommerce > Settings > Advanced > Webhooks.
- "Add webhook" বাটনে ক্লিক করুন। Click the "Add webhook" button.
-
নিচের ফিল্ডগুলো সঠিকভাবে পূরণ করুন:
Fill in the fields exactly as follows:
- Name:
StockWhisk Order Sync - Status: Select
Active - Topic: Select
Order created - Delivery URL: আপনার StockWhisk ওয়েবহুক URL পেস্ট করুনPaste your StockWhisk Webhook URL (
https://stockwhisk.com/api/integrations/webhooks/{UUID}/) - Secret: আপনার Secret Key পেস্ট করুনPaste your StockWhisk Secret Key (
whsec_xxxxxxxx) - API Version:
WP REST API Integration v3
- Name:
- "Save Webhook" বাটনে ক্লিক করুন। Click "Save Webhook".
কার্টে লাইভ স্টক ভ্যালিডেশন সহ কাস্টম ওয়ার্ডপ্রেস হুকCustom WordPress Hook with Live Cart Stock Validation
উন্নত উকমার্স স্টোরের জন্য এই কোড স্নিপেটটি আপনার চাইল্ড থিমের functions.php অথবা কাস্টম প্লাগইনে পেস্ট করুন। এটি পেমেন্টের পূর্বেই রিয়েল-টাইম স্টক ভ্যালিডেশন করে এবং অর্ডার নিশ্চিত হওয়ার সাথে সাথে তাৎক্ষণিক StockWhisk-এ পুশ করে:
For advanced WooCommerce stores, paste this snippet into your child theme's functions.php or a custom plugin. It checks live StockWhisk inventory before payment and sends the order immediately upon confirmation:
<?php
/**
* StockWhisk WooCommerce Integration Snippet
* Paste into your child theme's functions.php
*/
define('STOCKWHISK_WEBHOOK_URL', 'https://stockwhisk.com/api/integrations/webhooks/YOUR_ENDPOINT_UUID/?sync=true');
define('STOCKWHISK_SECRET_KEY', 'whsec_YOUR_SECRET_TOKEN');
// 1. Verify StockWhisk live inventory during checkout submission
add_action('woocommerce_check_cart_items', 'stockwhisk_verify_live_stock');
function stockwhisk_verify_live_stock() {
if (is_cart() || is_checkout()) {
foreach (WC()->cart->get_cart() as $cart_item) {
$product = $cart_item['data'];
$sku = $product->get_sku();
if (!$sku) continue;
$qty_needed = $cart_item['quantity'];
// Query StockWhisk live available stock
$url = add_query_arg('sku', $sku, strtok(STOCKWHISK_WEBHOOK_URL, '?'));
$response = wp_remote_get($url, [
'headers' => ['X-Webhook-Secret' => STOCKWHISK_SECRET_KEY],
'timeout' => 4,
]);
if (!is_wp_error($response) && wp_remote_retrieve_response_code($response) === 200) {
$stock_data = json_decode(wp_remote_retrieve_body($response), true);
if (isset($stock_data['available']) && $stock_data['available'] < $qty_needed) {
wc_add_notice(sprintf(
__('দুঃখিত! "%s" পণ্যটির পর্যাপ্ত স্টক নেই। স্টকে রয়েছে মাত্র %d টি।', 'woocommerce'),
$product->get_name(),
$stock_data['available']
), 'error');
}
}
}
}
}
// 2. Transmit confirmed order to StockWhisk
add_action('woocommerce_checkout_order_processed', 'stockwhisk_push_order_on_checkout', 10, 3);
function stockwhisk_push_order_on_checkout($order_id, $posted_data, $order) {
$items = [];
foreach ($order->get_items() as $item) {
$product = $item->get_product();
$items[] = [
'sku' => $product ? $product->get_sku() : '',
'quantity' => $item->get_quantity(),
'unit_price' => (float) $order->get_item_subtotal($item, false),
];
}
$payload = [
'event' => 'order.created',
'id' => (string) $order_id,
'order_number' => (string) $order->get_order_number(),
'total' => (float) $order->get_total(),
'customer' => [
'name' => $order->get_formatted_billing_full_name(),
'phone' => $order->get_billing_phone(),
'address' => $order->get_shipping_address_1() . ', ' . $order->get_shipping_city(),
],
'items' => $items,
];
$response = wp_remote_post(STOCKWHISK_WEBHOOK_URL, [
'headers' => [
'X-Webhook-Secret' => STOCKWHISK_SECRET_KEY,
'Content-Type' => 'application/json',
],
'body' => wp_json_encode($payload),
'timeout' => 6,
]);
if (!is_wp_error($response)) {
$body = json_decode(wp_remote_retrieve_body($response), true);
if (!empty($body['invoice_no'])) {
$order->update_meta_data('_stockwhisk_invoice_no', $body['invoice_no']);
$order->add_order_note('StockWhisk Retail Invoice Created: ' . $body['invoice_no']);
$order->save();
}
}
}
অ্যাটমিক কনকারেন্সি ও অ্যান্টি-ওভারসেল ইঞ্জিন Atomic Concurrency & Anti-Oversell Engine
কেন StockWhisk ফ্ল্যাশ সেলে ইনভেন্টরি বিচ্যুতির বিরুদ্ধে গাণিতিক নিশ্চয়তা প্রদান করে: Why StockWhisk provides a mathematical guarantee against flash-sale inventory corruption:
রো-লেভেল ডাটাবেস লক (Row-Level Locks) Row-Level Database Locks
যখন কোনো অর্ডার StockWhisk-এ পৌঁছায়, এটি Product.objects.select_for_update() ব্যবহার করে একটি transaction.atomic() ব্লকের ভেতরে কার্যকর হয়। সমান্তরাল ডাটাবেস কুয়েরিগুলো একটি কঠোর সারিতে অপেক্ষা করে।
When an order request reaches StockWhisk, it executes inside a transaction.atomic() block using Product.objects.select_for_update(). Parallel database queries wait in a strict queue.
শূন্য রেস কন্ডিশন (Zero Race Conditions) Zero Race Conditions
যদি স্টক থাকে ১ এবং দুজন ব্যবহারকারী একসাথে অর্ডার কনফার্ম করেন: ট্রানজ্যাকশন A রো লক করে, স্টক = ১ যাচাই করে স্টক কমায় এবং কমিট করে। এরপর ট্রানজ্যাকশন B স্টক = ০ দেখতে পায় এবং স্বয়ংক্রিয়ভাবে HTTP 409 Conflict সহ বাতিল হয়। If stock is 1 and two users submit payment simultaneously: Transaction A locks the row, verifies availability = 1, deducts stock, and commits. Transaction B then reads availability = 0 and is safely rejected with HTTP 409 Conflict.
লাইভ API সিমুলেটর Live API Simulator
সরাসরি আপনার ব্রাউজারের ভেতর থেকেই টেস্ট করুন। আপনার এন্ডপয়েন্ট URL ও সিক্রেট কি দিয়ে লাইভ API কল এক্সিকিউট করুন: Test your provisioned endpoint right here inside the browser. Enter your Endpoint URL and Secret Key, and execute live API calls:
{
"status": "success",
"event_id": 5,
"external_order_id": "WEB-ORD-9005",
"invoice_no": "INV-000006",
"sale_id": 216,
"total_amount": 1450.00,
"message": "Order successfully processed and sale created."
}
এরর কোড ও সাধারণ জিজ্ঞাসা (FAQ) Error Codes & Troubleshooting
স্ট্যান্ডার্ড HTTP স্ট্যাটাস কোড এবং সমাধানের উপায়: Standard HTTP status codes and resolution steps:
| স্ট্যাটাস কোডStatus Code | এরর মেসেজError Message | সমাধানের নির্দেশিকাResolution |
|---|---|---|
| 401 Unauthorized | Invalid or missing secret key |
হেডারে পাঠানো X-Webhook-Secret টোকেনটি ড্যাশবোর্ডের টোকেনের সাথে মিলিয়ে নিন।Verify the X-Webhook-Secret header matches your dashboard token. |
| 409 Conflict | Insufficient available stock |
অনুমোদিত অর্ডার বা পেন্ডিং রিজার্ভেশনের কারণে পণ্যটির স্টক ০ হয়ে গেছে।The requested item has 0 available units due to other confirmed orders or holds. |
| 200 Deduplicated | Event already received and processed |
স্বাভাবিক আচরণ: পুনঃপ্রেরিত অর্ডারের ক্ষেত্রে StockWhisk ডুপ্লিকেট ইনভয়েস তৈরি বন্ধ করেছে।Normal behavior: StockWhisk prevented duplicate invoice generation for a retried order. |
| 422 Unprocessable | Product SKU not found |
যাচাই করুন যে SKU-টি StockWhisk-এ রয়েছে এবং চ্যানেলটির সাথে সঠিকভাবে ম্যাপ করা আছে।Check that the SKU exists in StockWhisk and is mapped to the external channel. |