SDK Integration Guide
Complete guide to integrating OpenDev SDKs across different platforms.
Overview
OpenDev provides SDKs for multiple platforms to simplify integration with authentication and payment services.
Platform Support Matrix
| Platform | Auth | Payment | Min Version |
|---|---|---|---|
| iOS | ✅ | ✅ | iOS 12.0+ |
| Android | ✅ | ✅ | API 21+ |
| Windows | ✅ | ✅ | Windows 10+ |
| macOS | ✅ | ✅ | macOS 10.14+ |
| Web | ✅ | ✅ | ES6+ browsers |
| Server | ✅ | ✅ | Node 14+ |
iOS Integration
Installation
Swift Package Manager:
dependencies: [
.package(url: "https://github.com/opendev/ios-sdk.git", from: "1.0.0")
]
CocoaPods:
pod 'OpenDevSDK', '~> 1.0'
Initialization
import OpenDevSDK
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Initialize SDK
OpenDev.configure(
appId: "your-app-id",
channelId: "your-channel-id",
environment: .production
)
return true
}
}
OAuth Authentication
// Google Sign-In
OpenDev.auth.signIn(provider: .google) { result in
switch result {
case .success(let user):
print("Logged in as: \(user.email)")
case .failure(let error):
print("Login failed: \(error)")
}
}
// Apple Sign-In
OpenDev.auth.signIn(provider: .apple) { result in
// Handle result
}
In-App Purchase
// Fetch products
OpenDev.payment.fetchProducts(ids: ["premium_monthly", "premium_yearly"]) { products in
// Display products to user
}
// Purchase
OpenDev.payment.purchase(productId: "premium_monthly") { result in
switch result {
case .success(let transaction):
print("Purchase successful: \(transaction.id)")
case .failure(let error):
print("Purchase failed: \(error)")
}
}
// Restore purchases
OpenDev.payment.restorePurchases { result in
// Handle restored purchases
}
Android Integration
Installation
Gradle:
dependencies {
implementation 'com.opendev:sdk:1.0.0'
}
Initialization
import com.opendev.sdk.OpenDev
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
OpenDev.configure(
context = this,
appId = "your-app-id",
channelId = "your-channel-id",
environment = OpenDev.Environment.PRODUCTION
)
}
}
OAuth Authentication
// Google Sign-In
OpenDev.auth.signIn(
activity = this,
provider = AuthProvider.GOOGLE
) { result ->
result.onSuccess { user ->
Log.d("Auth", "Logged in as: ${user.email}")
}.onFailure { error ->
Log.e("Auth", "Login failed: ${error.message}")
}
}
// WeChat Sign-In
OpenDev.auth.signIn(
activity = this,
provider = AuthProvider.WECHAT
) { result ->
// Handle result
}
Google Play Billing
// Fetch products
OpenDev.payment.fetchProducts(
productIds = listOf("premium_monthly", "premium_yearly")
) { products ->
// Display products
}
// Purchase
OpenDev.payment.purchase(
activity = this,
productId = "premium_monthly"
) { result ->
result.onSuccess { transaction ->
Log.d("Payment", "Purchase successful: ${transaction.id}")
}
}
Web Integration
Installation
NPM:
npm install @opendev/web-sdk
CDN:
<script src="https://cdn.opendev.com/sdk/web/1.0.0/opendev.min.js"></script>
Initialization
import OpenDev from '@opendev/web-sdk';
OpenDev.configure({
appId: 'your-app-id',
channelId: 'your-channel-id',
environment: 'production'
});
OAuth Authentication
// Google Sign-In
document.getElementById('google-login').addEventListener('click', async () => {
try {
const user = await OpenDev.auth.signIn('google');
console.log('Logged in as:', user.email);
} catch (error) {
console.error('Login failed:', error);
}
});
// Handle OAuth callback
OpenDev.auth.handleCallback().then(user => {
if (user) {
console.log('OAuth callback successful');
}
});
Stripe Payment
// Initialize payment
const payment = await OpenDev.payment.createSession({
productId: 'premium_monthly',
successUrl: window.location.origin + '/success',
cancelUrl: window.location.origin + '/cancel'
});
// Redirect to checkout
window.location.href = payment.checkoutUrl;
Server Integration
Installation
Node.js:
npm install @opendev/server-sdk
Python:
pip install opendev-sdk
Node.js Usage
const OpenDev = require('@opendev/server-sdk');
const client = new OpenDev({
apiKey: process.env.OPENDEV_API_KEY,
apiSecret: process.env.OPENDEV_API_SECRET
});
// Verify user token
app.get('/api/user', async (req, res) => {
const token = req.headers.authorization?.split(' ')[1];
try {
const user = await client.auth.verifyToken(token);
res.json({ user });
} catch (error) {
res.status(401).json({ error: 'Invalid token' });
}
});
// Verify purchase
app.post('/api/verify-purchase', async (req, res) => {
const { receiptData, platform } = req.body;
try {
const result = await client.payment.verifyPurchase({
receiptData,
platform
});
res.json(result);
} catch (error) {
res.status(400).json({ error: error.message });
}
});
Python Usage
from opendev import OpenDev
client = OpenDev(
api_key=os.environ['OPENDEV_API_KEY'],
api_secret=os.environ['OPENDEV_API_SECRET']
)
# Verify token
@app.route('/api/user')
def get_user():
token = request.headers.get('Authorization', '').replace('Bearer ', '')
try:
user = client.auth.verify_token(token)
return jsonify(user)
except Exception as e:
return jsonify({'error': str(e)}), 401
Configuration Management
Configuration File Format
{
"appId": "your-app-id",
"channelId": "your-channel-id",
"environment": "production",
"auth": {
"providers": ["google", "apple", "wechat"],
"autoRefreshToken": true,
"tokenRefreshThreshold": 300
},
"payment": {
"providers": ["stripe", "apple_iap", "google_play"],
"currency": "USD"
},
"logging": {
"level": "info",
"enableCrashReporting": true
}
}
Dynamic Configuration
// Fetch latest configuration
const config = await OpenDev.config.fetch();
// Check feature flags
if (config.features.newPaymentFlow) {
// Use new payment flow
}
// Listen for config updates
OpenDev.config.onUpdate((newConfig) => {
console.log('Configuration updated');
});
Error Handling
Error Codes
| Code | Description | Action |
|---|---|---|
AUTH_EXPIRED |
Token expired | Refresh token or re-login |
AUTH_INVALID |
Invalid credentials | Check configuration |
PAYMENT_DECLINED |
Payment declined | Show user-friendly message |
PAYMENT_CANCELLED |
User cancelled | Allow retry |
NETWORK_ERROR |
Network issue | Retry with backoff |
CONFIG_ERROR |
Configuration error | Check app setup |
Error Handling Pattern
try {
await OpenDev.auth.signIn('google');
} catch (error) {
switch (error.code) {
case 'AUTH_CANCELLED':
// User cancelled, do nothing
break;
case 'AUTH_NETWORK_ERROR':
showError('Please check your internet connection');
break;
case 'AUTH_INVALID_CONFIG':
console.error('SDK configuration error');
break;
default:
showError('An unexpected error occurred');
reportError(error);
}
}
Debugging
Enable Debug Mode
OpenDev.configure({
appId: 'your-app-id',
debug: true, // Enable debug logging
logLevel: 'verbose'
});
Debug Console
// View SDK state
console.log(OpenDev.debug.getState());
// View pending operations
console.log(OpenDev.debug.getPendingOperations());
// Force token refresh
await OpenDev.debug.forceTokenRefresh();
Migration Guide
From v0.x to v1.x
Breaking Changes:
OpenDev.init()renamed toOpenDev.configure()- Callback-based APIs now return Promises
- Error codes standardized
Migration Steps:
// Before (v0.x)
OpenDev.init({ appId: 'xxx' });
OpenDev.auth.login('google', (err, user) => {
if (err) handleError(err);
else handleUser(user);
});
// After (v1.x)
OpenDev.configure({ appId: 'xxx' });
try {
const user = await OpenDev.auth.signIn('google');
handleUser(user);
} catch (error) {
handleError(error);
}
Last updated: January 2026