Closed selected-pixel-jameson closed 6 years ago
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?
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.
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!
I will give those suggestions a try. When I try to use payment_method_token the request always fails, however when I use payment_method_nonce it returns succesful.
Jameson W Parker Owner & Software Developer www.selectedpixel.com 920.203.4106
On Jul 16, 2018, at 5:04 PM, Yash Agrawal notifications@github.com wrote:
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!
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.
Comment if the issue persists.
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>
@TheAshwanik You're right that these aren't JSON serializable strings. We can look into adding this functionality in a future major version update.
hey @TheAshwanik @demerino was there any solution to this? cheers
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.
@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
Any updates on this? error handling is a bit of a mess in the python api
General information
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.