2

I am developing a payment module, which works with a webservice. After submit order, there is a session var with webservice response status. If this returns OK, the order must be set as paid and processing, else it must be canceled.

I am using capture() in my Payment model:

public function capture(\Magento\Payment\Model\InfoInterface $payment, $amount)
    {
        /** @var \Magento\Sales\Model\Order $order */
        $order = $payment->getOrder();

        /** @var \Magento\Sales\Model\Order\Address $billing */
        $billing = $order->getBillingAddress();

        try {
             if($someCondition)
            {
              //Process invoice and get 

            }
            else
            {
                $order->cancel();
                $order->save();
            }

//Also tried:
/*
            $payment->setState(\Magento\Sales\Model\Order::STATE_CANCELED);
            $order->setState(\Magento\Sales\Model\Order::STATE_CANCELED)
                ->setStatus($order->getConfig()->getStateDefaultStatus(\Magento\Sales\Model\Order::STATE_CANCELED));
*/
            $payment
                ->setTransactionId(rand(11112222,132222222))
                ->setIsTransactionClosed(1);

            $payment->save();
            $order->save();

        }

How can I do that?

Thanks

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.