DGT
DGT

Reputation: 401

How to read token from Braintree_PaymentMethod::create

What is the correct way of reading the return object from the Braintree_PaymentMethod::create call ? I would like to access the auto-generated token.

I am doing this currently: $result = $output->paymentMethod->_attributes['token']

I couldn't find it in the Braintree documentation.

Upvotes: 0

Views: 248

Answers (1)

Jessica d
Jessica d

Reputation: 743

Below is a snippet demonstrating how to retrieve the token from a successful payment method creation.

$result = Braintree_PaymentMethod::create(array(
    'customerId' => 'existing-customer',
    'paymentMethodNonce' => 'valid-nonce'
));

$token = $result->paymentMethod->token;

More information about result objects

Upvotes: 3

Related Questions