Payment Methodanchor

There are multiple types of payment methods. For the attributes of a specific type of payment method response, see one of the following response objects:

Payment method objects included in other responses (such as Customer) may be any of these types. For example:

  1. Java
Customer customer = gateway.customer().find("the_customer_id");
customer.getPaymentMethods(); // array of PaymentMethod instances
Server-side response object returned directly or within a successful result object from the following requests:

An alphanumeric value that references a specific payment method stored in your Vault.



To determine if a payment method is the default for its customer:

  1. Java

Determine payment method typeanchor

To determine the type of payment method (e.g. credit card, PayPal), you need to inspect the class of the payment method object.

  1. Java
PaymentMethod paymentMethod = gateway.paymentMethod().find("credit-card-token");
// com.braintree.CreditCard

PaymentMethod paymentMethod = gateway.paymentMethod().find("paypal-account-token");
// com.braintree.PayPalAccount

PaymentMethod paymentMethod = gateway.paymentMethod().find("apple-pay-token");
// com.braintree.ApplePayCard

PaymentMethod paymentMethod = gateway.paymentMethod().find("android-pay-token");
// com.braintree.AndroidPayCard

Cast payment method to its concrete classanchor

Once you've extracted the payment method from the result object, you need to cast the PaymentMethod object to its concrete class in order to access its attributes.

  1. Java
Result<? extends PaymentMethod> result = gateway.paymentMethod().update(paymentMethodRequest);
PaymentMethod paymentMethod = result.getTarget();

paymentMethod.getClass(); // com.braintree.CreditCard
CreditCard card = (CreditCard) paymentMethod;
card.getLast4(); // 1234