1

I'm facing one issue while splitting the order on checkout. I followed these code mentioned in the link:- https://magento.stackexchange.com/questions/196669/magento-2-split-order-for-every-item and https://github.com/magestat/magento2-split-order

Both solution is working with offline payment like check/mo, Cash on delivery, po number etc. But its not working with credit card details. Always getting error regarding credit card details.

I'm putting some more information through code:-

I am stuck at a point to distribute order and assign payment method into it. there are two scenario i'm getting:

  1. if i assign payment method checkmo,Cash on delivery then order is splitted and everything is working fine with this.
  2. But i need to order products using credit card and when i assign payment method code(credit card payment method is 'nmi_directpost') and also assign card details into quote and placed and order then its showing me error differently, Some time its shows credit card details is not valid, sometime page is redirected to cart page without any log/exception. Here is bunch of code i'm trying to do:-
public function aroundPlaceOrder(QuoteManagement $subject, callable $proceed, $cartId, $payment = null)
    {
        $currentQuote = $this->quoteRepository->getActive($cartId);

        // Separate all items in quote into new quotes.
        $quotes = $this->quoteHandler->normalizeQuotes($currentQuote);
        if (empty($quotes)) {
            return $result = array_values([($proceed($cartId, $payment))]);
        }
        // Collect list of data addresses.
        $addresses = $this->quoteHandler->collectAddressesData($currentQuote);

        /** @var \Magento\Sales\Api\Data\OrderInterface[] $orders */
        $orders = [];
        $orderIds = [];
        foreach ($quotes as $items) {
            /** @var \Magento\Quote\Model\Quote $split */
            $split = $this->quoteFactory->create();

            // Set all customer definition data.
            $this->quoteHandler->setCustomerData($currentQuote, $split);
            $this->toSaveQuote($split);

            // Map quote items.
            foreach ($items as $item) {
                // Add item by item.
                $item->setId(null);
                $split->addItem($item);
            }
            \Magento\Framework\App\ObjectManager::getInstance()->get('Psr\Log\LoggerInterface')->info('new quote 1st :-'. print_r($split->getData(),true));
            $this->quoteHandler->populateQuote($quotes, $split, $items, $addresses, $payment);
            // $split->getPayment()->setMethod('nmi_directpost');
            // if ($payment) {
            //     $split->getPayment()->setQuote($split);
                // $data = $payment->getData();

                // $paymentDetails = $paymentCardDetails = '';
                // $postData = file_get_contents("php://input");//Get all param
                // $postData = (array)json_decode($postData);//Decode all json param
                // foreach ($postData as $key => $value) {
                //     if ($key == 'paymentMethod') { //Get paymentMethod details
                //         $paymentDetails = (array)$value;
                //         foreach ($paymentDetails as $key1 => $paymentValue) {
                //             if ($key1 == 'additional_data') { //get  paymentMethod Details like card details
                //                 $paymentCardDetails = (array)$paymentValue;
                //             }
                //         }
                //     }
                // }
                // $split->setMethod('checkmo');

                \Magento\Framework\App\ObjectManager::getInstance()->get('Psr\Log\LoggerInterface')->info('Paynet :-');
                // $payment = $quotes->getPayment();
                $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$cart = $objectManager->get('\Magento\Checkout\Model\Cart');

$quote = $cart->getQuote();
$paymentMethod = $quote->getPayment()->getMethod();
                $payment = $this->checkoutSession->getQuote()->getData();
                \Magento\Framework\App\ObjectManager::getInstance()->get('Psr\Log\LoggerInterface')->info('second Paynet :-');
                \Magento\Framework\App\ObjectManager::getInstance()->get('Psr\Log\LoggerInterface')->info('new quote :-'. print_r($paymentMethod,true));
                // $split->setPayment($payment);
                // $split->getPayment()->importData(array(
                //     'method'      =>'nmi_directpost',
                //     'cc_type'     =>'VI',
                //     'cc_number'   =>'4111111111111111',
                //     'cc_exp_year' =>'2025',
                //     'cc_exp_month'=>'10',
                //   ));
            // }
            // \Magento\Framework\App\ObjectManager::getInstance()->get('Psr\Log\LoggerInterface')->info('original quote :-'. print_r($quotes->getData(),true));
            \Magento\Framework\App\ObjectManager::getInstance()->get('Psr\Log\LoggerInterface')->info('new quote :-'. print_r($split->getData(),true));
            // \Magento\Framework\App\ObjectManager::getInstance()->get('Psr\Log\LoggerInterface')->info('new quote :-'. print_r($payment->getData(),true));
            // Dispatch event as Magento standard once per each quote split.
            $this->eventManager->dispatch(
                'checkout_submit_before',
                ['quote' => $split]
            );

            $this->toSaveQuote($split);
            $order = $subject->submit($split);

            $orders[] = $order;
            $orderIds[$order->getId()] = $order->getIncrementId();

            if (null == $order) {
                throw new LocalizedException(__('Please try to place the order again.'));
            }
        }
        $currentQuote->setIsActive(false);
        $this->toSaveQuote($currentQuote);

        $this->quoteHandler->defineSessions($split, $order, $orderIds);

        $this->eventManager->dispatch(
            'checkout_submit_all_after',
            ['orders' => $orders, 'quote' => $currentQuote]
        );
        return $this->getOrderKeys($orderIds);
    }

Please suggest how can we achieve order splitting with credit card payment.

1 Answers1

1

Splitting payment across multiple credit cards like this is referred to as 'partial authorization'. (Note: This is a very different thing from 'partial invoicing' or 'partial capturing', terms you'll also see thrown around.)

Magento's default Authorize.Net gateway includes partial authorization functionality, you just have to enable it in the gateway settings. This works with both Community and Enterprise Edition. See official documentation on the setup and workflow here.

To my knowledge, this is the only payment method that supports it.

Note that the customer does not get to choose how much to charge to each card. Rather, if the card they enter does not have sufficient funds, they will be prompted to enter another one.

  • @LitCommmerce but my requirement is different.i want to implement 2 different credit card payment option stripe and nmi credit card payment for one order. – sushant kumar Jul 08 '22 at 21:50