Custom Payment Module

Create Module With Name Space As Ap and module name as CustomPayment.
Step 1:
Create module.xml inside etc folder.
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
  <module name="Ap_CustomPayment" setup_version="2.0.0">
      <sequence>
            <module name="Magento_Store"/>
            <module name="Magento_Catalog"/>
            <module name="Magento_Sales" />
            <module name="Magento_Payment" />
            <module name="Magento_Directory" />
            <module name="Magento_Config" />
        </sequence>
  </module>
</config>
Step 2:
Create Payment Method inside Admin by using below code.Go to Stores->Configration->Sales->Payment Methods.Your Custom Payment Method will visible here.
Create system.xml inside etc=>adminhtml folder.
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../Config/etc/system_file.xsd">
    <system>
        <section id="payment">
            <group id="mypayment" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>CustomPayment</label>
                <field id="active" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Enabled</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                </field>
                <field id="title" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Title</label>
                </field>
                 <field id="new_order_status" translate="label" type="select" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>New Order Status</label>
                    <source_model>Magento\Sales\Model\Config\Source\Order\Status\Newprocessing</source_model>
                </field>
                <field id="complete_order_status" translate="label" type="select" sortOrder="140" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Approved Order Status</label>
                    <source_model>Magento\Sales\Model\Config\Source\Order\Status\Processing</source_model>
                </field>
              
               <field id="paymentgatway_url" translate="label" type="text" sortOrder="70" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>PaymentGatway URL</label>
                </field>
                
                <field id="allowspecific" translate="label" type="allowspecific" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Payment from Applicable Countries</label>
                    <source_model>Magento\Payment\Model\Config\Source\Allspecificcountries</source_model>
                </field>
                <field id="specificcountry" translate="label" type="multiselect" sortOrder="41" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Payment from Specific Countries</label>
                    <source_model>Magento\Directory\Model\Config\Source\Country</source_model>
                    <can_be_empty>1</can_be_empty>
                </field>
                <field id="instructions" translate="label" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Instructions</label>
                </field>
                <field id="sort_order" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Sort Order</label>
                    <frontend_class>validate-number</frontend_class>
                </field>
            </group>
            <!-- payment-group -->
        </section>
    </system>
</config>
Here Group Id indicates your payment method Code.
Step 3:
Create cofig.xml File inside etc folder. That indicates default setting of your Payment Gateway.
Create system.xml inside etc=>adminhtml folder.
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../Store/etc/config.xsd">
    <default>
        <payment>
             <mypayment>
                <active>1</active>
                <title>MyPayment</title>
                <order_status>pending_payment</order_status>
                <instructions>Instruction.</instructions>
                <payment_action>true</payment_action>
                <model>Ap\CustomPayment\Model\MyPayment</model>
            </mypayment>
        </payment>
    </default>
</config>
Step 4:
Create Model class of your Payment Gateway inside Ap\CustomPayment\Model\MyPayment.php.In it, you can set your quote parameter so you can send to PaymentGatway.
namespace Ap\CustomPayment\Model;
class MyPayment extends \Magento\Payment\Model\Method\AbstractMethod
{

    protected $_code = 'mypayment';

   // protected $_isOffline = true;

    protected $_isGateway                   = false;
    protected $_canAuthorize                = false;
    protected $_canCapture                  = false;
    protected $_canCapturePartial           = false;
    protected $_canRefund                   = false;
    protected $_canRefundInvoicePartial     = false;
    protected $_canVoid                     = false;
    protected $_canUseInternal              = false;
    protected $_canUseCheckout              = true;
    protected $_canUseForMultishipping      = false;
    protected $_canSaveCc                   = false;
    
    protected $urlBuilder;
    protected $_moduleList;
    protected $checkoutSession;
    protected $_orderFactory;

      public function __construct(
        \Magento\Framework\Model\Context $context,
        \Magento\Framework\Registry $registry,
        \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
        \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory,
        \Magento\Payment\Helper\Data $paymentData,
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
        \Magento\Payment\Model\Method\Logger $logger,
        \Magento\Framework\Module\ModuleListInterface $moduleList,
        \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
        \Magento\Sales\Model\OrderFactory $orderFactory,
        \Magento\Framework\Url $urlBuilder,
        \Magento\Checkout\Model\Session $checkoutSession,
        \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
        \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
        array $data = []){
        $this->urlBuilder = $urlBuilder;
        $this->_moduleList = $moduleList;
        $this->checkoutSession = $checkoutSession;
        $this->_orderFactory = $orderFactory;
        parent::__construct($context,
            $registry,
            $extensionFactory,
            $customAttributeFactory,
            $paymentData,
            $scopeConfig,
            $logger,
            $resource,
            $resourceCollection,
            $data);
    }
    
    
    public function getOrderPlaceRedirectUrl()
    {
        return $this->urlBuilder->getUrl('apcustompayment/payment/redirect', ['_secure' => true]);
    }
    
     public function getCustomPaymentCheckoutRedirection()
    {
        $orderIncrementId = $this->checkoutSession->getLastRealOrderId();
        $order = $this->_orderFactory->create()->loadByIncrementId($orderIncrementId);
       // $url_payment = $this->getConfigData('paymentgatway_url'); 
        $url_payment ="http://localhost/test.php";
        
        $moduleDetails = $this->_moduleList->getOne('Ap_CustomPayment');
        $version = $moduleDetails['setup_version'];
        $params = array(
            'amount'        =>  ($order->getBaseGrandTotal()*100),
            'custom_data'   =>  $order->getStoreId(),
            'currency'      =>  $order->getOrderCurrencyCode(),
            'ipn_url'       =>  $this->urlBuilder->getUrl('appayplug/payment/ipn'),
            'cancel_url'    =>  $this->urlBuilder->getUrl('appayplug/payment/cancel'),
            'return_url'    =>  $this->urlBuilder->getUrl('checkout/onepage/success'),
            'email'         =>  $order->getCustomerEmail(),
            'firstname'     =>  $order->getCustomerFirstname(),
            'lastname'      =>  $order->getCustomerLastname(),
            'first_name'     =>  $order->getCustomerFirstname(),
            'last_name'      =>  $order->getCustomerLastname(),
            'order'         =>  $orderIncrementId,
            'customer'      =>  $order->getCustomerId()
        );

        $url_params = http_build_query($params);

        $url_param_base_encode = base64_encode($url_params);


        $redirect_url = $url_payment."?data=".$url_param_base_encode;
        
        //echo "<pre>";print_r($redirect_url);die;
        
        return $redirect_url;
    }
  

}

Step 5
Now you have to display your gateway on checkout process for this follow below steps.
You have to bind your gateway with checkout. To create file inside view=>frontend=>layout=>checkout_index_index.xml
Now you have to display your gatway on checkout process for this follow below steps.
You have to bind your gatway with checkout . So create file inside view=>frontend=>layout=>checkout_index_index.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="checkout.root">
            <arguments>
                <argument name="jsLayout" xsi:type="array">
                    <item name="components" xsi:type="array">
                        <item name="checkout" xsi:type="array">
                            <item name="children" xsi:type="array">
                                <item name="steps" xsi:type="array">
                                    <item name="children" xsi:type="array">
                                        <item name="billing-step" xsi:type="array">
                                            <item name="children" xsi:type="array">
                                                <item name="payment" xsi:type="array">
                                                    <item name="children" xsi:type="array">
                                                        <item name="renders" xsi:type="array">
                                                            <item name="children" xsi:type="array">
                                                            <!-- merge payment method renders here -->
                                                                <item name="custompayment-mypayment" xsi:type="array">
                                                                    <item name="component" xsi:type="string">Ap_CustomPayment/js/view/payment/mypayment</item>
                                                                    <item name="methods" xsi:type="array">
                                                                        <item name="mypayment" xsi:type="array">
                                                                            <item name="isBillingAddressRequired" xsi:type="boolean">true</item>
                                                                        </item>
                                                                    </item>
                                                                </item>
                                                            <!-- item-renderer -->
                                                            </item>
                                                        </item>
                                                    </item>
                                                </item>
                                            </item>
                                        </item>
                                    </item>
                                </item>
                            </item>
                        </item>
                    </item>
                </argument>
            </arguments>
        </referenceBlock>
    </body>
</page>


Create file Ap/CustomPayment/view/frontend/web/js/view/payment/mypayment.js
define(
    [
        'uiComponent',
        'Magento_Checkout/js/model/payment/renderer-list'
    ],
    function (
        Component,
        rendererList
    ) {
        'use strict';
        rendererList.push(
            {
                type: 'mypayment',
                component: 'Ap_CustomPayment/js/view/payment/method-renderer/mypayment-method'
            }
        );
        /** Add view logic here if needed */
        return Component.extend({});
    }
);


Create file Ap/CustomPayment/view/frontend/web/js/view/payment/method-renderer/mypayment-method.js

define(
    [
        'jquery',
        'Magento_Checkout/js/view/payment/default',
        'Ap_CustomPayment/js/action/set-payment-method',
        'Magento_Checkout/js/model/payment/additional-validators'
    ],
    function ($, Component, setPaymentMethodAction) {
        'use strict';

        return Component.extend({
            defaults: {
                template: 'Ap_CustomPayment/payment/mypayment'
            },
            
            continueToButton: function () {
                //update payment method information if additional data was changed
                this.selectPaymentMethod();
                setPaymentMethodAction(this.messageContainer);
                return false;
            },
            /** Returns send check to info */
            getMailingAddress: function() {
                return window.checkoutConfig.payment.checkmo.mailingAddress;
            },

           
        });
    }
);

Create file Ap/CustomPayment/view/frontend/web/js/action/set-payment-method.js

define(
    [
        'jquery',
        'Magento_Checkout/js/model/quote',
        'Magento_Checkout/js/model/url-builder',
        'mage/storage',
        'Magento_Checkout/js/model/error-processor',
        'Magento_Customer/js/model/customer',
        'Magento_Checkout/js/model/full-screen-loader'
    ],
    function ($, quote, urlBuilder, storage, errorProcessor, customer, fullScreenLoader) {
        'use strict';

        return function (messageContainer) {
            var serviceUrl,
                payload,
                paymentData = quote.paymentMethod();

            /**
             * Checkout for guest and registered customer.
             */
            if (!customer.isLoggedIn()) {
                serviceUrl = urlBuilder.createUrl('/guest-carts/:cartId/selected-payment-method', {
                    cartId: quote.getQuoteId()
                });
                payload = {
                    cartId: quote.getQuoteId(),
                    method: paymentData
                };
            } else {
                serviceUrl = urlBuilder.createUrl('/carts/mine/selected-payment-method', {});
                payload = {
                    cartId: quote.getQuoteId(),
                    method: paymentData
                };
            }
            fullScreenLoader.startLoader();

            return storage.put(
                serviceUrl, JSON.stringify(payload)
            ).done(
                function () {
                  //  alert(window.checkoutConfig.payment.custompayment.redirectUrl[quote.paymentMethod().method]);
                    $.mage.redirect(window.checkoutConfig.payment.custompayment.redirectUrl[quote.paymentMethod().method]);
                }
            ).fail(
                function (response) {
                    errorProcessor.process(response, messageContainer);
                    fullScreenLoader.stopLoader();
                }
            );
        };
    }
);


Create Template file inside Ap/CustomPayment/view/frontend/web/template/payment/mypayment.html

<div class="payment-method" data-bind="css: {'_active': (getCode() == isChecked())}">
    <div class="payment-method-title field choice">
        <input type="radio"
               name="payment[method]"
               class="radio"
               data-bind="attr: {'id': getCode()}, value: getCode(), checked: isChecked, click: selectPaymentMethod, visible: isRadioButtonVisible()"/>
        <label data-bind="attr: {'for': getCode()}" class="label"><span data-bind="text: getTitle()"></span></label>
    </div>
    <div class="payment-method-content">
        <!-- ko foreach: getRegion('messages') -->
        <!-- ko template: getTemplate() --><!-- /ko -->
        <!--/ko-->
        <div class="payment-method-billing-address">
            <!-- ko foreach: $parent.getRegion(getBillingAddressFormName()) -->
            <!-- ko template: getTemplate() --><!-- /ko -->
            <!--/ko-->
        </div>
        <div class="checkout-agreements-block">
            <!-- ko foreach: $parent.getRegion('before-place-order') -->
                <!-- ko template: getTemplate() --><!-- /ko -->
            <!--/ko-->
        </div>
        <div class="actions-toolbar">
            <div class="primary">
                <button class="action primary checkout"
                        type="submit"
                        data-bind="click: continueToButton, enable: (getCode() == isChecked())"
                        disabled>
                    <span data-bind="i18n: 'Place Order'"></span>
                </button>
            </div>
        </div>
    </div>
</div>

Step 6:
Ap/CustomPayment/etc/frontend/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Checkout\Model\CompositeConfigProvider">
        <arguments>
            <argument name="configProviders" xsi:type="array">
                <item name="customPayment_config_provider" xsi:type="object">Ap\CustomPayment\Model\ConfigProvider</item>
            </argument>
        </arguments>
    </type>
</config>

Step 7:
Create depency file Ap\CustomPayment\Model\ConfigProvider.php
namespace Ap\CustomPayment\Model;
use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Framework\Locale\ResolverInterface;
use Magento\Customer\Helper\Session\CurrentCustomer;
use Magento\Payment\Helper\Data as PaymentHelper;
class ConfigProvider implements ConfigProviderInterface
{

