-
Notifications
You must be signed in to change notification settings - Fork 3
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
Implements Stripe Refund functionality and wires the button #192
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -253,8 +253,13 @@ def refunded? | |
status == STATUS_REFUNDED | ||
end | ||
|
||
def mark_refunded | ||
Rails.logger.info { "ticket request marking refunded: #{id}" } | ||
update status: STATUS_REFUNDED | ||
kigster marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
|
||
def payment_received? | ||
payment.try(:stripe_payment_id) && payment.received? | ||
payment&.received? | ||
end | ||
|
||
# not able to purchase tickets in this state | ||
|
@@ -270,23 +275,20 @@ def refund | |
if refunded? | ||
errors.add(:base, 'Cannot refund a ticket that has already been refunded') | ||
return false | ||
elsif !completed? || !payment&.refundable? | ||
errors.add(:base, 'Cannot refund a ticket that has not been purchased') | ||
return false | ||
end | ||
|
||
return if payment&.received? | ||
|
||
errors.add(:base, 'Cannot refund a ticket that has not been purchased') | ||
false | ||
|
||
# XXX need to build refund. Put into Payment model | ||
# begin | ||
# TicketRequest.transaction do | ||
# Stripe::Charge.retrieve(payment.stripe_charge_id).refund | ||
# return update(status: STATUS_REFUNDED) | ||
# end | ||
# rescue Stripe::StripeError => e | ||
# errors.add(:base, "Cannot refund ticket: #{e.message}") | ||
# false | ||
# end | ||
# issue refund for payment | ||
Rails.logger.info { "ticket_request [#{id}] payment [#{payment.id}] refunding [#{payment.stripe_payment_id}]" } | ||
if payment.refund_payment | ||
mark_refunded | ||
true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the |
||
else | ||
Rails.logger.error { "ticket_request failed to refund [#{payment.stripe_payment_id}]" } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add the cause to the logger, by adding |
||
false | ||
end | ||
end | ||
|
||
def price | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class AddStripeRefundIdToPayments < ActiveRecord::Migration[7.1] | ||
def change | ||
add_column :payments, :stripe_refund_id, :string | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might want to call
save!
which raises exception if it can't be saved.Then you could add additional rescue: