Connect your own FastSpring store to KDPika licensing through a verified, durable backend. This does not add a processor to KDPika platform subscriptions.
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
- Use your own FastSpring test storefront and create one quantity-one product. Save its exact product path.
- Create an API credential with read access to your orders, subscriptions and returns. Save its username/password privately as KDP_STORE_API_KEY and KDP_STORE_API_SECRET.
- Configure an HMAC-secured webhook endpoint at your own HTTPS /provider-event. Save its secret as KDP_STORE_WEBHOOK_SECRET. Select order.completed, subscription.charge.completed, subscription.charge.failed, subscription.canceled, subscription.deactivated, subscription.updated and return.created as supported in your account.
- Set provider/source to fastspring, environment to sandbox and seller_id to your stable merchant reference. The API credential and webhook must belong to this same merchant.
- Map each exact product path in offer_map. Native API objects' live fields must match the configured environment. Keep a separate state/configuration for each account and environment.
Verify before granting access
X-FS-Signature is base64 HMAC-SHA256 over exact raw bytes. A signed envelope can contain up to 50 events here: each event is committed separately within one durable batch receipt. Event IDs deduplicate deliveries; stable order IDs prevent double granting when provider retries use different event IDs. Current objects are read with private Basic API authentication.
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
| Notification | Confirmed evidence | Licensing decision |
|---|---|---|
| order.completed | Current completed order, matching live mode, one mapped product, active matching subscription if present | Issue initial order once. Subscription identity is verified against its current record. |
| subscription.charge.completed | Current completed order and active subscription; GROUP_REGULAR_PERIOD acquisition type | Renew existing subscription once by order ID. Prorated charge types require review. |
| subscription.charge.failed / subscription.updated | Current subscription is overdue, not merely an old failure notification | Suspend. A healthy recovered subscription is not suspended by a stale failure. |
| subscription.canceled / subscription.deactivated | Current canceled intent or inactive subscription | Preserve paid time on cancellation; ended/inactive suspends. |
| return.created | Current completed return with one Full Refund item and matching live mode | Revoke license linked to original order. Partial/unknown returns require review. |
The orders/{id} and subscriptions/{id} endpoints return a single object; returns/{id} uses a returns array. The reference follows those different documented shapes. Subscription charge events can include prorations, so event name alone is insufficient. Refund-before-purchase mapping is held for reconciliation and remembered as an adverse-reference tombstone, not silently discarded. There is no invented universal chargeback event or automatic in-place plan migration.
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.
- Download all exact sources and check the SHA-256 manifest.
- Follow the shared setup without changing the provider/module source or putting private config under a web root.
- 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.
- Run the private work cron, inspect its aggregate states, and then run the separate mail cron. Keep both ledgers/backups persistent.
- 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.
<?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 StoreFastspringNormalizer
{
private function fastspring(array $envelope): array
{
storeRequire(count($envelope['events'] ?? []) === 1, 'ONE_EVENT_ENVELOPE_REQUIRED');
$event = $envelope['events'][0]; $type = $event['type'] ?? ''; $data = $event['data'] ?? [];
if (in_array($type, ['order.completed', 'subscription.charge.completed'], true)) {
$orderId = is_array($data['order'] ?? null) ? ($data['order']['id'] ?? null) : ($data['order'] ?? $data['id'] ?? null);
$order = $this->get('/orders/' . $this->ref($orderId)); $this->mode($order['live'] ?? null);
storeRequire(($order['id'] ?? null) === $orderId, 'ORDER_ID_MISMATCH');
storeRequire(($order['completed'] ?? false) === true, 'ORDER_NOT_COMPLETED');
$item = $this->one($order['items'] ?? []);
$nativeOrder = is_array($data['order'] ?? null) ? $data['order'] : $data;
$subscription = $data['subscription'] ?? $nativeOrder['items'][0]['subscription'] ?? null;
if (is_array($subscription)) { $subscription = $subscription['id'] ?? null; }
$recurring = is_string($subscription);
storeRequire($type !== 'subscription.charge.completed' || $recurring, 'SUBSCRIPTION_MAPPING_REQUIRED');
if ($recurring) {
$currentSubscription = $this->get('/subscriptions/' . $this->ref($subscription));
$this->mode($currentSubscription['live'] ?? null);
storeRequire(($currentSubscription['active'] ?? false) === true && in_array($currentSubscription['state'] ?? '', ['active', 'trial'], true) && ($currentSubscription['product'] ?? null) === ($item['product'] ?? null), 'SUBSCRIPTION_NOT_ACTIVE');
}
if ($type === 'subscription.charge.completed') {
storeRequire(($nativeOrder['acquisitionTransactionType'] ?? '') === 'GROUP_REGULAR_PERIOD', 'PRORATED_CHARGE_REQUIRES_REVIEW');
}
$customer = $order['customer'] ?? [];
return [$this->paid((string) ($subscription ?? $orderId), (string) $orderId, (string) ($item['product'] ?? ''),
(string) ($customer['email'] ?? ''), trim(($customer['first'] ?? '') . ' ' . ($customer['last'] ?? '')), $recurring,
[(string) $orderId], null, $type === 'order.completed')];
}
if (str_starts_with($type, 'subscription.')) {
$id = $data['subscription'] ?? $data['id'] ?? null;
if (is_array($id)) { $id = $id['id'] ?? null; }
$subscription = $this->get('/subscriptions/' . $this->ref($id)); $this->mode($subscription['live'] ?? null);
$state = match (true) { ($subscription['active'] ?? true) === false => 'ended',
($subscription['state'] ?? '') === 'canceled' || !empty($subscription['canceledDate']) => 'cancelled',
($subscription['state'] ?? '') === 'overdue' => 'failed', default => null };
return $state === null ? [] : [$this->negative((string) $id, (string) $event['id'], $state)];
}
if ($type === 'return.created') {
$id = $data['id'] ?? null; $result = $this->get('/returns/' . $this->ref($id));
$return = $this->one($result['returns'] ?? []);
storeRequire(($return['return'] ?? null) === $id && ($return['completed'] ?? false) === true, 'RETURN_NOT_COMPLETED');
$this->mode($return['live'] ?? null);
$item = $this->one($return['items'] ?? []);
storeRequire(($item['refundType'] ?? '') === 'Full Refund', 'PARTIAL_REFUND_REQUIRES_REVIEW');
return [$this->negative((string) ($return['original']['id'] ?? ''), (string) $event['id'], 'refunded')];
}
return [];
}
}
Test in Sandbox
- Confirm invalid/missing proof cannot issue, and no key or API credential appears in the HTTP reply.
- 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.
- Deliver to your verified test inbox and activate that key with the same buyer email and Sandbox App ID. Test a mismatched email too.
- Redeliver the same event and overlapping supported paid events. Confirm no second key and no additional renewal days for the same paid receipt.
- For supported subscriptions, test initial payment, another confirmed paid period, current failure/recovery and cancellation. Verify cancellation does not remove already-paid time.
- 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.
- 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 FastSpring 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.
- Official reference 1
- Official reference 2
- Official reference 3
- Official reference 4
- Official reference 5
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.