We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

    Before following the below steps you need to create the custom payment method module.

    Step 1) Create a template file – Magemonkey/Chargeanywhere/view/frontend/web/template/payment/chargeanywhere.html

    <!--
    /**
     * Copyright © 2015 Magento. All rights reserved.
     * See COPYING.txt for license details.
     */
    -->
    <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>
            <form class="form" data-bind="attr: {'id': getCode() + '-form'}">
                 <!-- ko template: 'Magento_Payment/payment/cc-form' --><!-- /ko -->         
                 
    
            </form>
            <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: placeOrder,
                            attr: {title: $t('Place Order')},
                            css: {disabled: !isPlaceOrderActionAllowed()},
                            enable: (getCode() == isChecked())
                            "
                            disabled>
                        <span data-bind="i18n: 'Place Order'"></span>
                    </button>
                </div>
            </div>
        </div>
    </div>

    Step 2) Magemonkey/Chargeanywhere/view/frontend/web/js/view/payment/method-renderer/chargeanywhere-method.js

    /**
     * Copyright © 2015 Magento. All rights reserved.
     * See COPYING.txt for license details.
     */
    /*browser:true*/
    /*global define*/
    define(
        [
            'jquery',
            'Magento_Payment/js/view/payment/cc-form'
        ],
        function (
            $,
            Component
            )  {
            'use strict';
    
            return Component.extend({
                defaults: {
                    template: 'Magemonkey_Chargeanywhere/payment/chargeanywhere'
                },
                context: function() {
                    return this;
                },
    
                getCode: function() {
                    return 'chargeanywhere';
                },
    
                isActive: function() {
                    return true;
                }
    
               
            });
        }
    );
    

    Step 3) create the di.xml file Magemonkey/Chargeanywhere/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="MagentoPaymentModelCcGenericConfigProvider">
            <arguments>
                <argument name="methodCodes" xsi:type="array">
                    <item name="chargeanywhere" xsi:type="const">MagemonkeyChargeanywhereModelChargeanywhere::CODE</item>
                </argument>
            </arguments>
        </type>
    </config>

    Step 4) create the config provider file Magemonkey/Chargeanywhere/Model/Chargeanywhere.php

    <?php
    /**
     * Copyright © 2015 Magento. All rights reserved.
     * See COPYING.txt for license details.
     */
    namespace MagemonkeyChargeanywhereModel;
    use MagentoFrameworkSimplexmlElement;
    use MagentoSalesModelOrderPaymentTransaction;
    
    
    /**
     * Pay In Store payment method model
     */
    class Chargeanywhere extends MagentoPaymentModelMethodCc
    {
        const CODE = 'chargeanywhere';
        /**
         * Payment code
         *
         * @var string
         */
        protected $_code = self::CODE;
    
        /**
         * Availability option
         *
         * @var bool
         */
        // protected $_isOffline = true;
    
        protected $_canAuthorize = true;
        protected $_canCapture = true;
    
        public function __construct(
            MagentoFrameworkModelContext $context,
            MagentoFrameworkRegistry $registry,
            MagentoFrameworkApiExtensionAttributesFactory $extensionFactory,
            MagentoFrameworkApiAttributeValueFactory $customAttributeFactory,
            MagentoPaymentHelperData $paymentData,
            MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig,
            MagentoPaymentModelMethodLogger $logger,
            MagentoFrameworkModuleModuleListInterface $moduleList,
            MagentoFrameworkStdlibDateTimeTimezoneInterface $localeDate,
            MagentoDirectoryModelCountryFactory $countryFactory,
            MagentoCheckoutModelCart $cart,
            MagentoQuoteModelQuoteFactory $quote,
            MagentoBackendModelSessionQuote $quoteSession,
            MagentoFrameworkAppResourceConnection $resource,
            MagentoFrameworkAppState $state,
            MagentoCustomerModelSession $customerSession,
            MagentoFrameworkSessionSessionManager $sessionManager,
            MagentoDirectoryModelRegion $regionList,
            MagentoFrameworkAppRequestHttp $request,
            MagentoSalesModelOrderPaymentTransactionBuilderInterface $transactionBuilder,
            MagemonkeyChargeanywhereHelperData $helperData,
            MagentoCheckoutModelSession $checkoutSession,
            array $data = array()
        ) {
            $this->quote = $quote;
            $this->_session = $quoteSession;
            $this->_appState = $state;
            $this->_customerSession = $customerSession;
            $this->_regionList = $regionList;
            $this->request = $request;
            $this->_sessionId = $sessionManager->getSessionId();
            $this->_sessionManager = $sessionManager;
            $this->transactionBuilder = $transactionBuilder;
            $this->helper = $helperData;
            $this->_checkoutSession = $checkoutSession;
            parent::__construct(
                $context,
                $registry,
                $extensionFactory,
                $customAttributeFactory,
                $paymentData,
                $scopeConfig,
                $logger,
                $moduleList,
                $localeDate,
                null,
                null,
                $data
                
            );
            
            $this->cart = $cart;
            $this->_countryFactory = $countryFactory;
            $this->_scopeConfig = $scopeConfig;
        }
    
        /**
         * Validate payment method information object
         *
         * @return $this
         * @throws MagentoFrameworkExceptionLocalizedException
         * @SuppressWarnings(PHPMD.CyclomaticComplexity)
         * @SuppressWarnings(PHPMD.NPathComplexity)
         */
        public function validate() {
             parent::validate();
            return true;
        }
        public function authorize(MagentoPaymentModelInfoInterface $payment, $amount) {
            $chargedata = $this->_checkoutSession->getChargeData();
            $payment->setTransactionId($chargedata['ReferenceNumber']);
            $payment->setParentTransactionId($chargedata['ReferenceNumber']);
            $payment->setIsTransactionClosed(0);
            return $this;
        }
        public function capture(MagentoPaymentModelInfoInterface $payment, $amount)
        {   $chargedata = $this->_checkoutSession->getChargeData();
            $payment->setLastTransId($chargedata['ReferenceNumber']);
            $payment->setTransactionId($chargedata['ReferenceNumber']);
            return $this;
        }
    
        public function getConfigPaymentAction()
        {
           return $this->getConfigData('payment_action');
        }   
    }

     

    Step 5) override checkout index file Magemonkey/Chargeanywhere/view/frontend/layout/checkout_index_index.xml

    <?xml version="1.0"?>
    <!--
    /**
     * Copyright © 2015 Magento. All rights reserved.
     * See COPYING.txt for license details.
     */
    -->
    <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="chargeanywhere-chargeanywhere" xsi:type="array">
                                                                        <item name="component" xsi:type="string">Magemonkey_Chargeanywhere/js/view/payment/chargeanywhere</item>
                                                                        <item name="methods" xsi:type="array">
                                                                      
    																		 <item name="chargeanywhere" 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>

    Step 6) Create system.xml file Magemonkey/Chargeanywhere/etc/adminhtml/system.xml

    <?xml version="1.0"?>
    <!--
    /**
     * Copyright © 2015 Magento. All rights reserved.
     * See COPYING.txt for license details.
     */
    -->
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../Config/etc/system_file.xsd">
        <system>
            <section id="payment">
                <group id="chargeanywhere" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Charge Anywhere</label>
                    <field id="active" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="0">
                        <label>Enabled</label>
                        <source_model>MagentoConfigModelConfigSourceYesno</source_model>
                    </field>
                    <field id="title" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                        <label>Title</label>
                    </field>
                    <field id="order_status" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="0">
                        <label>New Order Status</label>
                        <source_model>MagemonkeyChargeanywhereModelConfigSourceOrderStatusPendingpayment</source_model>
                    </field>
                    <field id="api_key" translate="label" type="obscure" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
                        <label>API Secret Key</label>
                        <!-- <backend_model>MagentoConfigModelConfigBackendEncrypted</backend_model> -->
                        <comment>Test/Live Secret Key</comment>
                    </field>
                    <field id="marchant_id" translate="label" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
                        <label>Marchant Id</label>
                    </field>
                    <field id="terminal_id" translate="label" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
                        <label>Terminal Id</label>
                    </field>
                    <field id="mode_type" translate="label" type="select" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="0">
                        <label>Test/Live</label>
                        <source_model>MagemonkeyChargeanywhereModelSourceModetype</source_model>
                    </field>
                     <field id="payment_action" translate="label" type="select" sortOrder="12" showInDefault="1" showInWebsite="1" showInStore="0">
                        <label>Payment Action</label>
                        <source_model>MagemonkeyChargeanywhereModelConfigSourceOrderActionPaymentaction</source_model>
                    </field>
                    <field id="cctypes" translate="label" type="multiselect" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="0">
                        <label>Credit Card Types</label>
                        <source_model>MagentoPaymentModelSourceCctype</source_model>
                    </field>
                    <field id="instructions" translate="label" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
                        <label>Instructions</label>
                    </field>
                </group>
                <!-- payment-group -->
            </section>
        </system>
    </config>
    

     

    Step 7) Create config.xml file Magemonkey/Chargeanywhere/etc/config.xml

    <?xml version="1.0"?>
    <!--
    /**
     * Copyright © 2015 Magento. All rights reserved.
     * See COPYING.txt for license details.
     */
    -->
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../Store/etc/config.xsd">
        <default>
            <payment>
                <chargeanywhere>
                    <active>1</active>
                    <title>Chargeanywhere</title>
                    <order_status>pending_payment</order_status>
                    <instructions>Instruction.</instructions>
                    <payment_action>authorize</payment_action>
                    <model>MagemonkeyChargeanywhereModelChargeanywhere</model>
                    <group>offline</group>
                </chargeanywhere>
                <!-- payment-config -->
            </payment>
        </default>
    </config>
    

     

    Step 8) Create payment action file Magemonkey/Chargeanywhere/Model/Config/Source/Order/Action/Paymentaction.php

    <?php
    /**
     * Copyright © 2015 Magento. All rights reserved.
     * See COPYING.txt for license details.
     */
    namespace MagemonkeyChargeanywhereModelConfigSourceOrderAction;
    /**
     * Order Status source model
     */
    class Paymentaction  
    {
        /**
         * @var string[]
         */
        public function toOptionArray(){
            return [
                ['value' => 'authorize', 'label' => __('Authorize Only')],
                ['value' => 'authorize_capture', 'label' => __('Sale')],
            ];
        }
    }
    

    Step 9) Create order status file Magemonkey/Chargeanywhere/Model/Config/Source/Order/Status/Pendingpayment.php

    <?php
    /**
     * Copyright © 2015 Magento. All rights reserved.
     * See COPYING.txt for license details.
     */
    namespace MagemonkeyChargeanywhereModelConfigSourceOrderStatus;
    
    use MagentoSalesModelOrder;
    use MagentoSalesModelConfigSourceOrderStatus;
    
    /**
     * Order Status source model
     */
    class Pendingpayment extends Status
    {
        /**
         * @var string[]
         */
        protected $_stateStatuses = [Order::STATE_PENDING_PAYMENT];
    }
    

     

    field_5bfb909c5ccae

      Get a Free Quote