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.
Braintree_PaymentMethod::create() to create a payment method for an existing customer:
$result = Braintree_PaymentMethod::create(array( 'customerId' => '12345', 'paymentMethodNonce' => 'nonce-from-the-client' ));
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.
$result = Braintree_PaymentMethod::create(array( 'customerId' => 'the_customer_id', 'paymentMethodNonce' => 'nonce-from-the-client', 'options' => array( 'verifyCard' => true, 'verificationMerchantAccountId' => 'the_merchant_account_id', ) ));
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:
- Card verification when creating a customer or updating a customer
- Card verification when creating a payment method or updating a payment method
Braintree_PaymentMethod::update() to update an existing payment method.
makeDefault option to set a payment method as the default for its customer:
$updateResult = Braintree_PaymentMethod::update( 'the_token', array( 'options' => array( 'makeDefault' => true ) ) );
Update the billing address:
$result = Braintree_PaymentMethod::update( 'the_token', array( 'billingAddress' => array( 'streetAddress' => '100 Maple Lane', 'options' => array( 'updateExisting' => true ) ) ));
You can also omit the
updateExisting option to create a new billing address for just this payment method.
Braintree_PaymentMethod::find() to find a payment method:
$paymentMethod = Braintree_PaymentMethod::find('token');
If the payment method cannot be found, it will throw a
Braintree_PaymentMethod::delete() to delete a payment method:
Was this page helpful? Give us some feedback.