Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Adyen Magento2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shared Libs
Adyen Magento2
Commits
ec38adaa
Commit
ec38adaa
authored
Sep 18, 2015
by
rikterbeek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
notifications optimalizations
parent
482b60ba
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
128 additions
and
21 deletions
+128
-21
app/code/Adyen/Payment/Controller/Process/Json.php
app/code/Adyen/Payment/Controller/Process/Json.php
+2
-0
app/code/Adyen/Payment/Model/Cron.php
app/code/Adyen/Payment/Model/Cron.php
+115
-16
app/code/Adyen/Payment/Model/Method/AdyenAbstract.php
app/code/Adyen/Payment/Model/Method/AdyenAbstract.php
+1
-1
app/code/Adyen/Payment/Model/Method/Cc.php
app/code/Adyen/Payment/Model/Method/Cc.php
+5
-0
app/code/Adyen/Payment/Model/Method/Hpp.php
app/code/Adyen/Payment/Model/Method/Hpp.php
+5
-4
No files found.
app/code/Adyen/Payment/Controller/Process/Json.php
View file @
ec38adaa
...
...
@@ -49,6 +49,8 @@ class Json extends \Magento\Framework\App\Action\Action
// check duplicates
// _isDuplicate
try
{
$notificationItems
=
json_decode
(
file_get_contents
(
'php://input'
),
true
);
// $notificationItems = json_decode('{"live":"false","notificationItems":[{"NotificationRequestItem":{"additionalData":{"expiryDate":"12\/2012"," NAME1 ":"VALUE1","authCode":"1234","cardSummary":"7777","totalFraudScore":"10","hmacSignature":"yGnVWLP+UcpqjHTJbO5IUkG4ZdIk3uHCu62QAJvbbyg=","NAME2":" VALUE2 ","fraudCheck-6-ShopperIpUsage":"10"},"amount":{"currency":"EUR","value":10500},"eventCode":"AUTHORISATION","eventDate":"2015-09-11T13:53:21+02:00","merchantAccountCode":"MagentoMerchantByteShop1","merchantReference":"000000023","operations":["CANCEL","CAPTURE","REFUND"],"paymentMethod":"visa","pspReference":"test_AUTHORISATION_1","reason":"1234:7777:12\/2012","success":"true"}}]}', true);
...
...
app/code/Adyen/Payment/Model/Cron.php
View file @
ec38adaa
...
...
@@ -148,7 +148,7 @@ class Cron
$this
->
_debugData
[
'_updateOrder info'
]
=
'Going to cancel the order'
;
// if payment is API check, check if API result pspreference is the same as reference
if
(
$this
->
_eventCode
==
Adyen_Payment_Model_Event
::
ADYEN_EVENT_AUTHORISATION
&&
$this
->
_getPaymentMethodType
(
$this
->
_order
)
==
'api'
)
{
if
(
$this
->
_eventCode
==
Adyen_Payment_Model_Event
::
ADYEN_EVENT_AUTHORISATION
&&
$this
->
_getPaymentMethodType
()
==
'api'
)
{
if
(
$this
->
_pspReference
==
$this
->
_order
->
getPayment
()
->
getAdyenPspReference
())
{
// don't cancel the order if previous state is authorisation with success=true
if
(
$previousAdyenEventCode
!=
"AUTHORISATION : TRUE"
)
{
...
...
@@ -300,6 +300,10 @@ class Cron
return
$this
->
_order
->
getPayment
()
->
getMethod
();
}
protected
function
_getPaymentMethodType
()
{
return
$this
->
_order
->
getPayment
()
->
getPaymentMethodType
();
}
/**
* @desc order comments or history
* @param type $order
...
...
@@ -386,7 +390,7 @@ class Cron
if
(
$ignoreHasInvoice
||
!
$this
->
_order
->
hasInvoices
())
{
$this
->
_order
->
setActionFlag
(
$orderStatus
,
true
);
if
(
$orderStatus
==
Mage_Sales_Model_
Order
::
STATE_HOLDED
)
{
if
(
$orderStatus
==
\Magento\Sales\Model\
Order
::
STATE_HOLDED
)
{
if
(
$this
->
_order
->
canHold
())
{
$this
->
_order
->
hold
();
}
else
{
...
...
@@ -421,9 +425,9 @@ class Cron
case
Notification
::
REFUND
:
$ignoreRefundNotification
=
$this
->
_getConfigData
(
'ignore_refund_notification'
,
'adyen_abstract'
,
$this
->
_order
->
getStoreId
());
if
(
$ignoreRefundNotification
!=
true
)
{
$this
->
_refundOrder
(
$this
->
_order
);
$this
->
_refundOrder
();
//refund completed
$this
->
_setRefundAuthorized
(
$this
->
_order
);
$this
->
_setRefundAuthorized
();
}
else
{
$this
->
_debugData
[
'_processNotification info'
]
=
'Setting to ignore refund notification is enabled so ignore this notification'
;
}
...
...
@@ -465,7 +469,7 @@ class Cron
}
else
{
// uncancel the order just to be sure that order is going trough
$this
->
_uncancelOrder
(
$this
->
_order
);
//
$this->_uncancelOrder($this->_order);
// FOR POS authorize the payment on the CAPTURE notification
$this
->
_authorizePayment
(
$this
->
_order
,
$this
->
_paymentMethod
);
...
...
@@ -481,22 +485,22 @@ class Cron
if
(
$this
->
_modificationResult
==
"cancel"
)
{
$this
->
_holdCancelOrder
(
true
);
}
elseif
(
$this
->
_modificationResult
==
"refund"
)
{
$this
->
_refundOrder
(
$this
->
_order
);
$this
->
_refundOrder
();
//refund completed
$this
->
_setRefundAuthorized
(
$this
->
_order
);
$this
->
_setRefundAuthorized
();
}
}
else
{
$orderStatus
=
$this
->
_getConfigData
(
'order_status'
,
'adyen_abstract'
,
$this
->
_order
->
getStoreId
());
if
((
$orderStatus
!=
Mage_Sales_Model_Order
::
STATE_HOLDED
&&
$this
->
_order
->
canCancel
())
||
(
$orderStatus
==
Mage_Sales_Model_Order
::
STATE_HOLDED
&&
$this
->
_order
->
canHold
()))
{
// cancel order
if
(
$this
->
_order
->
isCanceled
()
||
$this
->
_order
->
getState
()
===
\Magento\Sales\Model\Order
::
STATE_HOLDED
)
{
$this
->
_debugData
[
'_processNotification info'
]
=
'Order is already cancelled or holded so do nothing'
;
}
else
if
(
$this
->
_order
->
canCancel
()
||
$this
->
_order
->
canHold
())
{
$this
->
_debugData
[
'_processNotification info'
]
=
'try to cancel the order'
;
$this
->
_holdCancelOrder
(
true
);
$this
->
_holdCancelOrder
(
$this
->
_order
,
true
);
}
else
{
$this
->
_debugData
[
'_processNotification info'
]
=
'try to refund the order'
;
// refund
$this
->
_refundOrder
(
$this
->
_order
);
$this
->
_refundOrder
();
//refund completed
$this
->
_setRefundAuthorized
(
$this
->
_order
);
$this
->
_setRefundAuthorized
();
}
}
break
;
...
...
@@ -506,6 +510,74 @@ class Cron
}
}
/**
* Not implemented
* @return bool
*/
protected
function
_refundOrder
()
{
$this
->
_debugData
[
'_refundOrder'
]
=
'Refunding the order'
;
// // Don't create a credit memo if refund is initialize in Magento because in this case the credit memo already exits
// $result = Mage::getModel('adyen/event')
// ->getEvent($this->_pspReference, '[refund-received]');
// if (!empty($result)) {
// $this->_debugData['_refundOrder ignore'] = 'Skip refund process because credit memo is already created';
// return false;
// }
//
// $_mail = (bool) $this->_getConfigData('send_update_mail', 'adyen_abstract', $order->getStoreId());
//
// $currency = $order->getOrderCurrencyCode(); // use orderCurrency because adyen respond in the same currency as in the request
// $amount = Mage::helper('adyen')->originalAmount($this->_value, $currency);
//
// if ($order->canCreditmemo()) {
// $service = Mage::getModel('sales/service_order', $order);
// $creditmemo = $service->prepareCreditmemo();
// $creditmemo->getOrder()->setIsInProcess(true);
//
// //set refund data on the order
// $creditmemo->setGrandTotal($amount);
// $creditmemo->setBaseGrandTotal($amount);
// $creditmemo->save();
//
// try {
// Mage::getModel('core/resource_transaction')
// ->addObject($creditmemo)
// ->addObject($creditmemo->getOrder())
// ->save();
// //refund
// $creditmemo->refund();
// $transactionSave = Mage::getModel('core/resource_transaction')
// ->addObject($creditmemo)
// ->addObject($creditmemo->getOrder());
// if ($creditmemo->getInvoice()) {
// $transactionSave->addObject($creditmemo->getInvoice());
// }
// $transactionSave->save();
// if ($_mail) {
// $creditmemo->getOrder()->setCustomerNoteNotify(true);
// $creditmemo->sendEmail();
// }
// $this->_debugData['_refundOrder done'] = 'Credit memo is created';
// } catch (Exception $e) {
// $this->_debugData['_refundOrder error'] = 'Error creating credit memo error message is: ' . $e->getMessage();
// Mage::logException($e);
// }
// } else {
// $this->_debugData['_refundOrder error'] = 'Order can not be refunded';
// }
}
/**
* @param $order
*/
protected
function
_setRefundAuthorized
()
{
$this
->
_debugData
[
'_setRefundAuthorized'
]
=
'Status update to default status or refund_authorized status if this is set'
;
$this
->
_order
->
addStatusHistoryComment
(
__
(
'Adyen Refund Successfully completed'
));
}
/**
*
*/
...
...
@@ -538,7 +610,7 @@ class Cron
if
((
$this
->
_paymentMethod
==
"c_cash"
&&
$this
->
_getConfigData
(
'create_shipment'
,
'adyen_cash'
,
$this
->
_order
->
getStoreId
()))
||
(
$this
->
_getConfigData
(
'create_shipment'
,
'adyen_pos'
,
$this
->
_order
->
getStoreId
())
&&
$_paymentCode
==
"adyen_pos"
))
{
$this
->
_createShipment
(
$this
->
_order
);
$this
->
_createShipment
();
}
}
...
...
@@ -736,9 +808,9 @@ class Cron
// if amount is zero create a offline invoice
$value
=
(
int
)
$this
->
_value
;
if
(
$value
==
0
)
{
$invoice
->
setRequestedCaptureCase
(
Mage_Sales_Model_Order_
Invoice
::
CAPTURE_OFFLINE
);
$invoice
->
setRequestedCaptureCase
(
\Magento\Sales\Model\Order\
Invoice
::
CAPTURE_OFFLINE
);
}
else
{
$invoice
->
setRequestedCaptureCase
(
Mage_Sales_Model_Order_
Invoice
::
NOT_CAPTURE
);
$invoice
->
setRequestedCaptureCase
(
\Magento\Sales\Model\Order\
Invoice
::
NOT_CAPTURE
);
}
$invoice
->
register
();
...
...
@@ -844,6 +916,33 @@ class Cron
$this
->
_debugData
[
'_setPaymentAuthorized end'
]
=
'Order status is changed to authorised status, status is '
.
$status
;
}
/**
*
*/
protected
function
_createShipment
()
{
$this
->
_debugData
[
'_createShipment'
]
=
'Creating shipment for order'
;
// create shipment for cash payment
$payment
=
$this
->
_order
->
getPayment
()
->
getMethodInstance
();
if
(
$this
->
_order
->
canShip
())
{
$itemQty
=
array
();
$shipment
=
$this
->
_order
->
prepareShipment
(
$itemQty
);
if
(
$shipment
)
{
$shipment
->
register
();
$shipment
->
getOrder
()
->
setIsInProcess
(
true
);
$comment
=
__
(
'Shipment created by Adyen'
);
$shipment
->
addComment
(
$comment
);
Mage
::
getModel
(
'core/resource_transaction'
)
->
addObject
(
$shipment
)
->
addObject
(
$shipment
->
getOrder
())
->
save
();
$this
->
_debugData
[
'_createShipment done'
]
=
'Order is shipped'
;
}
}
else
{
$this
->
_debugData
[
'_createShipment error'
]
=
'Order can\'t be shipped'
;
}
}
/**
* Retrieve information from payment configuration
...
...
app/code/Adyen/Payment/Model/Method/AdyenAbstract.php
View file @
ec38adaa
...
...
@@ -14,7 +14,7 @@ use Magento\Payment\Model\Method\Online\GatewayInterface;
*/
class
AdyenAbstract
extends
\Magento\Payment\Model\Method\AbstractMethod
implements
GatewayInterface
{
const
METHOD_CODE
=
'adyen_
hpp
'
;
const
METHOD_CODE
=
'adyen_
abstract
'
;
/**
* @var string
...
...
app/code/Adyen/Payment/Model/Method/Cc.php
View file @
ec38adaa
...
...
@@ -93,6 +93,11 @@ class Cc extends \Magento\Payment\Model\Method\Cc
$this
->
_adyenLogger
=
$adyenLogger
;
}
protected
$_paymentMethodType
=
'api'
;
public
function
getPaymentMethodType
()
{
return
$this
->
_paymentMethodType
;
}
public
function
isActive
(
$storeId
=
null
)
{
...
...
app/code/Adyen/Payment/Model/Method/Hpp.php
View file @
ec38adaa
...
...
@@ -92,6 +92,11 @@ class Hpp extends \Magento\Payment\Model\Method\AbstractMethod implements Gatewa
$this
->
storeManager
=
$storeManager
;
}
protected
$_paymentMethodType
=
'hpp'
;
public
function
getPaymentMethodType
()
{
return
$this
->
_paymentMethodType
;
}
public
function
isAvailable
(
$quote
=
null
)
{
$this
->
_logger
->
critical
(
"HPP IS AVAILABLE!! IS TRUE"
);
...
...
@@ -120,10 +125,6 @@ class Hpp extends \Magento\Payment\Model\Method\AbstractMethod implements Gatewa
default
:
break
;
}
// magento 1.x code from our plugin
// $state = Mage_Sales_Model_Order::STATE_NEW;
// $stateObject->setState($state);
// $stateObject->setStatus($this->_getConfigData('order_status'));
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment