Unofficial Golang SDK for Chapa ET API
- We could add nice validations on demand.
- Add implementation for the remaining API endpoints.
go get github.com/Chapa-Et/chapa-go
Add your API_KEY: CHASECK_xxxxxxxxxxxxxxxx
inside config.yaml
file.
If you want to run the githb action on your forked repository, you have to create a secrete key named API_KEY
.
package main
import (
chapa "github.com/Chapa-Et/chapa-go"
)
func main(){
chapaAPI := chapa.New()
}
request := &chapaAPI.PaymentRequest{
Amount: 10,
Currency: "ETB",
FirstName: "Chapa",
LastName: "ET",
Email: "chapa@et.io",
CallbackURL: "https://posthere.io/e631-44fe-a19e",
TransactionRef: RandomString(20),
Customization: map[string]interface{}{
"title": "A Unique Title",
"description": "This a perfect description",
"logo": "https://your.logo",
},
}
response, err := chapaAPI.PaymentRequest(request)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Printf("payment response: %+v\n", response)
response, err := chapaAPI.Verify("your-txn-ref")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Printf("verification response: %+v\n", response)
request := &BankTransfer{
AccountName: "Yinebeb Tariku",
AccountNumber: "34264263",
Amount: 10,
BeneficiaryName: "Yinebeb Tariku",
Currency: "ETB",
Reference: "3264063st01",
BankCode: "32735b19-bb36-4cd7-b226-fb7451cd98f0",
}
response, err := chapaAPI.TransferToBank(request)
fmt.Printf("transfer response: %+v\n", response)
response, err := chapaAPI.getTransactions()
fmt.Printf("transactions response: %+v\n", response)
response, err := chapaAPI.getBanks()
fmt.Printf("banks response: %+v\n", response)
bulkData := BulkData{
AccountName: "Leul Abay Ejigu",
AccountNumber: "1000212482106",
Amount: 10,
Reference: "3241342142sfdd",
BankCode: "946",
}
request := &BulkTransferRequest{
Title: "Transfer to leul",
Currency: "ETB",
BulkData: []BulkData{bulkData},
}
response, err := chapaAPI.bulkTransfer(request)
fmt.Printf("bulk transfer response: %+v\n", response)
Suggestions on how to improve the API:
- Introduction of
status codes
would be a nice to have in the future. Status codes are better than themessage
in a way considering there are so many reasons a transaction could fail. e.g
1001: Success
4001: DuplicateTransaction
4002: InvalidCurrency
4003: InvalidAmount
4005: InsufficientBalance
5000: InternalServerError
5001: GatewayError
5002: RejectedByGateway
Just an example!
- Highly welcome