Updating handler to complete a subscription

This commit is contained in:
vinchent 2024-08-12 18:28:20 +02:00
parent fd1d1808f0
commit c3897d47bc

View File

@ -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,