Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on disbursement webhook object with to_json #140

Closed
getupstream opened this issue Apr 20, 2017 · 10 comments
Closed

Error on disbursement webhook object with to_json #140

getupstream opened this issue Apr 20, 2017 · 10 comments

Comments

@getupstream
Copy link

getupstream commented Apr 20, 2017

General information

  • SDK/Library version:
  • Environment: test
  • Language, language version, and OS: ruby, 2.3.4, Mac OSX

Issue description

I get an error when I attempt to transform a disbursement webhook object into json. This works for other types like disputes.

sample_notification = Braintree::WebhookTesting.sample_notification(
  Braintree::WebhookNotification::Kind::Disbursement,
  SecureRandom.uuid
)

webhook_notification = Braintree::WebhookNotification.parse(
  sample_notification[:bt_signature],
  sample_notification[:bt_payload]
)

webhook_notification.disbursement.to_json
IOError: not opened for reading
	from /Users/username/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-5.0.2/lib/active_support/core_ext/object/json.rb:130:in `each'
	from /Users/username/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-5.0.2/lib/active_support/core_ext/object/json.rb:130:in `to_a'
	from /Users/username/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-5.0.2/lib/active_support/core_ext/object/json.rb:130:in `as_json'
	from /Users/username/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-5.0.2/lib/active_support/core_ext/object/json.rb:161:in `block in as_json'
	from /Users/username/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-5.0.2/lib/active_support/core_ext/object/json.rb:161:in `each'
	from /Users/username/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-5.0.2/lib/active_support/core_ext/object/json.rb:161:in `map'
	from /Users/username/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-5.0.2/lib/active_support/core_ext/object/json.rb:161:in `as_json'
	from /Users/username/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-5.0.2/lib/active_support/core_ext/object/json.rb:52:in `as_json'
	from /Users/username/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-5.0.2/lib/active_support/core_ext/object/json.rb:161:in `block in as_json'
	from /Users/username/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-5.0.2/lib/active_support/core_ext/object/json.rb:161:in `each'
	from /Users/username/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-5.0.2/lib/active_support/core_ext/object/json.rb:161:in `map'
	from /Users/username/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-5.0.2/lib/active_support/core_ext/object/json.rb:161:in `as_json'
	from /Users/username/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-5.0.2/lib/active_support/core_ext/object/json.rb:52:in `as_json'
	from /Users/username/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-5.0.2/lib/active_support/core_ext/object/json.rb:161:in `block in as_json'
	from /Users/username/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-5.0.2/lib/active_support/core_ext/object/json.rb:161:in `each'
	from /Users/username/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-5.0.2/lib/active_support/core_ext/object/json.rb:161:in `map'
... 7 levels...
	from /Users/username/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-5.0.2/lib/active_support/core_ext/object/json.rb:161:in `block in as_json'
	from /Users/username/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-5.0.2/lib/active_support/core_ext/object/json.rb:161:in `each'
	from /Users/username/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-5.0.2/lib/active_support/core_ext/object/json.rb:161:in `map'
	from /Users/username/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-5.0.2/lib/active_support/core_ext/object/json.rb:161:in `as_json'
	from /Users/username/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-5.0.2/lib/active_support/core_ext/object/json.rb:52:in `as_json'
	from /Users/username/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-5.0.2/lib/active_support/json/encoding.rb:33:in `encode'
	from /Users/username/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-5.0.2/lib/active_support/json/encoding.rb:20:in `encode'
	from /Users/username/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-5.0.2/lib/active_support/core_ext/object/json.rb:37:in `to_json'
	from (irb):11
	from /Users/username/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-5.0.2/lib/rails/commands/console.rb:65:in `start'
	from /Users/username/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-5.0.2/lib/rails/commands/console_helper.rb:9:in `start'
	from /Users/username/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:78:in `console'
	from /Users/username/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
	from /Users/username/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-5.0.2/lib/rails/commands.rb:18:in `<top (required)>'
	from script/rails:6:in `require'
	from script/rails:6:in `<main>'```
@getupstream
Copy link
Author

Happy to provide more context if need.

As to why this is important. This is stopping us from easily passing the disbursement webhook to a backend worker.

@khpatel4991
Copy link

What If I need to persist the response object for query use as json field in my psql table?

@sdcoffey
Copy link

sdcoffey commented May 1, 2017

Hey @getupstream and @khpatel4991,

For either of these scenarios, I would recommend passing the raw payload and signature to either your backend worker or to postgres, and parsing them at the time that you need them. While I can't say for sure why to_json doesn't throw an exception for a dispute object, to_json is not a method or functionality that we support on any of our response objects. Let me know if this is a viable solution for you both.

@sdcoffey
Copy link

sdcoffey commented May 8, 2017

Hey @getupstream and @khpatel4991,

I'm closing this issue due to inactivity. Please comment here if you'd like to continue this discussion and I'll reopen the issue.

@sdcoffey sdcoffey closed this as completed May 8, 2017
@michelson
Copy link

We have got this error today on transactions .to_json in rails 4.1.14

@michelson
Copy link

please reopen this

@michelson
Copy link

I've "handled" this by using .instance_values instead of .as_json , but the bug still there

@michelson
Copy link

this bug is still happening 👎

@crookedneighbor
Copy link

@michelson Does this suggestion not work for you? #140 (comment)

@crookedneighbor
Copy link

Going to close this as I haven't received a response from @michelson about storing the raw payload instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants