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. CS
Customer customer = gateway.Customer.Find("the_customer_id");
customer.PaymentMethods; // array of PaymentMethod instances
Server-side response object returned directly or within a successful result object from the following requests:
Attributes
Tokenstring

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

Examplesanchor

Defaultanchor

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

  1. CS
paymentMethod.IsDefault;

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. CS
PaymentMethod paymentMethod = gateway.PaymentMethod.Find("credit-card-token");
paymentMethod.GetType();
// Braintree.CreditCard

PaymentMethod paymentMethod = gateway.PaymentMethod.Find("paypal-account-token");
paymentMethod.GetType();
// Braintree.PayPalAccount

PaymentMethod paymentMethod = gateway.PaymentMethod.Find("apple-pay-token");
paymentMethod.GetType();
// Braintree.ApplePayCard

PaymentMethod paymentMethod = gateway.PaymentMethod.Find("android-pay-token");
paymentMethod.GetType();
// 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. CS
Result<PaymentMethod> result = gateway.PaymentMethod.Update(paymentMethodRequest);
PaymentMethod paymentMethod = result.Target;

paymentMethod.GetType(); // Braintree.CreditCard
CreditCard creditCard = (CreditCard) paymentMethod;
creditCard.LastFour; // 1234