-
-
Notifications
You must be signed in to change notification settings - Fork 328
/
main.go
43 lines (35 loc) · 1.25 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"bytes"
"net/http"
"github.com/go-rod/rod"
"github.com/ysmood/gson"
)
// An example to handle stripe 3DS callback.
func main() {
page := rod.New().MustConnect().MustPage(getRedirectURL())
// Get the button from the nested iframes
frame01 := page.MustElement("div iframe").MustFrame()
frame02 := frame01.MustElement("#challengeFrame").MustFrame()
btn := frame02.MustElementR("button", "COMPLETE").MustWaitStable()
wait := frame02.MustWaitRequestIdle()
btn.MustClick()
wait()
}
// Create a card payment that requires Visa's confirmation
func getRedirectURL() string {
token := post(
"/tokens", "card[number]=4000000000003220&card[exp_month]=7&card[exp_year]=2025&card[cvc]=314",
).Get("id").Str()
return post(
"/payment_intents",
"amount=100¤cy=usd&payment_method_data[type]=card&confirm=true&return_url=https%3A%2F%2Fexample.com"+
"&payment_method_data[card][token]="+token,
).Get("next_action.redirect_to_url.url").Str()
}
func post(path, body string) gson.JSON {
req, _ := http.NewRequest(http.MethodPost, "https://api.stripe.com/v1"+path, bytes.NewBufferString(body))
req.Header.Add("Authorization", "Bearer sk_test_4eC39HqLyjWDarjtT1zdp7dc")
res, _ := http.DefaultClient.Do(req)
return gson.New(res.Body)
}