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 paymentMethodToken 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:

Node.js
gateway.paymentMethod.create({
  customerId: "12345",
  paymentMethodNonce: nonceFromTheClient
}, function (err, result) { });

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

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

Update

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

Make default

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

Node.js
gateway.paymentMethod.update("theToken", {
  options: {
    makeDefault: true
  }
}, function (err, result) {
});

Billing address

Update the billing address:

Node.js
gateway.paymentMethod.update("theToken", {
  billingAddress: {
    streetAddress: "100 Maple Lane",
    options: {
      updateExisting: true
    }
  }
}, function (err, result) {
});

If the payment method cannot be found, it will return a notFoundError.

You can also omit the updateExisting 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:

Node.js
gateway.paymentMethod.find("token", function (err, paymentMethod) {});

If the payment method cannot be found, it will return a notFoundError.

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

Delete

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

Node.js
gateway.paymentMethod.delete("theToken", function (err) {});

If the payment method cannot be found, it will return a notFoundError.

See also

Still Have Questions?

If you can’t find an answer, give us a call at 877.434.2894 or email our Support team.