Testing Your Integration
Learn how to test your BLAQPAY integration safely
Testing Your Integration
BLAQPAY provides a comprehensive testing environment so you can develop and test your integration without using real money or cryptocurrency.
Test Mode vs Live Mode
BLAQPAY uses a single API endpoint with different behavior based on your API key:
Test Mode
- Use for development and testing
- No real money or crypto involved
- Transactions marked as
testing_mode: true - Use testnet tokens (Sepolia, Mumbai, BSC Testnet, etc.)
- API keys start with
sk_test_ - API endpoint:
https://blaqpay.io/api
Live Mode (Production)
- Use for real transactions
- Real money and cryptocurrency
- Transactions marked as
testing_mode: false - Use mainnet tokens
- API keys start with
sk_live_ - API endpoint:
https://blaqpay.io/api(same endpoint)
Getting Test API Keys
- Log in to your Dashboard
- Navigate to your project settings
- Your API key will start with
sk_test_for test projects - Copy your test key
# Test key
BLAQPAY_API_KEY=sk_test_xyz789... Creating Test Payments
Test payments work exactly like live payments:
const response = await fetch('https://blaqpay.io/api/transactions/create', {
method: 'POST',
headers: {
'Authorization': 'Bearer sk_test_YOUR_TEST_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
amount: 100.0,
customer_email: 'test@example.com',
order_description: 'Test payment'
})
});
const { payment_url } = await response.json();
console.log('Test payment URL:', payment_url); Test Payment Behavior
Testing with Testnet Tokens
In test mode, transactions use testnet blockchains:
- Ethereum Sepolia: Test ETH and ERC-20 tokens
- Polygon Mumbai: Test MATIC and Polygon tokens
- BSC Testnet: Test BNB and BEP-20 tokens
Get testnet tokens from faucets:
- Sepolia: https://sepoliafaucet.com
- Mumbai: https://faucet.polygon.technology
- BSC Testnet: https://testnet.bnbchain.org/faucet-smart
Testing Different Scenarios
Successful Payment
// Create transaction
const response = await fetch('https://blaqpay.io/api/transactions/create', {
method: 'POST',
headers: {
'Authorization': 'Bearer sk_test_YOUR_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
amount: 100.0,
customer_email: 'test@example.com'
})
});
const { transaction, payment_url } = await response.json();
// Customer completes payment with testnet tokens
// Transaction will become 'completed' Expired Payment
// Create transaction with short expiration
const response = await fetch('https://blaqpay.io/api/transactions/create', {
method: 'POST',
headers: {
'Authorization': 'Bearer sk_test_YOUR_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
amount: 100.0,
expires_in_minutes: 5 // 5 minutes
})
});
// Wait for expiration
// Transaction will become 'expired' Testing Webhooks
Local Development
Use ngrok to receive webhooks locally:
# Install ngrok
npm install -g ngrok
# Start your local server
npm run dev
# Expose your server
ngrok http 3000
# Update webhook URL in Dashboard
https://abc123.ngrok.io/webhooks/blaqpay Webhook Logs
View webhook delivery logs in Dashboard:
- Go to Settings → Webhooks
- Select your webhook endpoint
- View Recent Deliveries
- See request/response details
Send Test Webhooks
Trigger test webhooks manually:
- Go to Settings → Webhooks
- Click Send Test Event
- Select event type
- Click Send
Verify Signatures
Test signature verification:
const crypto = require('crypto');
function testWebhookSignature() {
const payload = JSON.stringify({
event: 'transaction.completed',
transaction: {
id: 'test_123',
status: 'completed'
}
});
const signature = crypto
.createHmac('sha256', process.env.WEBHOOK_SECRET)
.update(payload)
.digest('hex');
// Test your verification function
const isValid = verifyWebhook(payload, signature, process.env.WEBHOOK_SECRET);
console.log('Signature valid:', isValid);
} Testing API Endpoints
Use the API Playground
Test API calls interactively:
- Visit API Playground
- Enter your test API key
- Select an endpoint
- Customize parameters
- Click “Try it”
cURL Commands
Test with cURL:
# Create transaction
curl -X POST https://blaqpay.io/api/transactions/create
-H "Authorization: Bearer sk_test_YOUR_KEY"
-H "Content-Type: application/json"
-d '{
"amount": 100.00,
"customer_email": "test@example.com"
}'
# Get transaction
curl https://blaqpay.io/api/transactions/TRANSACTION_ID
-H "Authorization: Bearer sk_test_YOUR_KEY"
# List transactions
curl https://blaqpay.io/api/transactions/project/PROJECT_ID
-H "Authorization: Bearer sk_test_YOUR_KEY" Testing Error Handling
Test Different Error Scenarios
// Invalid API key
try {
const response = await fetch('https://blaqpay.io/api/transactions/create', {
method: 'POST',
headers: {
'Authorization': 'Bearer sk_invalid_key',
'Content-Type': 'application/json'
},
body: JSON.stringify({ amount: 100 })
});
if (!response.ok) {
console.log('Auth error:', response.status);
}
} catch (error) {
console.log('Error:', error.message);
}
// Invalid amount
try {
const response = await fetch('https://blaqpay.io/api/transactions/create', {
method: 'POST',
headers: {
'Authorization': 'Bearer sk_test_YOUR_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({ amount: -10 }) // Invalid
});
if (!response.ok) {
const error = await response.json();
console.log('Validation error:', error.message);
}
} catch (error) {
console.log('Error:', error.message);
} Handle Rate Limits
// Test rate limiting behavior
async function testRateLimit() {
const promises = [];
// Send 100 requests quickly
for (let i = 0; i < 100; i++) {
const promise = fetch('https://blaqpay.io/api/transactions/project/PROJECT_ID', {
headers: {
'Authorization': 'Bearer sk_test_YOUR_KEY'
}
}).catch(e => e);
promises.push(promise);
}
const results = await Promise.all(promises);
const responses = results.filter(r => r.status);
const rateLimited = responses.filter((r) => r.status === 429);
console.log(`Rate limited: ${rateLimited.length}/${responses.length}`);
} Automated Testing
Unit Tests
// Jest example
describe('BLAQPAY Integration', () => {
let blaqpay;
beforeAll(() => {
blaqpay = new BlaqPay(process.env.BLAQPAY_TEST_KEY);
});
test('creates order successfully', async () => {
const order = await blaqpay.orders.create({
amount: 100.00,
currency: 'USD',
crypto_currency: 'BTC'
});
expect(order.id).toBeTruthy();
expect(order.status).toBe('pending');
expect(order.amount).toBe(100.00);
});
test('retrieves order by ID', async () => {
const created = await blaqpay.orders.create({ ... });
const retrieved = await blaqpay.orders.retrieve(created.id);
expect(retrieved.id).toBe(created.id);
});
test('handles invalid API key', async () => {
const invalid = new BlaqPay('sk_invalid');
await expect(
invalid.orders.list()
).rejects.toThrow('Invalid API key');
});
}); Integration Tests
// Test full payment flow
describe('Payment Flow', () => {
test('complete payment flow', async () => {
// 1. Create order
const order = await createOrder();
expect(order.status).toBe('pending');
// 2. Complete payment (in test mode)
await completeTestPayment(order.id);
// 3. Verify webhook received
const webhook = await waitForWebhook(order.id);
expect(webhook.type).toBe('order.completed');
// 4. Verify order status updated
const updated = await blaqpay.orders.retrieve(order.id);
expect(updated.status).toBe('completed');
});
}); Pre-Production Checklist
Before going live, verify:
- All test scenarios pass
- Webhooks are received and processed correctly
- Error handling works properly
- Transaction creation works
- Payment page displays correctly
- Mobile experience is good (responsive design)
- Database updates happen correctly
- Logging is in place
Going Live
When ready to go live:
- Get live API keys from Dashboard (starts with
sk_live_) - Update environment variables:
BLAQPAY_API_KEY=sk_live_YOUR_LIVE_KEY - Register live webhook URL in project settings
- Enable live mode in your application
- Test with small amounts first
- Monitor first transactions closely
Testing Tools
- API Playground: /docs/api-playground
- Request Logger: View in Dashboard
- Transaction Logs: Monitor all transactions in dashboard
Common Testing Issues
Webhooks Not Received
- Check ngrok is running
- Verify webhook URL is correct
- Check server logs for errors
- Ensure endpoint returns 200
Payments Don’t Complete
- Wait full 60 seconds in test mode
- Or use “Complete Payment” in Dashboard
- Check order hasn’t expired
Signature Verification Fails
- Use raw request body
- Check webhook secret is correct
- Verify header name is exact
Need Help?
- Try the API Playground
- Check the API Reference
- Email support@blaqpay.io
