1

I'm trying to get the payment method in checkout_onepage_controller_success_action observer. I have tried:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('\Magento\Sales\Model\Order')->load($orderId[0]);
$payment = $order->getPayment();


$method = $payment->getMethodInstance();
$methodTitle = $method->getTitle();
$qid = $order->getQuoteId();
$order_data= $order->getData();
var_dump( $order) ;  // there is nothing like payment mehotd.
var_dump( $methodTitle); // yes I get the payment method title.
$increment_id = $order_data['increment_id'];
var_dump($payment);  // The payment method is within this object.
die();

The out put of $payment is very long so I'm going to paste only necessary part.

/var/www/html/m4/app/code/Magento/SamplePaymentGateway/Observer/ProcessGatewayRedirect.php:49:
object(Magento\Sales\Model\Order)[1847]
  protected '_eventPrefix' => string 'sales_order' (length=11)
  protected '_eventObject' => string 'order' (length=5)
  protected '_invoices' => null

...
...
      protected '_config' => 
        object(Magento\Framework\Interception\ObjectManager\Config\Developer)[26]
          ...
  protected 'customAttributesCodes' => null
  protected 'customAttributesChanged' => boolean true
  protected '_idFieldName' => string 'entity_id' (length=9)
  protected '_hasDataChanges' => boolean true
  protected '_origData' => 
    array (size=54)
      'entity_id' => string '75' (length=2)
      'parent_id' => string '75' (length=2)
      'base_shipping_captured' => null
      'shipping_captured' => null
      'amount_refunded' => null
      'base_amount_paid' => null
      'amount_canceled' => null
      'base_amount_authorized' => string '37.0000' (length=7)
      'base_amount_paid_online' => null
      'base_amount_refunded_online' => null
      'base_shipping_amount' => string '5.0000' (length=6)
      'shipping_amount' => string '5.0000' (length=6)
      'amount_paid' => null
      'amount_authorized' => string '37.0000' (length=7)
      'base_amount_ordered' => string '37.0000' (length=7)
      'base_shipping_refunded' => null
      'shipping_refunded' => null
      'base_amount_refunded' => null
      'amount_ordered' => string '37.0000' (length=7)
      'base_amount_canceled' => null
      'quote_payment_id' => null
      'additional_data' => null
      'cc_exp_month' => null
      'cc_ss_start_year' => null
      'echeck_bank_name' => null
      'method' => string 'nobel_payment' (length=13)
      'cc_debug_request_body' => null
      'cc_secure_verify' => null
      'protection_eligibility' => null

You may see that my payment method 'nobel_payment' is listed. But I'm unable to fetch it.

1
  • 1
    Try this code: $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $order = $objectManager->create('\Magento\Sales\Model\Order')->load($orderId[0]); $payment = $order->getPayment(); echo $payment->getMethod();die;
    – Abdul
    Jan 2, 2018 at 6:29

1 Answer 1

5

Try this code:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('\Magento\Sales\Model\Order')->load($orderId[0]);
$payment = $order->getPayment();
echo $payment->getMethod();

Your Answer

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

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