Skip to content

Commit

Permalink
fix: forward context to stripe params & use context for config fetch
Browse files Browse the repository at this point in the history
Signed-off-by: Lawrence Zawila <113581282+darkmatterpool@users.noreply.github.com>
  • Loading branch information
darkmatterpool committed Dec 5, 2022
1 parent 9ea22d4 commit 7a424d8
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions internal/app/api/stripe.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package api

import (
"context"
"encoding/json"
"net/http"

Expand Down Expand Up @@ -49,16 +48,19 @@ func (req *stripeTransferRequest) validate() error {

func handleStripeTransfers(db *mongo.Database) http.HandlerFunc {
connectorStore := integration.NewMongoDBConnectorStore(db)
var cfg stripeConnector.Config

err := connectorStore.ReadConfig(context.Background(), stripeConnector.Name, &cfg)
if err != nil {
panic(err)
}
return func(w http.ResponseWriter, r *http.Request) {
var cfg stripeConnector.Config

stripe.Key = cfg.APIKey
err := connectorStore.ReadConfig(r.Context(), stripeConnector.Name, &cfg)
if err != nil {
handleError(w, r, err)

return
}

stripe.Key = cfg.APIKey

return func(w http.ResponseWriter, r *http.Request) {
var transferRequest stripeTransferRequest

err = json.NewDecoder(r.Body).Decode(&transferRequest)
Expand All @@ -76,6 +78,9 @@ func handleStripeTransfers(db *mongo.Database) http.HandlerFunc {
}

params := &stripe.TransferParams{
Params: stripe.Params{
Context: r.Context(),
},
Amount: stripe.Int64(transferRequest.Amount),
Currency: stripe.String(transferRequest.currency),
Destination: stripe.String(transferRequest.Destination),
Expand Down

0 comments on commit 7a424d8

Please sign in to comment.