got a silly ui that can yield a test token
parent
5a3d5e5610
commit
f69a850bd8
|
|
@ -0,0 +1 @@
|
|||
app_pdvv33dtmta4fema66000
|
||||
|
|
@ -3,18 +3,72 @@ package teller
|
|||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"slices"
|
||||
"strings"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
var (
|
||||
//go:embed application_id.txt
|
||||
applicationId string
|
||||
//go:embed init.html
|
||||
initHTML string
|
||||
)
|
||||
|
||||
func Init(ctx context.Context) error {
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
|
||||
if Token == "" {
|
||||
} else if reader := bufio.NewReader(os.Stdin); false {
|
||||
} else if fmt.Println("Token already exists; are you sure [nY]?"); false {
|
||||
} else if text, _ := reader.ReadString('\n'); !strings.Contains(text, "Y") {
|
||||
return fmt.Errorf("token already exists")
|
||||
}
|
||||
|
||||
environment := "development"
|
||||
if sandbox := !slices.Contains(os.Args, "forreal"); sandbox {
|
||||
environment = "sandbox"
|
||||
}
|
||||
fmt.Printf("environment=%q\n", environment)
|
||||
|
||||
newTokens := make(chan string)
|
||||
defer close(newTokens)
|
||||
s := &http.Server{
|
||||
Addr: ":20000",
|
||||
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
b, _ := io.ReadAll(r.Body)
|
||||
newTokens <- string(b)
|
||||
return
|
||||
}
|
||||
|
||||
t, err := template.New("initHTML").Parse(initHTML)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err := t.Execute(w, map[string]string{
|
||||
"applicationId": applicationId,
|
||||
"environment": environment,
|
||||
}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}),
|
||||
}
|
||||
defer s.Close()
|
||||
go s.ListenAndServe()
|
||||
|
||||
fmt.Println("Open https://localhost:20000")
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
case newToken := <-newTokens:
|
||||
return fmt.Errorf("not impl: %q => token.txt", newToken)
|
||||
}
|
||||
|
||||
return ctx.Err()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,58 @@
|
|||
<html>
|
||||
<head></head>
|
||||
<body>
|
||||
<button id="teller-connect">Connect to your bank</button>
|
||||
|
||||
<h3 id="log">
|
||||
</h3>
|
||||
|
||||
<script src="https://cdn.teller.io/connect/connect.js"></script>
|
||||
<script>
|
||||
function logme(msg) {
|
||||
document.getElementById("log").innerHTML += `<br>* ${msg}`
|
||||
}
|
||||
|
||||
function http(method, remote, callback, body) {
|
||||
var xmlhttp = new XMLHttpRequest();
|
||||
xmlhttp.onreadystatechange = function() {
|
||||
if (xmlhttp.readyState == XMLHttpRequest.DONE) {
|
||||
callback(xmlhttp.responseText, xmlhttp.status)
|
||||
}
|
||||
};
|
||||
xmlhttp.open(method, remote, true);
|
||||
if (typeof body == "undefined") {
|
||||
body = null
|
||||
}
|
||||
xmlhttp.send(body);
|
||||
}
|
||||
function callback(responseBody, responseStatus) {
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
var tellerConnect = TellerConnect.setup({
|
||||
applicationId: "{{.applicationId}}",
|
||||
environment: "{{.environment}}",
|
||||
products: ["verify", "balance", "transactions"],
|
||||
onInit: function() {
|
||||
logme("Teller Connect has initialized")
|
||||
},
|
||||
onSuccess: function(enrollment) {
|
||||
logme(`User enrolled successfully: ${enrollment.accessToken}`)
|
||||
http("post", "/", callback, enrollment.accessToken)
|
||||
},
|
||||
onExit: function() {
|
||||
logme("User closed Teller Connect")
|
||||
},
|
||||
onFailure: function(failure) {
|
||||
logme(`Failed: type=${failure.type} code=${failure.code} message=${failure.message}`)
|
||||
},
|
||||
});
|
||||
|
||||
var el = document.getElementById("teller-connect");
|
||||
el.addEventListener("click", function() {
|
||||
tellerConnect.open();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1 @@
|
|||
test_token_dwdwcxnnhh5du
|
||||
Loading…
Reference in New Issue