if support_type == 'non_financial'
current_user.update(support_type: 'non_financial')
AdminMailer.new_non_financial_member(current_user).deliver_later
+ SubscriptionMailer.confirmation_email(current_user, nil, 'non_financial').deliver_later
redirect_to subscriptions_path, notice: 'Thank you for your non-financial support!'
elsif ['one_time', 'ongoing'].include?(support_type)
begin
process_payment(support_type, payment_amount)
AdminMailer.new_paid_member(current_user).deliver_later
+ SubscriptionMailer.confirmation_email(current_user, payment_amount, support_type).deliver_later
redirect_to subscriptions_path, notice: 'Thank you for your support, it means the world to me! I will be in touch.'
rescue Stripe::CardError => e
flash.now[:error] = e.message
--- /dev/null
+<p>Dear <%= @user.first_name %>,</p>
+
+<p>My endless thanks for your generous support of mind reader. I am absolutely thrilled to have you on board as a <%= @support_type %> supporter.</p>
+
+<% if @amount.present? %>
+ <h3>Receipt Details:</h3>
+ <p>Amount: <%= number_to_currency(@amount, unit: "AU$") %></p>
+ <p>Date: <%= @date.strftime("%B %d, %Y") %></p>
+ <p>Support Type: <%= @support_type.titleize %></p>
+<% end %>
+
+<p>Your support means the world to me and helps me continue this anti-capitalist mission.</p>
+
+<p>If you have any questions or need any assistance, please don’t hesitate to reach out.</p>
+
+<p>In solidarity,<br>Aidan</p>
</div>
<div class="actions">
- <%= submit_tag "Subscribe", class: "button primary" %>
+ <%= submit_tag "Pay now", class: "button primary" %>
</div>
<% end %>
<% end %>
form.submit();
}
- // Format the payment amount input with AU$ prefix
- var paymentAmountInput = document.getElementById('payment_amount');
- if (paymentAmountInput) {
- paymentAmountInput.addEventListener('input', function(e) {
- var cursorPosition = e.target.selectionStart;
- var value = e.target.value.replace(/[^0-9.]/g, '');
-
- if (value !== '') {
- var floatValue = parseFloat(value);
- if (!isNaN(floatValue)) {
- var formattedValue = 'AU$' + floatValue.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
- e.target.value = formattedValue;
-
- // Adjust cursor position
- var newPosition = cursorPosition + (formattedValue.length - value.length);
- e.target.setSelectionRange(newPosition, newPosition);
+ // Format the payment amount input with AU$ prefix
+ var paymentAmountInput = document.getElementById('payment_amount');
+ if (paymentAmountInput) {
+ // Set initial value
+ paymentAmountInput.value = 'AU$0.00';
+
+ paymentAmountInput.addEventListener('input', function(e) {
+ var cursorPosition = e.target.selectionStart;
+ var value = e.target.value.replace(/[^0-9.]/g, '');
+
+ var floatValue = parseFloat(value) || 0;
+ var formattedValue = 'AU$' + floatValue.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
+
+ var oldLength = e.target.value.length;
+ e.target.value = formattedValue;
+ var newLength = e.target.value.length;
+
+ // Adjust cursor position
+ var newPosition = cursorPosition + (newLength - oldLength);
+ newPosition = Math.max(3, Math.min(newPosition, formattedValue.length));
+ e.target.setSelectionRange(newPosition, newPosition);
+ });
+
+ paymentAmountInput.addEventListener('focus', function(e) {
+ if (e.target.value === 'AU$0.00') {
+ setTimeout(function() {
+ e.target.setSelectionRange(3, 3);
+ }, 0);
}
- } else {
- e.target.value = '';
- }
- });
-
- paymentAmountInput.addEventListener('focus', function(e) {
- if (e.target.value === '') {
- e.target.value = 'AU$';
- }
- });
-
- paymentAmountInput.addEventListener('blur', function(e) {
- if (e.target.value === 'AU$') {
- e.target.value = '';
- }
- });
- }
+ });
+
+ paymentAmountInput.addEventListener('blur', function(e) {
+ var value = parseFloat(e.target.value.replace(/[^0-9.]/g, '')) || 0;
+ e.target.value = 'AU$' + value.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
+ });
+ }
});
</script>
<% end %>