Skip to content

Commit 26c296e

Browse files
code
0 parents  commit 26c296e

File tree

15 files changed

+403
-0
lines changed

15 files changed

+403
-0
lines changed

Controller/Satispay/Callback.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
namespace Satispay\Satispay\Controller\Satispay;
3+
4+
class Callback extends \Magento\Framework\App\Action\Action {
5+
protected $_order;
6+
protected $_satispayPayment;
7+
protected $_logger;
8+
9+
public function __construct(
10+
\Magento\Framework\App\Action\Context $context,
11+
\Magento\Sales\Model\Order $order,
12+
\Satispay\Satispay\Model\Payment $satispayPayment,
13+
\Psr\Log\LoggerInterface $logger
14+
) {
15+
parent::__construct($context);
16+
$this->_order = $order;
17+
$this->_satispayPayment = $satispayPayment;
18+
$this->_logger = $logger;
19+
}
20+
21+
public function execute() {
22+
$charge = \SatispayOnline\Charge::get($this->getRequest()->getParam('charge'));
23+
$order = $this->_order->load($charge->metadata->orderid);
24+
25+
if ($order->getState() === $order::STATE_NEW) {
26+
if ($charge->status === 'SUCCESS') {
27+
$payment = $order->getPayment();
28+
$payment->setTransactionId($charge->id);
29+
$payment->setCurrencyCode($charge->currency);
30+
$payment->setIsTransactionClosed(true);
31+
$payment->registerCaptureNotification($charge->amount / 100);
32+
33+
$order->save();
34+
} else {
35+
$payment = $order->getPayment();
36+
$payment->setTransactionId($charge->id);
37+
$payment->setCurrencyCode($charge->currency);
38+
$payment->setIsTransactionClosed(true);
39+
$payment->setNotificationResult(true);
40+
$payment->deny(false);
41+
42+
$order->registerCancellation();
43+
$order->save();
44+
}
45+
}
46+
$this->getResponse()->setBody('OK');
47+
}
48+
}

Controller/Satispay/Payment.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
namespace Satispay\Satispay\Controller\Satispay;
3+
4+
class Payment extends \Magento\Framework\App\Action\Action {
5+
protected $_satispayPayment;
6+
protected $_checkoutSession;
7+
protected $_logger;
8+
9+
public function __construct(
10+
\Magento\Framework\App\Action\Context $context,
11+
\Satispay\Satispay\Model\Payment $satispayPayment,
12+
\Magento\Checkout\Model\Session $checkoutSession,
13+
\Psr\Log\LoggerInterface $logger
14+
) {
15+
parent::__construct($context);
16+
$this->_satispayPayment = $satispayPayment;
17+
$this->_checkoutSession = $checkoutSession;
18+
$this->_logger = $logger;
19+
}
20+
21+
public function execute() {
22+
$lastOrder = $this->_checkoutSession->getLastRealOrder();
23+
if ($lastOrder->getState() === $lastOrder::STATE_NEW) {
24+
$checkout = \SatispayOnline\Checkout::create(array(
25+
'description' => '#'.$lastOrder->getIncrementId(),
26+
'phone_number' => $lastOrder->getBillingAddress()->getTelephone(),
27+
'redirect_url' => $this->_url->getUrl('satispay/satispay/redirect'),
28+
'callback_url' => $this->_url->getUrl('satispay/satispay/callback', $this->_redirect->updatePathParams([
29+
'charge' => '{uuid}'
30+
])),
31+
'amount_unit' => $lastOrder->getGrandTotal() * 100,
32+
'currency' => $lastOrder->getOrderCurrencyCode(),
33+
'metadata' => array(
34+
'orderid' => $lastOrder->getId(),
35+
'X-Satispay-Client' => \SatispayOnline\Api::getClient()
36+
)
37+
));
38+
$this->_redirect($checkout->checkout_url);
39+
}
40+
}
41+
}

