🐘PHP SDK

DevPayr PHP SDK

A lightweight and developer-friendly PHP SDK for integrating the DevPayr platform β€” allowing you to validate license keys, fetch injectables, manage projects, control domains, enforce payments, and more.

Designed for software creators, SaaS founders, and digital product developers who want to secure and monetize their code with minimal effort.

πŸ”° Introduction

DevPayr is a modern software licensing and payment enforcement platform built to help developers protect their code, enforce payment, and control how their software is used β€” across PHP, JavaScript, desktop, and SaaS environments.

This SDK enables seamless integration with DevPayr directly from your PHP application. Whether you're selling a script, distributing software, or building a SaaS, this SDK gives you the tools to:

  • Validate license keys and enforce runtime restrictions

  • Download and decrypt injectables (e.g., encrypted config or code blobs)

  • Interact with your DevPayr projects, licenses, and domains

  • Enforce project payment before allowing usage

πŸš€ Why Use DevPayr SDK?

Manually enforcing license checks, domain locks, and payment validation can be error-prone, time-consuming, and easily bypassed.

The DevPayr SDK solves this with:

βœ… One-Line Bootstrapping – Validate license, check payment, auto-handle injectables in a single call βœ… Secure Runtime Validation – Block unauthorized use and unpaid projects at runtime βœ… Customizable Failure Modes – Redirect, log, silently fail, or show a branded modal on license failure βœ… Injectable Decryption – Distribute sensitive data like config, templates, or code snippets securely βœ… Developer-Friendly API – Create, revoke, validate licenses and domains easily from your app βœ… Built-in Caching – Avoid repeated license checks with intelligent cache

Whether you're distributing self-hosted scripts, WordPress plugins, SaaS dashboards, or internal tools β€” DevPayr SDK brings enforcement, control, and peace of mind.

πŸ”§ Features

  • License Verification Securely validate license keys issued via DevPayr API.

  • Payment Enforcement Block access to features or full app when payment is not completed.

  • Injectables Support Automatically download, decrypt, and store encrypted files (templates, configs, snippets) tied to the license.

  • Domain Restriction Verify if a request or instance is coming from an approved domain or subdomain.

  • Runtime Enforcement Stop bootstrapping or execution on invalid/unpaid licenses with flexible fallback strategies (modal, redirect, log, silent).

  • Extensible Processor Hooks Customize how injectables are handled via your own class (e.g., save to S3, memory, etc).

  • Lightweight & Framework-Agnostic Built in pure PHP without framework dependencies. Works in Laravel, WordPress, or any PHP app.

  • Fully Typed & Exception-Driven Catch invalid responses, network failures, and API violations with structured exceptions.

  • Built-in Caching Automatically caches daily validation results in the OS temp folder to improve performance.

  • Custom Messaging & Views Show your own branded modal or custom message when a license is invalid.

πŸ“¦ Installation

Install via Composer

To install the DevPayr PHP SDK in your project, run the following command:

This will pull in the latest version of the SDK from Packagist and make it available for use in your PHP application.

πŸ“‹ Minimum Requirements

Before installing the SDK, ensure your environment meets the following requirements:

  • PHP 8.1 or higher

  • Composer 2.0+

  • OpenSSL extension enabled (used for secure decryption)

  • Either cURL or allow_url_fopen (for HTTP requests)

⚑ Quick Start

The DevPayr PHP SDK is designed for simple drop-in usage.

Below is a minimal working example that:

  1. Validates the license

  2. Checks if the project is paid

  3. Fetches and handles any associated injectables

This will automatically:

  • Validate the license

  • Check for active payment

  • Download and decrypt injectables (if enabled)

  • Handle failures based on your configuration

πŸ›  Configuration Options

The DevPayr::bootstrap() method accepts a flexible configuration array that tailors how validation, payment enforcement, and injectables are handled.

βœ… Required Keys

Key
Type
Description

base_url

string

