Getting started guide
Install stripe-go
$ go get -u github.com/stripe/stripe-go
API Doc
Create Customer
endpoint: https://api.stripe.com/v1/customers
import ( "fmt" "github.com/stripe/stripe-go" "github.com/stripe/stripe-go/customer" "log" ) func CreateCustomer() { stripe.Key = "sk_test_xxxxxxxxxxxxxx" params := &stripe.CustomerParams{ Email: stripe.String("test@example.com"), } customer, error := customer.New(params) if error != nil { log.Fatal(error) } fmt.Print(customer.ID) } func main() { CreateCustomer() }
GetCustomer
endpoint: https://api.stripe.com/v1/customers/{customer_id}
import ( "fmt" "github.com/stripe/stripe-go" "github.com/stripe/stripe-go/customer" "log" ) func GetCustomer(customerId string) { stripe.Key = "sk_test_xxxxxxxxxxxxxx" result, error := customer.Get(customerId, nil) if error != nil { log.Fatal(error) } fmt.Println(result.ID) } func main() { GetCustomer("cus_xxxxxxxxx")
- クラインアント側では直接通信するのはNG。(For security, the Customer API is not directly accessible from the client.ってちゃんと書いてある)
- これをAWSLambdaにデプロイしてAPIGatewayでクライアント側で叩けるようにする(GCPでもいい)。
- サインアップをした際にFirebaseのAuth -> StripeCustomer(emailやname、metadataにFirebaseのuidなど入れておけばいい) ->Firestore(StripeのCustomerIdを入れておく)で保存しておく
- クライアント側のSDKにPresetされてるUIを使用するときにEphemeralKeyの発行が必要になるのでその際にCustomerIdとAPIVersionが必要になる。
決済インフラ入門〔2020年版〕 仮想通貨、ブロックチェーンから新日銀ネット、次なる改革まで
- 作者:宿輪 純一
- 発売日: 2018/07/20
- メディア: 単行本