### eSewa Payment Response Examples Source: https://developer.esewa.com.np/pages/Epay Provides examples of the response body received after a successful payment, both in its decoded JSON format and as a Base64 encoded string. It also highlights the importance of signature verification. ```json { "transaction_code": "000AWEO", "status": "COMPLETE", "total_amount": 1000.0, "transaction_uuid": "250610-162413", "product_code": "EPAYTEST", "signed_field_names": "transaction_code,status,total_amount,transaction_uuid,product_code,signed_field_names", "signature": "62GcfZTmVkzhtUeh+QJ1AqiJrjoWWGof3U+eTPTZ7fA=" } ``` ```base64 eyJ0cmFuc2FjdGlvbl9jb2RlIjoiMDAwQVdFTyIsInN0YXR1cyI6IkNPTVBMRVRFIiwidG90YWxfYW1vdW50IjoiMTAwMC4wIiwi dHJhbnNhY3Rpb25fdXVpZCI6IjI1MDYxMC0xNjI0MTMiLCJwcm9kdWN0X2NvZGUiOiJFUEFZVEVTVCIsInNpZ25lZF9maWVsZF9uYW1lcyI6InRyYW5zYWN0aW9uX2NvZGUsc3RhdHVzLHRvdGFsX2Ftb3VudCx0cmFuc2FjdGlvbl91dWlkLHByb2R1Y3RfY29kZSxzaWdu ZWRfZmllbGRfbmFtZXMiLCJzaWduYXR1cmUiOiI2MkdjZlpUbVZremh0VWVoK1FKMUFxaUpyam9XV0dvZjNVK2VUUFRaN2ZBPSJ9 ``` -------------------------------- ### Generate HMAC SHA256 Signature in Groovy/JVM Source: https://developer.esewa.com.np/pages/Epay Provides a Groovy script example for generating an HMAC SHA256 hash. It utilizes Java's `Mac` class and Groovy's built-in base64 encoding for the output. ```groovy import javax.crypto.Mac import javax.crypto.spec.SecretKeySpec import java.security.InvalidKeyException def hmac_sha256(String secretKey, String data) { try { Mac mac = Mac.getInstance("HmacSHA256") SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey.getBytes(), "HmacSHA256") mac.init(secretKeySpec) byte[] digest = mac.doFinal(data.getBytes()) return digest } catch (InvalidKeyException e) { throw new RuntimeException("Invalid key exception while converting to HMac SHA256") } } def hash = hmac_sha256("secret", "Message") def encodedData = hash.encodeBase64().toString() log.info(encodedData) ``` -------------------------------- ### eSewa Payment Form Parameters and API Source: https://developer.esewa.com.np/pages/Epay Details the parameters required for submitting payment requests to the eSewa API. Includes parameter descriptions, types, constraints, and example usage via form submission and JSON payload. The production URL for the API is https://epay.esewa.com.np/api/epay/main/v2/form. ```APIDOC eSewaPaymentAPI: Endpoint: https://epay.esewa.com.np/api/epay/main/v2/form (Production) Method: POST Description: Submits payment transaction details to eSewa. Parameters: amount: Type: String Description: Amount of product. Required: Yes tax_amount: Type: String Description: Tax amount applied on product. Required: Yes (use '0' if not applicable) product_service_charge: Type: String Description: Service charge by merchant on product. Required: Yes (use '0' if not applicable) product_delivery_charge: Type: String Description: Delivery charge by merchant on product. Required: Yes (use '0' if not applicable) product_code: Type: String Description: Merchant code provided by eSewa. Required: Yes total_amount: Type: String Description: Total payment amount including tax, service and delivery charge. Calculated as amount + tax_amount + product_service_charge + product_delivery_charge. Required: Yes transaction_uuid: Type: String Description: A unique ID of product, should be unique on every request. Supports alphanumeric and hyphen(-) only. Required: Yes success_url: Type: String Description: A redirect URL of merchant application where customer will be redirected after SUCCESSFUL transaction. Required: Yes failure_url: Type: String Description: A redirect URL of merchant application where customer will be redirected after FAILURE or PENDING transaction. Required: Yes signed_field_names: Type: String Description: Comma-separated list of field names that are used for generating the signature. Required: Yes signature: Type: String Description: HMAC signature generated from the specified fields. The signature generation process involves using the HMAC algorithm with a secret key provided by eSewa. Required: Yes Constraints: - All parameters are required and must not be null or empty. - If tax_amount, product_service_charge, or product_delivery_charge are not used, their values should be '0'. - transaction_uuid must contain alphanumeric characters and hyphens only. Example Usage (JSON Payload): { "amount": "100", "failure_url": "https://developer.esewa.com.np/failure", "product_delivery_charge": "0", "product_service_charge": "0", "product_code": "EPAYTEST", "signature": "i94zsd3oXF6ZsSr/kGqT4sSzYQzjj1W/waxjWyRwaME=", "signed_field_names": "total_amount,transaction_uuid,product_code", "success_url": "https://developer.esewa.com.np/success", "tax_amount": "10", "total_amount": "110", "transaction_uuid": "241028" } ``` -------------------------------- ### eSewa Transaction Status Response Types Source: https://developer.esewa.com.np/pages/Epay Details various possible status codes returned by the eSewa transaction status check API, along with their descriptions and example JSON payloads. This helps in interpreting the outcome of a transaction. ```APIDOC Transaction Status Codes and Formats Response Types: - PENDING: Description: Payment Initiated but not been completed yet. Format: { "product_code": "EPAYTEST", "transaction_uuid": "240508-101430", "total_amount": 100.0, "status": "PENDING", "ref_id": null } - COMPLETE: Description: Successful Payment. Format: { "product_code": "EPAYTEST", "transaction_uuid": "240508-10108", "total_amount": 100.0, "status": "COMPLETE", "ref_id": "0007G36" } - FULL_REFUND: Description: Full Payment refunded to the customer. Format: { "product_code": "EPAYTEST", "transaction_uuid": "240508-101431", "total_amount": 100, "status": "FULL_REFUND", "ref_id": "0007G36" } - PARTIAL_REFUND: Description: Partial payment refunded to the customer. Format: { "product_code": "EPAYTEST", "transaction_uuid": "240508-101431", "total_amount": 100.0, "status": "PARTIAL_REFUND", "ref_id": "0007G36" } - AMBIGUOUS: Description: Payment is at a halt state. Format: { "product_code": "EPAYTEST", "transaction_uuid": "240508-101431", "total_amount": 100.0, "status": "AMBIGUOUS", "ref_id": "0KDL6NA" } - NOT_FOUND: Description: Payment terminated at eSewa: Session expired. Format: { "product_code": "EPAYTEST", "transaction_uuid": "240508-101430", "total_amount": 100.0, "status": "NOT_FOUND", "ref_id": null } - CANCELED: Description: Canceled/Reversed from eSewa side. Format: { "product_code": "EPAYTEST", "transaction_uuid": "240508-102939", "total_amount": 10.0, "status": "CANCELED", "ref_id": "0KDL6NA" } - Service is currently unavailable: Description: Server connection timeout. Format: { "code": 0, "error_message": "Service is currently unavailable" } Note: Ensure to compare the signature of the received response with the signature generated from the response parameters to verify integrity. ``` -------------------------------- ### eSewa ePay API Credentials and URLs Source: https://developer.esewa.com.np/pages/Epay Provides essential URLs and credentials for interacting with the eSewa ePay API. This includes the production environment URL and test credentials for development and testing phases. ```APIDOC eSewa ePay API Access Details: Production Mode URL: https://merchant.esewa.com.np Test Credentials (for development and testing): eSewa ID: 9806800001/2/3/4/5 Password: Nepal@123 MPIN: 1122 (for application use only) Token: 123456 Note: A registered eSewa user is required to make payments. MPIN is specific to mobile application usage. ``` -------------------------------- ### eSewa Payment Form HTML Source: https://developer.esewa.com.np/pages/Epay An HTML form demonstrating the structure for submitting payment details to the eSewa payment gateway. It includes fields for amount, transaction details, URLs, and signature. ```html
``` -------------------------------- ### Generate HMAC SHA256 Signature in JavaScript Source: https://developer.esewa.com.np/pages/Epay Demonstrates how to generate an HMAC SHA256 hash and convert it to a base64 string using the CryptoJS library. This is useful for securing API requests or transaction data. ```javascript ``` -------------------------------- ### Generate HMAC SHA256 Signature in Python Source: https://developer.esewa.com.np/pages/Epay Shows how to generate an HMAC SHA256 signature in Python using the `hmac` and `hashlib` modules. The resulting digest is then base64 encoded. ```python import hmac import hashlib import base64 secret = 'secret' message = 'Message' hmac_sha256 = hmac.new(secret.encode('utf-8'), message.encode('utf-8'), hashlib.sha256) digest = hmac_sha256.digest() signature = base64.b64encode(digest).decode('utf-8') ``` -------------------------------- ### Generate HMAC SHA256 Signature in PHP Source: https://developer.esewa.com.np/pages/Epay Provides a PHP snippet to compute an HMAC SHA256 hash of a message using a secret key and then encode the raw binary output into a base64 string. ```php $s = hash_hmac('sha256', 'Message', 'secret', true); echo base64_encode($s); ``` -------------------------------- ### Generate HMAC SHA256 Signature in Java Source: https://developer.esewa.com.np/pages/Epay Illustrates generating an HMAC SHA256 signature in Java using `javax.crypto.Mac` and Apache Commons Codec for base64 encoding. This is a common approach for secure communication in Java applications. ```java import java.security.InvalidKeyException; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; import org.apache.commons.codec.binary.Base64; public class ApiSecurityExample { public static void main(String[] args) { try { String secret = "secret"; String message = "Message"; Mac sha256_HMAC = Mac.getInstance("HmacSHA256"); SecretKeySpec secret_key = new SecretKeySpec(secret.getBytes(), "HmacSHA256"); sha256_HMAC.init(secret_key); String hash = Base64.encodeBase64String(sha256_HMAC.doFinal(message.getBytes())); System.out.println(hash); } catch (Exception e) { System.out.println("Error"); e.printStackTrace(); } } } ``` -------------------------------- ### eSewa Transaction Status Check API Source: https://developer.esewa.com.np/pages/Epay API endpoint for checking the status of a transaction when no immediate response is received. It requires product code, transaction UUID, and amount. The response includes transaction details and status. ```APIDOC eSewa Transaction Status Check API Endpoint: - Testing: https://rc.esewa.com.np/api/epay/transaction/status/ - Production: https://epay.esewa.com.np/api/epay/transaction/status/ Method: GET Parameters: - product_code (string, required): The product code for the transaction. - total_amount (number, required): The total amount of the transaction. - transaction_uuid (string, required): The unique identifier for the transaction. Response Example: { "product_code": "EPAYTEST", "transaction_uuid": "123", "total_amount": 100.0, "status": "COMPLETE", "ref_id": "0001TS9" } Related Methods: - Payment Initiation API (not detailed here) - Signature Verification (required for response integrity) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.