diff options
| -rw-r--r-- | main.go | 61 | ||||
| -rw-r--r-- | purchase/purchase.go | 23 | ||||
| -rw-r--r-- | static/index.html | 1 |
3 files changed, 66 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) +} diff --git a/purchase/purchase.go b/purchase/purchase.go new file mode 100644 index 0000000..45940f2 --- /dev/null +++ b/purchase/purchase.go @@ -0,0 +1,23 @@ +package purchase + +import ( + "github.com/teddywing/new-house-on-the-block/vendor/_nuts/github.com/fabioberger/coinbase-go" +) + +func SendMoney(from_key string, from_secret string, + to string, amount string) (transaction_id string, err error) { + c := coinbase.ApiKeyClientSandbox(from_key, from_secret) + + params := &coinbase.TransactionParams{ + To: to, + Amount: amount, + Notes: "You just bought a house", + } + + confirmation, err := c.SendMoney(params) + if err != nil { + return "", err + } else { + return confirmation.Transaction.Id, nil + } +} diff --git a/static/index.html b/static/index.html new file mode 100644 index 0000000..557db03 --- /dev/null +++ b/static/index.html @@ -0,0 +1 @@ +Hello World |
