I have been trying for a few days to create a custom payment method in checkout to implement a payment gateway from a new payment provider. So far I have seen many informations and tutorials but nothing ever show up in the frontend (I have the option in the admin panel). Here is what I have so far:
app/code/Xpertics/Satimpayment/etc/adminhtml/system.xml :
<?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" type="text" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="1000" translate="label">
<group id="satimpayment" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Satim Payment</label>
<field id="active" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" canRestore="1">
<label>Enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="order_status" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" canRestore="1">
<label>New Order Status</label>
<source_model>Magento\Sales\Model\Config\Source\Order\Status\NewStatus</source_model>
</field>
<field id="sort_order" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1">
<label>Sort Order</label>
<frontend_class>validate-number</frontend_class>
</field>
<field id="title" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Title</label>
</field>
<field id="allowspecific" translate="label" type="allowspecific" sortOrder="50" showInDefault="1" showInWebsite="1" canRestore="1">
<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="51" showInDefault="1" showInWebsite="1">
<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="payable_to" translate="label" sortOrder="61" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Make Check Payable to</label>
</field>
<field id="mailing_address" translate="label" type="textarea" sortOrder="62" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Send Check to</label>
</field>
<field id="min_order_total" translate="label" type="text" sortOrder="98" showInDefault="1" showInWebsite="1">
<label>Minimum Order Total</label>
<validate>validate-number validate-zero-or-greater</validate>
</field>
<field id="max_order_total" translate="label" type="text" sortOrder="99" showInDefault="1" showInWebsite="1">
<label>Maximum Order Total</label>
<validate>validate-number validate-zero-or-greater</validate>
</field>
<field id="model"></field>
</group>
</section>
</system>
</config>
app/code/Xpertics/Satimpayment/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="offline_payment_instructions_config_provider" xsi:type="object">Magento\OfflinePayments\Model\InstructionsConfigProvider</item>
<!--<item name="offline_payment_satimpayment_config_provider" xsi:type="object">Xpertics\SatimPayment\Model\SatimPaymentConfigProvider.php</item>-->
</argument>
</arguments>
</type>
</config>
app/code/Xpertics/Satimpayment/etc/config.xml :
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<payment>
<satimpayment>
<model>Xpertics\SatimPayment\Model\Satimpayment</model>
<title>Satim Payment</title>
<payment_action>authorize</payment_action>
<active>1</active>
<is_gateway>1</is_gateway>
<can_use_checkout>1</can_use_checkout>
<can_authorize>1</can_authorize>
<can_capture>1</can_capture>
<can_refund>1</can_refund>
<can_void>1</can_void>
<can_cancel>1</can_cancel>
<cctypes>AE,VI,MC,DI,JCB,CUP,DN,MI</cctypes>
<useccv>1</useccv>
<order_status>processing</order_status>
</satimpayment>
</payment>
</default>
</config>
app/code/Xpertics/Satimpayment/etc/module.xml :
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Xpertics_SatimPayment" setup_version="1.0.0">
<sequence>
<module name="Magento_Sales"/>
<module name="Magento_Payment"/>
<module name="Magento_Checkout"/>
<module name="Magento_OfflinePayments"/>
</sequence>
</module>
</config>
app/code/Xpertics/Satimpayment/etc/payment.xml :
<?xml version="1.0" ?>
<payment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Payment:etc/payment.xsd">
<methods>
<method name="satimpayment">
<allow_multiple_address>1</allow_multiple_address>
</method>
</methods>
</payment>
app/code/Xpertics/Satimpayment/Block/Form/SatimPayment.php :
<?php
namespace Xpertics\SatimPayment\Block\Form;
class SatimPayment extends \Magento\Payment\Block\Form
{
protected $_template = 'Xpertics_SatimPayment::form/satimpayment.phtml';
}
}
app/code/Xpertics/Satimpayment/Block/Info/SatimPayment.php :
<?php
namespace Xpertics\SatimPayment\Block\Info;
class SatimPayment extends \Magento\Payment\Block\Info{
protected $_template = 'Xpertics_SatimPayment::info/satimpayment.phtml';
}
app/code/Xpertics/Satimpayment/Model/Satimpayment.php :
<?php
namespace Xpertics\SatimPayment\Model;
use Magento\Payment\Model\Method\AbstractMethod;
class Satimpayment extends AbstractMethod
{
const PAYMENT_METHOD_SATIMPAYMENT_CODE = 'satimpayment';
protected $_code = self::PAYMENT_METHOD_SATIMPAYMENT_CODE;
protected $_isOffline = true;
protected $_formBlockType = \Xpertics\SatimPayments\Block\Form\SatimPayment::class;
protected $_infoBlockType = \Xpertics\SatimPayments\Block\Info\SatimPayment::class;
public function getPayableTo(){
return $this->getConfigData('payable_to');
}
public function getMailingAddress(){
return $this->getConfigData('mailing_address');
}
public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null)
{
return parent::isAvailable($quote);
}
}
app/code/Xpertics/Satimpayment/Model/SatimPaymentConfigProvider.php :
<?php
namespace Xpertics\SatimPayment\Model;
use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Framework\Escaper;
use Magento\Payment\Helper\Data as PaymentHelper;
class SatimPaymentConfigProvider implements ConfigProviderInterface{
protected $methodCode = SatimPayment::PAYMENT_METHOD_SATIMPAYMENT_CODE;
protected $method;
protected $escaper;
public function __construct(PaymentHelper $paymentHelper, Escaper $escaper){
$this->escaper = $escaper;
$this->method = $paymentHelper->getMethodInstance($this->methodCode);
}
public function getConfig(){
return $this->method->isAvailble() ?[
'payment' => [
'satimpayment' => [
'mailingAddress' => $this->getMailingAddress(),
'payableTo' => $this->getPayableTo(),
],
],
] : [];
}
protected function getMailingAddress(){
return nl2br($this->escaper->escapeHtml($this->method->getMailingAddress()));
}
protected function getPayableTo(){
return $this->method->getPayableTo();
}
}
app/code/Xpertics/Satimpayment/view/frontend/layout/checkout_index_index.xml :
<?xml version="1.0" ?>
<page layout="1column" 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="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">
<item name="satimpayment" xsi:type="array">
<item name="component" xsi:type="string">Xpertics_SatimPayment/js/view/payment/satimpayment</item>
<item name="methods" xsi:type="array">
<item name="xpertics_satimpayment" 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>
app/code/Xpertics/Satimpayment/view/frontend/templates/form/satimpayment.phtml :
<?php if ($block->getMethod()->getMailingAddress() || $block->getMethod()->getPayableTo()):?>
<dl class="items check payable" id="payment_form_<?= $block->escapeHtml($block->getMethodCode()) ?>" style="display:none;">
<?php if ($block->getMethod()->getPayableTo()) : ?>
<dt class="title"><?= $block->escapeHtml(__('Make Check payable to:')) ?></dt>
<dd class="content"><?= $block->escapeHtml($block->getMethod()->getPayableTo()) ?></dd>
<?php endif; ?>
<?php if ($block->getMethod()->getMailingAddress()) : ?>
<dt class="title"><?= $block->escapeHtml(__('Send Check to:')) ?></dt>
<dd class="content">
<address class="checkmo mailing address">
<?= /* @noEscape */ nl2br($block->escapeHtml($block->getMethod()->getMailingAddress())) ?>
</address>
</dd>
<?php endif; ?>
</dl>
<?php endif; ?>
app/code/Xpertics/Satimpayment/view/frontend/templates/info/satimpayment.phtml :
<dl class="payment-method checkmemo">
<dt class="title"><?= $block->escapeHtml($block->getMethod()->getTitle()) ?></dt>
<?php if ($block->getInfo()->getAdditionalInformation()) : ?>
<?php if ($block->getPayableTo()) : ?>
<dd class="content">
<strong><?= $block->escapeHtml(__('Make Check payable to')) ?></strong>
<?= $block->escapeHtml($block->getPayableTo()) ?>
</dd>
<?php endif; ?>
<?php if ($block->getMailingAddress()) : ?>
<dd class="content">
<strong><?= $block->escapeHtml(__('Send Check to')) ?></strong>
<address class="checkmo mailing address">
<?= /* @noEscape */ nl2br($block->escapeHtml($block->getMailingAddress())) ?>
</address>
</dd>
<?php endif; ?>
<?php endif; ?>
</dl>
app/code/Xpertics/Satimpayment/view/frontend/web/js/view/payment/method-renderer/satimpayment-method.js :
define(
[
'Magento_Checkout/js/view/payment/default',
'Magento_Payment/js/view/payment/cc-form',
'Magento_Checkout/js/action/place-order',
'Magento_Checkout/js/model/full-screen-loader',
'Magento_Checkout/js/model/payment/additional-validators',
'Magento_Payment/js/model/credit-card-validation/validator'
],
function (Component) {
'use strict';
return Component.extend({
defaults:{
template: 'Xpertics_SatimPayment/payment/satimpayment'
},
getMailingAddress: function () {
return window.checkoutConfig.payment.satimpayment.mailingAddress;
},
getInstructions: function () {
return window.checkoutConfig.payment.instructions(this.item.method);
},
getCode: function(){
return 'xpertics_sapimpayment';
},
isActive: function () {
return true;
}
});
}
);
app/code/Xpertics/Satimpayment/view/frontend/web/js/view/payment/satimpayment.js :
define(
[
'uiComponent',
'Magento_Checkout/js/model/payment/renderer-list'
],
function (
Component,
rendererList
) {
'use strict';
rendererList.push(
{
type: 'xpertics_satimpayment',
compoonent: 'Xpertics_SatimPayment/js/view/payment/method-renderer/satimpayment-method'
}
);
return Component.extend({});
}
);
app/code/Xpertics/Satimpayment/view/frontend/web/template/payment/satimpayment.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>
<p data-bind="html: getInstructions()"></p>
<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-role="review-save"
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>