Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VCR integration #320

Merged
merged 9 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ newrelic_agent.log
!/app/assets/builds/.keep
.terraform.lock.hcl
**/.terraform/*
*.bak
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ group :development, :test do
gem 'rubocop-rails-omakase', require: false
gem 'rubocop-rake'
gem 'rubocop-rspec'
gem 'vcr'
gem 'webmock'
end

group :development do
Expand Down
20 changes: 17 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ GEM
securerandom (>= 0.3)
tzinfo (~> 2.0, >= 2.0.5)
uri (>= 0.13.1)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
airbrussh (1.5.3)
sshkit (>= 1.6.1, != 1.7.0)
annotate (3.2.0)
Expand Down Expand Up @@ -138,6 +140,9 @@ GEM
unaccent (~> 0.3)
country_select (10.0.0)
countries (> 5.0, < 8.0)
crack (1.0.0)
bigdecimal
rexml
crass (1.0.6)
cssbundling-rails (1.4.1)
railties (>= 6.0.0)
Expand Down Expand Up @@ -182,6 +187,7 @@ GEM
activesupport (>= 5.1)
haml (>= 4.0.6)
railties (>= 5.1)
hashdiff (1.1.1)
hashie (5.0.0)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
Expand Down Expand Up @@ -268,6 +274,7 @@ GEM
activemodel (>= 5.0)
psych (5.1.2)
stringio
public_suffix (6.0.1)
puma (6.4.3)
nio4r (~> 2.0)
puma-status (1.7)
Expand Down Expand Up @@ -328,6 +335,7 @@ GEM
responders (3.1.1)
actionpack (>= 5.2)
railties (>= 5.2)
rexml (3.3.8)
rouge (4.4.0)
rspec (3.13.0)
rspec-core (~> 3.13.0)
Expand Down Expand Up @@ -418,6 +426,8 @@ GEM
unicode-display_width (2.6.0)
uri (0.13.1)
useragent (0.16.10)
vcr (6.3.1)
base64
ventable (1.3.1)
activesupport (>= 5)
warden (1.2.9)
Expand All @@ -427,6 +437,10 @@ GEM
activemodel (>= 6.0.0)
bindex (>= 0.4.0)
railties (>= 6.0.0)
webmock (3.24.0)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
webrick (1.8.2)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
Expand All @@ -436,13 +450,11 @@ GEM

PLATFORMS
aarch64-linux
aarch64-linux-musl
arm-linux
arm64-darwin
x86-linux
x86_64-darwin
x86_64-linux
x86_64-linux-musl

DEPENDENCIES
accept_values_for
Expand Down Expand Up @@ -512,12 +524,14 @@ DEPENDENCIES
timeout
turbo-rails
tzinfo-data
vcr
ventable (>= 1.3)
web-console
webmock
yard

RUBY VERSION
ruby 3.3.5p100

BUNDLED WITH
2.5.6
2.5.16
9 changes: 1 addition & 8 deletions app/controllers/payments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,8 @@ def sent

def mark_payment_completed
Payment.transaction do
kigster marked this conversation as resolved.
Show resolved Hide resolved
# if we have a payment explanation, mark as other. else mark received
@payment.mark_received
@payment.ticket_request.mark_complete
@payment.reload

@payment.request_completed
flash.now[:notice] = 'Payment has been received and marked as completed.'

# Deliver the email asynchronously
PaymentMailer.payment_received(@payment).deliver_later
rescue StandardError => e
Rails.logger.error("#mark_payment_completed() => error marking payment as received: #{e.message}")
flash.now[:error] = "ERROR: #{e.message}"
Expand Down
26 changes: 20 additions & 6 deletions app/models/payment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def save_with_payment_intent
Rails.logger.debug { "save_with_payment_intent: cost => #{cost}}" }

begin
# Create new Stripe PaymentIntent
# Create new Stripe PaymentIntent (external Stripe API)
self.payment_intent = create_payment_intent(cost)
log_intent(payment_intent)
self.stripe_payment_id = payment_intent.id
Expand Down Expand Up @@ -141,6 +141,7 @@ def retrieve_payment_intent
end

Rails.logger.debug { "retrieve_payment_intent payment => #{inspect}}" }
self.payment_intent
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove self since it's a reader

end

# cancel Stripe PaymentIntent if is in progress
Expand Down Expand Up @@ -189,11 +190,6 @@ def status_name
status.humanize
end

# Manually mark that a payment was received.
def mark_received
status_received!
end

def in_progress?
status_in_progress?
end
Expand Down Expand Up @@ -221,6 +217,24 @@ def convert_old_status!
save!
end

# Manually mark that a payment was received.
def mark_received
status_received!
end

# In transaction,
# mark payment received and ticket request completed
# Send off PaymentMailer for payment received
def request_completed
mark_received
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to wrap these two in a transaction?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll move the transaction from the controller.

ticket_request.mark_complete

# Deliver the email asynchronously
PaymentMailer.payment_received(self).deliver_later

self.reload
end

private

def log_intent(payment_intent)
Expand Down
Loading