devpayr-frontend-sdk
Version:
Frontend SDK for DevPayr license verification, payment enforcement, and injectable delivery.
207 lines (170 loc) β’ 6.29 kB
Markdown
for integrating **DevPayr** into your web or SaaS application. Use this SDK to verify license keys, enforce project-based payments, and load secure injectables dynamically.
---
You can either include the SDK directly in your HTML, or install it via `npm`/`yarn` for Node.js/ESM/CommonJS use.
```html
<script src="https://cdn.jsdelivr.net/npm/devpayr-frontend-sdk@latest/dist/devpayr-frontend.js"></script>
```
```bash
npm install devpayr-frontend-sdk
```
```js
// ESM
import 'devpayr-frontend-sdk';
// CommonJS
require('devpayr-frontend-sdk');
```
Before the SDK initializes, you must define a global config object in the browserβs `window` scope. This object allows the DevPayr SDK to read your license, configure behavior, and optionally handle secure injectables.
```html
<script>
window.myapp = {
license: 'YOUR_LICENSE_KEY', // Required
onReady: function () {
console.log('β
License verified.');
}
};
</script>
<script src="https://cdn.devpayr.com/devpayr-sdk.js"></script>
```
```html
<script>
window.myapp = {
license: 'LICENSE_ABC123',
invalidBehavior: 'modal',
debug: false
};
</script>
```
> This shows the default DevPayr modal with fallback messaging when license is invalid or expired.
```html
<script>
window.myapp = {
license: 'LICENSE_456DEF',
invalidBehavior: 'modal',
modalText: 'π« This application is not licensed. Please contact support.',
modalTheme: {
primary: '#10b981', // emerald
background: '#1a1a2e',
text: '#e0f2f1',
border: '#10b981',
glow: true
},
onReady: function () {
console.log('β
All good.');
}
};
</script>
```
> Customize modal appearance using modalTheme.
```html
<script>
window.myapp = {
license: 'LICENSE_XYZ789',
recheck: false,
onReady: function () {
console.log('π Cached license still valid.');
}
};
</script>
```
> This skips license verification after the first success, unless storage is cleared.
```html
<script>
window.myapp = {
license: 'LICENSE_REDIRECT',
invalidBehavior: 'redirect',
redirectUrl: 'https://yourapp.com/upgrade',
debug: true
};
</script>
```
> When license is invalid, users are redirected instead of seeing a modal.
```html
<script>
window.myapp = {
license: 'LICENSE_INJECT',
injectables: true,
injectablesEndpoint: 'https://yourapp.com/sdk/receive',
onReady: function () {
console.log('π License validated, injectables loading...');
}
};
</script>
```
> This sends retrieved injectables (if any) to your backend for secure use.
> π‘ **Tip:** You can name your global config variable anything β the SDK will automatically detect it
> as long as it contains a `license` or `lk` property. This helps you keep the SDK integration hidden
> or embedded in an existing namespace.
#### π§ Examples of custom config variable names
```html
<script>
window.sdkConfig = {
license: 'YOUR_LICENSE_KEY',
onReady: () => console.log('β
sdkConfig verified')
};
</script>
<script>
window._devSettings = {
lk: 'LICENSE_123ABC',
debug: true,
onReady: () => console.log('π _devSettings verified')
};
</script>
<script>
window.anythingYouWant = {
license: 'LICENSE_SOMETHING',
injectables: true,
onReady: () => console.log('π― anythingYouWant verified')
};
</script>
```
>The SDK will scan all global variables at runtime and automatically use the first object that has a
>valid license or lk key. No additional configuration is needed.
```js
import 'devpayr-frontend-sdk';
// Optionally inject config into window (for client detection)
window.devpayr = {
license: 'YOUR_LICENSE_KEY',
onReady: () => console.log('β
Verified')
};
```
```js
require('devpayr-frontend-sdk');
global.devpayr = {
license: 'YOUR_LICENSE_KEY',
injectables: true,
injectablesEndpoint: 'https://yourapp.com/sdk/receive'
};
```
- β
**Automatically detects** the license key from any global variable on the `window` scope.
- π **Verifies** the license against the DevPayr API in real-time.
- π§ **Caches** successful license checks using `localStorage` (with support for `recheck: false`).
- π« If the license is **invalid**:
- Shows a **modal** with customizable text and theme (`modalText`, `modalTheme`), or
- **Redirects** the user if `invalidBehavior: 'redirect'` is set.
- π If `injectables` are enabled:
- They are securely **forwarded** to your backend using the provided `injectablesEndpoint`.
> The SDK runs autonomously after being included β no need to manually call any methods.
## π‘ Notes
- π§© The global config key can be **named anything** (e.g., `window.myapp`, `window.licenseSettings`, etc.).
The SDK will automatically find the first object with a `license` or `lk` property.
- π« The SDK **only runs once** and gracefully exits if license validation fails. Whenever an error is encountered, it will display the modal
- π You can enable `debug: true` in your config to see detailed logs in the browser console.
## π« Contact & Support
For help, feedback, or integration support:
- π Visit: [https://devpayr.com](https://devpayr.com)
- π§ Email: [support@devpayr.com](mailto:support@devpayr.com)
The official JavaScript SDK