KDPika Licensing Sign inStart free
API v1
Show all languages
Browse documentation

Choose a page in the navigation drawer.

KDPika Licensing · API v1 Advanced

WooCommerce legacy service reference

Verified WooCommerce / WordPress purchase-to-license reference with native proof, durable mapping and honest lifecycle boundaries.

On this page
Updated 2026-10-18 UTCDownload Markdown

This is the legacy developer-operated service reference. New stores should use the official installable WooCommerce plugin, without a separate service, JSON mapping or developer cron. Keep this reference only for integrations already using these exact source files. Do not run both issuers on the same order.

What you will learn

  • Configure native notifications and approved product/plan mappings.
  • Issue once after confirmed payment, then handle supported lifecycle changes.
  • Deliver a saved key privately and test without exposing buyer/card data.

Prerequisites

  • Complete the Sandbox quickstart and store service setup.
  • Use your own provider merchant account and private backend credentials; never KDPika's platform billing credentials.
  • Have a product-scoped Sandbox management key with licenses:read and licenses:write.
  • Configure one eligible quantity-one line. Mixed baskets, multi-seat quantities and partial refunds need an explicitly reviewed policy.

Configure the provider

  1. Install supported WordPress/WooCommerce with working Action Scheduler and HTTPS. Create a dedicated REST read key authorized to read your orders; keep its consumer key/secret privately as KDP_STORE_API_KEY and KDP_STORE_API_SECRET.
  2. Set provider/source to woocommerce, environment to sandbox, seller_id to a stable merchant reference, store_url to the exact HTTPS origin without a trailing slash, and woocommerce_mode_policy to configured_environment.
  3. Use a payment plugin's own Test mode on that store. WooCommerce core has no universal order Test flag: pin a dedicated test store/key to KDPika Sandbox. Do not claim automatic payment-plugin mode detection.
  4. Map a quantity-one variation ID, or product ID when no variation is present, in offer_map.
  5. Install the complete plugin shown below as wp-content/plugins/kdpika-store-bridge/kdpika-store-bridge.php, then activate it. Set KDP_LICENSE_WEBHOOK_URL to your own service's HTTPS /provider-event and KDP_LICENSE_WEBHOOK_SECRET to the same private secret as KDP_STORE_WEBHOOK_SECRET in environment.php.
  6. Place those constants in private wp-config.php server configuration, not a page editor. Complete an order and inspect WooCommerce Scheduled Actions. Run the separate service cron to fulfill it.

Verify before granting access

The plugin signs the exact JSON body with base64 HMAC-SHA256 in X-WC-Webhook-Signature. This matches the native WooCommerce raw-body signature format, but these two plugin hook notices are this reference bridge, not a claim that every WooCommerce extension emits the same body. The worker retrieves the current order through authenticated /wp-json/wc/v3/orders/{id}; browser checkout fields are not payment proof.

Provider verification, receipt and fulfillment are separate. HTTP 202 only means the authenticated notification was saved. A buyer redirect or successful browser message never creates a license. Only the backend worker can authorize the scoped licensing write after current provider reads.

Event and lifecycle mapping

NotificationConfirmed evidenceLicensing decision
woocommerce_order_status_completedREST order completed, date_paid present, no refunds, one mapped quantity-one lineAsynchronously queue a notice, then issue once after the private worker verifies it.
woocommerce_order_refundedREST order is fully refundedRevoke the mapped license; partial refunds stop for review.
Failed/cancelled current order received by an order noticeAuthenticated current state, existing mappingFailed suspends; cancellation intent preserves paid time. The minimal plugin itself only subscribes to completed/refunded hooks.

Do not also configure a second custom issuer on the same order. This bridge retries failed receipt five times with increasing delays, then exposes a failed scheduled action for review; a 202 receipt is not a license/email confirmation. Check Action Scheduler and your service independently.

This is an order-based bridge. WooCommerce Subscriptions is a separate extension with its own renewal/subscription hooks and identifiers; this minimal plugin does not implement that extension or invent universal recurring hooks. A renewal treated as an independent completed order creates an independent order license, not a renewal of the original entitlement. Native WordPress installation tests require your own staging store; the supplied test executes the exact plugin with explicit WordPress/WooCommerce contract functions.

Server examples and deployment

The PHP application contains the native verification, provider API reads, durable ledger and licensing worker. Optional Node/Python examples are complete raw-body ingress servers with an explicit PHP service dependency, not independent native payment workers. The PHP shared-hosting path needs neither Node nor a long-running process.

  1. Download all exact sources and check the SHA-256 manifest.
  2. Follow the shared setup without changing the provider/module source or putting private config under a web root.
  3. Set config.json provider/merchant/mode and offer_map; set fulfillment.json source to the identical provider string and map the approved internal offer to your product plan.
  4. Run the private work cron, inspect its aggregate states, and then run the separate mail cron. Keep both ledgers/backups persistent.
  5. Configure SMTP delivery for your own sender. It reuses the encrypted saved key; it never creates another license to resend.

Complete provider module

This exact module is loaded by the shared normalizer. It depends on the complete native authentication and HTTP client and durable service source. It is not a standalone copy/paste webhook endpoint.

woocommerce.phpphp
<?php
declare(strict_types=1);
// Complete provider module for StoreNormalizer; loaded by normalize.php.
// Requires the shared service/archive, not a standalone payment endpoint.
trait StoreWoocommerceNormalizer
{
    private function woocommerce(array $event, array $headers): array
    {
        $orderId = $event['order_id'] ?? $event['id'] ?? null;
        $order = $this->get('/wp-json/wc/v3/orders/' . $this->ref($orderId));
        storeRequire((string) ($order['id'] ?? '') === (string) $orderId, 'ORDER_NOT_CONFIRMED');
        // WooCommerce has no universal test flag across payment plugins.
        storeRequire(($this->config['woocommerce_mode_policy'] ?? '') === 'configured_environment', 'EXPLICIT_WOO_MODE_POLICY_REQUIRED');
        $id = (string) $orderId; $status = $order['status'] ?? '';
        if ($status === 'refunded') { return [$this->negative($id, 'refund:' . $id, 'refunded')]; }
        if ($status === 'cancelled') { return [$this->negative($id, 'cancel:' . $id, 'cancelled')]; }
        if ($status === 'failed') { return [$this->negative($id, 'failed:' . $id, 'failed')]; }
        storeRequire($status === 'completed' && !empty($order['date_paid']) && empty($order['refunds']), 'ORDER_NOT_COMPLETED_OR_REFUNDED');
        $line = $this->one($order['line_items'] ?? []);
        $offer = (string) (($line['variation_id'] ?? 0) ?: ($line['product_id'] ?? ''));
        $buyer = $order['billing'] ?? [];
        return [$this->paid($id, $id, $offer, (string) ($buyer['email'] ?? ''), trim(($buyer['first_name'] ?? '') . ' ' . ($buyer['last_name'] ?? '')), false)];
    }
}

Complete WordPress plugin

woocommerce-plugin.phpphp
<?php
/**
 * Plugin Name: KDPika Store Notification Bridge (Reference)
 * Description: Queue completed/refunded WooCommerce order notices to your private licensing service.
 * Version: 1.0.0
 * Requires PHP: 8.2
 */
declare(strict_types=1);
// WordPress + WooCommerce/Action Scheduler. Private wp-config.php constants:
// KDP_LICENSE_WEBHOOK_URL (HTTPS /provider-event), KDP_LICENSE_WEBHOOK_SECRET.
// Service performs authenticated Woo REST rereads; no API key in browser/WordPress buyer page.
if (!defined('ABSPATH')) { exit; }

function kdpika_queue_order_notice(int $orderId): void
{
    if (!function_exists('as_enqueue_async_action') || !function_exists('wc_get_order')) { return; }
    as_enqueue_async_action('kdpika_store_notice', ['order_id' => $orderId, 'attempt' => 0], 'kdpika-licensing');
}
add_action('woocommerce_order_status_completed', 'kdpika_queue_order_notice', 10, 1);
add_action('woocommerce_order_refunded', 'kdpika_queue_order_notice', 10, 1);

function kdpika_send_order_notice(int $orderId, int $attempt): void
{
    if (!defined('KDP_LICENSE_WEBHOOK_URL') || !defined('KDP_LICENSE_WEBHOOK_SECRET')) { return; }
    $url = (string) KDP_LICENSE_WEBHOOK_URL;
    if (wp_parse_url($url, PHP_URL_SCHEME) !== 'https' || wp_parse_url($url, PHP_URL_PATH) !== '/provider-event' || strlen((string) KDP_LICENSE_WEBHOOK_SECRET) < 16) { return; }
    $order = wc_get_order($orderId); if (!$order) { return; }
    $body = wp_json_encode(['id' => $orderId, 'status' => $order->get_status()]);
    if (!is_string($body)) { return; }
    $signature = base64_encode(hash_hmac('sha256', $body, (string) KDP_LICENSE_WEBHOOK_SECRET, true));
    $result = wp_remote_post($url, ['timeout' => 10, 'redirection' => 0, 'sslverify' => true,
        'headers' => ['Content-Type' => 'application/json', 'X-WC-Webhook-Signature' => $signature, 'X-WC-Webhook-Topic' => 'order.updated'], 'body' => $body]);
    $accepted = !is_wp_error($result) && wp_remote_retrieve_response_code($result) === 202;
    if ($accepted) {
        $receipt = json_decode(wp_remote_retrieve_body($result), true);
        $accepted = is_array($receipt) && ($receipt['accepted'] ?? false) === true && is_bool($receipt['duplicate'] ?? null);
    }
    if (!$accepted && $attempt < 5 && function_exists('as_schedule_single_action')) {
        $delays = [60, 300, 1800, 7200, 43200];
        as_schedule_single_action(time() + $delays[$attempt], 'kdpika_store_notice', ['order_id' => $orderId, 'attempt' => $attempt + 1], 'kdpika-licensing');
    } elseif (!$accepted) {
        throw new RuntimeException('Licensing notification not confirmed. Review the private service and this scheduled action before retrying.');
    }
}
add_action('kdpika_store_notice', 'kdpika_send_order_notice', 10, 2);

Test in Sandbox

  1. Confirm invalid/missing proof cannot issue, and no key or API credential appears in the HTTP reply.
  2. Complete one permitted Test purchase in your merchant account. Confirm the provider delivery, then run work and verify one DONE issue and a saved encrypted key.
  3. Deliver to your verified test inbox and activate that key with the same buyer email and Sandbox App ID. Test a mismatched email too.
  4. Redeliver the same event and overlapping supported paid events. Confirm no second key and no additional renewal days for the same paid receipt.
  5. For supported subscriptions, test initial payment, another confirmed paid period, current failure/recovery and cancellation. Verify cancellation does not remove already-paid time.
  6. Test a supported full refund and any exposed dispute lifecycle. Check revoked/suspended state in KDPika; never simulate a refund only by editing the browser return URL.
  7. Test stale events and a missing initial mapping. Unknown, partial or unsupported cases must be held for review, not silently fulfilled.

Expected result: one authorized initial license, one additive extension per supported new paid receipt, no duplicate grant, no access from an unverified event, and a private delivery record. Renewal adds your mapped integer days, not an exact calendar-period-end update.

Verification boundary

The exact source was executed through local HTTP ingress and explicit synthetic provider-schema API fixtures, with real isolated KDPika Sandbox issuance, activation and supported lifecycle writes. Fixture signatures use local test secrets, not a provider's private signing infrastructure. No real WooCommerce / WordPress account purchase is claimed. Your account's permissions, actual delivery format, TLS, provider checkout and email inbox still need the procedure above before Live use. Native WordPress/merchant account execution was unavailable in this documentation environment; this is the explicit contract-test boundary, not recorded-payment evidence.

Go-live checklist

  • Review the unsupported boundaries above; do not sell a lifecycle this adapter does not implement.
  • Complete your provider account verification and real Test delivery procedure; check merchant, recipient, item and mode.
  • Use a separate Live config/state and scoped Live KDPika key; set KDP_CONFIRM_LIVE only after review. Never turn existing Sandbox ledgers into Live by editing their binding.
  • Replace provider credentials/destination secret with the matching Live account values. Do not reuse example placeholders.
  • Remove every loopback test override, use verified HTTPS and keep credentials and SQLite/encryption backups outside all web roots.
  • Monitor private REVIEW/IN_FLIGHT and mail failures. A missing acknowledgement is not proof a write or email did not happen; reconcile before retrying.
  • Retain business-effect identities to prevent reissuance. Apply your documented retention, refund, support and key-redelivery policies.

Common mistakes

  • Shipping a server management key inside an application or theme.
  • Issuing from a redirect, subscription-created event or unverified notification.
  • Granting both initial checkout and initial recurring invoice independently.
  • Deleting the durable ledger or creating a new effect ID after a timeout.
  • Treating a saved key or SMTP acceptance as confirmed inbox delivery.

Official sources

Reviewed for this reference on 18 October 2026. Provider documentation can change independently; check your pinned API and account before upgrading.

Expected result

Only a confirmed provider purchase authorizes a licensing effect. A durable HTTP receipt, completed licensing operation and SMTP acceptance are separate outcomes. Inspect aggregate worker states and verify the resulting license with the same buyer email; no full key appears in public replies.

Security notes

Use least-privilege private provider and product-scoped licensing credentials, verified HTTPS, owner-only persistent state and separate secrets per account/environment. Never trust browser payment claims. Preserve held operations after an unknown result and reconcile before another write; exactly-once behavior across systems is not guaranteed.

Troubleshooting

For a receipt refusal check raw-byte preservation, the matching endpoint secret/account/mode, server clock where applicable and the private bootstrap layout. For REVIEW/IN_FLIGHT inspect provider state, safe private error codes and the licensing ledger before retrying. Missing permissions, recipient data or an initial mapping are not successful payments. For mail verify the separate SMTP ledger and provider delivery evidence. Do not post raw events, keys or SQLite files publicly.

Next steps

Run the selected provider Sandbox procedure, then test private key email delivery. Review supported recipe limitations before enabling Live.

Was this page helpful?

Choose an answer

Do not include personal data, license keys or credentials. Retained for up to 30 days. This is not a support inbox.

Search documentation

Arrow keys to move, Enter to open, Escape to close. Search stays in your browser.

Cookie settings