Skip to content

Print transactions in JSON format #137

Description

@mailtobash

We are writing a connector to write JSON files of transactions that we search in the past day.
Version 3.57.1

import braintree
from braintree import Environment, BraintreeGateway, Configuration, TransactionSearch

gateway = braintree.BraintreeGateway(braintree.Configuration(environment=braintree.Environment.Sandbox,merchant_id="XXXXXX",public_key="XXXXX",private_key="XXXXXX"))
results=gateway.transaction.search(TransactionSearch.created_at.between("2021-05-05T09:03:00.000Z", "2021-05-05T10:03:00Z"))

for i in results.items:
    print(i)

Returns :

<Transaction {id: '9r6g66mr', additional_processor_response: None, amount: Decimal('1.00'), authorization_adjustments: [], authorization_expires_at: datetime.datetime(2021, 5, 12, 9, 14, 34), avs_error_response_code: None, avs_postal_code_response_code: 'M', avs_street_address_response_code: 'I', channel: None, created_at: datetime.datetime(2021, 5, 5, 9, 14, 33), credit_card_details: <CreditCard {token: '3qddmkg', bin: '401288', last_4: '1881', card_type: 'Visa', expiration_month: '12', expiration_year: '2022', customer_location: 'US', cardholder_name: None, image_url: 'https://assets.braintreegateway.com/payment_method_logo/visa.png?environment=sandbox', prepaid: 'No', healthcare: 'Unknown', debit: 'Unknown', durbin_regulated: 'Unknown', commercial: 'Unknown', payroll: 'Unknown', issuing_bank: 'Unknown', country_of_issuance: 'Unknown', product_id: 'Unknown', global_id: 'cGF5bWVudG1ldGhvZF9jY18zcWRkbWtn', account_type: None, unique_number_identifier: 'f2425aa6f4215f1be772e5144f480c70', venmo_sdk: False} at 4482418672>, currency_iso_code: 'AUD', cvv_response_code: 'M', discount_amount: None, disputes: [], escrow_status: None, gateway_rejection_reason: None, master_merchant_account_id: None, merchant_account_id: 'belongmobileverificationAUD', network_response_code: 'XX', network_response_text: 'sample network response text', network_transaction_id: '020210505091434', order_id: None, payment_instrument_type: 'credit_card', plan_id: None, processor_authorization_code: 'W95P6L', 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, service_fee_amount: None, settlement_batch_id: None, shipping_amount: None, ships_from_postal_code: None, status: 'authorization_expired', status_history: [<StatusEvent {timestamp: datetime.datetime(2021, 5, 5, 9, 14, 34), status: 'authorized', amount: Decimal('1.00'), user: 'System-User-Sandbox', transaction_source: 'api'} at 4482418896>, <StatusEvent {timestamp: datetime.datetime(2021, 5, 12, 9, 47, 31), status: 'authorization_expired', amount: Decimal('1.00'), transaction_source: 'recurring'} at 4482418952>], sub_merchant_account_id: None, subscription_id: None, tax_amount: None, tax_exempt: False, type: 'sale', updated_at: datetime.datetime(2021, 5, 12, 9, 47, 31), voice_referral_number: None} at 4482418560>

Is there a way to format it as JSON? I tried emulating the __repr__ method but it is still printing bjects like StatuEvent as
<StatusEvent ..... at 1214132321>

Here is what I tried:

detail_list = i._setattrs
details = ", ".join("\"%s\": %r" % (attr, getattr(i, attr)) for attr in detail_list if (hasattr(i, attr) and getattr(i, attr) is not None))
json_data="{%s}"%(details)

Thank you

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions