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:

Ruby
Copy
Copied
result = gateway.payment_method.create(
  :customer_id => "131866",
  :payment_method_nonce => nonce_from_the_client
)
This code snippet now uses gateway instance methods instead of class-level methods. Learn more.

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.

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.

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:

Ruby
Copy
Copied
result = gateway.payment_method.update(
  "the_token",
  :options => {
    :make_default => true
  }
)
This code snippet now uses gateway instance methods instead of class-level methods. Learn more.

Billing address

Update the billing address:

Ruby
Copy
Copied
result = gateway.payment_method.update(
  "the_token",
  :billing_address => {
    :street_address => "1 E Main St",
    :extended_address => "Suite 3",
    :locality => "Chicago",
    :region => "IL",
    :postal_code => "60622",
    :options => {
      :update_existing => true
    }
  }
)
This code snippet now uses gateway instance methods instead of class-level methods. Learn more.

If the payment method can't be found, it will raise a Braintree::NotFoundError.

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:

Ruby
Copy
Copied
payment_method = gateway.payment_method.find("token")
This code snippet now uses gateway instance methods instead of class-level methods. Learn more.

If the payment method can't be found, it will raise a Braintree::NotFoundError.

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

Delete

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

Ruby
Copy
Copied
result = gateway.payment_method.delete("the_token")

result.success?
# true
This code snippet now uses gateway instance methods instead of class-level methods. Learn more.

If the payment method can't be found, it will raise a Braintree::NotFoundError.

See also

Still have questions?

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