A payment method represents transactable payment information such as credit card details or a customer's authorization to charge a PayPal or Venmo account. Payment methods belong to a customer, are securely stored in the Braintree Vault, and have a payment_method_token attribute that you can store on your servers (with reduced PCI compliance burden) and later use to create transactions.

Create

Use PaymentMethod.create() to create a payment method for an existing customer using a payment method nonce received from the client:

Python
Click to copy
Copied
result = braintree.PaymentMethod.create({
    "customer_id": "12345",
    "payment_method_nonce": nonce_from_the_client
})

Alternatively, you can create a new customer with a payment method using Customer.create() with the payment_method_nonce parameter.

Once successfully created, you can use Transaction.sale() with the payment_method_token parameter to create a transaction.

Update

Use PaymentMethod.update() to update an existing payment method.

Make default

Use the make_default option to set a payment method as the default for its customer:

Python
Click to copy
Copied
result = braintree.PaymentMethod.update("the_token", {
    "options": {
      "make_default": True
    }
})

Billing address

Update the billing address:

Python
Click to copy
Copied
result = braintree.PaymentMethod.update("the_token", {
    "billing_address": {
        "street_address": "100 Maple Lane",
        "options": {
            "update_existing": True
        }
    }
})

If the payment method cannot be found, it will throw a NotFoundError exception.

You can also omit the update_existing option to create a new billing address for just this payment method.

See the reference and more examples of updating a payment method. If you want to update both payment method and customer information together, use Customer.update().

Find

Use PaymentMethod.find() to find a payment method:

Python
Click to copy
Copied
payment_method = braintree.PaymentMethod.find("token")

If the payment method cannot be found, it will throw a NotFoundError exception.

The return value of the PaymentMethod.find() call will be a PaymentMethod response object.

Delete

Use PaymentMethod.delete() to delete a payment method:

Python
Click to copy
Copied
result = braintree.PaymentMethod.delete("the_token")

result.is_success
# True

If the payment method cannot be found, it will throw a NotFoundError exception.

See also

Still have questions?

If you can’t find an answer, contact our Support team.