4

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

3
  • you need to check vault functionality in Magento.
    – Charlie
    Jul 25 '18 at 14:51
  • what is your exact requirement. 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. Jan 31 '20 at 20:01
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's flow for security reasons.


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.