diff --git a/src/api/v1/donate.go b/src/api/v1/donate.go index 9c71c42..31ab342 100644 --- a/src/api/v1/donate.go +++ b/src/api/v1/donate.go @@ -5,6 +5,7 @@ import ( "encoding/json" "github.com/ImpactDevelopment/ImpactServer/src/database" "github.com/ImpactDevelopment/ImpactServer/src/discord" + "github.com/ImpactDevelopment/ImpactServer/src/recaptcha" "github.com/ImpactDevelopment/ImpactServer/src/stripe" "github.com/ImpactDevelopment/ImpactServer/src/util" "github.com/google/uuid" @@ -102,6 +103,12 @@ func createStripePayment(c echo.Context) error { return echo.NewHTTPError(http.StatusForbidden) } + // Only check recaptcha after we've verified that the address is allowed + err = recaptcha.Verify(c) + if err != nil { + return err + } + payment, err := stripe.CreatePayment(body.Amount, body.Currency, "Donation", body.Email) if err != nil { return err diff --git a/static/donate.html b/static/donate.html index eacb8d7..912e6bf 100644 --- a/static/donate.html +++ b/static/donate.html @@ -13,6 +13,7 @@ + @@ -129,7 +130,8 @@

An email to send your receipt to -
+
+
@@ -380,6 +382,9 @@

Thank you for donating to Impac var amount = Math.floor(form['amount'].value.trim() * 100) var email = form['email'].value.trim() var currency = form['currency'].value.trim() + var captcha = $("#g-recaptcha-response").val() + + if (!captcha) showError($(form), "Recaptcha is required") // Show a spinner while creating payment loading($(form), true) @@ -391,7 +396,7 @@

Thank you for donating to Impac return } - api.createPayment(currency, amount, email) + api.createPayment(currency, amount, email, captcha) .then(function (payment) { return currentPayment = payment }) diff --git a/static/js/api.js b/static/js/api.js index 4af9183..13a0fa1 100644 --- a/static/js/api.js +++ b/static/js/api.js @@ -125,7 +125,7 @@ }) }) }, - createPayment: function(currency, amount, email) { + createPayment: function(currency, amount, email, verification) { if (!email) { // currency is optional, if only two args are present then shift them right email = amount @@ -138,7 +138,8 @@ data: { currency: currency, amount: amount, - email: email + email: email, + "g-recaptcha-response": verification }, dataType: "json", error: function (jqXHR, textStatus, errorThrown) {