The customer object is an important component of the Braintree gateway. Use customers to store and organize payment methods. A single customer can have multiple payment methods.

This guide will walk you through the basics. See Customer Request and Customer Response references for complete details.

Create

Use Customer.create() to add new customers.

You can create just a customer without an associated payment method, and the operation will be successful if all customer validations pass:

Python
Copy
Copied
result = gateway.customer.create({
    "first_name": "Jen",
    "last_name": "Smith",
    "company": "Braintree",
    "email": "jen@example.com",
    "phone": "312.555.1234",
    "fax": "614.555.5678",
    "website": "www.example.com"
})

result.is_success
# True

result.customer.id
# e.g. 594019
This code snippet now uses gateway instance methods instead of class-level methods. Learn more.

Create with payment method

You can also create a customer with an associated payment method:

Python
Copy
Copied
result = gateway.customer.create({
    "first_name": "Charity",
    "last_name": "Smith",
    "payment_method_nonce": nonce_from_the_client
})

result.is_success
# True

result.customer.id
# e.g 160923

result.customer.payment_methods[0].token
# e.g f28w
This code snippet now uses gateway instance methods instead of class-level methods. Learn more.

Success depends on both customer validations and payment method validations, and whether the payment method is verified (if card verification is enabled).

note

Braintree strongly recommends verifying all cards before they are stored in your Vault by enabling card verification for your entire account in the Control Panel. If you choose to manually verify cards, set verify_card to True.

See the reference and more examples of creating a customer.

Update

Use Customer.update() to update an existing customer:

Python
Copy
Copied
result = gateway.customer.update("the_customer_id", {
    "first_name": "New First Name",
    "last_name": "New Last Name"
})
This code snippet now uses gateway instance methods instead of class-level methods. Learn more.

If the customer can't be found, it will throw a NotFoundError exception.

See the reference and more examples of updating a customer.

Find

Use Customer.find() to find a customer by ID:

Python
Copy
Copied
customer = gateway.customer.find("the_customer_id")
This code snippet now uses gateway instance methods instead of class-level methods. Learn more.

If the customer can't be found, it will throw a NotFoundError exception.

The return value of this call will be a Customer response object.

Delete

Use Customer.delete() to delete a customer and its payment methods using the customer's ID:

Python
Copy
Copied
result = gateway.customer.delete("the_customer_id")

result.is_success
# True
This code snippet now uses gateway instance methods instead of class-level methods. Learn more.

If the customer can't be found, it will throw a NotFoundError exception.

Still have questions?

If you can’t find an answer, contact us