Created
January 10, 2019 21:38
-
-
Save biancalpadilla/640fa8cf9be767f2baadeb1500c9ccdb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def address_verification(order) | |
shipping = Bigcommerce.find_shipping(order.id).first | |
address = verify_address(shipping) | |
unless address['deliverability'] == 'deliverable' || | |
address['deliverability'] == 'deliverable_unnecessary_unit' | |
notes = order.staff_notes + "\n" + footnotes(address) | |
Bigcommerce.update_staff_notes(order.id, notes) | |
Bigcommerce.update_order_status_id(order.id, ENV['manual_verification']) | |
end | |
end | |
def verify_address(shipping) | |
lob = Lob::Client.new(api_key: ENV["lob_api_key"]) | |
lob.us_verifications.verify( | |
primary_line: shipping.street_1, | |
secondary_line: shipping.street_2, | |
city: shipping.city, | |
state: shipping.state, | |
zip_code: shipping.zip | |
) | |
end | |
def footnotes(address) | |
footnotes = | |
{ | |
AA: 'Some parts of the address (such as the street and ZIP code) are valid.', | |
A1: 'The address is invalid based on given inputs.', | |
BB: 'The address is deliverable.', | |
CC: 'The address is deliverable by removing the provided secondary unit designator.', | |
N1: 'The address is deliverable but is missing a secondary information (apartment, unit, etc).', | |
F1: 'The address is a deliverable military address.', | |
G1: 'The address is a deliverable General Delivery address. General Delivery is a USPS service which allows individuals without permanent addresses to receive mail.', | |
U1: 'The address is a deliverable unique address. A unique ZIP code is assigned to a single organization (such as a government agency) that receives a large volume of mail.', | |
M1: 'The primary number is missing.', | |
M3: 'The primary number is invalid.', | |
P1: 'PO Box, Rural Route, or Highway Contract box number is missing.', | |
P3: 'PO Box, Rural Route, or Highway Contract box number is invalid.', | |
R1: 'The address matched to a CMRA and private mailbox information is present.', | |
RR: 'The address matched to a CMRA and private mailbox information is not present.' | |
} | |
fn = address["deliverability"].to_s.upcase + '. Address Type: ' + address["components"]["address_type"].to_s.capitalize + '. Record Type: ' + address["components"]["record_type"].to_s.capitalize + '. Vacant: ' + address["deliverability_analysis"]["dpv_vacant"].to_s.capitalize + '. Analysis: ' | |
address["deliverability_analysis"]["dpv_footnotes"].each do |footnote| | |
fn += footnotes[footnote.to_sym].to_s + ' ' | |
end | |
fn | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment