please tell me what is wrong? i use this tutorial
https://www.youtube.com/watch?v=BRBtiL9Sp10
i try create paymant method without deprecated method
thank you!
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">
<groups>
<group id="offline">
<label>Coins Payment Methods</label>
</group>
</groups>
<methods>
<method name="coins">
<allow_multiple_address>1</allow_multiple_address>
</method>
</methods>
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>
<coins>
<active>1</active>
<can_use_checkout>1</can_use_checkout>
<model>CoinsFacade</model>
<order_status>pending</order_status>
<title>Christmas Coins</title>
</coins>
</payment>
</default>
</config>
etc/di.xml
<virtualType name="CoinsFacade" type="MagentoPaymentModelMethodAdapter">
<arguments>
<argument name="code"
xsi:type="const">SegaChristmasCoinsModelConfigSettings::CODE</argument>
<argument name="formBlockType"
xsi:type="string">MagentoPaymentBlockForm</argument>
<argument name="infoBlockType"
xsi:type="string">MagentoPaymentBlockInfo</argument>
<argument name="valueHandlerPool"
xsi:type="object">CoinsValueHandlerPool</argument>
<argument name="validatorPool" xsi:type="object">CoinsValidatorPool</argument>
</arguments>
</virtualType>
<virtualType name="CoinsValueHandlerPool"
type="MagentoPaymentGatewayConfigValueHandlerPool">
<arguments>
<argument name="handlers" xsi:type="array">
<item name="default" xsi:type="string">CoinsConfigValueHandler</item>
</argument>
</arguments>
</virtualType>
<virtualType name="CoinsConfigValueHandler"
type="MagentoPaymentGatewayConfigConfigValueHandler">
<arguments>
<argument name="configInterface" xsi:type="object">CoinsConfig</argument>
</arguments>
</virtualType>
<virtualType name="CoinsConfig" type="MagentoPaymentGatewayConfigConfig">
<arguments>
<argument name="methodCode" xsi:type="string">coins</argument>
</arguments>
</virtualType>
<virtualType name="CoinsValidatorPool"
type="MagentoPaymentGatewayValidatorValidatorPool">
<arguments>
<argument name="validators" xsi:type="array">
<!-- no validation -->
</argument>
</arguments>
</virtualType>
</config>
frontand/di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCheckoutModelCompositeConfigProvider">
<arguments>
<argument name="configProviders" xsi:type="array">
<item name="pay_later_payment_config_provider"
xsi:type="object">SegaChristmasCoinsModelConfigSettings</item>
</argument>
</arguments>
</type>
</config>
Model/Config/Settings.php
<?php
namespace SegaChristmasCoinsModelConfig;
use MagentoCheckoutModelConfigProviderInterface;
use MagentoCustomerModelSession;
use MagentoCustomerModelSessionFactory;
use MagentoFrameworkAppConfigScopeConfigInterface;
use MagentoFrameworkExceptionNoSuchEntityException;
use MagentoStoreModelScopeInterface;
use MagentoStoreModelStoreManagerInterface;
class Settings implements ConfigProviderInterface
{
const CODE = 'coins';
const CHECKOUT_CONFIG_CODE = 'coins';
/**
* @var ScopeConfigInterface
*/
protected $scopeConfig;
/**
* @var StoreManagerInterface
*/
protected $storeManager;
/**
* @var SessionFactory
*/
private $sessionFactory;
/**
* Settings constructor.
* @param ScopeConfigInterface $scopeConfig
* @param StoreManagerInterface $storeManager
* @param SessionFactory $sessionFactory
*/
public function __construct(
ScopeConfigInterface $scopeConfig,
StoreManagerInterface $storeManager,
SessionFactory $sessionFactory
) {
$this->scopeConfig = $scopeConfig;
$this->storeManager = $storeManager;
$this->sessionFactory = $sessionFactory;
}
/**
* @param $paymentMethodCode
* @return bool
*/
public function getEnabledForStores()
{
$xmlConfigPath = "payment/" . self::CODE . "/active";
try {
$storeCode = $this->storeManager->getStore()->getCode();
} catch (NoSuchEntityException $e) {
return false;
}
return (bool)$this->scopeConfig->getValue($xmlConfigPath,
ScopeInterface::SCOPE_STORE, $storeCode);
}
/**
* @return string
* @throws NoSuchEntityException
*/
public function getCurrentStoreCode()
{
return $this->storeManager->getStore()->getCode();
}
/**
* @param $xmlPath
* @return mixed
*/
protected function getValue($xmlPath)
{
return $this->scopeConfig->getValue($xmlPath,
ScopeInterface::SCOPE_STORE);
}
/**
* @return string
*/
public function getLogo()
{
return '';
}
/**
* @inheritDoc
* @return array
*/
public function getConfig()
{
/**
* @var Session $customer
*/
$customer = $this->sessionFactory->create();
return [
'payment' => [
self::CHECKOUT_CONFIG_CODE => [
'enable' => $this->getEnabledForStores() &&
$customer->getCustomerId(),
'logo' => $this->getLogo()
]
]
];
}
}
system.xml
<section id="payment">
<group id="coins" translate="label" sortOrder="100" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Coins Payment Method</label>
<field id="active" translate="label" sortOrder="10" type="select"
showInDefault="1" showInWebsite="1"
showInStore="1">
<label>Enable</label>
<source_model>MagentoConfigModelConfigSourceYesno</source_model>
</field>
<field id="title" translate="label" type="text" sortOrder="20"
showInDefault="1" showInWebsite="1" showInStore="1">
<label>Reward Points</label>
</field>
</group>
</section>
view/frontend/layout/checkout_index_index.xml
<?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="coins"
xsi:type="array">
<item name="component"
xsi:type="string">
Sega_ChristmasCoins/js/view/payment/method-renderer</item>
<item name="methods"
xsi:type="array">
<item name="coins"
xsi:type="array">
<item
name="isBillingAddressRequired"
xsi:type="boolean">false</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</argument>
</arguments>
</referenceBlock>
</body>
</page>
view/frontend/web/js/view/payment/method-renderer.js
define(
[
'uiComponent',
'Magento_Checkout/js/model/payment/renderer-list'
],
function (Component, rendererList) {
'use strict';
const isEnabled =
window.checkoutConfig.payment.paylater.enable;
if (isEnabled){
rendererList.push(
{
type: 'coins',
component:'Sega_ChristmasCoins/js/view/payment/method-renderer/coins-method'
}
);
}
return Component.extend({});
}
);
view/frontend/web/js/view/payment/method-renderer/coins-method.js
define(
[
'ko',
'Magento_Checkout/js/view/payment/default',
'Magento_Customer/js/model/customer',
'mage/translate'
],
function (
ko,
Component,
customer,
$t
) {
'use strict';
return Component.extend({
defaults: {
template: 'Sega_ChristmasCoins/payment/coins'
},
currentCoins: ko.observable(0),
initialize: function () {
this._super();
if (customer.isLoggedIn() && customer.customerData.custom_attributes) {
this.currentCoins
(Math.round(customer.customerData.custom_attributes.coins.value * 100) / 100);
}
this.currentCoinsMsg = ko.computed(() => {
return $t('You have ') + this.currentCoins() + $t(' coins.');
});
}
});
}
);
view/frontend/web/template/payment/coins.phtml
<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 data-bind="text: currentCoins"></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>