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

Unable to JSON Serialize Result #102

Closed
selected-pixel-jameson opened this issue Jul 14, 2018 · 11 comments
Closed

Unable to JSON Serialize Result #102

selected-pixel-jameson opened this issue Jul 14, 2018 · 11 comments

Comments

@selected-pixel-jameson
Copy link

General information

  • SDK/Library version: 3.46.0
  • Language, language version, and OS: Python 2.7.0 | MacOS

Issue description

Hello, I'm having trouble JSON serializing the result object that is returned when calling gateway.subscription.create. I've tried using json.dumps and it just tells me the object cannot be serialized. I'm sure this is something I'm doing wrong, but I don't really know where else to go.

Thank you.

@yagrawl
Copy link

yagrawl commented Jul 16, 2018

Hi, thanks for reaching out. Can you share the code snippet and the logs so we have a better idea of what solution would work?

@selected-pixel-jameson
Copy link
Author

selected-pixel-jameson commented Jul 16, 2018

The log is simply an exception that states the following result can't be parsed to JSON.

result = self.gateway.subscription.create({
        "payment_method_nonce": nonce,
        "plan_id": plan_id
})
print json.dumps(result)

I'm working around this by taking the response and breaking it into a simplified custom response. I also can't find anywhere in the BrainTree docs where it states what should be returned to the Drop-In-UI.

@yagrawl
Copy link

yagrawl commented Jul 16, 2018

The returned object in result after calling gateway.subscription.create is not JSON serializable. You could use a toString method or __repr__ if that serves your needs.

I also wanted to confirm if you see an object description when you print json.dumps(result) because from the snippet you sent, it seems like you are passing a nonce for the payment_method_token. Since you need a vaulted payment method before associating it with a subscription usually the simplest method is to pass a payment_method_token. Read this for more info.

Please let me know if you have any more comments or problems. Thanks!

@selected-pixel-jameson
Copy link
Author

selected-pixel-jameson commented Jul 16, 2018 via email

@yagrawl
Copy link

yagrawl commented Jul 16, 2018

Comment if the issue persists.

@yagrawl yagrawl closed this as completed Jul 16, 2018
@TheAshwanik
Copy link

Comment if the issue persists.

Hey.. Its 2 years since your comment. But I still see this as an issue. Please let me know if someone was able to convert this String representation to a well formed Json ( Not sure why its not JSON in the first place.. it would have been best).

I get this right now.
<Transaction {id: '56bmgpz0', graphql_id: 'dHJhbnNhY3Rpb25fNTZibWdwejA', additional_processor_response: None, amount: Decimal('6.50'), authorization_adjustments: [], authorization_expires_at: datetime.datetime(2020, 8, 6, 18, 8, 9), avs_error_response_code: None, avs_postal_code_response_code: 'I', avs_street_address_response_code: 'I', channel: None, created_at: datetime.datetime(2020, 7, 30, 18, 8, 9), credit_card_details: <CreditCard {token: '9f544yw', bin: '411111', last_4: '1111', card_type: 'Visa', expiration_month: '11', expiration_year: '2020', customer_location: 'US', cardholder_name: None, image_url: 'https://assets.braintreegateway.com/payment_method_logo/visa.png?environment=sandbox', prepaid: 'Unknown', healthcare: 'Unknown', debit: 'Unknown', durbin_regulated: 'Unknown', commercial: 'Unknown', payroll: 'Unknown', issuing_bank: 'Unknown', country_of_issuance: 'Unknown', product_id: 'Unknown', global_id: 'cGF5bWVudG1ldGhvZF9jY185ZjU0NHl3', graphql_id: 'cGF5bWVudG1ldGhvZF9jY185ZjU0NHl3', account_type: None, unique_number_identifier: '0b12b15dc996e5cde0ec22e9c07b494d', venmo_sdk: False} at 140219677190416>, currency_iso_code: 'EUR', cvv_response_code: 'I', discount_amount: None, disputes: [], escrow_status: None, gateway_rejection_reason: None, master_merchant_account_id: None, merchant_account_id: 'mycompany', network_response_code: None, network_response_text: None, network_transaction_id: '020200730180809', order_id: None, payment_instrument_type: 'credit_card', plan_id: None, processor_authorization_code: 'KM72LB', processor_response_code: '1000', processor_response_text: 'Approved', processor_settlement_response_code: '', processor_settlement_response_text: '', purchase_order_number: None, recurring: False, refund_id: None, refunded_transaction_id: None, retrieval_reference_number: '1234567', service_fee_amount: None, settlement_batch_id: None, shipping_amount: None, ships_from_postal_code: None, status: 'submitted_for_settlement', status_history: [<StatusEvent {timestamp: datetime.datetime(2020, 7, 30, 18, 8, 9), status: 'authorized', amount: Decimal('6.50'), user: 'AK-SandBox', transaction_source: 'api'} at 140219677190672>, <StatusEvent {timestamp: datetime.datetime(2020, 7, 30, 18, 8, 9), status: 'submitted_for_settlement', amount: Decimal('6.50'), user: 'AK-SandBox', transaction_source: 'api'} at 140219677190800>], sub_merchant_account_id: None, subscription_id: None, tax_amount: None, tax_exempt: False, type: 'sale', updated_at: datetime.datetime(2020, 7, 30, 18, 8, 9), voice_referral_number: None} at 140219688160656>

@demerino
Copy link
Member

@TheAshwanik You're right that these aren't JSON serializable strings. We can look into adding this functionality in a future major version update.

@njlupu
Copy link

njlupu commented Nov 6, 2020

hey @TheAshwanik @demerino was there any solution to this? cheers

@crookedneighbor
Copy link
Contributor

No additional work on adding this was done.

This is not a high priority for us at this time (too many other things to work on right now), but we'd love to review a pull request if anyone feels passionately about adding this functionality.

@aryaniyaps
Copy link

aryaniyaps commented Apr 29, 2021

@crookedneighbor
what about now guys?
At the top of my head, I think that we must make the classes inherit from a dict (this would be sort of a breaking change)

class ErrorResults(dict):
    def __init__(self, fname):
        dict.__init__(self, fname=fname)

# directly dump the object
errs = ErrorResults()
json.dumps(errs)

maybe I can make a PR

@pbnsilva
Copy link

pbnsilva commented Apr 5, 2022

Any updates on this? error handling is a bit of a mess in the python api

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

8 participants