0

Preconditions

Magento 2.1.9 PHP 5.6 Ubuntu 16

Expected result

Many choices payment method enter image description here

Actual result enter image description here

here is log

exception.log:
[2018-03-28 19:38:24] main.CRITICAL: exception 'Exception' with message 'Notice: Array to string conversion in /var/www/html/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php on line 2929' in /var/www/html/vendor/magento/framework/App/ErrorHandler.php:61
Stack trace:
/var/www/html/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php(2929): Magento\Framework\App\ErrorHandler->handler(8, 'Array to string...', '/var/www/html/v...', 2929, Array)
/var/www/html/vendor/magento/framework/Model/ResourceModel/AbstractResource.php(168): Magento\Framework\DB\Adapter\Pdo\Mysql->prepareColumnValue(Array, Array)
/var/www/html/vendor/magento/framework/Model/ResourceModel/Db/AbstractDb.php(728): Magento\Framework\Model\ResourceModel\AbstractResource->_prepareDataForTable(Object(Magento\Quote\Model\Quote\Address), 'quote_address').....
{main} [] []
[2018-03-28 19:38:24] main.CRITICAL: exception 'Magento\Framework\Exception\InputException' with message 'Unable to save address. Please check input data.' in /var/www/html/vendor/magento/module-quote/Model/ShippingAddressManagement.php:128
Stack trace:
/var/www/html/vendor/magento/module-quote/Model/Quote/ShippingAssignment/ShippingProcessor.php(66): Magento\Quote\Model\ShippingAddressManagement->assign('71', Object(Magento\Quote\Model\Quote\Address))
/var/www/html/vendor/magento/module-quote/Model/Quote/ShippingAssignment/ShippingAssignmentProcessor.php(110): Magento\Quote\Model\Quote\ShippingAssignment\ShippingProcessor->save(Object(Magento\Quote\Model\Shipping), Object(Magento\Quote\Model\Quote))
/var/www/html/vendor/magento/module-quote/Model/Quote/ShippingAssignment/ShippingAssignmentPersister.php(34): Magento\Quote\Model\Quote\ShippingAssignment\ShippingAssignmentProcessor->save(Object(Magento\Quote\Model\Quote), Object(Magento\Quote\Model\ShippingAssignment))
/var/www/html/vendor/magento/module-quote/Model/QuoteRepository/SaveHandler.php(133): Magento\Quote\Model\Quote\ShippingAssignment\ShippingAssignmentPersister->save(Object(Magento\Quote\Model\Quote), Object(Magento\Quote\Model\ShippingAssignment))
/var/www/html/vendor/magento/module-quote/Model/QuoteRepository/SaveHandler.php(106): Magento\Quote\Model\QuoteRepository\SaveHandler->processShippingAssignment(Object(Magento\Quote\Model\Quote))
/var/www/html/vendor/magento/module-quote/Model/QuoteRepository.php(161): Magento\Quote\Model\QuoteRepository\SaveHandler->save(Object(Magento\Quote\Model\Quote))
/var/www/html/vendor/magento/module-checkout/Model/ShippingInformationManagement.php(156): Magento\Quote\Model\QuoteRepository->save(Object(Magento\Quote\Model\Quote))
/var/www/html/vendor/magento/framework/Interception/Interceptor.php(146): Magento\Checkout\Model\ShippingInformationManagement->saveAddressInformation('71', Object(Magento\Checkout\Model\ShippingInformation)) /var/www/html/var/generation/Magento/Checkout/Model/ShippingInformationManagement/Interceptor.php(26): Magento\Checkout\Model\ShippingInformationManagement\Interceptor->___callPlugins('saveAddressInfo...', Array, Array)
/var/www/html/vendor/magento/module-checkout/Model/GuestShippingInformationManagement.php(45): Magento\Checkout\Model\ShippingInformationManagement\Interceptor->saveAddressInformation('71', Object(Magento\Checkout\Model\ShippingInformation))
[internal function]: Magento\Checkout\Model\GuestShippingInformationManagement->saveAddressInformation('35a2c05016bbdc8...', Object(Magento\Checkout\Model\ShippingInformation))
/var/www/html/vendor/magento/module-webapi/Controller/Rest.php(307): call_user_func_array(Array, Array)
/var/www/html/vendor/magento/module-webapi/Controller/Rest.php(216): Magento\Webapi\Controller\Rest->processApiRequest()
/var/www/html/var/generation/Magento/Webapi/Controller/Rest/Interceptor.php(24): Magento\Webapi\Controller\Rest->dispatch(Object(Magento\Framework\App\Request\Http))
/var/www/html/vendor/magento/framework/App/Http.php(135): Magento\Webapi\Controller\Rest\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
/var/www/html/vendor/magento/framework/App/Bootstrap.php(258): Magento\Framework\App\Http->launch()
/var/www/html/index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
{main} [] []
1
  • disable checkout extension, first and then test again if your custom payment method works on it and not secondly could you also update question with your module code to check where could be the issue. Commented Mar 31, 2018 at 19:38

