generated from inc4/go-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
73bcf28
commit 3e3b8fd
Showing
3 changed files
with
83 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |