Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
f56a3b8
add pay gem
jmilljr24 Mar 28, 2026
24506db
pay gem migrations
jmilljr24 Mar 28, 2026
c7d0360
add pay_customer to person
jmilljr24 Mar 29, 2026
aef5332
create allocations migration
jmilljr24 Mar 29, 2026
e2fa10f
change payments to sti
jmilljr24 Mar 29, 2026
ebab3ff
add refunds migration
jmilljr24 Mar 29, 2026
549f234
fix migration
jmilljr24 Mar 29, 2026
6fa31f2
update models to use allocations
jmilljr24 Mar 29, 2026
1b5949e
Merge branch 'main' into add-pay-gem
jmilljr24 Apr 6, 2026
c2dfc28
add allocation index with cash and check payment form
jmilljr24 Apr 6, 2026
84683be
create allocation form
jmilljr24 Apr 6, 2026
27a72e9
us turbo stream replace
jmilljr24 Apr 6, 2026
0c0d224
change payment totals to allocations_sum
jmilljr24 Apr 6, 2026
95c8fb1
clean up new payment form
jmilljr24 Apr 6, 2026
e8ee56b
add stimulus selection for payer typer
jmilljr24 Apr 6, 2026
4388f42
fix toggle of payer type search
jmilljr24 Apr 6, 2026
1386148
fix form style
jmilljr24 Apr 6, 2026
dc9620f
add dollars to UI
jmilljr24 Apr 6, 2026
7bf4311
add dollars to allocations and add payment index pagination
jmilljr24 Apr 6, 2026
c733ac6
titlize payment type
jmilljr24 Apr 6, 2026
6aeb0b5
display amount input with decimal
jmilljr24 Apr 6, 2026
1e11b71
add allocated amount to payment
jmilljr24 Apr 6, 2026
191f130
handle allocation payment transaction
jmilljr24 Apr 6, 2026
260dc5d
allocate payments manually
jmilljr24 Apr 6, 2026
287eaf2
add refunds to payments
jmilljr24 Apr 6, 2026
f4dc62e
show refunds and allocation source
jmilljr24 Apr 6, 2026
1860791
add refund method
jmilljr24 Apr 6, 2026
433b96b
add revert of allocation
jmilljr24 Apr 7, 2026
3167847
add event cost validation for allocation
jmilljr24 Apr 7, 2026
8d55619
add flash errors
jmilljr24 Apr 7, 2026
e35cf04
show reverted reference
jmilljr24 Apr 7, 2026
978ebe5
fix allocated amount update
jmilljr24 Apr 7, 2026
6e77bcf
change to amount remaining
jmilljr24 Apr 7, 2026
4cce141
update flash with remaining on payment
jmilljr24 Apr 7, 2026
366d0ef
add stripe env
jmilljr24 Apr 7, 2026
ef6b0f0
add stripe checkout
jmilljr24 Apr 7, 2026
d7fb872
create payment when pay charge is paid
jmilljr24 Apr 7, 2026
c6d9cbd
add stripe refund id to refunds
jmilljr24 Apr 7, 2026
f13ff0a
order payment lists newest first
jmilljr24 Apr 8, 2026
0ebcfd2
fix amount cents remaning for new payments
jmilljr24 Apr 8, 2026
fb6ed64
refactor search type selector to be generic
jmilljr24 Apr 9, 2026
587295e
add join scope to remote search concern
jmilljr24 Apr 9, 2026
d1b146b
Merge branch 'main' into add-pay-gem
jmilljr24 Apr 9, 2026
57ee01f
create payment seeds
jmilljr24 Apr 9, 2026
aa2b24f
add seed for unallocation
jmilljr24 Apr 9, 2026
c08322b
fix event create seed
jmilljr24 Apr 9, 2026
454f868
add cursor to revert button
jmilljr24 Apr 9, 2026
1929058
more refund query to controller
jmilljr24 Apr 9, 2026
8fa8800
add search boxes for payments
jmilljr24 Apr 9, 2026
8928dad
fix search on amount remaining
jmilljr24 Apr 9, 2026
eaab324
fix dropdown toggle
jmilljr24 Apr 9, 2026
6db7f34
add turbo frame results
jmilljr24 Apr 9, 2026
19a43be
exclude remove select input typing from auto submit
jmilljr24 Apr 9, 2026
ea33b8f
fix payment type select
jmilljr24 Apr 9, 2026
c8f86e4
fix new payment form type select
jmilljr24 Apr 9, 2026
eb1b580
use turbo frame top for payment view link
jmilljr24 Apr 9, 2026
e1e332c
remove redudant payment name
jmilljr24 Apr 9, 2026
dddf918
hard code stripe name
jmilljr24 Apr 9, 2026
9687507
comments
jmilljr24 Apr 9, 2026
172f753
fix check for nil on event allocation
jmilljr24 Apr 9, 2026
ba6614e
rubocop
jmilljr24 Apr 9, 2026
2ee5178
add turbo flash to allocations
jmilljr24 Apr 10, 2026
0812b91
add allocation validation
jmilljr24 Apr 10, 2026
7622884
add search to allocations
jmilljr24 Apr 10, 2026
2ae0b5e
fix turbo frame on allocation search
jmilljr24 Apr 10, 2026
b303d52
move search box columns
jmilljr24 Apr 10, 2026
a77703c
add placeholder for type select
jmilljr24 Apr 11, 2026
5b25736
clear search
jmilljr24 Apr 11, 2026
e880e14
check for outlet
jmilljr24 Apr 12, 2026
969ce18
justify end for clear filters buttons
jmilljr24 Apr 12, 2026
3ea05bd
use model card helper
jmilljr24 Apr 13, 2026
7519974
clean up
jmilljr24 Apr 13, 2026
641f8aa
Fix system notifications showing Oopsie error (#1488)
maebeale Apr 17, 2026
c48d1da
Bump vulnerable gems flagged by bundler-audit (#1495)
maebeale May 15, 2026
22deee6
Bump actions/upload-artifact from 4 to 7 (#1485)
dependabot[bot] May 15, 2026
4a65874
Hide locked users' profiles from the non-admin people index (#1489)
maebeale May 15, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@ RAILS_SERVE_STATIC_FILES=true
ORGANIZATION_NAME=A Window Between Worlds
REPLY_TO_EMAIL=umberto.user@example.com
BLAZER_DATABASE_URL=db_url # Optional if you want to use a different db for Blazer

# Pay Gem
STRIPE_PUBLIC_KEY=test
STRIPE_PRIVATE_KEY=test
STRIPE_WEBHOOK_RECEIVE_TEST_EVENTS=true
# STRIPE_SIGNING_SECRET=
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:
CI: "true"

- name: Publish test results
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v7
if: always()
with:
name: rspec-results
Expand Down
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ gem "active_storage_validations", "~> 3.0"

gem "solid_cache"

# Payments
gem "pay", "~> 11.4"
gem "stripe", "~> 18.0"
gem "receipts", "~> 2.4"

group :development do
gem "rubocop-rails-omakase", require: false
end
Expand Down
71 changes: 47 additions & 24 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ GEM
securerandom (>= 0.3)
tzinfo (~> 2.0, >= 2.0.5)
uri (>= 0.13.1)
addressable (2.8.8)
addressable (2.9.0)
public_suffix (>= 2.0.2, < 8.0)
ahoy_matey (5.4.1)
activesupport (>= 7.1)
Expand Down Expand Up @@ -315,7 +315,7 @@ GEM
multi_xml (0.8.1)
bigdecimal (>= 3.1, < 5)
mutex_m (0.3.0)
net-imap (0.6.3)
net-imap (0.6.4)
date
net-protocol
net-pop (0.1.2)
Expand All @@ -325,21 +325,21 @@ GEM
net-smtp (0.5.1)
net-protocol
nio4r (2.7.5)
nokogiri (1.19.2-aarch64-linux-gnu)
nokogiri (1.19.3-aarch64-linux-gnu)
racc (~> 1.4)
nokogiri (1.19.2-aarch64-linux-musl)
nokogiri (1.19.3-aarch64-linux-musl)
racc (~> 1.4)
nokogiri (1.19.2-arm-linux-gnu)
nokogiri (1.19.3-arm-linux-gnu)
racc (~> 1.4)
nokogiri (1.19.2-arm-linux-musl)
nokogiri (1.19.3-arm-linux-musl)
racc (~> 1.4)
nokogiri (1.19.2-arm64-darwin)
nokogiri (1.19.3-arm64-darwin)
racc (~> 1.4)
nokogiri (1.19.2-x86_64-darwin)
nokogiri (1.19.3-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.19.2-x86_64-linux-gnu)
nokogiri (1.19.3-x86_64-linux-gnu)
racc (~> 1.4)
nokogiri (1.19.2-x86_64-linux-musl)
nokogiri (1.19.3-x86_64-linux-musl)
racc (~> 1.4)
opentelemetry-api (1.7.0)
opentelemetry-common (0.23.0)
Expand Down Expand Up @@ -520,12 +520,20 @@ GEM
parser (3.3.10.1)
ast (~> 2.4.1)
racc
pay (11.4.3)
rails (>= 7.0.0)
pdf-core (0.9.0)
polyglot (0.3.5)
positioning (0.4.7)
activerecord (>= 6.1)
activesupport (>= 6.1)
pp (0.6.3)
prettyprint
prawn (2.4.0)
pdf-core (~> 0.9.0)
ttfunk (~> 1.7)
prawn-table (0.2.2)
prawn (>= 1.3.0, < 3.0.0)
premailer (1.27.0)
addressable
css_parser (>= 1.19.0)
Expand Down Expand Up @@ -553,12 +561,12 @@ GEM
nio4r (~> 2.0)
raabro (1.4.0)
racc (1.8.1)
rack (3.2.5)
rack (3.2.6)
rack-mini-profiler (4.0.1)
rack (>= 1.2.0)
rack-proxy (0.7.7)
rack
rack-session (2.1.1)
rack-session (2.1.2)
base64 (>= 0.1.0)
rack (>= 3.0.0)
rack-test (2.2.0)
Expand Down Expand Up @@ -604,6 +612,9 @@ GEM
erb
psych (>= 4.0.0)
tsort
receipts (2.4.0)
prawn (>= 1.3.0, < 3.0.0)
prawn-table (~> 0.2.1)
regexp_parser (2.11.3)
reline (0.6.3)
io-console (~> 0.5)
Expand Down Expand Up @@ -709,12 +720,14 @@ GEM
stimulus-rails (1.3.4)
railties (>= 6.0.0)
stringio (3.2.0)
stripe (18.4.2)
thor (1.5.0)
timeout (0.6.1)
treetop (1.6.18)
polyglot (~> 0.3)
trilogy (2.9.0)
tsort (0.2.0)
ttfunk (1.7.0)
turbo-rails (2.0.23)
actionpack (>= 7.1.0)
railties (>= 7.1.0)
Expand Down Expand Up @@ -800,13 +813,15 @@ DEPENDENCIES
opentelemetry-instrumentation-all
opentelemetry-sdk
ostruct
pay (~> 11.4)
positioning (~> 0.4.7)
premailer-rails
pry-coolline
pry-rails
puma (~> 6.0)
rack-mini-profiler (~> 4.0)
rails (~> 8.1.0)
receipts (~> 2.4)
rspec-rails
rubocop-rails-omakase
search_cop
Expand All @@ -819,6 +834,7 @@ DEPENDENCIES
solid_queue (~> 1.3)
sprockets-rails (~> 3.2.2)
stimulus-rails (~> 1.3)
stripe (~> 18.0)
trilogy (= 2.9.0)
turbo-rails (~> 2.0)
uglifier
Expand All @@ -841,7 +857,7 @@ CHECKSUMS
activerecord (8.1.3) sha256=8003be7b2466ba0a2a670e603eeb0a61dd66058fccecfc49901e775260ac70ab
activestorage (8.1.3) sha256=0564ce9309143951a67615e1bb4e090ee54b8befed417133cae614479b46384d
activesupport (8.1.3) sha256=21a5e0dfbd4c3ddd9e1317ec6a4d782fa226e7867dc70b0743acda81a1dca20e
addressable (2.8.8) sha256=7c13b8f9536cf6364c03b9d417c19986019e28f7c00ac8132da4eb0fe393b057
addressable (2.9.0) sha256=7fdf6ac3660f7f4e867a0838be3f6cf722ace541dd97767fa42bc6cfa980c7af
ahoy_matey (5.4.1) sha256=b9ccac7f497889de6982f1503b41a7e275c5a6e4e12a6947b418c69c2c2119b1
ast (2.4.3) sha256=954615157c1d6a382bc27d690d973195e79db7f55e9765ac7c481c60bdb4d383
aws-eventstream (1.4.0) sha256=116bf85c436200d1060811e6f5d2d40c88f65448f2125bc77ffce5121e6e183b
Expand Down Expand Up @@ -943,19 +959,19 @@ CHECKSUMS
msgpack (1.8.0) sha256=e64ce0212000d016809f5048b48eb3a65ffb169db22238fb4b72472fecb2d732
multi_xml (0.8.1) sha256=addba0290bac34e9088bfe73dc4878530297a82a7bbd66cb44dcd0a4b86edf5a
mutex_m (0.3.0) sha256=cfcb04ac16b69c4813777022fdceda24e9f798e48092a2b817eb4c0a782b0751
net-imap (0.6.3) sha256=9bab75f876596d09ee7bf911a291da478e0cd6badc54dfb82874855ccc82f2ad
net-imap (0.6.4) sha256=9a5598c67a3022c284d98430ef1d4948e7dbdb62596f61081ea8ca933270a02b
net-pop (0.1.2) sha256=848b4e982013c15b2f0382792268763b748cce91c9e91e36b0f27ed26420dff3
net-protocol (0.2.2) sha256=aa73e0cba6a125369de9837b8d8ef82a61849360eba0521900e2c3713aa162a8
net-smtp (0.5.1) sha256=ed96a0af63c524fceb4b29b0d352195c30d82dd916a42f03c62a3a70e5b70736
nio4r (2.7.5) sha256=6c90168e48fb5f8e768419c93abb94ba2b892a1d0602cb06eef16d8b7df1dca1
nokogiri (1.19.2-aarch64-linux-gnu) sha256=c34d5c8208025587554608e98fd88ab125b29c80f9352b821964e9a5d5cfbd19
nokogiri (1.19.2-aarch64-linux-musl) sha256=7f6b4b0202d507326841a4f790294bf75098aef50c7173443812e3ac5cb06515
nokogiri (1.19.2-arm-linux-gnu) sha256=b7fa1139016f3dc850bda1260988f0d749934a939d04ef2da13bec060d7d5081
nokogiri (1.19.2-arm-linux-musl) sha256=61114d44f6742ff72194a1b3020967201e2eb982814778d130f6471c11f9828c
nokogiri (1.19.2-arm64-darwin) sha256=58d8ea2e31a967b843b70487a44c14c8ba1866daa1b9da9be9dbdf1b43dee205
nokogiri (1.19.2-x86_64-darwin) sha256=7d9af11fda72dfaa2961d8c4d5380ca0b51bc389dc5f8d4b859b9644f195e7a4
nokogiri (1.19.2-x86_64-linux-gnu) sha256=fa8feca882b73e871a9845f3817a72e9734c8e974bdc4fbad6e4bc6e8076b94f
nokogiri (1.19.2-x86_64-linux-musl) sha256=93128448e61a9383a30baef041bf1f5817e22f297a1d400521e90294445069a8
nokogiri (1.19.3-aarch64-linux-gnu) sha256=46b89e5d7b9e844c2ee360794240c6ea2a4e6fa0c5892a4ed487db621224b639
nokogiri (1.19.3-aarch64-linux-musl) sha256=8392dfdcd21be7a94dbbe9ccc138dea01b97b24cb2dc02a114ca98bfb1d9a0b7
nokogiri (1.19.3-arm-linux-gnu) sha256=3919d5ffc334ad778a4a9eb88fda7dcb8b1fb58c8a52ac640c6dcd2f038e774f
nokogiri (1.19.3-arm-linux-musl) sha256=9ce1cb6346bb9c67b1550eb537aa183ead91e4b6eadb2f36ade02d8dd2a79fb6
nokogiri (1.19.3-arm64-darwin) sha256=71b9bd424b1b7abc18b05052a1a3cfd3627abdca62be280854cc411791357e42
nokogiri (1.19.3-x86_64-darwin) sha256=77f3fba57d46c53ab31e62fc6c28f705109d1bf6264356c76f132b2be5728d4d
nokogiri (1.19.3-x86_64-linux-gnu) sha256=2f5078620fe12e83669b5b17311b32532a8153d02eee7ad06948b926d6080976
nokogiri (1.19.3-x86_64-linux-musl) sha256=248c906d2166eca5efb56d52fdee5f9a1f51d69a72e2b64fdac647b4ce39ea3f
opentelemetry-api (1.7.0) sha256=ccfd264ea6f2db5bf4185e3c07a1297977b44a944e2ce65457c4fe63a697214f
opentelemetry-common (0.23.0) sha256=da721190479d57bae0ad2207468f47f3e2c3b9a91024b5bc32c9d280183eb32c
opentelemetry-exporter-otlp (0.31.1) sha256=5358be17d7849cbcc4f49e1fc24105edc780a6f96c8e57b64192ab9a8e47474a
Expand Down Expand Up @@ -1015,9 +1031,13 @@ CHECKSUMS
ostruct (0.6.3) sha256=95a2ed4a4bd1d190784e666b47b2d3f078e4a9efda2fccf18f84ddc6538ed912
parallel (1.27.0) sha256=4ac151e1806b755fb4e2dc2332cbf0e54f2e24ba821ff2d3dcf86bf6dc4ae130
parser (3.3.10.1) sha256=06f6a725d2cd91e5e7f2b7c32ba143631e1f7c8ae2fb918fc4cebec187e6a688
pay (11.4.3) sha256=f3d50b1a900ab0a7bfe9ba9fda631b2f5faf0c95236dd3d2afa9effc9bfb15e8
pdf-core (0.9.0) sha256=4f368b2f12b57ec979872d4bf4bd1a67e8648e0c81ab89801431d2fc89f4e0bb
polyglot (0.3.5) sha256=59d66ef5e3c166431c39cb8b7c1d02af419051352f27912f6a43981b3def16af
positioning (0.4.7) sha256=c9a8cfba8b99180bd2b05022cdbcc7b234ea8bb1aa9101010e06bdda9a7bb220
pp (0.6.3) sha256=2951d514450b93ccfeb1df7d021cae0da16e0a7f95ee1e2273719669d0ab9df6
prawn (2.4.0) sha256=82062744f7126c2d77501da253a154271790254dfa8c309b8e52e79bc5de2abd
prawn-table (0.2.2) sha256=336d46e39e003f77bf973337a958af6a68300b941c85cb22288872dc2b36addb
premailer (1.27.0) sha256=0fe2348cd82738855c482b31c915a06ecb1d3ad004578c19042905196ddbd1e7
premailer-rails (1.12.0) sha256=c13815d161b9bc7f7d3d81396b0bb0a61a90fa9bd89931548bf4e537c7710400
prettyprint (0.2.0) sha256=2bc9e15581a94742064a3cc8b0fb9d45aae3d03a1baa6ef80922627a0766f193
Expand All @@ -1030,10 +1050,10 @@ CHECKSUMS
puma (6.6.1) sha256=b9b56e4a4ea75d1bfa6d9e1972ee2c9f43d0883f011826d914e8e37b3694ea1e
raabro (1.4.0) sha256=d4fa9ff5172391edb92b242eed8be802d1934b1464061ae5e70d80962c5da882
racc (1.8.1) sha256=4a7f6929691dbec8b5209a0b373bc2614882b55fc5d2e447a21aaa691303d62f
rack (3.2.5) sha256=4cbd0974c0b79f7a139b4812004a62e4c60b145cba76422e288ee670601ed6d3
rack (3.2.6) sha256=5ed78e1f73b2e25679bec7d45ee2d4483cc4146eb1be0264fc4d94cb5ef212c2
rack-mini-profiler (4.0.1) sha256=485810c23211f908196c896ea10cad72ed68780ee2998bec1f1dfd7558263d78
rack-proxy (0.7.7) sha256=446a4b57001022145d5c3ba73b775f66a2260eaf7420c6907483141900395c8a
rack-session (2.1.1) sha256=0b6dc07dea7e4b583f58a48e8b806d4c9f1c6c9214ebc202ec94562cbea2e4e9
rack-session (2.1.2) sha256=595434f8c0c3473ae7d7ac56ecda6cc6dfd9d37c0b2b5255330aa1576967ffe8
rack-test (2.2.0) sha256=005a36692c306ac0b4a9350355ee080fd09ddef1148a5f8b2ac636c720f5c463
rackup (2.3.1) sha256=6c79c26753778e90983761d677a48937ee3192b3ffef6bc963c0950f94688868
rails (8.1.3) sha256=6d017ba5348c98fc909753a8169b21d44de14d2a0b92d140d1a966834c3c9cd3
Expand All @@ -1045,6 +1065,7 @@ CHECKSUMS
rb-fsevent (0.11.2) sha256=43900b972e7301d6570f64b850a5aa67833ee7d87b458ee92805d56b7318aefe
rb-inotify (0.11.1) sha256=a0a700441239b0ff18eb65e3866236cd78613d6b9f78fea1f9ac47a85e47be6e
rdoc (7.2.0) sha256=8650f76cd4009c3b54955eb5d7e3a075c60a57276766ebf36f9085e8c9f23192
receipts (2.4.0) sha256=64a7d9d95d223694106719dc10fb9291fa362e6bc684228d5cde4b772392fa74
regexp_parser (2.11.3) sha256=ca13f381a173b7a93450e53459075c9b76a10433caadcb2f1180f2c741fc55a4
reline (0.6.3) sha256=1198b04973565b36ec0f11542ab3f5cfeeec34823f4e54cebde90968092b1835
request_store (1.7.0) sha256=e1b75d5346a315f452242a68c937ef8e48b215b9453a77a6c0acdca2934c88cb
Expand Down Expand Up @@ -1081,11 +1102,13 @@ CHECKSUMS
sprockets-rails (3.2.2) sha256=62862bce136e31d7497eededde5f7730d4096bc8ef33ef7037c41423ccf89557
stimulus-rails (1.3.4) sha256=765676ffa1f33af64ce026d26b48e8ffb2e0b94e0f50e9119e11d6107d67cb06
stringio (3.2.0) sha256=c37cb2e58b4ffbd33fe5cd948c05934af997b36e0b6ca6fdf43afa234cf222e1
stripe (18.4.2) sha256=fd08a73ab87fc0b0ad938ca71293e1051e593001b70de5e9fcf12d1097133831
thor (1.5.0) sha256=e3a9e55fe857e44859ce104a84675ab6e8cd59c650a49106a05f55f136425e73
timeout (0.6.1) sha256=78f57368a7e7bbadec56971f78a3f5ecbcfb59b7fcbb0a3ed6ddc08a5094accb
treetop (1.6.18) sha256=a3043f32f1c652aa2abdf3a3848edb2d2f69897257af2675516ac61355c183da
trilogy (2.9.0) sha256=a2d63b663ba68a4758e15d1f9afb228f5d16efc7fe7cea68699e1c106ef6067f
tsort (0.2.0) sha256=9650a793f6859a43b6641671278f79cfead60ac714148aabe4e3f0060480089f
ttfunk (1.7.0) sha256=2370ba484b1891c70bdcafd3448cfd82a32dd794802d81d720a64c15d3ef2a96
turbo-rails (2.0.23) sha256=ee0d90733aafff056cf51ff11e803d65e43cae258cc55f6492020ec1f9f9315f
tzinfo (2.0.6) sha256=8daf828cc77bcf7d63b0e3bdb6caa47e2272dcfaf4fbfe46f8c3a9df087a829b
uglifier (4.2.1) sha256=75d42b81b10bfd21e7a427fabb1d49ff5ea7bda3c4a5039ddb2a78d194c6f5aa
Expand Down
146 changes: 146 additions & 0 deletions app/controllers/allocations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
class AllocationsController < ApplicationController
before_action :authenticate_user!

def index
authorize!
if params[:allocatable_sgid].present?
@allocatable = GlobalID::Locator.locate_signed(params[:allocatable_sgid])
@allocations = @allocatable.allocations.includes(:source).order(created_at: :desc).paginate(page: params[:page], per_page: 10)
else
if turbo_frame_request?
@allocations = Allocation.search_by_params(params).includes(:source).order(created_at: :desc).paginate(page: params[:page], per_page: 10)
render :allocation_results
else
@allocations = Allocation.search_by_params(params).includes(:source).order(created_at: :desc).paginate(page: params[:page], per_page: 10)
end
end
end

def new
authorize!

if params[:source_sgid].present?
@source = GlobalID::Locator.locate_signed(params[:source_sgid])
end

@allocation = Allocation.new(source: @source)
end

def create
authorize!

amount_val = allocation_params[:amount_dollars].present? ? (allocation_params[:amount_dollars].to_d * 100).to_i : 0

@allocation = Allocation.new(
source_type: allocation_params[:source_type],
source_id: allocation_params[:source_id],
allocatable_type: allocation_params[:allocatable_type],
allocatable_id: allocation_params[:allocatable_id],
amount: amount_val
)

if @allocation.source_type && @allocation.source_id
@source = @allocation.source_type.constantize.find_by(id: @allocation.source_id)
end

if @allocation.allocatable_type == "EventRegistration" && @allocation.allocatable.present?
unless validate_event_registration_cost(amount_val)
flash.now[:error] = @allocation.errors.full_messages.join(", ")
respond_to do |format|
format.turbo_stream { render turbo_stream: turbo_stream.replace("flash_now", partial: "shared/flash_messages"), status: :unprocessable_content }
format.html { render :new, status: :unprocessable_content }
end
return
end
end

unless @source.present?
@allocation.errors.add(:base, "Source is required")
render :new, status: :unprocessable_content
return
end

@source.with_lock do
if @source.is_a?(Payment)
if @allocation.amount > @source.amount_cents_remaining
@allocation.errors.add(:base, "Cannot exceed remaining amount ($#{@source.remaining_dollars})")

flash.now[:error] = @allocation.errors.full_messages.join(", ")
respond_to do |format|
format.turbo_stream { render turbo_stream: turbo_stream.replace("flash_now", partial: "shared/flash_messages"), status: :unprocessable_content }
format.html { render :new, status: :unprocessable_content }
end
return
end

if @allocation.save
@source.update!(amount_cents_remaining: @source.amount_cents_remaining - amount_val)
flash[:notice] = "Allocation created. $#{'%.2f' % @source.remaining_dollars} remaining on payment."
redirect_to payment_path(@source)
else
render :new, status: :unprocessable_content
end
end
end
end

def revert
authorize!

@allocation = Allocation.find(params[:id])

if @allocation.reverted?
flash[:error] = "This allocation has already been reverted"
redirect_to payment_path(@allocation.source)
return
end

@revert = Allocation.new(
source: @allocation.source,
allocatable: @allocation.allocatable,
amount: -@allocation.amount
)

payment = @allocation.source

payment.with_lock do
ActiveRecord::Base.transaction do
if @revert.save
@allocation.update!(reverted_id: @revert.id)

payment.update!(amount_cents_remaining: payment.amount_cents_remaining + @allocation.amount)

redirect_to payment_path(payment), notice: "Allocation reverted"
else
flash[:error] = @revert.errors.full_messages.join(", ")
redirect_to payment_path(@allocation.source)
end
end
end
end

private

def validate_event_registration_cost(amount_val)
event_reg = @allocation.allocatable
event = event_reg.event
if event.cost_cents.blank?
@allocation.errors.add(:base, "Cannot allocate to a free event.")
return false
end
current_allocated = event_reg.allocations_sum || 0
new_total = current_allocated + amount_val

if new_total > event.cost_cents
remaining = [ event.cost_cents - current_allocated, 0 ].max
@allocation.errors.add(:base, "Cannot allocate more than remaining event cost. remaining: $#{'%.2f' % (remaining / 100.0)}")
return false
end

true
end

def allocation_params
params.expect(allocation: [ :source_type, :source_id, :allocatable_type, :allocatable_id, :amount_dollars ])
end
end
Loading
Loading