Controller/Satispay/Redirect.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
namespace Satispay\Satispay\Controller\Satispay;
3+
4+
class Redirect extends \Magento\Framework\App\Action\Action {
5+
protected $_satispayPayment;
6+
protected $_checkoutSession;
7+
protected $_logger;
8+
9+
public function __construct(
10+
\Magento\Framework\App\Action\Context $context,
11+
\Satispay\Satispay\Model\Payment $satispayPayment,
12+
\Magento\Checkout\Model\Session $checkoutSession,
13+
\Psr\Log\LoggerInterface $logger
14+
) {
15+
parent::__construct($context);
16+
$this->_satispayPayment = $satispayPayment;
17+
$this->_checkoutSession = $checkoutSession;
18+
$this->_logger = $logger;
19+
}
20+
21+
public function execute() {
22+
$charge = \SatispayOnline\Charge::get($this->getRequest()->getParam('charge_id'));
23+
if ($charge->status === 'SUCCESS') {
24+
$this->_redirect('checkout/onepage/success');
25+
} else {
26+
$this->_checkoutSession->restoreQuote();
27+
$this->_redirect('checkout/cart');
28+
}
29+
}
30+
}

Model/Payment.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
namespace Satispay\Satispay\Model;
3+
4+
class Payment extends \Magento\Payment\Model\Method\AbstractMethod {
5+
protected $_code = 'satispay_satispay';
6+
protected $_canRefund = true;
7+
protected $_canRefundInvoicePartial = true;
8+
9+
protected $_supportedCurrencies = array('EUR');
10+
11+
public function __construct(
12+
\Magento\Framework\Model\Context $context,
13+
\Magento\Framework\Registry $registry,
14+
\Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
15+
\Magento\Framework\Api\AttributeValueFactory $customAttributeFactory,
16+
\Magento\Payment\Helper\Data $paymentData,
17+
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
18+
\Magento\Payment\Model\Method\Logger $logger,
19+
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
20+
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
21+
array $data = []
22+
) {
23+
parent::__construct(
24+
$context,
25+
$registry,
26+
$extensionFactory,
27+
$customAttributeFactory,
28+
$paymentData,
29+
$scopeConfig,
30+
$logger,
31+
$resource,
32+
$resourceCollection,
33+
$data
34+
);
35+
36+
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
37+
$productMetadata = $objectManager->get('Magento\Framework\App\ProductMetadataInterface');
38+
$version = $productMetadata->getVersion();
39+
40+
\SatispayOnline\Api::setSecurityBearer($this->getConfigData('security_bearer'));
41+
\SatispayOnline\Api::setStaging((bool)$this->getConfigData('staging'));
42+
\SatispayOnline\Api::setClient('Magento/'.$version);
43+
}
44+
45+
public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null) {
46+
if (!$this->getConfigData('security_bearer')) {
47+
return false;
48+
}
49+
return parent::isAvailable($quote);
50+
}
51+
52+
public function canUseForCurrency($currencyCode) {
53+
if (!in_array($currencyCode, $this->_supportedCurrencies)) {
54+
return false;
55+
}
56+
return true;
57+
}
58+
59+
public function refund(\Magento\Payment\Model\InfoInterface $payment, $amount) {
60+
$order = $payment->getOrder();
61+
62+
\SatispayOnline\Refund::create(array(
63+
'charge_id' => $payment->getParentTransactionId(),
64+
'currency' => $order->getOrderCurrencyCode(),
65+
'amount' => $amount * 100,
66+
'description' => '#'.$order->getIncrementId()
67+
));
68+
69+
return $this;
70+
}
71+
}

composer.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "satispay/magento2-plugin",
3+
"description": "Satispay",
4+
"license": "GPL-3.0",
5+
"version": "1.0.0",
6+
"type": "magento2-module",
7+
"authors": [
8+
{
9+
"name": "Satispay",
10+
"homepage": "http://satispay.com"
11+
}
12+
],
13+
"require": {
14+
"satispay/online-api-php-sdk": "^1.3"
15+
},
16+
"autoload": {
17+
"files": [
18+
"registration.php"
19+
],
20+
"psr-4": {
21+
"Satispay\\Satispay\\": ""
22+
}
23+
}
24+
}

etc/adminhtml/system.xml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0"?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
3+
<system>
4+
<section id="payment">
5+
<group id="satispay_satispay" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
6+
<label>Satispay</label>
7+
<!-- <comment>
8+
<![CDATA[<a href="https://business.satispay.com/signup" target="_blank">Click here to sign up for Satispay account</a>]]>
9+
</comment> -->
10+
<field id="active" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="0">
11+
<label>Enabled</label>
12+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
13+
</field>
14+
<field id="title" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
15+
<label>Title</label>
16+
</field>
17+
<field id="security_bearer" translate="label" type="obscure" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="0">
18+
<label>Security Bearer</label>
19+
<comment><![CDATA[Get it from <a href="https://business.satispay.com" target="_blank">business.satispay.com</a>]]></comment>
20+
</field>
21+
<field id="staging" translate="label" type="select" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="0">
22+
<label>Sandbox</label>
23+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
24+
</field>
25+
<field id="sort_order" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="0">
26+
<label>Sort Order</label>
27+
</field>
28+
</group>
29+
</section>
30+
</system>
31+
</config>

etc/config.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0"?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
3+
<default>
4+
<payment>
5+
<satispay_satispay>
6+
<model>Satispay\Satispay\Model\Payment</model>
7+
<title>Satispay</title>
8+
<staging>0</staging>
9+
<sort_order>1</sort_order>
10+
</satispay_satispay>
11+
</payment>
12+
</default>
13+
</config>

etc/frontend/routes.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0"?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
3+
<router id ="standard">
4+
<route id="satispay" frontName="satispay">
5+
<module name="Satispay_Satispay" />
6+
</route>
7+
</router>
8+
</config>

etc/module.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
3+
<module name="Satispay_Satispay" setup_version="1.0.0">
4+
<sequence>
5+
<module name="Magento_Sales" />
6+
<module name="Magento_Payment" />
7+
<module name="Magento_Checkout" />
8+
</sequence>
9+
</module>
10+
</config>

etc/payment.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<payment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Payment:etc/payment.xsd">
2+
<methods>
3+
<method name="satispay_satispay">
4+
5+
</method>
6+
</methods>
7+
</payment>

registration.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
use \Magento\Framework\Component\ComponentRegistrar;
3+
4+
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Satispay_Satispay', __DIR__);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0"?>
2+
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
3+
<body>
4+
<referenceBlock name="checkout.root">
5+
<arguments>
6+
<argument name="jsLayout" xsi:type="array">
7+
<item name="components" xsi:type="array">
8+
<item name="checkout" xsi:type="array">
9+
<item name="children" xsi:type="array">
10+
<item name="steps" xsi:type="array">
11+
<item name="children" xsi:type="array">
12+
<item name="billing-step" xsi:type="array">
13+
<item name="children" xsi:type="array">
14+
<item name="payment" xsi:type="array">
15+
<item name="children" xsi:type="array">
16+
<item name="renders" xsi:type="array">
17+
<!-- merge payment method renders here -->
18+
<item name="children" xsi:type="array">
19+
<item name="satispay-payments" xsi:type="array">
20+
<item name="component" xsi:type="string">Satispay_Satispay/js/view/payment/payments</item>
21+
<item name="methods" xsi:type="array">
22+
<item name="satispay_satispay" xsi:type="array">
23+
24+
</item>
25+
</item>
26+
</item>
27+
</item>
28+
</item>
29+
</item>
30+
</item>
31+
</item>
32+
</item>
33+
</item>
34+
</item>
35+
</item>
36+
</item>
37+
</item>
38+
</argument>
39+
</arguments>
40+
</referenceBlock>
41+
</body>
42+
</page>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*browser:true*/
2+
/*global define*/
3+
define(
4+
[
5+
'ko',
6+
'jquery',
7+
'Magento_Checkout/js/view/payment/default',
8+
'mage/url'
9+
],
10+
function (ko, $, Component, url) {
11+
'use strict'
12+
return Component.extend({
13+
defaults: {
14+
template: 'Satispay_Satispay/payment/form',
15+
redirectAfterPlaceOrder: false
16+
},
17+
afterPlaceOrder: function () {
18+
window.location.replace(url.build('satispay/satispay/payment'));
19+
}
20+
})
21+
}
22+
)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*browser:true*/
2+
/*global define*/
3+
define(
4+
[
5+
'uiComponent',
6+
'Magento_Checkout/js/model/payment/renderer-list'
7+
],
8+
function (
9+
Component,
10+
rendererList
11+
) {
12+
'use strict';
13+
rendererList.push(
14+
{
15+
type: 'satispay_satispay',
16+
component: 'Satispay_Satispay/js/view/payment/method-renderer/method'
17+
}
18+
)
19+
return Component.extend({})
20+
}
21+
)

0 commit comments

Comments
 (0)