# Send a signed test notification to your local endpoint
RECUSTOMER_WEBHOOK_SECRET='your_webhook_secret'
BODY=$(cat <<'JSON'
{
"order_number": "string",
"shipping_address": {
"phone_number": "09012345678"
},
"tracking_number": "string",
"estimated_delivery_date": "2026-01-15",
"actual_delivery_date": "2024-01-15",
"actual_delivery_datetime": "2024-01-15T10:00:00+09:00",
"latest_delivery_status": "荷物受付け",
"delivery_company": "yamato",
"logistics_centers": [
{
"center": {
"center_name": "string",
"updated_at": "2024-01-15T10:00:00+09:00",
"status": "string"
}
}
]
}
JSON
)
TIMESTAMP=$(date +%s)
SIGNATURE=$(printf '%s.%s' "$TIMESTAMP" "$BODY" | openssl dgst -sha256 -hmac "$RECUSTOMER_WEBHOOK_SECRET" | sed 's/^.* //')
curl -X POST 'http://localhost:3000/your_shipping_endpoint' \
-H "X-Recustomer-Signature-256-V2: $SIGNATURE" \
-H "X-Recustomer-Signature-256-V2-Timestamp-Epoch: $TIMESTAMP" \
-H 'X-Recustomer-Sender-Id: 1bad6b8cf97131fceab8543e81f7757195fbb1d36b376ee994ad1cf17699c464' \
-H 'X-Recustomer-Event-Id: evt_0123456789abcdef0123456789abcdef' \
-H 'X-Recustomer-Event-Occurred-At: 2026-01-15T01:30:00.123456+00:00' \
-H 'Content-Type: application/json' \
--data-binary "$BODY"
// npm install express
import crypto from 'node:crypto';
import express from 'express';
const secret = process.env.RECUSTOMER_WEBHOOK_SECRET;
if (!secret) throw new Error('RECUSTOMER_WEBHOOK_SECRET is not set');
// Compare in constant time so the response time does not reveal the expected value
const safeEqual = (a, b) => {
const x = Buffer.from(a);
const y = Buffer.from(b);
return x.length === y.length && crypto.timingSafeEqual(x, y);
};
const app = express();
// Verify the signature against the raw body, before parsing it as JSON
app.post(
"/your_shipping_endpoint",
express.raw({ type: 'application/json' }),
(req, res) => {
const timestamp = req.get("X-Recustomer-Signature-256-V2-Timestamp-Epoch") ?? '';
const age = Math.abs(Date.now() / 1000 - Number(timestamp));
const expected = crypto
.createHmac('sha256', secret)
.update(`${timestamp}.`)
.update(req.body)
.digest('hex');
if (
!(age <= 300) ||
!safeEqual(req.get("X-Recustomer-Signature-256-V2") ?? '', expected)
) {
return res.sendStatus(401);
}
const event = JSON.parse(req.body.toString('utf8'));
console.log(event);
res.sendStatus(200);
},
);
app.listen(3000);
# pip install flask
import hashlib
import hmac
import os
import time
from flask import Flask, jsonify, request
SECRET = os.environ.get("RECUSTOMER_WEBHOOK_SECRET", "")
if not SECRET:
raise RuntimeError("RECUSTOMER_WEBHOOK_SECRET is not set")
app = Flask(__name__)
@app.route("/your_shipping_endpoint", methods=["POST"])
def handle():
# Verify the signature against the raw body, before parsing it as JSON
body = request.get_data()
timestamp = request.headers.get("X-Recustomer-Signature-256-V2-Timestamp-Epoch", "")
# Unix seconds. Reject anything that is not a short run of digits before converting it
if not (timestamp.isdecimal() and len(timestamp) <= 12):
return "", 401
if abs(time.time() - int(timestamp)) > 300:
return "", 401
expected = hmac.new(
SECRET.encode(), timestamp.encode() + b"." + body, hashlib.sha256
).hexdigest()
received = request.headers.get("X-Recustomer-Signature-256-V2", "")
if not hmac.compare_digest(received.encode(), expected.encode()):
return "", 401
event = request.get_json()
print(event)
return "", 200
if __name__ == "__main__":
app.run(port=3000)
<?php
// Run: php -S localhost:3000 handler.php (POST /your_shipping_endpoint)
$secret = getenv('RECUSTOMER_WEBHOOK_SECRET');
if ($secret === false || $secret === '') {
http_response_code(500);
exit('RECUSTOMER_WEBHOOK_SECRET is not set');
}
// Verify the signature against the raw body, before parsing it as JSON
$body = file_get_contents('php://input');
$headers = [];
foreach (getallheaders() as $name => $value) {
$headers[str_replace('_', '-', strtolower($name))] = $value;
}
$timestamp = $headers['x-recustomer-signature-256-v2-timestamp-epoch'] ?? '';
if (!ctype_digit($timestamp) || abs(time() - (int) $timestamp) > 300) {
http_response_code(401);
exit;
}
$expected = hash_hmac('sha256', $timestamp . '.' . $body, $secret);
if (!hash_equals($expected, $headers['x-recustomer-signature-256-v2'] ?? '')) {
http_response_code(401);
exit;
}
$event = json_decode($body, true);
http_response_code(200);
package main
import (
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
"encoding/json"
"io"
"log"
"net/http"
"os"
"strconv"
"time"
)
func main() {
secret := os.Getenv("RECUSTOMER_WEBHOOK_SECRET")
if secret == "" {
log.Fatal("RECUSTOMER_WEBHOOK_SECRET is not set")
}
http.HandleFunc("POST /your_shipping_endpoint", func(w http.ResponseWriter, r *http.Request) {
// Verify the signature against the raw body, before parsing it as JSON
body, err := io.ReadAll(r.Body)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
timestamp := r.Header.Get("X-Recustomer-Signature-256-V2-Timestamp-Epoch")
sent, err := strconv.ParseInt(timestamp, 10, 64)
age := time.Now().Unix() - sent
if err != nil || age > 300 || age < -300 {
w.WriteHeader(http.StatusUnauthorized)
return
}
mac := hmac.New(sha256.New, []byte(secret))
mac.Write([]byte(timestamp + "."))
mac.Write(body)
expected := hex.EncodeToString(mac.Sum(nil))
received := r.Header.Get("X-Recustomer-Signature-256-V2")
if !hmac.Equal([]byte(received), []byte(expected)) {
w.WriteHeader(http.StatusUnauthorized)
return
}
var event map[string]any
if err := json.Unmarshal(body, &event); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
log.Println(event)
w.WriteHeader(200)
})
http.ListenAndServe(":3000", nil)
}
// Cargo.toml: axum = "0.8", tokio = { version = "1", features = ["full"] },
// hmac = "0.12", sha2 = "0.10", hex = "0.4"
use std::time::{SystemTime, UNIX_EPOCH};
use axum::{
body::Bytes,
extract::State,
http::{HeaderMap, StatusCode},
response::{IntoResponse, Response},
routing::post,
Router,
};
use hmac::{Hmac, Mac};
use sha2::Sha256;
fn header_value<'a>(headers: &'a HeaderMap, name: &str) -> &'a str {
headers.get(name).and_then(|v| v.to_str().ok()).unwrap_or_default()
}
// Verify the signature against the raw body, before parsing it as JSON
async fn handle(State(secret): State<String>, headers: HeaderMap, body: Bytes) -> Response {
let timestamp = header_value(&headers, "X-Recustomer-Signature-256-V2-Timestamp-Epoch");
let now = SystemTime::now().duration_since(UNIX_EPOCH).map_or(0, |d| d.as_secs() as i64);
match timestamp.parse::<i64>() {
Ok(sent) if now.abs_diff(sent) <= 300 => {}
_ => return StatusCode::UNAUTHORIZED.into_response(),
}
let mut mac = Hmac::<Sha256>::new_from_slice(secret.as_bytes()).expect("HMAC accepts any key length");
mac.update(timestamp.as_bytes());
mac.update(b".");
mac.update(&body);
let signature = hex::decode(header_value(&headers, "X-Recustomer-Signature-256-V2"));
if !signature.is_ok_and(|s| mac.verify_slice(&s).is_ok()) {
return StatusCode::UNAUTHORIZED.into_response();
}
println!("{}", String::from_utf8_lossy(&body));
StatusCode::OK.into_response()
}
#[tokio::main]
async fn main() {
let state = std::env::var("RECUSTOMER_WEBHOOK_SECRET")
.ok()
.filter(|v| !v.is_empty())
.expect("RECUSTOMER_WEBHOOK_SECRET is not set");
let app = Router::new().route("/your_shipping_endpoint", post(handle)).with_state(state);
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
}