braintree / braintree_python

Braintree Python library
https://developer.paypal.com/braintree/docs/start/overview
MIT License
241 stars 155 forks source link

Transaction using nonce fails but payment method gets vaulted with option "store_in_vault_on_success" #130

Closed anu-kailash closed 3 years ago

anu-kailash commented 3 years ago

General information

SDK/Library version: 4.4.0
Environment: Sandbox
Language, language version, and OS: Python 3.6 and 3.8 on Debian stretch and Ubuntu

Issue description

For an existing braintree customer with no payment methods, I try to make a transaction sale with a "payment_method_nonce" and the option "store_in_vault_on_success" is True. (https://developers.braintreepayments.com/reference/request/transaction/sale/python#options.store_in_vault_on_success) If I use an amount that causes a processor decline in sandbox, I expect that the transaction will fail and the credit card will not get vaulted. The transaction fails as expected but the credit card gets vaulted. This seems to be an issue with the Braintree API itself.

Here's an integration test that might help demonstrate the issue. Am adding it here since I could not run integration test locally.

    def test_sale_with_vault_customer_does_not_store_credit_card_in_the_vault_on_failure(self):
        customer = Customer.create({
            "first_name": "Pingu",
            "last_name": "Penguin",
        }).customer
        self.assertEqual(len(customer.payment_methods), 0)

        result = Transaction.sale({
            "amount": TransactionAmounts.Decline,
            "customer_id": customer.id,
            "payment_method_nonce": "fake-valid-debit-nonce",
            "options": {
                "store_in_vault_on_success": True
            }
        })
        found_customer = Customer.find(customer.id)
        self.assertEqual(len(found_customer.payment_methods), 0)

        self.assertFalse(result.is_success)
        transaction = result.transaction
        self.assertEqual(None, transaction.credit_card_details.token)
hollabaq86 commented 3 years ago

👋 @anu-kailash please contact Support referencing this issue. They can assist in troubleshooting the behavior you're encountering around vaulting.