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

[REFERENCE ONLY] ignore #localized_amount #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
20 changes: 4 additions & 16 deletions lib/active_merchant/billing/gateway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,23 +272,11 @@ def three_decimal_currency?(currency)
self.currencies_with_three_decimal_places.include?(currency.to_s)
end

# Pin Payments does not want to mess with the amount being passed in.
# We correctly send exactly the amount that we want processed.
# eg. When we say 100 JPY, we mean 100 JPY, not 1 JPY.
def localized_amount(money, currency)
amount = amount(money)

return amount unless non_fractional_currency?(currency) || three_decimal_currency?(currency)
if non_fractional_currency?(currency)
if self.money_format == :cents
sprintf('%.0f', amount.to_f / 100)
else
amount.split('.').first
end
elsif three_decimal_currency?(currency)
if self.money_format == :cents
amount.to_s
else
sprintf('%.3f', (amount.to_f / 10))
end
end
amount(money)
end

def currency(money)
Expand Down
2 changes: 1 addition & 1 deletion lib/active_merchant/billing/gateways/fat_zebra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def add_creditcard(post, creditcard, options = {})
end

def add_extra_options(post, options)
extra = {}
extra = options.fetch(:extra, {})
extra[:ecm] = '32' if options[:recurring]
extra[:cavv] = options[:cavv] if options[:cavv]
extra[:xid] = options[:xid] if options[:xid]
Expand Down
4 changes: 2 additions & 2 deletions test/remote/gateways/remote_fat_zebra_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ def test_successful_purchase_with_metadata
end

def test_successful_purchase_with_3DS_information
assert response = @gateway.purchase(@amount, @credit_card, @options.merge(:cavv => 'MDRjN2MxZTAxYjllNTBkNmM2MTA=', :xid => 'MGVmMmNlMzI4NjAyOWU2ZDgwNTQ=', :sli => '05'))
assert response = @gateway.purchase(@amount, @credit_card, @options.merge(:extra => { :cavv => 'MDRjN2MxZTAxYjllNTBkNmM2MTA=', :xid => 'MGVmMmNlMzI4NjAyOWU2ZDgwNTQ=', :sli => '05' }))
assert_success response
assert_equal 'Approved', response.message
end

def test_failed_purchase_with_incomplete_3DS_information
assert response = @gateway.purchase(@amount, @credit_card, @options.merge(:cavv => 'MDRjN2MxZTAxYjllNTBkNmM2MTA=', :sli => '05'))
assert response = @gateway.purchase(@amount, @credit_card, @options.merge(:extra => { :cavv => 'MDRjN2MxZTAxYjllNTBkNmM2MTA=', :sli => '05' }))
assert_failure response
assert_match %r{Extra/xid is required for SLI 05}, response.message
end
Expand Down