Accepting Payments - Integration Guide
Complete step-by-step integration for production
Accepting Payments Integration Guide
This comprehensive guide walks you through integrating payment acceptance into your application for production use.
Prerequisites
Before you begin:
- API credentials (key, secret, organizationId, merchantId)
- Webhook endpoint configured (recommended)
- Test environment access
- Understanding of Core Concepts
- Familiarity with Order Types
Integration Overview
Step 1: Authenticate
Obtain an access token for all subsequent requests:
Response:
Token Management: Tokens expire after 1 hour. Implement token caching and refresh logic in production.
Production Token Management
Step 2: Get Available Payment Methods
Query which payment methods are available for your target country and currency:
Caching: Cache payment methods per country/currency to reduce API calls. Methods don’t change frequently.
Step 3: Create Contact (Optional but Recommended)
Create a contact for the customer to track payment history and meet compliance requirements:
Document Types by Country
Complete document types reference →
Step 4: Create PAYIN Order
Create the payment order with all required details:
Response:
Payment URL Generated: The paymentUrl is where you should redirect your customer to complete the payment.
Step 5: Redirect Customer to Payment
Send the customer to the payment URL:
Step 6: Handle Webhooks
Listen for webhook events to track payment status:
Critical: Always verify webhook signatures to ensure the webhook is from Koywe.
Step 7: Check Order Status (Alternative/Supplement to Webhooks)
Query order status directly if needed:
Response:
Complete Integration Example
Here’s a full end-to-end example:
Error Handling
Common Errors and Solutions
Insufficient Balance
Invalid Payment Method
Invalid Document
Expired Token
Complete error handling guide →
Testing
Test your integration in sandbox:
Production Checklist
Before going live:
- Change to production URL (
https://api.koywe.com) - Update to production API credentials
- Implement webhook signature verification
- Setup error logging and monitoring
- Test with small real amounts
- Implement token caching and refresh
- Setup retry logic for transient failures
- Configure proper timeout values
- Implement idempotency with
externalId - Test all payment methods you’ll support