diff --git a/cmd/api/handlers-api.go b/cmd/api/handlers-api.go index 3111b90..1c575a5 100644 --- a/cmd/api/handlers-api.go +++ b/cmd/api/handlers-api.go @@ -99,9 +99,33 @@ func (app *application) CreateCustomerAndSubscribeToPlan(w http.ResponseWriter, app.infoLog.Println(data.Email, data.LastFour, data.PaymentMethod, data.Plan) - okay := true - msg := "" + card := cards.Card{ + Secret: app.config.stripe.secret, + Key: app.config.stripe.key, + Currency: data.Currency, + } + stripeCustomer, msg, err := card.CreateCustomer(data.PaymentMethod, data.Email) + if err != nil { + app.errorLog.Println(err) + return + } + + subscriptionID, err := card.SubscribeToPlan( + stripeCustomer, + data.Plan, + data.Email, + data.LastFour, + "", + ) + if err != nil { + app.errorLog.Println(err) + return + } + + app.infoLog.Println("subscription id is", subscriptionID) + + okay := true resp := jsonResponse{ OK: okay, Message: msg,