Pay-NP is a unified Go SDK for integrating with all major payment providers in Nepal. This is your one-stop solution for handling digital payments in the Nepalese market.
- Multiple Payment Providers: Unified interface for eSewa, ConnectIPS (NCHL), and more
- Type-Safe: Strongly typed API for all payment operations
- Secure: Built-in signature generation and verification
- Easy Integration: Simple and intuitive API design
- Well-Tested: Comprehensive test coverage
- Production Ready: Used in production environments
| Provider | Status | Features |
|---|---|---|
| eSewa | β Supported | Signature generation, Payment verification, HMAC-SHA256 |
| ConnectIPS (NCHL/CIPS) | β Supported | Transaction validation, Transaction details, RSA digital signatures |
go get github.com/mukezhz/pay-npeSewa is one of Nepal's leading digital payment platforms. Here's how to integrate it:
package main
import (
"fmt"
"github.com/mukezhz/pay-np/esewa"
)
func main() {
// Your eSewa secret key
secret := "your_esewa_secret_key"
// Create payment payload
payload := &esewa.EsewaPayload{
Amount: "100",
TaxAmount: "13",
TotalAmount: "113",
TransactionUUID: "unique-transaction-id",
ProductServiceCharge: "0",
ProductDeliveryCharge: "0",
ProductCode: "EPAYTEST",
SuccessURL: "https://yoursite.com/success",
FailureURL: "https://yoursite.com/failure",
SignedFieldNames: "total_amount,transaction_uuid,product_code",
}
// Create eSewa client
client, err := esewa.New(secret, payload)
if err != nil {
panic(err)
}
// Generate signature for payment request
signature, err := client.GenerateSignature()
if err != nil {
panic(err)
}
fmt.Println("Signature:", signature)
// Verify payment response (after payment completion)
err = client.VerifySignature(base64EncodedResponse)
if err != nil {
fmt.Println("Payment verification failed:", err)
return
}
fmt.Println("Payment verified successfully!")
fmt.Println("Transaction Code:", client.ReponsePayload.TransactionCode)
fmt.Println("Status:", client.ReponsePayload.Status)
}ConnectIPS is Nepal's interbank payment gateway. Here's how to use it:
package main
import (
"fmt"
"github.com/mukezhz/pay-np/nchl"
"github.com/mukezhz/pay-np/utils"
)
func main() {
// Create CIPS client
client := nchl.New("https://uat.connectips.com")
// Load your PFX certificate
privateKey, err := client.LoadPrivateKeyFromPFX("path/to/cert.pfx", "password")
if err != nil {
panic(err)
}
// Generate digital signature
payload := "your_payload_string"
signature, err := client.GenerateDigitalSignatureWithRSA(utils.GenerateDigitalSignatureWithRSAParams{
PfxCertPath: "path/to/cert.pfx",
Password: "password",
Payload: payload,
PrivKey: privateKey,
})
if err != nil {
panic(err)
}
// Validate transaction
req := nchl.CIPSJSONRequest{
MerchantID: 12345,
AppID: "YOUR_APP_ID",
TxnAmount: "1000",
ReferenceID: "unique-ref-id",
Token: "your_token",
}
resp, statusCode, err := client.ValidateTxn(req, "Bearer "+signature)
if err != nil {
panic(err)
}
fmt.Printf("Status: %s, Code: %d\n", resp.Status, statusCode)
// Get transaction details
details, statusCode, err := client.GetTxnDetail(req, "Bearer "+signature)
if err != nil {
panic(err)
}
fmt.Printf("Transaction ID: %d\n", details.TxnID)
fmt.Printf("Amount: %.2f\n", details.TxnAmount)
}pay-np/
βββ esewa/ # eSewa payment integration
β βββ esewa_client.go # Client implementation
β βββ types.go # Data structures
β βββ README.md # eSewa-specific documentation
βββ nchl/ # ConnectIPS (NCHL) integration
β βββ cips_client.go # CIPS client implementation
β βββ types.go # Data structures
βββ errorz/ # Custom error types
β βββ esewa_error.go # eSewa-specific errors
β βββ cips_error.go # CIPS-specific errors
βββ utils/ # Utility functions
β βββ crypto.go # Cryptographic utilities (HMAC, RSA, SHA256)
βββ esewa_test.go # Test cases
This SDK implements industry-standard security practices:
- HMAC-SHA256 for eSewa signature generation and verification
- RSA Digital Signatures with PKCS#1 v1.5 for ConnectIPS
- Base64 Encoding for secure data transmission
- Certificate-based Authentication for ConnectIPS using PFX/PKCS12
Run the test suite:
go test ./...Run specific tests:
go test esewa_test.goThe SDK provides comprehensive error handling with custom error types:
// eSewa errors
errorz.ErrEsewaTotalAmount // Missing total amount
errorz.ErrEsewaTransactionUUID // Missing transaction UUID
errorz.ErrEsewaProductCode // Missing product code
errorz.ErrEsewaInvalidDataForSignature // Invalid signature data
// CIPS errors
errorz.ErrCIPSFailedToReadPFX // Failed to read PFX certificate
errorz.ErrCIPSFailedToDecodePFX // Failed to decode PFX
errorz.ErrCIPSPrivateKeyNotRSA // Private key is not RSA
errorz.ErrCIPSSigningFailed // Signature generation failed- Production:
https://epay.esewa.com.np/api/epay/ - Testing:
https://uat.esewa.com.np/epay/
- Production:
https://connectips.com/ - UAT:
https://uat.connectips.com/
- Go 1.24 or higher
- Valid merchant accounts with respective payment providers
- For ConnectIPS: PFX certificate from your bank
Contributions are welcome! If you'd like to add support for more Nepalese payment providers or improve existing implementations:
- Fork the repository
- Create your feature branch (
git checkout -b feature/new-provider) - Commit your changes (
git commit -am 'Add support for XYZ payment provider') - Push to the branch (
git push origin feature/new-provider) - Open a Pull Request
- Add Khalti payment integration
- Add IME Pay integration
- Add Prabhu Pay integration
- Add webhook handling utilities
- Add payment reconciliation tools
- Improve documentation with more examples
- Add integration tests with mock servers
This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any issues or have questions:
- Open an issue on GitHub
- Check the documentation in respective provider directories
- Review the test files for usage examples
- eSewa for their payment gateway services
- NCHL (National Clearing and Settlement Limited) for ConnectIPS
- The Go community for excellent cryptographic libraries
This is an unofficial SDK. Please ensure you comply with all terms and conditions of the respective payment providers. Always test thoroughly in sandbox/UAT environments before going to production.
Made with β€οΈ for the Nepalese developer community