Payment Methods

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

gateway.paymentMethod.create({
  customerId: "12345",
  paymentMethodNonce: "nonce-from-the-client"
}, function (err, result) { });
Node.js

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.

Credit card verification

If the payment method is a credit card, you can use options.verifyCard to ensure that Braintree attempts to verify that the credit card number matches a valid, open account.

gateway.paymentMethod.create({
  customerId: "theCustomerId",
  paymentMethodNonce: "nonce-from-the-client",
  options: {
    verifyCard: true,
    verificationMerchantAccountId: "theMerchantAccountId",
  }
}, function (err, result) {
});
Node.js

If you wish to always run verification regardless of the presence of verifyCard, you can turn on card verification in the Control Panel.

Card verification can be performed through the customer API or the credit card API. See also:

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:

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

Billing address

Update the billing address:

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

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:

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

If the payment method cannot be found, the err in the callback will be set to a not found error.

gateway.paymentMethod.find("unknown", function (err, paymentMethod) {
  err.type; // braintree.errorTypes.notFoundError
});
JavaScript

Delete

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

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