Skip to content

Commit

Permalink
Don't break if we're handed the older refund-notification XML format
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisparrish committed Jun 23, 2011
1 parent d5db02e commit e34ed3f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/google4r/checkout/notifications.rb
Expand Up @@ -368,9 +368,11 @@ def self.create_from_element(element, frontend)
amount = (BigDecimal.new(element.elements['total-refund-amount'].text)*100).to_i
refund.total_refund_amount = Money.new(amount, currency)

currency = element.elements['latest-fee-refund-amount'].attributes['currency']
amount = (BigDecimal.new(element.elements['latest-fee-refund-amount'].text)*100).to_i
refund.latest_fee_refund_amount = Money.new(amount, currency)
if element.elements['latest-fee-refund-amount']
currency = element.elements['latest-fee-refund-amount'].attributes['currency']
amount = (BigDecimal.new(element.elements['latest-fee-refund-amount'].text)*100).to_i
refund.latest_fee_refund_amount = Money.new(amount, currency)
end

refund.timestamp = Time.parse(element.elements['timestamp'].text)

Expand Down
25 changes: 25 additions & 0 deletions test/unit/chargeback_amount_notification_test.rb
Expand Up @@ -51,6 +51,18 @@ def setup
<timestamp>2006-03-18T20:25:31</timestamp>
</chargeback-amount-notification>
}

@example2_xml = %q{
<?xml version="1.0" encoding="UTF-8"?>
<chargeback-amount-notification xmlns="http://checkout.google.com/schema/2"
serial-number="bea6bc1b-e1e2-44fe-80ff-0180e33a2614">
<google-order-number>841171949013218</google-order-number>
<latest-chargeback-amount currency="GBP">226.06</latest-chargeback-amount>
<total-chargeback-amount currency="GBP">226.06</total-chargeback-amount>
<timestamp>2006-03-18T20:25:31</timestamp>
</chargeback-amount-notification>
}

end

def test_create_from_element_works_correctly
Expand All @@ -66,4 +78,17 @@ def test_create_from_element_works_correctly
assert_equal(Money.new(221, 'GBP'), notification.latest_fee_refund_amount)
assert_equal(Money.new(1000, 'GBP'), notification.latest_chargeback_fee_amount)
end

def test_create_from_minimal_element_works_correctly
root = REXML::Document.new(@example2_xml).root

notification = ChargebackAmountNotification.create_from_element(root, @frontend)

assert_equal 'bea6bc1b-e1e2-44fe-80ff-0180e33a2614', notification.serial_number
assert_equal '841171949013218', notification.google_order_number
assert_equal Time.parse('2006-03-18T20:25:31'), notification.timestamp
assert_equal(Money.new(22606, 'GBP'), notification.total_chargeback_amount)
assert_equal(Money.new(22606, 'GBP'), notification.latest_chargeback_amount)
end

end

0 comments on commit e34ed3f

Please sign in to comment.