diff options
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 61 |
1 files changed, 42 insertions, 19 deletions
@@ -1,37 +1,60 @@ package main import ( - "com.teddywing/new-house-on-the-block/vendor/_nuts/github.com/fabioberger/coinbase-go" "fmt" "log" + "net/http" "os" -) - -func sendMoney(from string, to string, amount string) (transaction_id string, err error) { - c := coinbase.ApiKeyClientSandbox(os.Getenv("COINBASE_KEY"), os.Getenv("COINBASE_SECRET")) - params := &coinbase.TransactionParams{ - To: to, - Amount: amount, - Notes: "You just bought a house", - } + "github.com/teddywing/new-house-on-the-block/purchase" +) - confirmation, err := c.SendMoney(params) +func sendMoneyToSeller() error { + transaction_id, err := purchase.SendMoney(os.Getenv("COINBASE_KEY"), + os.Getenv("COINBASE_SECRET"), + "n2Qd6da1jiFgij5SSncFKh7MoFN74GdUxv", + "0.0001") if err != nil { - return "", err + return err } else { - fmt.Println(confirmation.Transaction.Status) - fmt.Println(confirmation.Transaction.Id) - - return confirmation.Transaction.Id, nil + fmt.Println(transaction_id) + return nil } } -func main() { - transaction_id, err := sendMoney("TODO", "n2Qd6da1jiFgij5SSncFKh7MoFN74GdUxv", "0.0001") +func sendTokenToBuyer() error { + transaction_id, err := purchase.SendMoney(os.Getenv("SELLER_COINBASE_KEY"), + os.Getenv("SELLER_COINBASE_SECRET"), + "mqy3kT6aFHymTcvmdwZLKq1Svo2m6sUtzH", + "0.0001") if err != nil { - log.Println(err) + return err } else { fmt.Println(transaction_id) + return nil } } + +func main() { + fs := http.FileServer(http.Dir("static")) + http.Handle("/", fs) + + http.HandleFunc("/buy/", func(w http.ResponseWriter, r *http.Request) { + var err error + + err = sendMoneyToSeller() + if err != nil { + log.Println(err) + } + + err = sendTokenToBuyer() + if err != nil { + log.Println(err) + } + + http.Redirect(w, r, "http://testsite.perfectburpee.com/new-house-on-the-block-page6/", 302) + }) + + log.Println("Listening on port 3000") + http.ListenAndServe(":3000", nil) +} |
