From 8fcce5db35f57525e55e9ae86d5d6002dc5129d8 Mon Sep 17 00:00:00 2001 From: David Ang Date: Fri, 31 Mar 2017 18:30:44 +0800 Subject: [PATCH] use state_name in rare cases that state_id is nil, this will prevent the exception --- lib/hushed/documents/request/hash_converter.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/hushed/documents/request/hash_converter.rb b/lib/hushed/documents/request/hash_converter.rb index ba99b37..ab18a62 100644 --- a/lib/hushed/documents/request/hash_converter.rb +++ b/lib/hushed/documents/request/hash_converter.rb @@ -19,7 +19,7 @@ def ship_to_hash 'Address1' => ship_address.address1, 'Address2' => ship_address.address2, 'City' => ship_address.city, - 'State' => ship_address.state.name, + 'State' => state(ship_address), 'PostalCode' => ship_address.zipcode, 'Country' => ship_address.country.name } @@ -32,7 +32,7 @@ def bill_to_hash 'Address1' => bill_address.address1, 'Address2' => bill_address.address2, 'City' => bill_address.city, - 'State' => bill_address.state.name, + 'State' => state(bill_address), 'PostalCode' => bill_address.zipcode, 'Country' => bill_address.country.name } @@ -42,6 +42,10 @@ def bill_to_hash def normalize_sku(sku) sku.chomp("-SET") end + + def state(address) + address.state ? address.state.name : address.state_name + end end end end