diff --git a/Controller/Checkout/Redirect.php b/Controller/Checkout/Redirect.php
index 77556c06..4e473fd5 100644
--- a/Controller/Checkout/Redirect.php
+++ b/Controller/Checkout/Redirect.php
@@ -76,12 +76,13 @@ public function __construct(
public function execute()
{
try {
- $order = $this->_getCheckoutSession()->getLastRealOrder();
- $method = $order->getPayment()->getMethod();
+ $order = $this->checkoutSession->getLastRealOrder();
+ $payment = $order->getPayment();
+ $method = $payment->getMethod();
// restore the quote
$quote = $this->quoteRepository->get($order->getQuoteId());
- $quote->setIsActive(true)->setReservedOrderId(null);
+ $quote->setIsActive(true);
$this->quoteRepository->save($quote);
$methodInstance = $this->paymentHelper->getMethodInstance($method);
diff --git a/Model/Config/Source/Order/Status/PendingPayment.php b/Model/Config/Source/Order/Status/PendingPayment.php
index 77e57f5c..fa1715c7 100644
--- a/Model/Config/Source/Order/Status/PendingPayment.php
+++ b/Model/Config/Source/Order/Status/PendingPayment.php
@@ -16,5 +16,5 @@ class PendingPayment extends Status
/**
* @var string[]
*/
- protected $_stateStatuses = [Order::STATE_PENDING_PAYMENT];
+ protected $_stateStatuses = [Order::STATE_PENDING_PAYMENT, Order::STATE_NEW];
}
diff --git a/Model/Paymentmethod/Paylink.php b/Model/Paymentmethod/Paylink.php
index edf71a39..b361c870 100644
--- a/Model/Paymentmethod/Paylink.php
+++ b/Model/Paymentmethod/Paylink.php
@@ -1,58 +1,48 @@
*/
-class Paylink extends PaymentMethod {
- protected $_code = 'paynl_payment_paylink';
-
- /**
- * Paylink payment block paths
- *
- * @var string
- */
- protected $_formBlockType = \Paynl\Payment\Block\Form\Paylink::class;
-
- /**
- * @var OrderRepository
- */
- protected $_orderRepository;
+class Paylink extends PaymentMethod
+{
+ protected $_code = 'paynl_payment_paylink';
+
+ /**
+ * Paylink payment block paths
+ *
+ * @var string
+ */
+ protected $_formBlockType = \Paynl\Payment\Block\Form\Paylink::class;
+
// this is an admin only method
protected $_canUseCheckout = false;
- function __construct(
- \Magento\Framework\Model\Context $context,
- \Magento\Framework\Registry $registry,
- \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
- \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory,
- \Magento\Payment\Helper\Data $paymentData,
- \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
- \Magento\Payment\Model\Method\Logger $logger,
- OrderRepository $orderRepository,
- \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
- \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
- array $data = [] ) {
- parent::__construct( $context, $registry, $extensionFactory, $customAttributeFactory, $paymentData, $scopeConfig, $logger, $resource, $resourceCollection, $data );
- $this->_orderRepository = $orderRepository;
- }
-
- public function initialize( $paymentAction, $stateObject ) {
- if($paymentAction == 'order') {
- /** @var Order $order */
- $order = $this->getInfoInstance()->getOrder();
- $this->_orderRepository->save($order);
- $transaction = $this->doStartTransaction( $order );
- $state = $this->getConfigData('order_status');
- parent::initialize( $paymentAction, $stateObject );
- $order->addStatusHistoryComment('Betaallink: '.$transaction->getRedirectUrl(), $state);
- }
- }
- public function assignData( \Magento\Framework\DataObject $data ) {
- $this->getInfoInstance()->setAdditionalInformation('valid_days', $data->getData('additional_data')['valid_days']);
- return parent::assignData( $data );
- }
+
+ public function initialize($paymentAction, $stateObject)
+ {
+ if ($paymentAction == 'order') {
+ /** @var Order $order */
+ $order = $this->getInfoInstance()->getOrder();
+ $this->orderRepository->save($order);
+
+ $transaction = $this->doStartTransaction($order);
+
+ $status = $this->getConfigData('order_status');
+
+ $order->addStatusHistoryComment('Betaallink: ' . $transaction->getRedirectUrl(), $status);
+ parent::initialize($paymentAction, $stateObject);
+ }
+ }
+
+ public function assignData(\Magento\Framework\DataObject $data)
+ {
+ $this->getInfoInstance()->setAdditionalInformation('valid_days', $data->getData('additional_data')['valid_days']);
+
+ return parent::assignData($data);
+ }
}
\ No newline at end of file
diff --git a/Model/Paymentmethod/PaymentMethod.php b/Model/Paymentmethod/PaymentMethod.php
index a56ca34d..fdfc2ac9 100644
--- a/Model/Paymentmethod/PaymentMethod.php
+++ b/Model/Paymentmethod/PaymentMethod.php
@@ -25,6 +25,15 @@ abstract class PaymentMethod extends AbstractMethod
*/
protected $paynlConfig;
+ /**
+ * @var \Magento\Sales\Model\OrderRepository
+ */
+ protected $orderRepository;
+ /**
+ * @var \Magento\Sales\Model\Order\Config
+ */
+ protected $orderConfig;
+
public function __construct(
\Magento\Framework\Model\Context $context,
\Magento\Framework\Registry $registry,
@@ -33,6 +42,8 @@ public function __construct(
\Magento\Payment\Helper\Data $paymentData,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Payment\Model\Method\Logger $logger,
+ \Magento\Sales\Model\Order\Config $orderConfig,
+ \Magento\Sales\Model\OrderRepository $orderRepository,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = []
@@ -41,9 +52,25 @@ public function __construct(
$context, $registry, $extensionFactory, $customAttributeFactory,
$paymentData, $scopeConfig, $logger, $resource, $resourceCollection, $data );
+ $this->orderRepository = $orderRepository;
+ $this->orderConfig = $orderConfig;
$this->paynlConfig = new Config($this->_scopeConfig);
}
+ protected function getState($status){
+ $validStates = [
+ Order::STATE_NEW,
+ Order::STATE_PENDING_PAYMENT,
+ Order::STATE_HOLDED
+ ];
+
+ foreach($validStates as $state){
+ $statusses = $this->orderConfig->getStateStatuses($state, false);
+ if(in_array($status, $statusses)) return $state;
+ }
+ return false;
+ }
+
/**
* Get payment instructions text from config
*
@@ -58,19 +85,26 @@ public function getBanks(){
}
public function initialize($paymentAction, $stateObject)
{
- $state = $this->getConfigData('order_status');
- $stateObject->setState($state);
- $stateObject->setStatus($state);
+ $status = $this->getConfigData('order_status');
+
+ $stateObject->setState($this->getState($status));
+ $stateObject->setStatus($status);
$stateObject->setIsNotified(false);
$sendEmail = $this->_scopeConfig->getValue('payment/' . $this->_code . '/send_new_order_email', 'store');
+ $payment = $this->getInfoInstance();
+ /** @var Order $order */
+ $order = $payment->getOrder();
+
if($sendEmail == 'after_payment') {
//prevent sending the order confirmation
- $payment = $this->getInfoInstance();
- $order = $payment->getOrder();
$order->setCanSendNewEmailFlag( false );
}
+
+ $this->orderRepository->save($order);
+
+ return parent::initialize($paymentAction, $stateObject);
}
public function refund(\Magento\Payment\Model\InfoInterface $payment, $amount)
@@ -85,6 +119,13 @@ public function refund(\Magento\Payment\Model\InfoInterface $payment, $amount)
}
public function startTransaction(Order $order){
$transaction = $this->doStartTransaction($order);
+
+ $holded = $this->_scopeConfig->getValue('payment/' . $this->_code . '/holded', 'store');
+ if($holded){
+ $order->hold();
+ }
+ $this->orderRepository->save($order);
+
return $transaction->getRedirectUrl();
}
protected function doStartTransaction(Order $order)
diff --git a/etc/adminhtml/paymentmethods/overboeking.xml b/etc/adminhtml/paymentmethods/overboeking.xml
index dd2b417d..87e16264 100644
--- a/etc/adminhtml/paymentmethods/overboeking.xml
+++ b/etc/adminhtml/paymentmethods/overboeking.xml
@@ -25,12 +25,22 @@
- Paynl\Payment\Model\Config\Source\Order\Status\Holded
+ Paynl\Payment\Model\Config\Source\Order\Status\PendingPayment
1
payment/paynl_payment_overboeking/order_status
+
+
+ Magento\Config\Model\Config\Source\Yesno
+ payment/paynl_payment_overboeking/holded
+
+ 1
+
+
diff --git a/etc/adminhtml/paymentmethods/sofortbanking.xml b/etc/adminhtml/paymentmethods/sofortbanking.xml
index e180872d..fa9c1403 100644
--- a/etc/adminhtml/paymentmethods/sofortbanking.xml
+++ b/etc/adminhtml/paymentmethods/sofortbanking.xml
@@ -25,12 +25,22 @@
- Paynl\Payment\Model\Config\Source\Order\Status\Holded
+ Paynl\Payment\Model\Config\Source\Order\Status\PendingPayment
1
payment/paynl_payment_sofortbanking/order_status
+
+
+ Magento\Config\Model\Config\Source\Yesno
+ payment/paynl_payment_sofortbanking/holded
+
+ 1
+
+
diff --git a/etc/config.xml b/etc/config.xml
index ebf20f09..486ea112 100644
--- a/etc/config.xml
+++ b/etc/config.xml
@@ -12,7 +12,7 @@
1
Pay.nl betaallink
961
- pending_payment
+ pending
order
Paynl\Payment\Model\Paymentmethod\Paylink
@@ -232,12 +232,13 @@
0
Overboeking
136
- holded
+ pending
order
Paynl\Payment\Model\Paymentmethod\Overboeking
paynl_payment
before_payment
+ 1
0
@@ -287,7 +288,8 @@
0
Sofortbanking
559
- holded
+ pending_payment
+ 1
order
Paynl\Payment\Model\Paymentmethod\Sofortbanking