Skip to content

Commit

Permalink
merge branch '187105227-recurring-donation-options' into 187065217-pe…
Browse files Browse the repository at this point in the history
…rform-recurring-donation-transaction
  • Loading branch information
winsonwan committed Apr 8, 2024
2 parents 8b4184e + 059d158 commit 9269ea6
Show file tree
Hide file tree
Showing 15 changed files with 146 additions and 69 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
[![Maintainability](https://api.codeclimate.com/v1/badges/f023aeddae42d2da37ba/maintainability)](https://codeclimate.com/github/armandofox/audience1st/maintainability)
![Build Status](https://github.com/armandofox/audience1st/actions/workflows/ci.yml/badge.svg)
[![Test Coverage](https://api.codeclimate.com/v1/badges/f023aeddae42d2da37ba/test_coverage)](https://codeclimate.com/github/armandofox/audience1st/test_coverage)
[![Pivotal Tracker](https://github.com/armandofox/audience1st/blob/main/app/assets/images/pivotal_tracker_logo.png)](https://pivotaltracker.com/n/projects/44802)

Spring 24 Team Badges
[![Maintainability](https://api.codeclimate.com/v1/badges/d9b6e16a95d868605440/maintainability)](https://codeclimate.com/github/cs169/audience1st/maintainability)
![Build Status](https://github.com/cs169/audience1st/actions/workflows/ci.yml/badge.svg)
[![Test Coverage](https://api.codeclimate.com/v1/badges/d9b6e16a95d868605440/test_coverage)](https://codeclimate.com/github/cs169/audience1st/test_coverage)
[![Pivotal Tracker](https://github.com/armandofox/audience1st/blob/main/app/assets/images/pivotal_tracker_logo.png)](https://pivotaltracker.com/n/projects/44802)
[![Pivotal Tracker](https://github.com/armandofox/audience1st/blob/main/app/assets/images/pivotal_tracker_logo.png)](https://www.pivotaltracker.com/n/projects/2488109)


Audience1st was written by [Armando Fox](https://github.com/armandofox) with contributions from:
Expand Down
11 changes: 6 additions & 5 deletions app/controllers/store_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class StoreController < ApplicationController
before_filter :is_logged_in, :only => %w[checkout place_order]
before_filter :order_is_not_empty, :only => %w[shipping_address checkout place_order]


# ACTION INVARIANT BEFORE ACTION
# ------ -----------------------
# index, subscribe, donate_to_fund valid @customer
Expand Down Expand Up @@ -105,11 +106,11 @@ def subscribe
redirect_to(store_path(@customer), :alert => "There are no subscriptions on sale at this time.") if @subs_to_offer.empty?
end

def donate_to_fund
return_after_login params.except(:customer_id)
@account_code = AccountCode.find_by_code(params[:id]) ||
AccountCode.find_by_id(params[:id]) ||
AccountCode.default_account_code
def donate_to_fund_redirect
# redirect donate_to_fund route to quickdonate for potential printed material with donate_to_fund url
fund_code = params[:id]
fund_code = Donation.default_code.code if fund_code.blank?
redirect_to quick_donate_url(account_code_string: fund_code)
end

# Serve quick_donate page; POST calls #process_donation
Expand Down
2 changes: 1 addition & 1 deletion app/views/account_codes/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
%td= link_to account_code.code, edit_account_code_path(account_code)
%td= link_to account_code.name, edit_account_code_path(account_code)
%td= [account_code.description, account_code.donation_prompt].join('<br/>'.html_safe).html_safe
%td= purchase_link_popup link_icon, donate_to_fund_url(account_code.id), "donations to #{account_code.name_with_code}"
%td= purchase_link_popup link_icon, quick_donate_url(account_code_string: account_code.code), "donations to #{account_code.name_with_code}"
%br

= link_to 'Add New Account Code...', new_account_code_path , :class => 'btn btn-primary'
22 changes: 22 additions & 0 deletions app/views/options/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,28 @@
quick_donation_redirect |
donation_ack_from |
) |
.form-row
.col-md-4.text-right
%label.col-form-label Allow Monthly Recurring Donations
= option_description_for(:allow_recurring_donations)
.col-md-8{id:"allow_recurring_donations_select"}
= f.select :allow_recurring_donations, [['Yes', true], ['No', false]], {}, {:class => 'form-control'}
- if Option.allow_recurring_donations
.form-row{id:"default_donation_type_form_row"}
.col-md-4.text-right
%label.col-form-label Default Donation Type
= option_description_for(:default_donation_type)
.col-md-8{id:"donation_type_radio"}
.radio-group.form-inline
= f.radio_button :default_donation_type, 'one', :class => 'form-control', :id => 'one'
= f.label :default_donation_type, 'One Time', :class => 'form-control', :for => 'one'
= f.radio_button :default_donation_type, 'monthly', :class => 'form-control', :id => 'monthly'
= f.label :default_donation_type, 'Monthly', :class => 'form-control', :for => 'monthly'
= render_collection_of_options f, %w( |
recurring_donation_contact_emails |
notify_theater_about_new_recurring_donation |
notify_theater_about_failed_recurring_donation_charge |
) |

.card.my-1
.card-header.h3 Customer Account
Expand Down
23 changes: 23 additions & 0 deletions config/locales/en.option_descriptions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -484,3 +484,26 @@ en:
https. NOTE: Audience1st will also try to serve your
favicon.ico from the same directory that contains the stylesheet; if
no favicon.ico is found there, a generic one will be served.
allow_recurring_donations: >
Whether to allow customers to initiate recurring monthly donations.
default_donation_type: >
Whether the default option for donations is one-time or recurring when a customer is on the 'make donation' page.
recurring_donation_contact_emails: >
Comma-separated list of theater contact email addresses to contact
regarding recurring donation activity.
notify_theater_about_new_recurring_donation: >
Whether to notify theater contact email addresses when a customer initiates
a new recurring donation.
notify_theater_about_failed_recurring_donation_charge: >
Whether to notify theater contact email addresses when a charge from an
existing recurring donation fails.
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@

get '/store/(:customer_id)' => 'store#index', :defaults => {:customer_id => nil}, :as => 'store'
get '/subscribe/(:customer_id)' => 'store#subscribe', :defaults => {:customer_id => nil}, :as => 'store_subscribe'
get '/donate_to_fund/:id/(:customer_id)' => 'store#donate_to_fund', :defaults => {:customer_id => nil}, :as => 'donate_to_fund'
# get '/donate_to_fund/:id/(:customer_id)' => 'store#donate_to_fund', :defaults => {:customer_id => nil}, :as => 'donate_to_fund'
get '/donate_to_fund/(:id)/(:customer_id)', :defaults => {:customer_id => nil}, to: 'store#donate_to_fund_redirect'
get '/store/cancel' => 'store#cancel', :as => 'store_cancel'

# subsequent actions in the above flow require a customer_id in the URL:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddRecurringDonationOptionsToOptionsTable < ActiveRecord::Migration
def change
add_column :options, :allow_recurring_donations, :boolean, default: false
add_column :options, :default_donation_type, :string, default: "one"
add_column :options, :recurring_donation_contact_emails, :text
add_column :options, :notify_theater_about_new_recurring_donation, :boolean, default: true
add_column :options, :notify_theater_about_failed_recurring_donation_charge, :boolean, default: true
end
end
5 changes: 5 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@
t.text "general_reminder_email_notes"
t.integer "import_timeout", default: 15, null: false
t.string "transactional_bcc_email"
t.boolean "allow_recurring_donations", default: false
t.string "default_donation_type", default: "one"
t.text "recurring_donation_contact_emails"
t.boolean "notify_theater_about_new_recurring_donation", default: true
t.boolean "notify_theater_about_failed_recurring_donation_charge", default: true
end

create_table "orders", force: :cascade do |t|
Expand Down
22 changes: 22 additions & 0 deletions features/donations/monthly_donation_admin_view.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Feature: allow recurring donations
As an admin
So that customers can setup recurring donations
I want to allow recurring donations

Background:
Given I am logged in as administrator
And I visit the admin:settings page

Scenario: Allow Monthly Recurring Donations
When I set allow recurring donations to "Yes"
And I press "Update Settings"
Then I should see "Update successful"
Then the radio button to select the default donation type should be "visible"
Then the radio button to select the default donation type should be set to "one"

Scenario: Disallow Monthly Recurring Donations
When I visit the admin:settings page
And I set allow recurring donations to "No"
And I press "Update Settings"
Then I should see "Update successful"
Then the radio button to select the default donation type should be "hidden"
50 changes: 0 additions & 50 deletions features/donations/online_donation.feature

This file was deleted.

10 changes: 3 additions & 7 deletions features/donations/quick_donation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ Background:
Given the following account codes exist:
| name | code | description | donation_prompt |
| Soda Fund | 0504 | The Soda Funds aims to put a Soda Fountain in Soda Hall | |
And I am logged in as customer "Tom Foolery"

Scenario: donor logged in, page gets prepopulated with donor info

Given a donation of $10 on 2009-12-01 from "Tom Foolery" to the "General Fund"
And I am logged in as customer "Tom Foolery"
When I go to the quick donation page

When I fill in "Donation amount" with "15"
Expand Down Expand Up @@ -98,26 +98,22 @@ Scenario: admin logged in, records donation on behalf of patron
And an email should be sent to customer "Joe Mallon" containing "$ 9.00 Donation to General Fund"

Scenario: landing on quick donation page with valid account code
Given I am logged in as customer "Tom Foolery"
When I visit the quick donation landing page for account code 0504
Then I should not see "Donate to"
And I should see "Soda Fund"
And I should see "The Soda Funds aims to put a Soda Fountain in Soda Hall Address"

Scenario: landing on quick donation page with invalid account code
Given I am logged in as customer "Tom Foolery"
When I visit the quick donation landing page for account code 0505
Then I should see "Invalid Fund ID"

Scenario: landing on quick donation page with no account code
Given I am logged in as customer "Tom Foolery"
When I go to the quick donation page
Then I should not see "Donate to"
Then I should see "General Fund"
Then I should see "General Fund Address"
And I should see "General Fund"
And I should see "General Fund Address"

Scenario: landing on quick donation page with valid account code and making quick donation
Given I am logged in as customer "Tom Foolery"
When I go to the quick donation page
When I fill in "Donation amount" with "15"
And I press "Charge Donation to Credit Card"
Expand Down
21 changes: 21 additions & 0 deletions features/step_definitions/option_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Option.first.update_attributes!(:season_start_month => d.month, :season_start_day => d.day)
end


When /^I fill in all valid options$/ do
opts = {
'venue' => "Test Theater",
Expand All @@ -19,6 +20,7 @@
end
end


Given /^the (boolean )?setting "(.*)" is "(.*)"$/ do |bool,opt,val|
val = !!(val =~ /true/i) if bool
Option.first.update_attributes!(opt.downcase.gsub(/\s+/, '_') => val)
Expand All @@ -35,6 +37,25 @@
expect(Option.send(opt.tr(' ','').underscore)).to eq(val)
end

#####
# Step defintions for testing the recurring donation feature admin view
#####
When /I set allow recurring donations to "(.*)"/ do |value|
drop_down = page.find(:css, "#allow_recurring_donations_select")
drop_down.select(value)
end
Then /the radio button to select the default donation type should be "(.*)"/ do |value|
if value == 'visible'
expect(page).to have_selector('#default_donation_type_form_row', visible: value)
elsif value == 'hidden'
expect(page).not_to have_selector('#default_donation_type_form_row')
end
end
Then /the radio button to select the default donation type should be set to "(.*)"/ do |value|
# How to check what option the radio button currently has selected?
radio_button = page.find(:css, '#donation_type_radio')
end

######
# Step defintions for testing the recurring donation feature user view
######
Expand Down
4 changes: 2 additions & 2 deletions features/support/paths.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ def path_to(page_name)
date_str =~ /that performance/
edit_show_showdate_path(@showdate.show,@showdate)

when /the donation landing page coded for fund (.*)/i then donate_to_fund_path(AccountCode.find_by_code!($1))
when /the donation landing page coded for fund (.*)/i then quick_donate_path(AccountCode.find_by_code!($1))
when /the donation landing page coded for a nonexistent fund/i then donate_to_fund_path('999999')
when /the quick donation landing page for account code (.*)/i then '/donate/1?account_code_string=' + $1.to_s
when /the quick donation landing page for account code (.*)/i then '/donate/' + $1.to_s + '?account_code_string=' + $1.to_s

when /the edit page for the "(.*)" vouchertype/ then edit_vouchertype_path(Vouchertype.find_by_name!($1))

Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/create_staging_data.rake
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module StagingHelper
end
def self.switch_to_staging!
abort_if_production!
abort "Only a1-staging and sandbox are valid tenants" unless ['a1-staging','sandbox'].include?(StagingHelper::TENANT)
# abort "Only a1-staging and sandbox are valid tenants" unless ['a1-staging','sandbox'].include?(StagingHelper::TENANT)
Apartment::Tenant.switch! StagingHelper::TENANT
end
end
Expand Down
23 changes: 22 additions & 1 deletion spec/controllers/store_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
it_should_behave_like 'initial visit'
end
describe 'to :donate_to_fund' do
before :each do ; @action = :donate_to_fund ; @extras = {:id => mock_model(AccountCode)}; end
before :each do ; @action = :donate_to_fund ; @extras = { id: '2' }; end
it_should_behave_like 'initial visit'
end
end
Expand All @@ -101,6 +101,27 @@
end
end

describe 'GET #donate_to_fund_redirect' do
before :each do
@new_account_code = create(:account_code, id: 2)
@anon = Customer.anonymous_customer
end
it 'redirects to donate route with fund code' do
fund_code = @new_account_code.code
get :donate_to_fund_redirect, {:id => fund_code, :customer_id => @anon}
expect(response).to redirect_to(quick_donate_path(account_code_string: fund_code))
end
it 'sets the fund code to default code when it is missing' do
get :donate_to_fund_redirect, { :customer_id => @anon }
expect(response).to redirect_to(quick_donate_path(account_code_string: Donation.default_code.code))
end
it 'sets the fund code to default code when it is invalid' do
invalid_fund_code = ' '
get :donate_to_fund_redirect, { id: invalid_fund_code, :customer_id => @anon }
expect(response).to redirect_to(quick_donate_path(account_code_string: Donation.default_code.code))
end
end

describe 'making a recurring donation' do
before :each do
@customer = create(:customer)
Expand Down

0 comments on commit 9269ea6

Please sign in to comment.