Security Best Practices

Guidelines for securing your EcobankPay integration

Overview

Security is a critical aspect of any payment integration. This guide covers key security best practices for integrating with EcobankPay, focusing on:

  • API authentication and validation
  • Secure hash implementation
  • Safe credential management
  • Transaction verification
  • Secure communication

API Authentication

EcobankPay uses a combination of API keys and secure hashing to authenticate requests:

Merchant Key Management

  • Your Merchant Key uniquely identifies your account with EcobankPay
  • Never share your Merchant Key in public client-side code or repositories
  • Store your Merchant Key in secure environment variables or a configuration management system
  • Rotate your keys immediately if they are compromised

Secure Hash Implementation (HMAC)

The secure_hash parameter is critical for ensuring the integrity of your API requests:

StepDescription
1Sort all request parameters alphabetically by parameter name
2Concatenate the key-value pairs in the format "key1=value1&key2=value2"
3Create an HMAC SHA-256 hash using your Merchant Secret as the key
4Convert the hash to a hexadecimal string
5Include this value as the secure_hash parameter in your request

Example HMAC Implementation:

// Sample Node.js HMAC implementation
const crypto = require('crypto');

function generateSecureHash(params, merchantSecret) {
  // 1. Remove secure_hash if it exists in the params
  const { secure_hash, ...restParams } = params;

  // 2. Sort parameters alphabetically
  const sortedParams = Object.keys(restParams).sort().reduce(
    (obj, key) => {
      obj[key] = restParams[key];
      return obj;
    },
    {}
  );

  // 3. Create parameter string
  const paramString = Object.entries(sortedParams)
    .map(([key, value]) => `${key}=${value}`)
    .join('&');

  // 4. Create HMAC SHA-256 hash
  const hmac = crypto.createHmac('sha256', merchantSecret);
  hmac.update(paramString);

  // 5. Return hex digest
  return hmac.digest('hex');
}

Secure Storage of Credentials

Follow these practices for securely storing your EcobankPay credentials:

  • Never hardcode Merchant Keys or Secrets in your application code
  • Use environment variables, encrypted configuration files, or a secure vault service
  • Implement proper access controls to limit who can access these credentials
  • Avoid storing credentials in version control systems
  • Consider using a secrets management service like AWS Secrets Manager, HashiCorp Vault, or Azure Key Vault

Environment Variables Example:

Use environment variables to securely store your credentials:

# .env file (not committed to version control)
ECOBANKPAY_MERCHANT_KEY=abcdef1234-f5d6-4931-8544-58dc97a5
ECOBANKPAY_MERCHANT_SECRET=your-merchant-secret

# In your application
const merchantKey = process.env.ECOBANKPAY_MERCHANT_KEY;
const merchantSecret = process.env.ECOBANKPAY_MERCHANT_SECRET;

Transaction Verification

Always verify transaction statuses to prevent fraud and ensure payment completion:

  • Double-check payment status: Always verify payment status through the status check endpoint before fulfilling orders
  • Don't rely solely on IPN: Instant Payment Notifications (IPNs) should be treated as prompts to check status, not as confirmation
  • Validate IPN requests: Verify that IPN notifications are genuine by checking their origin and content
  • Implement idempotency: Ensure your system can handle repeated notifications for the same transaction without duplicate processing

Status Check Endpoint:

GET https://pgw.paywithonline.com/v1/gateway/json_status_chk?invoice_id=INV12345&merchant_key=YOUR_MERCHANT_KEY

Secure Communication

Ensure all communication with EcobankPay's API is secured:

  • Always use HTTPS: Never make API calls over unencrypted HTTP
  • Validate SSL certificates: Ensure your client verifies SSL certificates to prevent man-in-the-middle attacks
  • Set reasonable timeouts: Configure appropriate connection and request timeouts
  • Implement retry logic: Use exponential backoff for retries in case of network failures

TLS Implementation:

Always verify TLS certificates and use modern TLS versions (TLS 1.2 or later):

// Node.js example with Axios
const axios = require('axios');

const apiClient = axios.create({
  baseURL: 'https://pgw.paywithonline.com/v1',
  timeout: 10000,
  headers: {
    'Content-Type': 'application/json'
  },
  // Enforce certificate validation
  httpsAgent: new https.Agent({
    rejectUnauthorized: true
  })
});

Additional Security Measures

Request Validation

  • Validate all inputs before sending them to EcobankPay
  • Implement proper data sanitization to prevent injection attacks
  • Verify that invoice IDs are unique to prevent duplicate charges
  • Validate amount ranges to prevent unusually small or large transactions

Logging and Monitoring

  • Implement comprehensive logging for all payment operations
  • Monitor for unusual transaction patterns that might indicate fraud
  • Log API request and response metadata, but never log sensitive data like card details
  • Set up alerts for failed transactions, authentication errors, or unusual activity

PCI Compliance Considerations

  • Use EcobankPay's hosted checkout pages to minimize PCI DSS compliance requirements
  • Never store, log, or transmit full card details in your systems
  • For direct card integrations, ensure your systems comply with PCI DSS requirements
  • Regularly review and update your security measures to maintain compliance

Security Checklist

Use this checklist to ensure your EcobankPay integration is secure:

CategorySecurity Measure
AuthenticationCorrectly implement HMAC SHA-256 for all requests
Credential StorageStore API keys and secrets securely using environment variables or a vault service
Transaction VerificationVerify all transactions through the status check endpoint
CommunicationUse HTTPS for all API calls with proper certificate validation
Input ValidationValidate and sanitize all user inputs
LoggingImplement secure logging that excludes sensitive data
Error HandlingImplement proper error handling without exposing sensitive details
MonitoringSet up alerts for unusual transaction patterns