4

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 at 5:40
0

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

<?php
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()
  {
    // CUSTOMER
    $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.

0

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;***

$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*  

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.