YouCan is where most Moroccan COD orders come from, so this is the integration worth getting right. The whole thing is two webhook handlers and three API calls.
Read the plugin contract first — the signature scheme, the retry rules and the privacy boundary are the same on every platform, and they are not repeated here. This page is only the YouCan-shaped part.
Two sets of webhooks, two different signatures. YouCan signs its events with your OAuth client secret and puts a bare hex digest in
X-YOUCAN-SIGNATURE. We sign ours with your endpoint'swhsec_…and putt=…,v1=…inX-EBlacklist-Signature. They are not interchangeable and you need both verifiers. Getting this wrong is the single most common way one of these integrations ends up accepting forged events.YouCan details on this page were checked against docs.youcan.shop on 2026-11-16. YouCan ships changes; re-check before you ship.
What you are building
YouCan: order.created ──► your app ──► POST /v1/checks ──► score
│
└──► write check_id onto the order
tag / hold / let it through
eBlacklist: followup.due ──► your app ──► ask the merchant "what happened?"
score.changed ─► your app ──► hold a parcel still in the shop
outcome.recorded ► your app ──► close the task
YouCan: order.updated ───► your app ──► POST /v1/checks/{id}/outcome
Three calls to us: one check, one outcome, and the one-off webhook registration. Everything else is us calling you.
1. Set up
Scopes
Your YouCan app needs edit-rest-hooks to subscribe and delete-rest-hooks to clean up on
uninstall.
Your eBlacklist token needs checks:write, outcomes:write and read. Register your webhook
endpoint with a separate token carrying webhooks:write, used once at setup and then
discarded — see why that scope is separate.
Register your eBlacklist endpoint
Once per merchant, when they connect their account:
$response = http_post('https://api.eblacklist.app/v1/webhooks', [
'label' => 'YouCan — ' . $store->slug,
'url' => 'https://plugin.example.com/eblacklist/webhook/' . $store->id,
'events' => ['followup.due', 'outcome.recorded', 'score.changed'],
], ['Authorization: Bearer ' . $setupToken]);
// Returned once, here, and never again. There is no rotation endpoint.
$store->eblacklist_webhook_secret = $response['secret'];
$store->eblacklist_webhook_id = $response['id'];
$store->save();
One endpoint per merchant, with the store id in the path, so a disabled endpoint takes down one merchant rather than all of them. A merchant may have at most 5 endpoints; if you are also writing to a staging URL, that is two of their five.
Then prove it works before you depend on it:
curl -s -X POST https://api.eblacklist.app/v1/webhooks/$ID/test \
-H "Authorization: Bearer $EBLACKLIST_TOKEN"
# {"delivered": true, "response_code": 204, "error": null, "latency_ms": 143}
Subscribe to YouCan's events
curl -s -X POST https://api.youcan.shop/resthooks/subscribe \
-H "Authorization: Bearer $YOUCAN_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"event": "order.created", "target_url": "https://plugin.example.com/youcan/order-created"}'
# {"id": "8e6b019b-06de-496d-a96d-c9ee69c0ccf0"}
Repeat for order.updated and app.uninstalled. Four things worth knowing:
- Subscribing twice is safe. The same
event+target_urlreturns the existing subscription's id rather than creating a duplicate — and if that subscription had been deactivated, this reactivates it and resets its failure count. That makes "subscribe on every app boot" a reasonable recovery strategy. target_urlmust be https and publicly reachable. localhost and private addresses do not work, on either side. Use a tunnel in development.- Use the canonical event names.
order.create,inventory.lowandupsell.acceptare deprecated aliases; do not subscribe to them in new code. - Seven active subscriptions per event per store, per app. Over that you get a
429with"This store has reached the max of subscriptions for this event."
On uninstall, POST https://api.youcan.shop/resthooks/unsubscribe/{id} (scope
delete-rest-hooks), and DELETE /v1/webhooks/{id} on our side.
2. Event mapping
| YouCan event | eBlacklist call | Notes |
|---|---|---|
order.created | POST /v1/checks | The one that matters. COD orders only |
order.updated | POST /v1/checks/{id}/outcome | Only when the status moved to a terminal one — see the table below |
order.paid | POST /v1/checks/{id}/outcome with delivered | Worth handling: on a COD order, "paid" means the cash was actually collected. Confirm against a real delivery that your merchants' flow marks it, rather than assuming |
cart.abandoned | — | No order, nothing to check |
product.inventory.low | — | Unrelated |
app.uninstalled | DELETE /v1/webhooks/{id} | Stop the endpoint, then unsubscribe from YouCan |
Order status to outcome
Map YouCan's status onto our four reportable outcomes. The status is a number, and the meanings live on YouCan's own Statuses page rather than in the webhook payload, so resolve it in the adapter above — never with integers written inline:
| What happened | Outcome to report | Why it matters |
|---|---|---|
| The buyer took the parcel and paid | delivered | The signal that makes good buyers look good |
| The buyer refused it at the door | refused | The signal the whole product exists for |
| Accepted, then sent back | returned | Different from a refusal, and weighted differently |
| The merchant decided not to ship | not_shipped | Never counts against the buyer. Use it when a merchant cancels on our advice, or the data would quietly confirm its own predictions |
That last row deserves a moment. If your plugin holds a risky order, the merchant cancels it,
and you report that as a refusal, you have invented evidence: the buyer never got the chance
to accept. Report not_shipped and the check contributes nothing to the score, which is the
correct answer.
3. The check, on order.created
<?php
// POST /youcan/order-created
$raw = file_get_contents('php://input');
$given = $_SERVER['HTTP_X_YOUCAN_SIGNATURE'] ?? '';
// YouCan's signature: a bare hex HMAC-SHA256 of the raw body, keyed with your
// OAuth client secret. Nothing like the eBlacklist header — different name,
// different shape, different key.
$expected = hash_hmac('sha256', $raw, getenv('YOUCAN_CLIENT_SECRET'));
if (!hash_equals($expected, $given)) {
http_response_code(401);
exit;
}
// Answer now. YouCan retries a 5xx up to 5 times over about four hours, and
// X-YOUCAN-DELIVERY-ID stays the same across those retries, so dedupe on it.
http_response_code(200);
if (function_exists('fastcgi_finish_request')) {
fastcgi_finish_request();
}
$order = json_decode($raw, true)['data'];
if (seen_before($_SERVER['HTTP_X_YOUCAN_DELIVERY_ID'] ?? '')) {
exit;
}
// Prepaid orders are not worth scoring: the money is already in.
if (!yc_is_cash_on_delivery($order)) {
exit;
}
$buyer = yc_buyer($order); // see the adapter below
$check = eblacklist_post('/v1/checks', [
'country' => 'MA',
'buyer' => $buyer,
'product' => ['sku' => yc_first_sku($order)],
], [
// Derived from the order id, because YouCan retries and your own queue may too.
'Idempotency-Key: youcan-order-' . $order['id'],
]);
if ($check === null) {
// Fail OPEN. A scoring service having a bad minute must never stop a
// merchant trading. Queue a retry and let the order through.
queue_recheck($order['id']);
exit;
}
store_check_id($order['id'], $check['check_id']); // ← do not skip this
apply_policy($order, $check);
The adapter — write this against a real payload, not against this page
The order.created sample published at
docs.youcan.shop is
trimmed. As of 2026-11-16 it shows an order id, a reference, a numeric status, a
total and a currency, plus a customer with an id, a first name and an email — and it does
not show a phone number, a shipping address, line items or a payment method.
Everything this integration needs is therefore outside the documented sample. Do not copy field paths out of a guide, this one included. Subscribe a staging endpoint, log one real delivery, and write these three functions against it — then keep them as the only place YouCan's shape is known:
/** The three fields a check needs, as the buyer typed them. */
function yc_buyer(array $order): array
{
return [
// Map from a real order.created delivery, then cross-check against the
// "Order" entity reference in YouCan's own sidebar. These paths are a
// starting point, not a documented contract.
'phone' => $order['customer']['phone'] ?? null,
'name' => trim(($order['customer']['first_name'] ?? '') . ' ' . ($order['customer']['last_name'] ?? '')),
// Do NOT normalize the address. We match it better with the full picture, and a
// tidied address matches fewer records, not more.
'address' => $order['shipping']['address'] ?? null,
];
}
/** Your SKU for the first line item, or null. A check works without one. */
function yc_first_sku(array $order): ?string
{
return $order['items'][0]['sku'] ?? null;
}
/** True when the money is collected at the door. */
function yc_is_cash_on_delivery(array $order): bool
{
// There is no documented COD flag. Determine it from the real payload's payment
// fields, or treat every order as COD if the merchant's store is COD-only, which
// most Moroccan YouCan stores are.
return true;
}
/**
* YouCan's numeric order status -> one of our four reportable outcomes, or null
* while the order is still in flight.
*/
function yc_outcome_for_status(int $status): ?string
{
// Map from YouCan's own "Statuses" page, which is where the integers are
// defined — they are not in the webhook payload. Keep this the only place an
// integer appears, and cover it with a test against a captured payload.
return match ($status) {
// 0 => null, // pending / processing
// 1 => 'delivered',
// 2 => 'refused',
// 3 => 'returned',
// 4 => 'not_shipped',
default => null,
};
}
Assert on this in your own test suite with a captured payload fixture. When YouCan changes
shape, exactly one file breaks and it breaks loudly, rather than every check silently
going out with phone: null.
status is a number, not a string. The sample shows a numeric status and the docs
keep the mapping on a separate Statuses page. Resolve it once in an adapter the same way,
and do not hard-code integers inline.
And the policy, which is the part merchants will argue with you about:
function apply_policy(array $order, array $check): void
{
$score = $check['trust_score'];
$confidence = $check['confidence'];
// A 2 at low confidence is a buyer we know nothing about, not a warning —
// it carries NO_HISTORY and every first-time customer looks like this.
// Holding those will get your plugin turned off in a week.
if ($score <= 1 && $confidence !== 'low') {
hold_order($order['id']);
add_note($order['id'], reason_text($check['reasons']));
notify_merchant($order['id'], $check);
return;
}
if ($score <= 3) {
tag_order($order['id'], 'eblacklist-review');
add_note($order['id'], reason_text($check['reasons']));
}
}
Tag and note; let the merchant cancel. A plugin that cancels orders by itself is a plugin that gets blamed for every lost sale.
The most actionable field is not the score at all — it is
product_signal.concurrent_same_product, the count of other merchants with an open,
unresolved order for the same item in the last 72 hours. A buyer with the same item on order
from four shops will accept one parcel. Surface that number verbatim in your note.
4. The outcome, on order.updated
<?php
// POST /youcan/order-updated — signature check as above
// Same envelope as order.created: the order lives under `data`.
$order = json_decode($raw, true)['data'];
$check_id = lookup_check_id($order['id']);
if ($check_id === null) {
exit; // never checked (prepaid, or created before the plugin was installed)
}
$outcome = yc_outcome_for_status((int) $order['status']); // numeric; see the adapter
if ($outcome === null) {
exit; // still in flight; nothing to report yet
}
eblacklist_post("/v1/checks/{$check_id}/outcome", ['outcome' => $outcome]);
You have 14 days from the check to correct an answer. A later report supersedes an earlier one, so reporting a refusal after an implied delivery is always safe — and worth doing, because an implied delivery is a much weaker signal than you simply telling us.
5. Handling our webhooks
One endpoint, the store id in the path, verified with that store's whsec_…. The verification
function is in the plugin contract; only the routing is YouCan-specific:
<?php
// POST /eblacklist/webhook/{storeId}
$store = find_store($storeId);
$event = eblacklist_verify(
file_get_contents('php://input'),
$_SERVER['HTTP_X_EBLACKLIST_SIGNATURE'] ?? '',
$store->eblacklist_webhook_secret
);
if ($event === null) {
http_response_code(400);
exit;
}
http_response_code(204);
if (function_exists('fastcgi_finish_request')) {
fastcgi_finish_request();
}
// At-least-once: `id` is stable across our eight retry attempts.
if (already_processed($event['id'])) {
exit;
}
mark_processed($event['id']);
$order = order_for_check($event['data']['check_id']); // your own index
if ($order === null) {
exit;
}
switch ($event['type']) {
case 'score.changed':
// The buyer got worse while the parcel was still in the shop. This is the
// event you cannot get any other way — nothing happened in YouCan.
if ($event['data']['trust_score'] <= 1 && !has_shipped($order)) {
hold_order($order->id);
add_note($order->id, 'Buyer score dropped to ' . $event['data']['trust_score']);
}
break;
case 'followup.due':
// We are asking what happened. Ask the merchant, in your own UI, with the
// real deadline — after closes_at, silence becomes an implied delivery.
open_merchant_task($order->id, $event['data']['closes_at']);
break;
case 'outcome.recorded':
// Fires for every route an answer can arrive by, including the merchant
// tapping a push notification and the +7-day implied delivery. Close your
// task so the merchant is not asked twice.
close_merchant_task($order->id, $event['data']['outcome']);
break;
}
Platform differences, side by side
| YouCan → you | eBlacklist → you | |
|---|---|---|
| Signature header | X-YOUCAN-SIGNATURE | X-EBlacklist-Signature |
| Shape | bare hex digest | t=<unix>,v1=<hex> |
| Key | your OAuth client secret | that endpoint's whsec_… |
| Signed bytes | the raw body | "{t}.{raw body}" |
| Replay window | none — the digest covers the body only | 300 seconds, enforced by you |
| Dedupe on | X-YOUCAN-DELIVERY-ID | X-EBlacklist-Event-Id (= the body's id) |
| Topic header | X-YOUCAN-TOPIC | X-EBlacklist-Event-Type |
| Version header | X-YOUCAN-API-VERSION (v1) | api_version in the body |
| Expected reply | any 2xx | any 2xx |
| Retries | up to 5, over ~4 hours, on 5xx | 8 attempts, over ~3 hours |
| 4xx | not retried | retried like any other failure, except 410 |
| 410 Gone | deactivates the subscription | disables the endpoint and drops its queue |
Note the replay-window row. YouCan's digest covers the body alone, so a captured order.created
can be replayed at any time — your X-YOUCAN-DELIVERY-ID dedupe is what stops it mattering,
which is another reason to write the id down before you act on the event rather than after.
Common failures
Every eBlacklist signature fails. You parsed the body before verifying it. Laravel's
$request->all() and any JSON middleware consume the raw bytes, and re-encoding changes them.
Use file_get_contents('php://input') and verify first.
Every YouCan signature fails. You used the eBlacklist verifier, or the app's API key instead of the OAuth client secret.
Webhooks arrive but nothing happens. check_id was never stored at order.created, so
order_for_check() returns null and every event is dropped silently. Log that branch.
The endpoint got disabled. GET /v1/webhooks/{id} gives disabled_reason. Twenty
consecutive failed attempts does it; so does answering 410; so does the hostname starting to
resolve into private space. Re-enable with PATCH {"enabled": true} once the receiver is
healthy — which also clears the failure counter. Note that whatever was queued while it was
off is gone, deliberately: a day of stale "should I ship?" questions about parcels that
left hours ago is worse than useless.
Scores look wrong for everyone. Check that outcomes are actually being reported. A plugin
that only ever checks and never reports leaves its own merchants' buyers permanently at
confidence: low, because their own deliveries never get counted.