Skip to content

Commit

Permalink
Get transfers from stripe
Browse files Browse the repository at this point in the history
  • Loading branch information
SigismundSchlomo committed Sep 4, 2023
1 parent 73bcf28 commit 3e3b8fd
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ all: build

# TODO Use this if cmd/main.go used
build: $(SRC)
go build $(GOFLAGS) -o $(BINDIR)/example ./cmd
go build $(GOFLAGS) -o $(BINDIR)/stripe ./cmd

# TODO Use this if cmd/<names> used
#build: $(SRC)
Expand Down
56 changes: 50 additions & 6 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,61 @@
package main

import (
"flag"
"fmt"
"encoding/json"
"io"
"log"
"net/http"
)

// Experiment to show how to use stripe API
// TODO: Get some data about transfers using stripe
// Use plaine stripe http api to get this info
// Use testing key set
type Transfer struct {
Id string
Amount int
Created int
AvailableOn int `json:"available_on"`
Currency string
Description string
Fee int
Net int
Category string
Status string
Type string
}

func main() {
req, err := http.NewRequest("GET", "https://api.stripe.com/v1/balance_transactions", nil)
if err != nil {
log.Fatal(err)
}

req.SetBasicAuth("sk_test_51NmYi7E76ZgI9KtXBgSfN0qLCcvfMt8i8PbJYNqe4Fo5EB7V9grS91fyjwK4XhTpHDoqMz7Yovm7TTPurdat6t3U00KiUzT8EI", "")
resp, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()

body, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}

log.Printf("got data: %v", string(body))

var data struct {
Object string
Data []Transfer
HasMore bool `json:"has_more"`
Url string
}

if err := json.Unmarshal(body, &data); err != nil {
log.Fatal(err)
}

log.Printf("marshaled object: %+v", data)

for _, transfer := range data.Data {
log.Printf("result: %v", transfer)
}

}
32 changes: 32 additions & 0 deletions transfers_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"object": "list",
"data": [
{
"id": "txn_3NmZrCE76ZgI9KtX0HKerGFH",
"object": "balance_transaction",
"amount": 1000,
"available_on": 1694390400,
"created": 1693822690,
"currency": "usd",
"description": "test",
"exchange_rate": null,
"fee": 64,
"fee_details": [
{
"amount": 64,
"application": null,
"currency": "usd",
"description": "Stripe processing fees",
"type": "stripe_fee"
}
],
"net": 936,
"reporting_category": "charge",
"source": "ch_3NmZrCE76ZgI9KtX0JVvGrWs",
"status": "pending",
"type": "charge"
}
],
"has_more": false,
"url": "/v1/balance_transactions"
}

0 comments on commit 3e3b8fd

Please sign in to comment.