Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
yosmared committed May 21, 2023
0 parents commit 8c1114a
Show file tree
Hide file tree
Showing 19 changed files with 1,108 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Block/Form/AbstractInstruction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace SarrapiaTech\Zinli\Block\Form;

/**
* Abstract class for Cash On Delivery and Bank Transfer payment method form
*/
abstract class AbstractInstruction extends \Magento\Payment\Block\Form
{
/**
* Instructions text
*
* @var string
*/
protected $_instructions;

/**
* Get instructions text from config
*
* @return null|string
*/
public function getInstructions()
{
if ($this->_instructions === null) {
/** @var \Magento\Payment\Model\Method\AbstractMethod $method */
$method = $this->getMethod();
$this->_instructions = $method->getConfigData('instructions');
}
return $this->_instructions;
}
}
19 changes: 19 additions & 0 deletions Block/Form/Zinli.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace SarrapiaTech\Zinli\Block\Form;

/**
* Block for Bank Transfer payment method form
*/
class Zinli extends SarrapiaTech\Zinli\Block\Form\AbstractInstruction
{
/**
* Bank transfer template
*
* @var string
*/
protected $_template = 'SarrapiaTech_Zinli::form/zinli.phtml';
}
17 changes: 17 additions & 0 deletions COPYING.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Copyright © 2023-present 2023

This file is part of SarrapiaTech/Zinli.

SarrapiaTech/Zinli is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Please see LICENSE.txt for the full text of GNU General Public License
619 changes: 619 additions & 0 deletions LICENSE.txt

Large diffs are not rendered by default.

69 changes: 69 additions & 0 deletions Model/Payment/InstructionsConfigProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace SarrapiaTech\Zinli\Model\Payment;

use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Framework\Escaper;
use Magento\Payment\Helper\Data as PaymentHelper;

class InstructionsConfigProvider implements ConfigProviderInterface
{
/**
* @var string[]
*/
protected $methodCodes = [
Zinli::PAYMENT_METHOD_ZINLI_CODE,
];

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

/**
* @var Escaper
*/
protected $escaper;

/**
* @param PaymentHelper $paymentHelper
* @param Escaper $escaper
*/
public function __construct(
PaymentHelper $paymentHelper,
Escaper $escaper
) {
$this->escaper = $escaper;
foreach ($this->methodCodes as $code) {
$this->methods[$code] = $paymentHelper->getMethodInstance($code);
}
}

/**
* {@inheritdoc}
*/
public function getConfig()
{
$config = [];
foreach ($this->methodCodes as $code) {
if ($this->methods[$code]->isAvailable()) {
$config['payment']['instructions'][$code] = $this->getInstructions($code);
}
}
return $config;
}

/**
* Get instructions text from config
*
* @param string $code
* @return string
*/
protected function getInstructions($code)
{
return nl2br($this->escaper->escapeHtml($this->methods[$code]->getInstructions()));
}
}
30 changes: 30 additions & 0 deletions Model/Payment/Zinli.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Copyright © 2023 All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace SarrapiaTech\Zinli\Model\Payment;

class Zinli extends \Magento\Payment\Model\Method\AbstractMethod
{

const PAYMENT_METHOD_ZINLI_CODE = 'zinli';
protected $_code = self::PAYMENT_METHOD_ZINLI_CODE;
protected $_isOffline = true;

protected $_formBlockType = SarrapiaTech\Zinli\Block\Form\Zinli::class;

public function isAvailable(
\Magento\Quote\Api\Data\CartInterface $quote = null
) {
return parent::isAvailable($quote);
}

public function getInstructions()
{
return trim($this->getConfigData('instructions'));
}
}

52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Module Offline Payment SarrapiaTech Zinli

``sarrapiatech/module-zinli``

- [Main Functionalities](#markdown-header-main-functionalities)
- [Installation](#markdown-header-installation)
- [Configuration](#markdown-header-configuration)
- [Specifications](#markdown-header-specifications)
- [Attributes](#markdown-header-attributes)


## Main Functionalities
Zinli Gateway Payment

## Installation
\* = in production please use the `--keep-generated` option

### Type 1: Zip file

- Unzip the zip file in `app/code/SarrapiaTech`
- Enable the module by running `php bin/magento module:enable SarrapiaTech_Zinli`
- Apply database updates by running `php bin/magento setup:upgrade`\*
- Flush the cache by running `php bin/magento cache:flush`

### Type 2: Composer

- Make the module available in a composer repository for example:
- private repository `repo.magento.com`
- public repository `packagist.org`
- public github repository as vcs
- Add the composer repository to the configuration by running `composer config repositories.repo.magento.com composer https://repo.magento.com/`
- Install the module composer by running `composer require sarrapiatech/module-zinli`
- enable the module by running `php bin/magento module:enable SarrapiaTech_Zinli`
- apply database updates by running `php bin/magento setup:upgrade`\*
- Flush the cache by running `php bin/magento cache:flush`


## Configuration

- Zinli - payment/zinli/*


## Specifications

- Payment Method
- Zinli


## Attributes



22 changes: 22 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "sarrapiatech/module-zinli",
"description": "Zinli Gateway Payment",
"type": "magento2-module",
"license": "MIT",
"authors": [
{
"name": "Yosmar Ramirez",
"email": "[email protected]"
}
],
"minimum-stability": "stable",
"require": {},
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"SarrapiaTech\\Zinli\\": ""
}
}
}
36 changes: 36 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?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" sortOrder="1000" showInWebsite="1" showInStore="1" showInDefault="1" translate="label">
<group id="zinli" sortOrder="10" showInWebsite="1" showInStore="1" showInDefault="1" translate="label">
<label>Zinli</label>
<field id="active" type="select" sortOrder="10" showInWebsite="1" showInStore="1" showInDefault="1" translate="label">
<label>Enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="title" type="text" sortOrder="20" showInWebsite="1" showInStore="1" showInDefault="1" translate="label">
<label>Title</label>
</field>
<field id="order_status" type="select" sortOrder="30" showInWebsite="1" showInStore="1" showInDefault="1" translate="label">
<label>New Order Status</label>
<source_model>Magento\Sales\Model\Config\Source\Order\Status\NewStatus</source_model>
</field>
<field id="allowspecific" type="allowspecific" sortOrder="40" showInWebsite="1" showInStore="1" showInDefault="1" translate="label">
<label>Payment from Applicable Countries</label>
<source_model>Magento\Payment\Model\Config\Source\Allspecificcountries</source_model>
</field>
<field id="specificcountry" type="multiselect" sortOrder="50" showInWebsite="1" showInStore="1" showInDefault="1" translate="label">
<label>Payment from Applicable Countries</label>
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
<can_be_empty>1</can_be_empty>
</field>
<field id="sort_order" type="text" sortOrder="60" showInWebsite="1" showInStore="1" showInDefault="1" translate="label">
<label>Sort Order</label>
</field>
<field id="instructions" type="textarea" sortOrder="70" showInWebsite="1" showInStore="1" showInDefault="1" translate="label">
<label>Instructions</label>
</field>
</group>
</section>
</system>
</config>
15 changes: 15 additions & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?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>
<zinli>
<active>0</active>
<model>SarrapiaTech\Zinli\Model\Payment\Zinli</model>
<order_status>pending</order_status>
<title>Zinli</title>
<allowspecific>0</allowspecific>
<group>offline</group>
</zinli>
</payment>
</default>
</config>
17 changes: 17 additions & 0 deletions etc/frontend/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<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="zinli_payment_instructions_config_provider" xsi:type="object">SarrapiaTech\Zinli\Model\Payment\InstructionsConfigProvider</item>

</argument>
</arguments>
</type>
</config>
4 changes: 4 additions & 0 deletions etc/module.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?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="SarrapiaTech_Zinli"/>
</config>
13 changes: 13 additions & 0 deletions etc/payment.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?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>Offline Payment Methods</label>
</group>
</groups>
<methods>
<method name="zinli">
<allow_multiple_address>1</allow_multiple_address>
</method>
</methods>
</payment>
9 changes: 9 additions & 0 deletions registration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
/**
* Copyright © 2023 All rights reserved.
* See COPYING.txt for license details.
*/
use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::MODULE, 'SarrapiaTech_Zinli', __DIR__);

41 changes: 41 additions & 0 deletions view/frontend/layout/checkout_index_index.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" ?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" 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="zinli" xsi:type="array">
<item name="component" xsi:type="string">SarrapiaTech_Zinli/js/view/payment/zinli</item>
<item name="methods" xsi:type="array">
<item name="zinli" 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>
Loading

0 comments on commit 8c1114a

Please sign in to comment.