// Payments API SDK // Auto-generated — v1.0 package payments import ( "bytes" "encoding/json" "fmt" "io" "net/http" "net/url" "time" ) type Client struct { BaseURL string Token string HTTPClient *http.Client } func NewClient(token string, baseURL ...string) *Client { base := "https://api.aikdata.com/v1/payments" if len(baseURL) > 0 && baseURL[0] != "" { base = baseURL[0] } return &Client{ BaseURL: base, Token: token, HTTPClient: &http.Client{Timeout: 30 * time.Second}, } } type Response struct { Status int Data map[string]interface{} } // ── Charges ── // CreateCharge — Create a new payment charge func (c *Client) CreateCharge(body map[string]interface{}) (*Response, error) { return c.doRequest("POST", "/charge", nil, body) } // GetCharge — Retrieve a charge by ID func (c *Client) GetCharge(id string) (*Response, error) { return c.doRequest("GET", fmt.Sprintf("/charge/%s", id), nil, nil) } // ListCharges — List all charges with pagination func (c *Client) ListCharges(query url.Values) (*Response, error) { return c.doRequest("GET", "/charges", query, nil) } // ── Refunds ── // CreateRefund — Refund a charge fully or partially func (c *Client) CreateRefund(body map[string]interface{}) (*Response, error) { return c.doRequest("POST", "/refund", nil, body) } func (c *Client) doRequest(method, path string, query url.Values, body map[string]interface{}) (*Response, error) { u := c.BaseURL + path if len(query) > 0 { u += "?" + query.Encode() } var reqBody io.Reader if body != nil { b, _ := json.Marshal(body) reqBody = bytes.NewBuffer(b) } req, err := http.NewRequest(method, u, reqBody) if err != nil { return nil, err } req.Header.Set("Authorization", "Bearer "+c.Token) req.Header.Set("Content-Type", "application/json") req.Header.Set("Accept", "application/json") resp, err := c.HTTPClient.Do(req) if err != nil { return nil, err } defer resp.Body.Close() data := map[string]interface{}{} _ = json.NewDecoder(resp.Body).Decode(&data) return &Response{Status: resp.StatusCode, Data: data}, nil }