|
|
@@ -233,6 +233,11 @@ type Password struct { |
|
|
|
|
|
|
|
type Endpoint func(http.ResponseWriter, *sql.DB, *http.Request) |
|
|
|
|
|
|
|
type HookKeys struct { |
|
|
|
InvoicePaid string |
|
|
|
InvoiceFailed string |
|
|
|
} |
|
|
|
|
|
|
|
var ( |
|
|
|
regexen = make(map[string]*regexp.Regexp) |
|
|
|
relock sync.Mutex |
|
|
@@ -275,6 +280,11 @@ var feeTypes = []string{ |
|
|
|
"Other", |
|
|
|
} |
|
|
|
|
|
|
|
var hookKeys = HookKeys{ |
|
|
|
InvoicePaid: "", |
|
|
|
InvoiceFailed: "", |
|
|
|
} |
|
|
|
|
|
|
|
var standardPriceId = "price_1OZLK9BPMoXn2pf9kuTAf8rs" |
|
|
|
|
|
|
|
// Used to validate claim in JWT token body. Checks if user id is greater than |
|
|
@@ -3036,15 +3046,23 @@ func invoicePaid(w http.ResponseWriter, db *sql.DB, r *http.Request) { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
event, err := webhook.ConstructEvent(b, r.Header.Get("Stripe-Signature"), |
|
|
|
os.Getenv("STRIPE_SECRET_KEY")) |
|
|
|
event, err := webhook.ConstructEvent(b, |
|
|
|
r.Header.Get("Stripe-Signature"), |
|
|
|
hookKeys.InvoicePaid) |
|
|
|
if err != nil { |
|
|
|
http.Error(w, err.Error(), http.StatusBadRequest) |
|
|
|
log.Printf("webhook.ConstructEvent: %v", err) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
log.Println(event.Data) |
|
|
|
|
|
|
|
w.WriteHeader(http.StatusOK) |
|
|
|
if event.Type != "invoice.paid" { |
|
|
|
log.Println("Invalid event type sent to invoice-paid.") |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
log.Println(event.Type) |
|
|
|
// json.Unmarshal(event.Data.Raw, & |
|
|
|
} |
|
|
|
|
|
|
|
func invoiceFailed(w http.ResponseWriter, db *sql.DB, r *http.Request) { |
|
|
@@ -3523,6 +3541,10 @@ func dev(args []string) { |
|
|
|
os.Setenv("DBPass", "test123") |
|
|
|
stripe.Key = os.Getenv("STRIPE_SECRET_KEY") |
|
|
|
standardPriceId = "price_1OZLK9BPMoXn2pf9kuTAf8rs" |
|
|
|
hookKeys = HookKeys{ |
|
|
|
InvoicePaid: os.Getenv("DEV_WEBHOOK_KEY"), |
|
|
|
InvoiceFailed: os.Getenv("DEV_WEBHOOK_KEY"), |
|
|
|
} |
|
|
|
|
|
|
|
db, err := sql.Open("mysql", |
|
|
|
fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/%s?multiStatements=true", |
|
|
|