Chapa Golang
Unofficial Golang SDK for Chapa ET API
Todo:
- We could add nice validations on demand.
Usage
1. Installation
go get github.com/vonmutinda/chapa
2. Setup
package main
import (
"os"
"github.com/vonmutinda/chapa"
)
func main(){
chapaAPI := chapa.New(os.Getenv("CHAPA_API_KEY"))
}
3. Accept Payments
request := &chapa.ChapaPaymentRequest{
Amount: 10,
Currency: "ETB",
FirstName: "Chapa",
LastName: "ET",
Email: "[email protected]",
CallbackURL: "https://posthere.io/e631-44fe-a19e",
TransactionRef: faker.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)
4. Verify Payment Transactions
response, err := chapa.Verify("your-txn-ref")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Printf("verification response: %+v\n", response)
Resources
Quirks
- Failure to set
Content-Type
toapplication/json
returnsInvalid currency
error - Failure to provide
Callback URL
returns an error. - The
checkout url
might expire before the user is done keying in the credit card details. This happens when the user attempts a payment with the wrong details at first, the second attempt with the correct details throwssession expired
error. - Amount fields in
verification response
object should be infloat
and notstring
. - Suggestion: Introduction of response codes could be a great way of summarizing the transaction response.
Contributions
- Highly welcome