-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #144 from debtcollective/feat/add-recaptcha
Feat/add recaptcha
- Loading branch information
Showing
11 changed files
with
155 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<script> | ||
// Create a Stripe client. | ||
const stripe = Stripe('<%= ENV['STRIPE_PUBLISHABLE_KEY'] %>'); | ||
|
||
// Create an instance of Elements. | ||
const elements = stripe.elements(); | ||
|
||
// Custom styling can be passed to options when creating an Element. | ||
const style = { | ||
base: { | ||
color: '#32325d', | ||
fontFamily: '"Helvetica Neue", Helvetica, sans-serif', | ||
fontSmoothing: 'antialiased', | ||
fontSize: '16px', | ||
'::placeholder': { | ||
color: '#aab7c4' | ||
} | ||
}, | ||
invalid: { | ||
color: '#fa755a', | ||
iconColor: '#fa755a' | ||
} | ||
}; | ||
|
||
// Create an instance of the card Element. | ||
const card = elements.create('card', {style: style}); | ||
|
||
// Add an instance of the card Element into the `card-element` <div>. | ||
card.mount('#card-element'); | ||
|
||
// Handle real-time validation errors from the card Element. | ||
card.addEventListener('change', function(event) { | ||
const displayError = document.getElementById('card-errors'); | ||
if (event.error) { | ||
displayError.textContent = event.error.message; | ||
} else { | ||
displayError.textContent = ''; | ||
} | ||
}); | ||
|
||
// Handle form submission. | ||
const form = document.getElementById('payment-form'); | ||
form.addEventListener('submit', function(event) { | ||
event.preventDefault(); | ||
|
||
stripe.createToken(card).then(function(result) { | ||
if (result.error) { | ||
// Inform the user if there was an error. | ||
const errorElement = document.getElementById('card-errors'); | ||
errorElement.textContent = result.error.message; | ||
} else { | ||
// Send the token to your server. | ||
stripeTokenHandler(result.token); | ||
} | ||
}); | ||
}); | ||
|
||
// Submit the form with the token ID. | ||
function stripeTokenHandler(token) { | ||
// Insert the token ID into the form so it gets submitted to the server | ||
const form = document.getElementById('payment-form'); | ||
const stripeHiddenInput = document.createElement('input'); | ||
stripeHiddenInput.setAttribute('type', 'hidden'); | ||
stripeHiddenInput.setAttribute('name', 'stripeToken'); | ||
stripeHiddenInput.setAttribute('value', token.id); | ||
form.appendChild(stripeHiddenInput); | ||
|
||
const planHiddenInput = document.createElement('input'); | ||
planHiddenInput.setAttribute('type', 'hidden'); | ||
planHiddenInput.setAttribute('name', 'subscription[plan_attributes][id]'); | ||
planHiddenInput.setAttribute('value', '<%= @subscription&.plan&.id %>'); | ||
form.appendChild(planHiddenInput); | ||
|
||
// Submit the form | ||
form.submit(); | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
Recaptcha.configure do |config| | ||
config.site_key = ENV['RECAPTCHA_SITE_KEY'] | ||
config.secret_key = ENV['RECAPTCHA_SECRET_KEY'] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters