Card Payments Integration
Learn how to accept debit and credit card payments through EcobankPay
Supported Card Schemes
Overview
Card payment integration with EcobankPay allows your customers to make payments using their credit or debit cards. The integration process follows these general steps:
- Initialize a payment request to EcobankPay
- Redirect the customer to the EcobankPay secure payment page
- Customer enters card details and completes 3D Secure authentication if required
- EcobankPay processes the payment and notifies your application
- Verify the payment status using the status check endpoint
Integration Steps
1. Initiate Card Payment Request
To start a card payment, send a POST request to the EcobankPay card payment endpoint:
POST https://pgw.paywithonline.com/v1/card_paymentsThe request body must include the following required parameters:
| Parameter | Required | Description |
|---|---|---|
| merchant_key | Y | Your unique assigned Merchant Key |
| invoice_id | Y | Your internally generated transaction invoice ID (unique, max 25 chars) |
| total | Y | The total payment amount for the transaction |
| generate_checkout_url | Y | Set to 'true' to receive a hosted checkout page URL |
| secure_hash | Y | HMAC SHA-256 hash of sorted request parameters |
Optional parameters that enhance the payment experience:
| Parameter | Required | Description |
|---|---|---|
| number | N | Customer's phone number (for SMS notifications) |
| N | Customer's email address (for email notifications) | |
| name | N | Customer's name |
| description | N | Description of the payment or order details |
| success_url | N | URL to redirect customer after successful payment |
| cancelled_url | N | URL to redirect customer if payment is cancelled |
| ipn_url | N | URL for instant payment notifications |
2. Creating the Secure Hash
The secure_hash is critical for card transactions to ensure request integrity. Create it using these steps:
- Sort the request parameters alphabetically by parameter name
- Concatenate the parameter name-value pairs as name=value
- Apply HMAC SHA-256 using your merchant secret as the key
- Convert the result to a hexadecimal string
Example:
// Parameters (sorted alphabetically) description=Payment for Order #12345 invoice_id=INV12345 merchant_key=abcdef1234-f5d6-4931-8544-58dc97a5 total=10.00 // Concatenated string "invoice_id=INV12345&merchant_key=abcdef1234-f5d6-4931-8544-58dc97a5&total=10.00" // Apply HMAC SHA-256 with your merchant secret secure_hash = HMAC_SHA256(concatenated_string, merchant_secret)
Implementation Example:
You can find example hashing implementations at:
https://gist.github.com/jasny/2200937201863415ebd206fe0f7b74982e61863674a5c1d
3. Sample Request
Here's an example of a card payment request:
POST https://pgw.paywithonline.com/v1/card_payments
Content-Type: application/json
{
"merchant_key": "abcdef1234-f5d6-4931-8544-58dc97a5",
"invoice_id": "INV12345",
"total": 10.00,
"description": "Payment for Order #12345",
"email": "customer@example.com",
"number": "+233201234567",
"generate_checkout_url": true,
"success_url": "https://yourwebsite.com/payment/success",
"cancelled_url": "https://yourwebsite.com/payment/cancelled",
"ipn_url": "https://yourwebsite.com/api/payment-webhook",
"secure_hash": "d4f321f8fddd0e7cc24e5d9bc321ea5c25c6f05d44401f7fb0b9f2a3cc4c"
}4. Response Handling
Upon successful submission, you'll receive a JSON response with payment details:
{
"success": true,
"url": "https://pgw.paywithonline.com/checkout/7785598425589933",
"tx_reference": "ECO123456789",
"message": "Payment process initiated"
}The key parameters in the response:
- url: The checkout URL to redirect the customer to
- tx_reference: EcobankPay's unique transaction reference
- success: Indicates if the request was accepted (not payment completion)
5. Redirect the Customer
Redirect your customer to the URL provided in the response. This secure page will:
- Collect the customer's card details
- Implement 3D Secure verification if supported by the card issuer
- Process the payment and show the result to the customer
6. Payment Notification Handling
EcobankPay will notify your application about payment status in two ways:
- Redirect to your
success_urlorcancelled_urlbased on payment outcome - POST request to your
ipn_urlwith payment details and status (if provided)
Card-Specific Response Parameters:
For card payments, EcobankPay includes additional parameters in the extra object:
- psp_response_code: Card processor response code
- psp_response_msg: Explanation of the card transaction result
7. Verify Payment Status
To verify the payment status, make a GET request to the transaction status endpoint:
GET https://pgw.paywithonline.com/v1/gateway/json_status_chk?invoice_id=INV12345&merchant_key=YOUR_MERCHANT_KEYThe response will include the current transaction status:
{
"status": "paid",
"status_reason": "",
"buyer_firstname": "John",
"buyer_lastname": "Doe",
"buyer_email": "customer@example.com",
"buyer_phone": "+233201234567",
"invoice_id": "INV12345",
"amount": 10.00,
"as_at": "2023-03-28T14:22:30Z",
"narration": "Payment for Order #12345"
}3D Secure Authentication
EcobankPay automatically handles 3D Secure authentication for eligible cards. This process:
- Provides an additional layer of security for online card transactions
- Requires the cardholder to complete an authentication step with their bank
- Reduces the risk of fraud and chargebacks
- Is fully managed by the EcobankPay checkout flow
No additional integration is required on your end to support 3D Secure - it's built into the card payment flow.
Error Handling
Common errors you might encounter during card payment integration:
| Error Code | Description |
|---|---|
| GW-001 | merchant_key missing or empty |
| GW-002 | invoice_id missing or empty |
| GW-003 | total/amount value missing or empty |
| GW-009 | Merchant is deactivated from receiving payments |
| GW-020 | Invalid secure_hash value |
Security Considerations
Additional security measures for card payments:
- Always use HTTPS for all communication with EcobankPay APIs
- Never store card details on your servers
- The secure_hash is critically important for card transactions - implement it properly
- EcobankPay's hosted checkout page is PCI-DSS compliant, minimizing your compliance burden
- Always verify payment status using the status check endpoint before fulfilling orders
