Skip to content
This repository has been archived by the owner on Apr 28, 2021. It is now read-only.

Commit

Permalink
Fix country code and contributor document on konduto data builder
Browse files Browse the repository at this point in the history
  • Loading branch information
stephannv committed Apr 13, 2020
1 parent 2e09ab8 commit e1722d3
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
catarse_pagarme (2.14.12)
catarse_pagarme (2.14.13)
countries (= 3.0.0)
konduto-ruby (= 2.1.0)
pagarme (= 2.1.4)
Expand Down
8 changes: 2 additions & 6 deletions app/controllers/catarse_pagarme/credit_cards_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,7 @@ def address_number
end

def document_number
user_document = contribution.user.cpf.try(:gsub, /[-.\/_\s]/, '')
card_owner_document = contribution.card_owner_document.try(:gsub, /[-.\/_\s]/, '')
fallback_document = '00000000000'

user_document || card_owner_document || fallback_document
contribution.user.cpf.try(:gsub, /[-.\/_\s]/, '')
end

def phone_matches
Expand Down Expand Up @@ -137,7 +133,7 @@ def installments_for_json

def address_hash
{
country: contribution.country.try(:name),
country_code: contribution.country.try(:code),
state: contribution.address_state,
city: contribution.address_city,
zipcode: contribution.address_zip_code.try(:gsub, /[-.\/_\s]/, ''),
Expand Down
13 changes: 5 additions & 8 deletions app/models/catarse_pagarme/antifraud_order_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,15 @@ def order_attributes

def customer_attributes
customer = self.attributes.dig(:customer)
tax_id = customer[:document_number].present? ? { tax_id: customer[:document_number] } : {}

{
id: customer[:id].to_s,
tax_id: customer[:document_number],
name: customer[:name],
email: customer[:email],
phone1: customer[:phone].to_h.values.join,
created_at: self.attributes.dig(:antifraud_metadata, :register, :registered_at)
}
}.merge(tax_id)
end

def payment_attributes
Expand All @@ -99,7 +100,8 @@ def billing_address_attributes
city: billing_data.dig(:address, :city),
state: billing_data.dig(:address, :state),
zip: billing_data.dig(:address, :zipcode),
}.merge(card_country_code)
country: billing_data.dig(:address, :country_code),
}
end

def shipping_address_attributes
Expand Down Expand Up @@ -139,10 +141,5 @@ def card_expiration_date
expiration_date = self.transaction.card.expiration_date
"#{expiration_date[0..1]}20#{expiration_date[2..3]}"
end

def card_country_code
country = ::ISO3166::Country.find_country_by_name(self.transaction.card.country)
country.present? ? { country: country.try(:alpha2) } : {}
end
end
end
2 changes: 1 addition & 1 deletion lib/catarse_pagarme/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module CatarsePagarme
VERSION = "2.14.12"
VERSION = "2.14.13"
end
9 changes: 5 additions & 4 deletions spec/models/catarse_pagarme/antifraud_order_wrapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,15 @@
street: 'R. A',
city: 'New City',
state: 'NC',
zipcode: '1245'
zipcode: '1245',
country_code: 'BR'
}
}
}
}
end

let(:transaction) { double(card: double(country: 'BRAZIL', holder_name: 'holder name')) }
let(:transaction) { double(card: double(holder_name: 'holder name')) }

before do
subject.attributes = attributes
Expand All @@ -267,7 +268,7 @@
expect(billing_address_attributes[:city]).to eq 'New City'
expect(billing_address_attributes[:state]).to eq 'NC'
expect(billing_address_attributes[:zip]).to eq '1245'
expect(billing_address_attributes[:country]).to eq 'BR'
expect(billing_address_attributes[:country_code]).to eq 'BR'
end
end

Expand All @@ -290,7 +291,7 @@
}
end

let(:transaction) { double(card: double(country: 'BRAZIL')) }
let(:transaction) { double(card: double) }

before do
subject.attributes = attributes
Expand Down

0 comments on commit e1722d3

Please sign in to comment.