An unofficial golang SDK for thawani, just calls there APIs easily switch between dev and prod mode by changing the constants as shown below.
go mod init example.com/test
go get github.com/ahmkindi/go-thawani
package main
import (
"fmt"
"github.com/ahmkindi/go-thawani"
)
const (
THAWANI_BASE_URL = "https://uatcheckout.thawani.om"
THAWANI_API_KEY = "rRQ26GcsZzoEhbrP2HZvLYDbn9C9et"
THAWANI_PUBLISHABLE_KEY = "HGvTMLDssJghr9tlN9gr4DVYt0qyBy"
)
func main() {
thawaniHost, err := url.Parse(THAWANI_BASE_URL)
if err != nil {
return nil, fmt.Errorf("failed to parse thawani url: %w", err)
}
ThawaniClient := thawani.NewClient(
&http.Client{Timeout: time.Second * 20},
thawaniHost,
THAWANI_API_KEY,
THAWANI_PUBLISHABLE_KEY
)
customer, err := ThawaniClient.CreateCustomer(thawani.CreateCustomerReq{
ClientCustomerId: user.ID.String(),
})
if err != nil {
return fmt.Errorf("failed to create customer: %w", err)
}
customerId := customer.Data.Id
fmt.Print("Created a customer with id: ", customerId)
}
There is still loads to implement, feel free to add and make a PR. Currently with the available functions you can:
- create a customer
- create a session
- get a session
Thats enough for a simple workflow.