Skip to content

Initial commit #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Block/Adminhtml/System/Config/Field/AbstractCallbackUrl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace CheckoutCom\Magento2\Block\Adminhtml\System\Config\Field;

use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\Data\Form\Element\AbstractElement;

abstract class AbstractCallbackUrl extends Field {

/**
* Overridden method for rendering a field. In this case the field must be only for read.
*
* @param AbstractElement $element
* @return string
*/
protected function _getElementHtml(AbstractElement $element) {
$callbackUrl= $this->getBaseUrl() . 'checkout_com/' . $this->getControllerUrl();

$element->setData('value', $callbackUrl);
$element->setReadonly('readonly');

return $element->getElementHtml();
}

/**
* Returns the controller url.
*
* @return string
*/
public abstract function getControllerUrl();

}
16 changes: 16 additions & 0 deletions Block/Adminhtml/System/Config/Field/RedirectionFailUrl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace CheckoutCom\Magento2\Block\Adminhtml\System\Config\Field;

class RedirectionFailUrl extends AbstractCallbackUrl {

/**
* Returns the controller url.
*
* @return string
*/
public function getControllerUrl() {
return 'payment/verify';
}

}
16 changes: 16 additions & 0 deletions Block/Adminhtml/System/Config/Field/RedirectionUrl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace CheckoutCom\Magento2\Block\Adminhtml\System\Config\Field;

class RedirectionUrl extends AbstractCallbackUrl {

/**
* Returns the controller url.
*
* @return string
*/
public function getControllerUrl() {
return 'payment/verify';
}

}
16 changes: 16 additions & 0 deletions Block/Adminhtml/System/Config/Field/WebhookUrl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace CheckoutCom\Magento2\Block\Adminhtml\System\Config\Field;

class WebhookUrl extends AbstractCallbackUrl {

/**
* Returns the controller url.
*
* @return string
*/
public function getControllerUrl() {
return 'webhook/callback';
}

}
25 changes: 25 additions & 0 deletions Block/Adminhtml/System/Config/Fieldset/Logo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace CheckoutCom\Magento2\Block\Adminhtml\System\Config\Fieldset;

use Magento\Backend\Block\Template;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Magento\Framework\Data\Form\Element\Renderer\RendererInterface;

class Logo extends Template implements RendererInterface {

/**
* Renders form element as HTML
*
* @param AbstractElement $element
* @return string
*/
public function render(AbstractElement $element) {
$pattern = '<div id="checkout_com_adminhtml_logo"><a href="%s" target="_blank"><img src="%s" alt="Checkout.com Logo"></a></div>';
$url = 'https://checkout.com';
$src = $this->getViewFileUrl('CheckoutCom_Magento2::images/checkout_com_logo.png', ['area' => 'adminhtml']);

return sprintf($pattern, $url, $src);
}

}
113 changes: 113 additions & 0 deletions Block/Cards/Form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php

namespace CheckoutCom\Magento2\Block\Cards;

use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use CheckoutCom\Magento2\Gateway\Config\Config as GatewayConfig;
use Magento\Customer\Model\Session;
use Magento\Payment\Model\CcConfig;

class Form extends Template {

/**
* @var GatewayConfig
*/
protected $gatewayConfig;

/**
*
* @var CcConfig
*/
protected $ccConfig;

/**
* @var Session
*/
protected $session;

/**
* Form constructor.
* @param GatewayConfig $gatewayConfig
* @param CcConfig $ccConfig
* @param Session $session
* @param Context $context
* @param array $data
*/
public function __construct(GatewayConfig $gatewayConfig, CcConfig $ccConfig, Session $session, Context $context, array $data = []) {
parent::__construct($context, $data);

$this->gatewayConfig = $gatewayConfig;
$this->ccConfig = $ccConfig;
$this->session = $session;
}

/**
* Returns the customer instance from the session.
*
* @return \Magento\Customer\Model\Customer
*/
public function getCustomer() {
return $this->session->getCustomer();
}

/**
* Returns the gateway config.
*
* @return GatewayConfig
*/
public function getGatewayConfig() {
return $this->gatewayConfig;
}

/**
* Returns the url for the form.
*
* @return string
*/
public function getFormActionUrl() {
return $this->_urlBuilder->getRouteUrl('checkout_com/cards/store');
}

/**
* Returns the HTML img element with CVV image.
*
* @return string
*/
public function getCvvImgHtml() {
return '<img src=' . $this->ccConfig->getCvvImageUrl() . ' />';
}

/**
* Returns the HTML option list with CC years.
*
* @return string
*/
public function getYearsForSelect() {
$options = [];

foreach($this->ccConfig->getCcYears() as $year) {
$options[] = sprintf('<option value="%s">%s</option>', $year, $year);
}

return implode('', $options);
}

/**
* Returns the HTML option list with CC months.
*
* @return string
*/
public function getMonthsForSelect() {
$options = [];

foreach($this->ccConfig->getCcMonths() as $key => $month) {
$key = str_pad($key, 2, '0', STR_PAD_LEFT);

$options[] = sprintf('<option value="%s">%s</option>', $key, $month);
}

return implode('', $options);
}

}
96 changes: 96 additions & 0 deletions Block/Customer/CardRenderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

namespace CheckoutCom\Magento2\Block\Customer;

use Magento\Payment\Model\CcConfigProvider;
use CheckoutCom\Magento2\Model\Ui\ConfigProvider;
use Magento\Framework\View\Element\Template;
use Magento\Vault\Api\Data\PaymentTokenInterface;
use Magento\Vault\Block\AbstractCardRenderer;
use CheckoutCom\Magento2\Gateway\Config\Config as GatewayConfig;

class CardRenderer extends AbstractCardRenderer {

/**
* @var GatewayConfig
*/
protected $gatewayConfig;

/**
* CardRenderer constructor.
* @param Template\Context $context
* @param CcConfigProvider $iconsProvider
* @param GatewayConfig $gatewayConfig
* @param array $data
*/
public function __construct(Template\Context $context, CcConfigProvider $iconsProvider, GatewayConfig $gatewayConfig, array $data) {
parent::__construct($context, $iconsProvider, $data);

$this->gatewayConfig = $gatewayConfig;
}

/**
* Returns 4 last digits from the credit card number.
*
* @return string
*/
public function getNumberLast4Digits() {
return $this->getTokenDetails()['maskedCC'];
}

/**
* Returns the credit card expiration date.
*
* @return string
*/
public function getExpDate() {
return $this->getTokenDetails()['expirationDate'];
}

/**
* Returns the url to the CC icon.
*
* @return string
*/
public function getIconUrl() {
return $this->getIconForType($this->getCartType())['url'];
}

/**
* Returns the icon height in pixels.
*
* @return int
*/
public function getIconHeight() {
return $this->getIconForType($this->getCartType())['height'];
}

/**
* Returns the icon width in pixels.
*
* @return int
*/
public function getIconWidth() {
return $this->getIconForType($this->getCartType())['width'];
}

/**
* Determines if can render the given token.
*
* @param PaymentTokenInterface $token
* @return boolean
*/
public function canRender(PaymentTokenInterface $token) {
return $token->getPaymentMethodCode() === ConfigProvider::CODE;
}

/**
* Returns the credit card type.
*
* @return string
*/
private function getCartType() {
return $this->getTokenDetails()['type'];
}

}
Loading