Skip to content

Commit

Permalink
Manual transfer and Sofort orders will be put on hold.
Browse files Browse the repository at this point in the history
This will prevent magento from automatically canceling the order.
  • Loading branch information
Andy Pieters committed Aug 15, 2016
1 parent 2eea625 commit 02f70a7
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 45 deletions.
20 changes: 20 additions & 0 deletions Model/Config/Source/Order/Status/Holded.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* Copyright © 2015 Pay.nl All rights reserved.
*/

namespace Paynl\Payment\Model\Config\Source\Order\Status;

use Magento\Sales\Model\Order;
use Magento\Sales\Model\Config\Source\Order\Status;

/**
* Order Status source model
*/
class Holded extends Status
{
/**
* @var string[]
*/
protected $_stateStatuses = [Order::STATE_HOLDED];
}
99 changes: 58 additions & 41 deletions Model/Paymentmethod/PaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Paynl\Payment\Model\Paymentmethod;

use Magento\Framework\UrlInterface;
use \Magento\Payment\Model\Method\AbstractMethod;
use Magento\Payment\Model\Method\AbstractMethod;
use Magento\Sales\Model\Order;
use Paynl\Payment\Model\Config;

Expand All @@ -20,6 +20,7 @@ abstract class PaymentMethod extends AbstractMethod
protected $_isInitializeNeeded = true;

protected $_canRefund = false;

