A Go package for integrating with the SSLCommerz payment gateway. This package provides functions to initiate payments and handle responses, structured in a modular way for easy management and extension.
sslcommerz-go/
├── config/
│ └── config.go
├── client/
│ └── client.go
├── sslcommerz/
│ └── sslcommerz.go
├── examples/
│ └── main.go
├── go.mod
└── go.sum
- config/config.go: Handles configuration settings, such as storing the store ID and password.
- client/client.go: Manages HTTP requests to the SSLCommerz API.
- sslcommerz/sslcommerz.go: Implements payment processing functions, such as initiating payments.
- examples/main.go: Provides an example usage of the package, demonstrating how to initiate a payment request.
-
Install:
go get -u github.com/JubaerHossain/sslcommerz-go
-
Set up Go modules:
go mod tidy
Set the following environment variables with your SSLCommerz credentials:
export SSLCOMMERZ_STORE_ID=your_store_id
export SSLCOMMERZ_STORE_PASS=your_store_password
The following example demonstrates how to initiate a payment request using the package.
package main
import (
"fmt"
"log"
"github.com/yourusername/sslcommerz-go/sslcommerz"
)
func main() {
paymentRequest := &sslcommerzEntity.PaymentRequest{
TotalAmount: 103,
Currency: "BDT",
TransactionID: "SSLCZ_TEST_" + GenerateUniqueID(),
SuccessURL: "http://localhost:8080/success",
FailURL: "http://localhost:8080/fail",
CancelURL: "http://localhost:8080/cancel",
IPNURL: "http://localhost:8080/ipn",
CustomerName: "Test Customer",
CustomerEmail: "[email protected]",
CustomerAddress1: "Dhaka",
CustomerAddress2: "Dhaka",
CustomerCity: "Dhaka",
CustomerState: "Dhaka",
CustomerPostcode: "1000",
CustomerCountry: "Bangladesh",
CustomerPhone: "01711111111",
CustomerFax: "01711111111",
ShippingMethod: "No",
ShippingName: "Store Test",
ShippingAddress1: "Dhaka",
ShippingAddress2: "Dhaka",
ShippingCity: "Dhaka",
ShippingState: "Dhaka",
ShippingPostcode: "1000",
ShippingCountry: "Bangladesh",
ValueA: "ref001",
ValueB: "ref002",
ValueC: "ref003",
ValueD: "ref004",
ProductName: "Computer",
ProductCategory: "Goods",
ProductProfile: "physical-goods",
}
sslc := sslcommerz.NewSSLCommerz()
response, err := sslc.InitiatePayment(paymentRequest)
if err != nil {
log.Printf("Error initiating payment: %v", err)
http.Error(w, "Internal Server Error: Payment initiation failed", http.StatusInternalServerError)
return
}
fmt.Printf("Payment Response: %+v\n", response)
// Redirect to the payment gateway
}
-
Set environment variables:
export SSLCOMMERZ_STORE_ID=your_store_id export SSLCOMMERZ_STORE_PASS=your_store_password
-
Run the example:
go run examples/main.go
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please feel free to submit a pull request or open an issue.
Thanks to the SSLCommerz team for providing the API and documentation.
For any questions or feedback, please open an issue or contact me at [email protected].
This README provides a comprehensive guide for using the SSLCommerz-Go package, including setup, configuration, and example usage.