Deduplicate your business events durably; the current API creation key is useful but does not guarantee exactly-once fulfillment.
What you will learn
- Choose stable keys and identical retry bodies.
- Understand atomic creation replay and its expiry boundary.
- Handle store fulfillment and renewal uncertainty without guessing.
Prerequisites
- Read API conventions.
- Complete the Sandbox quickstart.
Creation key contract
POST /api/v1/licenses requires an Idempotency-Key header with 8–190 trimmed characters. The key is scoped to the whole organization. Include a stable product/store/event identity so unrelated operations cannot collide. Store event IDs are input to your own mapping; KDPika does not verify an external store event here.
The encrypted replay response lasts24 hours. Reusing the unexpired key and identical request hash returns the original201 body, including the original request_id and newly issued license key, plus Idempotent-Replay:true. X-Request-ID identifies the current request. A changed body, product or environment returns409 IDEMPOTENCY_CONFLICT. A used key outside the replay window returns409 IDEMPOTENCY_EXPIRED, never a new license.
The server hashes the trusted API-key product/environment scope and PHP JSON encoding of the decoded body. Whitespace is decoded away, but member order and unknown fields can change the hash. Serialize one stable request; do not regenerate or reorder fields between retries.
Atomic creation, not cross-system exactly once
Phase1 fixes the previous creation race and expired-key duplication defects. License, customer, queued webhook and encrypted receipt share one database commit, serialized per workspace. Concurrent identical requests return one original receipt; a failure before commit rolls back creation. Minimal used-key receipts survive replay-secret cleanup, so expiry cannot silently create another license. Older legacy rows still present are promoted or retained as expired markers; rows purged before this release cannot be reconstructed.
Different keys still identify different operations. Keep your purchase-to-license mapping and provider-event deduplication. Retry a lost creation response with the identical key/body within24 hours. After expiry, reconcile the original operation instead of automatically choosing a fresh key. A management GET requires the license ID you retained; this API is not a cross-system payment or delivery guarantee.
Retry safety by operation
| Operation | Idempotency-Key behavior | Client decision |
|---|---|---|
| GET /api/v1/public-key | Ignored / no replay | Safe bounded read retry |
| POST /api/v1/licenses | Required; atomic encrypted24-hour replay, then409 expiry | Retry identical key/body inside24 hours; reconcile expiry |
| POST /api/v1/licenses/activate | Ignored / no replay | Reconcile uncertain result before another write |
| POST /api/v1/licenses/validate | Ignored / no replay | Token/last-seen refresh; coordinate retries |
| POST /api/v1/licenses/deactivate | Ignored / no replay | Reconcile uncertain result before another write |
| GET /api/v1/licenses/{license} | Ignored / no replay | Safe bounded read retry |
| POST /api/v1/licenses/{license}/revoke | Ignored / no replay | Reconcile uncertain result before another write |
| POST /api/v1/licenses/{license}/suspend | Ignored / no replay | Reconcile uncertain result before another write |
| POST /api/v1/licenses/{license}/restore | Ignored / no replay | Reconcile uncertain result before another write |
| POST /api/v1/licenses/{license}/renew | Ignored / no replay | Reconcile uncertain result before another write |
| POST /api/v1/licenses/{license}/reset-devices | Ignored / no replay | Reconcile uncertain result before another write |
Activation rotates tokens even on an existing ACTIVE installation. Renewal extends time on every accepted call. Deactivation repeats401; repeated status/reset actions can repeat events. Database row locks serialize updates but do not identify a repeated external business event.
Durable fulfillment example
For a verified event such as YOUR_STORE_EVENT_ID, persist a fulfillment row under a unique key of store/account/product/event. Save the normalized request, intended action and state before calling the API. Serialize workers on that row; do not use process-local locks as durable deduplication.
- Verify the store webhook or server-side purchase with your own provider integration. Expected: authenticated event, not a success-page query string.
- Acquire the unique durable fulfillment row. Expected: only one worker owns this event; an already completed row returns its saved license mapping without another API call.
- Use a stable creation key such as store:YOUR_STORE_ACCOUNT:YOUR_PRODUCT:YOUR_STORE_EVENT_ID. Expected: an 8–190 character key with no buyer email or card data.
- Send the saved normalized JSON to the create operation. Expected: a documented201 with a new license ID/key, or an explicit error.
- Persist the license mapping and secret-delivery state atomically in your system. Expected: subsequent deliveries reuse the durable record, not another API creation.
- Mark any timeout/500 as uncertain and reconcile before releasing another write. Expected: no automatic duplicate issuance or renewal. Do not claim a provider charged the buyer unless your provider data confirms it.
A stable illustrative request key is YOUR_STORE_EVENT_ID, not a new random value on every retry. Use your provider account in the dedupe namespace when event IDs are not globally unique. This is a workflow specification, not a new provider integration or a fake payment example. Store-specific tested integration code belongs to the separate integration guides.
Renewal requires its own deduplication
Persist each verified renewal event and expected old/new expiration before calling renew. Renew has no replay key. If a response is lost, compare a known license summary and your durable record; do not add the same days automatically a second time. Concurrent unrelated renewals need deliberate business serialization, because merely reading then writing is not compare-and-swap.
Retention and secrecy
New receipts encrypt the complete creation response, including license_key, using APP_KEY. Retention scrubs encrypted responses after24 hours while retaining minimal used-key markers. Existing legacy plaintext rows are promoted on replay or scrubbed after expiry; cleanup depends on the scheduler. Keep APP_KEY, database access and backups protected. Key delivery must remain authorized and confidential; this API does not automatically email the buyer.
Expected result
A replayed business event does not trigger an intentional second write from your worker, and uncertain outcomes are surfaced for reconciliation.
Common mistakes
- Choosing a new random header for every attempt of the same event.
- Assuming renew supports the creation replay mechanism.
- Advertising cross-system exactly-once fulfillment based only on a creation key.
Security notes
Verify purchases on your backend. Never put provider secrets or developer API keys in buyer applications. Keep replay bodies and fulfillment records private.
Troubleshooting
| Symptom | Cause | Action |
|---|---|---|
| 409 IDEMPOTENCY_CONFLICT | Different decoded request hash/member order | Use the saved original request; do not hide the conflict with a new key |
| 409 IDEMPOTENCY_EXPIRED | Original operation completed but replay expired | Inspect the original license before intentionally creating anything new |
| 500 or timeout after create | Outcome not yet known to the caller | Retry identical key/body within24 hours; retain request IDs |
| Expiry extended twice | Same renewal event repeated without durable dedupe | Investigate the event mapping; do not automate further extensions |
Next steps
Review the endpoint reference and signature verification.