Skip to content

Commit

Permalink
Do not automatically perform! after redund creation
Browse files Browse the repository at this point in the history
After solidusio/solidus#3641 it's requested to create and
perform refunds in two different operations. This commit
aligns the code to the new standard.

Co-authored-by: Rainer Dema <rainerdema@users.noreply.github.com>
  • Loading branch information
kennyadsl and rainerdema committed Jan 29, 2021
1 parent 6f55ac8 commit ecbd45c
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions app/models/spree/payment_method/stripe_credit_card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,13 @@ def payment_intents_refund_reason

def try_void(payment)
if v3_intents? && payment.completed?
payment.refunds.create!(
amount: payment.credit_allowed,
reason: payment_intents_refund_reason
).response
refund = perform_refund(payment)

if refund.respnd_to?(:perform_response)
refund.perform_response
else
refund.response
end
else
void(payment.response_code, nil, nil)
end
Expand Down Expand Up @@ -190,6 +193,24 @@ def update_source!(source)
source.cc_type = CARD_TYPE_MAPPING[source.cc_type] if CARD_TYPE_MAPPING.include?(source.cc_type)
source
end

def perform_refund(payment)
refund = payment.refunds.build(
amount: payment.credit_allowed,
reason: payment_intents_refund_reason
)

if refund.respond_to?(:perform_after_create)
refund.perform_after_create = false
refund.save!
refund.perform!
else
refund.save!
refund.perform! if Gem::Requirement.new('>= 3.0.0.alpha').satisfied_by?(Spree.solidus_gem_version)
end

refund
end
end
end
end

0 comments on commit ecbd45c

Please sign in to comment.