Skip to content

Commit

Permalink
Merge pull request #115 from paynl/feature/PLUG-282
Browse files Browse the repository at this point in the history
Auto-capture function added.
  • Loading branch information
woutse authored Mar 22, 2021
2 parents eb8269d + 4bb6158 commit 8c322c3
Show file tree
Hide file tree
Showing 20 changed files with 554 additions and 8 deletions.
9 changes: 7 additions & 2 deletions Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,20 @@ public function getAuthorizedStatus($methodCode)
return $this->store->getConfig('payment/' . $methodCode . '/order_status_authorized');
}

public function getPaidStatus($methodCode){
public function getPaidStatus($methodCode)
{
return $this->store->getConfig('payment/' . $methodCode . '/order_status_processing');
}

public function ignoreB2BInvoice($methodCode)
{
return $this->store->getConfig('payment/' . $methodCode . '/turn_off_invoices_b2b') == 1;
}


public function autoCaptureEnabled()
{
return $this->store->getConfig('payment/paynl/auto_capture') == 1;
}

/**
* @param $methodCode string
Expand Down
12 changes: 12 additions & 0 deletions Model/Config/Source/Available/SofortbankingDigitalServices.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
/**
* Copyright © 2020 PAY. All rights reserved.
*/

namespace Paynl\Payment\Model\Config\Source\Available;


class SofortbankingDigitalServices extends Available
{
protected $_class = \Paynl\Payment\Model\Paymentmethod\SofortbankingDigitalServices::class;
}
12 changes: 12 additions & 0 deletions Model/Config/Source/Available/SofortbankingHighRisk.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
/**
* Copyright © 2020 PAY. All rights reserved.
*/

namespace Paynl\Payment\Model\Config\Source\Available;


class SofortbankingHighRisk extends Available
{
protected $_class = \Paynl\Payment\Model\Paymentmethod\SofortbankingHighRisk::class;
}
42 changes: 42 additions & 0 deletions Model/Config/Source/OffOn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* Copyright © 2020 PAY. All rights reserved.
*/

namespace Paynl\Payment\Model\Config\Source;

use \Magento\Framework\Option\ArrayInterface;

class OffOn implements ArrayInterface
{

/**
* Options getter
*
* @return array
*/
public function toOptionArray()
{
$arrOptions = $this->toArray();

$arrResult = [];
foreach ($arrOptions as $value => $label) {
$arrResult[] = ['value' => $value, 'label' => $label];
}
return $arrResult;
}

/**
* Get options in "key-value" format
*
* @return array
*/
public function toArray()
{
return [
'0' => __('Off'),
'1' => __('On'),
];
}

}
2 changes: 2 additions & 0 deletions Model/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class ConfigProvider implements ConfigProviderInterface
'paynl_payment_postepay',
'paynl_payment_przelewy24',
'paynl_payment_sofortbanking',
'paynl_payment_sofortbanking_hr',
'paynl_payment_sofortbanking_ds',
'paynl_payment_spraypay',
'paynl_payment_telefonischbetalen',
'paynl_payment_tikkie',
Expand Down
20 changes: 20 additions & 0 deletions Model/Paymentmethod/SofortbankingDigitalServices.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* Copyright © 2020 PAY. All rights reserved.
*/

namespace Paynl\Payment\Model\Paymentmethod;

/**
* Class SofortbankingDigitalServices
* @package Paynl\Payment\Model\Paymentmethod
*/
class SofortbankingDigitalServices extends PaymentMethod
{
protected $_code = 'paynl_payment_sofortbanking_ds';

protected function getDefaultPaymentOptionId()
{
return 577;
}
}
20 changes: 20 additions & 0 deletions Model/Paymentmethod/SofortbankingHighRisk.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* Copyright © 2020 PAY. All rights reserved.
*/

namespace Paynl\Payment\Model\Paymentmethod;

/**
* Class SofortbankingHighRisk
* @package Paynl\Payment\Model\Paymentmethod
*/
class SofortbankingHighRisk extends PaymentMethod
{
protected $_code = 'paynl_payment_sofortbanking_hr';

protected function getDefaultPaymentOptionId()
{
return 595;
}
}
73 changes: 73 additions & 0 deletions Observer/OrderSaveCommitAfter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

namespace Paynl\Payment\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Store\Model\Store;
use Psr\Log\LoggerInterface;
use Paynl\Result\Transaction\Transaction;
use Paynl\Payment\Model\Config;
use Magento\Sales\Model\Order;

class OrderSaveCommitAfter implements ObserverInterface
{

/**
*
* @var Magento\Store\Model\Store;
*/
private $store;

/**
*
* @var Psr\Log\LoggerInterface
*/
protected $logger;

/**
*
* @var \Paynl\Payment\Model\Config
*/
private $config;

public function __construct(
LoggerInterface $logger,
Config $config,
Store $store
) {
$this->logger = $logger;
$this->config = $config;
$this->store = $store;
}

public function execute(\Magento\Framework\Event\Observer $observer)
{
if ($this->config->autoCaptureEnabled()) {
$order = $observer->getEvent()->getOrder();
if ($order->getState() == Order::STATE_PROCESSING && !$order->hasInvoices() && $order->hasShipments()) {
$data = $order->getPayment()->getData();

if (!empty($data['last_trans_id'])) {
$bHasAmountAuthorized = !empty($data['base_amount_authorized']);
$amountPaid = isset($data['amount_paid']) ? $data['amount_paid'] : null;
$amountRefunded = isset($data['amount_refunded']) ? $data['amount_refunded'] : null;

if ($bHasAmountAuthorized && is_null($amountPaid) && is_null($amountRefunded)) {
$this->logger->debug('PAY.: AUTO-CAPTURING ' . $data['last_trans_id']);
try {
\Paynl\Config::setApiToken($this->config->getApiToken());
$result = \Paynl\Transaction::capture($data['last_trans_id']);
$strResult = 'Success';
} catch (\Exception $e) {
$this->logger->debug('Order PAY error: ' . $e->getMessage() . ' EntityId: ' . $order->getEntityId());
$strResult = 'Failed. Errorcode: PAY-MAGENTO2-003. See docs.pay.nl for more information';
}

$order->addStatusHistoryComment(__('PAY. - Performed auto-capture. Result: ') . $strResult, false)->save();
}
}
}
}
}

}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "paynl/magento2-plugin",
"description": "PAY. Magento2 Payment methods",
"type": "magento2-module",
"version": "1.7.3",
"version": "1.7.4",
"require": {
"magento/module-sales": "100 - 103",
"magento/module-payment": "100 - 103",
Expand Down
2 changes: 2 additions & 0 deletions etc/adminhtml/paymentmethods.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
<include path="Paynl_Payment::paymentmethods/postepay.xml" />
<include path="Paynl_Payment::paymentmethods/przelewy24.xml" />
<include path="Paynl_Payment::paymentmethods/sofortbanking.xml" />
<include path="Paynl_Payment::paymentmethods/sofortbanking_hr.xml" />
<include path="Paynl_Payment::paymentmethods/sofortbanking_ds.xml" />
<include path="Paynl_Payment::paymentmethods/spraypay.xml" />
<include path="Paynl_Payment::paymentmethods/telefonischbetalen.xml" />
<include path="Paynl_Payment::paymentmethods/tikkie.xml" />
Expand Down
145 changes: 145 additions & 0 deletions etc/adminhtml/paymentmethods/sofortbanking_ds.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<?xml version="1.0" encoding="UTF-8"?>
<include xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_include.xsd">
<group id="paynl_payment_sofortbanking_ds" sortOrder="1900" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Sofortbanking Digital Services</label>
<field id="active" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1"
showInStore="1">
<label>Enabled</label>
<source_model>Paynl\Payment\Model\Config\Source\Available\SofortbankingDigitalServices</source_model>
<config_path>payment/paynl_payment_sofortbanking_ds/active</config_path>
</field>
<field id="title" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1"
showInStore="1">
<label>Title</label>
<config_path>payment/paynl_payment_sofortbanking_ds/title</config_path>
<depends>
<field id="active">1</field>
</depends>
</field>
<field id="order_status" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="1"
showInStore="1">
<label>New Order Status</label>
<source_model>Paynl\Payment\Model\Config\Source\Order\Status\PendingPayment</source_model>
<depends>
<field id="active">1</field>
</depends>
<config_path>payment/paynl_payment_sofortbanking_ds/order_status</config_path>
</field>
<field id="order_status_authorized" translate="label" type="select" sortOrder="32" showInDefault="1" showInWebsite="1"
showInStore="1">
<label>Authorized Order Status</label>
<source_model>Paynl\Payment\Model\Config\Source\Order\Status\Processing</source_model>
<depends>
<field id="active">1</field>
</depends>
<config_path>payment/paynl_payment_sofortbanking_ds/order_status_authorized</config_path>
</field>
<field id="order_status_processing" translate="label" type="select" sortOrder="35" showInDefault="1" showInWebsite="1"
showInStore="1">
<label>Paid Order Status</label>
<source_model>Paynl\Payment\Model\Config\Source\Order\Status\Processing</source_model>
<depends>
<field id="active">1</field>
</depends>
<config_path>payment/paynl_payment_sofortbanking_ds/order_status_processing</config_path>
</field>
<field id="holded" translate="label" type="select" sortOrder="35" showInDefault="1"
showInWebsite="1"
showInStore="1">
<label>Set order on-hold</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>payment/paynl_payment_sofortbanking_ds/holded</config_path>
<depends>
<field id="active">1</field>
</depends>
<comment><![CDATA[Set the orderstatus to on-hold when payment begins (to hold stock).]]></comment>
</field>
<field id="allowspecific" translate="label" type="allowspecific" sortOrder="40" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Payment from Applicable Countries</label>
<source_model>Magento\Payment\Model\Config\Source\Allspecificcountries</source_model>
<config_path>payment/paynl_payment_sofortbanking_ds/allowspecific</config_path>
<depends>
<field id="active">1</field>
</depends>
</field>
<field id="specificcountry" translate="label" type="multiselect" sortOrder="50" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Payment from Specific Countries</label>
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
<can_be_empty>1</can_be_empty>
<config_path>payment/paynl_payment_sofortbanking_ds/specificcountry</config_path>
<depends>
<field id="allowspecific">1</field>
<field id="active">1</field>
</depends>
</field>
<field id="instructions" translate="label" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Instructions</label>
<depends>
<field id="active">1</field>
</depends>
<config_path>payment/paynl_payment_sofortbanking_ds/instructions</config_path>
</field>
<field id="min_order_total" translate="label" type="text" sortOrder="70" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Minimum Order Total</label>
<config_path>payment/paynl_payment_sofortbanking_ds/min_order_total</config_path>
<depends>
<field id="active">1</field>
</depends>
</field>
<field id="max_order_total" translate="label" type="text" sortOrder="80" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Maximum Order Total</label>
<config_path>payment/paynl_payment_sofortbanking_ds/max_order_total</config_path>
<depends>
<field id="active">1</field>
</depends>
</field>
<field id="sort_order" translate="label" type="text" sortOrder="90" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Sort Order</label>
<frontend_class>validate-number</frontend_class>
<config_path>payment/paynl_payment_sofortbanking_ds/sort_order</config_path>
<depends>
<field id="active">1</field>
</depends>
</field>
<field id="send_new_order_email" translate="label" type="select" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Send new order email</label>
<source_model>Paynl\Payment\Model\Config\Source\SendNewOrderEmail</source_model>
<config_path>payment/paynl_payment_sofortbanking_ds/send_new_order_email</config_path>
<depends>
<field id="active">1</field>
</depends>
</field>
<field id="disallowedshipping" translate="label" type="multiselect" sortOrder="110" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Disallowed Shipping Methods</label>
<source_model>Magento\Shipping\Model\Config\Source\Allmethods</source_model>
<can_be_empty>1</can_be_empty>
<depends>
<field id="active">1</field>
</depends>
<config_path>payment/paynl_payment_sofortbanking_ds/disallowedshipping</config_path>
<comment><![CDATA[Hold CTRL button to select/deselect multiple]]></comment>
</field>
<field id="showforcompany" translate="label" type="select" sortOrder="150" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Show for companies</label>
<source_model>Paynl\Payment\Model\Config\Source\showCompanyOptions</source_model>
<depends>
<field id="active">1</field>
</depends>
<config_path>payment/paynl_payment_sofortbanking_ds/showforcompany</config_path>
<comment><![CDATA[Allow payment method to be used for companies, private, or both.]]></comment>
</field>
<group id="advanced" translate="label" sortOrder="200" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Advanced</label>
<field id="payment_option_id" translate="label comment" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Payment option id</label>
<comment>The id of the payment method, only change this if you are told to do so</comment>
<config_path>payment/paynl_payment_sofortbanking_ds/payment_option_id</config_path>
</field>
</group>
</group>
</include>

Loading

0 comments on commit 8c322c3

Please sign in to comment.