I need to build an api method which should receive customer's payment information (credit card info) along with product details and place an order with it further processing.

Right now I faced that braintree payment facade requires credit card tokenization which is made via javascript during checkout process, as well as authorize.net method is connecting to transact.dll endpoint.

Is this actually possible, to trigger order processing only in backend ?

Can I refer somewhere in existing magento2 code to see how it is made, maybe in some adminhtml area ?

The code i use to create an order:

    // prepare adresses, products in quote, shipping method - skipped
    // Set Sales Order Payment

            'method'      => 'authorizenet_directpost',
            'card_type'   => $payment->cardType,
            'cvv'         => $payment->cvv,
            'expire_year' => $payment->expireYear

    $customer = $this->customerRepository->get($contact->email);
   // prepare customer

    // Collect Totals & Save Quote
    $order = $this->quoteManagement->submit($quote);

1 Answer 1


You first need to find the customer saved cards list (vault), then you can use one of the cards in the order placement as you described:

use Magento\Vault\Api\PaymentTokenManagementInterface;
use Magento\Customer\Model\Session;


// Get the customer id (currently logged in user)
$customerId = $this->session->getCustomer()->getId();

// Card list
$cardList = $this->paymentTokenManagement->getListByCustomerId($customerId);

You can use the following methods to get the details of a card. Example on the first card object of the list above:


Note: The getListByCustomerId($customerId) function will give you all stored cards for a single customer, whether the cards are active or not. If you only want the list of active cards, use getVisibleAvailableTokens($customerId) instead.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.