Skip to content

Commit

Permalink
Paypal Express gateway: Fix missing address
Browse files Browse the repository at this point in the history
Calling PaypalExpressResponse#address when the response didn't contain
any address information was causing a dereference error:

  NoMethodError: undefined method `[]' for nil:NilClass

Closes activemerchant#628.
  • Loading branch information
Pierre-Alexandre Meyer authored and chengz committed Dec 7, 2013
1 parent 21b5eb7 commit 336b095
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* DataCash: Update test Mastercard number [jamesshipton]
* DataCash: Update test response fixtures [jamesshipton]
* Pin: Add Pin.js card token support [nagash]
* PayPal Express gateway: Fix error when no address information is in response [pierre]

== Version 1.31.1 (February 25, 2013)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,36 @@ def email
def info
(@params['PayerInfo']||{})
end


def details
(@params['PaymentDetails']||{})
end

def name
payer = (info['PayerName']||{})
[payer['FirstName'], payer['MiddleName'], payer['LastName']].compact.join(' ')
end

def token
@params['Token']
end

def payer_id
info['PayerID']
end

def payer_country
info['PayerCountry']
end

# PayPal returns a contact telephone number only if your Merchant account profile settings require that the buyer enter one.

# PayPal returns a contact telephone number only if your Merchant account
# profile settings require that the buyer enter one.
def contact_phone
@params['ContactPhone']
end

def address
address = (@params['PaymentDetails']||{})['ShipToAddress']
address = (details['ShipToAddress']||{})
{ 'name' => address['Name'],
'company' => info['PayerBusiness'],
'address1' => address['Street1'],
Expand All @@ -44,7 +49,7 @@ def address
'phone' => (contact_phone || address['Phone'])
}
end

def shipping
shipping = (@params['UserSelectedOptions']||{})
{ 'amount' => shipping['ShippingOptionAmount'],
Expand Down
4 changes: 4 additions & 0 deletions test/unit/gateways/paypal_express_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ def test_get_express_details
assert shipping = response.shipping
assert_equal '2.95', shipping['amount']
assert_equal 'default', shipping['name']
end

def test_express_response_missing_address
response = PaypalExpressResponse.new(true, "ok")
assert_nil response.address['address1']
end

def test_authorization
Expand Down

0 comments on commit 336b095

Please sign in to comment.