The base API URL (defaults to https://api.devpayr.com/api/v1/)

secret

string

The secret key used to decrypt injectables (this is created when you add an injectable)


🧰 Optional Keys (with Defaults)

Key
Type
Default
Description

recheck

bool

true

Revalidate license on every load (false enables caching)

injectables

bool

true

Whether to fetch injectables from the server

injectablesVerify

bool

true

Verify HMAC signature on injectables

injectablesPath

string|null

null

Directory where injectables are saved (default: system temp path)

invalidBehavior

string

'modal'

Behavior on invalid license: modal, redirect, log, silent

redirectUrl

string|null

null

Redirect URL on invalid license (used when invalidBehavior = redirect)

timeout

int

1000

Request timeout in milliseconds

action

string

'check_project'

Action passed to DevPayr (for tracking/analytics)

onReady

callable|null

null

Callback function executed on successful license validation

handleInjectables

bool

false

If true, SDK will auto-process injectables into your file system

injectablesProcessor

string|null

null

Fully qualified class name to handle injectable processing manually

customInvalidView

string|null

null

Absolute path to your custom HTML view to show on license failure

customInvalidMessage

string

'This copy is not licensed for production use.'

Message displayed on failure when no view is provided

license

string|null

null

License key for project-scoped validation

api_key

string|null

null

API key (global or project scoped) for backend operations

per_page

int|null

null

Number of items to return for paginated results (used in services)


πŸ”’ You only need to set what's relevant to your use-case. Defaults will handle most basic setups.

βš™οΈ Runtime Boot & Validation

The SDK provides a simple bootstrapping method to handle license validation, payment enforcement, and injectable fetching in one unified call.

βœ… DevPayr::bootstrap(array $config): void

This is the recommended entry point. It performs:

  1. License Key or API Key Detection (if not explicitly set)

  2. Domain Validation (if enforced via DevPayr)

  3. Project Payment Check

  4. Injectables Retrieval & (Optional) Processing

  5. Runtime Enforcement based on your invalidBehavior

πŸ“¦ Example Usage

This will block further execution automatically if the license is invalid or payment is not confirmed.

πŸ”’ License or API Key

DevPayr will always utilize license key when validating a project; however, for every other actions, the API Key would be required. Consult our Documentation for more information about this - DevPayr Doc

πŸ“₯ Injectables Handling

Injectables are encrypted files or snippets tied to a project or license, securely managed through the DevPayr platform. These could include:

  • Config files

  • HTML templates

  • Scripts or code snippets

  • Markdown docs

  • JSON configs

  • Custom logic modules

The SDK automatically fetches injectables during DevPayr::bootstrap() if the injectables option is true.

🧩 How It Works

When bootstrapping:

  1. The SDK requests injectables from DevPayr.

  2. They are decrypted using your provided secret key.

  3. If handleInjectables is enabled, each injectable is written to the target location based on its target_path, slug, and mode.

You may choose to either:

  • Let the SDK auto-handle them (handleInjectables => true)

  • Or define your own logic using a custom processor class


βš™οΈ Modes Supported

Each injectable supports a mode, which determines how it’s written:

Mode
Description

replace

Replaces the entire file with new content

append

Appends to the end of the target file

prepend

Prepends to the beginning of the file

inject

(Reserved for future support: marker-based)

inline_render

Intended for rendering, not saving

stream

Stream to output, not saved

Others

Default to replace


πŸ“‚ File Types

Injectables support multiple types including:

  • file

  • snippet

  • html, markdown, css, json, config

  • sdk_module, template, docs, component, etc.

Only file types support actual file uploads. Others are content-based.


πŸ›  Custom Injectable Processor (Optional)

If you need to control how injectables are stored (e.g. save to DB, S3, cache, etc), define a custom processor class, which implements the InjectableProcessorInterface contract

Then reference it in config:

πŸ” Handling License Failure

When a license is invalid, expired, unverified, or the associated project has not paid, the SDK halts normal execution and responds according to the invalidBehavior config option.

You can choose what happens in such scenarios using:

🎭 Supported Behaviors

Behavior
Description

modal

Displays a branded HTML message or modal (default)

redirect

Redirects the user to a custom URL

log

Logs the failure to error_log() or stdout (if applicable)

silent

Fails silently β€” no output, just skips execution

🧩 Additional Options

You can configure fallback behaviors further:

Config Key
Description

redirectUrl

Where to redirect when behavior is redirect

customInvalidMessage

Message to display when using the default modal view

customInvalidView

Path to your own custom HTML to show instead of the default unlicensed.html

Example:

πŸ’‘ Pro Tip

You can also define an onReady() callback that will only run if validation passes:

🧰 Available Services

DevPayr provides dedicated service classes for working with various parts of your licensing system β€” including projects, licenses, domains, injectables, and payment verification.

Each service class can be used independently or accessed via the DevPayr:: static methods after bootstrap().

βœ… Accessing Services After Bootstrapping

Once you've bootstrapped with a valid configuration:

Each of these returns a strongly typed service class:

Service
Class
Description

DevPayr::projects()

ProjectService

Manage projects: list, create, update, delete

DevPayr::licenses()

LicenseService

Create, revoke, or validate license keys

DevPayr::domains()

DomainService

Manage domain restrictions for your projects

DevPayr::injectables()

InjectableService

Fetch and manage encrypted injectables

DevPayr::payments()

PaymentService

Check payment status for licenses or projects

🧠 These services are authenticated using the same config object passed to DevPayr::bootstrap(). You can also instantiate them manually if needed.

πŸ“¦ Service API Examples

Below are real-world examples of how to use each core service within the DevPayr SDK to interact with your projects, licenses, domains, injectables, and payment status.


πŸ”Ή ProjectService

πŸ”Ή LicenseService

πŸ”Ή DomainService

πŸ”Ή InjectableService

πŸ”Ή PaymentService

These examples show how you can build powerful integrations and admin tools around your software licensing β€” right from your own dashboard or script.

🧩 Custom Injectable Processor

DevPayr allows you to define your own injectable processor β€” so you can decide what to do with each decrypted file (e.g. store in memory, write to disk, upload to cloud).

Instead of using the default file-based processor, you can implement the following interface:

🧱 Example: Create Your Custom Processor

βš™οΈ Registering Your Processor

Pass your class via the injectablesProcessor config key:

πŸ’‘ Use Cases

Here are some ways you can use a custom injectable processor:

  • βœ… Save injectables to memory or cache (e.g. Redis, Memcached)

  • ☁️ Upload injectables to cloud storage (e.g. AWS S3, Dropbox)

  • πŸ”„ Dynamically inject content into application runtime

  • πŸ–ΌοΈ Render injectables directly in views or templates

πŸ”„ Note: This method is invoked per injectable, allowing you to handle each file individually and flexibly.

❗ Error Handling

The DevPayr PHP SDK uses structured exceptions to help you handle issues like license failure, API errors, and decryption problems gracefully.

πŸ”Ή Common Exceptions

Exception
Description

DevPayrException

Base exception for all SDK-related logic or configuration errors

ApiResponseException

Thrown when the DevPayr API returns an error, bad payload, or HTTP failure

βœ… Both exceptions implement standard PHP \Throwable, so you can catch them with try/catch.


πŸ”Έ Example: Catching Runtime Errors

βš™οΈ Advanced Usage

For developers building more dynamic or complex applications, the DevPayr PHP SDK provides several advanced options for customization and integration.


πŸ” Enable/Disable Revalidation

By default, DevPayr caches validation results for a short period (using your OS temp folder) to avoid repeated network requests.

You can disable rechecking and force revalidation on every boot:

πŸ“¦ Custom Injectables Folder

By default, injectables are saved to the system temp folder. You can change where they’re stored:

🧩 Handle Injectables Yourself

If you want full control over how injectables are stored or interpreted:

πŸ’‘ See Custom Injectable Processor for how to define your own handler.

🧠 Runtime Callback (onReady)

Run custom logic only if validation succeeds:

πŸ” License Key vs API Key

πŸ” You can use either:

  • license: Runtime key for validation and injectables (best for public or distributed software).

  • api_key: Authenticated API access (for listing, creating, managing resources via backend).

βœ… Both can be used separately or together, depending on your need .

Last updated