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

[v3.1] Fix creating refund with amount in foreign format #4345

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions core/app/models/spree/refund.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ def total_amount_reimbursed_for(reimbursement)
end
end

# Sets this price's amount to a new value, parsing it if the new value is
# a string.
#
# @param price [String, #to_d] a new amount
def amount=(price)
self[:amount] = Spree::LocalizedNumber.parse(price)
end

def description
payment.payment_method.name
end
Expand Down
15 changes: 15 additions & 0 deletions core/spec/models/spree/refund_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@
it "does not attempt to process a transaction" do
expect(subject.transaction_id).to be_nil
end

context "with a european price format" do
let(:amount) { "100,00" }
let(:payment_amount) { 200.0 }

before do
expect(I18n).to receive(:t).with(:'number.currency.format.separator') do
","
end
end

it "creates a refund record" do
expect { subject }.to change { Spree::Refund.count }.by(1)
end
end
end

describe "#perform!" do
Expand Down