braintree / braintree_ruby

Braintree Ruby library
https://developer.paypal.com/braintree/docs/start/overview
MIT License
444 stars 195 forks source link

Customer `payment_methods` fails because `@sepa_sepa_direct_debit_accounts` #239

Closed juan-m-medina closed 7 months ago

juan-m-medina commented 7 months ago

General information

Issue description

Attempting to retrieve payment_methods from customer fails. This is because the payment_methods ends up as a nil value due to concatenating a nil @sepa_direct_debit_accounts.

Sample test call for version 4.9.0

 13 #<Braintree::SuccessfulResult customer:#<Braintree::Customer id: "129183505", company: nil, email: nil, fax: nil, first_name: nil, last_name: nil, phone: nil, website: nil, created_at: 2021-07-29 13:54:53 UTC, updated_at: 2021-07-
 14 (byebug) result.customer
 15 #<Braintree::Customer id: "129183505", company: nil, email: nil, fax: nil, first_name: nil, last_name: nil, phone: nil, website: nil, created_at: 2021-07-29 13:54:53 UTC, updated_at: 2021-07-29 13:54:53 UTC, addresses: [], credit_
 16 (byebug) result.customer.payment_methods
 17 [#<Braintree::VenmoAccount:0x0000ffff7b527eb8 @gateway=#<Braintree::Gateway:0x0000ffff7b522e40 @config=#<Braintree::Configuration:0x0000ffff7b522cd8 @custom_user_agent=nil, @endpoint=nil, @http_open_timeout=nil, @http_read_timeout
 18 (byebug)

Same exact call for version for version 4.10.0

#<Braintree::SuccessfulResult customer:#<Braintree::Customer id: "129183505", company: nil, email: nil, fax: nil, first_name: nil, last_name: nil, phone: nil, website: nil, created_at: 2021-07-29 13:54:53 UTC, updated_at: 2021-07-29 13:54:53 UTC, addresses: [], credit_cards: [], paypal_accounts: [], tax_identifiers: []>>
(byebug) result.customer
#<Braintree::Customer id: "129183505", company: nil, email: nil, fax: nil, first_name: nil, last_name: nil, phone: nil, website: nil, created_at: 2021-07-29 13:54:53 UTC, updated_at: 2021-07-29 13:54:53 UTC, addresses: [], credit_cards: [], paypal_accounts: [], tax_identifiers: []>
(byebug) result.customer.payment_methods
*** TypeError Exception: no implicit conversion of nil into Array

Lines related to issue: https://github.com/braintree/braintree_ruby/commit/7a013357548e56c0cbed536dcb61a9141b0d3116#diff-b73d16263b6983fda69a7[…]0a13cd1ec916bf38e7bee67eR93 https://github.com/braintree/braintree_ruby/commit/7a013357548e56c0cbed536dcb61a9141b0d3116#diff-b73d16263b6983fda69a7[…]a13cd1ec916bf38e7bee67eR127

juan-m-medina commented 7 months ago

Turned out to be this issue was due to a stored YAML copy of the prior Braintree::Customer layout of the library that was being read using unsafe_load. This caused the failure to happen late in the call stack - should have failed to load to start with, instead of filling the missing fields with nil.