Skip to content

Commit

Permalink
PHP 7.4 support
Browse files Browse the repository at this point in the history
  • Loading branch information
chandan-PS committed Jul 30, 2021
1 parent bb24c7c commit a9b1de4
Show file tree
Hide file tree
Showing 39 changed files with 440 additions and 118 deletions.
5 changes: 5 additions & 0 deletions Block/Webpayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,4 +367,9 @@ public function getSessionId()
{
return $this->session->getSessionId();
}

public function is3DsEnabled()
{
return $this->_helper->is3DSecureEnabled() || $this->_helper->isDynamic3DEnabled();
}
}
2 changes: 1 addition & 1 deletion Controller/Adminhtml/Cancel/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(
\Sapient\Worldpay\Model\Order\Service $orderservice,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Sapient\Worldpay\Helper\GeneralException $helper,
\Sapient\Worldpay\Model\PaymentMethods\AbstractMethod $abstractMethod
\Sapient\Worldpay\Model\PaymentMethods\PaymentOperations $abstractMethod
) {

parent::__construct($context);
Expand Down
8 changes: 7 additions & 1 deletion Controller/Adminhtml/Recurring/Plan/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ public function __construct(
public function execute()
{
$data = $this->getRequest()->getPostValue();
$productId = $this->getRequest()->getParam('product_id');
//$productId = $this->getRequest()->getParam('product_id');
$url = parse_url($this->_redirect->getRefererUrl());
$path_parts=explode('/', $url['path']);
if (in_array('id', $path_parts)) {
$key = array_search('id', $path_parts);
$productId = $path_parts[$key+1];
}
$store=$this->storeManager->getWebsite($data['website_id'])->getCode();
if ($data && $productId) {
$data['code'] = $this->buildCode(
Expand Down
4 changes: 2 additions & 2 deletions Controller/Adminhtml/Syncstatus/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Index extends \Magento\Backend\App\Action
* @param \Sapient\Worldpay\Model\Payment\Service $paymentservice,
* @param \Sapient\Worldpay\Model\Token\WorldpayToken $worldpaytoken,
* @param \Sapient\Worldpay\Model\Order\Service $orderservice,
* @param \Sapient\Worldpay\Model\PaymentMethods\AbstractMethod $abstractMethod
* @param \Sapient\Worldpay\Model\PaymentMethods\PaymentOperations $abstractMethod
*/
public function __construct(
Context $context,
Expand All @@ -45,7 +45,7 @@ public function __construct(
\Sapient\Worldpay\Model\Token\WorldpayToken $worldpaytoken,
\Sapient\Worldpay\Model\Order\Service $orderservice,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Sapient\Worldpay\Model\PaymentMethods\AbstractMethod $abstractMethod,
\Sapient\Worldpay\Model\PaymentMethods\PaymentOperations $abstractMethod,
\Sapient\Worldpay\Helper\GeneralException $helper
) {

Expand Down
4 changes: 2 additions & 2 deletions Controller/Adminhtml/VoidSale/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Index extends \Magento\Backend\App\Action
* @param \Sapient\Worldpay\Model\Order\Service $orderservice
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
@param \Sapient\Worldpay\Helper\GeneralException $helper
@param \Sapient\Worldpay\Model\PaymentMethods\AbstractMethod $abstractMethod
@param \Sapient\Worldpay\Model\PaymentMethods\PaymentOperations $abstractMethod
*/
public function __construct(
Context $context,
Expand All @@ -47,7 +47,7 @@ public function __construct(
\Sapient\Worldpay\Model\Order\Service $orderservice,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Sapient\Worldpay\Helper\GeneralException $helper,
\Sapient\Worldpay\Model\PaymentMethods\AbstractMethod $abstractMethod
\Sapient\Worldpay\Model\PaymentMethods\PaymentOperations $abstractMethod
) {

parent::__construct($context);
Expand Down
4 changes: 3 additions & 1 deletion Controller/Button/PlaceOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public function execute()
if ($dfReferenceId) {
$this->checkoutSession->setDfReferenceId($dfReferenceId);
$this->checkoutSession->setInstantPurchaseOrder(true);
$this->checkoutSession->setInstantPurchaseRedirectUrl($this->_redirect->getRefererUrl());
}
}
try {
Expand Down Expand Up @@ -175,7 +176,8 @@ public function execute()
$threeDSecureChallengeParams = $this->checkoutSession->get3Ds2Params();
$this->messageManager->getMessages(true);
if ($threeDSecureChallengeParams || ($redirectData = $this->checkoutSession->get3DSecureParams())) {
$this->checkoutSession->setInstantPurchaseMessage($message);
$this->checkoutSession->setInstantPurchaseRedirectUrl($this->_redirect->getRefererUrl());
$this->checkoutSession->setInstantPurchaseMessage($message);
$message = __('');
} else {
return $this->createResponse($message, true);
Expand Down
17 changes: 17 additions & 0 deletions Controller/Hostedpaymentpage/Challenge.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ public function __construct(

public function execute()
{
if (isset($_COOKIE['PHPSESSID'])) {
$phpsessId = $_COOKIE['PHPSESSID'];
if (phpversion() < '7.3.0') {
setcookie("PHPSESSID", $phpsessId, time() + 3600, "/; SameSite=None; Secure;");
}else {
$domain = parse_url($this->_url->getUrl(), PHP_URL_HOST);
setcookie("PHPSESSID", $phpsessId, [
'expires' => time() + 3600,
'path' => '/',
'domain' => $domain,
'secure' => true,
'httponly' => true,
'samesite' => 'None',
]);
}
}

return $this->_pageFactory->create();
}
}
14 changes: 9 additions & 5 deletions Controller/Notification/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Index extends \Magento\Framework\App\Action\Action
* @param \Sapient\Worldpay\Model\Payment\Service $paymentservice
* @param \Sapient\Worldpay\Model\Token\WorldpayToken $worldpaytoken
* @param \Sapient\Worldpay\Model\Order\Service $orderservice
* @param \Sapient\Worldpay\Model\PaymentMethods\AbstractMethod $abstractMethod
* @param \Sapient\Worldpay\Model\PaymentMethods\PaymentOperations $abstractMethod
* @param \Sapient\Worldpay\Model\HistoryNotificationFactory $historyNotification
*/
public function __construct(
Expand All @@ -46,7 +46,7 @@ public function __construct(
\Sapient\Worldpay\Model\Payment\Service $paymentservice,
\Sapient\Worldpay\Model\Token\WorldpayToken $worldpaytoken,
\Sapient\Worldpay\Model\Order\Service $orderservice,
\Sapient\Worldpay\Model\PaymentMethods\AbstractMethod $abstractMethod,
\Sapient\Worldpay\Model\PaymentMethods\PaymentOperations $abstractMethod,
\Sapient\Worldpay\Model\HistoryNotificationFactory $historyNotification
) {
parent::__construct($context);
Expand Down Expand Up @@ -79,7 +79,8 @@ public function execute()
}
} catch (Exception $e) {
$this->wplogger->error($e->getMessage());
if ($e->getMessage() == 'invalid state transition' || $e->getMessage() == 'same state') {
if ($e->getMessage() == 'invalid state transition' || $e->getMessage() == 'same state'
|| $e->getMessage() == 'Notification received for Partial Captutre') {
return $this->_returnOk();
} else {
return $this->_returnFailure();
Expand All @@ -106,6 +107,9 @@ public function _getRawBody()
*/
private function _createPaymentUpdate($xmlRequest)
{
$this->wplogger->info('########## Received notification ##########');
$this->wplogger->info($this->_getRawBody());
$this->paymentservice->getPaymentUpdateXmlForNotification($this->_getRawBody());
$this->_paymentUpdate = $this->paymentservice
->createPaymentUpdateFromWorldPayXml($xmlRequest);

Expand All @@ -114,8 +118,8 @@ private function _createPaymentUpdate($xmlRequest)

private function _logNotification()
{
$this->wplogger->info('########## Received notification ##########');
$this->wplogger->info($this->_getRawBody());
// $this->wplogger->info('########## Received notification ##########');
// $this->wplogger->info($this->_getRawBody());
$this->wplogger->info('########## Payment update of type: ' .
get_class($this->_paymentUpdate). ' created ##########');
}
Expand Down
18 changes: 16 additions & 2 deletions Controller/Savedcard/AddnewcardPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,12 @@ public function execute()
'cardHolderName' => $fullRequest->payment->cardHolderName,
'expiryMonth' => $fullRequest->payment->expiryMonth,
'expiryYear' => $fullRequest->payment->expiryYear,
'cvc' => $fullRequest->payment->cvc,
'cseEnabled' => $fullRequest->payment->cseEnabled
];
if (isset($fullRequest->payment->cvc) &&
!$fullRequest->payment->cvc == '' && !empty($fullRequest->payment->cvc)) {
$payment['cvc'] = $fullRequest->payment->cvc;
}
if ($this->worldpayHelper->isDynamic3DS2Enabled() && $fullRequest->payment->dfReferenceId) {
$payment['dfReferenceId'] = $fullRequest->payment->dfReferenceId;
$this->checkoutSession->setIavCall(true);
Expand All @@ -246,11 +249,12 @@ public function execute()
$payment['dynamicInteractionType'] = $this->worldpayHelper->getDynamicIntegrationType($paymentType);
$orderParams = [];
$incrementId = $this->_generateOrderCode();
$isNominalAmount = $payment['paymentType'] =='DINERS-SSL' || $payment['paymentType'] == 'DANKORT-SSL' ;
$orderParams['orderCode'] = $incrementId. '-' . time();
$orderParams['merchantCode'] = $merchantCode;
$orderParams['orderDescription'] = 'Add new card in My account';
$orderParams['currencyCode'] = $currencyCode;
$orderParams['amount'] = 0;
$orderParams['amount'] = $isNominalAmount?1: 0;
$orderParams['paymentDetails'] = $payment;
$orderParams['cardAddress'] = $billingadd;
$orderParams['billingAddress'] = $billingadd;
Expand Down Expand Up @@ -292,6 +296,14 @@ public function execute()
$directResponse = $this->directResponse->setResponse($response);
$threeDSecureParams = $directResponse->get3dSecureParams();
$threeDSecureChallengeParams = $directResponse->get3ds2Params();
if(!$this->worldpayHelper->is3dsEnabled() && isset($threeDSecureParams)) {
$this->wplogger->info("3Ds attempted but 3DS is not enabled for the store. Please contact merchant.");
$this->messageManager->addErrorMessage(
"3Ds attempted but 3DS is not enabled for the store. Please contact merchant. ");
//return $this->resultRedirectFactory->create()->setPath('worldpay/savedcard', ['_current' => true]);
return $this->resultJsonFactory->create()->setData(['success' => false]);

}
$threeDSecureConfig = [];
$disclaimerFlag = isset($fullRequest->payment->disclaimerFlag)?$fullRequest->payment->disclaimerFlag:0 ;

Expand Down Expand Up @@ -360,6 +372,8 @@ public function execute()
->getCreditCardSpecificException('CCAM22')));
} else {
$this->messageManager->addException($e, __('Error: ').$e->getMessage());
return $this->resultJsonFactory->create()
->setData(['threeDError' => true]);
}
return $this->resultJsonFactory->create()
->setData(['success' => false]);
Expand Down
4 changes: 3 additions & 1 deletion Controller/Savedcard/Instantredirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ public function __construct(

public function execute()
{
$threeDSecureChallengeParams = $this->checkoutSession->get3Ds2Params();
$threeDSecureChallengeParams = $this->checkoutSession->get3Ds2Params();
$instantRedirectUrl = $this->_redirect->getRefererUrl();

// $this->messageManager->getMessages(true);
if ($redirectData = $this->checkoutSession->get3DSecureParams()) {
$this->checkoutSession->setInstantPurchaseOrder(true);
$this->checkoutSession->setInstantPurchaseRedirectUrl($instantRedirectUrl);
return $this->resultRedirectFactory->create()->setPath('worldpay/threedsecure/auth', ['_current' => true]);
} elseif ($threeDSecureChallengeParams) {
Expand Down
35 changes: 31 additions & 4 deletions Controller/ThreeDSecure/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,38 @@ public function execute()
$orderId = $this->checkoutSession->getAuthOrderId();
$iframe = false;
// Chrome 84 releted updates for 3DS
$phpsessId = $_COOKIE['PHPSESSID'];
setcookie("PHPSESSID", $phpsessId, time() + 3600, "/; SameSite=None; Secure;");
if ($threeDSecureChallengeConfig['challengeWindowType'] == 'iframe') {
$iframe = true;

if (isset($_COOKIE['PHPSESSID'])) {
$phpsessId = $_COOKIE['PHPSESSID'];
if (phpversion() < '7.3.0') {
setcookie("PHPSESSID", $phpsessId, time() + 3600, "/; SameSite=None; Secure;");
} else {
$domain = parse_url($this->_url->getUrl(), PHP_URL_HOST);
setcookie("PHPSESSID", $phpsessId, [
'expires' => time() + 3600,
'path' => '/',
'domain' => $domain,
'secure' => true,
'httponly' => true,
'samesite' => 'None',
]);
}
}

//setcookie("PHPSESSID", $phpsessId, time() + 3600, "/; SameSite=None; Secure;");



if (!$threeDSecureChallengeConfig == null) {

if ($threeDSecureChallengeConfig['challengeWindowType'] == 'iframe') {
$iframe = true;
}
}
if ($redirectData = $this->checkoutSession->get3DSecureParams()) {
// Chrome 84 releted updates for 3DS
// $phpsessId = $_COOKIE['PHPSESSID'];
// setcookie("PHPSESSID", $phpsessId, time() + 3600, "/; SameSite=None; Secure;");
$responseUrl = $this->_url->getUrl('worldpay/threedsecure/authresponse', ['_secure' => true]);
print_r('
<form name="theForm" id="form" method="POST" action=' . $redirectData->getUrl() . '>
Expand Down Expand Up @@ -90,6 +116,7 @@ public function execute()
</script>
');
} else {
ob_start();
$authUrl = $this->_url->getUrl('worldpay/threedsecure/ChallengeAuthResponse', ['_secure' => true]);
print_r('
<form name= "challengeForm" id="challengeForm"
Expand Down
2 changes: 1 addition & 1 deletion Controller/ThreeDSecure/AuthResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function execute()
}
}
if ($this->checkoutSession->getInstantPurchaseOrder()) {
$redirectUrl = $this->checkoutSession->getInstantPurchaseRedirectUrl();
$redirectUrl = $this->checkoutSession->getInstantPurchaseRedirectUrl();
$this->checkoutSession->unsInstantPurchaseRedirectUrl();
$this->checkoutSession->unsInstantPurchaseOrder();
$message=$this->checkoutSession->getInstantPurchaseMessage();
Expand Down
16 changes: 15 additions & 1 deletion Controller/ThreeDSecure/ChallengeAuthResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,20 @@ public function __construct(
* authorised, update order and redirect to the checkout success page.
*/
public function execute()
{
{
if (isset($_COOKIE['PHPSESSID'])) {
$phpsessId = $_COOKIE['PHPSESSID'];
$domain = parse_url($this->_url->getUrl(), PHP_URL_HOST);
setcookie("PHPSESSID", $phpsessId, [
'expires' => time() + 3600,
'path' => '/',
'domain' => $domain,
'secure' => true,
'httponly' => true,
'samesite' => 'None',
]);
}

$directOrderParams = $this->checkoutSession->getDirectOrderParams();
$threeDSecureParams = $this->checkoutSession->get3Ds2Params();
$this->checkoutSession->unsDirectOrderParams();
Expand All @@ -79,6 +92,7 @@ public function execute()
}
if ($this->checkoutSession->getInstantPurchaseOrder()) {
$redirectUrl = $this->checkoutSession->getInstantPurchaseRedirectUrl();

$this->checkoutSession->unsInstantPurchaseRedirectUrl();
$this->checkoutSession->unsInstantPurchaseOrder();
//$this->getResponse()->setRedirect($redirectUrl);
Expand Down
2 changes: 1 addition & 1 deletion Cron/OrderSyncStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private function _applyPaymentUpdate()
try {
$this->_paymentUpdate->apply($this->_order->getPayment(), $this->_order);
} catch (Exception $e) {
throw new \Magento\Framework\Exception\LocalizedException($e->getMessage());
throw new \Magento\Framework\Exception\LocalizedException(__($e->getMessage()));
}
}

Expand Down
38 changes: 25 additions & 13 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,12 @@ public function getLiveUrl()

public function getMerchantCode($paymentType)
{
$merchat_detail = $this->merchantprofile->getConfigValue($paymentType);
$merchantCodeValue = $merchat_detail['merchant_code'];
if (!empty($merchantCodeValue)) {
return $merchantCodeValue;
if ($paymentType) {
$merchat_detail = $this->merchantprofile->getConfigValue($paymentType);
$merchantCodeValue = $merchat_detail?$merchat_detail['merchant_code']: '';
if (!empty($merchantCodeValue)) {
return $merchantCodeValue;
}
}
return $this->_scopeConfig->getValue(
'worldpay/general_config/merchant_code',
Expand All @@ -106,10 +108,12 @@ public function getMerchantCode($paymentType)

public function getXmlUsername($paymentType)
{
$merchat_detail = $this->merchantprofile->getConfigValue($paymentType);
$merchantCodeValue = $merchat_detail['merchant_username'];
if (!empty($merchantCodeValue)) {
return $merchantCodeValue;
if ($paymentType) {
$merchat_detail = $this->merchantprofile->getConfigValue($paymentType);
$merchantCodeValue = $merchat_detail?$merchat_detail['merchant_username']:'';
if (!empty($merchantCodeValue)) {
return $merchantCodeValue;
}
}
return $this->_scopeConfig->getValue(
'worldpay/general_config/xml_username',
Expand All @@ -119,10 +123,12 @@ public function getXmlUsername($paymentType)

public function getXmlPassword($paymentType)
{
$merchat_detail = $this->merchantprofile->getConfigValue($paymentType);
$merchantCodeValue = $merchat_detail['merchant_password'];
if (!empty($merchantCodeValue)) {
return $merchantCodeValue;
if ($paymentType) {
$merchat_detail = $this->merchantprofile->getConfigValue($paymentType);
$merchantCodeValue = $merchat_detail?$merchat_detail['merchant_password']:'';
if (!empty($merchantCodeValue)) {
return $merchantCodeValue;
}
}
return $this->_scopeConfig->getValue(
'worldpay/general_config/xml_password',
Expand Down Expand Up @@ -173,6 +179,11 @@ public function is3DSecureEnabled()
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}

public function is3dsEnabled()
{
return $this->isDynamic3DEnabled() || $this->is3DSecureEnabled();
}

public function isLoggerEnable()
{
Expand Down Expand Up @@ -1038,7 +1049,8 @@ public function getSavedCardsCount($customerId)
->addFieldToSelect(['id'])
->addFieldToFilter('customer_id', ['eq' => $customerId])
->addFieldToFilter('created_at', ['lteq' => $now->format('Y-m-d H:i:s')])
->addFieldToFilter('created_at', ['gteq' => $lastDay->format('Y-m-d H:i:s')]);
// ->addFieldToFilter('created_at', ['gteq' => $lastDay->format('Y-m-d H:i:s')]
;
return count($savedCards->getData());
}
public function getGlobalCurrencyExponent()
Expand Down
Loading

0 comments on commit a9b1de4

Please sign in to comment.