    protected $localeResolver;

    protected $config;

    protected $currentCustomer;

    /**
     * @var \Magento\Payment\Model\Method\AbstractMethod[]
     */
    protected $methods = [];

    /**
     * @var PaymentHelper
     */
    protected $paymentHelper;
    
    protected $checkoutSession;

    public function __construct(
        ResolverInterface $localeResolver,
        CurrentCustomer $currentCustomer,
        \Magento\Checkout\Model\Session $checkoutSession,
        PaymentHelper $paymentHelper
    ) {
        $this->localeResolver = $localeResolver;
        //$this->config = $configFactory->create();
        $this->currentCustomer = $currentCustomer;
        $this->paymentHelper = $paymentHelper;
        $this->checkoutSession = $checkoutSession;

        $code = 'mypayment';
        $this->methods[$code] = $this->paymentHelper->getMethodInstance($code);
    }

    public function getConfig()
    {
        $code = 'mypayment';
        $config = [];
        
        if ($this->methods[$code]->isAvailable($this->checkoutSession->getQuote())) {
            $config = [];
            $config['payment'] = [];
            $config['payment']['custompayment']['redirectUrl'] = [];
            $config['payment']['custompayment']['redirectUrl'][$code] = $this->getMethodRedirectUrl($code);
            
        }
        
        return $config;
    }

    protected function getMethodRedirectUrl($code)
    {
        return $this->methods[$code]->getOrderPlaceRedirectUrl();
    }

}


Step 7:
Ap/CustomPayment/etc/frontend/routes.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="standard">
        <route id="apCustomPayment" frontName="apCustomPayment">
            <module name="Ap_CustomPayment" />
        </route>
    </router>
</config>

Step 8:
Ap/CustomPayment/Controller/Payment/Redirect.php

namespace Ap\CustomPayment\Controller\Payment; 
use Magento\Framework\Controller\ResultFactory;
use Magento\Quote\Api\CartManagementInterface;

class Redirect extends \Magento\Framework\App\Action\Action
{
    protected $_customerSession;
    protected $resultPageFactory;
    protected $_paymentMethod;
    protected $_checkoutSession;
    protected $checkout;
    protected $cartManagement;
    protected $orderRepository;
    protected $_scopeConfig;

    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Customer\Model\Session $customerSession,
        \Ap\CustomPayment\Model\PaymentMethod $paymentMethod,
        \Magento\Checkout\Model\Session $checkoutSession,
        \Magento\Sales\Api\OrderRepositoryInterface $orderRepository,
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
        CartManagementInterface $cartManagement
    ) {
        $this->_customerSession = $customerSession;
        parent::__construct($context);
        $this->_paymentMethod = $paymentMethod;
        $this->_checkoutSession = $checkoutSession;
        $this->cartManagement = $cartManagement;
        $this->orderRepository = $orderRepository;
        $this->_scopeConfig = $scopeConfig;
    }

    
    public function execute()
    {
        $orderId = $this->cartManagement->placeOrder($this->_checkoutSession->getQuote()->getId());
        $order = $this->orderRepository->get($orderId);
        if ($order){
            $order->setState($this->_scopeConfig->getValue('payment/apCustomPayment/new_order_status', \Magento\Store\Model\ScopeInterface::SCOPE_STORE));
            $order->setStatus($this->_scopeConfig->getValue('payment/apCustomPayment/new_order_status', \Magento\Store\Model\ScopeInterface::SCOPE_STORE));
            $order->save();
        }
        $url = $this->_paymentMethod->getCustomPaymentCheckoutRedirection();
        $resultRedirect = $this->resultRedirectFactory->create();
        $resultRedirect->setUrl($url);
        return $resultRedirect;
    }
}


Ap/CustomPayment/Controller/Payment/Success.php
namespace Ap\CustomPayment\Controller\Payment; 
use Magento\Framework\Controller\ResultFactory;
class Success extends \Magento\Framework\App\Action\Action
{
    protected $_customerSession;
    protected $resultPageFactory;
    protected $_scopeConfig;
    protected $_orderFactory;
    private $invoiceService;
    protected $orderSender;
    
    const PAYMENT_STATUS_PAID = 0;
    const PAYMENT_STATUS_REFUND = 4;
    const PAYMENT_STATUS_CANCEL = 2; 
    protected $transactionBuilder;
    public function __construct(
        \Magento\Customer\Model\Session $customerSession,
        \Magento\Framework\App\Action\Context $context,
        \Magento\Sales\Model\OrderFactory $orderFactory,
        \Magento\Sales\Model\Service\InvoiceService $invoiceService,
        \Magento\Sales\Model\Order\Email\Sender\CreditmemoSender $creditmemoSender,
        \Magento\Sales\Model\Order\Email\Sender\OrderSender $orderSender,
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
        \Magento\Sales\Model\Order\Payment\Transaction\BuilderInterface $transactionBuilder    
    ) {
        $this->_customerSession = $customerSession;
        parent::__construct($context);
        $this->_scopeConfig = $scopeConfig;
        $this->_orderFactory = $orderFactory;
        $this->invoiceService = $invoiceService;
        $this->creditmemoSender = $creditmemoSender;
        $this->orderSender = $orderSender;
        $this->transactionBuilder = $transactionBuilder;
    }

    
    protected function _createInvoice($order)
    {
        if (!$order->canInvoice()) {
            return;
        }
        
        $invoice = $order->prepareInvoice();
        if (!$invoice->getTotalQty()) {
            throw new \RuntimeException("Cannot create an invoice without products.");
        }

        $invoice->setRequestedCaptureCase(\Magento\Sales\Model\Order\Invoice::CAPTURE_OFFLINE);
        $invoice->register();
        $order->addRelatedObject($invoice);
    }
    
    public function execute()
    {
       
        $order   =  $_GET['order'];
        $status = 0;
        $transId = rand();
        $paymentData = array();
        
        $order = $this->_orderFactory->create()->loadByIncrementId($order);
        
        $this->_createInvoice($order);
        
        $orderId = $order->getId();
        
        $payment = $order->getPayment();
        
        $payment->setLastTransId($transId);
        
        $payment->setTransactionId($transId);

       //$this->orderSender->send($order);
         
        $trans = $this->transactionBuilder;
        
        $formatedPrice = $order->getBaseCurrency()->formatTxt(
                $order->getGrandTotal()
            );
        
        $message = __('The authorized amount is %1.', $formatedPrice);
        
        $transaction = $trans->setPayment($payment)
            ->setOrder($order)
            ->setTransactionId($transId)
            ->setAdditionalInformation(
                [\Magento\Sales\Model\Order\Payment\Transaction::RAW_DETAILS => (array) $paymentData]
            )
            ->setFailSafe(true)
            //build method creates the transaction and returns the object
            ->build(\Magento\Sales\Model\Order\Payment\Transaction::TYPE_CAPTURE);
        
        $payment->addTransactionCommentsToOrder(
                $transaction,
                $message
            );
        
        $payment->setParentTransactionId(null);
        $order->setState(\Magento\Sales\Model\Order::STATE_PROCESSING)
                                ->setStatus($order->getConfig()->getStateDefaultStatus(\Magento\Sales\Model\Order::STATE_PROCESSING));
        $order->addStatusToHistory(\Magento\Sales\Model\Order::STATE_PROCESSING, __('Payment has been captured by Payment Gateway. Transaction id: %1', $transId));     
        $payment->save();
        $order->save();     
        $id = $transaction->save()->getTransactionId();
        $resultRedirect = $this->resultRedirectFactory->create();
        $resultRedirect->setPath('checkout/onepage/success');
        return $resultRedirect;               
    }
}
Ap/CustomPayment/Controller/Payment/Cancel.php
namespace Ap\CustomPayment\Controller\Payment; 
use Magento\Framework\Controller\ResultFactory;
class Cancel extends \Magento\Framework\App\Action\Action
{
    protected $_customerSession;
    protected $resultPageFactory;
    protected $checkoutSession;
    protected $orderRepository;
    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Customer\Model\Session $customerSession,
        \Magento\Sales\Api\OrderRepositoryInterface $orderRepository,
        \Magento\Checkout\Model\Session $checkoutSession
    ) {
        $this->_customerSession = $customerSession;
        $this->checkoutSession = $checkoutSession;
        $this->orderRepository = $orderRepository;
        parent::__construct($context);
    }
    public function execute()
    {
        $this->messageManager->addError(__('Payment has been cancelled.'));
        /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
        //change order status to cancel
        $order = $this->orderRepository->get($this->checkoutSession->getLastOrderId());
        if ($order) {
            $order->cancel();
            $order->addStatusToHistory(\Magento\Sales\Model\Order::STATE_CANCELED, __('Canceled by customer'));
            $order->save();
        }
        
        $resultRedirect = $this->resultRedirectFactory->create();
        $resultRedirect->setPath('checkout/cart');
        return $resultRedirect;
    }
}





Comments

Post a Comment