forked from GoesToEleven/GolangTraining
/
stripe.go
executable file
·34 lines (31 loc) · 878 Bytes
/
stripe.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
package stripeexample
import (
"github.com/stripe/stripe-go"
"github.com/stripe/stripe-go/charge"
"golang.org/x/net/context"
"google.golang.org/appengine/log"
"google.golang.org/appengine/urlfetch"
)
func init() {
stripe.Key = "sk_test_8bZtX27RlHVMwe0YexxgBB1s"
}
func chargeAccount(ctx context.Context, stripeToken string) error {
// because we're on app engine, use a custom http client
// this is being set globally, however
// if we wanted to do it this way, we'd have to use a lock
// https://youtu.be/KT4ki_ClX2A?t=1018
hc := urlfetch.Client(ctx)
stripe.SetHTTPClient(hc)
chargeParams := &stripe.ChargeParams{
Amount: 100 * 200000,
Currency: "usd",
Desc: "Charge for test@example.com",
}
chargeParams.SetSource(stripeToken)
ch, err := charge.New(chargeParams)
if err != nil {
return err
}
log.Infof(ctx, "CHARGE: %v", ch)
return nil
}