/**
* Get payment instructions text from config
*
Expand All @@ -30,10 +31,6 @@ public function getInstructions()
return trim($this->getConfigData('instructions'));
}

public function getPaymentOptionId(){
return $this->getConfigData('payment_option_id');
}

public function initialize($paymentAction, $stateObject)
{
$state = $this->getConfigData('order_status');
Expand All @@ -42,8 +39,8 @@ public function initialize($paymentAction, $stateObject)
$stateObject->setIsNotified(false);
}


public function startTransaction(Order $order, UrlInterface $url){
public function startTransaction(Order $order, UrlInterface $url)
{
$config = new Config($this->_scopeConfig);

$config->configureSDK();
Expand All @@ -61,40 +58,50 @@ public function startTransaction(Order $order, UrlInterface $url){

$paymentOptionId = $this->getPaymentOptionId();

$arrBillingAddress = $order->getBillingAddress()->toArray();

$arrShippingAddress = $order->getShippingAddress()->toArray();
$arrBillingAddress = $order->getBillingAddress();
if ($arrBillingAddress) {
$arrBillingAddress = $arrBillingAddress->toArray();

$enduser = array(
'initials' => substr($arrBillingAddress['firstname'], 0, 1),
'lastName' => $arrBillingAddress['lastname'],
'phoneNumber' => $arrBillingAddress['telephone'],
'emailAddress' => $arrBillingAddress['email'],
);

$invoiceAddress = array(
'initials' => substr($arrBillingAddress['firstname'], 0, 1),
'lastName' => $arrBillingAddress['lastname']
);
$enduser = array(
'initials' => substr($arrBillingAddress['firstname'], 0, 1),
'lastName' => $arrBillingAddress['lastname'],
'phoneNumber' => $arrBillingAddress['telephone'],
'emailAddress' => $arrBillingAddress['email'],
);

$invoiceAddress = array(
'initials' => substr($arrBillingAddress['firstname'], 0, 1),
'lastName' => $arrBillingAddress['lastname']
);

$arrAddress = \Paynl\Helper::splitAddress($arrBillingAddress['street']);
$invoiceAddress['streetName'] = $arrAddress[0];
$invoiceAddress['houseNumber'] = $arrAddress[1];
$invoiceAddress['zipCode'] = $arrBillingAddress['postcode'];
$invoiceAddress['city'] = $arrBillingAddress['city'];
$invoiceAddress['country'] = $arrBillingAddress['country_id'];
$arrAddress = \Paynl\Helper::splitAddress($arrBillingAddress['street']);
$invoiceAddress['streetName'] = $arrAddress[0];
$invoiceAddress['houseNumber'] = $arrAddress[1];
$invoiceAddress['zipCode'] = $arrBillingAddress['postcode'];
$invoiceAddress['city'] = $arrBillingAddress['city'];
$invoiceAddress['country'] = $arrBillingAddress['country_id'];

$shippingAddress = array(
'initials' => substr($arrShippingAddress['firstname'], 0, 1),
'lastName' => $arrShippingAddress['lastname']
);
$arrAddress2 = \Paynl\Helper::splitAddress($arrShippingAddress['street']);
$shippingAddress['streetName'] = $arrAddress2[0];
$shippingAddress['houseNumber'] = $arrAddress2[1];
$shippingAddress['zipCode'] = $arrShippingAddress['postcode'];
$shippingAddress['city'] = $arrShippingAddress['city'];
$shippingAddress['country'] = $arrShippingAddress['country_id'];
}

$arrShippingAddress = $order->getShippingAddress();
if ($arrShippingAddress) {
$arrShippingAddress = $arrShippingAddress->toArray();


$shippingAddress = array(
'initials' => substr($arrShippingAddress['firstname'], 0, 1),
'lastName' => $arrShippingAddress['lastname']
);
$arrAddress2 = \Paynl\Helper::splitAddress($arrShippingAddress['street']);
$shippingAddress['streetName'] = $arrAddress2[0];
$shippingAddress['houseNumber'] = $arrAddress2[1];
$shippingAddress['zipCode'] = $arrShippingAddress['postcode'];
$shippingAddress['city'] = $arrShippingAddress['city'];
$shippingAddress['country'] = $arrShippingAddress['country_id'];

}
$data = array(
'amount' => $total,
'returnUrl' => $returnUrl,
Expand All @@ -105,16 +112,21 @@ public function startTransaction(Order $order, UrlInterface $url){
'exchangeUrl' => $exchangeUrl,
'currency' => $currency,
);
$data['address'] = $shippingAddress;
$data['invoiceAddress'] = $invoiceAddress;

$data['enduser'] = $enduser;
if(isset($shippingAddress)){
$data['address'] = $shippingAddress;
}
if(isset($invoiceAddress)) {
$data['invoiceAddress'] = $invoiceAddress;
}
if(isset($enduser)){
$data['enduser'] = $enduser;
}
$arrProducts = array();
foreach ($items as $item) {
$arrItem = $item->toArray();
if ($arrItem['price_incl_tax'] != null) {
// taxamount is not valid, because on discount it returns the taxamount after discount
$taxAmount = $arrItem['price_incl_tax']-$arrItem['price'];
$taxAmount = $arrItem['price_incl_tax'] - $arrItem['price'];
$product = array(
'id' => $arrItem['product_id'],
'name' => $arrItem['name'],
Expand Down Expand Up @@ -149,7 +161,7 @@ public function startTransaction(Order $order, UrlInterface $url){
'name' => $discountDescription,
'price' => $discount,
'qty' => 1,
'tax' => $order->getDiscountTaxCompensationAmount()*-1
'tax' => $order->getDiscountTaxCompensationAmount() * -1
);
}

Expand All @@ -164,4 +176,9 @@ public function startTransaction(Order $order, UrlInterface $url){

return $transaction->getRedirectUrl();
}

public function getPaymentOptionId()
{
return $this->getConfigData('payment_option_id');
}
}
2 changes: 1 addition & 1 deletion etc/adminhtml/paymentmethods/overboeking.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<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>
<source_model>Paynl\Payment\Model\Config\Source\Order\Status\Holded</source_model>
<depends>
<field id="active">1</field>
</depends>
Expand Down
2 changes: 1 addition & 1 deletion etc/adminhtml/paymentmethods/sofortbanking.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<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>
<source_model>Paynl\Payment\Model\Config\Source\Order\Status\Holded</source_model>
<depends>
<field id="active">1</field>
</depends>
Expand Down
4 changes: 2 additions & 2 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
<active>0</active>
<title>Overboeking</title>
<payment_option_id>136</payment_option_id>
<order_status>pending_payment</order_status>
<order_status>holded</order_status>
<instructions></instructions>
<payment_action>order</payment_action>
<model>Paynl\Payment\Model\Paymentmethod\Overboeking</model>
Expand Down Expand Up @@ -192,7 +192,7 @@
<active>0</active>
<title>Sofortbanking</title>
<payment_option_id>559</payment_option_id>
<order_status>pending_payment</order_status>
<order_status>holded</order_status>
<instructions></instructions>
<payment_action>order</payment_action>
<model>Paynl\Payment\Model\Paymentmethod\Sofortbanking</model>
Expand Down

0 comments on commit 02f70a7

Please sign in to comment.