# Send a signed test notification to your local endpoint
RECUSTOMER_WEBHOOK_SECRET='your_webhook_secret'
BODY=$(cat <<'JSON'
{
"id": 1,
"external_order_id": "A123",
"order_number": "#1001",
"request_id": "#1001_01",
"created_at": "2024-01-17T20:13:41.103117+00:00",
"refund_reject_reason": "返金の条件を満たしていない",
"approval_at": "2024-01-17T20:13:41.103117+00:00",
"send_backed_at": "2024-01-17T20:13:41.103117+00:00",
"reshipmented_at": "2024-01-17T20:13:41.103117+00:00",
"exchanged_at": "2024-01-17T20:13:41.103117+00:00",
"refunded_at": "2024-01-17T20:13:41.103117+00:00",
"completed_at": "2024-01-17T20:13:41.103117+00:00",
"approval_status": "unapproved",
"send_back_status": "unarrived",
"reshipment_status": "unreshiped",
"exchange_status": "unexchanged",
"refund_status": "unrefunded",
"payment_status": "unpaid",
"exchange_slip_creation_status": "uncreated",
"order_items": [
{
"id": 1,
"original_item_id": "A11",
"sku": "sku123",
"product_id": "product1234",
"image_link": "https://~",
"is_deleted": false,
"item_name": "return item A",
"item_price": 5000,
"currency": "JPY",
"item_result": {
"id": 1,
"approval_status": "unapproved",
"send_back_status": "unarrived",
"reshipment_status": "unreshiped",
"resolution_method": "exchange",
"item_status": "A品",
"is_required_send_back": true,
"is_customer_pay": true,
"approval_reject_reason": "承認条件を満たしてない",
"exchange_reject_reason": "交換条件を満たしてない",
"memo": "在庫処分",
"send_back_reject_reason": "リクエスト内容と異なる",
"arrival_date": "2024-01-17"
},
"options": [
{
"key": "color",
"value": "black"
}
],
"exchange_item": {
"id": 1,
"item_name": "exchange item A",
"options": [
{
"key": "color",
"value": "black"
}
],
"image_link": "https://~",
"sku": "sku123",
"item_price": 5000,
"currency": "JPY",
"exchange_status": "unexchanged",
"exchange_slip_creation_status": "uncreated",
"external_order_code": "order123"
}
}
],
"customer": {
"id": 1,
"email": "info@recustomer.co",
"return_count": 2,
"cancel_count": 2,
"last_name": "山田",
"first_name": "太郎",
"full_name": "山田太郎",
"phone_number": "08011112222",
"is_consent_email_marketing": true,
"is_consent_sms_marketing": true
},
"shipping_address": {
"last_name": "山田",
"first_name": "太郎",
"full_name": "山田太郎",
"phone_number": "09012345678",
"country_code": "JP",
"postal_code": "100-0024",
"province": "東京都",
"city": "千代田区",
"address1": "千代田1-1-1",
"address2": "千代田ビル501"
},
"billing_address": {
"last_name": "山田",
"first_name": "太郎",
"full_name": "山田太郎",
"phone_number": "09012345678",
"country_code": "JP",
"postal_code": "100-0024",
"province": "東京都",
"city": "千代田区",
"address1": "千代田1-1-1",
"address2": "千代田ビル501"
},
"refund_info": {
"id": 1,
"payment_method": "クレジットカード",
"refund_method": "API返金",
"refund_sub_total": 10000,
"tax": 1000,
"suggested_amount": 11000,
"fixed_amount": 11000,
"discount_and_expenses": [
{
"id": 0,
"suggested_amount": 0,
"fixed_amount": 0,
"discount_expenses_name": "返品手数料"
}
]
},
"is_archive": true
}
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_return_order_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_return_order_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_return_order_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_return_order_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_return_order_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_return_order_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();
}