Commit ea2d4f27 by liumengfei

增加Oceanpayment模块

parent c8bbb3e8
<?php
/**
* Copyright © 2016 Oceanpayment Design. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Oceanpayment\Creditcard\Block;
class Form extends \Magento\Payment\Block\Form
{
/**
* Checkmo template
*
* @var string
*/
protected $_supportedInfoLocales = array('fr');
protected $_defaultInfoLocale = 'en';
protected $_template = 'Oceanpayment_Creditcard::form.phtml';
}
<?php
/**
* Copyright © 2016 Oceanpayment Design. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Oceanpayment\Creditcard\Block;
class Info extends \Magento\Payment\Block\Info
{
/**
* @var string
*/
protected $_payableTo;
/**
* @var string
*/
protected $_mailingAddress;
/**
* @var string
*/
protected $_template = 'Oceanpayment_Creditcard::info.phtml';
public function getMethodCode()
{
return $this->getInfo()->getMethodInstance()->getCode();
}
/**
* @return string
*/
public function toPdf()
{
//$this->setTemplate('Oceanpayment_Creditcard::info/pdf/checkmo.phtml');
$this->setTemplate('Oceanpayment_Creditcard::pdf/info.phtml');
return $this->toHtml();
}
}
<?php
/**
* ######
* ######
* ########### ########### ########### ########### ########### ############ ########### ###### ###### ########### ########### ########### #############
* ############# ############# ############# ############# ############# ############# ############# ###### ###### ############# ############# ############# #############
* ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### #### ### #### ###### ###### ###### ###### #############
* ###### ###### ###### ############# ############# ###### ###### ###### ###### ############# ###### ###### #### ### #### ############# ###### ###### ######
* ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### #### ### #### ###### ###### ###### ######
* ############# ############# ############# ############# ###### ###### ############# ############# ############# #### ### #### ############# ###### ###### ##########
* ########### ########### ########### ########### ###### ###### ############ ########### ############# #### ### #### ########### ###### ###### ##########
* ###### ######
* ###### #############
* ###### ############
*
*
*
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Oceanpayment\Creditcard\Block\Payment;
class Redirect extends \Magento\Framework\View\Element\Template
{
/**
* @var \Magento\Checkout\Model\Session
*/
protected $_checkoutSession;
protected $_paymentMethod;
/**
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Checkout\Model\Session $checkoutSession
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Oceanpayment\Creditcard\Model\PaymentMethod $paymentMethod,
\Magento\Checkout\Model\Session $checkoutSession,
array $data = []
) {
$this->_checkoutSession = $checkoutSession;
parent::__construct($context, $data);
$this->_paymentMethod = $paymentMethod;
$this->_isScopePrivate = true;
}
public function getCheckoutForm(){
$parameter = $this->_paymentMethod->getCheckoutParameter();
$gatewayUrl = $this->_paymentMethod->getGatewayUrl();
$formHTML = '';
$formHTML .= '<form action="'.$gatewayUrl.'" name="payment_checkout" id="payment_checkout">';
foreach ($parameter as $field => $value) {
$formHTML .= '<input type="hidden" name="'.$field.'" value="'.$value.'" >';
}
$formHTML .= '</form>';
return $formHTML;
}
public function getPayMode(){
return $this->_paymentMethod->getConfigData('pay_mode');
}
}
<?php
namespace Oceanpayment\Creditcard\Controller\Payment;
use Magento\Framework\Controller\ResultFactory;
use Magento\Customer\Api\Data\GroupInterface;
class Redirect extends \Magento\Framework\App\Action\Action
{
/**
* Customer session model
*
* @var \Magento\Customer\Model\Session
*/
protected $_customerSession;
protected $resultPageFactory;
protected $_paymentMethod;
protected $_checkoutSession;
protected $checkout;
/**
* @param \Magento\Framework\App\Action\Context $context
* @param \Magento\Customer\Model\Session $customerSession
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Customer\Model\Session $customerSession,
\Oceanpayment\Creditcard\Model\PaymentMethod $paymentMethod,
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Framework\View\Result\PageFactory $resultPageFactory
) {
$this->_customerSession = $customerSession;
$this->resultPageFactory = $resultPageFactory;
parent::__construct($context);
$this->_paymentMethod = $paymentMethod;
$this->_checkoutSession = $checkoutSession;
}
public function execute()
{
$resultPage = $this->resultPageFactory->create();
$resultPage->getConfig()->getTitle()->set(__('Credit/Debit Card'));
return $resultPage;
}
}
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Oceanpayment\Creditcard\Model;
use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Framework\Locale\ResolverInterface;
use Magento\Customer\Helper\Session\CurrentCustomer;
use Magento\Payment\Helper\Data as PaymentHelper;
class CreditcardConfigProvider implements ConfigProviderInterface
{
/**
* @var ResolverInterface
*/
protected $localeResolver;
/**
* @var Config
*/
protected $config;
/**
* @var \Magento\Customer\Helper\Session\CurrentCustomer
*/
protected $currentCustomer;
/**
* @var string[]
*/
/*protected $methodCodes = [
Config::METHOD_WPP_BML,
Config::METHOD_WPP_PE_EXPRESS,
Config::METHOD_WPP_EXPRESS,
Config::METHOD_WPP_PE_BML
];*/
/**
* @var \Magento\Payment\Model\Method\AbstractMethod[]
*/
protected $methods = [];
/**
* @var PaymentHelper
*/
protected $paymentHelper;
protected $checkoutSession;
/**
* @param ConfigFactory $configFactory
* @param ResolverInterface $localeResolver
* @param CurrentCustomer $currentCustomer
* @param PaymentHelper $paymentHelper
*/
public function __construct(
//ConfigFactory $configFactory,
ResolverInterface $localeResolver,
CurrentCustomer $currentCustomer,
\Magento\Checkout\Model\Session $checkoutSession,
PaymentHelper $paymentHelper
) {
$this->localeResolver = $localeResolver;
//$this->config = $configFactory->create();
$this->currentCustomer = $currentCustomer;
$this->paymentHelper = $paymentHelper;
$this->checkoutSession = $checkoutSession;
$code = 'oceanpaymentcreditcard';
$this->methods[$code] = $this->paymentHelper->getMethodInstance($code);
}
/**
* {@inheritdoc}
*/
public function getConfig()
{
$code = 'oceanpaymentcreditcard';
$config = [];
if ($this->methods[$code]->isAvailable($this->checkoutSession->getQuote())) {
$config = [];
$config['payment'] = [];
$config['payment']['creditcard']['redirectUrl'] = [];
$config['payment']['creditcard']['redirectUrl'][$code] = $this->getMethodRedirectUrl($code);
}
return $config;
}
/**
* Return redirect URL for method
*
* @param string $code
* @return mixed
*/
protected function getMethodRedirectUrl($code)
{
return $this->methods[$code]->getOrderPlaceRedirectUrl();
}
}
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Oceanpayment\Creditcard\Model\Source;
use Magento\Framework\Option\ArrayInterface;
class OtherCurrency implements ArrayInterface {
/**
* @return array
*/
public function toOptionArray() {
return [
['value' => '1', 'label' => __('3D Secure')],
['value' => '0', 'label' =>__('Sale')]
];
}
}
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Oceanpayment\Creditcard\Model\Source;
use Magento\Framework\Option\ArrayInterface;
class PayMode implements ArrayInterface {
/**
* @return array
*/
public function toOptionArray() {
return [
['value' => 'iframe', 'label' => __('Iframe')],
['value' => 'redirect', 'label' =>__('Redirect')]
];
}
}
#Oceanpayment Creditcard
Installation
1 - unzip de module in app/code/Oceanpayment/Creditcard
2 - enable module: bin/magento module:enable --clear-static-content Oceanpayment_Creditcard
3 - upgrade database: bin/magento setup:upgrade
4 - re-run compile command: bin/magento setup:di:compile
In order to deactivate the module bin/magento module:disable --clear-static-content Oceanpayment_Creditcard
In order to update static files: bin/magento setup:static-content:deploy
Important: make sure that php path is correct in bin/magento file
{
"name": "oceanpayment/module-creditcard",
"description": "Accept payments using Oceanpayment Creditcard payment gateway",
"type": "magento2-module",
"version": "2.0.2",
"license": [
"OSL-3.0",
"AFL-3.0"
],
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Oceanpayment\\Creditcard\\": ""
}
}
}
<?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="oceanpaymentcreditcard" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Oceanpayment Debit/Credit Card</label>
<field id="active" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="title" translate="label" type="text" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Title</label>
</field>
<field id="account" translate="label" type="text" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Account</label>
<can_be_empty>0</can_be_empty>
</field>
<field id="terminal" translate="label" type="text" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Terminal</label>
<can_be_empty>0</can_be_empty>
</field>
<field id="securecode" translate="label" type="text" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="0">
<label>SecureCode</label>
<can_be_empty>0</can_be_empty>
</field>
<field id="gateway_url" translate="label" type="text" sortOrder="7" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Gateway URL</label>
</field>
<field id="pay_mode" translate="label" type="select" sortOrder="8" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Pay Mode</label>
<source_model>Oceanpayment\Creditcard\Model\Source\PayMode</source_model>
</field>
<field id="new_order_status" translate="label" type="select" sortOrder="9" showInDefault="1" showInWebsite="1" showInStore="0">
<label>New Order Status</label>
<source_model>Magento\Sales\Model\Config\Source\Order\Status</source_model>
</field>
<field id="success_order_status" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Approved Order Status</label>
<source_model>Magento\Sales\Model\Config\Source\Order\Status</source_model>
</field>
<field id="failure_order_status" translate="label" type="select" sortOrder="11" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Failure Order Status</label>
<source_model>Magento\Sales\Model\Config\Source\Order\Status</source_model>
</field>
<field id="high_risk_order_status" translate="label" type="select" sortOrder="12" showInDefault="1" showInWebsite="1" showInStore="0">
<label>High Risk Order Status</label>
<source_model>Magento\Sales\Model\Config\Source\Order\Status</source_model>
</field>
<field id="pre_auth_order_status" translate="label" type="select" sortOrder="13" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Pre-auth Order Status</label>
<source_model>Magento\Sales\Model\Config\Source\Order\Status</source_model>
</field>
<field id="invoice" translate="label" type="select" sortOrder="14" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Invoice When Complete</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="allowspecific" translate="label" type="allowspecific" sortOrder="14" showInDefault="1" showInWebsite="1" showInStore="0">
<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="16" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Payment from Specific Countries</label>
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
</field>
<field id="sort_order" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Sort Order</label>
</field>
<include path="Oceanpayment_Creditcard::system/secure_mode.xml"/>
</group>
</section>
</system>
</config>
\ No newline at end of file
<?xml version="1.0"?>
<include xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_include.xsd">
<group id="secure" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
<label>3D Secure Mode</label>
<frontend_model>Magento\Config\Block\System\Config\Form\Fieldset</frontend_model>
<field id="secure_mode" translate="label" sortOrder="1" type="select" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="secure_terminal" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="0">
<label>3D Secure Terminal</label>
<can_be_empty>0</can_be_empty>
</field>
<field id="secure_securecode" translate="label" type="text" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="0">
<label>3D Secure SecureCode</label>
<can_be_empty>0</can_be_empty>
</field>
<field id="secure_currency" translate="label" type="text" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="0">
<label>3D Secure Currency</label>
<can_be_empty>0</can_be_empty>
</field>
<field id="secure_amount" translate="label" type="text" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="0">
<label>3D Secure Amount</label>
<can_be_empty>0</can_be_empty>
</field>
<field id="secure_other_currency" translate="label" type="select" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Other Currency</label>
<source_model>Oceanpayment\Creditcard\Model\Source\OtherCurrency</source_model>
</field>
<field id="secure_country" translate="label" type="multiselect" sortOrder="7" showInDefault="1" showInWebsite="1" showInStore="0">
<label>3D Secure Countries</label>
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
</field>
</group>
</include>
\ No newline at end of file
<?xml version="1.0"?>
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<payment>
<oceanpaymentcreditcard>
<title>Debit/Credit Card</title>
<model>Oceanpayment\Creditcard\Model\PaymentMethod</model>
<active>0</active>
<new_order_status>pending</new_order_status>
<success_order_status>processing</success_order_status>
<failure_order_status>canceled</failure_order_status>
<pre_auth_order_status>processing</pre_auth_order_status>
<invoice>0</invoice>
<sort_order>0</sort_order>
<allowspecific>0</allowspecific>
</oceanpaymentcreditcard>
</payment>
</default>
</config>
<?xml version="1.0"?>
<!--
/**
* Copyright © 2015 Magento. 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="creditcard_config_provider" xsi:type="object">Oceanpayment\Creditcard\Model\CreditcardConfigProvider</item>
</argument>
</arguments>
</type>
</config>
<?xml version="1.0"?>
<!--
/**
* Copyright © 2016 Oceanpayment Design. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
<route id="oceanpaymentcreditcard" frontName="oceanpaymentcreditcard">
<module name="Oceanpayment_Creditcard" />
</route>
</router>
</config>
<?xml version="1.0"?>
<!--
/**
* Copyright © 2016 Oceanpayment Design All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Oceanpayment_Creditcard" active="true" schema_version="2.0.2" setup_version="2.0.2">
<sequence>
<module name="Magento_Store"/>
<module name="Magento_Catalog"/>
</sequence>
</module>
</config>
*************************************
\ No newline at end of file
<?php
/**
* Copyright © 2016 Oceanpayment Design. All rights reserved.
* See COPYING.txt for license details.
*/
use \Magento\Framework\Component\ComponentRegistrar;
\Magento\Framework\Component\ComponentRegistrar::register(
ComponentRegistrar::MODULE,
'Oceanpayment_Creditcard',
__DIR__
);
<?php
/**
* Copyright © 2016 Oceanpayment Design. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile
/**
* @var $block \Oceanpayment\Creditcard\Block\Info
*/
?>
<?php echo $block->escapeHtml($block->getMethod()->getTitle()) ?>
<?php if ($block->getInfo()->getLastTransId() == ''): ?>
<br /><?php echo __('No transaction ID recorded.') ?>
<?php else: ?>
<br /><?php echo __('CreditCard Transaction ID: %1', $this->escapeHtml($block->getInfo()->getLastTransId())) ?>
<?php endif; ?>
<?php
/**
* Copyright © 2016 Oceanpayment Design. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile
/**
* @var $block \Oceanpayment\Creditcard\Block\Info
*/
?>
<?php echo $this->escapeHtml($block->getMethod()->getTitle()) ?>
{{pdf_row_separator}}
<?php echo __('CreditCard Transaction ID: %1', $this->escapeHtml($block->getInfo()->getLastTransId())) ?>
{{pdf_row_separator}}
<?xml version="1.0"?>
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<css src="Oceanpayment_Creditcard::css/styles.css"/>
</head>
<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">
<!-- merge payment method renders here -->
<item name="children" xsi:type="array">
<item name="creditcard-payments" xsi:type="array">
<item name="component" xsi:type="string">Oceanpayment_Creditcard/js/view/payment/creditcard-method</item>
<item name="methods" xsi:type="array">
<item name="oceanpaymentcreditcard" 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>
\ No newline at end of file
<?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" layout="1column">
<body>
<referenceContainer name="content">
<block class="Oceanpayment\Creditcard\Block\Payment\Redirect" name="creditcard.redirect" template="payment/redirect.phtml" cacheable="false"/>
</referenceContainer>
</body>
</page>
\ No newline at end of file
<?php
/**
* Copyright © 2016 Oceanpayment Design. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile
/**
* @var $block \Oceanpayment\Creditcard\Block\Form
*/
?>
<?php $methodCode = $block->escapeHtml($block->getMethodCode());?>
<div class="items <?php /* @noEscape */ echo $methodCode ?> instructions agreement checkout-agreement-item-content" id="payment_form_<?php /* @noEscape */ echo $methodCode ?>" style="display: none;">
<?php /* @noEscape */ echo nl2br($block->escapeHtml($instructions)) ?>
<div style="padding:10px 15px 15px;">
<img src="<?php $block->escapeUrl($block->getViewFileUrl('Oceanpayment_Creditcard::icon_accepted_cards_creditcard.gif'));?>" alt="<?php echo __('Payment by visa or mastercard'); ?>"><br>
</div>
</div>
\ No newline at end of file
<?php
/**
* Copyright © 2016 Oceanpayment Design. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile
/**
* @var $block \Oceanpayment\Creditcard\Block\Info
*/
?>
<dl class="payment-method oceanpaymentcreditcard">
<dt class="title"><?php echo $block->escapeHtml($block->getMethod()->getTitle()) ?></dt>
<dd class="content">
<strong><?php echo $block->escapeHtml(__('You will be redirected to our secure payment page when you place an order.')) ?></strong>
</dd>
</dl>
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
?>
<div id="checkout-loader" data-role="checkout-loader" class="loading-mask" data-mage-init='{"checkoutLoader": {}}'>
<div class="loader">
<img src="<?php echo $block->getViewFileUrl('images/loader-1.gif'); ?>"
alt="<?php echo __('Loading...'); ?>"
style="position: absolute;">
</div>
</div>
<div>
<?php echo $block->getCheckoutForm(); ?>
<?php if($block->getPayMode() == 'iframe'){?>
<iframe width="100%" height="800px" scrolling="auto" name="iframe_checkout" id="iframe_checkout" style="border:none; margin: 0 auto; overflow:auto;"></iframe>
<script type="text/javascript">
if (window.XMLHttpRequest) {
document.payment_checkout.target="iframe_checkout";
}
document.payment_checkout.submit();
</script>
<?php }elseif($block->getPayMode() == 'redirect'){?>
<p style="font: 16px; padding: 0px; text-align: center; margin: 100px auto 0px; width: 90%;"><?php echo __('Processing, please do not click the refresh button.'); ?></p>
<script type="text/javascript">
document.payment_checkout.submit();
</script>
<?php } ?>
</div>
\ No newline at end of file
.payment-method div.payment_logo_oceanpaymentcreditcard {
background:url(../images/payment_logo.png) no-repeat;
}
/**
* Copyright © 2016 Oceanpayment Design. All rights reserved.
* See COPYING.txt for license details.
*/
define(
[
'jquery',
'Magento_Checkout/js/model/quote',
'Magento_Checkout/js/model/url-builder',
'mage/storage',
'Magento_Checkout/js/model/error-processor',
'Magento_Customer/js/model/customer',
'Magento_Checkout/js/model/full-screen-loader'
],
function ($, quote, urlBuilder, storage, errorProcessor, customer, fullScreenLoader) {
'use strict';
return function (messageContainer) {
var serviceUrl,
payload,
paymentData = quote.paymentMethod();
if (Object.prototype.hasOwnProperty.call(paymentData, '__disableTmpl')) { delete paymentData.__disableTmpl; }
/**
* Checkout for guest and registered customer.
*/
if (!customer.isLoggedIn()) {
serviceUrl = urlBuilder.createUrl('/guest-carts/:cartId/payment-information', {
cartId: quote.getQuoteId()
});
payload = {
cartId: quote.getQuoteId(),
email: quote.guestEmail,
paymentMethod: paymentData,
billingAddress: quote.billingAddress()
};
} else {
serviceUrl = urlBuilder.createUrl('/carts/mine/payment-information', {});
payload = {
cartId: quote.getQuoteId(),
paymentMethod: paymentData,
billingAddress: quote.billingAddress()
};
}
fullScreenLoader.startLoader();
return storage.post(
serviceUrl, JSON.stringify(payload)
).done(
function () {
//$.mage.redirect(window.checkoutConfig.payment.paypalExpress.redirectUrl[quote.paymentMethod().method]);
$.mage.redirect(window.checkoutConfig.payment.creditcard.redirectUrl[quote.paymentMethod().method]);
}
).fail(
function (response) {
errorProcessor.process(response, messageContainer);
fullScreenLoader.stopLoader();
}
);
};
}
);
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
/*browser:true*/
/*global define*/
define(
[
'uiComponent',
'Magento_Checkout/js/model/payment/renderer-list'
],
function (
Component,
rendererList
) {
'use strict';
rendererList.push(
{
type: 'oceanpaymentcreditcard',
component: 'Oceanpayment_Creditcard/js/view/payment/method-renderer/creditcard-method'
}
);
/** Add view logic here if needed */
return Component.extend({});
}
);
\ No newline at end of file
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
/*browser:true*/
/*global define*/
define(
[
'jquery',
'Magento_Checkout/js/view/payment/default',
'Oceanpayment_Creditcard/js/action/set-payment-method',
'Magento_Checkout/js/model/payment/additional-validators'
],
function ($, Component, setPaymentMethodAction) {
'use strict';
return Component.extend({
defaults: {
template: 'Oceanpayment_Creditcard/payment/creditcard'
},
/** Redirect to creditcard */
continueToCreditCard: function () {
//update payment method information if additional data was changed
this.selectPaymentMethod();
setPaymentMethodAction(this.messageContainer);
return false;
}
});
}
);
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<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>
<div alt="Logo" data-bind="attr: {'class': 'payment_logo_' + getCode()}"></div>
</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>
<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-bind="click: continueToCreditCard, enable: (getCode() == isChecked())"
disabled>
<span data-bind="i18n: 'Place Order'"></span>
</button>
</div>
</div>
</div>
</div>
\ No newline at end of file
<?php
/**
* Copyright © 2016 Oceanpayment Design. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Oceanpayment\Klarna\Block;
class Form extends \Magento\Payment\Block\Form
{
/**
* Checkmo template
*
* @var string
*/
protected $_supportedInfoLocales = array('fr');
protected $_defaultInfoLocale = 'en';
protected $_template = 'Oceanpayment_Klarna::form.phtml';
}
<?php
/**
* Copyright © 2016 Oceanpayment Design. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Oceanpayment\Klarna\Block;
class Info extends \Magento\Payment\Block\Info
{
/**
* @var string
*/
protected $_payableTo;
/**
* @var string
*/
protected $_mailingAddress;
/**
* @var string
*/
protected $_template = 'Oceanpayment_Klarna::info.phtml';
public function getMethodCode()
{
return $this->getInfo()->getMethodInstance()->getCode();
}
/**
* @return string
*/
public function toPdf()
{
//$this->setTemplate('Oceanpayment_Klarna::info/pdf/checkmo.phtml');
$this->setTemplate('Oceanpayment_Klarna::pdf/info.phtml');
return $this->toHtml();
}
}
<?php
/**
* ######
* ######
* ########### ########### ########### ########### ########### ############ ########### ###### ###### ########### ########### ########### #############
* ############# ############# ############# ############# ############# ############# ############# ###### ###### ############# ############# ############# #############
* ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### #### ### #### ###### ###### ###### ###### #############
* ###### ###### ###### ############# ############# ###### ###### ###### ###### ############# ###### ###### #### ### #### ############# ###### ###### ######
* ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### #### ### #### ###### ###### ###### ######
* ############# ############# ############# ############# ###### ###### ############# ############# ############# #### ### #### ############# ###### ###### ##########
* ########### ########### ########### ########### ###### ###### ############ ########### ############# #### ### #### ########### ###### ###### ##########
* ###### ######
* ###### #############
* ###### ############
*
*
*
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Oceanpayment\Klarna\Block\Payment;
class Redirect extends \Magento\Framework\View\Element\Template
{
/**
* @var \Magento\Checkout\Model\Session
*/
protected $_checkoutSession;
protected $_paymentMethod;
/**
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Checkout\Model\Session $checkoutSession
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Oceanpayment\Klarna\Model\PaymentMethod $paymentMethod,
\Magento\Checkout\Model\Session $checkoutSession,
array $data = []
) {
$this->_checkoutSession = $checkoutSession;
parent::__construct($context, $data);
$this->_paymentMethod = $paymentMethod;
$this->_isScopePrivate = true;
}
public function getCheckoutForm(){
$parameter = $this->_paymentMethod->getCheckoutParameter();
$gatewayUrl = $this->_paymentMethod->getGatewayUrl();
$formHTML = '';
$formHTML .= '<form action="'.$gatewayUrl.'" name="payment_checkout" id="payment_checkout">';
foreach ($parameter as $field => $value) {
$formHTML .= "<input type='hidden' name='".$field."' value='".$value."' >";
}
$formHTML .= '</form>';
// echo "<pre>";
// print_r($formHTML);die();
return $formHTML;
}
public function getPayMode(){
return $this->_paymentMethod->getConfigData('pay_mode');
}
}
<?php
namespace Oceanpayment\Klarna\Controller\Payment;
use Magento\Framework\Controller\ResultFactory;
use Magento\Customer\Api\Data\GroupInterface;
class Redirect extends \Magento\Framework\App\Action\Action
{
/**
* Customer session model
*
* @var \Magento\Customer\Model\Session
*/
protected $_customerSession;
protected $resultPageFactory;
protected $_paymentMethod;
protected $_checkoutSession;
protected $checkout;
/**
* @param \Magento\Framework\App\Action\Context $context
* @param \Magento\Customer\Model\Session $customerSession
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Customer\Model\Session $customerSession,
\Oceanpayment\Klarna\Model\PaymentMethod $paymentMethod,
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Framework\View\Result\PageFactory $resultPageFactory
) {
$this->_customerSession = $customerSession;
$this->resultPageFactory = $resultPageFactory;
parent::__construct($context);
$this->_paymentMethod = $paymentMethod;
$this->_checkoutSession = $checkoutSession;
}
public function execute()
{
$resultPage = $this->resultPageFactory->create();
$resultPage->getConfig()->getTitle()->set(__('Klarna'));
return $resultPage;
}
}
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Oceanpayment\Klarna\Model;
use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Framework\Locale\ResolverInterface;
use Magento\Customer\Helper\Session\CurrentCustomer;
use Magento\Payment\Helper\Data as PaymentHelper;
class KlarnaConfigProvider implements ConfigProviderInterface
{
/**
* @var ResolverInterface
*/
protected $localeResolver;
/**
* @var Config
*/
protected $config;
/**
* @var \Magento\Customer\Helper\Session\CurrentCustomer
*/
protected $currentCustomer;
/**
* @var string[]
*/
/*protected $methodCodes = [
Config::METHOD_WPP_BML,
Config::METHOD_WPP_PE_EXPRESS,
Config::METHOD_WPP_EXPRESS,
Config::METHOD_WPP_PE_BML
];*/
/**
* @var \Magento\Payment\Model\Method\AbstractMethod[]
*/
protected $methods = [];
/**
* @var PaymentHelper
*/
protected $paymentHelper;
protected $checkoutSession;
/**
* @param ConfigFactory $configFactory
* @param ResolverInterface $localeResolver
* @param CurrentCustomer $currentCustomer
* @param PaymentHelper $paymentHelper
*/
public function __construct(
//ConfigFactory $configFactory,
ResolverInterface $localeResolver,
CurrentCustomer $currentCustomer,
\Magento\Checkout\Model\Session $checkoutSession,
PaymentHelper $paymentHelper
) {
$this->localeResolver = $localeResolver;
//$this->config = $configFactory->create();
$this->currentCustomer = $currentCustomer;
$this->paymentHelper = $paymentHelper;
$this->checkoutSession = $checkoutSession;
$code = 'oceanpaymentklarna';
$this->methods[$code] = $this->paymentHelper->getMethodInstance($code);
}
/**
* {@inheritdoc}
*/
public function getConfig()
{
$code = 'oceanpaymentklarna';
$config = [];
if ($this->methods[$code]->isAvailable($this->checkoutSession->getQuote())) {
$config = [];
$config['payment'] = [];
$config['payment']['klarna']['redirectUrl'] = [];
$config['payment']['klarna']['redirectUrl'][$code] = $this->getMethodRedirectUrl($code);
}
return $config;
}
/**
* Return redirect URL for method
*
* @param string $code
* @return mixed
*/
protected function getMethodRedirectUrl($code)
{
return $this->methods[$code]->getOrderPlaceRedirectUrl();
}
}
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Oceanpayment\Klarna\Model\Source;
use Magento\Framework\Option\ArrayInterface;
class OtherCurrency implements ArrayInterface {
/**
* @return array
*/
public function toOptionArray() {
return [
['value' => '1', 'label' => __('3D Secure')],
['value' => '0', 'label' =>__('Sale')]
];
}
}
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Oceanpayment\Klarna\Model\Source;
use Magento\Framework\Option\ArrayInterface;
class PayMode implements ArrayInterface {
/**
* @return array
*/
public function toOptionArray() {
return [
['value' => 'iframe', 'label' => __('Iframe')],
['value' => 'redirect', 'label' =>__('Redirect')]
];
}
}
#Oceanpayment Klarna
Installation
1 - unzip de module in app/code/Oceanpayment/Klarna
2 - enable module: bin/magento module:enable --clear-static-content Oceanpayment_Klarna
3 - upgrade database: bin/magento setup:upgrade
4 - re-run compile command: bin/magento setup:di:compile
In order to deactivate the module bin/magento module:disable --clear-static-content Oceanpayment_Klarna
In order to update static files: bin/magento setup:static-content:deploy
Important: make sure that php path is correct in bin/magento file
{
"name": "oceanpayment/module-klarna",
"description": "Accept payments using Oceanpayment Klarna payment gateway",
"type": "magento2-module",
"version": "1.0.0",
"license": [
"OSL-3.0",
"AFL-3.0"
],
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Oceanpayment\\Klarna\\": ""
}
}
}
<?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="oceanpaymentklarna" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Klarna</label>
<field id="active" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="title" translate="label" type="text" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Title</label>
</field>
<field id="account" translate="label" type="text" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Account</label>
<can_be_empty>0</can_be_empty>
</field>
<field id="terminal" translate="label" type="text" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Terminal</label>
<can_be_empty>0</can_be_empty>
</field>
<field id="securecode" translate="label" type="text" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="0">
<label>SecureCode</label>
<can_be_empty>0</can_be_empty>
</field>
<field id="gateway_url" translate="label" type="text" sortOrder="7" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Gateway URL</label>
</field>
<field id="pay_mode" translate="label" type="select" sortOrder="8" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Pay Mode</label>
<source_model>Oceanpayment\Klarna\Model\Source\PayMode</source_model>
</field>
<field id="new_order_status" translate="label" type="select" sortOrder="9" showInDefault="1" showInWebsite="1" showInStore="0">
<label>New Order Status</label>
<source_model>Magento\Sales\Model\Config\Source\Order\Status</source_model>
</field>
<field id="success_order_status" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Approved Order Status</label>
<source_model>Magento\Sales\Model\Config\Source\Order\Status</source_model>
</field>
<field id="failure_order_status" translate="label" type="select" sortOrder="11" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Failure Order Status</label>
<source_model>Magento\Sales\Model\Config\Source\Order\Status</source_model>
</field>
<field id="high_risk_order_status" translate="label" type="select" sortOrder="12" showInDefault="1" showInWebsite="1" showInStore="0">
<label>High Risk Order Status</label>
<source_model>Magento\Sales\Model\Config\Source\Order\Status</source_model>
</field>
<field id="pre_auth_order_status" translate="label" type="select" sortOrder="13" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Pre-auth Order Status</label>
<source_model>Magento\Sales\Model\Config\Source\Order\Status</source_model>
</field>
<field id="invoice" translate="label" type="select" sortOrder="14" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Invoice When Complete</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="allowspecific" translate="label" type="allowspecific" sortOrder="14" showInDefault="1" showInWebsite="1" showInStore="0">
<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="16" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Payment from Specific Countries</label>
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
</field>
<field id="sort_order" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Sort Order</label>
</field>
</group>
</section>
</system>
</config>
\ No newline at end of file
<?xml version="1.0"?>
<include xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_include.xsd">
<group id="secure" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
<label>3D Secure Mode</label>
<frontend_model>Magento\Config\Block\System\Config\Form\Fieldset</frontend_model>
<field id="secure_mode" translate="label" sortOrder="1" type="select" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="secure_terminal" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="0">
<label>3D Secure Terminal</label>
<can_be_empty>0</can_be_empty>
</field>
<field id="secure_securecode" translate="label" type="text" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="0">
<label>3D Secure SecureCode</label>
<can_be_empty>0</can_be_empty>
</field>
<field id="secure_currency" translate="label" type="text" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="0">
<label>3D Secure Currency</label>
<can_be_empty>0</can_be_empty>
</field>
<field id="secure_amount" translate="label" type="text" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="0">
<label>3D Secure Amount</label>
<can_be_empty>0</can_be_empty>
</field>
<field id="secure_other_currency" translate="label" type="select" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Other Currency</label>
<source_model>Oceanpayment\Klarna\Model\Source\OtherCurrency</source_model>
</field>
<field id="secure_country" translate="label" type="multiselect" sortOrder="7" showInDefault="1" showInWebsite="1" showInStore="0">
<label>3D Secure Countries</label>
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
</field>
</group>
</include>
\ No newline at end of file
<?xml version="1.0"?>
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<payment>
<oceanpaymentklarna>
<title>Klarna</title>
<model>Oceanpayment\Klarna\Model\PaymentMethod</model>
<active>0</active>
<new_order_status>pending</new_order_status>
<success_order_status>processing</success_order_status>
<failure_order_status>canceled</failure_order_status>
<pre_auth_order_status>processing</pre_auth_order_status>
<invoice>0</invoice>
<sort_order>0</sort_order>
<allowspecific>0</allowspecific>
</oceanpaymentklarna>
</payment>
</default>
</config>
<?xml version="1.0"?>
<!--
/**
* Copyright © 2015 Magento. 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="klarna_config_provider" xsi:type="object">Oceanpayment\Klarna\Model\KlarnaConfigProvider</item>
</argument>
</arguments>
</type>
</config>
<?xml version="1.0"?>
<!--
/**
* Copyright © 2016 Oceanpayment Design. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
<route id="oceanpaymentklarna" frontName="oceanpaymentklarna">
<module name="Oceanpayment_Klarna" />
</route>
</router>
</config>
<?xml version="1.0"?>
<!--
/**
* Copyright © 2016 Oceanpayment Design All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Oceanpayment_Klarna" active="true" schema_version="2.0.2" setup_version="2.0.2">
<sequence>
<module name="Magento_Store"/>
<module name="Magento_Catalog"/>
</sequence>
</module>
</config>
*************************************
\ No newline at end of file
<?php
/**
* Copyright © 2016 Oceanpayment Design. All rights reserved.
* See COPYING.txt for license details.
*/
use \Magento\Framework\Component\ComponentRegistrar;
\Magento\Framework\Component\ComponentRegistrar::register(
ComponentRegistrar::MODULE,
'Oceanpayment_Klarna',
__DIR__
);
<?php
/**
* Copyright © 2016 Oceanpayment Design. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile
/**
* @var $block \Oceanpayment\Klarna\Block\Info
*/
?>
<?php echo $block->escapeHtml($block->getMethod()->getTitle()) ?>
<?php if ($block->getInfo()->getLastTransId() == ''): ?>
<br /><?php echo __('No transaction ID recorded.') ?>
<?php else: ?>
<br /><?php echo __('Klarna Transaction ID: %1', $this->escapeHtml($block->getInfo()->getLastTransId())) ?>
<?php endif; ?>
<?php
/**
* Copyright © 2016 Oceanpayment Design. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile
/**
* @var $block \Oceanpayment\Klarna\Block\Info
*/
?>
<?php echo $this->escapeHtml($block->getMethod()->getTitle()) ?>
{{pdf_row_separator}}
<?php echo __('Klarna Transaction ID: %1', $this->escapeHtml($block->getInfo()->getLastTransId())) ?>
{{pdf_row_separator}}
<?xml version="1.0"?>
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<css src="Oceanpayment_Klarna::css/styles.css"/>
</head>
<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">
<!-- merge payment method renders here -->
<item name="children" xsi:type="array">
<item name="klarna-payments" xsi:type="array">
<item name="component" xsi:type="string">Oceanpayment_Klarna/js/view/payment/klarna-method</item>
<item name="methods" xsi:type="array">
<item name="oceanpaymentklarna" 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>
\ No newline at end of file
<?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" layout="1column">
<body>
<referenceContainer name="content">
<block class="Oceanpayment\Klarna\Block\Payment\Redirect" name="klarna.redirect" template="payment/redirect.phtml" cacheable="false"/>
</referenceContainer>
</body>
</page>
\ No newline at end of file
<?php
/**
* Copyright © 2016 Oceanpayment Design. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile
/**
* @var $block \Oceanpayment\Klarna\Block\Form
*/
?>
<?php $methodCode = $block->escapeHtml($block->getMethodCode());?>
<div class="items <?php /* @noEscape */ echo $methodCode ?> instructions agreement checkout-agreement-item-content" id="payment_form_<?php /* @noEscape */ echo $methodCode ?>" style="display: none;">
<?php /* @noEscape */ echo nl2br($block->escapeHtml($instructions)) ?>
<div style="padding:10px 15px 15px;">
<img src="<?php $block->escapeUrl($block->getViewFileUrl('Oceanpayment_Klarna::icon_accepted_cards_klarna.gif'));?>" alt="<?php echo __('Payment by visa or mastercard'); ?>"><br>
</div>
</div>
\ No newline at end of file
<?php
/**
* Copyright © 2016 Oceanpayment Design. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile
/**
* @var $block \Oceanpayment\Klarna\Block\Info
*/
?>
<dl class="payment-method oceanpaymentklarna">
<dt class="title"><?php echo $block->escapeHtml($block->getMethod()->getTitle()) ?></dt>
<dd class="content">
<strong><?php echo $block->escapeHtml(__('You will be redirected to our secure payment page when you place an order.')) ?></strong>
</dd>
</dl>
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
?>
<div>
<?php echo $block->getCheckoutForm(); ?>
<?php if($block->getPayMode() == 'iframe'){?>
<iframe width="100%" height="800px" scrolling="auto" name="iframe_checkout" id="iframe_checkout" style="border:none; margin: 0 auto; overflow:auto;"></iframe>
<script type="text/javascript">
if (window.XMLHttpRequest) {
document.payment_checkout.target="iframe_checkout";
}
document.payment_checkout.submit();
</script>
<?php }elseif($block->getPayMode() == 'redirect'){?>
<p style="font: 16px; padding: 0px; text-align: center; margin: 100px auto 0px; width: 90%;"><?php echo __('Processing, please do not click the refresh button.'); ?></p>
<script type="text/javascript">
document.payment_checkout.submit();
</script>
<?php } ?>
</div>
\ No newline at end of file
.payment-method div.payment_logo_oceanpaymentklarna {
background:url(../images/payment_logo.png) no-repeat;
height:80px;
}
/**
* Copyright © 2016 Oceanpayment Design. All rights reserved.
* See COPYING.txt for license details.
*/
define(
[
'jquery',
'Magento_Checkout/js/model/quote',
'Magento_Checkout/js/model/url-builder',
'mage/storage',
'Magento_Checkout/js/model/error-processor',
'Magento_Customer/js/model/customer',
'Magento_Checkout/js/model/full-screen-loader'
],
function ($, quote, urlBuilder, storage, errorProcessor, customer, fullScreenLoader) {
'use strict';
return function (messageContainer) {
var serviceUrl,
payload,
paymentData = quote.paymentMethod();
if (Object.prototype.hasOwnProperty.call(paymentData, '__disableTmpl')) { delete paymentData.__disableTmpl; }
/**
* Checkout for guest and registered customer.
*/
if (!customer.isLoggedIn()) {
serviceUrl = urlBuilder.createUrl('/guest-carts/:cartId/payment-information', {
cartId: quote.getQuoteId()
});
payload = {
cartId: quote.getQuoteId(),
email: quote.guestEmail,
paymentMethod: paymentData,
billingAddress: quote.billingAddress()
};
} else {
serviceUrl = urlBuilder.createUrl('/carts/mine/payment-information', {});
payload = {
cartId: quote.getQuoteId(),
paymentMethod: paymentData,
billingAddress: quote.billingAddress()
};
}
fullScreenLoader.startLoader();
return storage.post(
serviceUrl, JSON.stringify(payload)
).done(
function () {
//$.mage.redirect(window.checkoutConfig.payment.paypalExpress.redirectUrl[quote.paymentMethod().method]);
$.mage.redirect(window.checkoutConfig.payment.klarna.redirectUrl[quote.paymentMethod().method]);
}
).fail(
function (response) {
errorProcessor.process(response, messageContainer);
fullScreenLoader.stopLoader();
}
);
};
}
);
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
/*browser:true*/
/*global define*/
define(
[
'uiComponent',
'Magento_Checkout/js/model/payment/renderer-list'
],
function (
Component,
rendererList
) {
'use strict';
rendererList.push(
{
type: 'oceanpaymentklarna',
component: 'Oceanpayment_Klarna/js/view/payment/method-renderer/klarna-method'
}
);
/** Add view logic here if needed */
return Component.extend({});
}
);
\ No newline at end of file
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
/*browser:true*/
/*global define*/
define(
[
'jquery',
'Magento_Checkout/js/view/payment/default',
'Oceanpayment_Klarna/js/action/set-payment-method',
'Magento_Checkout/js/model/payment/additional-validators'
],
function ($, Component, setPaymentMethodAction) {
'use strict';
return Component.extend({
defaults: {
template: 'Oceanpayment_Klarna/payment/klarna'
},
/** Redirect to klarna */
continueToKlarna: function () {
//update payment method information if additional data was changed
this.selectPaymentMethod();
setPaymentMethodAction(this.messageContainer);
return false;
}
});
}
);
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<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>
<div alt="Logo" data-bind="attr: {'class': 'payment_logo_' + getCode()}"></div>
</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>
<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-bind="click: continueToKlarna, enable: (getCode() == isChecked())"
disabled>
<span data-bind="i18n: 'Place Order'"></span>
</button>
</div>
</div>
</div>
</div>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment