How can I get already saved credit/debit card details to use in my custom module from checkout page before place order.

  • you need to check vault functionality in Magento. – Charlie Jul 25 '18 at 14:51
  • what is your exact requirement. – Narendra Vyas Mar 25 '19 at 5:40
  • @Yogita : Have able to achive your requirment. Actually I also want that. I have saved card details in db but now I want to use that card details for order place. – Balwant Singh Jan 31 at 20:01

I was able to load a customer's saved card info from their customerId by using the following:

namespace Company\Mondule\Controller\Adminhtml\Order;

use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Vault\Api\PaymentTokenManagementInterface;

class Connector extends Action
  protected $customerRepositoryFactory;
  protected $paymentTokenManagement;

  public function __construct(
    Context $context,
    PageFactory $pageFactory,
    CustomerRepositoryInterface $customerRepositoryInterface,
    PaymentTokenManagementInterface $paymentTokenManagement,
    array $data = []
  ) {
    $this->customerRepositoryInterface = $customerRepositoryInterface;
    $this->paymentTokenManagement = $paymentTokenManagement;
    parent::__construct($context, $data);

  public function execute()
    $customerId = '1';
    $customer = $this->customerRepositoryInterface->getById($customerId);

    // Get Saved CC
    $cardList = $this->paymentTokenManagement->getListByCustomerId($customerId);

    foreach($cardList as $card) {
      if ($card->getIsActive()) {
        echo $card->getData();

I should note that this is just a snippet from our implementation. Without seeing any of your code, you may need to alter it some depending on your application.

| improve this answer | |

No, you can retrieve only last four credit card digits from an order in Magento flow for security reason.

If you just need to full credit card number. Please purchase an extension from Magento 2 marketplace

use event (checkout_onepage_controller_success_action) and observer to get order details

//***if orderid=1001;***

$order = $this->order->load($orderId);
$expmonth=$order->getPayment()->getCcExpMonth();    //get expirymonth* 
$expyear=$order->getPayment()->getCcExpYear();      //get expiryyear*
$cclast4=$order->getPayment()->getCcLast4();        //get expiry last four digit from card*  
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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