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 store on your servers with reduced PCI compliance burden and later use to create transactions.
Create
Use Payment Method: Create to create a payment method for an existing customer using a payment method single-object token received from the client :
- Callback
- Promise
gateway.paymentMethod.create({
customerId: "12345",
paymentMethodNonce: nonceFromTheClient
}, (err, result) => { });
Alternatively, you can create a new customer with a payment method using Customer: Create with the paymentMethodNonce parameter.
After the payment method is successfully created, you can use Transaction: Sale with the paymentMethodToken parameter to create a transaction.
Update
Use Payment Method: Update to update an existing payment method.
Make default
Use the makeDefault option to set a payment method as the default for its customer:
- Callback
- Promise
gateway.paymentMethod.update("theToken", {
options: {
makeDefault: true
}
}, (err, result) => {
});
Billing address
Update the billing address:
- Callback
- Promise
gateway.paymentMethod.update("theToken", {
billingAddress: {
streetAddress: "100 Maple Lane",
options: {
updateExisting: true
}
}
}, (err, result) => {
});
You can also omit the updateExisting option to create a new billing address for the 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 Payment Method: Find to find a payment method:
- Callback
- Promise
gateway.paymentMethod.find("token", (err, paymentMethod) => { });
The return value of the Payment Method: Find call will be a paymentMethod response object.
Delete
Use Payment Method: Delete to delete a payment method:
- Callback
- Promise
gateway.paymentMethod.delete("theToken", (err) => { });