Go SDK
Installation
Copy
go get github.com/Reevit-Platform/go-sdk@v0.5.0
Quick Start
Copy
package main
import (
"context"
"fmt"
reevit "github.com/Reevit-Platform/go-sdk"
)
func main() {
client := reevit.NewClient("pfk_live_xxx.secret", "org_123")
// Create payment intent
intent, err := client.Payments.CreateIntent(context.Background(), &reevit.PaymentIntentRequest{
Amount: 5000,
Currency: "GHS",
Method: "mobile_money",
Country: "GH",
CustomerID: "cust_456",
Reference: "ORD-12345",
Metadata: map[string]interface{}{
"order_id": "12345",
},
})
if err != nil {
panic(err)
}
fmt.Printf("Payment ID: %s, Status: %s\n", intent.ID, intent.Status)
}
Configuration
Copy
client := reevit.NewClient("pfk_live_xxx.secret", "org_123")
Environment Variables
Copy
import "os"
client := reevit.NewClient(
os.Getenv("REEVIT_API_KEY"),
os.Getenv("REEVIT_ORG_ID"),
)
Payments
Create Payment Intent
Copy
intent, err := client.Payments.CreateIntent(ctx, &reevit.PaymentIntentRequest{
Amount: 10000,
Currency: "GHS",
Method: "mobile_money",
Country: "GH",
CustomerID: "cust_123",
Reference: "ORD-2024-001",
Metadata: map[string]interface{}{
"order_id": "ORD-2024-001",
},
})
Get Payment
Copy
payment, err := client.Payments.Get(ctx, "pay_abc123")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Status: %s, Amount: %d\n", payment.Status, payment.Amount)
List Payments
Copy
payments, err := client.Payments.List(ctx, 50, 0) // limit, offset
for _, p := range payments {
fmt.Printf("%s: %s\n", p.ID, p.Status)
}
Connections
Create Connection
Copy
conn, err := client.Connections.Create(ctx, &reevit.CreateConnectionRequest{
Provider: "paystack",
Mode: "live",
Credentials: map[string]string{
"secret_key": "sk_live_xxx",
},
Labels: []string{"nigeria", "primary"},
RoutingHints: &reevit.RoutingHints{
CountryPreference: []string{"NG"},
MethodBias: map[string]string{
"card": "high",
},
},
})
List Connections
Copy
connections, err := client.Connections.List(ctx)
for _, c := range connections {
fmt.Printf("%s (%s): %s\n", c.Provider, c.Mode, c.Status)
}
Webhook Verification
Copy
import (
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
"encoding/json"
"io"
"log"
"net/http"
)
func handleWebhook(w http.ResponseWriter, r *http.Request) {
body, _ := io.ReadAll(r.Body)
signature := r.Header.Get("X-Reevit-Signature")
mac := hmac.New(sha256.New, []byte(webhookSecret))
mac.Write(body)
expected := "sha256=" + hex.EncodeToString(mac.Sum(nil))
if !hmac.Equal([]byte(signature), []byte(expected)) {
http.Error(w, "Invalid signature", 401)
return
}
var event map[string]interface{}
json.Unmarshal(body, &event)
switch event["type"] {
case "payment.succeeded":
// Handle success
log.Printf("Payment succeeded: %v", event["data"])
case "payment.failed":
// Handle failure
}
w.WriteHeader(200)
}
Error Handling
Copy
intent, err := client.Payments.CreateIntent(ctx, req)
if err != nil {
if apiErr, ok := err.(*reevit.APIError); ok {
fmt.Printf("API Error: %s (code: %s)\n", apiErr.Message, apiErr.Code)
fmt.Printf("HTTP Status: %d\n", apiErr.StatusCode)
} else {
fmt.Printf("Error: %v\n", err)
}
return
}
Types
Copy
import reevit "github.com/Reevit-Platform/go-sdk"
func processPayment(payment *reevit.Payment) {
fmt.Printf("Processing %s\n", payment.ID)
}
func buildRequest() *reevit.PaymentIntentRequest {
return &reevit.PaymentIntentRequest{
Amount: 5000,
Currency: "GHS",
Method: "mobile_money",
Country: "GH",
}
}
Supported Providers
| Provider | Countries | Methods |
|---|---|---|
| Paystack | NG, GH, ZA, KE | Card, Mobile Money, Bank |
| Flutterwave | NG, GH, KE, ZA+ | Card, Mobile Money, Bank |
| Hubtel | GH | Mobile Money |
| Stripe | Global | Card, Apple Pay, Google Pay |
| Monnify | NG | Bank Transfer, Card |
| M-Pesa | KE, TZ | Mobile Money |

