0

I have to call some API on order status complete. For that I need values for the following.

  • credit card number (16 digits).
  • CVV
  • subtotal
  • and I have already called an API while place order I need to pass some of the response of that API here.

and my code is below

 public function execute(Observer $observer) {
        $order = $observer->getEvent()->getOrder(); 
        $controller = $observer->getControllerAction();

        if($order->getState() == "complete") 
        { 

           $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
           $cart = $objectManager->create('Magento\Checkout\Model\Cart');
           $payment = $order->getPayment();
           $order_id = $order->getIncrementId();
           $creditCardNumber =  $payment->getCcNumber();
           $CCV = $payment->getCcCid();
           $SubtotalAmount =(double)$cart->getQuote()->getSubtotal();
           $Rate = $_SESSION["rate"];//This is the response of API called on place order.

        }

for the above code my output is

  • credit card number = null (if i use getCcLast4() its working, but i want full 16 digits number).
  • CVV = null
  • subtotal = 0
  • and I have already called an API while place order I need to pass some of the response of that API here. = log error.

can any one help me to solve this?

1

Magento 2 doesn't store customer's credit card number or CCV number.

It's against PCI standards to keep customer credit card info in your database. You can find the reasons why PCI Council restricts this in the post - http://blog.emagicone.com/2015/12/why-credit-cards-can-not-be-charged.html

Edit

I think, cart object is not require because you have $order instance already. So you can get order sub-total by $order->getSubTotal().

public function execute(Observer $observer)
{
    $order = $observer->getEvent()->getOrder();
    $controller = $observer->getControllerAction();

    if ($order->getState() == "complete") {
        /*
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $cart = $objectManager->create('\Magento\Sales\Model\OrderFactory');
        */
        $payment = $order->getPayment();
        $order_id = $order->getIncrementId();
        $creditCardNumber = $payment->getCcNumber();
        $CCV = $payment->getCcCid();
        /*
        $SubtotalAmount = (double)$cart->getQuote()->getSubtotal();
        */
        $SubtotalAmount = $order->getSubtotal();
        $Rate = $_SESSION["rate"];//This is the response of API called on place order.
    }
}
5
  • how can i get subtotal? – ASHWINI MURTHY Dec 10 '18 at 9:40
  • @ASHWINIMURTHY check my update – Supravat Mondal Dec 12 '18 at 13:05
  • Thanks. now iam able to get subtotal, but still my creditcard number and CVV is null... – ASHWINI MURTHY Dec 13 '18 at 7:09
  • i mentioned why couldn't you get these information. – Supravat Mondal Dec 13 '18 at 7:45
  • yeah i went through, how can i get Cart id? – ASHWINI MURTHY Dec 13 '18 at 8:40
0

I Got cart Id in my sales_order_save_after observer using quote Id $order = $observer->getEvent()->getOrder(); CartId = $order->getQuoteId();

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.