Updating handler to complete a subscription
This commit is contained in:
parent
fd1d1808f0
commit
c3897d47bc
@ -99,9 +99,33 @@ func (app *application) CreateCustomerAndSubscribeToPlan(w http.ResponseWriter,
|
|||||||
|
|
||||||
app.infoLog.Println(data.Email, data.LastFour, data.PaymentMethod, data.Plan)
|
app.infoLog.Println(data.Email, data.LastFour, data.PaymentMethod, data.Plan)
|
||||||
|
|
||||||
okay := true
|
card := cards.Card{
|
||||||
msg := ""
|
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{
|
resp := jsonResponse{
|
||||||
OK: okay,
|
OK: okay,
|
||||||
Message: msg,
|
Message: msg,
|
||||||
|
Loading…
Reference in New Issue
Block a user