|
| 1 | +# n8n Integration Guide |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This guide provides comprehensive instructions for integrating SVM-Pay with n8n, a powerful workflow automation platform. With this integration, you can automate payment workflows, handle complex business logic, and integrate cryptocurrency payments seamlessly into your existing automation processes. |
| 6 | + |
| 7 | +## What is n8n? |
| 8 | + |
| 9 | +n8n is an open-source workflow automation tool that allows you to connect different services and automate tasks. It provides a visual workflow editor and supports custom nodes for extending functionality. With the SVM-Pay integration, you can: |
| 10 | + |
| 11 | +- Automate payment processing based on external events |
| 12 | +- Create conditional payment workflows |
| 13 | +- Process bulk payments and transfers |
| 14 | +- Handle payment notifications and updates |
| 15 | +- Integrate with databases, APIs, and other services |
| 16 | + |
| 17 | +## Key Features |
| 18 | + |
| 19 | +### SVM-Pay Custom Nodes |
| 20 | + |
| 21 | +The integration includes several custom nodes: |
| 22 | + |
| 23 | +1. **SVM-Pay Node** - Main payment processing and wallet operations |
| 24 | +2. **SVM-Pay Webhook Node** - Handle payment events and notifications |
| 25 | +3. **SVM-Pay Batch Node** - Process multiple payments efficiently |
| 26 | +4. **SVM-Pay Credentials** - Secure credential management |
| 27 | + |
| 28 | +### Supported Operations |
| 29 | + |
| 30 | +- **Payment Processing**: Create payment requests, process direct payments, verify transactions |
| 31 | +- **Webhook Handling**: Receive and process real-time payment events |
| 32 | +- **Batch Operations**: Handle bulk payments, payroll distribution, airdrops |
| 33 | +- **Wallet Management**: Check balances, manage multiple wallets |
| 34 | +- **Token Operations**: Support for USDC, SOL, and custom tokens |
| 35 | + |
| 36 | +## Installation |
| 37 | + |
| 38 | +### Prerequisites |
| 39 | + |
| 40 | +- n8n installed (locally or cloud) |
| 41 | +- Node.js 16+ (for local development) |
| 42 | +- SVM-Pay account and API credentials |
| 43 | +- Basic understanding of workflow automation |
| 44 | + |
| 45 | +### Installing Custom Nodes |
| 46 | + |
| 47 | +1. **Create Node Package**: |
| 48 | +```bash |
| 49 | +mkdir n8n-nodes-svm-pay |
| 50 | +cd n8n-nodes-svm-pay |
| 51 | +npm init -y |
| 52 | +``` |
| 53 | + |
| 54 | +2. **Install Dependencies**: |
| 55 | +```bash |
| 56 | +npm install --save n8n-workflow n8n-core @svm-pay/sdk |
| 57 | +npm install --save-dev typescript @types/node |
| 58 | +``` |
| 59 | + |
| 60 | +3. **Build and Install**: |
| 61 | +```bash |
| 62 | +npm run build |
| 63 | +npm install -g . |
| 64 | +``` |
| 65 | + |
| 66 | +4. **Restart n8n**: |
| 67 | +```bash |
| 68 | +n8n start |
| 69 | +``` |
| 70 | + |
| 71 | +## Configuration |
| 72 | + |
| 73 | +### Setting Up Credentials |
| 74 | + |
| 75 | +1. In n8n, go to **Settings** > **Credentials** |
| 76 | +2. Click **Add Credential** and select **SVM-Pay API** |
| 77 | +3. Configure the following: |
| 78 | + - **Environment**: Choose between Mainnet and Devnet |
| 79 | + - **Private Key**: Your wallet private key (base58 format) |
| 80 | + - **API Key**: Optional API key for enhanced features |
| 81 | + - **Default Token**: Default token for payments (e.g., USDC) |
| 82 | + - **Webhook Secret**: Secret for webhook verification |
| 83 | + |
| 84 | +### Environment Variables |
| 85 | + |
| 86 | +For production deployments, set these environment variables: |
| 87 | + |
| 88 | +```bash |
| 89 | +# SVM-Pay Configuration |
| 90 | +SVMPAY_ENVIRONMENT=mainnet |
| 91 | +SVMPAY_PRIVATE_KEY=your_private_key_here |
| 92 | +SVMPAY_API_KEY=your_api_key_here |
| 93 | +SVMPAY_WEBHOOK_SECRET=your_webhook_secret_here |
| 94 | + |
| 95 | +# n8n Configuration |
| 96 | +N8N_HOST=your-domain.com |
| 97 | +N8N_PROTOCOL=https |
| 98 | +WEBHOOK_URL=https://your-domain.com/webhook |
| 99 | +``` |
| 100 | + |
| 101 | +## Common Use Cases |
| 102 | + |
| 103 | +### 1. E-commerce Order Processing |
| 104 | + |
| 105 | +Automate payment processing for online stores: |
| 106 | + |
| 107 | +```yaml |
| 108 | +Workflow: Order Payment Automation |
| 109 | +Trigger: Webhook (Order Created) |
| 110 | +Steps: |
| 111 | + 1. Validate order data |
| 112 | + 2. Create payment request |
| 113 | + 3. Send payment link to customer |
| 114 | + 4. Wait for payment confirmation |
| 115 | + 5. Update order status |
| 116 | + 6. Send confirmation email |
| 117 | +``` |
| 118 | +
|
| 119 | +### 2. Subscription Billing |
| 120 | +
|
| 121 | +Automate recurring subscription payments: |
| 122 | +
|
| 123 | +```yaml |
| 124 | +Workflow: Monthly Subscription Billing |
| 125 | +Trigger: Cron (Monthly) |
| 126 | +Steps: |
| 127 | + 1. Get active subscriptions from database |
| 128 | + 2. Process batch payments |
| 129 | + 3. Update billing dates |
| 130 | + 4. Handle failed payments |
| 131 | + 5. Send invoices and receipts |
| 132 | +``` |
| 133 | +
|
| 134 | +### 3. Payroll Distribution |
| 135 | +
|
| 136 | +Automate employee payroll payments: |
| 137 | +
|
| 138 | +```yaml |
| 139 | +Workflow: Payroll Processing |
| 140 | +Trigger: Manual/Scheduled |
| 141 | +Steps: |
| 142 | + 1. Load payroll data from HR system |
| 143 | + 2. Validate employee wallet addresses |
| 144 | + 3. Process batch transfers |
| 145 | + 4. Generate payroll reports |
| 146 | + 5. Notify employees of payment |
| 147 | +``` |
| 148 | +
|
| 149 | +### 4. Event-Driven Payments |
| 150 | +
|
| 151 | +Create conditional payment workflows: |
| 152 | +
|
| 153 | +```yaml |
| 154 | +Workflow: Conditional Payment Router |
| 155 | +Trigger: Payment Event Webhook |
| 156 | +Steps: |
| 157 | + 1. Receive payment event |
| 158 | + 2. Check payment amount and conditions |
| 159 | + 3. Route to appropriate handler |
| 160 | + 4. Execute business logic |
| 161 | + 5. Send notifications |
| 162 | +``` |
| 163 | +
|
| 164 | +## Advanced Features |
| 165 | +
|
| 166 | +### Batch Processing |
| 167 | +
|
| 168 | +The SVM-Pay Batch node supports several batch operations: |
| 169 | +
|
| 170 | +- **Batch Payments**: Process multiple payments in optimized batches |
| 171 | +- **Bulk Transfers**: Send transfers to multiple recipients |
| 172 | +- **Payroll Distribution**: Handle employee payments with metadata |
| 173 | +- **Airdrop Campaigns**: Distribute tokens to community members |
| 174 | +
|
| 175 | +### Error Handling |
| 176 | +
|
| 177 | +Implement robust error handling: |
| 178 | +
|
| 179 | +- **Continue on Error**: Process remaining items if some fail |
| 180 | +- **Retry Logic**: Automatic retry with exponential backoff |
| 181 | +- **Error Notifications**: Alert administrators of failures |
| 182 | +- **Grace Periods**: Handle temporary payment failures |
| 183 | +
|
| 184 | +### Monitoring and Analytics |
| 185 | +
|
| 186 | +Track workflow performance: |
| 187 | +
|
| 188 | +- **Execution Metrics**: Monitor success rates and timing |
| 189 | +- **Payment Analytics**: Track volumes and patterns |
| 190 | +- **Error Tracking**: Identify and resolve issues quickly |
| 191 | +- **Performance Optimization**: Optimize batch sizes and timing |
| 192 | +
|
| 193 | +## Security Best Practices |
| 194 | +
|
| 195 | +### Credential Management |
| 196 | +
|
| 197 | +- Store private keys securely using n8n's credential system |
| 198 | +- Use environment variables for production deployments |
| 199 | +- Rotate API keys and webhook secrets regularly |
| 200 | +- Implement proper access controls |
| 201 | +
|
| 202 | +### Webhook Security |
| 203 | +
|
| 204 | +- Always verify webhook signatures |
| 205 | +- Use HTTPS for all webhook endpoints |
| 206 | +- Implement rate limiting and throttling |
| 207 | +- Log and monitor webhook activity |
| 208 | +
|
| 209 | +### Network Security |
| 210 | +
|
| 211 | +- Use secure networks (Mainnet for production) |
| 212 | +- Implement proper firewall rules |
| 213 | +- Monitor for unusual activity |
| 214 | +- Keep n8n and dependencies updated |
| 215 | +
|
| 216 | +## Troubleshooting |
| 217 | +
|
| 218 | +### Common Issues |
| 219 | +
|
| 220 | +1. **Connection Errors**: |
| 221 | + - Verify network configuration |
| 222 | + - Check API endpoints and credentials |
| 223 | + - Ensure proper firewall settings |
| 224 | +
|
| 225 | +2. **Payment Failures**: |
| 226 | + - Verify wallet balances |
| 227 | + - Check token configurations |
| 228 | + - Review transaction limits |
| 229 | +
|
| 230 | +3. **Webhook Issues**: |
| 231 | + - Verify webhook URLs and secrets |
| 232 | + - Check n8n webhook configuration |
| 233 | + - Monitor webhook logs |
| 234 | +
|
| 235 | +4. **Performance Issues**: |
| 236 | + - Optimize batch sizes |
| 237 | + - Implement proper delays |
| 238 | + - Monitor resource usage |
| 239 | +
|
| 240 | +### Debug Mode |
| 241 | +
|
| 242 | +Enable debug logging for troubleshooting: |
| 243 | +
|
| 244 | +```bash |
| 245 | +N8N_LOG_LEVEL=debug n8n start |
| 246 | +``` |
| 247 | + |
| 248 | +### Support Resources |
| 249 | + |
| 250 | +- **Documentation**: [SVM-Pay Docs](https://docs.svm-pay.dev) |
| 251 | +- **n8n Community**: [n8n Community Forum](https://community.n8n.io) |
| 252 | +- **GitHub Issues**: [SVM-Pay GitHub](https://github.com/openSVM/svm-pay/issues) |
| 253 | +- **Discord**: [SVM-Pay Discord](https://discord.gg/svm-pay) |
| 254 | + |
| 255 | +## Examples and Templates |
| 256 | + |
| 257 | +### Basic Payment Workflow |
| 258 | + |
| 259 | +```json |
| 260 | +{ |
| 261 | + "name": "Basic Payment Processing", |
| 262 | + "nodes": [ |
| 263 | + { |
| 264 | + "name": "Payment Trigger", |
| 265 | + "type": "svmPayWebhook", |
| 266 | + "parameters": { |
| 267 | + "eventTypes": ["payment.pending"] |
| 268 | + } |
| 269 | + }, |
| 270 | + { |
| 271 | + "name": "Process Payment", |
| 272 | + "type": "svmPay", |
| 273 | + "parameters": { |
| 274 | + "resource": "payment", |
| 275 | + "operation": "processPayment" |
| 276 | + } |
| 277 | + }, |
| 278 | + { |
| 279 | + "name": "Send Confirmation", |
| 280 | + "type": "n8n-nodes-base.emailSend", |
| 281 | + "parameters": { |
| 282 | + "subject": "Payment Confirmed" |
| 283 | + } |
| 284 | + } |
| 285 | + ] |
| 286 | +} |
| 287 | +``` |
| 288 | + |
| 289 | +### Batch Payment Template |
| 290 | + |
| 291 | +```json |
| 292 | +{ |
| 293 | + "name": "Bulk Payment Distribution", |
| 294 | + "nodes": [ |
| 295 | + { |
| 296 | + "name": "Load Payment Data", |
| 297 | + "type": "n8n-nodes-base.postgres", |
| 298 | + "parameters": { |
| 299 | + "query": "SELECT * FROM pending_payments" |
| 300 | + } |
| 301 | + }, |
| 302 | + { |
| 303 | + "name": "Process Batch", |
| 304 | + "type": "svmPayBatch", |
| 305 | + "parameters": { |
| 306 | + "operation": "batchPayments", |
| 307 | + "batchSize": 20 |
| 308 | + } |
| 309 | + }, |
| 310 | + { |
| 311 | + "name": "Update Database", |
| 312 | + "type": "n8n-nodes-base.postgres", |
| 313 | + "parameters": { |
| 314 | + "query": "UPDATE payments SET status = 'completed'" |
| 315 | + } |
| 316 | + } |
| 317 | + ] |
| 318 | +} |
| 319 | +``` |
| 320 | + |
| 321 | +## Migration Guide |
| 322 | + |
| 323 | +### From Manual Processes |
| 324 | + |
| 325 | +1. **Identify Automation Opportunities**: Review current manual payment processes |
| 326 | +2. **Design Workflows**: Create n8n workflows for each process |
| 327 | +3. **Test in Devnet**: Thoroughly test all workflows |
| 328 | +4. **Gradual Migration**: Migrate processes incrementally |
| 329 | +5. **Monitor and Optimize**: Continuously improve workflows |
| 330 | + |
| 331 | +### From Other Platforms |
| 332 | + |
| 333 | +1. **Export Existing Workflows**: Export configurations from current platform |
| 334 | +2. **Map to n8n Nodes**: Identify equivalent n8n nodes and operations |
| 335 | +3. **Recreate Workflows**: Build new workflows in n8n |
| 336 | +4. **Data Migration**: Migrate any stored data or configurations |
| 337 | +5. **Testing and Validation**: Ensure all functionality works correctly |
| 338 | + |
| 339 | +## Conclusion |
| 340 | + |
| 341 | +The SVM-Pay n8n integration provides a powerful platform for automating cryptocurrency payment workflows. With custom nodes, comprehensive error handling, and extensive monitoring capabilities, you can build robust payment automation systems that scale with your business needs. |
| 342 | + |
| 343 | +For additional support and advanced use cases, refer to the main SVM-Pay documentation and join our community channels. |
0 commit comments