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:

C♯
var request = new PaymentMethodRequest
{
    CustomerId = "131866",
    PaymentMethodNonce = NonceFromTheClient
};

Result<PaymentMethod> result = gateway.PaymentMethod.Create(request);

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:

C♯
var updateRequest = new PaymentMethodRequest
{
    Options = new PaymentMethodOptionsRequest
    {
        MakeDefault = true
    }
};

Result<PaymentMethod> result = gateway.PaymentMethod.Update("the_token", updateRequest);

Billing address

Update the billing address:

C♯
var updateRequest = new PaymentMethodRequest
{
    BillingAddress = new PaymentMethodAddressRequest
    {
        StreetAddress = "100 Maple Lane",
        Options = new PaymentMethodAddressOptionsRequest
        {
            UpdateExisting = true
        }
    }
};

Result<PaymentMethod> result = gateway.PaymentMethod.Update("the_token", updateRequest);

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

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:

C♯
PaymentMethod paymentMethod = gateway.PaymentMethod.Find("token");

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

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

Delete

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

C♯
var result = gateway.PaymentMethod.Delete("the_token");

result.IsSuccess();
// true

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

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.