I am trying to capture payment online but it's not capturing. I am working with Magento 2.2. Not sure why this code does not work even the same code works with the latest version of Magento.

 public function createInvoice($order, $requireCapture = false)
  if (filter_var($requireCapture, FILTER_VALIDATE_BOOLEAN) === true) {
   $captureType = Invoice::CAPTURE_ONLINE;
  } else {
   $captureType = Invoice::CAPTURE_OFFLINE;

  if (!$order->getInvoiceCollection()->count()) {
   $invoice = $this->invoiceService->prepareInvoice($order);
   $transaction = $this->transactionFactory->create()->addObject($invoice)->addObject($invoice->getOrder());

Your Answer

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

Browse other questions tagged or ask your own question.