How to store paypal transaction email and id in my database

Here I am integrating braintee paypal payment in my django app. The payment works fine. But the problem I got is while saving the paypal transaction email and payer Id in my database.

While printing the result I can get payment_instrument_type: 'paypal_account', But I am not being able to get this account email and payer id in my result.

Is there anyone who can help me on this ?

def braintree_payment(customer_kwargs, amount, nonce):
    gateway = braintree_config()

    customer_create = gateway.customer.create(customer_kwargs)

    result = gateway.transaction.sale({
        "amount": amount,
        "payment_method_nonce": nonce,
        "options": {
            "submit_for_settlement": True,

        }
    })

    return result 

view

  nonce_from_the_client = request.POST['payment_method_nonce']
   customer_kwargs = {
         "first_name": payment_donar.first_name,
         "last_name": payment_donar.last_name,
          "email": payment_donar.email,
        }
    amount = payment_donar.donation_amount
    result = braintree_payment(
        customer_kwargs=customer_kwargs,
        amount=amount,
        nonce=nonce_from_the_client
    )
    if result.is_success:
        data = {
            'transaction_id': result.transaction.id,
            'currency_iso_code': result.transaction.currency_iso_code,
            'last_4': result.transaction.credit_card_details.last_4,
            'card_type': result.transaction.credit_card_details.card_type,
            'expiration_month': result.transaction.credit_card_details.expiration_month,
            'expiration_year': result.transaction.credit_card_details.expiration_year,
            'customer_location': result.transaction.credit_card_details.customer_location,
            'cardholder_name': result.transaction.credit_card_details.cardholder_name,
            'merchant_account_id': result.transaction.merchant_account_id,
            'network_transaction_id': result.transaction.network_transaction_id,
        }

        Model.objects.create(**data)           
        return redirect('home')

this is the transaction result

<SuccessfulResult {transaction: <Transaction {id: 'n0gxdkcf', graphql_id: 'dHJhbnNhY3Rpb25fbjBneGRrY2Y', additional_processor_response: None, amount: Decimal('10.00'), authorization_adjustments: [], authorization_expires_at: datetime.datetime(2021, 2, 23, 13, 59, 3), avs_error_response_code: None, avs_postal_code_response_code: 'A', avs_street_address_response_code: 'A', channel: None, created_at: datetime.datetime(2021, 1, 24, 13, 59), credit_card_details: <CreditCard {token: None, bin: None, last_4: None, card_type: None, expiration_month: '', expiration_year
: '', customer_location: None, cardholder_name: None, image_url: 'https://assets.braintreegateway.com/payment_method_logo/unknown.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
: None, graphql_id: None, account_type: None, unique_number_identifier: None, venmo_sdk: False} at 173237488>, currency_iso_code: 'USD', cvv_response_code: 'A', discount_amount: None, dispu
tes: [], escrow_status: None, gateway_rejection_reason: None, master_merchant_account_id: None, merchant_account_id: 'mymerchant', network_response_code: None, network_response_te
xt: None, network_transaction_id: None, order_id: None, payment_instrument_type: 'paypal_account', plan_id: None, processor_authorization_code: None, processor_response_code: '1000', proces
sor_response_text: 'Approved', processor_settlement_response_code: '4000', processor_settlement_response_text: 'Confirmed', purchase_order_number: None, recurring: False, refund_id: None, refunded_transaction_id: None, service_fee_amount: None, settlement_batch_id: '2021-01-24_infodeveloperspvtltd_epre1zym', shipping_amount: None, ships_from_postal_code: None, status: 'settling', status_history: [<StatusEvent {timestamp: datetime.datetime(2021, 1, 24, 13, 59, 4), status: 'authorized', amount: Decimal('10.00'), user: 'testuser', transaction_source: 'api'} a
t 13019376>, <StatusEvent {timestamp: datetime.datetime(2021, 1, 24, 13, 59, 4), status: 'submitted_for_settlement', amount: Decimal('10.00'), user: 'testuser', transaction_source: 'ap
i'} at 13019504>, <StatusEvent {timestamp: datetime.datetime(2021, 1, 24, 13, 59, 4), status: 'settling', amount: Decimal('10.00'), user: 'testuser', transaction_source: 'api'} at 1301
8896>], sub_merchant_account_id: None, subscription_id: None, tax_amount: None, tax_exempt: False, type: 'sale', updated_at: datetime.datetime(2021, 1, 24, 13, 59, 4), voice_referral_number
: None} at 165498064>} at 164917200>

Source: Python Questions

LEAVE A COMMENT