1 Answer 1

1

How to create custom payment method in Magento2 :- Here, I am going to learn that how to create custom payment method and render it to checkout page in magento2.

There are following files which will have to create :-

1 – Create Test/Testpayment/registration.php for register your module.

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Test_Testpayment',
    __DIR__
);

2- Craete Test/Testpayment/etc/module.xml for define module name.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noTestSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Test_Testpayment" setup_version="2.0.0" active="true">
    </module>
</config>

3- Create Test/Testpayment/etc/config.xml for define your payment method.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../Store/etc/config.xsd">
    <default>
        <payment>
            <testpayment>
                <payment_action>authorize</payment_action><!-- You can use another methor like capture  -->
                <model>Test\Testpayment\Model\PaymentMethod</model>
                <active>1</active>
                <title>Test Payment</title>
                <order_status>pending_payment</order_status><!-- set default order status-->
            </testpayment>
        </payment>
    </default>
</config>

4- Create Test/Testpayment/etc/adminhtml/system.xml for display payment method in backend. In this file mentioned only one field for enable/disable method.You can add field accordingly your need.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
        <section id="payment">
                <group id="testpayment" translate="label" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Test Payment</label>
                    <field id="active" translate="label comment" sortOrder="1" type="select" showInDefault="1" showInWebsite="1" showInStore="0">
                        <label>Enable</label>
                        <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                    </field>
                </group>
        </section>
    </system>
</config>

5- Create model file to define payment method

Test/Testpayment/Model/PaymentMethod.php
<?php

namespace Test\Testpayment\Model;

/**
 * Pay In Store payment method model
 */
class PaymentMethod extends \Magento\Payment\Model\Method\AbstractMethod
{

    /**
     * Payment code
     *
     * @var string
     */
    protected $_code = 'testpayment';
}

6- In this file Test/Testpayment/view/frontend/web/js/view/payment/method-renderer.js register our template or renderer file.

define(
    [
        'uiComponent',
        'Magento_Checkout/js/model/payment/renderer-list'
    ],
    function (
        Component,
        rendererList
    ) {
        'use strict';
        rendererList.push(
            {
                type: 'testpayment',
                component: 'Test_Testpayment/js/view/payment/method-renderer/testpayment'
            }
        );
        return Component.extend({});
    }
);

7- Create Test/Testpayment/view/frontend/web/js/view/payment/method-

renderer/testpayment.js
define(
    [
        'Magento_Checkout/js/view/payment/default'
    ],
    function (Component) {
        'use strict';

        return Component.extend({
            defaults: {
                template: 'Test_Testpayment/payment/testpayment'
            }
        });
    }
);

8- Create template file Test/Testpayment/view/frontend/web/template/payment/testpayment.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">
        <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>

9- Create Test/Testpayment/view/frontend/layout/checkout_index_index.xml for define payment method at checkout page.

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn: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="component" xsi:type="string">uiComponent</item>
                                            <item name="children" xsi:type="array">
                                                <item name="payment" xsi:type="array">
                                                    <item name="children" xsi:type="array">
                                                        <item name="renders" xsi:type="array">
                                                            <!-- merge payment method renders here -->
                                                            <item name="children" xsi:type="array">
                                                                <item name="testpayment" xsi:type="array">
                                                                    <item name="component" xsi:type="string">Test_Testpayment/js/view/payment/method-renderer</item>
                                                                    <item name="methods" xsi:type="array">
                                                                        <item name="testpayment" xsi:type="array">
                                                                            <item name="isBillingAddressRequired" xsi:type="boolean">true</item>
                                                                        </item>
                                                                    </item>
                                                                </item>
                                                            </item>
                                                        </item>
                                                    </item>
                                                </item>
                                            </item>
                                        </item>
                                    </item>
                                </item>
                            </item>
                        </item>
                    </item>
                </argument>
            </arguments>
        </referenceBlock>
    </body>
</page>

Now install this module execute php bin/magento setup:upgarde command in your root.

Now, You can check your custom payment method at checkout page like as below screen-shot. enter image description here

we also use this way in your site you can use.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.