diff --git a/Block/Addnewcard.php b/Block/Addnewcard.php index 90adaef2..f5f16d14 100644 --- a/Block/Addnewcard.php +++ b/Block/Addnewcard.php @@ -14,6 +14,39 @@ class Addnewcard extends \Magento\Framework\View\Element\Template * @var \Magento\Customer\Model\Session */ protected $_customerSession; + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $worldpayHelper; + + /** + * @var \Magento\Customer\Helper\Session\CurrentCustomerAddress + */ + protected $currentCustomerAddress; + + /** + * @var \Magento\Customer\Model\Address\Config + */ + protected $_addressConfig; + /** + * @var \Magento\Customer\Model\Address\Mapper + */ + protected $addressMapper; + /** + * @var \Magento\Framework\App\Config\ScopeConfigInterface + */ + protected $scopeConfig; + + /** + * @var \Magento\Framework\Message\ManagerInterface + */ + protected $_messageManager; + + /** + * @var \Magento\Integration\Model\Oauth\TokenFactory + */ + protected $_tokenModelFactory; + /** * @var array */ diff --git a/Block/Adminhtml/Form/Field/Paymentmethod.php b/Block/Adminhtml/Form/Field/Paymentmethod.php index d77a7839..08522df4 100644 --- a/Block/Adminhtml/Form/Field/Paymentmethod.php +++ b/Block/Adminhtml/Form/Field/Paymentmethod.php @@ -6,7 +6,10 @@ class Paymentmethod extends \Magento\Framework\View\Element\Html\Select { - + /** + * @var \Sapient\Worldpay\Model\Utilities\PaymentMethods + */ + public $paymentutils; /** * Paymentmethod constructor. * diff --git a/Block/Adminhtml/Order/View/View.php b/Block/Adminhtml/Order/View/View.php index 21444a01..8751a50b 100644 --- a/Block/Adminhtml/Order/View/View.php +++ b/Block/Adminhtml/Order/View/View.php @@ -15,11 +15,22 @@ class View extends \Magento\Backend\Block\Template */ protected $_worldpaymentFactory; + /** + * @var \Sapient\Worldpay\Helper\Multishipping + */ + protected $multishippingHelper; + + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $helper; + /** * @param \Magento\Backend\Block\Template\Context $context * @param \Magento\Framework\Registry $registry * @param \Sapient\Worldpay\Model\WorldpaymentFactory $worldpaymentFactory * @param \Sapient\Worldpay\Helper\Multishipping $multishippingHelper + * @param \Sapient\Worldpay\Helper\Data $worldpayhelper * @param array $data */ public function __construct( @@ -27,11 +38,13 @@ public function __construct( \Magento\Framework\Registry $registry, \Sapient\Worldpay\Model\WorldpaymentFactory $worldpaymentFactory, \Sapient\Worldpay\Helper\Multishipping $multishippingHelper, + \Sapient\Worldpay\Helper\Data $worldpayhelper, array $data = [] ) { $this->registry = $registry; $this->_worldpaymentFactory= $worldpaymentFactory; $this->multishippingHelper = $multishippingHelper; + $this->helper = $worldpayhelper; parent::__construct($context, $data); } /** @@ -105,4 +118,32 @@ public function getMultishippingOrderIds() $multishipping_orders = substr($multishipping_orders, 1); return $multishipping_orders; } + /** + * Retrieve Worldpay Xml user name + * + * @param string $paymentType + * @param boolean $ismultishipping + * @return string + */ + public function getXmluserName($paymentType, $ismultishipping) + { + $xmlUsername = $this->helper->getXmlUsername($paymentType); + $paymentMethod= $this->getPaymentMethod(); + if ($ismultishipping) { + $msMerchantUn = $this->helper->getMultishippingMerchantUsername(); + $xmlUsername = !empty($msMerchantUn) ? $msMerchantUn : $xmlUsername; + } + + if ($paymentMethod=='worldpay_moto') { + $xmlUsernameMoto = $this->helper->getMotoUsername(); + $xmlUsername = !empty($xmlUsernameMoto) ? $xmlUsernameMoto : $xmlUsername; + } + + if ($paymentMethod=='worldpay_paybylink') { + $pblMerchantUn = $this->helper->getPayByLinkMerchantUsername(); + $xmlUsername = !empty($pblMerchantUn) ? $pblMerchantUn : $xmlUsername; + } + + return $xmlUsername; + } } diff --git a/Block/Adminhtml/System/Config/Editor.php b/Block/Adminhtml/System/Config/Editor.php index 6960e160..bcaac7e4 100644 --- a/Block/Adminhtml/System/Config/Editor.php +++ b/Block/Adminhtml/System/Config/Editor.php @@ -7,6 +7,10 @@ class Editor extends \Magento\Config\Block\System\Config\Form\Field { + /** + * @var WysiwygConfig + */ + protected $_wysiwygConfig; /** * @var Registry */ diff --git a/Block/ApplePay/Button.php b/Block/ApplePay/Button.php index ee2c7920..ff8212d1 100644 --- a/Block/ApplePay/Button.php +++ b/Block/ApplePay/Button.php @@ -27,6 +27,16 @@ class Button extends Template */ protected $session; + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $worldpayHelper; + /** * Button constructor. * @param Context $context @@ -36,7 +46,7 @@ class Button extends Template */ public function __construct( Context $context, - \Sapient\Worldpay\Logger\WorldpayLogger $wplogger, + WorldpayLogger $wplogger, \Sapient\Worldpay\Helper\Data $helper, array $data = [] ) { diff --git a/Block/Catalog/Product/SubscriptionPlans.php b/Block/Catalog/Product/SubscriptionPlans.php index d6faace0..12c5b39a 100644 --- a/Block/Catalog/Product/SubscriptionPlans.php +++ b/Block/Catalog/Product/SubscriptionPlans.php @@ -23,6 +23,11 @@ class SubscriptionPlans extends \Magento\Catalog\Block\Product\AbstractProduct */ private $encoder; + /** + * @var Data + */ + private $worldpayHelper; + /** * @param \Magento\Catalog\Block\Product\Context $context * @param \Sapient\Worldpay\Helper\Recurring $recurringHelper diff --git a/Block/Challenge.php b/Block/Challenge.php index aaf85eb7..eae41ed6 100644 --- a/Block/Challenge.php +++ b/Block/Challenge.php @@ -6,10 +6,10 @@ class Challenge extends \Magento\Framework\View\Element\Template { /** - * @var Sapient\Worldpay\Helper\Data; + * @var \Sapient\Worldpay\Helper\Data; */ - protected $helper; + protected $_helper; /** * @var \Magento\Checkout\Model\Session diff --git a/Block/Checkout/Hpp/ChallengeIframe.php b/Block/Checkout/Hpp/ChallengeIframe.php index 47b57647..1c47c90e 100644 --- a/Block/Checkout/Hpp/ChallengeIframe.php +++ b/Block/Checkout/Hpp/ChallengeIframe.php @@ -6,6 +6,10 @@ class ChallengeIframe extends \Magento\Framework\View\Element\Template { + /** + * @var \Sapient\Worldpay\Model\Checkout\Hpp\Json\Config\Factory + */ + public $configfactory; /** * Constructor * diff --git a/Block/Checkout/Hpp/Json/Config.php b/Block/Checkout/Hpp/Json/Config.php index 72976039..43a73d0c 100644 --- a/Block/Checkout/Hpp/Json/Config.php +++ b/Block/Checkout/Hpp/Json/Config.php @@ -6,7 +6,14 @@ class Config extends \Magento\Framework\View\Element\Template { - + /** + * @var \Sapient\Worldpay\Model\Checkout\Hpp\Json\Config\Factory + */ + public $configfactory; + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + public $wplogger; /** * Constructor * diff --git a/Block/Checkout/Multishipping/Billing.php b/Block/Checkout/Multishipping/Billing.php index 33e28d1e..72b89649 100644 --- a/Block/Checkout/Multishipping/Billing.php +++ b/Block/Checkout/Multishipping/Billing.php @@ -60,6 +60,10 @@ class Billing extends \Magento\Multishipping\Block\Checkout\Billing * @var \Sapient\Worldpay\Helper\Data */ protected $wpHelper; + /** + * @var CheckoutHelper + */ + protected $checkoutHelper; /** * Constructor @@ -74,10 +78,10 @@ class Billing extends \Magento\Multishipping\Block\Checkout\Billing * @param PriceCurrencyInterface $priceCurrency * @param \Magento\Quote\Model\Quote\TotalsCollector $totalsCollector * @param \Magento\Quote\Model\Quote\TotalsReader $totalsReader - * @param Sapient\Worldpay\Helper\Data $wpHelper + * @param CheckoutHelper $checkoutHelper + * @param \Sapient\Worldpay\Helper\Data $wpHelper * @param array $data * @param array $additionalChecks - * @param ?CheckoutHelper $checkoutHelper = null */ public function __construct( @@ -91,15 +95,16 @@ public function __construct( PriceCurrencyInterface $priceCurrency, \Magento\Quote\Model\Quote\TotalsCollector $totalsCollector, \Magento\Quote\Model\Quote\TotalsReader $totalsReader, + CheckoutHelper $checkoutHelper, \Sapient\Worldpay\Helper\Data $wpHelper, array $data = [], - array $additionalChecks = [], - ?CheckoutHelper $checkoutHelper = null, + array $additionalChecks = [] ) { $this->_multishipping = $multishipping; $this->_checkoutSession = $checkoutSession; $this->paymentSpecification = $paymentSpecification; - $data['checkoutHelper'] = $checkoutHelper ?? ObjectManager::getInstance()->get(CheckoutHelper::class); + $this->checkoutHelper = $checkoutHelper; + $data['checkoutHelper'] = $this->checkoutHelper; $this->_taxHelper = $taxHelper; $data['taxHelper'] = $this->_taxHelper; $this->wpHelper = $wpHelper; @@ -124,12 +129,8 @@ public function __construct( */ protected function _prepareLayout() { - if ($this->isWorldpayEnable()) { - $this->setTemplate('Sapient_Worldpay::multishipping/billing/billing.phtml'); - $this->pageConfig->addBodyClass('worldpay-multishipping'); - } else { - $this->setTemplate('Magento_Multishipping::checkout/billing.phtml'); - } + $this->setTemplate('Sapient_Worldpay::multishipping/billing/billing.phtml'); + $this->pageConfig->addBodyClass('worldpay-multishipping'); return parent::_prepareLayout(); } /** @@ -384,4 +385,45 @@ public function isWorldpayEnable() { return $this->wpHelper->isWorldPayEnable(); } + /** + * Get worldpay method code + */ + public function getWorldpayMethodsCode() + { + return [ + 'worldpay_cc', + 'worldpay_apm', + 'worldpay_wallets' + ]; + } + /** + * Get Worldpay Methods + */ + public function getWorldpayMethods() + { + $allMethods = $this->getMethods(); + $wpMethods = $this->getWorldpayMethodsCode(); + $wpPaymentMethods = []; + foreach ($allMethods as $method) { + if (in_array($method->getCode(), $wpMethods)) { + $wpPaymentMethods[] = $method; + } + } + return $wpPaymentMethods; + } + /** + * Get other Payment methods + */ + public function getOtherPaymentMethods() + { + $allMethods = $this->getMethods(); + $wpMethods = $this->getWorldpayMethodsCode(); + $otherPaymentMethods = []; + foreach ($allMethods as $method) { + if (!in_array($method->getCode(), $wpMethods)) { + $otherPaymentMethods[] = $method; + } + } + return $otherPaymentMethods; + } } diff --git a/Block/Edit.php b/Block/Edit.php index f947a225..da5ca0ff 100644 --- a/Block/Edit.php +++ b/Block/Edit.php @@ -14,6 +14,11 @@ class Edit extends \Magento\Framework\View\Element\Template * @var \Magento\Customer\Model\Session */ protected $_customerSession; + + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $worldpayHelper; /** * @var array */ diff --git a/Block/Form/Card.php b/Block/Form/Card.php index f2ca0f96..67e90a2a 100644 --- a/Block/Form/Card.php +++ b/Block/Form/Card.php @@ -18,6 +18,46 @@ class Card extends \Magento\Payment\Block\Form * @var worldpayPaymentsMoto */ private $worldpayPaymentsMoto; + + /** + * @var \Sapient\Worldpay\Model\WorldpayConfigProvider + */ + private $configProvider; + + /** + * @var \Magento\Framework\Registry + */ + private $_coreRegistry; + + /** + * @var \Magento\Backend\Model\Session\Quote + */ + private $adminquotesession; + + /** + * @var \Sapient\Worldpay\Helper\Data + */ + private $worldpayhelper; + + /** + * @var \Sapient\Worldpay\Model\Payment\LatAmInstalTypes + */ + private $latamtypes; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + private $wplogger; + + /** + * @var \Sapient\Worldpay\Model\Payment\PaymentTypes + */ + private $paymenttypes; + + /** + * @var \Magento\Backend\Model\Session\Quote + */ + private $adminsessionquote; /** * Constructor * diff --git a/Block/GooglePay/Button.php b/Block/GooglePay/Button.php index 19ec4e53..3a8505dd 100644 --- a/Block/GooglePay/Button.php +++ b/Block/GooglePay/Button.php @@ -33,6 +33,11 @@ class Button extends Template * @var SessionManagerInterface */ protected $session; + + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $worldpayHelper; /** * Button constructor. diff --git a/Block/Jwt.php b/Block/Jwt.php index 9851d470..4906c3b8 100644 --- a/Block/Jwt.php +++ b/Block/Jwt.php @@ -6,10 +6,10 @@ class Jwt extends \Magento\Framework\View\Element\Template { /** - * @var Sapient\Worldpay\Helper\Data; + * @var Data; */ - protected $helper; + protected $_helper; /** * @var \Magento\Framework\Url\DecoderInterface @@ -19,7 +19,7 @@ class Jwt extends \Magento\Framework\View\Element\Template /** * Jwt constructor * - * @param Context $context + * @param \Magento\Framework\View\Element\Template\Context $context * @param string $helper * @param \Magento\Framework\Url\DecoderInterface $decoder */ diff --git a/Block/Multishipping/Paybylink/Email/Addresses.php b/Block/Multishipping/Paybylink/Email/Addresses.php new file mode 100644 index 00000000..58c66f5f --- /dev/null +++ b/Block/Multishipping/Paybylink/Email/Addresses.php @@ -0,0 +1,79 @@ + + */ +namespace Sapient\Worldpay\Block\Multishipping\Paybylink\Email; + +/** + * Sales Order Email items. + * + * @api + * @since 100.0.2 + */ +class Addresses extends \Magento\Framework\View\Element\Template +{ + + /** + * @var \Magento\Customer\Model\Address\Config + */ + protected $_addressConfig = null; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + + /** + * @var \Magento\Quote\Api\CartRepositoryInterface + */ + protected $quoteRepository; + /** + * constructor + * + * @param \Magento\Backend\Block\Template\Context $context + * @param \Magento\Customer\Model\Address\Config $addressConfig, + * @param \Sapient\Worldpay\Logger\WorldpayLogger $wplogger + * @param array $data + */ + public function __construct( + \Magento\Backend\Block\Template\Context $context, + \Magento\Customer\Model\Address\Config $addressConfig, + \Sapient\Worldpay\Logger\WorldpayLogger $wplogger, + \Magento\Quote\Api\CartRepositoryInterface $quoteRepository, + array $data = [] + ) { + $this->wplogger = $wplogger; + $this->_addressConfig = $addressConfig; + $this->quoteRepository = $quoteRepository; + parent::__construct($context, $data); + } + + /** + * Get Multishipping Shipment Addresses + */ + public function getQuote() + { + $quote_id = $this->getData('quote_id'); + $quote = $this->quoteRepository->get($quote_id); + return $quote; + } + + /** + * Format Shipping Address + * + * @param array $address + * @return array + */ + public function getFormatAddressByCode($address) + { + $renderer = $this->_addressConfig->getFormatByCode('html')->getRenderer(); + return $renderer->renderArray($address); + } +} diff --git a/Block/Multishipping/Paybylink/Success.php b/Block/Multishipping/Paybylink/Success.php new file mode 100644 index 00000000..6619b8b9 --- /dev/null +++ b/Block/Multishipping/Paybylink/Success.php @@ -0,0 +1,21 @@ +httpContext = $httpContext; $this->customerSession = $customerSession; $this->_customerUrl = $customerUrl; + $this->jsLayout = isset($data['jsLayout']) && is_array($data['jsLayout']) ? $data['jsLayout'] : []; + $this->serializer = $serializer; } /** @@ -163,4 +181,14 @@ public function checkCustomerLogin() } return false; } + + /** + * Get JS layout + * + * @return string + */ + public function getJsLayout() + { + return $this->serializer->serialize($this->jsLayout); + } } diff --git a/Block/PaymentRequestApi.php b/Block/PaymentRequestApi.php deleted file mode 100644 index 6bd7b059..00000000 --- a/Block/PaymentRequestApi.php +++ /dev/null @@ -1,72 +0,0 @@ -httpHeader = $httpHeader; - parent::__construct( - $context, - $data - ); - } - /** - * Get User Agent - * - * @return string - */ - - public function getUserAgent() - { - return $this->httpHeader->getHttpUserAgent(); - } - /** - * Get Payment Api Script - * - * @return string - */ - - public function getPaymentApiScript() - { - $script = ''; - return $script; - } -} diff --git a/Block/Recurring/Customer/Subscriptions/Edit.php b/Block/Recurring/Customer/Subscriptions/Edit.php index d85931cc..9964c3e4 100644 --- a/Block/Recurring/Customer/Subscriptions/Edit.php +++ b/Block/Recurring/Customer/Subscriptions/Edit.php @@ -20,7 +20,7 @@ //use Sapient\Worldpay\Model\Ui\CcConfigProvider; -class Edit extends \Magento\Framework\View\Element\Template +class Edit extends Template { /** * @var \Sapient\Worldpay\Model\Recurring\Subscription|null @@ -54,6 +54,10 @@ class Edit extends \Magento\Framework\View\Element\Template * @var IconsProvider */ private $iconsProvider; + /** + * @var Data + */ + private $helper; /** * @param Template\Context $context diff --git a/Block/SavedCardLink.php b/Block/SavedCardLink.php index 371dc81e..b7b428c2 100644 --- a/Block/SavedCardLink.php +++ b/Block/SavedCardLink.php @@ -27,6 +27,14 @@ class SavedCardLink extends \Magento\Framework\View\Element\Html\Link\Current */ protected $_scopeConfig = null; + /** + * @var WorldpayConfigProvider + */ + protected $config; + /** + * @var Data + */ + protected $helper; /** * Constructor * diff --git a/Block/Savedcard.php b/Block/Savedcard.php index 5197158c..f68de54a 100644 --- a/Block/Savedcard.php +++ b/Block/Savedcard.php @@ -16,6 +16,25 @@ class Savedcard extends \Magento\Framework\View\Element\Template * @var \Magento\Customer\Model\Session */ protected $_customerSession; + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $worlpayhelper; + /** + * @var \Magento\Customer\Helper\Session\CurrentCustomerAddress + */ + protected $currentCustomerAddress; + + /** + * @var \Magento\Customer\Model\Address\Config + */ + protected $_addressConfig; + + /** + * @var \Magento\Customer\Model\Address\Mapper + */ + protected $addressMapper; + /** * @var SerializerInterface */ diff --git a/Block/SubscriptionsLink.php b/Block/SubscriptionsLink.php index 3126eeb5..8bccda90 100644 --- a/Block/SubscriptionsLink.php +++ b/Block/SubscriptionsLink.php @@ -27,6 +27,20 @@ class SubscriptionsLink extends \Magento\Framework\View\Element\Html\Link\Curren * @var _scopeConfig */ protected $_scopeConfig = null; + /** + * @var Subscriptions + */ + protected $subscriptionconfig; + + /** + * @var Recurring + */ + protected $helper; + + /** + * @var Recurring + */ + protected $worldpayHelper; /** * Constructor diff --git a/Block/Wallets.php b/Block/Wallets.php index 0e3b17c1..8c4d62f0 100644 --- a/Block/Wallets.php +++ b/Block/Wallets.php @@ -36,6 +36,41 @@ class Wallets extends \Magento\Catalog\Block\Product\AbstractProduct */ protected $session; + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $worldpayHelper; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + + /** + * @var CustomerRepository + */ + protected $customerRepository; + + /** + * @var CustomerSession + */ + protected $customerSession; + + /** + * @var CustomerAddressDataProvider + */ + protected $customerAddressData; + + /** + * @var \Magento\Directory\Helper\Data + */ + protected $directoryData; + + /** + * @var \Sapient\Worldpay\Helper\Recurring + */ + protected $recurringHelper; + /** * Button constructor * @@ -54,7 +89,7 @@ class Wallets extends \Magento\Catalog\Block\Product\AbstractProduct public function __construct( \Magento\Catalog\Block\Product\Context $context, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, - \Magento\Framework\Session\SessionManagerInterface $session, + SessionManagerInterface $session, \Sapient\Worldpay\Logger\WorldpayLogger $wplogger, \Sapient\Worldpay\Helper\Data $helper, CustomerRepository $customerRepository, diff --git a/Block/Webpayment.php b/Block/Webpayment.php index 4b388cea..f919db8c 100644 --- a/Block/Webpayment.php +++ b/Block/Webpayment.php @@ -65,8 +65,33 @@ class Webpayment extends Template private $serializer; /** - * @var httpRequest + * @var Data */ + protected $_helper; + + /** + * @var AbstractCart + */ + protected $_cart; + + /** + * @var Session + */ + protected $_customerSession; + + /** + * @var \Magento\Integration\Model\Oauth\TokenFactory + */ + protected $_tokenModelFactory; + + /** + * @var SessionManagerInterface + */ + protected $session; + + /** + * @var \Magento\Framework\App\Request\Http + */ protected $httpRequest; /** diff --git a/Controller/Adminhtml/Cancel/Index.php b/Controller/Adminhtml/Cancel/Index.php index 96279a43..2ac7962d 100644 --- a/Controller/Adminhtml/Cancel/Index.php +++ b/Controller/Adminhtml/Cancel/Index.php @@ -21,6 +21,30 @@ class Index extends \Magento\Backend\App\Action * @var $pageFactory */ protected $pageFactory; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + /** + * @var \Sapient\Worldpay\Model\Payment\Service + */ + protected $paymentservice; + /** + * @var \Sapient\Worldpay\Model\Order\Service + */ + protected $orderservice; + + /** + * @var JsonFactory + */ + protected $resultJsonFactory; + + /** + * @var \Sapient\Worldpay\Model\Token\WorldpayToken + */ + protected $worldpaytoken; + /** * @var $_rawBody */ diff --git a/Controller/Adminhtml/Recurring/Plan/Save.php b/Controller/Adminhtml/Recurring/Plan/Save.php index 2a31543e..816875bf 100644 --- a/Controller/Adminhtml/Recurring/Plan/Save.php +++ b/Controller/Adminhtml/Recurring/Plan/Save.php @@ -23,6 +23,15 @@ class Save extends \Sapient\Worldpay\Controller\Adminhtml\Recurring\Plan * @var \Magento\Store\Model\StoreManagerInterface */ private $storeManager; + /** + * @var \Magento\Framework\Locale\FormatInterface + */ + private $localeFormat; + + /** + * @var \Laminas\Uri\Uri + */ + private $uri; /** * Constructor diff --git a/Controller/Adminhtml/Syncstatus/Index.php b/Controller/Adminhtml/Syncstatus/Index.php index d316e49f..36197ba7 100644 --- a/Controller/Adminhtml/Syncstatus/Index.php +++ b/Controller/Adminhtml/Syncstatus/Index.php @@ -52,6 +52,31 @@ class Index extends \Magento\Backend\App\Action */ private $abstractMethod; + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + private $wplogger; + + /** + * @var \Sapient\Worldpay\Model\Payment\Service + */ + private $paymentservice; + + /** + * @var \Sapient\Worldpay\Model\Token\WorldpayToken + */ + private $worldpaytoken; + + /** + * @var \Sapient\Worldpay\Model\Order\Service + */ + private $orderservice; + + /** + * @var JsonFactory + */ + private $resultJsonFactory; + /** * Constructor * diff --git a/Controller/Adminhtml/VoidSale/Index.php b/Controller/Adminhtml/VoidSale/Index.php index 1bfae62c..68014813 100644 --- a/Controller/Adminhtml/VoidSale/Index.php +++ b/Controller/Adminhtml/VoidSale/Index.php @@ -52,6 +52,32 @@ class Index extends \Magento\Backend\App\Action */ private $abstractMethod; + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + private $wplogger; + /** + * @var \Sapient\Worldpay\Model\Payment\Service + */ + + private $paymentservice; + + /** + * @var \Sapient\Worldpay\Model\Order\Service + */ + + private $orderservice; + + /** + * @var JsonFactory + */ + private $resultJsonFactory; + + /** + * @var \Sapient\Worldpay\Model\Token\WorldpayToken + */ + private $worldpaytoken; + /** * Constructor * diff --git a/Controller/Adminhtml/motoRedirectResult/Cancel.php b/Controller/Adminhtml/motoRedirectResult/Cancel.php index 8dccd095..8ed8a2d0 100644 --- a/Controller/Adminhtml/motoRedirectResult/Cancel.php +++ b/Controller/Adminhtml/motoRedirectResult/Cancel.php @@ -31,6 +31,43 @@ class Cancel extends \Magento\Backend\App\Action private $_paymentUpdate; + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + + /** + * @var \Sapient\Worldpay\Model\Payment\Service + */ + protected $paymentservice; + + /** + * @var \Sapient\Worldpay\Model\Order\Service + */ + + protected $orderservice; + + /** + * @var JsonFactory + */ + protected $resultJsonFactory; + + /** + * @var \Sapient\Worldpay\Model\Adminhtml\Order\Service + */ + protected $adminorderservice; + /** + * @var \Sapient\Worldpay\Model\Request\AuthenticationService + */ + protected $authenticatinservice; + /** + * @var \Sapient\Worldpay\Model\Payment\StateResponse + */ + protected $paymentStateResponse; + /** + * @var \Sapient\Worldpay\Model\Payment\WpResponse + */ + protected $wpresponse; /** * Constructor * diff --git a/Controller/Adminhtml/motoRedirectResult/Failure.php b/Controller/Adminhtml/motoRedirectResult/Failure.php index 9068ebc1..71d5aaea 100644 --- a/Controller/Adminhtml/motoRedirectResult/Failure.php +++ b/Controller/Adminhtml/motoRedirectResult/Failure.php @@ -14,7 +14,26 @@ */ class Failure extends \Magento\Backend\App\Action { - + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + + /** + * @var \Sapient\Worldpay\Model\Order\Service + */ + + protected $orderservice; + + /** + * @var JsonFactory + */ + protected $resultJsonFactory; + + /** + * @var \Sapient\Worldpay\Model\Adminhtml\Order\Service + */ + protected $adminorderservice; /** * Constructor * diff --git a/Controller/Adminhtml/motoRedirectResult/Success.php b/Controller/Adminhtml/motoRedirectResult/Success.php index b34131c2..3b4f18de 100644 --- a/Controller/Adminhtml/motoRedirectResult/Success.php +++ b/Controller/Adminhtml/motoRedirectResult/Success.php @@ -14,6 +14,21 @@ */ class Success extends \Magento\Backend\App\Action { + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + + /** + * @var \Sapient\Worldpay\Model\Order\Service + */ + + protected $orderservice; + + /** + * @var JsonFactory + */ + protected $resultJsonFactory; /** * Constructor * diff --git a/Controller/Applepay/Index.php b/Controller/Applepay/Index.php index a86a551e..3bc17a2c 100644 --- a/Controller/Applepay/Index.php +++ b/Controller/Applepay/Index.php @@ -23,7 +23,37 @@ class Index extends \Magento\Framework\App\Action\Action * @var curlHelper */ public $curlHelper; - + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + public $wplogger; + /** + * @var \Sapient\Worldpay\Model\Payment\Service + */ + public $paymentservice; + + /** + * @var \Sapient\Worldpay\Model\Order\Service + */ + public $orderservice; + /** + * @var JsonFactory + */ + public $resultJsonFactory; + /** + * @var \Magento\Framework\App\Request\Http + */ + public $request; + /** + * @var \Magento\Framework\App\Config\ScopeConfigInterface + */ + public $scopeConfig; + /** + * @var \Magento\Checkout\Model\Cart + */ + public $cart; + /** * Constructor * @@ -33,6 +63,7 @@ class Index extends \Magento\Framework\App\Action\Action * @param \Sapient\Worldpay\Model\Payment\Service $paymentservice * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Framework\App\Request\Http $request + * @param \Magento\Checkout\Model\Cart $cart * @param \Sapient\Worldpay\Helper\CurlHelper $curlHelper * @param \Magento\Framework\Filesystem\Driver\file $fileDriver */ @@ -44,6 +75,7 @@ public function __construct( \Sapient\Worldpay\Model\Payment\Service $paymentservice, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\App\Request\Http $request, + \Magento\Checkout\Model\Cart $cart, \Sapient\Worldpay\Helper\CurlHelper $curlHelper, \Magento\Framework\Filesystem\Driver\file $fileDriver ) { @@ -53,6 +85,7 @@ public function __construct( $this->resultJsonFactory = $resultJsonFactory; $this->scopeConfig = $scopeConfig; $this->request = $request; + $this->cart = $cart; $this->curlHelper = $curlHelper; $this->fileDriver = $fileDriver; } @@ -82,12 +115,8 @@ public function execute() $validation_url = $this->request->getParam('u'); if ($validation_url == 'getTotal') { - - $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); - $cart = $objectManager->get(\Magento\Checkout\Model\Cart::class); - - $subTotal = $cart->getQuote()->getSubtotal(); - $grandTotal = $cart->getQuote()->getGrandTotal(); + $subTotal = $this->cart->getQuote()->getSubtotal(); + $grandTotal = $this->cart->getQuote()->getGrandTotal(); $resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON); $resultJson->setData($grandTotal); diff --git a/Controller/Button/PlaceOrder.php b/Controller/Button/PlaceOrder.php index 923331d7..fa711ebe 100644 --- a/Controller/Button/PlaceOrder.php +++ b/Controller/Button/PlaceOrder.php @@ -76,6 +76,15 @@ class PlaceOrder extends Action */ private $orderRepository; + /** + * @var \Magento\Checkout\Model\Session + */ + private $checkoutSession; + /** + * @var \Magento\Framework\App\Response\RedirectInterface + */ + private $redirect; + /** * @param Context $context * @param StoreManagerInterface $storeManager diff --git a/Controller/Cartdetails/Chromepay.php b/Controller/Cartdetails/Chromepay.php index 8d580b01..98524c12 100644 --- a/Controller/Cartdetails/Chromepay.php +++ b/Controller/Cartdetails/Chromepay.php @@ -19,6 +19,11 @@ class Chromepay extends \Magento\Framework\App\Action\Action * @var $_authSession */ protected $_authSession; + + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $worldpayHelper; /** * Constructor * diff --git a/Controller/Hostedpaymentpage/Challenge.php b/Controller/Hostedpaymentpage/Challenge.php index 2f244bcd..27a28aa1 100644 --- a/Controller/Hostedpaymentpage/Challenge.php +++ b/Controller/Hostedpaymentpage/Challenge.php @@ -19,6 +19,16 @@ class Challenge extends \Magento\Framework\App\Action\Action * @var $cookieMetadataFactory */ protected $cookieMetadataFactory; + + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $worldpayHelper; + + /** + * @var \Magento\Checkout\Model\Session + */ + protected $checkoutSession; /** * Constructor * diff --git a/Controller/Hostedpaymentpage/Pay.php b/Controller/Hostedpaymentpage/Pay.php index 467e5f67..02c4d420 100644 --- a/Controller/Hostedpaymentpage/Pay.php +++ b/Controller/Hostedpaymentpage/Pay.php @@ -14,7 +14,7 @@ class Pay extends \Magento\Framework\App\Action\Action { /** - * @var Magento\Framework\View\Result\PageFactory + * @var \Magento\Framework\View\Result\PageFactory */ protected $pageFactory; @@ -22,6 +22,21 @@ class Pay extends \Magento\Framework\App\Action\Action * @var \Sapient\Worldpay\Model\Checkout\Hpp\State */ protected $_status; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + + /** + * @var \Sapient\Worldpay\Model\Checkout\Hpp\State + */ + protected $hppstate; + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $worldpayhelper; + /** * Constructor * diff --git a/Controller/Notification/Index.php b/Controller/Notification/Index.php index 8f93431a..bb8b1bb2 100644 --- a/Controller/Notification/Index.php +++ b/Controller/Notification/Index.php @@ -46,6 +46,39 @@ class Index extends \Magento\Framework\App\Action\Action */ protected $fileDriver; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + public $wplogger; + /** + * @var \Sapient\Worldpay\Model\Payment\Service + */ + public $paymentservice; + /** + * @var \Sapient\Worldpay\Model\Order\Service + */ + public $orderservice; + /** + * @var JsonFactory + */ + public $resultJsonFactory; + + /** + * @var \Sapient\Worldpay\Model\Token\WorldpayToken + */ + public $worldpaytoken; + + /** + * @var object + */ + public $_paymentUpdate; + + /** + * @var object + */ + public $_order; + /** * Constructor * diff --git a/Controller/Paybylink/Cancel.php b/Controller/Paybylink/Cancel.php index 5bb31e15..65bca3c0 100644 --- a/Controller/Paybylink/Cancel.php +++ b/Controller/Paybylink/Cancel.php @@ -19,6 +19,59 @@ class Cancel extends \Magento\Framework\App\Action\Action */ protected $pageFactory; + /** + * @var \Sapient\Worldpay\Model\Order\Service + */ + protected $orderservice; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + + /** + * @var \Sapient\Worldpay\Model\Payment\Service + */ + protected $paymentservice; + /** + * @var \Sapient\Worldpay\Model\Checkout\Service + */ + protected $checkoutservice; + + /** + * @var \Sapient\Worldpay\Model\Request\AuthenticationService + */ + protected $authenticatinservice; + /** + * @var \Sapient\Worldpay\Model\Payment\StateResponse + */ + protected $paymentStateResponse; + + /** + * @var \Sapient\Worldpay\Model\Payment\WpResponse + */ + protected $wpresponse; + + /** + * @var \Magento\Sales\Model\Order + */ + protected $order; + + /** + * @var \Sapient\Worldpay\Model\Payment\MultishippingStateResponse + */ + protected $multishippingStateResponse; + + /** + * @var \Magento\Quote\Api\CartRepositoryInterface + */ + protected $quoteRepository; + + /** + * @var \Sapient\Worldpay\Model\ResourceModel\Multishipping\Order\Collection + */ + protected $wpMultishippingCollection; + /** * Constructor * @@ -31,7 +84,10 @@ class Cancel extends \Magento\Framework\App\Action\Action * @param \Sapient\Worldpay\Model\Payment\StateResponse $paymentStateResponse * @param \Sapient\Worldpay\Logger\WorldpayLogger $wplogger * @param \Sapient\Worldpay\Model\Payment\WpResponse $wpresponse - * @param \Magento\Sales\Model\Order $orderItemsDetails + * @param \Magento\Sales\Model\Order $order + * @param \Sapient\Worldpay\Model\Payment\MultishippingStateResponse $multishippingStateResponse + * @param \Magento\Quote\Api\CartRepositoryInterface $quoteRepository + * @param \Sapient\Worldpay\Model\ResourceModel\Multishipping\Order\Collection $wpMultishippingCollection */ public function __construct( Context $context, @@ -43,7 +99,10 @@ public function __construct( \Sapient\Worldpay\Model\Payment\StateResponseFactory $paymentStateResponse, \Sapient\Worldpay\Logger\WorldpayLogger $wplogger, \Sapient\Worldpay\Model\Payment\WpResponse $wpresponse, - \Magento\Sales\Model\Order $orderItemsDetails + \Magento\Sales\Model\Order $order, + \Sapient\Worldpay\Model\Payment\MultishippingStateResponse $multishippingStateResponse, + \Magento\Quote\Api\CartRepositoryInterface $quoteRepository, + \Sapient\Worldpay\Model\ResourceModel\Multishipping\Order\Collection $wpMultishippingCollection ) { $this->pageFactory = $pageFactory; $this->orderservice = $orderservice; @@ -53,7 +112,10 @@ public function __construct( $this->authenticatinservice = $authenticatinservice; $this->paymentStateResponse = $paymentStateResponse; $this->wpresponse = $wpresponse; - $this->orderItemsDetails = $orderItemsDetails; + $this->order = $order; + $this->multishippingStateResponse = $multishippingStateResponse; + $this->quoteRepository = $quoteRepository; + $this->wpMultishippingCollection = $wpMultishippingCollection; return parent::__construct($context); } /** @@ -68,15 +130,37 @@ public function execute() $this->wplogger->info('Params : '.json_encode($params, true)); if (!empty($params['orderKey'])) { preg_match('/\^(\d+)-/', $params['orderKey'], $matches); - $order = $this->orderItemsDetails->loadByIncrementId($matches[1]); + $order = $this->order->loadByIncrementId($matches[1]); if ($order->getId()) { $magentoorder = $order; - $notice = $this->_getCancellationNoticeForOrder($order); - $this->messageManager->addNotice($notice); - $params = $this->getRequest()->getParams(); - if ($this->authenticatinservice->requestAuthenticated($params)) { - if (isset($params['orderKey'])) { - $this->_applyPaymentUpdate($this->wpresponse->createFromCancelledResponse($params), $order); + $quoteId = $order->getQuoteId(); + $quoteObj = $this->quoteRepository->get($quoteId); + if ($quoteObj->getIsMultiShipping()) { + $params = $this->getRequest()->getParams(); + $multiShippingOrders = $this->wpMultishippingCollection->getMultishippingOrderIds($quoteId); + if (count($multiShippingOrders) > 0) { + foreach ($multiShippingOrders as $orderId) { + $orderObj = $this->order->loadByIncrementId($orderId); + $notice = $this->_getCancellationNoticeForOrder($order); + $this->messageManager->addNotice($notice); + $this->_applyPaymentUpdate( + $this->multishippingStateResponse->createResponse( + $params, + $magentoorder->getIncrementId(), + 'cancelled' + ), + $orderObj + ); + } + } + } else { + $notice = $this->_getCancellationNoticeForOrder($order); + $this->messageManager->addNotice($notice); + $params = $this->getRequest()->getParams(); + if ($this->authenticatinservice->requestAuthenticated($params)) { + if (isset($params['orderKey'])) { + $this->_applyPaymentUpdate($this->wpresponse->createFromCancelledResponse($params), $order); + } } } return $this->resultRedirectFactory->create()->setPath('checkout/cart', ['_current' => true]); diff --git a/Controller/Paybylink/Failure.php b/Controller/Paybylink/Failure.php index 89087066..564af03f 100644 --- a/Controller/Paybylink/Failure.php +++ b/Controller/Paybylink/Failure.php @@ -29,6 +29,26 @@ class Failure extends \Magento\Framework\App\Action\Action */ private $transactionsFactory; + /** + * @var \Sapient\Worldpay\Model\Order\Service + */ + protected $orderservice; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + + /** + * @var \Magento\Checkout\Model\Session + */ + protected $checkoutSession; + + /** + * @var \Magento\Sales\Model\Order\Email\Sender\OrderSender + */ + protected $emailsender; + /** * Constructor * diff --git a/Controller/Paybylink/Multishipping/Orderplaced.php b/Controller/Paybylink/Multishipping/Orderplaced.php new file mode 100644 index 00000000..fce01122 --- /dev/null +++ b/Controller/Paybylink/Multishipping/Orderplaced.php @@ -0,0 +1,59 @@ +state = $state; + $this->multishipping = $multishipping; + parent::__construct($context); + } + /** + * Multishipping checkout success page + * + * @return void + */ + public function execute() + { + if (!$this->state->getCompleteStep(State::STEP_OVERVIEW)) { + return $this->resultRedirectFactory->create()->setPath('checkout/cart'); + } + $this->_view->loadLayout(); + $ids = $this->multishipping->getOrderIds(); + $this->_eventManager->dispatch('multishipping_checkout_controller_success_action', ['order_ids' => $ids]); + $this->_view->renderLayout(); + } +} diff --git a/Controller/Paybylink/Multishipping/Success.php b/Controller/Paybylink/Multishipping/Success.php new file mode 100644 index 00000000..5d38ea14 --- /dev/null +++ b/Controller/Paybylink/Multishipping/Success.php @@ -0,0 +1,96 @@ +state = $state; + $this->multishipping = $multishipping; + $this->order = $order; + $this->wpMultishippingCollection = $wpMultishippingCollection; + $this->quoteRepository = $quoteRepository; + parent::__construct($context); + } + /** + * Multishipping checkout success page + * + * @return void + */ + public function execute() + { + $params = $this->getRequest()->getParams(); + if (empty($params['orderKey'])) { + $this->messageManager->addNotice(__("Order key not found.")); + return $this->resultRedirectFactory->create()->setPath('checkout/cart', ['_current' => true]); + } + preg_match('/\^(\d+)-/', $params['orderKey'], $matches); + $order = $this->order->loadByIncrementId($matches[1]); // load order by common multishipping order code + if ($order->getId()) { + $quoteId = $order->getQuoteId(); + $quoteObj = $this->quoteRepository->get($quoteId); + $multiShippingOrders = $this->wpMultishippingCollection->getMultishippingOrderIds($quoteId); + if (count($multiShippingOrders) == 0) { + $this->messageManager->addNotice("Multishipping orders not found"); + return $this->resultRedirectFactory->create()->setPath('checkout/cart', ['_current' => true]); + } + $this->_view->loadLayout(); + $ids = $multiShippingOrders; + $this->_eventManager->dispatch('multishipping_checkout_controller_success_action', ['order_ids' => $ids]); + $this->_view->renderLayout(); + return; + } + $this->messageManager->addNotice("Order not found"); + return $this->resultRedirectFactory->create()->setPath('checkout/cart', ['_current' => true]); + } +} diff --git a/Controller/Paybylink/Orderplaced.php b/Controller/Paybylink/Orderplaced.php index d224ef42..82be7e7f 100644 --- a/Controller/Paybylink/Orderplaced.php +++ b/Controller/Paybylink/Orderplaced.php @@ -19,6 +19,11 @@ class Orderplaced extends \Magento\Checkout\Controller\Onepage implements HttpGe */ protected $orderservice; + /** + * @var \Magento\Checkout\Model\Session + */ + protected $checkoutsession; + /** * Constructor * @@ -87,7 +92,7 @@ public function __construct( public function execute() { $session = $this->getOnepage()->getCheckout(); - if (!$this->_objectManager->get(\Magento\Checkout\Model\Session\SuccessValidator::class)->isValid()) { + if (!$this->isValid()) { return $this->resultRedirectFactory->create()->setPath('checkout/cart'); } $session->clearQuote(); @@ -103,4 +108,21 @@ public function execute() return $resultPage; } + + /** + * Check if valid quote + * + * @return bool + */ + public function isValid() + { + if (!$this->checkoutsession->getLastSuccessQuoteId()) { + return false; + } + + if (!$this->checkoutsession->getLastQuoteId() || !$this->checkoutsession->getLastOrderId()) { + return false; + } + return true; + } } diff --git a/Controller/Paybylink/Process.php b/Controller/Paybylink/Process.php index 96ef4a14..5ac33695 100644 --- a/Controller/Paybylink/Process.php +++ b/Controller/Paybylink/Process.php @@ -25,6 +25,56 @@ class Process extends \Magento\Framework\App\Action\Action */ protected $quoteFactory; + /** + * @var \Sapient\Worldpay\Model\Order\Service + */ + protected $orderservice; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + + /** + * @var \Magento\Sales\Model\Order + */ + protected $orderItemsDetails; + + /** + * @var \Magento\Sales\Model\Order + */ + protected $worldpayhelper; + + /** + * @var \Sapient\Worldpay\Model\Payment\Service + */ + protected $paymentservice; + + /** + * @var \Sapient\Worldpay\Model\Request\AuthenticationService + */ + protected $authenticatinservice; + + /** + * @var \Sapient\Worldpay\Model\Payment\WpResponse + */ + protected $wpresponse; + + /** + * @var \Magento\Checkout\Model\Session + */ + protected $_checkoutSession; + + /** + * @var \Sapient\Worldpay\Model\ResourceModel\Multishipping\Order\Collection + */ + protected $wpMultishippingCollection; + + /** + * @var \Sapient\Worldpay\Model\Payment\MultishippingStateResponse + */ + protected $multishippingStateResponse; + /** * Constructor * @@ -36,6 +86,13 @@ class Process extends \Magento\Framework\App\Action\Action * @param \Sapient\Worldpay\Logger\WorldpayLogger $wplogger * @param \Magento\Framework\Controller\Result\Redirect $resultRedirectFactory * @param \Magento\Sales\Model\Order $orderItemsDetails + * @param \Sapient\Worldpay\Helper\Data $worldpayhelper + * @param \Sapient\Worldpay\Model\Payment\Service $paymentservice + * @param \Sapient\Worldpay\Model\Request\AuthenticationService $authenticatinservice + * @param \Sapient\Worldpay\Model\Payment\WpResponse $wpresponse + * @param \Magento\Checkout\Model\Session $checkoutSession + * @param \Sapient\Worldpay\Model\ResourceModel\Multishipping\Order\Collection $wpMultishippingCollection + * @param \Sapient\Worldpay\Model\Payment\MultishippingStateResponse $multishippingStateResponse */ public function __construct( \Magento\Framework\App\Action\Context $context, @@ -45,7 +102,14 @@ public function __construct( \Sapient\Worldpay\Model\PaymentMethods\PayByLink $paybylink, \Sapient\Worldpay\Logger\WorldpayLogger $wplogger, \Magento\Framework\Controller\Result\Redirect $resultRedirectFactory, - \Magento\Sales\Model\Order $orderItemsDetails + \Magento\Sales\Model\Order $orderItemsDetails, + \Sapient\Worldpay\Helper\Data $worldpayhelper, + \Sapient\Worldpay\Model\Payment\Service $paymentservice, + \Sapient\Worldpay\Model\Request\AuthenticationService $authenticatinservice, + \Sapient\Worldpay\Model\Payment\WpResponse $wpresponse, + \Magento\Checkout\Model\Session $checkoutSession, + \Sapient\Worldpay\Model\ResourceModel\Multishipping\Order\Collection $wpMultishippingCollection, + \Sapient\Worldpay\Model\Payment\MultishippingStateResponse $multishippingStateResponse ) { $this->request = $request; $this->orderservice = $orderservice; @@ -54,6 +118,13 @@ public function __construct( $this->wplogger = $wplogger; $this->resultRedirectFactory = $resultRedirectFactory; $this->orderItemsDetails = $orderItemsDetails; + $this->worldpayhelper = $worldpayhelper; + $this->paymentservice = $paymentservice; + $this->authenticatinservice = $authenticatinservice; + $this->wpresponse = $wpresponse; + $this->_checkoutSession = $checkoutSession; + $this->wpMultishippingCollection = $wpMultishippingCollection; + $this->multishippingStateResponse = $multishippingStateResponse; return parent::__construct($context); } @@ -79,6 +150,47 @@ public function execute() $magentoorder = $order->getOrder(); $quoteId = $magentoorder->getQuoteId(); $quote = $this->getPaybylinkquote($quoteId); + /* Start Expiry Code */ + $currentDate = date("Y-m-d H:i:s"); + $orderDate = $orderInfo->getCreatedAt(); + $interval = $this->worldpayhelper->findPblOrderIntervalTime($currentDate, $orderDate); + $expiryTime = $this->worldpayhelper->getPayByLinkExpiryTime(); + $isResendEnable = $this->worldpayhelper->isPayByLinkResendEnable(); + if ($isResendEnable) { + $expiryTime = $this->worldpayhelper->calculatePblResendExpiryTime($expiryTime); + } + if ($interval >= $expiryTime) { + $this->wplogger->info('Pay by link expired. Cancelling the order.'); + $this->_checkoutSession->setauthenticatedOrderId($order->getIncrementId()); + $worldPayPayment = $order->getWorldPayPayment(); + $merchantCode = $worldPayPayment->getMerchantId(); + if ($quote->getIsMultiShipping()) { + $multiShippingOrders = $this->wpMultishippingCollection->getMultishippingOrderIds($quoteId); + if (count($multiShippingOrders) > 0) { + foreach ($multiShippingOrders as $orderId) { + $orderObj = $this->orderItemsDetails->loadByIncrementId($orderId); + $notice = $this->_getCancellationNoticeForOrder($orderObj); + $this->messageManager->addNotice($notice); + $this->_applyPaymentUpdate( + $this->multishippingStateResponse->createCancelledResponse( + $orderCode, + $merchantCode + ), + $orderObj + ); + } + } + } else { + $notice = $this->_getCancellationNoticeForOrder($order); + $this->messageManager->addNotice($notice); + $this->_applyPaymentUpdate( + $this->wpresponse->createFromPblCancelledResponse($orderCode, $merchantCode), + $orderInfo + ); + } + return $this->resultRedirectFactory->create()->setPath('checkout/cart', ['_current' => true]); + } + /* End Expiry Code */ $payment = $magentoorder->getPayment(); $paymentDetails = []; $paymentDetails['additional_data']['cc_type'] = 'ALL'; @@ -103,6 +215,41 @@ public function execute() } } + /** + * Get Cancellation NoticeFor Order + * + * @param array $order + * @return string + */ + private function _getCancellationNoticeForOrder($order) + { + + $incrementId = $order->getIncrementId(); + $message = $incrementId === null + ? __('Order Cancelled') + : __('Order #'. $incrementId.' Cancelled'); + + return $message; + } + + /** + * Apply Payment Update + * + * @param string $paymentState + * @param array $order + * @return string + */ + private function _applyPaymentUpdate($paymentState, $order) + { + try { + $this->_paymentUpdate = $this->paymentservice + ->createPaymentUpdateFromWorldPayResponse($paymentState); + $this->_paymentUpdate->apply($order->getPayment(), $order); + } catch (\Exception $e) { + $this->wplogger->error($e->getMessage()); + } + } + /** * Get pay by link order * diff --git a/Controller/Paybylink/Success.php b/Controller/Paybylink/Success.php index ea288c9a..2baab889 100644 --- a/Controller/Paybylink/Success.php +++ b/Controller/Paybylink/Success.php @@ -22,6 +22,26 @@ class Success extends \Magento\Framework\App\Action\Action */ protected $orderItemsDetails; + /** + * @var \Sapient\Worldpay\Model\Order\Service + */ + protected $orderservice; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + + /** + * @var \Magento\Checkout\Model\Session + */ + protected $_checkoutSession; + + /** + * @var \Magento\Quote\Model\QuoteFactory + */ + protected $quoteFactory; + /** * Constructor * @@ -31,6 +51,7 @@ class Success extends \Magento\Framework\App\Action\Action * @param \Magento\Sales\Model\Order $orderItemsDetails * @param \Sapient\Worldpay\Logger\WorldpayLogger $wplogger * @param \Magento\Checkout\Model\Session $checkoutSession + * @param \Magento\Quote\Model\QuoteFactory $quoteFactory */ public function __construct( Context $context, @@ -38,13 +59,15 @@ public function __construct( \Sapient\Worldpay\Model\Order\Service $orderservice, \Magento\Sales\Model\Order $orderItemsDetails, \Sapient\Worldpay\Logger\WorldpayLogger $wplogger, - \Magento\Checkout\Model\Session $checkoutSession + \Magento\Checkout\Model\Session $checkoutSession, + \Magento\Quote\Model\QuoteFactory $quoteFactory ) { $this->pageFactory = $pageFactory; $this->orderservice = $orderservice; $this->wplogger = $wplogger; $this->orderItemsDetails = $orderItemsDetails; $this->_checkoutSession = $checkoutSession; + $this->quoteFactory = $quoteFactory; return parent::__construct($context); } @@ -57,7 +80,6 @@ public function execute() { $this->wplogger->info('worldpay returned Pay by link success url'); $params = $this->getRequest()->getParams(); - $this->wplogger->info('Params : '.json_encode($params, true)); if (!empty($params['orderKey'])) { preg_match('/\^(\d+)-/', $params['orderKey'], $matches); $order = $this->orderItemsDetails->loadByIncrementId($matches[1]); @@ -65,8 +87,16 @@ public function execute() $this->setOrderSessionData($order); $this->orderservice->redirectOrderSuccess(); $this->orderservice->removeAuthorisedOrder(); - return $this->resultRedirectFactory->create() - ->setPath('checkout/onepage/success', ['_current' => true]); + $quote = $this->quoteFactory->create()->load($order->getQuoteId()); + $isMultiShipping = $quote->getIsMultiShipping(); + if ($isMultiShipping) { + $url = 'worldpay/paybylink_multishipping/success?orderKey='.$params['orderKey']; + return $this->resultRedirectFactory->create() + ->setPath($url); + } else { + return $this->resultRedirectFactory->create() + ->setPath('checkout/onepage/success', ['_current' => true]); + } } else { $this->wplogger->info('Order not found.Redirecting to checkout cart page'); return $this->resultRedirectFactory->create()->setPath('checkout/cart', ['_current' => true]); diff --git a/Controller/Payment/Pay.php b/Controller/Payment/Pay.php index dcd292bd..9e35aeda 100644 --- a/Controller/Payment/Pay.php +++ b/Controller/Payment/Pay.php @@ -16,16 +16,16 @@ class Pay extends \Magento\Framework\App\Action\Action { /** - * @var PAYMENT_MANIFEST_JSON + * @var string */ public const PAYMENT_MANIFEST_JSON = 'payment-manifest.json'; /** - * @var MANIFEST_JSON + * @var string */ public const MANIFEST_JSON = 'manifest.json'; /** - * @var curlHelper + * @var \Sapient\Worldpay\Helper\CurlHelper */ public $curlHelper; /** @@ -36,6 +36,51 @@ class Pay extends \Magento\Framework\App\Action\Action * @var _assetRepo */ protected $_assetRepo; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + public $wplogger; + + /** + * @var \Sapient\Worldpay\Model\Payment\Service + */ + public $paymentservice; + + /** + * @var JsonFactory + */ + public $resultJsonFactory; + + /** + * @var \Magento\Framework\App\Config\ScopeConfigInterface + */ + public $scopeConfig; + + /** + * @var \Magento\Framework\App\Request\Http + */ + public $request; + + /** + * @var \Magento\Framework\Filesystem + */ + public $_filesystem; + + /** + * @var \Magento\Framework\Setup\JsonPersistor + */ + public $jsonPersistor; + + /** + * @var \Sapient\Worldpay\Helper\Data + */ + public $wpHelper; + + /** + * @var \Magento\Framework\Filesystem\Io\File + */ + public $file; /** * Constructor diff --git a/Controller/Recurring/Cancel.php b/Controller/Recurring/Cancel.php index 12901b70..0ba25fd6 100644 --- a/Controller/Recurring/Cancel.php +++ b/Controller/Recurring/Cancel.php @@ -38,25 +38,34 @@ class Cancel extends \Magento\Framework\App\Action\Action private $helper; + /** + * @var \Magento\Customer\Model\Url + */ + + private $customerUrl; + /** * @param Context $context * @param Session $customerSession * @param SubscriptionFactory $subscriptionFactory * @param TransactionsFactory $transactionFactory * @param MyAccountException $helper + * @param \Magento\Customer\Model\Url $customerUrl */ public function __construct( Context $context, Session $customerSession, SubscriptionFactory $subscriptionFactory, TransactionsFactory $transactionFactory, - MyAccountException $helper + MyAccountException $helper, + \Magento\Customer\Model\Url $customerUrl ) { parent::__construct($context); $this->customerSession = $customerSession; $this->subscriptionFactory = $subscriptionFactory; $this->transactionFactory = $transactionFactory; $this->helper = $helper; + $this->customerUrl = $customerUrl; } /** @@ -67,8 +76,7 @@ public function __construct( */ public function dispatch(RequestInterface $request) { - $loginUrl = $this->_objectManager->get(\Magento\Customer\Model\Url::class)->getLoginUrl(); - + $loginUrl = $this->customerUrl->getLoginUrl(); if (!$this->customerSession->authenticate($loginUrl)) { $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true); } diff --git a/Controller/Recurring/Edit.php b/Controller/Recurring/Edit.php index f81357ee..f016b03c 100644 --- a/Controller/Recurring/Edit.php +++ b/Controller/Recurring/Edit.php @@ -36,25 +36,33 @@ class Edit extends \Magento\Framework\App\Action\Action */ private $helper; + /** + * @var \Magento\Customer\Model\Url + */ + private $customerUrl; + /** * @param Context $context * @param Session $customerSession * @param PageFactory $resultPageFactory * @param SubscriptionFactory $subscriptionFactory * @param Sapient\Worldpay\Helper\GeneralException $helper + * @param \Magento\Customer\Model\Url $customerUrl */ public function __construct( Context $context, Session $customerSession, PageFactory $resultPageFactory, SubscriptionFactory $subscriptionFactory, - \Sapient\Worldpay\Helper\GeneralException $helper + \Sapient\Worldpay\Helper\GeneralException $helper, + \Magento\Customer\Model\Url $customerUrl ) { $this->customerSession = $customerSession; parent::__construct($context); $this->resultPageFactory = $resultPageFactory; $this->subscriptionFactory = $subscriptionFactory; $this->helper = $helper; + $this->customerUrl = $customerUrl; } /** @@ -65,8 +73,7 @@ public function __construct( */ public function dispatch(RequestInterface $request) { - $loginUrl = $this->_objectManager->get(\Magento\Customer\Model\Url::class)->getLoginUrl(); - + $loginUrl = $this->customerUrl->getLoginUrl(); if (!$this->customerSession->authenticate($loginUrl)) { $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true); } diff --git a/Controller/Recurring/FormPost.php b/Controller/Recurring/FormPost.php index 756572b2..b5602f07 100644 --- a/Controller/Recurring/FormPost.php +++ b/Controller/Recurring/FormPost.php @@ -48,6 +48,11 @@ class FormPost extends \Magento\Framework\App\Action\Action */ protected $helper; + /** + * @var \Magento\Customer\Model\Url + */ + private $customerUrl; + /** * @param Context $context * @param Session $customerSession @@ -56,6 +61,7 @@ class FormPost extends \Magento\Framework\App\Action\Action * @param PaymentTokenFactory $tokenFactory * @param CollectionFactory $regionCollectionFactory * @param MyAccountException $helper + * @param \Magento\Customer\Model\Url $customerUrl */ public function __construct( Context $context, @@ -64,7 +70,8 @@ public function __construct( SubscriptionFactory $subscriptionFactory, PaymentTokenFactory $tokenFactory, CollectionFactory $regionCollectionFactory, - MyAccountException $helper + MyAccountException $helper, + \Magento\Customer\Model\Url $customerUrl ) { parent::__construct($context); $this->customerSession = $customerSession; @@ -73,6 +80,7 @@ public function __construct( $this->tokenFactory = $tokenFactory; $this->regionCollectionFactory = $regionCollectionFactory; $this->helper = $helper; + $this->customerUrl = $customerUrl; } /** @@ -83,8 +91,7 @@ public function __construct( */ public function dispatch(RequestInterface $request) { - $loginUrl = $this->_objectManager->get(\Magento\Customer\Model\Url::class)->getLoginUrl(); - + $loginUrl = $this->customerUrl->getLoginUrl(); if (!$this->customerSession->authenticate($loginUrl)) { $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true); } diff --git a/Controller/Recurring/Index.php b/Controller/Recurring/Index.php index 928d3860..b09d55f2 100644 --- a/Controller/Recurring/Index.php +++ b/Controller/Recurring/Index.php @@ -16,18 +16,31 @@ class Index extends \Magento\Framework\App\Action\Action implements HttpGetActio */ private $customerSession; + /** + * @var \Sapient\Worldpay\Helper\Data + */ + private $worldpayHelper; + + /** + * @var \Magento\Customer\Model\Url + */ + private $customerUrl; + /** * @param \Magento\Framework\App\Action\Context $context * @param \Magento\Customer\Model\Session $customerSession * @param \Sapient\Worldpay\Helper\Data $worldpayHelper + * @param \Magento\Customer\Model\Url $customerUrl */ public function __construct( \Magento\Framework\App\Action\Context $context, \Magento\Customer\Model\Session $customerSession, - \Sapient\Worldpay\Helper\Data $worldpayHelper + \Sapient\Worldpay\Helper\Data $worldpayHelper, + \Magento\Customer\Model\Url $customerUrl ) { $this->customerSession = $customerSession; $this->worldpayHelper = $worldpayHelper; + $this->customerUrl = $customerUrl; parent::__construct($context); } @@ -39,8 +52,7 @@ public function __construct( */ public function dispatch(RequestInterface $request) { - $loginUrl = $this->_objectManager->get(\Magento\Customer\Model\Url::class)->getLoginUrl(); - + $loginUrl = $this->customerUrl->getLoginUrl(); if (!$this->customerSession->authenticate($loginUrl)) { $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true); } diff --git a/Controller/Redirectresult/Cancel.php b/Controller/Redirectresult/Cancel.php index 5d02e20d..3038f359 100644 --- a/Controller/Redirectresult/Cancel.php +++ b/Controller/Redirectresult/Cancel.php @@ -15,10 +15,50 @@ class Cancel extends \Magento\Framework\App\Action\Action { /** - * @var Magento\Framework\View\Result\PageFactory + * @var \Magento\Framework\View\Result\PageFactory */ protected $pageFactory; + /** + * @var \Sapient\Worldpay\Model\Order\Service + */ + protected $orderservice; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + + /** + * @var \Sapient\Worldpay\Model\Checkout\Service + */ + protected $checkoutservice; + + /** + * @var \Sapient\Worldpay\Model\Payment\Service + */ + protected $paymentservice; + + /** + * @var \Sapient\Worldpay\Model\Request\AuthenticationService + */ + protected $authenticatinservice; + + /** + * @var \Sapient\Worldpay\Model\Payment\StateResponse + */ + protected $paymentStateResponse; + + /** + * @var \Sapient\Worldpay\Model\Payment\WpResponse + */ + protected $wpresponse; + + /** + * @var \Sapient\Worldpay\Helper\Multishipping + */ + protected $multishippingHelper; + /** * Constructor * diff --git a/Controller/Redirectresult/Error.php b/Controller/Redirectresult/Error.php index 313bbad9..ad7b83fd 100644 --- a/Controller/Redirectresult/Error.php +++ b/Controller/Redirectresult/Error.php @@ -35,6 +35,26 @@ class Error extends \Magento\Framework\App\Action\Action */ protected $helper; + /** + * @var \Sapient\Worldpay\Model\Order\Service + */ + protected $orderservice; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + + /** + * @var \Magento\Checkout\Model\Session + */ + protected $checkoutSession; + + /** + * @var \Sapient\Worldpay\Helper\Multishipping + */ + protected $multishippingHelper; + /** * Constructor * diff --git a/Controller/Redirectresult/Failure.php b/Controller/Redirectresult/Failure.php index 406c685f..0aa35a66 100644 --- a/Controller/Redirectresult/Failure.php +++ b/Controller/Redirectresult/Failure.php @@ -29,6 +29,31 @@ class Failure extends \Magento\Framework\App\Action\Action */ private $transactionsFactory; + /** + * @var \Sapient\Worldpay\Model\Order\Service + */ + private $orderservice; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + + /** + * @var \Magento\Checkout\Model\Session + */ + protected $checkoutSession; + + /** + * @var \Sapient\Worldpay\Helper\Multishipping + */ + protected $multishippingHelper; + + /** + * @var \Magento\Sales\Model\Order\Email\Sender\OrderSender + */ + protected $emailsender; + /** * Constructor * diff --git a/Controller/Redirectresult/Iframe.php b/Controller/Redirectresult/Iframe.php index 217418a6..db01003d 100644 --- a/Controller/Redirectresult/Iframe.php +++ b/Controller/Redirectresult/Iframe.php @@ -21,7 +21,27 @@ class Iframe extends \Magento\Framework\App\Action\Action /** * @var \Sapient\Worldpay\Model\Checkout\Hpp\State */ - protected $_status; + protected $hppstate; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + + /** + * @var ResultFactory + */ + protected $resultPageFactory; + + /** + * @var \Magento\Checkout\Model\Session + */ + protected $checkoutsession; + + /** + * @var mixed + */ + public $_status; /** * Constructor diff --git a/Controller/Redirectresult/Pending.php b/Controller/Redirectresult/Pending.php index f7531c7c..48d7a9de 100644 --- a/Controller/Redirectresult/Pending.php +++ b/Controller/Redirectresult/Pending.php @@ -17,7 +17,42 @@ class Pending extends \Magento\Framework\App\Action\Action * @var Magento\Framework\View\Result\PageFactory */ protected $pageFactory; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + + /** + * @var \Sapient\Worldpay\Model\Order\Service + */ + protected $orderservice; + + /** + * @var \Sapient\Worldpay\Model\Checkout\Service + */ + protected $checkoutservice; + + /** + * @var \Sapient\Worldpay\Model\Payment\Service + */ + protected $paymentservice; + + /** + * @var \Sapient\Worldpay\Model\Payment\StateResponseFactory + */ + protected $paymentStateResponse; + + /** + * @var \Sapient\Worldpay\Model\Payment\WpResponse + */ + protected $wpresponse; + /** + * @var object + */ + protected $_paymentUpdate; + /** * Constructor * diff --git a/Controller/Redirectresult/Redirect.php b/Controller/Redirectresult/Redirect.php index 2f45ade5..f61d4ce4 100644 --- a/Controller/Redirectresult/Redirect.php +++ b/Controller/Redirectresult/Redirect.php @@ -19,6 +19,16 @@ class Redirect extends \Magento\Framework\App\Action\Action */ protected $pageFactory; + /** + * @var \Magento\Checkout\Model\Session + */ + protected $checkoutsession; + + /** + * @var \Magento\Sales\Model\Order + */ + protected $mageOrder; + /** * Constructor * diff --git a/Controller/Redirectresult/Success.php b/Controller/Redirectresult/Success.php index 73ff75f3..b7c938a2 100644 --- a/Controller/Redirectresult/Success.php +++ b/Controller/Redirectresult/Success.php @@ -13,10 +13,19 @@ class Success extends \Magento\Framework\App\Action\Action { /** - * @var Magento\Framework\View\Result\PageFactory + * @var \Magento\Framework\View\Result\PageFactory */ protected $pageFactory; + /** + * @var \Sapient\Worldpay\Model\Order\Service + */ + protected $orderservice; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; /** * Constructor * diff --git a/Controller/Samsungpay/CallBack.php b/Controller/Samsungpay/CallBack.php index 64a6b0fc..e4cc68b6 100644 --- a/Controller/Samsungpay/CallBack.php +++ b/Controller/Samsungpay/CallBack.php @@ -44,6 +44,50 @@ class CallBack extends \Magento\Framework\App\Action\Action */ public $quoteRepository; + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + + /** + * @var \Sapient\Worldpay\Model\Payment\Service + */ + protected $paymentservice; + + /** + * @var JsonFactory + */ + protected $resultJsonFactory; + + /** + * @var \Magento\Framework\App\Config\ScopeConfigInterface + */ + protected $scopeConfig; + /** + * @var \Magento\Framework\App\Request\Http + */ + protected $request; + + /** + * @var \Sapient\Worldpay\Model\Request\PaymentServiceRequest + */ + protected $_paymentservicerequest; + + /** + * @var \Magento\Backend\Model\Auth\Session + */ + protected $_authSession; + + /** + * @var \Sapient\Worldpay\Model\WorldpaymentFactory + */ + protected $_worldpaymentFactory; + + /** + * @var \Sapient\Worldpay\Helper\CurlHelper + */ + protected $curlHelper; + /** * Constructor * diff --git a/Controller/Samsungpay/Index.php b/Controller/Samsungpay/Index.php index 17ac660e..5c466182 100644 --- a/Controller/Samsungpay/Index.php +++ b/Controller/Samsungpay/Index.php @@ -34,6 +34,36 @@ class Index extends \Magento\Framework\App\Action\Action * @var $customerSession */ public $customerSession; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + public $wplogger; + + /** + * @var \Sapient\Worldpay\Model\Payment\Service + */ + public $paymentservice; + + /** + * @var JsonFactory + */ + protected $resultJsonFactory; + + /** + * @var \Magento\Framework\App\Config\ScopeConfigInterface + */ + protected $scopeConfig; + + /** + * @var \Magento\Framework\App\Request\Http + */ + protected $request; + + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $worldpayHelper; /** * Constructor * diff --git a/Controller/Savedcard/Addnewcard.php b/Controller/Savedcard/Addnewcard.php index 16ba30e4..14125c03 100644 --- a/Controller/Savedcard/Addnewcard.php +++ b/Controller/Savedcard/Addnewcard.php @@ -19,6 +19,12 @@ class Addnewcard extends \Magento\Framework\App\Action\Action * @var \Magento\Customer\Model\Session */ protected $customerSession; + + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $worldpayHelper; + /** * Constructor * diff --git a/Controller/Savedcard/AddnewcardPost.php b/Controller/Savedcard/AddnewcardPost.php index b9df28cf..e68fa34b 100644 --- a/Controller/Savedcard/AddnewcardPost.php +++ b/Controller/Savedcard/AddnewcardPost.php @@ -72,6 +72,75 @@ class AddnewcardPost extends \Magento\Customer\Controller\AbstractAccount protected $helper; + /** + * @var \Magento\Framework\Controller\Result\JsonFactory + */ + protected $resultJsonFactory; + + /** + * @var StoreManagerInterface + */ + protected $_storeManager; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + + /** + * @var \Magento\Customer\Api\AddressRepositoryInterface + */ + protected $addressRepository; + + /** + * @var \Magento\Framework\App\Config\ScopeConfigInterface + */ + protected $scopeConfig; + + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $worldpayHelper; + + /** + * @var \Sapient\Worldpay\Model\Request\PaymentServiceRequest + */ + protected $_paymentservicerequest; + + /** + * @var \Magento\Framework\Session\SessionManagerInterface + */ + protected $session; + + /** + * @var \Sapient\Worldpay\Model\Response\DirectResponse + */ + protected $directResponse; + + /** + * @var \Sapient\Worldpay\Model\Payment\UpdateWorldpaymentFactory + */ + protected $updateWorldPayPayment; + + /** + * @var \Sapient\Worldpay\Model\Payment\Service + */ + protected $paymentservice; + + /** + * @var \Magento\Integration\Model\Oauth\TokenFactory + */ + protected $_tokenModelFactory; + + /** + * @var \Magento\SalesSequence\Model\Manager + */ + protected $sequenceManager; + /** + * @var \Sapient\Worldpay\Helper\Registry + */ + protected $registryhelper; + /** * Constructor * diff --git a/Controller/Savedcard/Delete.php b/Controller/Savedcard/Delete.php index 43a81d28..8767fc47 100644 --- a/Controller/Savedcard/Delete.php +++ b/Controller/Savedcard/Delete.php @@ -40,6 +40,41 @@ class Delete extends \Magento\Framework\App\Action\Action */ protected $resultRedirect; + /** + * @var StoreManagerInterface + */ + protected $_storeManager; + + /** + * @var SavedTokenFactory + */ + protected $savecard; + + /** + * @var \Sapient\Worldpay\Model\Token\Service + */ + protected $_tokenService; + + /** + * @var \Sapient\Worldpay\Model\Token\WorldpayToken + */ + protected $_worldpayToken; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + + /** + * @var PaymentTokenRepositoryInterface + */ + protected $tokenRepository; + + /** + * @var PaymentTokenManagement + */ + protected $paymentTokenManagement; + /** * Constructor * diff --git a/Controller/Savedcard/Edit.php b/Controller/Savedcard/Edit.php index 11828ca1..f3da1de4 100644 --- a/Controller/Savedcard/Edit.php +++ b/Controller/Savedcard/Edit.php @@ -24,6 +24,16 @@ class Edit extends \Magento\Framework\App\Action\Action */ protected $customerSession; + /** + * @var SavedTokenFactory + */ + protected $savecard; + + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $worldpayHelper; + /** * Constructor * diff --git a/Controller/Savedcard/EditPost.php b/Controller/Savedcard/EditPost.php index 7b962473..f516a1ce 100644 --- a/Controller/Savedcard/EditPost.php +++ b/Controller/Savedcard/EditPost.php @@ -38,7 +38,38 @@ class EditPost extends \Magento\Customer\Controller\AbstractAccount * @var Magento\Framework\Serialize\Serializer\Json */ protected $serializer; + /** + * @var StoreManagerInterface + */ + protected $_storeManager; + + /** + * @var SavedTokenFactory + */ + protected $savecard; + /** + * @var \Sapient\Worldpay\Model\Token\Service + */ + protected $_tokenService; + + /** + * @var \Sapient\Worldpay\Model\Token\WorldpayToken + */ + protected $_worldpayToken; + /** + * @var \Sapient\Worldpay\Model\Token\WorldpayToken + */ + protected $wplogger; + /** + * @var PaymentTokenRepositoryInterface + */ + protected $tokenRepository; + + /** + * @var PaymentTokenManagement + */ + protected $paymentTokenManagement; /** * Constructor * diff --git a/Controller/Savedcard/Index.php b/Controller/Savedcard/Index.php index 2a9d8635..10465ff2 100644 --- a/Controller/Savedcard/Index.php +++ b/Controller/Savedcard/Index.php @@ -19,6 +19,12 @@ class Index extends \Magento\Framework\App\Action\Action * @var \Magento\Customer\Model\Session */ protected $customerSession; + + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $worldpayHelper; + /** * Constructor * diff --git a/Controller/Savedcard/Instantredirect.php b/Controller/Savedcard/Instantredirect.php index bca36d9f..c2145b70 100644 --- a/Controller/Savedcard/Instantredirect.php +++ b/Controller/Savedcard/Instantredirect.php @@ -19,6 +19,11 @@ class Instantredirect extends \Magento\Framework\App\Action\Action */ protected $redirect; + /** + * @var \Sapient\Worldpay\Model\Token\WorldpayToken + */ + protected $wplogger; + /** * Constructor * diff --git a/Controller/Savedcard/Multishippingredirect.php b/Controller/Savedcard/Multishippingredirect.php index 8713f2c3..c0a00dae 100644 --- a/Controller/Savedcard/Multishippingredirect.php +++ b/Controller/Savedcard/Multishippingredirect.php @@ -15,6 +15,11 @@ class Multishippingredirect extends \Magento\Framework\App\Action\Action protected $checkoutSession; + /** + * @var \Sapient\Worldpay\Model\Token\WorldpayToken + */ + protected $wplogger; + /** * Constructor * diff --git a/Controller/Savedcard/Redirect.php b/Controller/Savedcard/Redirect.php index 61439f01..49a5b274 100644 --- a/Controller/Savedcard/Redirect.php +++ b/Controller/Savedcard/Redirect.php @@ -15,6 +15,11 @@ class Redirect extends \Magento\Framework\App\Action\Action protected $checkoutSession; + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + + protected $wplogger; /** * Constructor * diff --git a/Controller/ThreeDSecure/Auth.php b/Controller/ThreeDSecure/Auth.php index d70d67df..89027433 100644 --- a/Controller/ThreeDSecure/Auth.php +++ b/Controller/ThreeDSecure/Auth.php @@ -13,18 +13,41 @@ class Auth extends \Magento\Framework\App\Action\Action { + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + /** * @var \Magento\Checkout\Model\Session */ protected $checkoutSession; + + /** + * @var \Magento\Framework\View\Result\PageFactory + */ + protected $_resultPageFactory; + /** * @var _assetRepo */ protected $_assetRepo; + + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $worldpayHelper; + + /** + * @var ResultFactory + */ + protected $resultFactory; + /** - * @var request + * @var \Magento\Framework\App\Request\Http */ protected $request; + /** * @var _cookieManager */ diff --git a/Controller/ThreeDSecure/AuthResponse.php b/Controller/ThreeDSecure/AuthResponse.php index f18f8ad6..353dd0b2 100644 --- a/Controller/ThreeDSecure/AuthResponse.php +++ b/Controller/ThreeDSecure/AuthResponse.php @@ -25,6 +25,47 @@ class AuthResponse extends \Magento\Framework\App\Action\Action * @var cookieMetadataFactory */ protected $cookieMetadataFactory; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + + /** + * @var \Magento\Framework\Controller\Result\JsonFactory + */ + protected $resultJsonFactory; + + /** + * @var string + */ + protected $urlBuilder; + + /** + * @var \Magento\Checkout\Model\Session + */ + protected $checkoutSession; + + /** + * @var \Magento\Sales\Model\OrderFactory + */ + protected $orderFactory; + + /** + * @var \Magento\Sales\Model\Order\Email\Sender\OrderSender + */ + protected $orderSender; + + /** + * @var \Sapient\Worldpay\Model\Authorisation\ThreeDSecureService + */ + protected $threedsredirectresponse; + + /** + * @var \Magento\Framework\UrlInterface + */ + protected $urlBuilders; + /** * Constructor * diff --git a/Controller/ThreeDSecure/ChallengeAuthResponse.php b/Controller/ThreeDSecure/ChallengeAuthResponse.php index 0dc4f7f8..e997b459 100644 --- a/Controller/ThreeDSecure/ChallengeAuthResponse.php +++ b/Controller/ThreeDSecure/ChallengeAuthResponse.php @@ -9,10 +9,53 @@ class ChallengeAuthResponse extends \Magento\Framework\App\Action\Action { - /** - * @var CreditCardException - */ + /** + * @var CreditCardException + */ protected $helper; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + /** + * @var \Magento\Framework\Controller\Result\JsonFactory + */ + protected $resultJsonFactory; + + /** + * @var string + */ + protected $urlBuilder; + + /** + * @var \Magento\Checkout\Model\Session + */ + protected $checkoutSession; + /** + * @var \Magento\Sales\Model\OrderFactory + */ + protected $orderFactory; + + /** + * @var \Magento\Sales\Model\Order\Email\Sender\OrderSender + */ + protected $orderSender; + + /** + * @var \Sapient\Worldpay\Model\Authorisation\ThreeDSecureChallenge + */ + protected $threedscredirectresponse; + + /** + * @var \Magento\Framework\UrlInterface + */ + protected $urlBuilders; + /** + * @var \Magento\Framework\Session\SessionManagerInterface + */ + protected $session; + /** * Constructor * diff --git a/Controller/ThreeDSecure/ChallengeRedirectResponse.php b/Controller/ThreeDSecure/ChallengeRedirectResponse.php index 30e8bdd8..af74d369 100644 --- a/Controller/ThreeDSecure/ChallengeRedirectResponse.php +++ b/Controller/ThreeDSecure/ChallengeRedirectResponse.php @@ -6,6 +6,44 @@ class ChallengeRedirectResponse extends \Magento\Framework\App\Action\Action { + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + /** + * @var \Magento\Framework\Controller\Result\JsonFactory + */ + protected $resultJsonFactory; + + /** + * @var string + */ + protected $urlBuilder; + + /** + * @var \Magento\Checkout\Model\Session + */ + protected $checkoutSession; + /** + * @var \Magento\Sales\Model\OrderFactory + */ + protected $orderFactory; + + /** + * @var \Magento\Sales\Model\Order\Email\Sender\OrderSender + */ + protected $orderSender; + + /** + * @var \Sapient\Worldpay\Model\Authorisation\ThreeDSecureChallenge + */ + protected $threedscredirectresponse; + + /** + * @var \Magento\Framework\View\Result\PageFactory + */ + protected $_resultPageFactory; /** * Constructor * diff --git a/Controller/Wallets/CancelCheckout.php b/Controller/Wallets/CancelCheckout.php index 9eef246c..6b94b4af 100644 --- a/Controller/Wallets/CancelCheckout.php +++ b/Controller/Wallets/CancelCheckout.php @@ -10,6 +10,28 @@ class CancelCheckout extends \Magento\Framework\App\Action\Action implements HttpPostActionInterface { + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + /** + * @var \Magento\Framework\Controller\Result\JsonFactory + */ + protected $_resultPageFactory; + /** + * @var \Magento\Quote\Api\CartRepositoryInterface + */ + protected $quoteRepository; + /** + * @var \Magento\Customer\Model\Session + */ + protected $customerSession; + + /** + * @var \Magento\Checkout\Model\Session + */ + protected $checkoutSession; + /** * Constructor * diff --git a/Controller/Wallets/MultishippingSuccess.php b/Controller/Wallets/MultishippingSuccess.php index e3a3b888..b82da31e 100644 --- a/Controller/Wallets/MultishippingSuccess.php +++ b/Controller/Wallets/MultishippingSuccess.php @@ -11,6 +11,14 @@ class MultishippingSuccess extends \Magento\Framework\App\Action\Action { + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + /** + * @var \Magento\Framework\View\Result\PageFactory + */ + protected $_resultPageFactory; /** * Constructor * diff --git a/Controller/Wallets/Success.php b/Controller/Wallets/Success.php index bf6c98c5..94a597b3 100644 --- a/Controller/Wallets/Success.php +++ b/Controller/Wallets/Success.php @@ -9,6 +9,14 @@ class Success extends \Magento\Framework\App\Action\Action { + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + /** + * @var \Magento\Framework\View\Result\PageFactory + */ + protected $_resultPageFactory; /** * Constructor * diff --git a/Cron/OrderSyncStatus.php b/Cron/OrderSyncStatus.php index ab6ba74d..78e3cd4d 100644 --- a/Cron/OrderSyncStatus.php +++ b/Cron/OrderSyncStatus.php @@ -39,6 +39,35 @@ class OrderSyncStatus * @var _tokenState */ private $_tokenState; + + /** + * @var \Magento\Sales\Model\ResourceModel\Order\CollectionFactory + */ + private $_orderCollectionFactory; + + /** + * @var \Sapient\Worldpay\Helper\Data + */ + private $worldpayhelper; + /** + * @var \Sapient\Worldpay\Model\Payment\Service + */ + private $paymentservice; + + /** + * @var \Sapient\Worldpay\Model\Order\Service + */ + private $orderservice; + + /** + * @var JsonFactory + */ + private $resultJsonFactory; + + /** + * @var \Sapient\Worldpay\Model\Token\WorldpayToken + */ + private $worldpaytoken; /** * Constructor @@ -124,7 +153,7 @@ private function getOrderCollectionFactory() { if ($this->orderCollectionFactory === null) { - $this->orderCollectionFactory = ObjectManager::getInstance()->get(CollectionFactoryInterface::class); + $this->orderCollectionFactory = $this->_orderCollectionFactory; } return $this->orderCollectionFactory; } diff --git a/Cron/PayByLinkOrders.php b/Cron/PayByLinkOrders.php new file mode 100644 index 00000000..5ae26794 --- /dev/null +++ b/Cron/PayByLinkOrders.php @@ -0,0 +1,276 @@ +_logger = $wplogger; + $this->worldpayhelper = $worldpayhelper; + $this->paymentservice = $paymentservice; + $this->orderservice = $orderservice; + $this->wpresponse = $wpresponse; + $this->_storeManager = $_storeManager; + $this->pricingHelper = $pricingHelper; + $this->_addressConfig = $addressConfig; + $this->payByLinkEmail = $payByLinkEmail; + $this->quoteRepository = $quoteRepository; + $this->wpMultishippingCollection = $wpMultishippingCollection; + $this->multishippingStateResponse = $multishippingStateResponse; + $this->orderItemsDetails = $orderItemsDetails; + $this->pblOrder = $pblOrder; + } + + /** + * Get the list of orders to be expired or resend + */ + public function execute() + { + $this->_logger->info('Pay by link orders executed on - '.date('Y-m-d H:i:s')); + $curDate = date("Y-m-d H:i:s"); + $expiryTime = $this->worldpayhelper->getPayByLinkExpiryTime(); + $isResendEnable = $this->worldpayhelper->isPayByLinkResendEnable(); + $resendExpiryTime = ''; + if ($isResendEnable) { + $resendExpiryTime = $this->worldpayhelper->calculatePblResendExpiryTime($expiryTime); + } + $orderIds = $this->pblOrder->getPayByLinkOrderIds($curDate, $expiryTime, $resendExpiryTime); + if (!empty($orderIds)) { + foreach ($orderIds as $order) { + $createdAt = $order['created_at']; + $currentDate = date('Y-m-d H:i:s'); + $interval = $this->worldpayhelper->findPblOrderIntervalTime($currentDate, $createdAt); + $orderIncrementId = $order['increment_id']; + $order = $this->orderservice->getByIncrementId($orderIncrementId); + $magentoorder = $order->getOrder(); + $worldPayPayment = $order->getWorldPayPayment(); + $orderCode = $worldPayPayment->getWorldpayOrderId(); + $merchantCode = $worldPayPayment->getMerchantId(); + $quoteId = $order->getQuoteId(); + $quoteObj = $this->quoteRepository->get($quoteId); + if (empty($resendExpiryTime) || $interval == $resendExpiryTime) { + /* Cancel Order */ + $this->_logger->info('Pay by link expired. Cancelling the order.'); + if ($quoteObj->getIsMultiShipping()) { + $this->cancelMultiShippingOrders( + $quoteObj, + $orderCode, + $merchantCode + ); + } else { + $this->_applyPaymentUpdate( + $this->wpresponse->createFromPblCancelledResponse($orderCode, $merchantCode), + $magentoorder + ); + } + } else { + /* Resend Mail */ + $this->_logger->info('Pay by link resend mail.'); + $pblOrderCodeUrl = 'worldpay/paybylink/process?orderkey='.$orderCode; + $paybylink_url = $this->_storeManager->getStore() + ->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB).$pblOrderCodeUrl; + $grandTotal = $this->getFormatGrandTotal($magentoorder); + $address = $magentoorder->getShippingAddress(); + if (empty($address)) { + $address = $magentoorder->getBillingAddress(); + } + $formatedAddress = $this->getFormatAddressByCode($address->getData()); + $customerEmail = $magentoorder->getCustomerEmail(); + $csName = $magentoorder->getCustomerFirstName().' '.$magentoorder->getCustomerLastName(); + $payByLinkParams['paybylink_url'] = $paybylink_url; + $payByLinkParams['orderId'] = $magentoorder->getIncrementId(); + $payByLinkParams['order_total'] = $grandTotal; + $payByLinkParams['formated_shipping'] = $formatedAddress; + $payByLinkParams['customerName'] = $csName; + $payByLinkParams['customerEmail'] = $customerEmail; + $payByLinkParams['is_resend'] = true; + $payByLinkParams['is_multishipping'] = false; + if ($quoteObj->getIsMultiShipping()) { + $payByLinkParams['is_multishipping'] = true; + } + $this->payByLinkEmail->sendPayBylinkEmail($payByLinkParams); + } + } + } + return $this; + } + /** + * Cancel Multishipping Orders + * + * @param object $quoteObj + * @param string $orderCode + * @param string $merchantCode + */ + private function cancelMultiShippingOrders($quoteObj, $orderCode, $merchantCode) + { + $multiShippingOrders = $this->wpMultishippingCollection->getMultishippingOrderIds($quoteObj->getId()); + if (count($multiShippingOrders) > 0) { + foreach ($multiShippingOrders as $orderId) { + $orderObj = $this->orderItemsDetails->loadByIncrementId($orderId); + $this->_applyPaymentUpdate( + $this->multishippingStateResponse->createCancelledResponse( + $orderCode, + $merchantCode + ), + $orderObj + ); + } + } + } + /** + * Apply Payment Update + * + * @param string $paymentState + * @param array $order + * @return string + */ + private function _applyPaymentUpdate($paymentState, $order) + { + try { + $this->_paymentUpdate = $this->paymentservice + ->createPaymentUpdateFromWorldPayResponse($paymentState); + $this->_paymentUpdate->apply($order->getPayment(), $order); + } catch (\Exception $e) { + $this->_logger->error($e->getMessage()); + } + } + /** + * Format Grand Total + * + * @param \Magento\Sales\Model\Order $mageOrder + * @return string + */ + public function getFormatGrandTotal($mageOrder) + { + if ($mageOrder->getGrandTotal()) { + $formattedTotal = $this->pricingHelper->currency($mageOrder->getGrandTotal(), true, false); + return $formattedTotal; + } + } + /** + * Format Shipping Address + * + * @param array $address + * @return array + */ + + public function getFormatAddressByCode($address) + { + $renderer = $this->_addressConfig->getFormatByCode('html')->getRenderer(); + return $renderer->renderArray($address); + } +} diff --git a/Cron/RecurringOrders.php b/Cron/RecurringOrders.php index 77b296fb..d7add497 100644 --- a/Cron/RecurringOrders.php +++ b/Cron/RecurringOrders.php @@ -64,7 +64,52 @@ class RecurringOrders * @var CollectionFactory */ private $addressCollectionFactory; - + + /** + * @var \Sapient\Worldpay\Helper\Data + */ + private $worldpayhelper; + + /** + * @var \Sapient\Worldpay\Model\Payment\Service + */ + protected $paymentservice; + + /** + * @var \Sapient\Worldpay\Model\Order\Service + */ + protected $orderservice; + + /** + * @var JsonFactory + */ + protected $resultJsonFactory; + + /** + * @var \Sapient\Worldpay\Model\SavedToken + */ + protected $worldpaytoken; + + /** + * @var \Sapient\Worldpay\Helper\Recurring + */ + protected $recurringhelper; + + /** + * @var \Sapient\Worldpay\Model\Recurring\Subscription\TransactionsFactory + */ + protected $transactionFactory; + + /** + * @var \Sapient\Worldpay\Model\Recurring\PlanFactory + */ + protected $planFactory; + + /** + * @var \Magento\Sales\Model\ResourceModel\Order\CollectionFactory + */ + protected $_orderCollectionFactory; + /** * Constructor * @@ -78,7 +123,7 @@ class RecurringOrders * @param \Sapient\Worldpay\Model\Recurring\Subscription $subscriptions * @param \Sapient\Worldpay\Model\Recurring\Subscription\Transactions $recurringTransactions * @param \Sapient\Worldpay\Model\Recurring\Subscription\Address $subscriptionAddress - * @param Sapient\Worldpay\Helper\Recurring $recurringhelper + * @param \Sapient\Worldpay\Helper\Recurring $recurringhelper * @param SubscriptionFactory $subscriptionFactory * @param \Sapient\Worldpay\Model\Recurring\Subscription\TransactionsFactory $transactionsFactory * @param \Sapient\Worldpay\Model\Recurring\PlanFactory $planFactory @@ -129,8 +174,12 @@ public function execute() $totalInfo = $this->getTotalDetails($recurringOrderData); if ($totalInfo && isset($totalInfo['tokenData'][0])) { $orderDetails = $totalInfo['orderDetails'][0]; - $addressDetails['shipping'] = $totalInfo['addressData'][1]; $addressDetails['billing'] = $totalInfo['addressData'][0]; + if (!empty($totalInfo['addressData'][1])) { + $addressDetails['shipping'] = $totalInfo['addressData'][1]; + } else { + $addressDetails['shipping'] = $totalInfo['addressData'][0]; + } $subscriptionDetails = $totalInfo['subscriptionData'][0]; $tokenDetails = $totalInfo['tokenData'][0]; $orderData = [ @@ -289,7 +338,7 @@ private function getOrderCollectionFactory() { if ($this->orderCollectionFactory === null) { - $this->orderCollectionFactory = ObjectManager::getInstance()->get(CollectionFactoryInterface::class); + $this->orderCollectionFactory = $this->_orderCollectionFactory; } return $this->orderCollectionFactory; } diff --git a/Helper/Data.php b/Helper/Data.php index a705173d..3f5dda56 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -50,6 +50,90 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper */ protected $worldpaypaymentmodel; + /** + * @var \Sapient\Worldpay\Model\Utilities\PaymentMethods + */ + public $paymentlist; + + /** + * @var \Sapient\Worldpay\Helper\Merchantprofile + */ + public $merchantprofile; + + /** + * @var \Magento\Checkout\Model\Session + */ + public $_checkoutSession; + + /** + * @var \Magento\Sales\Model\OrderFactory + */ + public $orderFactory; + + /** + * @var \Sapient\Worldpay\Helper\Recurring + */ + public $recurringHelper; + + /** + * @var \Sapient\Worldpay\Helper\ExtendedResponseCodes + */ + public $extendedResponseCodes; + + /** + * @var \Sapient\Worldpay\Helper\Instalmentconfig + */ + public $instalmentconfig; + + /** + * @var \Magento\Sales\Model\ResourceModel\Order\CollectionFactory + */ + public $orderCollectionFactory; + + /** + * @var \Sapient\Worldpay\Model\SavedTokenFactory + */ + public $_savecard; + + /** + * @var \Magento\Sales\Model\Order\ItemFactory + */ + public $_itemFactory; + + /** + * @var \Sapient\Worldpay\Helper\Currencyexponents + */ + public $currencyexponents; + + /** + * @var \Sapient\Worldpay\Helper\KlarnaCountries + */ + public $klarnaCountries; + + /** + * @var \Magento\Backend\Model\Session\Quote + */ + public $adminsessionquote; + + /** + * @var \Magento\Framework\App\ProductMetadataInterface + */ + public $productMetaData; + + /** + * @var \Magento\Quote\Model\QuoteFactory + */ + public $quoteFactory; + + /** + * @var \Magento\Framework\Locale\CurrencyInterface + */ + public $localecurrency; + /** + * @var mixed + */ + public $quotes; + /** * Constructor * @@ -387,7 +471,6 @@ public function getApmTypes($code) $allApmMethods = [ 'CHINAUNIONPAY-SSL' => 'Union Pay', 'IDEAL-SSL' => 'IDEAL', - 'QIWI-SSL' => 'Qiwi', //'YANDEXMONEY-SSL' => 'Yandex.Money', 'PAYPAL-EXPRESS' => 'PayPal', 'SOFORT-SSL' => 'SoFort EU', @@ -407,7 +490,9 @@ public function getApmTypes($code) $activeMethods = []; foreach ($configMethods as $method) { if ($this->paymentlist->checkCurrency($code, $method)) { - $activeMethods[$method] = $allApmMethods[$method]; + if (isset($allApmMethods[$method])) { + $activeMethods[$method] = $allApmMethods[$method]; + } } } return $activeMethods; @@ -421,13 +506,11 @@ public function getApmTypes($code) public function getWalletsTypes($code) { $activeMethods = []; - if ($this->isMultiShipping()) { - if ($this->isGooglePayEnable()) { - $activeMethods['PAYWITHGOOGLE-SSL'] = 'Google Pay'; - } - if ($this->isApplePayEnable()) { - $activeMethods['APPLEPAY-SSL'] = 'Apple Pay'; - } + if ($this->isGooglePayEnable()) { + $activeMethods['PAYWITHGOOGLE-SSL'] = 'Google Pay'; + } + if ($this->isApplePayEnable()) { + $activeMethods['APPLEPAY-SSL'] = 'Apple Pay'; } if ($this->isSamsungPayEnable()) { $activeMethods['SAMSUNGPAY-SSL'] = 'Samsung Pay'; @@ -893,10 +976,24 @@ public function getOrderDescription() \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); if ($this->isMultiShipping()) { - return 'Multishipping - '.$description; + return $this->getMultiShippingOrderDescription(); } return $description; } + + /** + * Get Multishipping OrderDescription + * + * @return string + */ + public function getMultiShippingOrderDescription() + { + $description = $this->_scopeConfig->getValue( + 'worldpay/general_config/order_description', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + return __('Multishipping - ').$description; + } /** * Get MotoTitle * @@ -2608,18 +2705,19 @@ public function getCurrentMagentoVersionDetails() } /** * Get Plugin Tracker Details + * + * @param string $username + * @param SimpleXMLElement $xmlQuote */ - public function getPluginTrackerdetails() + public function getPluginTrackerdetails($username, $xmlQuote) { $details=[]; - $details['MERCHANT_ID'] = $this->_scopeConfig->getValue( - 'worldpay/general_config/merchant_code', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ); - $details['API_USERNAME'] = $this->_scopeConfig->getValue( - 'worldpay/general_config/xml_username', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ); + + $xmlquoteData = clone($xmlQuote); + $quoteData = new \SimpleXmlElement($xmlquoteData->saveXML()); + $merchantCode = (string) $quoteData['merchantCode']; + $details['MERCHANT_ID'] = $merchantCode; + $details['API_USERNAME'] = $username; $magento = $this->getCurrentMagentoVersionDetails(); $details['MAGENTO_EDITION'] = $magento['Edition']; $details['MAGENTO_VERSION'] = $magento['Version']; @@ -2794,6 +2892,26 @@ public function getPayByLinkButtonName() \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); } + /** + * Get Pay by Link Expirt Lifetime + */ + public function getPayByLinkExpiryTime() + { + return $this->_scopeConfig->getValue( + 'worldpay/paybylink_config/paybylink_expiry_time', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + } + /** + * Check if Pay By Link resend option enable + */ + public function isPayByLinkResendEnable() + { + return $this->_scopeConfig->getValue( + 'worldpay/paybylink_config/paybylink_resend_link', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + } /** * GetWorldpayPayment Model */ @@ -2801,4 +2919,274 @@ public function getWorldpayPaymentModel() { return $this->worldpaypaymentmodel; } + /** + * Get Recurring MerchantCode + * + * @return string + */ + public function getRecurringMerchantCode() + { + $recurringMerchantCode = $this->_scopeConfig->getValue( + 'worldpay/recurring_merchant_config/recurring_merchant_code', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + return $recurringMerchantCode; + } + /** + * Get Recurring Merchant Username + * + * @return string + */ + public function getRecurringUsername() + { + $recurringMerchantUn = $this->_scopeConfig->getValue( + 'worldpay/recurring_merchant_config/recurring_username', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + return $recurringMerchantUn; + } + /** + * Get Recurring Merchant Password + * + * @return string + */ + public function getRecurringPassword() + { + $recurringMerchantPw = $this->_scopeConfig->getValue( + 'worldpay/recurring_merchant_config/recurring_password', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + return $recurringMerchantPw; + } + + /** + * Check if Pay By Link merchant code + */ + public function getPayByLinkMerchantCode() + { + $paybyLinkMC = $this->_scopeConfig->getValue( + 'worldpay/paybylink_config/pbl_merchant_code', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + return $paybyLinkMC; + } + + /** + * Get Pay by Link Merchant username + */ + public function getPayByLinkMerchantUsername() + { + $paybyLinkUn = $this->_scopeConfig->getValue( + 'worldpay/paybylink_config/pbl_xml_username', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + return $paybyLinkUn; + } + + /** + * Get Pay by Link merchant password + */ + public function getPayByLinkMerchantPassword() + { + $paybyLinkPw = $this->_scopeConfig->getValue( + 'worldpay/paybylink_config/pbl_xml_password', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + return $paybyLinkPw; + } + + /** + * Get multishipping merchant code + */ + public function getMultishippingMerchantCode() + { + $multishippingMC = $this->_scopeConfig->getValue( + 'worldpay/multishipping/ms_merchant_code', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + return $multishippingMC; + } + + /** + * Get multishipping Merchant username + */ + public function getMultishippingMerchantUsername() + { + $multishippingUn = $this->_scopeConfig->getValue( + 'worldpay/multishipping/ms_xml_username', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + return $multishippingUn; + } + + /** + * Get multishipping merchant password + */ + public function getMultishippingMerchantPassword() + { + $multishippingPw = $this->_scopeConfig->getValue( + 'worldpay/multishipping/ms_xml_password', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + return $multishippingPw; + } + /** + * Get multishipping Installation Id + */ + public function getMultishippingInstallationId() + { + $multishippingIID = $this->_scopeConfig->getValue( + 'worldpay/multishipping/ms_xml_installationId', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + return $multishippingIID; + } + + /** + * Get PaybyLink Installation Id + */ + public function getPayByLinkInstallationId() + { + $pblIId = $this->_scopeConfig->getValue( + 'worldpay/paybylink_config/pbl_xml_installationId', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + return $pblIId; + } + + /** + * Calculate Pay By Link Resend expiry time + * + * @param int $expiryTime + * @retrun int + */ + public function calculatePblResendExpiryTime($expiryTime) + { + return $expiryTime * 2; + } + + /** + * Find Pay By Link Interval time between order date and current date + * + * @param string $currentDate + * @param string $orderDate + * @retrun int + */ + public function findPblOrderIntervalTime($currentDate, $orderDate) + { + return round(abs(strtotime($currentDate) - strtotime($orderDate))/3600, 0); + } + + /** + * Find Pay By Link expiry date and time + * + * @param string $currentDate + * @param string $expiryTime + * @retrun int + */ + public function findPblOrderExpiryTime($currentDate, $expiryTime) + { + return strtotime(date("Y-m-d H:i:s", strtotime($currentDate)) . " -$expiryTime hour"); + } + + /** + * Find Pay By Link expiry date and time + * + * @param string $minDate + * @retrun array + */ + public function findFromToPblDateAndTime($minDate) + { + $dates = []; + $cronMinDate = date('Y-m-d H:i', $minDate).':00'; + $maxDate = strtotime(date("Y-m-d H:i:s", strtotime($cronMinDate)) . " +59 seconds"); + $cronMaxDate = date('Y-m-d H:i:s', $maxDate); + $dates['from'] = $cronMinDate; + $dates['to'] = $cronMaxDate; + + return $dates; + } + /** + * Get Capture Delay value + */ + public function getCaptureDelayValues() + { + $captureDelay = $this->_scopeConfig->getValue( + 'worldpay/dynamic_capture_delay/capture_delay', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + if ($captureDelay == \Sapient\Worldpay\Model\Config\Source\CaptureDelay::CUSTOM_CAPTURE_DELAY_KEY) { + $captureDelay = $this->_scopeConfig->getValue( + 'worldpay/dynamic_capture_delay/capture_delay_custom_value', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + } + return $captureDelay; + } + /** + * Get SEPA Details + * + * @return string + */ + public function getSEPADetails() + { + $integrationmode = $this->getCcIntegrationMode(); + $apmmethods = $this->getApmTypes('worldpay_apm'); + if (strtoupper($integrationmode) === 'DIRECT' && + array_key_exists("SEPA_DIRECT_DEBIT-SSL", $apmmethods)) { + $data = $this->getSEPAMandateTypes(); + if (!empty($data)) { + return explode(",", $data); + } + } + return []; + } + /** + * Get SEPA E-Mandate + * + * @return string + */ + public function getSepaEmandate() + { + return $this->_scopeConfig->getValue( + 'worldpay/apm_config/sepa_e_mandate', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + } + + /** + * Get SEPA Mandate Types + * + * @return string + */ + public function getSEPAMandateTypes() + { + return $this->_scopeConfig->getValue( + 'worldpay/apm_config/sepa_mandate_types', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + } + /** + * Get SEPA Merchant Number + * + * @return string + */ + + public function getSEPAMerchantNo() + { + return $this->_scopeConfig->getValue( + 'worldpay/apm_config/sepa_merchant_no', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + } + /** + * Get Order By OrderIncrementId + * + * @param string $orderIncId + * @return string + */ + public function getOrderByOrderIncId($orderIncId) + { + return $this->orderFactory->create()->loadByIncrementId($orderIncId); + } } diff --git a/Helper/Instalmentconfig.php b/Helper/Instalmentconfig.php index 55feb9cf..3eae8c15 100644 --- a/Helper/Instalmentconfig.php +++ b/Helper/Instalmentconfig.php @@ -36,24 +36,32 @@ class Instalmentconfig * @var SerializerInterface */ private $serializer; + + /** + * @var \Magento\Framework\Serialize\Serializer\Json + */ + protected $json; /** * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Framework\Math\Random $mathRandom * @param \Sapient\Worldpay\Model\Config\Source\InstalmentTypes $instalmentTypes * @param SerializerInterface $serializer + * @param \Magento\Framework\Serialize\Serializer\Json $json */ public function __construct( \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\Math\Random $mathRandom, \Sapient\Worldpay\Model\Config\Source\InstalmentTypes $instalmentTypes, - SerializerInterface $serializer + SerializerInterface $serializer, + \Magento\Framework\Serialize\Serializer\Json $json ) { $this->scopeConfig = $scopeConfig; $this->mathRandom = $mathRandom; $this->instalmentTypes = $instalmentTypes; $this->serializer = $serializer; + $this->json = $json; } /** @@ -328,9 +336,9 @@ public function getSerializedConfigValue($configPath, $store = null) } if ($this->isSerialized($value)) { - $unserializer = ObjectManager::getInstance()->get(\Magento\Framework\Unserialize\Unserialize::class); + $unserializer = $this->serializer; } else { - $unserializer = ObjectManager::getInstance()->get(\Magento\Framework\Serialize\Serializer\Json::class); + $unserializer = $this->json; } return $unserializer->unserialize($value); diff --git a/Helper/KlarnaCountries.php b/Helper/KlarnaCountries.php index f7261885..be0d1c00 100644 --- a/Helper/KlarnaCountries.php +++ b/Helper/KlarnaCountries.php @@ -28,6 +28,11 @@ class KlarnaCountries * @var SerializerInterface */ private $serializer; + + /** + * @var \Sapient\Worldpay\Model\Config\Source\KlarnaCountries + */ + protected $klarnaCountries; /** * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig diff --git a/Helper/Multishipping.php b/Helper/Multishipping.php index 9efaf630..9f6cae98 100644 --- a/Helper/Multishipping.php +++ b/Helper/Multishipping.php @@ -39,6 +39,74 @@ class Multishipping */ public $generalexception; + /** + * @var \Magento\Multishipping\Model\Checkout\Type\Multishipping\State + */ + public $state; + /** + * @var \Magento\Framework\Session\SessionManagerInterface + */ + public $session; + /** + * @var \Magento\Checkout\Model\Session + */ + public $checkoutSession; + /** + * @var \Magento\Framework\Message\ManagerInterface + */ + public $messageManager; + /** + * @var \Magento\Framework\Event\ManagerInterface + */ + public $eventManager; + /** + * @var \Sapient\Worldpay\Model\Checkout\Type\MultishippingFactory + */ + public $multishippingCheckoutFactory; + /** + * @var \Sapient\Worldpay\Helper\Data + */ + public $helper; + /** + * @var \Sapient\Worldpay\Model\Multishipping\OrderFactory + */ + public $multishippingOrderFactory; + /** + * @var \Sapient\Worldpay\Model\Multishipping\Order + */ + public $multishippingOrder; + /** + * @var \Sapient\Worldpay\Model\ResourceModel\Multishipping\Order\Collection + */ + public $multishippingOrderCollection; + /** + * @var \Magento\Framework\App\Request\Http + */ + public $request; + + /** + * @var \Sapient\Worldpay\Model\Payment\UpdateWorldpaymentFactory + */ + public $updateWorldPayPayment; + /** + * @var \Sapient\Worldpay\Model\Order\Service + */ + public $orderservice; + /** + * @var \Magento\Store\Model\StoreManagerInterface + */ + public $storeManager; + + /** + * @var \Magento\Sales\Model\Order\Email\Sender\OrderSender + */ + public $emailsender; + + /** + * @var \Sapient\Worldpay\Helper\CreditCardException + */ + public $exceptionHelper; + /** * Constructor * @@ -164,7 +232,7 @@ protected function getFinalRedirectUrl($quoteId, $cc_type) // Redirect to the success page $this->state->setCompleteStep(State::STEP_OVERVIEW); $this->state->setActiveStep(State::STEP_SUCCESS); - if ($cc_type == 'ACH_DIRECT_DEBIT-SSL') { + if ($cc_type == 'ACH_DIRECT_DEBIT-SSL' || $cc_type == 'SEPA_DIRECT_DEBIT-SSL') { $url = $this->getUrl('worldpay/savedcard/Multishippingredirect'); $response['redirect'] = $url; } elseif ($cc_type == 'APPLEPAY-SSL') { @@ -622,4 +690,14 @@ public function getConfigValue($order, $paymenttype, $scope = null) $store = $this->storeManager->getStore($storeid)->getCode(); return $this->generalexception->getConfigValue($paymenttype, $store, $scope); } + /** + * Get multishipping order ids + * + * @param string $quoteId + */ + public function getMultishippingOrdersIds($quoteId) + { + $multiShippingOrders = $this->multishippingOrderCollection->getMultishippingOrderIds($quoteId); + return $multiShippingOrders; + } } diff --git a/Helper/Recurring.php b/Helper/Recurring.php index a6ffb6b9..060e3bb2 100644 --- a/Helper/Recurring.php +++ b/Helper/Recurring.php @@ -87,6 +87,61 @@ class Recurring extends \Magento\Framework\App\Helper\AbstractHelper * @var curlHelper */ protected $curlHelper; + + /** + * @var \Magento\Store\Model\StoreManagerInterface + */ + protected $_storeManager; + + /** + * @var \Magento\Customer\Model\CustomerFactory + */ + protected $customerFactory; + + /** + * @var \Magento\Customer\Api\CustomerRepositoryInterface + */ + protected $customerRepository; + + /** + * @var \Magento\Sales\Model\Service\OrderService + */ + protected $orderService; + + /** + * @var \Magento\Quote\Model\Quote\Payment + */ + protected $payment; + + /** + * @var \Magento\Checkout\Model\Cart + */ + protected $cart; + + /** + * @var \Magento\Customer\Model\Session + */ + protected $customerSession; + + /** + * @var \Magento\Integration\Model\Oauth\TokenFactory + */ + protected $tokenModelFactory; + + /** + * @var \Magento\Quote\Model\QuoteFactory + */ + protected $quote; + + /** + * @var \Magento\Quote\Model\QuoteManagement + */ + protected $quoteManagement; + + /** + * @var \Magento\Integration\Model\Oauth\TokenFactory + */ + protected $_tokenModelFactory; /** * Recurring constructor * @param \Magento\Framework\App\Helper\Context $context @@ -145,15 +200,12 @@ public function __construct( $this->localeDate = $localeDate; $this->scopeConfig = $scopeConfig; $this->_storeManager = $storeManager; - $this->_product = $product; - $this->_formkey = $formkey; $this->quote = $quote; $this->quoteManagement = $quoteManagement; $this->customerFactory = $customerFactory; $this->customerRepository = $customerRepository; $this->orderService = $orderService; $this->payment = $payment; - $this->_cart = $cart; $this->_customerSession = $customerSession; $this->_tokenModelFactory = $tokenModelFactory; $this->serializer = $serializer; @@ -607,8 +659,6 @@ public function createMageOrder($orderData, $paymentData) $customer->loadByEmail($orderData['email']);// load customet by email address $customerToken = $this->_tokenModelFactory->create(); $tokenKey = $customerToken->createCustomerToken($customer->getId())->getToken(); - $savedShippingMethod = explode('_', $orderData['shipping_method']); - $quoteId = $this->createEmptyQuote($tokenKey); $itemData = []; $itemData['cartItem'] = ['sku' => $orderData['product_sku'], @@ -621,20 +671,22 @@ public function createMageOrder($orderData, $paymentData) $this->updateCartItem($cartId, $itemId, $price, $orderData['qty']); $addressData = []; $addressData['address'] = $orderData['shipping_address']; - $shippingMethodResponse = $this->getShippingMethods($tokenKey, json_encode($addressData)); - foreach ($shippingMethodResponse as $shippingMethod) { - if ($shippingMethod['carrier_code'] == $savedShippingMethod[0]) { - $shippingCarrierCode = $shippingMethod['carrier_code']; - $shippingMethodCode = $shippingMethod['method_code']; + if (!empty($orderData['shipping_method'])) { + $savedShippingMethod = explode('_', $orderData['shipping_method']); + $shippingMethodResponse = $this->getShippingMethods($tokenKey, json_encode($addressData)); + foreach ($shippingMethodResponse as $shippingMethod) { + if ($shippingMethod['carrier_code'] == $savedShippingMethod[0]) { + $shippingCarrierCode = $shippingMethod['carrier_code']; + $shippingMethodCode = $shippingMethod['method_code']; + } } + $shippingInformation = []; + $shippingInformation['addressInformation']['shipping_address'] = $orderData['shipping_address']; + $shippingInformation['addressInformation']['billing_address'] = $orderData['billing_address']; + $shippingInformation['addressInformation']['shipping_carrier_code'] = $shippingCarrierCode; + $shippingInformation['addressInformation']['shipping_method_code'] = $shippingMethodCode; + $shippingResponse = $this->setShippingInformation($tokenKey, json_encode($shippingInformation)); } - $shippingInformation = []; - $shippingInformation['addressInformation']['shipping_address'] = $orderData['shipping_address']; - $shippingInformation['addressInformation']['billing_address'] = $orderData['billing_address']; - $shippingInformation['addressInformation']['shipping_carrier_code'] = $shippingCarrierCode; - $shippingInformation['addressInformation']['shipping_method_code'] = $shippingMethodCode; - - $shippingResponse = $this->setShippingInformation($tokenKey, json_encode($shippingInformation)); $paymentData = json_encode($paymentData); $orderId = $this->orderPayment($tokenKey, $paymentData); return $orderId; diff --git a/Helper/SendErrorReport.php b/Helper/SendErrorReport.php index 73fc8b3b..7a903803 100644 --- a/Helper/SendErrorReport.php +++ b/Helper/SendErrorReport.php @@ -21,6 +21,21 @@ class SendErrorReport extends \Magento\Framework\App\Helper\AbstractHelper * @var \Sapient\Worldpay\Logger\WorldpayLogger */ protected $wplogger; + + /** + * @var \Sapient\Worldpay\Model\Mail\Template\EmailTransportBuilder + */ + protected $transportBuilder; + + /** + * @var \Magento\Framework\Translate\Inline\StateInterface + */ + protected $inlineTranslation; + + /** + * @var \Magento\Store\Model\StoreManagerInterface + */ + protected $storeManager; /** * SendErrorReport constructor diff --git a/Helper/SendPayByLinkEmail.php b/Helper/SendPayByLinkEmail.php index 2357ab08..6aae9602 100644 --- a/Helper/SendPayByLinkEmail.php +++ b/Helper/SendPayByLinkEmail.php @@ -11,6 +11,7 @@ class SendPayByLinkEmail extends \Magento\Framework\App\Helper\AbstractHelper { public const WORLDPAY_SALES_EMAIL_PAYBYLINK_TEMPLATE = "wp_sales_email_paybylink"; + public const WORLDPAY_SALES_EMAIL_PAYBYLINK_MULTISHIPPING_TEMPLATE = "wp_sales_email_paybylink_multishipping"; /** * @var ScopeConfigInterface @@ -20,15 +21,29 @@ class SendPayByLinkEmail extends \Magento\Framework\App\Helper\AbstractHelper * @var \Sapient\Worldpay\Logger\WorldpayLogger */ protected $wplogger; + + /** + * @var \Magento\Store\Model\StoreManagerInterface + */ + protected $storeManager; + + /** + * @var \Magento\Framework\Translate\Inline\StateInterface + */ + protected $inlineTranslation; + /** + * @var \Sapient\Worldpay\Model\Mail\Template\EmailTransportBuilder + */ + protected $transportBuilder; /** * @var \Magento\Customer\Model\Session */ protected $_customerSession; - /** - * @var CheckoutSession - */ - private $checkoutSession; + /** + * @var CheckoutSession + */ + private $checkoutSession; /** * SendPayByLinkEmail constructor * @@ -86,6 +101,21 @@ public function getCustomerEmail() } return []; } + /** + * Get Customer Emails + * + * @param string $customerEmail + */ + public function getCustomerEmailForResend($customerEmail) + { + if (!empty($customerEmail)) { + $allEmails = explode(',', $customerEmail); + if (!empty($allEmails)) { + return $allEmails; + } + } + return []; + } /** * Send Email * @@ -96,12 +126,26 @@ public function sendEmail($params, $toEmail) { $senderDetails = $this->getAdminContactEmail(); $templateId = self::WORLDPAY_SALES_EMAIL_PAYBYLINK_TEMPLATE; + if ($params['is_multishipping']) { + $templateId = self::WORLDPAY_SALES_EMAIL_PAYBYLINK_MULTISHIPPING_TEMPLATE; + } try { // template variables pass here $templateVars = $params; - $templateVars['mail_subject'] = __("WORLDPAY: "). + $subject = __("WORLDPAY: "). "Pay by Link for Order".' '.$this->checkoutSession->getAuthenticatedOrderId(); + + if ($params['is_multishipping']) { + $subject = __("WORLDPAY: "). + "Pay by Link for Multishipping Order".' '.$params['orderId']; + } + + if ($params['is_resend']) { + $subject = __("WORLDPAY: "). + "Resend Pay by Link for Order".' '.$params['orderId']; + } + $templateVars['mail_subject'] = $subject; $storeId = $this->storeManager->getStore()->getId(); $from = ['email' => $senderDetails['email'], 'name' => $senderDetails['name']]; $this->inlineTranslation->suspend(); @@ -149,7 +193,11 @@ public function sendPayBylinkEmail($params) { try { if ($this->isEnablePayByLink()) { - $customerEmail = $this->getCustomerEmail(); + if ($params['is_resend']) { + $customerEmail = $this->getCustomerEmailForResend($params['customerEmail']); + } else { + $customerEmail = $this->getCustomerEmail(); + } if (!empty($customerEmail)) { foreach ($customerEmail as $recipientEmail) { $this->sendEmail($params, $recipientEmail); diff --git a/Logger/WorldpayLogger.php b/Logger/WorldpayLogger.php index 12e2dfca..91d6c945 100644 --- a/Logger/WorldpayLogger.php +++ b/Logger/WorldpayLogger.php @@ -4,8 +4,41 @@ */ namespace Sapient\Worldpay\Logger; +use DateTimeZone; +use Monolog\Handler\HandlerInterface; + class WorldpayLogger extends \Monolog\Logger { + /** + * @var \Magento\Framework\App\Config\ScopeConfigInterface + */ + public $scopeConfig; + + /** + * Constructor + * + * @param string $name + * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig + * @param array $handlers + * @param array $processors + * @param DateTimeZone $timezone + * + */ + public function __construct( + string $name, + \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, + array $handlers = [], + array $processors = [], + ?DateTimeZone $timezone = null + ) { + $this->scopeConfig = $scopeConfig; + parent::__construct( + $name, + $handlers, + $processors, + $timezone ?: new DateTimeZone(date_default_timezone_get() ?: 'UTC') + ); + } /** * Adds a log record. * @@ -17,9 +50,8 @@ class WorldpayLogger extends \Monolog\Logger */ public function addRecord($level, $message, array $context = [], $datetime = null) : bool { - $ObjectManager = \Magento\Framework\App\ObjectManager::getInstance(); - $logEnabled = (bool) $ObjectManager->get(\Magento\Framework\App\Config\ScopeConfigInterface::class) - ->getValue('worldpay/general_config/enable_logging'); + $logEnabled = (bool) $this->scopeConfig->getValue('worldpay/general_config/enable_logging'); + if ($logEnabled) { return parent::addRecord($level, $message, $context); } diff --git a/Model/Adminhtml/Order/Service.php b/Model/Adminhtml/Order/Service.php index f7d7b494..d56723da 100644 --- a/Model/Adminhtml/Order/Service.php +++ b/Model/Adminhtml/Order/Service.php @@ -6,6 +6,15 @@ class Service { + /** + * @var \Magento\Backend\Model\Session\Quote + */ + protected $adminsessionquote; + + /** + * @var \Magento\Sales\Model\AdminOrder\Create + */ + protected $adminordercreate; /** * Service constructor * diff --git a/Model/Authorisation/DirectService.php b/Model/Authorisation/DirectService.php index bdd460f8..873765b0 100644 --- a/Model/Authorisation/DirectService.php +++ b/Model/Authorisation/DirectService.php @@ -17,6 +17,51 @@ class DirectService extends \Magento\Framework\DataObject * @var \Sapient\Worldpay\Model\Payment\UpdateWorldpaymentFactory */ protected $updateWorldPayPayment; + + /** + * @var \Sapient\Worldpay\Model\Request\PaymentServiceRequest + */ + protected $mappingservice; + + /** + * @var \Sapient\Worldpay\Model\Payment\UpdateWorldpaymentFactory + */ + protected $paymentservicerequest; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + + /** + * @var \Sapient\Worldpay\Model\Response\DirectResponse + */ + protected $directResponse; + + /** + * @var \Sapient\Worldpay\Model\Payment\Service + */ + protected $paymentservice; + + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $worldpayHelper; + + /** + * @var \Sapient\Worldpay\Helper\Registry + */ + protected $registryhelper; + + /** + * @var \Magento\Framework\UrlInterface + */ + protected $urlBuilders; + + /** + * @var \Sapient\Worldpay\Helper\Multishipping + */ + protected $multishippingHelper; /** * @var \Magento\Framework\DataObject\Copy @@ -118,6 +163,14 @@ public function authorizePayment( $paymentDetails ); $response = $this->paymentservicerequest->achOrder($directOrderParams); + } elseif ($paymentDetails['additional_data']['cc_type'] == 'SEPA_DIRECT_DEBIT-SSL') { + $directOrderParams = $this->mappingservice->collectSEPAOrderParameters( + $orderCode, + $quote, + $orderStoreId, + $paymentDetails + ); + $response = $this->paymentservicerequest->sepaOrder($directOrderParams); } else { $directOrderParams = $this->mappingservice->collectDirectOrderParameters( $orderCode, diff --git a/Model/Authorisation/HostedPaymentPageService.php b/Model/Authorisation/HostedPaymentPageService.php index 28953784..9d3a972a 100644 --- a/Model/Authorisation/HostedPaymentPageService.php +++ b/Model/Authorisation/HostedPaymentPageService.php @@ -13,6 +13,48 @@ class HostedPaymentPageService extends \Magento\Framework\DataObject protected $_status; /** @var \Sapient\Worldpay\Model\Response\RedirectResponse */ protected $_redirectResponseModel; + /** + * @var \Sapient\Worldpay\Model\Request\PaymentServiceRequest + */ + protected $mappingservice; + /** + * @var \Sapient\Worldpay\Model\Payment\UpdateWorldpaymentFactory + */ + protected $paymentservicerequest; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + + /** + * @var \Sapient\Worldpay\Helper\Registry + */ + protected $registryhelper; + + /** + * @var \Magento\Checkout\Model\Session + */ + protected $checkoutsession; + + /** + * @var \Sapient\Worldpay\Model\Checkout\Hpp\State + */ + protected $hppstate; + + /** + * @var \Magento\Framework\UrlInterface + */ + protected $_urlInterface; + /** + * @var \Sapient\Worldpay\Model\Response\RedirectResponse + */ + protected $redirectresponse; + + /** + * @var \Sapient\Worldpay\Helper\Multishipping + */ + protected $multishippingHelper; /** * Constructor diff --git a/Model/Authorisation/MotoRedirectService.php b/Model/Authorisation/MotoRedirectService.php index c426060a..d3137f62 100644 --- a/Model/Authorisation/MotoRedirectService.php +++ b/Model/Authorisation/MotoRedirectService.php @@ -17,6 +17,55 @@ class MotoRedirectService extends \Magento\Framework\DataObject */ protected $_redirectResponseModel; + /** + * @var \Sapient\Worldpay\Model\Request\PaymentServiceRequest + */ + protected $mappingservice; + /** + * @var \Sapient\Worldpay\Model\Payment\UpdateWorldpaymentFactory + */ + protected $paymentservicerequest; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + + /** + * @var \Sapient\Worldpay\Helper\Registry + */ + protected $registryhelper; + + /** + * @var \Magento\Checkout\Model\Session + */ + protected $checkoutsession; + + /** + * @var \Sapient\Worldpay\Model\Payment\Service + */ + protected $paymentservice; + + /** + * @var \Sapient\Worldpay\Model\Response\RedirectResponse + */ + protected $redirectresponse; + + /** + * @var \Sapient\Worldpay\Model\Utilities\PaymentMethods + */ + protected $paymentlist; + + /** + * @var \Magento\Framework\UrlInterface + */ + protected $_urlBuilder; + + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $worldpayhelper; + /** * MotoRedirectService constructor * diff --git a/Model/Authorisation/PayByLinkService.php b/Model/Authorisation/PayByLinkService.php index 18fde4a0..9fdd7948 100644 --- a/Model/Authorisation/PayByLinkService.php +++ b/Model/Authorisation/PayByLinkService.php @@ -24,6 +24,87 @@ class PayByLinkService extends \Magento\Framework\DataObject */ protected $_storeManager; + /** + * @var \Sapient\Worldpay\Model\Request\PaymentServiceRequest + */ + protected $mappingservice; + /** + * @var \Sapient\Worldpay\Model\Payment\UpdateWorldpaymentFactory + */ + protected $paymentservicerequest; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + + /** + * @var \Sapient\Worldpay\Helper\Registry + */ + protected $registryhelper; + + /** + * @var \Sapient\Worldpay\Model\Payment\Service + */ + protected $paymentservice; + + /** + * @var \Sapient\Worldpay\Model\Response\RedirectResponse + */ + protected $redirectresponse; + /** + * @var \Sapient\Worldpay\Model\Utilities\PaymentMethods + */ + protected $paymentlist; + + /** + * @var \Magento\Checkout\Model\Session + */ + protected $checkoutsession; + /** + * @var \Magento\Framework\UrlInterface + */ + protected $_urlBuilder; + + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $worldpayhelper; + + /** + * @var \Sapient\Worldpay\Helper\SendPayByLinkEmail + */ + protected $payByLinkEmail; + + /** + * @var \Sapient\Worldpay\Model\Request + */ + protected $_request; + + /** + * @var \Magento\Framework\Message\ManagerInterface + */ + protected $_messageManager; + + /** + * @var \Magento\Checkout\Model\Cart + */ + protected $cart; + /** + * @var \Magento\Customer\Model\Address\Config + */ + protected $_addressConfig; + + /** + * @var \Magento\Framework\Pricing\Helper\Data + */ + protected $pricingHelper; + + /** + * @var \Sapient\Worldpay\Helper\Multishipping + */ + protected $multishippingHelper; + /** * MotoRedirectService constructor * @@ -44,6 +125,7 @@ class PayByLinkService extends \Magento\Framework\DataObject * @param \Magento\Checkout\Model\Cart $cart * @param \Magento\Customer\Model\Address\Config $addressConfig * @param \Magento\Framework\Pricing\Helper\Data $pricingHelper + * @param \Sapient\Worldpay\Helper\Multishipping $multishippingHelper */ public function __construct( \Sapient\Worldpay\Model\Mapping\Service $mappingservice, @@ -62,7 +144,8 @@ public function __construct( \Magento\Framework\Message\ManagerInterface $messageManager, \Magento\Checkout\Model\Cart $cart, \Magento\Customer\Model\Address\Config $addressConfig, - \Magento\Framework\Pricing\Helper\Data $pricingHelper + \Magento\Framework\Pricing\Helper\Data $pricingHelper, + \Sapient\Worldpay\Helper\Multishipping $multishippingHelper ) { $this->mappingservice = $mappingservice; $this->paymentservicerequest = $paymentservicerequest; @@ -81,6 +164,7 @@ public function __construct( $this->cart = $cart; $this->_addressConfig = $addressConfig; $this->pricingHelper = $pricingHelper; + $this->multishippingHelper = $multishippingHelper; } /** @@ -104,14 +188,36 @@ public function authorizePayment( $payment ) { $this->checkoutsession->setauthenticatedOrderId($mageOrder->getIncrementId()); - + /** Start Multishipping Code */ + $isMultishipping = false; + if ($this->multishippingHelper->isMultiShipping($quote)) { + $isMultishipping = true; + $sessionOrderCode = $this->multishippingHelper->getOrderCodeFromSession(); + if (!empty($sessionOrderCode)) { + $orgWorldpayPayment = $this->multishippingHelper->getOrgWorldpayId($sessionOrderCode); + $orgOrderId = $orgWorldpayPayment['order_id']; + $isOrg = false; + $this->multishippingHelper->_createWorldpayMultishipping($mageOrder, $sessionOrderCode, $isOrg); + $this->multishippingHelper->_copyWorldPayPayment($orgOrderId, $orderCode); + $payment->setIsTransactionPending(1); + return; + } else { + $isOrg = true; + $this->multishippingHelper->_createWorldpayMultishipping($mageOrder, $orderCode, $isOrg); + } + } + /** End Multishipping Code */ + $paymentDetails['is_paybylink_order'] = 1; $redirectOrderParams = $this->mappingservice->collectRedirectOrderParameters( $orderCode, $quote, $orderStoreId, $paymentDetails ); - + $redirectOrderParams['is_paybylink_order'] = 1; + if ($isMultishipping) { + $redirectOrderParams['isMultishippingOrder'] = 1; + } $responseXml = $this->paymentservicerequest->redirectOrder($redirectOrderParams); $successUrl = $this->_buildRedirectUrl( @@ -120,24 +226,47 @@ public function authorizePayment( $this->_getCountryForQuote($quote), $orderCode ); + $this->wplogger->info('Multishipping Payment URL =>'); + $this->wplogger->info($successUrl); $payment->setIsTransactionPending(1); $this->registryhelper->setworldpayRedirectUrl($successUrl); $this->checkoutsession->setPayByLinkRedirecturl($successUrl); $paybylink_url = $this->_storeManager->getStore() - ->getBaseUrl().'worldpay/paybylink/process?orderkey='.$orderCode; - + ->getBaseUrl().'worldpay/paybylink/process?orderkey='.$orderCode; + $this->wplogger->info('Pay By link URl '.$paybylink_url); $grandTotal = $this->getFormatGrandTotal($mageOrder); $address = $mageOrder->getShippingAddress(); if (empty($address)) { $address = $mageOrder->getBillingAddress(); } + $quote_id = $quote->getId(); $formatedAddress = $this->getFormatAddressByCode($address->getData()); + $multishippingOrderIds = $this->multishippingHelper->getMultishippingOrdersIds($quote_id); $this->payByLinkEmail->sendPayBylinkEmail([ 'paybylink_url'=>$paybylink_url, 'orderId'=> $mageOrder->getIncrementId(), 'order_total'=> $grandTotal, 'formated_shipping'=> $formatedAddress, - 'customerName' => $mageOrder->getCustomerFirstName().' '.$mageOrder->getCustomerLastName()]); + 'customerName' => $mageOrder->getCustomerFirstName().' '.$mageOrder->getCustomerLastName(), + 'is_multishipping' => $isMultishipping, + 'is_resend' => false, + 'customerEmail' => false, + 'quote_id' => $quote_id, + 'pblexpirytime' => $this->getPayByLinkExpiryTime(), + 'multishipping_order_ids'=> $multishippingOrderIds + ]); + } + + /** + * Get PBL expiry time + * + */ + public function getPayByLinkExpiryTime() + { + $currentDate = date('Y-m-d H:i:s'); + $pblExpiryConfiguration = $this->worldpayhelper->getPayByLinkExpiryTime(); + $interval = date("Y-m-d H:i:s", $this->worldpayhelper->findPblOrderExpiryTime($currentDate, $pblExpiryConfiguration)); + return $interval; } /** @@ -189,6 +318,7 @@ public function authorizeRegenaretPayment( $this->checkoutsession->setauthenticatedOrderId($mageOrder->getIncrementId()); try { + $paymentDetails['is_paybylink_order'] = 1; $redirectOrderParams = $this->mappingservice->collectRedirectOrderParameters( $orderCode, $quote, @@ -197,15 +327,32 @@ public function authorizeRegenaretPayment( ); /* Sending Order Inquiry */ $this->xmlinquiry = new \Sapient\Worldpay\Model\XmlBuilder\Inquiry(); + + $merchantCode = $redirectOrderParams['merchantCode']; + $merchantUsername = $this->worldpayhelper->getXmlUsername($redirectOrderParams['paymentType']); + $merchantPassword = $this->worldpayhelper->getXmlPassword($redirectOrderParams['paymentType']); + $installationId = $this->worldpayhelper->getInstallationId($redirectOrderParams['paymentType']); + // pbl merchant configurations + $pblMerchantUn = $this->worldpayhelper->getPayByLinkMerchantUsername(); + $pblMerchantPw = $this->worldpayhelper->getPayByLinkMerchantPassword(); + $pblMerchantCode = $this->worldpayhelper->getPayByLinkMerchantCode(); + $pblInstallationId = $this->worldpayhelper->getPayByLinkInstallationId(); + + $merchantUsername = !empty($pblMerchantUn) ? $pblMerchantUn : $merchantUsername ; + $merchantPassword = !empty($pblMerchantPw) ? $pblMerchantPw : $merchantPassword ; + $merchantCode = !empty($pblMerchantCode) ? $pblMerchantCode : $merchantCode ; + $installationId = !empty($pblInstallationId) ? $pblInstallationId : $installationId ; + $inquirySimpleXml = $this->xmlinquiry->build( - $redirectOrderParams['merchantCode'], + $merchantCode, $orderCode ); /* Response Order Inquiry */ $responseInquiry = $this->_sendRequest( dom_import_simplexml($inquirySimpleXml)->ownerDocument, - $this->worldpayhelper->getXmlUsername($redirectOrderParams['paymentType']), - $this->worldpayhelper->getXmlPassword($redirectOrderParams['paymentType']) + $merchantUsername, + $merchantPassword, + \Sapient\Worldpay\Model\Request\PaymentServiceRequest::SEND_ADDITIONAL_HEADER ); $paymentService = new \SimpleXmlElement($responseInquiry); @@ -214,6 +361,11 @@ public function authorizeRegenaretPayment( if (!empty($error) && $error[0] == 'Could not find payment for order') { $this->wplogger->info('Could not find payment for order ########'.$orderCode); + if ($quote->getIsMultiShipping()) { + $multiDesc = $this->worldpayhelper->getMultiShippingOrderDescription(); + $redirectOrderParams['orderDescription'] = $multiDesc; + } + $redirectOrderParams['is_paybylink_order'] = 1; $responseXml = $this->paymentservicerequest->redirectOrder($redirectOrderParams); $successUrl = $this->_buildRedirectUrl( $responseXml, @@ -390,11 +542,12 @@ private function _setredirectpaybylinkhpp($redirectLink) * @param SimpleXmlElement $xml * @param string $username * @param string $password + * @param bool $additionalHeader * @return SimpleXmlElement $response */ - protected function _sendRequest($xml, $username, $password) + protected function _sendRequest($xml, $username, $password, $additionalHeader) { - $response = $this->_request->sendRequest($xml, $username, $password); + $response = $this->_request->sendRequest($xml, $username, $password, $additionalHeader); return $response; } /** diff --git a/Model/Authorisation/PaymentOptionsService.php b/Model/Authorisation/PaymentOptionsService.php index 211dfbc9..ae3647d5 100644 --- a/Model/Authorisation/PaymentOptionsService.php +++ b/Model/Authorisation/PaymentOptionsService.php @@ -8,6 +8,22 @@ class PaymentOptionsService extends \Magento\Framework\DataObject { + /** + * @var \Sapient\Worldpay\Model\Request\PaymentServiceRequest + */ + protected $mappingservice; + /** + * @var \Sapient\Worldpay\Model\Payment\UpdateWorldpaymentFactory + */ + protected $paymentservicerequest; + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $worldpayhelper; /** * Constructor @@ -40,14 +56,18 @@ public function collectPaymentOptions( $countryId, $paymenttype ) { + + $isMultishipping = false; + if ($this->worldpayhelper->isMultiShipping()) { + $isMultishipping = true; + } $paymentOptionParams = $this->mappingservice->collectPaymentOptionsParameters( $countryId, - $paymenttype + $paymenttype, + $isMultishipping ); - - $response = $this->paymentservicerequest->paymentOptionsByCountry($paymentOptionParams); + $response = $this->paymentservicerequest->paymentOptionsByCountry($paymentOptionParams, $isMultishipping); $responsexml = simplexml_load_string($response); - $paymentoptions = $this->getPaymentOptions($responsexml); if ($this->worldpayhelper->isGlobalApmEnable()) { diff --git a/Model/Authorisation/RedirectService.php b/Model/Authorisation/RedirectService.php index 22e4ee1d..42d755ba 100644 --- a/Model/Authorisation/RedirectService.php +++ b/Model/Authorisation/RedirectService.php @@ -9,9 +9,54 @@ class RedirectService extends \Magento\Framework\DataObject { + /** + * @var \Sapient\Worldpay\Model\Request\PaymentServiceRequest + */ + protected $mappingservice; + /** + * @var \Sapient\Worldpay\Model\Payment\UpdateWorldpaymentFactory + */ + protected $paymentservicerequest; + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + /** @var \Sapient\Worldpay\Model\Response\RedirectResponse */ protected $_redirectResponseModel; + /** + * @var \Sapient\Worldpay\Model\Payment\Service + */ + protected $paymentservice; + /** + * @var \Sapient\Worldpay\Model\Response\RedirectResponse + */ + protected $redirectresponse; + /** + * @var \Sapient\Worldpay\Helper\Registry + */ + protected $registryhelper; + /** + * @var \Magento\Checkout\Model\Session + */ + protected $checkoutsession; + + /** + * @var \Sapient\Worldpay\Model\Utilities\PaymentMethods + */ + protected $paymentlist; + + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $worldpayhelper; + + /** + * @var \Sapient\Worldpay\Helper\Multishipping + */ + protected $multishippingHelper; + /** * Constructor * @param \Sapient\Worldpay\Model\Mapping\Service $mappingservice diff --git a/Model/Authorisation/ThreeDSecureChallenge.php b/Model/Authorisation/ThreeDSecureChallenge.php index d0e5a9fd..10ee72c5 100644 --- a/Model/Authorisation/ThreeDSecureChallenge.php +++ b/Model/Authorisation/ThreeDSecureChallenge.php @@ -12,7 +12,60 @@ class ThreeDSecureChallenge extends \Magento\Framework\DataObject protected $updateWorldPayPayment; public const CART_URL = 'checkout/cart'; + /** + * @var \Sapient\Worldpay\Model\Payment\UpdateWorldpaymentFactory + */ + protected $paymentservicerequest; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + + /** + * @var \Sapient\Worldpay\Model\Response\DirectResponse + */ + protected $directResponse; + + /** + * @var \Sapient\Worldpay\Model\Payment\Service + */ + protected $paymentservice; + /** + * @var \Magento\Framework\UrlInterface + */ + protected $urlBuilders; + /** + * @var \Sapient\Worldpay\Model\Order\Service + */ + protected $orderservice; + /** + * @var \Magento\Framework\Message\ManagerInterface + */ + protected $_messageManager; + /** + * @var \Magento\Customer\Model\Session + */ + protected $customerSession; + /** + * @var \Sapient\Worldpay\Model\Token\WorldpayToken + */ + protected $worldpaytoken; + + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $worldpayHelper; + + /** + * @var \Sapient\Worldpay\Helper\Multishipping + */ + protected $multishippingHelper; + /** + * @var \Magento\Checkout\Model\Session + */ + protected $checkoutSession; /** * ThreeDSecureChallenge Constructor * diff --git a/Model/Authorisation/ThreeDSecureService.php b/Model/Authorisation/ThreeDSecureService.php index 4620895a..a79c1f1e 100644 --- a/Model/Authorisation/ThreeDSecureService.php +++ b/Model/Authorisation/ThreeDSecureService.php @@ -12,6 +12,73 @@ class ThreeDSecureService extends \Magento\Framework\DataObject protected $updateWorldPayPayment; public const CART_URL = 'checkout/cart'; + /** + * @var \Sapient\Worldpay\Model\Payment\UpdateWorldpaymentFactory + */ + protected $paymentservicerequest; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + + /** + * @var \Sapient\Worldpay\Model\Response\DirectResponse + */ + protected $directResponse; + + /** + * @var \Sapient\Worldpay\Model\Payment\Service + */ + protected $paymentservice; + + /** + * @var \Magento\Framework\UrlInterface + */ + protected $urlBuilders; + /** + * @var \Sapient\Worldpay\Model\Order\Service + */ + protected $orderservice; + /** + * @var \Magento\Framework\Message\ManagerInterface + */ + protected $_messageManager; + /** + * @var \Magento\Customer\Model\Session + */ + protected $customerSession; + /** + * @var \Sapient\Worldpay\Model\Token\WorldpayToken + */ + protected $worldpaytoken; + + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $worldpayHelper; + + /** + * @var \Sapient\Worldpay\Helper\Multishipping + */ + protected $multishippingHelper; + /** + * @var \Magento\Checkout\Model\Session + */ + protected $checkoutSession; + + /** + * @var object + */ + protected $_paymentUpdate; + /** + * @var object + */ + protected $_order; + /** + * @var object + */ + protected $response; /** * Constructor diff --git a/Model/Authorisation/TokenService.php b/Model/Authorisation/TokenService.php index 8732276c..31988944 100644 --- a/Model/Authorisation/TokenService.php +++ b/Model/Authorisation/TokenService.php @@ -8,15 +8,53 @@ class TokenService extends \Magento\Framework\DataObject { - /** - * @var \Magento\Backend\Model\Auth\Session - */ - protected $_session; + /** + * @var \Sapient\Worldpay\Model\Mapping\Service + */ + protected $mappingservice; /** * @var \Sapient\Worldpay\Model\Payment\UpdateWorldpaymentFactory */ protected $updateWorldPayPayment; + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + + /** + * @var \Sapient\Worldpay\Model\Response\DirectResponse + */ + protected $directResponse; + + /** + * @var \Sapient\Worldpay\Model\Payment\Service + */ + protected $paymentservice; + + /** + * @var \Sapient\Worldpay\Model\Request\PaymentServiceRequest + */ + protected $paymentservicerequest; + /** + * @var \Sapient\Worldpay\Helper\Registry + */ + protected $registryhelper; + + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $worldpayHelper; + + /** + * @var \Sapient\Worldpay\Helper\Multishipping + */ + protected $multishippingHelper; + /** + * @var \Magento\Checkout\Model\Session + */ + protected $checkoutSession; + /** * TokenService constructor * @@ -77,7 +115,7 @@ public function authorizePayment( if ($this->worldpayHelper->isMultiShipping($quote)) { $sessionOrderCode = $this->multishippingHelper->getOrderCodeFromSession(); if (!empty($sessionOrderCode)) { - $this->checkoutSession->setauthenticatedOrderId($mageOrder->getIncrementId()); + $this->checkoutSession->setauthenticatedOrderId($mageOrder->getIncrementId()); $orgWorldpayPayment = $this->multishippingHelper->getOrgWorldpayId($sessionOrderCode); $orgOrderId = $orgWorldpayPayment['order_id']; $isOrg = false; diff --git a/Model/Authorisation/VaultService.php b/Model/Authorisation/VaultService.php index 7e28ad7e..52a850c7 100644 --- a/Model/Authorisation/VaultService.php +++ b/Model/Authorisation/VaultService.php @@ -12,6 +12,49 @@ class VaultService extends \Magento\Framework\DataObject * @var \Magento\Checkout\Model\Session */ protected $checkoutSession; + + /** + * @var \Sapient\Worldpay\Model\Mapping\Service + */ + protected $mappingservice; + /** + * @var \Sapient\Worldpay\Model\Payment\UpdateWorldpaymentFactory + */ + protected $updateWorldPayPayment; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + + /** + * @var \Sapient\Worldpay\Model\Response\DirectResponse + */ + protected $directResponse; + + /** + * @var \Sapient\Worldpay\Model\Payment\Service + */ + protected $paymentservice; + + /** + * @var \Sapient\Worldpay\Model\Request\PaymentServiceRequest + */ + protected $paymentservicerequest; + /** + * @var \Sapient\Worldpay\Helper\Registry + */ + protected $registryhelper; + + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $worldpayHelper; + + /** + * @var \Sapient\Worldpay\Helper\Multishipping + */ + protected $multishippingHelper; /** * VaultService constructor * diff --git a/Model/Authorisation/WalletService.php b/Model/Authorisation/WalletService.php index 9ca3f167..870653ff 100644 --- a/Model/Authorisation/WalletService.php +++ b/Model/Authorisation/WalletService.php @@ -18,6 +18,49 @@ class WalletService extends \Magento\Framework\DataObject */ protected $updateWorldPayPayment; + /** + * @var \Sapient\Worldpay\Model\Mapping\Service + */ + protected $mappingservice; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + + /** + * @var \Sapient\Worldpay\Model\Response\DirectResponse + */ + protected $directResponse; + /** + * @var \Sapient\Worldpay\Model\Payment\Service + */ + protected $paymentservice; + + /** + * @var \Sapient\Worldpay\Model\Request\PaymentServiceRequest + */ + protected $paymentservicerequest; + /** + * @var \Sapient\Worldpay\Helper\Registry + */ + protected $registryhelper; + + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $worldpayHelper; + + /** + * @var \Sapient\Worldpay\Helper\Multishipping + */ + protected $multishippingHelper; + + /** + * @var \Magento\Framework\UrlInterface + */ + protected $urlBuilders; + /** * WalletService constructor * diff --git a/Model/Checkout/Hpp/Json/Config/Factory.php b/Model/Checkout/Hpp/Json/Config/Factory.php index b0559fd8..959264f4 100644 --- a/Model/Checkout/Hpp/Json/Config/Factory.php +++ b/Model/Checkout/Hpp/Json/Config/Factory.php @@ -17,6 +17,43 @@ class Factory { /** @var \Magento\Store\Model\Store*/ private $store; + /** + * @var \Magento\Framework\App\Config\ScopeConfigInterface + */ + private $scopeConfig; + + /** + * @var Repository + */ + private $assetRepo; + /** + * @var RequestInterface + */ + private $request; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + private $wplogger; + + /** + * @var \Sapient\Worldpay\Helper\Data + */ + private $worldpayhelper; + /** + * @var \Magento\Quote\Api\CartRepositoryInterface + */ + private $quoteRepository; + + /** + * @var \Magento\Sales\Model\Order + */ + private $mageorder; + + /** + * @var object + */ + private $state; /** * Factory constructor diff --git a/Model/Checkout/Hpp/State.php b/Model/Checkout/Hpp/State.php index dc8b25ef..75f62ba9 100644 --- a/Model/Checkout/Hpp/State.php +++ b/Model/Checkout/Hpp/State.php @@ -11,6 +11,11 @@ class State public const SESSION_KEY_STATE = 'worldpay_hpp_state'; public const SESSION_KEY_URL = 'worldpay_hpp_redirect_url'; + /** + * @var \Magento\Checkout\Model\Session + */ + public $session; + /** * State constructor * diff --git a/Model/Checkout/Service.php b/Model/Checkout/Service.php index 4569e7b6..49f90ee1 100644 --- a/Model/Checkout/Service.php +++ b/Model/Checkout/Service.php @@ -8,6 +8,20 @@ class Service { + /** + * @var \Magento\Checkout\Model\Session + */ + private $checkoutsession; + + /** + * @var CustomerCart + */ + private $cart; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + private $wplogger; /** * Constructor * diff --git a/Model/Checkout/Type/Multishipping.php b/Model/Checkout/Type/Multishipping.php index 8de46c88..78d51c12 100644 --- a/Model/Checkout/Type/Multishipping.php +++ b/Model/Checkout/Type/Multishipping.php @@ -9,6 +9,12 @@ use Magento\Framework\Exception\NotFoundException; use Magento\Sales\Api\Data\OrderInterface; use Magento\Framework\Pricing\PriceCurrencyInterface; +use Magento\Customer\Api\AddressRepositoryInterface; +use Magento\Sales\Model\Order\Email\Sender\OrderSender; +use Magento\Framework\Exception\LocalizedException; +use Magento\Directory\Model\AllowedCountries; +use Psr\Log\LoggerInterface; +use Magento\Framework\App\ObjectManager; class Multishipping extends \Magento\Multishipping\Model\Checkout\Type\Multishipping { @@ -56,28 +62,103 @@ class Multishipping extends \Magento\Multishipping\Model\Checkout\Type\Multiship * @var \Magento\Quote\Model\Quote\Item\ToOrderItem */ protected $quoteItemToOrderItem; + /** - * Constructor + * @param \Magento\Checkout\Model\Session $checkoutSession + * @param \Magento\Customer\Model\Session $customerSession + * @param \Magento\Sales\Model\OrderFactory $orderFactory + * @param AddressRepositoryInterface $addressRepository + * @param \Magento\Framework\Event\ManagerInterface $eventManager + * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig + * @param \Magento\Framework\Session\Generic $session + * @param \Magento\Quote\Model\Quote\AddressFactory $addressFactory + * @param \Magento\Quote\Model\Quote\Address\ToOrder $quoteAddressToOrder + * @param \Magento\Quote\Model\Quote\Address\ToOrderAddress $quoteAddressToOrderAddress + * @param \Magento\Quote\Model\Quote\Payment\ToOrderPayment $quotePaymentToOrderPayment + * @param \Magento\Quote\Model\Quote\Item\ToOrderItem $quoteItemToOrderItem + * @param \Magento\Store\Model\StoreManagerInterface $storeManager + * @param \Magento\Payment\Model\Method\SpecificationInterface $paymentSpecification + * @param \Magento\Multishipping\Helper\Data $helper + * @param OrderSender $orderSender + * @param PriceCurrencyInterface $priceCurrency + * @param \Magento\Quote\Api\CartRepositoryInterface $quoteRepository + * @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder + * @param \Magento\Framework\Api\FilterBuilder $filterBuilder + * @param \Magento\Quote\Model\Quote\TotalsCollector $totalsCollector + * @param array $data + * @param \Magento\Quote\Api\Data\CartExtensionFactory|null $cartExtensionFactory + * @param AllowedCountries|null $allowedCountryReader + * @param \Magento\Multishipping\Model\Checkout\Type\Multishipping\PlaceOrderFactory $placeOrderFactory + * @param LoggerInterface|null $logger + * @param \Magento\Framework\Api\DataObjectHelper|null $dataObjectHelper + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ - protected function _construct() - { - $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); - $placOrder = \Magento\Multishipping\Model\Checkout\Type\Multishipping\PlaceOrderFactory::class; - $this->placeOrderFactory = $objectManager->get($placOrder); - $this->logger = $objectManager->get(\Psr\Log\LoggerInterface::class); - $this->session = $objectManager->get(\Magento\Framework\Session\Generic::class); - $this->checkoutSession = $objectManager->get(\Magento\Checkout\Model\Session::class); - $this->eventManager = $objectManager->get(\Magento\Framework\Event\ManagerInterface::class); - $this->_orderFactory = $objectManager->get(\Magento\Sales\Model\OrderFactory::class); - $this->dataObjectHelper = $objectManager->get(\Magento\Framework\Api\DataObjectHelper::class); - $this->quoteAddressToOrder = $objectManager->get(\Magento\Quote\Model\Quote\Address\ToOrder::class); - $toOrderAddress = \Magento\Quote\Model\Quote\Address\ToOrderAddress::class; - $this->quoteAddressToOrderAddress = $objectManager->get($toOrderAddress); - $toOrderPayment = \Magento\Quote\Model\Quote\Payment\ToOrderPayment::class; - $this->quotePaymentToOrderPayment = $objectManager->get($toOrderPayment); - $this->priceCurrency = $objectManager->get(PriceCurrencyInterface::class); - $this->quoteItemToOrderItem = $objectManager->get(\Magento\Quote\Model\Quote\Item\ToOrderItem::class); - $this->quoteRepository = $objectManager->get(\Magento\Quote\Api\CartRepositoryInterface::class); + public function __construct( + \Magento\Checkout\Model\Session $checkoutSession, + \Magento\Customer\Model\Session $customerSession, + \Magento\Sales\Model\OrderFactory $orderFactory, + AddressRepositoryInterface $addressRepository, + \Magento\Framework\Event\ManagerInterface $eventManager, + \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, + \Magento\Framework\Session\Generic $session, + \Magento\Quote\Model\Quote\AddressFactory $addressFactory, + \Magento\Quote\Model\Quote\Address\ToOrder $quoteAddressToOrder, + \Magento\Quote\Model\Quote\Address\ToOrderAddress $quoteAddressToOrderAddress, + \Magento\Quote\Model\Quote\Payment\ToOrderPayment $quotePaymentToOrderPayment, + \Magento\Quote\Model\Quote\Item\ToOrderItem $quoteItemToOrderItem, + \Magento\Store\Model\StoreManagerInterface $storeManager, + \Magento\Payment\Model\Method\SpecificationInterface $paymentSpecification, + \Magento\Multishipping\Helper\Data $helper, + OrderSender $orderSender, + PriceCurrencyInterface $priceCurrency, + \Magento\Quote\Api\CartRepositoryInterface $quoteRepository, + \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder, + \Magento\Framework\Api\FilterBuilder $filterBuilder, + \Magento\Quote\Model\Quote\TotalsCollector $totalsCollector, + array $data = [], + \Magento\Quote\Api\Data\CartExtensionFactory $cartExtensionFactory = null, + AllowedCountries $allowedCountryReader = null, + \Magento\Multishipping\Model\Checkout\Type\Multishipping\PlaceOrderFactory $placeOrderFactory = null, + LoggerInterface $logger = null, + \Magento\Framework\Api\DataObjectHelper $dataObjectHelper = null + ) { + $this->dataObjectHelper = $dataObjectHelper ?: ObjectManager::getInstance() + ->get(\Magento\Framework\Api\DataObjectHelper::class); + $this->placeOrderFactory = $placeOrderFactory ?: ObjectManager::getInstance() + ->get(\Magento\Multishipping\Model\Checkout\Type\Multishipping\PlaceOrderFactory::class); + $this->cartExtensionFactory = $cartExtensionFactory ?: + ObjectManager::getInstance() + ->get(\Magento\Quote\Api\Data\CartExtensionFactory::class); + $this->allowedCountryReader = $allowedCountryReader ?: + ObjectManager::getInstance() + ->get(AllowedCountries::class); + $this->logger = $logger ?: ObjectManager::getInstance() + ->get(LoggerInterface::class); + + parent::__construct( + $checkoutSession, + $customerSession, + $orderFactory, + $addressRepository, + $eventManager, + $scopeConfig, + $session, + $addressFactory, + $quoteAddressToOrder, + $quoteAddressToOrderAddress, + $quotePaymentToOrderPayment, + $quoteItemToOrderItem, + $storeManager, + $paymentSpecification, + $helper, + $orderSender, + $priceCurrency, + $quoteRepository, + $searchCriteriaBuilder, + $filterBuilder, + $totalsCollector, + $data + ); } /** @@ -85,8 +166,6 @@ protected function _construct() */ public function createOrders() { - $this->_construct(); - $quote = $this->getQuote(); $orders = []; @@ -106,12 +185,12 @@ public function createOrders() $order = $this->_prepareOrder($address); $orders[] = $order; - $this->eventManager->dispatch( + $this->_eventManager->dispatch( 'checkout_type_multishipping_create_orders_single', ['order' => $order, 'address' => $address, 'quote' => $quote] ); } - + $this->logger->info("=============CREATING THIS ORDER======="); $paymentProviderCode = $quote->getPayment()->getMethod(); $placeOrderService = $this->placeOrderFactory->create($paymentProviderCode); $exceptionList = $placeOrderService->place($orders); @@ -133,7 +212,7 @@ public function createOrders() } $placedAddressItems = []; - $orderIds = []; + $orderIds = []; foreach ($successfulOrders as $order) { $orderIds[$order->getId()] = $order->getIncrementId(); $placedAddressItems = $this->getPlacedAddressItems($order); @@ -177,9 +256,9 @@ protected function _prepareOrder(\Magento\Quote\Model\Quote\Address $address) { $quote = $this->getQuote(); $quote->unsReservedOrderId(); - if (!empty($this->checkoutSession->getHppReservedOrderId())) { - $quote->setReservedOrderId($this->checkoutSession->getHppReservedOrderId()); - $this->checkoutSession->unsHppReservedOrderId(); + if (!empty($this->_checkoutSession->getHppReservedOrderId())) { + $quote->setReservedOrderId($this->_checkoutSession->getHppReservedOrderId()); + $this->_checkoutSession->unsHppReservedOrderId(); } else { $quote->reserveOrderId(); } @@ -262,12 +341,12 @@ public function setResultsPageData($quote, $successfulOrders, $failedOrders, $ex $successfulOrderIds[$order->getId()] = $order->getIncrementId(); } - $this->session->setOrderIds($successfulOrderIds); + $this->_session->setOrderIds($successfulOrderIds); $addressErrors = []; if (!empty($failedOrders)) { $addressErrors = $this->getQuoteAddressErrors($failedOrders, $shippingAddresses, $exceptionList); - $this->session->setAddressErrors($addressErrors); + $this->_session->setAddressErrors($addressErrors); } } /** @@ -303,9 +382,7 @@ public function getAddressErrors($quote, $successfulOrders, $failedOrders, $exce */ public function deactivateQuote($quote) { - $this->_construct(); - - $this->checkoutSession->setLastQuoteId($quote->getId()); + $this->_checkoutSession->setLastQuoteId($quote->getId()); $quote->setIsActive(false); $this->quoteRepository->save($quote); } diff --git a/Model/Config/Source/CaptureDelay.php b/Model/Config/Source/CaptureDelay.php new file mode 100644 index 00000000..9e98305f --- /dev/null +++ b/Model/Config/Source/CaptureDelay.php @@ -0,0 +1,25 @@ + '0', 'label' => __('0')], + ['value' => self::CUSTOM_CAPTURE_DELAY_KEY, 'label' => __('1-14')], + ['value' => 'off', 'label' => __('OFF')], + ['value' => 'default', 'label' => __('DEFAULT')] + ]; + } +} diff --git a/Model/Config/Source/KlarnaCountries.php b/Model/Config/Source/KlarnaCountries.php index 5c1910d2..b0d29368 100644 --- a/Model/Config/Source/KlarnaCountries.php +++ b/Model/Config/Source/KlarnaCountries.php @@ -9,11 +9,11 @@ class KlarnaCountries implements \Magento\Framework\Option\ArrayInterface { /** - * @var _countryCollectionFactory + * @var \Magento\Directory\Model\ResourceModel\Country\CollectionFactory */ protected $_countryCollectionFactory; /** - * @var _scopeConfig + * @var \Magento\Framework\App\Config\ScopeConfigInterface */ protected $_scopeConfig; diff --git a/Model/Config/Source/PaymentMethodsApm.php b/Model/Config/Source/PaymentMethodsApm.php index 453d2548..6c8a6c0e 100644 --- a/Model/Config/Source/PaymentMethodsApm.php +++ b/Model/Config/Source/PaymentMethodsApm.php @@ -16,7 +16,6 @@ public function toOptionArray() return [ ['value' => 'CHINAUNIONPAY-SSL', 'label' => __('Union Pay')], ['value' => 'IDEAL-SSL', 'label' => __('IDEAL')], - ['value' => 'QIWI-SSL', 'label' => __('Qiwi')], //['value' => 'YANDEXMONEY-SSL', 'label' => __('Yandex.Money')], ['value' => 'PAYPAL-EXPRESS', 'label' => __('PayPal')], ['value' => 'SOFORT-SSL', 'label' => __('SoFort EU')], diff --git a/Model/Config/Source/SEPAMandateTypes.php b/Model/Config/Source/SEPAMandateTypes.php new file mode 100644 index 00000000..ee8cb15d --- /dev/null +++ b/Model/Config/Source/SEPAMandateTypes.php @@ -0,0 +1,20 @@ + 'ONE-OFF', 'label' => __('ONE-OFF')] + ]; + } +} diff --git a/Model/Config/Source/Website.php b/Model/Config/Source/Website.php index f9c249c7..37524ad5 100644 --- a/Model/Config/Source/Website.php +++ b/Model/Config/Source/Website.php @@ -16,7 +16,7 @@ class Website implements \Magento\Framework\Option\ArrayInterface private $storeManager; /** - * @var directoryHelper + * @var Data */ private $directoryHelper; diff --git a/Model/InstantPurchase/CreditCard/AvailabilityChecker.php b/Model/InstantPurchase/CreditCard/AvailabilityChecker.php index c8547ce9..2ca7f1bc 100644 --- a/Model/InstantPurchase/CreditCard/AvailabilityChecker.php +++ b/Model/InstantPurchase/CreditCard/AvailabilityChecker.php @@ -4,19 +4,19 @@ class AvailabilityChecker implements \Magento\InstantPurchase\PaymentMethodIntegration\AvailabilityCheckerInterface { /** - * @var Config + * @var \Sapient\Worldpay\Helper\Data */ private $config; /** - * @var wplogger + * @var \Sapient\Worldpay\Logger\WorldpayLogger */ private $wplogger; /** * Constructor * - * @param Sapient\Worldpay\Helper\Data $worldpayHelper - * @param Sapient\Worldpay\Logger\WorldpayLogger $wplogger + * @param \Sapient\Worldpay\Helper\Data $worldpayHelper + * @param \Sapient\Worldpay\Logger\WorldpayLogger $wplogger */ public function __construct( \Sapient\Worldpay\Helper\Data $worldpayHelper, diff --git a/Model/InstantPurchase/CreditCard/TokenFormatter.php b/Model/InstantPurchase/CreditCard/TokenFormatter.php index 0069c565..9e0817eb 100644 --- a/Model/InstantPurchase/CreditCard/TokenFormatter.php +++ b/Model/InstantPurchase/CreditCard/TokenFormatter.php @@ -15,6 +15,25 @@ class TokenFormatter implements PaymentTokenFormatterInterface * @var \Sapient\Worldpay\Model\WorldpaymentFactory */ protected $_worldpaymentFactory; + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + + /** + * @var \Sapient\Worldpay\Model\SavedTokenFactory + */ + protected $savecard; + + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $wpdata; + + /** + * @var \Sapient\Worldpay\Model\ResourceModel\SavedToken + */ + protected $savedtoken; /** * @var baseCardTypes */ diff --git a/Model/InstantPurchase/PaymentAdditionalInformationProvider.php b/Model/InstantPurchase/PaymentAdditionalInformationProvider.php index 6aa8b61e..9e2f2ceb 100644 --- a/Model/InstantPurchase/PaymentAdditionalInformationProvider.php +++ b/Model/InstantPurchase/PaymentAdditionalInformationProvider.php @@ -10,6 +10,18 @@ */ class PaymentAdditionalInformationProvider implements PaymentAdditionalInformationProviderInterface { + /** + * @var WorldpayLogger + */ + protected $logger; + /** + * @var \Magento\Framework\Session\SessionManagerInterface + */ + protected $session; + /** + * @var \Magento\Checkout\Model\Session + */ + protected $checkoutSession; /** * Constructor * diff --git a/Model/Mapping/Service.php b/Model/Mapping/Service.php index bdaa815b..b195d072 100644 --- a/Model/Mapping/Service.php +++ b/Model/Mapping/Service.php @@ -8,9 +8,9 @@ class Service { /** - * @var _logger + * @var \Sapient\Worldpay\Logger\WorldpayLogger */ - protected $_logger; + protected $wplogger; /** * @var savedTokenFactory */ @@ -19,10 +19,6 @@ class Service * @var _scopeConfig */ protected $_scopeConfig; - /** - * @var session - */ - protected $session; /** * @var THIS_TRANSACTION */ @@ -59,6 +55,36 @@ class Service * @var NO_CHANGE */ public const NO_CHANGE = 'noChange'; + + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $worldpayHelper; + + /** + * @var \Sapient\Worldpay\Model\SavedToken + */ + protected $savedtoken; + + /** + * @var \Magento\Framework\UrlInterface + */ + protected $_urlBuilder; + + /** + * @var \Magento\Framework\Session\SessionManagerInterface + */ + protected $session; + + /** + * @var \Magento\Customer\Model\Session + */ + protected $customerSession; + + /** + * @var \Sapient\Worldpay\Helper\Recurring + */ + protected $recurringHelper; /** * Constructor * @@ -123,6 +149,10 @@ public function collectVaultOrderParameters( $orderLineItems = $this->_getL23OrderLineItems($quote, $vaultPaymentDetails['brand'].'-SSL'); $vaultPaymentDetails['salesTax'] = $quote->getShippingAddress()->getData('tax_amount'); } + $isMultiShippingOrder = 0; + if ((bool)$quote->getIsMultiShipping()) { + $isMultiShippingOrder = 1; + } return [ 'orderCode' => $orderCode, @@ -151,7 +181,8 @@ public function collectVaultOrderParameters( 'shopperId' => $quote->getCustomerId(), 'exponent' => $exponent, 'primeRoutingData' => $this->getPrimeRoutingDetails($paymentDetails, $quote), - 'orderLineItems' => $orderLineItems + 'orderLineItems' => $orderLineItems, + 'isMultishippingOrder' => $isMultiShippingOrder ]; } /** @@ -202,7 +233,11 @@ public function collectDirectOrderParameters( } $currencyCode = $quote->getQuoteCurrencyCode(); $exponent = $this->worldpayHelper->getCurrencyExponent($currencyCode); - + $isMultiShippingOrder = 0; + if ((bool)$quote->getIsMultiShipping()) { + $isMultiShippingOrder = 1; + } + return [ 'orderCode' => $orderCode, 'merchantCode' => $this->worldpayHelper->getMerchantCode($paymentDetails['additional_data']['cc_type']), @@ -235,7 +270,8 @@ public function collectDirectOrderParameters( 'shippingfee' => $shippingFee, 'exponent' => $exponent, 'primeRoutingData' => $this->getPrimeRoutingDetails($paymentDetails, $quote), - 'orderLineItems' => $orderLineItems + 'orderLineItems' => $orderLineItems, + 'isMultishippingOrder' => $isMultiShippingOrder ]; } /** @@ -358,6 +394,10 @@ public function collectRedirectOrderParameters( $orderLineItems = $this->_getL23OrderLineItems($quote, $paymentType); $updatedPaymentDetails['salesTax'] = $quote->getShippingAddress()->getData('tax_amount'); } + + if (!empty($paymentDetails['is_paybylink_order'])) { + $orderLineItems = $this->_getOrderLineItems($quote, 'null'); + } if ($paymentDetails['additional_data']['cc_type'] !== 'savedcard') { $updatedPaymentDetails['cardType'] = $paymentType; @@ -380,6 +420,10 @@ public function collectRedirectOrderParameters( } $currencyCode = $quote->getQuoteCurrencyCode(); $exponent = $this->worldpayHelper->getCurrencyExponent($currencyCode); + $isMultiShippingOrder = 0; + if ((bool)$quote->getIsMultiShipping()) { + $isMultiShippingOrder = 1; + } return [ 'orderCode' => $orderCode, 'merchantCode' => $this->worldpayHelper-> @@ -416,6 +460,7 @@ public function collectRedirectOrderParameters( 'orderLineItems' => $orderLineItems, 'saveCardEnabled' => $savemyCard, 'storedCredentialsEnabled' => $storedCredentialsEnabled, + 'isMultishippingOrder' => $isMultiShippingOrder ]; } @@ -446,6 +491,10 @@ public function collectKlarnaOrderParameters( $currencyCode = $quote->getQuoteCurrencyCode(); $exponent = $this->worldpayHelper->getCurrencyExponent($currencyCode); $countryCode = $quote->getBillingAddress()->getCountryId(); + $isMultiShippingOrder = 0; + if ((bool)$quote->getIsMultiShipping()) { + $isMultiShippingOrder = 1; + } return [ 'orderCode' => $orderCode, 'merchantCode' => $this->worldpayHelper->getMerchantCode($paymentDetails['additional_data']['cc_type']), @@ -475,7 +524,8 @@ public function collectKlarnaOrderParameters( 'shopperId' => $quote->getCustomerId(), 'exponent' => $exponent, 'sessionData' => $this->_getSessionDetails($paymentDetails, $countryCode), - 'orderContent' => $orderContent + 'orderContent' => $orderContent, + 'isMultishippingOrder' => $isMultiShippingOrder ]; } /** @@ -527,7 +577,16 @@ public function collectTokenOrderParameters( $orderLineItems = $this->_getL23OrderLineItems($quote, $paymentType); $updatedPaymentDetails['salesTax'] = $quote->getShippingAddress()->getData('tax_amount'); } - + $merchantCode = $this->worldpayHelper->getMerchantCode($paymentType); + if (isset($updatedPaymentDetails['isRecurringOrder'])) { + if ($updatedPaymentDetails['isRecurringOrder'] == 1) { + $merchantCode = $this->worldpayHelper->getRecurringMerchantCode($paymentType); + } + } + $isMultiShippingOrder = 0; + if ((bool)$quote->getIsMultiShipping()) { + $isMultiShippingOrder = 1; + } return [ 'orderCode' => $orderCode, 'merchantCode' => $this->worldpayHelper->getMerchantCode($paymentType), @@ -561,7 +620,8 @@ public function collectTokenOrderParameters( 'shippingfee' => $shippingFee, 'exponent' => $exponent, 'primeRoutingData' => $this->getPrimeRoutingDetails($paymentDetails, $quote), - 'orderLineItems' => $orderLineItems + 'orderLineItems' => $orderLineItems, + 'isMultishippingOrder' => $isMultiShippingOrder ]; } /** @@ -596,6 +656,10 @@ public function collectACHOrderParameters( $currencyCode = $quote->getQuoteCurrencyCode(); $exponent = $this->worldpayHelper->getCurrencyExponent($currencyCode); + $isMultiShippingOrder = 0; + if ((bool)$quote->getIsMultiShipping()) { + $isMultiShippingOrder = 1; + } return [ 'orderCode' => $orderCode, 'merchantCode' => $this->worldpayHelper->getMerchantCode($paymentDetails['additional_data']['cc_type']), @@ -617,7 +681,63 @@ public function collectACHOrderParameters( 'orderStoreId' => $orderStoreId, 'shopperId' => $quote->getCustomerId(), 'statementNarrative' => $stmtNarrative, - 'exponent' => $exponent + 'exponent' => $exponent, + 'isMultishippingOrder' => $isMultiShippingOrder + ]; + } + /** + * Collect SEPA Order Parameters + * + * @param string $orderCode + * @param int $quote + * @param string $orderStoreId + * @param array $paymentDetails + * @return array + */ + public function collectSEPAOrderParameters( + $orderCode, + $quote, + $orderStoreId, + $paymentDetails + ) { + $reservedOrderId = $quote->getReservedOrderId(); + $stmtNarrative = ''; + $apmPaymentTypes = $this->worldpayHelper->getApmTypes('worldpay_apm'); + if (array_key_exists($paymentDetails['additional_data']['cc_type'], $apmPaymentTypes) + && (isset($paymentDetails['additional_data']['statementNarrative']))) { + $stmtNarrative = $paymentDetails['additional_data']['statementNarrative']; + $stmtNarrative = strlen($stmtNarrative)>15?substr($stmtNarrative, 0, 15):$stmtNarrative; + } + $currencyCode = $quote->getQuoteCurrencyCode(); + $exponent = $this->worldpayHelper->getCurrencyExponent($currencyCode); + + $isMultiShippingOrder = 0; + if ((bool)$quote->getIsMultiShipping()) { + $isMultiShippingOrder = 1; + } + return [ + 'orderCode' => $orderCode, + 'merchantCode' => $this->worldpayHelper->getMerchantCode($paymentDetails['additional_data']['cc_type']), + 'orderDescription' => $this->_getOrderDescription($reservedOrderId), + 'currencyCode' => $quote->getQuoteCurrencyCode(), + 'amount' => $quote->getGrandTotal(), + 'paymentDetails' => $this->_getPaymentDetails($paymentDetails), + 'shopperEmail' => $quote->getCustomerEmail(), + 'acceptHeader' => php_sapi_name() !== "cli" ? filter_input(INPUT_SERVER, 'HTTP_ACCEPT') : '', + 'userAgentHeader' => php_sapi_name() !== "cli" ? filter_input( + INPUT_SERVER, + 'HTTP_USER_AGENT', + FILTER_SANITIZE_FULL_SPECIAL_CHARS, + FILTER_FLAG_STRIP_LOW + ) : '', + 'shippingAddress' => $this->_getShippingAddress($quote), + 'billingAddress' => $this->_getSepaBillingAddress($quote), + 'method' => $paymentDetails['method'], + 'orderStoreId' => $orderStoreId, + 'shopperId' => $quote->getCustomerId(), + 'statementNarrative' => $stmtNarrative, + 'exponent' => $exponent, + 'isMultishippingOrder' => $isMultiShippingOrder ]; } /** @@ -625,14 +745,21 @@ public function collectACHOrderParameters( * * @param Int $countryId * @param string $paymenttype + * @param boolean $ismultishipping * @return array */ public function collectPaymentOptionsParameters( $countryId, - $paymenttype + $paymenttype, + $ismultishipping = false ) { + $merchantCode = $this->worldpayHelper->getMerchantCode($paymenttype); + if ($ismultishipping) { + $msMC = $this->worldpayHelper->getMultishippingMerchantCode(); + $merchantCode = !empty($msMC) ? $msMC : $merchantCode; + } return [ - 'merchantCode' => $this->worldpayHelper->getMerchantCode($paymenttype), + 'merchantCode' => $merchantCode, 'countryCode' => $countryId, 'paymentType' => $paymenttype ]; @@ -722,6 +849,16 @@ private function _getKlarnaBillingAddress($quote) { return $this->_getKlarnaAddress($quote->getBillingAddress()); } + /** + * Collect Sepa Billing Address - This function is used for SEPA alone + * + * @param int $quote + * @return array + */ + private function _getSepaBillingAddress($quote) + { + return $this->_getSepaAddress($quote->getBillingAddress()); + } /** * Collect Order Line Items * @@ -792,8 +929,15 @@ private function _getOrderLineItems($quote, $paymentType = null) $lineitem['unitPrice'] = $shippingPrice + $msTax; $lineitem['totalAmount'] = $shippingPrice + $msTax; $lineitem['totalTaxAmount'] = $msTax; - $lineitem['taxRate'] = (int) (($msTax * 100) / $shippingPrice); - ; + + $lineItemTaxRate = 0; + if ($msTax > 0) { + if ($shippingPrice > 0) { + $lineItemTaxRate = (int) (($msTax * 100) / $shippingPrice); + } + } + + $lineitem['taxRate'] = $lineItemTaxRate; $orderitems['lineItem'][] = $lineitem; } else { $address = $quote->getShippingAddress(); @@ -871,6 +1015,25 @@ private function _getAddress($address) 'countryCode' => $address->getCountryId(), ]; } + /** + * Collect Address - This function is used for SEPA alone + * + * @param array $address + * @return array + */ + private function _getSepaAddress($address) + { + return [ + 'firstName' => $address->getFirstname(), + 'lastName' => $address->getLastname(), + 'street' => $address->getData('street'), + 'postalCode' => $address->getPostcode(), + 'city' => $address->getCity(), + 'state' => $address->getData('region'), + 'countryCode' => $address->getCountryId(), + 'telephone' => $address->getData('telephone'), + ]; + } /** * Collect Klarna Address * @@ -931,6 +1094,18 @@ private function _getPaymentDetails($paymentDetails) $details['shopperIpAddress'] = $this->_getClientIPAddress(); return $details; } + + if ($paymentDetails['additional_data']['cc_type'] == "SEPA_DIRECT_DEBIT-SSL") { + + $details = [ + 'paymentType' => $paymentDetails['additional_data']['cc_type'], + 'sepaMandateType' => $paymentDetails['additional_data']['sepa_mandateType'], + 'sepaIban' => $paymentDetails['additional_data']['sepa_iban'], + 'sepaAccountHolderName' => $paymentDetails['additional_data']['sepa_accountHolderName'] + ]; + $details['sepaMerchantNumber'] = $this->worldpayHelper->getSEPAMerchantNo(); + return $details; + } if ($paymentDetails['additional_data']['cse_enabled']) { $details = [ @@ -1119,7 +1294,10 @@ public function collectWalletOrderParameters( $reservedOrderId = $quote->getReservedOrderId(); $currencyCode = $quote->getQuoteCurrencyCode(); $exponent = $this->worldpayHelper->getCurrencyExponent($currencyCode); - + $isMultiShippingOrder = 0; + if ((bool)$quote->getIsMultiShipping()) { + $isMultiShippingOrder = 1; + } //Google Pay if ($paymentDetails['additional_data']['cc_type'] == 'PAYWITHGOOGLE-SSL') { if ($paymentDetails['additional_data']['walletResponse']) { @@ -1175,7 +1353,8 @@ public function collectWalletOrderParameters( 'paymentDetails' => $paymentDetails, 'threeDSecureConfig' => $this->_getThreeDSecureConfig($paymentDetails['method']), 'shopperIpAddress' => $this->_getClientIPAddress(), - 'exponent' => $exponent + 'exponent' => $exponent, + 'isMultishippingOrder' => $isMultiShippingOrder ]; } } @@ -1214,7 +1393,8 @@ public function collectWalletOrderParameters( 'ephemeralPublicKey' => $ephemeralPublicKey, 'publicKeyHash' => $publicKeyHash, 'transactionId' => $transactionId, - 'exponent' => $exponent + 'exponent' => $exponent, + 'isMultishippingOrder' => $isMultiShippingOrder ]; } } diff --git a/Model/Multishipping/Multishipping.php b/Model/Multishipping/Multishipping.php index 7a357343..d3a3732a 100644 --- a/Model/Multishipping/Multishipping.php +++ b/Model/Multishipping/Multishipping.php @@ -16,20 +16,46 @@ class Multishipping extends \Magento\Framework\Model\AbstractModel * @var \Magento\Framework\Json\Helper\Data */ protected $jsonHelper; + + /** + * @var \Sapient\Worldpay\Helper\Multishipping + */ + protected $multishippingHelper; + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $helper; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + + /** + * @var \Magento\Checkout\Model\Session + */ + protected $checkoutSession; + /** * Service constructor. * * @param \Sapient\Worldpay\Helper\Multishipping $multishippingHelper * @param \Sapient\Worldpay\Helper\Data $helper + * @param \Sapient\Worldpay\Logger\WorldpayLogger $wplogger + * @param \Magento\Checkout\Model\Session $checkoutSession * @param \Magento\Framework\Json\Helper\Data $jsonHelper */ public function __construct( \Sapient\Worldpay\Helper\Multishipping $multishippingHelper, \Sapient\Worldpay\Helper\Data $helper, + \Sapient\Worldpay\Logger\WorldpayLogger $wplogger, + \Magento\Checkout\Model\Session $checkoutSession, \Magento\Framework\Json\Helper\Data $jsonHelper ) { $this->multishippingHelper = $multishippingHelper; $this->helper = $helper; + $this->wplogger = $wplogger; + $this->checkoutSession = $checkoutSession; $this->jsonHelper = $jsonHelper; } /** @@ -52,6 +78,12 @@ public function placeMultishippingOrder( $quoteId = $quote->getId(); $quote->getPayment()->importData($paymentMethod->getData()); $cc_type = $paymentMethod['additional_data']['cc_type']; + if ($paymentMethod['method'] == "worldpay_paybylink" && + $paymentMethod['additional_data']['cc_type'] == "ALL") { + $this->checkoutSession->setAuthenticationOrderId( + $this->checkoutSession->getData('authentication_order_id') + ); + } $response = $this->multishippingHelper->placeMultishippingOrder($quoteId, $cc_type); return $this->jsonHelper->jsonEncode($response); } catch (\Exception $e) { diff --git a/Model/Notification/History.php b/Model/Notification/History.php index c856d3ff..0793366f 100644 --- a/Model/Notification/History.php +++ b/Model/Notification/History.php @@ -8,7 +8,10 @@ class History implements HistoryInterface { - + /** + * @var \Sapient\Worldpay\Model\HistoryNotification + */ + protected $historyNotification; /** * Constructor * diff --git a/Model/Observer/AddExtraDataToTransport.php b/Model/Observer/AddExtraDataToTransport.php index c8cc7c30..992341a6 100644 --- a/Model/Observer/AddExtraDataToTransport.php +++ b/Model/Observer/AddExtraDataToTransport.php @@ -9,11 +9,11 @@ class AddExtraDataToTransport implements ObserverInterface { /** - * @var worldpaypayment + * @var \Sapient\Worldpay\Model\WorldpaymentFactory */ protected $worldpaypayment; /** - * @var wpHelper + * @var \Sapient\Worldpay\Helper\Data */ protected $wpHelper; /** diff --git a/Model/Observer/Cart.php b/Model/Observer/Cart.php index d9f0b506..475acb70 100644 --- a/Model/Observer/Cart.php +++ b/Model/Observer/Cart.php @@ -9,6 +9,25 @@ class Cart implements ObserverInterface { + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + private $wplogger; + /** + * @var \Sapient\Worldpay\Model\Order\Service + */ + private $orderservice; + + /** + * @var \Sapient\Worldpay\Model\Checkout\Service + */ + private $checkoutservice; + + /** + * @var \Magento\Checkout\Model\Session + */ + private $checkoutsession; + /** * Constructor * diff --git a/Model/Observer/Redirect.php b/Model/Observer/Redirect.php index 093b78b3..7f74726f 100644 --- a/Model/Observer/Redirect.php +++ b/Model/Observer/Redirect.php @@ -18,6 +18,17 @@ class Redirect implements ObserverInterface * @var _url */ protected $_url; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + + /** + * @var \Magento\Checkout\Model\Session + */ + protected $checkoutsession; + /** * Constructor * diff --git a/Model/Observer/Refund.php b/Model/Observer/Refund.php index b987f333..6cc1e067 100644 --- a/Model/Observer/Refund.php +++ b/Model/Observer/Refund.php @@ -9,6 +9,19 @@ class Refund implements ObserverInterface { + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + public $wplogger; + /** + * @var \Magento\Framework\Pricing\Helper\Data + */ + public $pricinghelper; + + /** + * @var \Magento\Checkout\Model\Session + */ + public $checkoutsession; /** * Constructor * diff --git a/Model/Order.php b/Model/Order.php index 0e96716c..d8e8b505 100644 --- a/Model/Order.php +++ b/Model/Order.php @@ -13,6 +13,51 @@ class Order * @var order */ private $_order; + + /** + * @var \Magento\Sales\Model\Service\InvoiceService + */ + private $_invoiceService; + + /** + * @var \Magento\Framework\DB\Transaction + */ + private $_transaction; + + /** + * @var \Sapient\Worldpay\Model\Worldpayment + */ + private $worldpaypaymentmodel; + + /** + * @var \Magento\Sales\Model\Order\CreditmemoFactory + */ + private $creditmemoFactory; + + /** + * @var \Magento\Sales\Model\Order\Invoice + */ + private $Invoice; + + /** + * @var \Magento\Sales\Model\Service\CreditmemoService + */ + private $CreditmemoService; + + /** + * @var \Magento\Sales\Model\Order\Creditmemo + */ + private $creditmemo; + + /** + * @var \Magento\Sales\Api\CreditmemoRepositoryInterface + */ + private $creditmemoRepository; + + /** + * @var \Magento\Sales\Model\Order\Creditmemo + */ + private $ordercreditmemo; /** * Constructor diff --git a/Model/Order/Email/Sender/OrderSender.php b/Model/Order/Email/Sender/OrderSender.php index effc1261..1e9c7b95 100644 --- a/Model/Order/Email/Sender/OrderSender.php +++ b/Model/Order/Email/Sender/OrderSender.php @@ -21,6 +21,16 @@ class OrderSender extends \Magento\Sales\Model\Order\Email\Sender\OrderSender public const XML_PATH_AUTHORISED_EMAIL_GUEST_TEMPLATE = 'wp_auth_sales_email_order_guest_template'; public const XML_PATH_AUTHORISED_EMAIL_TEMPLATE = 'wp_auth_sales_email_order_template'; + /** + * @var \Sapient\Worldpay\Model\Worldpayment + */ + public $worldpaypaymentmodel; + + /** + * @var \Magento\Framework\App\Config\ScopeConfigInterface + */ + public $scopeConfig; + /** * Constructor * diff --git a/Model/Order/Service.php b/Model/Order/Service.php index 37443e64..9e97af0f 100644 --- a/Model/Order/Service.php +++ b/Model/Order/Service.php @@ -7,6 +7,54 @@ class Service { + /** + * @var \Magento\Checkout\Model\Session + */ + protected $checkoutsession; + /** + * @var \Magento\Sales\Model\Order + */ + protected $mageorder; + /** + * @var \Magento\Sales\Model\Order\Email\Sender\OrderSender + */ + protected $emailsender; + /** + * @var \Magento\Sales\Model\Service\InvoiceService + */ + protected $_invoiceService; + /** + * @var \Magento\Framework\DB\Transaction + */ + protected $_transaction; + /** + * @var \Sapient\Worldpay\Model\Worldpayment + */ + protected $worldpaypaymentmodel; + /** + * @var \Magento\Sales\Model\Order\CreditmemoFactory + */ + protected $creditmemoFactory; + /** + * @var \Magento\Sales\Model\Order\Invoice + */ + protected $Invoice; + /** + * @var \Magento\Sales\Model\Service\CreditmemoService + */ + protected $CreditmemoService; + /** + * @var \Magento\Sales\Model\Order\Creditmemo + */ + protected $ordercreditmemo; + /** + * @var \Magento\Sales\Api\CreditmemoRepositoryInterface + */ + protected $creditmemoRepository; + /** + * @var \Sapient\Worldpay\Model\ResourceModel\Multishipping\Order\Collection + */ + protected $multishippingOrderCollection; /** * Constructor * diff --git a/Model/PayByLink/Order.php b/Model/PayByLink/Order.php new file mode 100644 index 00000000..10b97394 --- /dev/null +++ b/Model/PayByLink/Order.php @@ -0,0 +1,86 @@ +worldpayhelper = $worldpayhelper; + $this->_orderCollectionFactory = $orderCollectionFactory; + } + /** + * Get the list of orders to be expired or resend + * + * @param string $curDate + * @param int $expiryTime + * @param bool|null $resendExpiryTime + * @return array List of order IDs + */ + public function getPayByLinkOrderIds($curDate, $expiryTime, $resendExpiryTime = null) + { + $dateFieldValues = []; + $dateFields = []; + /* Expiry Time date finding */ + $minDate = $this->worldpayhelper->findPblOrderExpiryTime($curDate, $expiryTime); + $cronDates = $this->worldpayhelper->findFromToPblDateAndTime($minDate); + $dateFieldValues[] = ['from' => $cronDates['from'], 'to' => $cronDates['to']]; + $dateFields[] = 'main_table.created_at'; + /* Resend Expiry Time */ + if (!empty($resendExpiryTime)) { + $dateFields[] = 'main_table.created_at'; + $minResendDate = $this->worldpayhelper->findPblOrderExpiryTime($curDate, $resendExpiryTime); + $cronResendDates = $this->worldpayhelper->findFromToPblDateAndTime($minResendDate); + $dateFieldValues[] = ['from' => $cronResendDates['from'], 'to' => $cronResendDates['to']]; + } + $orderStatus = 'pending'; + $orders = $this->getOrderCollectionFactory()->create(); + $orders->distinct(true); + $orders->addFieldToSelect(['increment_id','created_at']); + $orders->addFieldToFilter('main_table.status', ['in' => $orderStatus]); + $orders->addFieldToFilter($dateFields, $dateFieldValues); + $orders->addFieldToFilter('og.payment_method', ['eq' => 'worldpay_paybylink']); + $orders->join(['wp' => 'worldpay_payment'], 'wp.order_id=main_table.increment_id', ''); + $orders->join(['og' => 'sales_order_grid'], 'og.entity_id=main_table.entity_id', ''); + $orders->getSelect()->group('wp.worldpay_order_id'); + $orderIds = $orders->getData(); + return $orderIds; + } + /** + * Get Order Collection Factory + * + * @return CollectionFactoryInterface + */ + private function getOrderCollectionFactory() + { + if ($this->orderCollectionFactory === null) { + + $this->orderCollectionFactory = $this->_orderCollectionFactory; + } + return $this->orderCollectionFactory; + } +} diff --git a/Model/Payment/HostedUrl.php b/Model/Payment/HostedUrl.php index d35ee5ca..79dbd0e6 100644 --- a/Model/Payment/HostedUrl.php +++ b/Model/Payment/HostedUrl.php @@ -57,6 +57,16 @@ class HostedUrl implements HostedUrlInterface * @var quoteIdMaskFactory */ protected $quoteIdMaskFactory; + + /** + * @var Repository + */ + protected $assetRepo; + + /** + * @var mixed + */ + protected $store; /** * Constructor diff --git a/Model/Payment/MultishippingStateResponse.php b/Model/Payment/MultishippingStateResponse.php new file mode 100644 index 00000000..af394f76 --- /dev/null +++ b/Model/Payment/MultishippingStateResponse.php @@ -0,0 +1,91 @@ +stateResponse = $stateResponse; + } + /** + * Extract merchant code from params + * + * @param Array $params + */ + public function extractMerchantCodeFromParams($params) + { + $orderkey = $params['orderKey']; + $extractMerchantCode = explode('^', $orderkey); + $merchantCode = $extractMerchantCode[1]; + return $merchantCode; + } + + /** + * Create Response + * + * @param string $params + * @param string $ordercode + * @param string $status + */ + public function createResponse($params, $ordercode, $status) + { + $merchantCode = $this->extractMerchantCodeFromParams($params); + $stateResponseObj = null; + switch ($status) { + case 'cancelled': + $stateResponseObj = new \Sapient\Worldpay\Model\Payment\StateResponse( + $ordercode, + $merchantCode, + \Sapient\Worldpay\Model\Payment\StateInterface::STATUS_CANCELLED, + null + ); + break; + case 'pending': + $stateResponseObj = new \Sapient\Worldpay\Model\Payment\StateResponse( + $ordercode, + $merchantCode, + \Sapient\Worldpay\Model\Payment\StateInterface::STATUS_PENDING_PAYMENT, + null + ); + break; + default: + $stateResponseObj = new \Sapient\Worldpay\Model\Payment\StateResponse( + $ordercode, + $merchantCode, + \Sapient\Worldpay\Model\Payment\StateInterface::STATUS_PENDING_PAYMENT, + null + ); + break; + } + return $stateResponseObj; + } + /** + * Create Cancelled Response + * + * @param string $ordercode + * @param string $merchantCode + */ + public function createCancelledResponse($ordercode, $merchantCode) + { + $stateResponseObj = null; + $stateResponseObj = new \Sapient\Worldpay\Model\Payment\StateResponse( + $ordercode, + $merchantCode, + \Sapient\Worldpay\Model\Payment\StateInterface::STATUS_CANCELLED, + null + ); + return $stateResponseObj; + } +} diff --git a/Model/Payment/PaymentTypes.php b/Model/Payment/PaymentTypes.php index e7fd8535..a76f71f7 100644 --- a/Model/Payment/PaymentTypes.php +++ b/Model/Payment/PaymentTypes.php @@ -8,6 +8,10 @@ class PaymentTypes implements PaymentTypeInterface { + /** + * @var \Sapient\Worldpay\Model\Authorisation\PaymentOptionsService + */ + public $paymentoptionsservice; /** * Constructor * diff --git a/Model/Payment/Service.php b/Model/Payment/Service.php index c1bd5e2a..b610af28 100644 --- a/Model/Payment/Service.php +++ b/Model/Payment/Service.php @@ -6,7 +6,7 @@ class Service { - + public const INTERACTION_TYPE_MS = "ECOM_MULTISHIPPING"; /** * @var \Sapient\Worldpay\Model\Request\PaymentServiceRequest */ @@ -31,6 +31,26 @@ class Service * @var _helper */ protected $_helper; + + /** + * @var paymentupdatefactory + */ + protected $paymentupdatefactory; + + /** + * @var \Sapient\Worldpay\Model\Request\PaymentServiceRequest + */ + protected $paymentservicerequest; + + /** + * @var \Sapient\Worldpay\Model\Worldpayment + */ + protected $worldpayPayment; + + /** + * @var \Sapient\Worldpay\Model\ResourceModel\Multishipping\Order\Collection + */ + protected $multishippingOrderCollection; /** * Constructor * @@ -134,13 +154,18 @@ public function getPaymentUpdateXmlForOrder(\Sapient\Worldpay\Model\Order $order if (!$worldPayPayment) { return false; } + $interactionType = $worldPayPayment->getInteractionType(); + if ($worldPayPayment->getIsMultishippingOrder()) { + $interactionType = self::INTERACTION_TYPE_MS; + } + $rawXml = $this->paymentservicerequest->inquiry( $worldPayPayment->getMerchantId(), $worldPayPayment->getWorldpayOrderId(), $worldPayPayment->getStoreId(), $order->getPaymentMethodCode(), $worldPayPayment->getPaymentType(), - $worldPayPayment->getInteractionType() + $interactionType ); $paymentService = new \SimpleXmlElement($rawXml); diff --git a/Model/Payment/StateResponse.php b/Model/Payment/StateResponse.php index 9b369eb3..0de4d797 100644 --- a/Model/Payment/StateResponse.php +++ b/Model/Payment/StateResponse.php @@ -21,7 +21,10 @@ class StateResponse implements \Sapient\Worldpay\Model\Payment\StateInterface * @var amount */ public $amount; - + /** + * @var string + */ + public $merchantCode; /** * Constructor * diff --git a/Model/Payment/Update/Authorised.php b/Model/Payment/Update/Authorised.php index 4646a3fc..28cf4294 100644 --- a/Model/Payment/Update/Authorised.php +++ b/Model/Payment/Update/Authorised.php @@ -11,6 +11,20 @@ class Authorised extends \Sapient\Worldpay\Model\Payment\Update\Base implements /** @var \Sapient\Worldpay\Helper\Data */ private $_configHelper; + /** + * @var \Sapient\Worldpay\Model\Payment\StateInterface + */ + public $paymentState; + + /** + * @var \Sapient\Worldpay\Model\Payment\WorldPayPayment + */ + public $_worldPayPayment; + /** + * @var \Sapient\Worldpay\Helper\Multishipping + */ + public $multishippingHelper; + /** * Constructor * @param \Sapient\Worldpay\Model\Payment\StateInterface $paymentState @@ -109,7 +123,7 @@ private function _getAllowedPaymentStatuses(\Sapient\Worldpay\Model\Order $order \Sapient\Worldpay\Model\Payment\StateInterface::STATUS_AUTHORISED ]; } - if ($this->_isACHIntegrationMode($order)) { + if ($this->_isACHIntegrationMode($order) || $this->_isSEPAIntegrationMode($order)) { return [ \Sapient\Worldpay\Model\Payment\StateInterface::STATUS_SENT_FOR_AUTHORISATION, \Sapient\Worldpay\Model\Payment\StateInterface::STATUS_AUTHORISED, @@ -202,4 +216,18 @@ private function _isACHIntegrationMode(\Sapient\Worldpay\Model\Order $order) } return false; } + + /** + * Check if integration mode is sepa + * + * @param \Sapient\Worldpay\Model\Order $order + * @return bool + */ + private function _isSEPAIntegrationMode(\Sapient\Worldpay\Model\Order $order) + { + if ($order->getPaymentType() === 'SEPA_DIRECT_DEBIT-SSL') { + return true; + } + return false; + } } diff --git a/Model/Payment/Update/Defaultupdate.php b/Model/Payment/Update/Defaultupdate.php index 0988e044..20f58f87 100644 --- a/Model/Payment/Update/Defaultupdate.php +++ b/Model/Payment/Update/Defaultupdate.php @@ -10,6 +10,10 @@ class Defaultupdate extends \Sapient\Worldpay\Model\Payment\Update\Base implemen { /** @var \Sapient\Worldpay\Helper\Data */ private $_configHelper; + /** + * @var \Sapient\Worldpay\Helper\Multishipping + */ + protected $multishippingHelper; /** * Constructor * @param \Sapient\Worldpay\Model\Payment\StateInterface $paymentState diff --git a/Model/Payment/Update/Error.php b/Model/Payment/Update/Error.php index f7f93ebd..5ef80963 100644 --- a/Model/Payment/Update/Error.php +++ b/Model/Payment/Update/Error.php @@ -10,6 +10,10 @@ class Error extends \Sapient\Worldpay\Model\Payment\Update\Base implements Updat { /** @var \Sapient\Worldpay\Helper\Data */ private $_configHelper; + /** + * @var \Sapient\Worldpay\Helper\Multishipping + */ + protected $multishippingHelper; /** * Constructor * @param \Sapient\Worldpay\Model\Payment\StateInterface $paymentState diff --git a/Model/Payment/Update/Factory.php b/Model/Payment/Update/Factory.php index 9ab1c873..8ef921bb 100644 --- a/Model/Payment/Update/Factory.php +++ b/Model/Payment/Update/Factory.php @@ -8,6 +8,17 @@ class Factory { /** @var \Sapient\Worldpay\Helper\Data */ private $_configHelper; + + /** + * @var \Sapient\Worldpay\Model\Payment\WorldPayPayment + */ + private $worldpaymentmodel; + + /** + * @var \Sapient\Worldpay\Helper\Multishipping + */ + private $_multishippingHelper; + /** * Constructor * diff --git a/Model/Payment/Update/PendingPayment.php b/Model/Payment/Update/PendingPayment.php index 64587b4c..165be428 100644 --- a/Model/Payment/Update/PendingPayment.php +++ b/Model/Payment/Update/PendingPayment.php @@ -10,6 +10,10 @@ class PendingPayment extends \Sapient\Worldpay\Model\Payment\Update\Base impleme { /** @var \Sapient\Worldpay\Helper\Data */ private $_configHelper; + /** + * @var \Sapient\Worldpay\Helper\Multishipping + */ + protected $multishippingHelper; /** * Constructor * @param \Sapient\Worldpay\Model\Payment\StateInterface $paymentState diff --git a/Model/Payment/Update/Refused.php b/Model/Payment/Update/Refused.php index 3018e5de..f65e8e7b 100644 --- a/Model/Payment/Update/Refused.php +++ b/Model/Payment/Update/Refused.php @@ -10,6 +10,10 @@ class Refused extends \Sapient\Worldpay\Model\Payment\Update\Base implements Upd { /** @var \Sapient\Worldpay\Helper\Data */ private $_configHelper; + /** + * @var \Sapient\Worldpay\Helper\Multishipping + */ + protected $multishippingHelper; /** * Constructor * @param \Sapient\Worldpay\Model\Payment\StateInterface $paymentState diff --git a/Model/Payment/UpdateWorldpayment.php b/Model/Payment/UpdateWorldpayment.php index fe9169e5..72adfbca 100644 --- a/Model/Payment/UpdateWorldpayment.php +++ b/Model/Payment/UpdateWorldpayment.php @@ -36,9 +36,68 @@ class UpdateWorldpayment */ private $transactionsFactory; /** - * @var Magento\Framework\Serialize\Serializer\Json + * @var \Magento\Framework\Serialize\Serializer\Json */ protected $serializer; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + public $wplogger; + /** + * @var SavedTokenFactory + */ + public $savedTokenFactory; + + /** + * @var \Sapient\Worldpay\Helper\Data + */ + public $worldpayHelper; + + /** + * @var \Magento\Framework\Message\ManagerInterface + */ + public $_messageManager; + + /** + * @var \Magento\Customer\Model\Session + */ + public $customerSession; + + /** + * @var OrderPaymentExtensionInterfaceFactory + */ + public $paymentExtensionFactory; + + /** + * @var CreditCardTokenFactory + */ + public $paymentTokenFactory; + + /** + * @var \Magento\Backend\Model\Session\Quote + */ + public $quotesession; + + /** + * @var \Magento\Vault\Api\PaymentTokenRepositoryInterface + */ + public $paymentTokenRepository; + + /** + * @var EncryptorInterface + */ + public $encryptor; + + /** + * @var \Sapient\Worldpay\Model\Worldpayment + */ + public $worldpaypaymentmodel; + + /** + * @var \Sapient\Worldpay\Model\Recurring\Subscription\TransactionsFactory + */ + public $transactionFactory; /** * Constructor * diff --git a/Model/Payment/WorldPayPayment.php b/Model/Payment/WorldPayPayment.php index d9c96d43..40532b9d 100644 --- a/Model/Payment/WorldPayPayment.php +++ b/Model/Payment/WorldPayPayment.php @@ -12,6 +12,21 @@ class WorldPayPayment { + /** + * @var \Sapient\Worldpay\Model\WorldpaymentFactory + */ + protected $worldpaypayment; + + /** + * @var \Magento\Sales\Model\Order + */ + protected $order; + + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $worldpayHelper; + /** * @var array */ @@ -53,7 +68,7 @@ public function updateWorldpayPayment(\Sapient\Worldpay\Model\Payment\StateInter if (strpos($paymentState->getPaymentStatus(), "KLARNA") !== false) { $wpp->setData('payment_type', $paymentState->getPaymentMethod()); } - if (!empty($wpp->getData('payment_type'))) { + if (!empty($wpp->getData('payment_type')) && !empty($paymentState->getPaymentMethod())) { if (strtolower($wpp->getData('payment_type')) == "all") { if (!in_array( strtoupper($paymentState->getPaymentMethod()), @@ -69,6 +84,7 @@ public function updateWorldpayPayment(\Sapient\Worldpay\Model\Payment\StateInter } } } + $wpp->setData('merchant_id', $paymentState->getMerchantCode()); $wpp->setData('card_number', $paymentState->getCardNumber()); $wpp->setData('avs_result', $paymentState->getAvsResultCode()); $wpp->setData('cvc_result', $paymentState->getCvcResultCode()); diff --git a/Model/Payment/WpResponse.php b/Model/Payment/WpResponse.php index 033a4336..f6b0a9ce 100644 --- a/Model/Payment/WpResponse.php +++ b/Model/Payment/WpResponse.php @@ -6,6 +6,11 @@ class WpResponse { + + /** + * @var \Sapient\Worldpay\Model\Payment\StateResponseFactory + */ + public $stateResponse; /** * Constructor * @@ -38,6 +43,22 @@ public function createFromCancelledResponse($params) null ); } + /** + * Create From Pay By Link Cancelled Response + * + * @param string $orderCode + * @param string $merchantCode + * @return string + */ + public function createFromPblCancelledResponse($orderCode, $merchantCode) + { + return new \Sapient\Worldpay\Model\Payment\StateResponse( + $orderCode, + $merchantCode, + \Sapient\Worldpay\Model\Payment\StateInterface::STATUS_CANCELLED, + null + ); + } /** * Create from Pending Response diff --git a/Model/PaymentMethods/AbstractMethod.php b/Model/PaymentMethods/AbstractMethod.php index 0969639a..ef058c2e 100644 --- a/Model/PaymentMethods/AbstractMethod.php +++ b/Model/PaymentMethods/AbstractMethod.php @@ -65,6 +65,108 @@ abstract class AbstractMethod extends \Magento\Payment\Model\Method\AbstractMeth * @var array */ protected $paymentdetailsdata; + + /** + * @var \Sapient\Worldpay\Model\Request\PaymentServiceRequest + */ + protected $paymentservicerequest; + /** + * @var \Sapient\Worldpay\Model\Authorisation\RedirectService + */ + protected $redirectservice; + + /** + * @var \Sapient\Worldpay\Model\Authorisation\TokenService + */ + protected $tokenservice; + /** + * @var \Sapient\Worldpay\Model\Authorisation\HostedPaymentPageService + */ + protected $hostedpaymentpageservice; + /** + * @var \Sapient\Worldpay\Model\Authorisation\WalletService + */ + protected $walletService; + /** + * @var \Sapient\Worldpay\Model\Authorisation\PayByLinkService + */ + protected $paybylinkservice; + /** + * @var \Magento\Quote\Api\CartRepositoryInterface + */ + protected $quoteRepository; + /** + * @var \Sapient\Worldpay\Helper\Registry + */ + protected $registryhelper; + + /** + * @var \Magento\Framework\UrlInterface + */ + protected $urlbuilder; + /** + * @var \Sapient\Worldpay\Model\Worldpayment + */ + protected $worldpaypaymentmodel; + /** + * @var \Magento\Framework\Pricing\Helper\Data + */ + protected $pricinghelper; + /** + * @var \Sapient\Worldpay\Model\Response\AdminhtmlResponse + */ + protected $adminhtmlresponse; + /** + * @var \Sapient\Worldpay\Model\Utilities\PaymentMethods + */ + protected $paymentutils; + /** + * @var \Magento\Backend\Model\Session\Quote + */ + protected $adminsessionquote; + /** + * @var \Sapient\Worldpay\Model\SavedTokenFactory + */ + protected $_savecard; + /** + * @var \Magento\Backend\Model\Auth\Session + */ + protected $authSession; + /** + * @var \Sapient\Worldpay\Model\Authorisation\MotoRedirectService + */ + protected $motoredirectservice; + + /** + * @var \Sapient\Worldpay\Model\Payment\PaymentTypes + */ + protected $paymenttypes; + + /** + * @var \Magento\Framework\Registry + */ + protected $registry; + + /** + * @var \Magento\Framework\App\RequestInterface + */ + protected $_request; + + /** + * @var \Sapient\Worldpay\Helper\Multishipping + */ + protected $multishippingHelper; + + /** + * @var \Sapient\Worldpay\Model\Multishipping\OrderFactory + */ + protected $multishippingOrderFactory; + + /** + * @var \Sapient\Worldpay\Model\ResourceModel\Multishipping\Order\Collection + */ + protected $multishippingOrderCollection; + /** * Availability option * @@ -430,7 +532,8 @@ private function _createWorldPayPayment( if ($paymentdetails['method'] == self::WORLDPAY_WALLETS_TYPE) { $integrationType = 'direct'; } - if ($paymentdetails['additional_data']['cc_type'] === 'ACH_DIRECT_DEBIT-SSL') { + if ($paymentdetails['additional_data']['cc_type'] === 'ACH_DIRECT_DEBIT-SSL' || + $paymentdetails['additional_data']['cc_type'] === 'SEPA_DIRECT_DEBIT-SSL') { $integrationType = 'direct'; } $mode = $this->worlpayhelper->getCcIntegrationMode(); @@ -446,9 +549,9 @@ private function _createWorldPayPayment( $cardType = $this->_getpaymentType(); if ($mode == 'redirect') { $tokenId = $this->getTokenIdByCode($paymentdetails['additional_data']['tokenCode']); - if(empty($this->registry->registry('token_code'))){ - $this->registry->register('token_code', $tokenId); - } + if (empty($this->registry->registry('token_code'))) { + $this->registry->register('token_code', $tokenId); + } } } @@ -532,7 +635,8 @@ public function capture(\Magento\Payment\Model\InfoInterface $payment, $amount) $payment->getOrder(), $worldPayPayment, $amount, - $captureArray + $captureArray, + $payment->getMethod() ); } else { $this->_wplogger->info("Partial Capture is disabled or not supported."); diff --git a/Model/PaymentMethods/AlternativePaymentMethods.php b/Model/PaymentMethods/AlternativePaymentMethods.php index afb8aaf6..09f23a35 100644 --- a/Model/PaymentMethods/AlternativePaymentMethods.php +++ b/Model/PaymentMethods/AlternativePaymentMethods.php @@ -63,7 +63,7 @@ public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount public function getAuthorisationService($storeId) { $apmmethods = $this->paymentdetailsdata['additional_data']['cc_type']; - if ($apmmethods === "ACH_DIRECT_DEBIT-SSL") { + if ($apmmethods === "ACH_DIRECT_DEBIT-SSL" || $apmmethods === "SEPA_DIRECT_DEBIT-SSL") { return $this->directservice; } return $this->redirectservice; diff --git a/Model/PaymentMethods/CcVault.php b/Model/PaymentMethods/CcVault.php index 06697e2e..0c58c859 100644 --- a/Model/PaymentMethods/CcVault.php +++ b/Model/PaymentMethods/CcVault.php @@ -98,6 +98,53 @@ class CcVault extends \Magento\Vault\Model\Method\Vault */ protected static $paymentDetails; + /** + * @var WorldpayLogger + */ + protected $logger; + + /** + * @var \Sapient\Worldpay\Model\Authorisation\VaultService + */ + protected $vaultService; + + /** + * @var \Magento\Quote\Api\CartRepositoryInterface + */ + protected $quoteRepository; + + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $worlpayhelper; + + /** + * @var \Sapient\Worldpay\Model\Worldpayment + */ + protected $worldpaypaymentmodel; + + /** + * @var \Sapient\Worldpay\Model\Worldpayment + */ + protected $worldpaypayment; + + /** + * @var \Sapient\Worldpay\Model\Utilities\PaymentMethods + */ + protected $paymentutils; + /** + * @var \Sapient\Worldpay\Model\Request\PaymentServiceRequest + */ + protected $paymentservicerequest; + /** + * @var \Sapient\Worldpay\Model\Response\AdminhtmlResponse + */ + protected $adminhtmlresponse; + /** + * @var \Magento\Framework\Registry + */ + protected $registry; + /** * CcVault constructor * diff --git a/Model/PaymentMethods/PaymentOperations.php b/Model/PaymentMethods/PaymentOperations.php index d711fafe..8e228d45 100644 --- a/Model/PaymentMethods/PaymentOperations.php +++ b/Model/PaymentMethods/PaymentOperations.php @@ -4,6 +4,10 @@ class PaymentOperations extends \Sapient\Worldpay\Model\PaymentMethods\AbstractMethod { + /** + * @var object + */ + public $_response; /** * Update status for void order abstract method * @@ -50,7 +54,8 @@ public function canVoidSale($order) $paymenttype = $worldPayPayment->getPaymentType(); $isPrimeRoutingRequest = $worldPayPayment->getIsPrimeroutingEnabled(); - if (($paymenttype === 'ACH_DIRECT_DEBIT-SSL' || $isPrimeRoutingRequest) + if (($paymenttype === 'ACH_DIRECT_DEBIT-SSL' || + $isPrimeRoutingRequest) && !($worldPayPayment->getPaymentStatus() === 'VOIDED')) { $xml = $this->paymentservicerequest->voidSale( $payment->getOrder(), diff --git a/Model/Recurring/Subscription.php b/Model/Recurring/Subscription.php index 8977def8..c482c8f6 100644 --- a/Model/Recurring/Subscription.php +++ b/Model/Recurring/Subscription.php @@ -166,6 +166,11 @@ class Subscription extends \Magento\Framework\Model\AbstractModel */ public $registryObj; + /** + * @var \Sapient\Worldpay\Helper\Recurring + */ + private $recurringHelper; + /** * Subscription model constructor. * diff --git a/Model/Request.php b/Model/Request.php index 92ac782b..7c7c51fe 100644 --- a/Model/Request.php +++ b/Model/Request.php @@ -19,7 +19,16 @@ class Request /** * @var \Sapient\Worldpay\Logger\WorldpayLogger */ - protected $_logger; + protected $_wplogger; + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $helper; + + /** + * @var \Magento\Framework\HTTP\Client\Curl + */ + protected $curl; public const CURL_POST = true; public const CURL_RETURNTRANSFER = true; @@ -50,15 +59,16 @@ public function __construct( * @param array $quote * @param string $username * @param string $password + * @param bool $additionalHeader * @return SimpleXMLElement body * @throws Exception */ - public function sendRequest($quote, $username, $password) + public function sendRequest($quote, $username, $password, $additionalHeader = false) { $request = $this->_getRequest(); $logger = $this->_wplogger; $url = $this->_getUrl(); - $pluginTrackerDetails = $this->helper->getPluginTrackerdetails(); + $pluginTrackerDetails = $this->helper->getPluginTrackerdetails($username, $quote); $logger->info('Setting destination URL: ' . $url); $logger->info('Initialising request'); $request->setOption(CURLOPT_POST, self::CURL_POST); @@ -80,31 +90,28 @@ public function sendRequest($quote, $username, $password) } //$request->addCookie(CURLOPT_COOKIE, $cookie); $request->setTimeout(self::CURL_TIMEOUT); - $request->setHeaders([ + $headersArray = [ 'Content-Type'=> 'text/xml', 'Expect'=>'' - ]); + ]; $logger->info('Sending XML as: ' . $this->_getObfuscatedXmlLog($quote)); - $request->setOption(CURLOPT_HEADER, 1); - $request->setOption( - CURLOPT_HTTPHEADER, - ["content-type: application/json", - "MERCHANT_ID" => $pluginTrackerDetails['MERCHANT_ID'], - "API_USERNAME" => $pluginTrackerDetails['API_USERNAME'], - "MAGENTO_EDITION"=>$pluginTrackerDetails['MAGENTO_EDITION'], - "MAGENTO_VERSION"=>$pluginTrackerDetails['MAGENTO_VERSION'], - "PHP_VERSION"=> $pluginTrackerDetails['PHP_VERSION'], - "CURRENT_WORLDPAY_PLUGIN_VERSION"=>isset($pluginTrackerDetails['CURRENT_WORLDPAY_PLUGIN_VERSION'])? - $pluginTrackerDetails['CURRENT_WORLDPAY_PLUGIN_VERSION']:"", - "WORLDPAY_PLUGIN_VERSION_USED_TILL_DATE" => - isset($pluginTrackerDetails['WORLDPAY_PLUGIN_VERSION_USED_TILL_DATE'])? - $pluginTrackerDetails['WORLDPAY_PLUGIN_VERSION_USED_TILL_DATE']:"", - "UPGRADE_DATES" => isset($pluginTrackerDetails['UPGRADE_DATES'])? - $pluginTrackerDetails['UPGRADE_DATES']:"" - ] - ); - $logger->info('Sending additional headers as: ' . json_encode([ + + if ($additionalHeader) { + $headersArray['MERCHANT_ID'] = $pluginTrackerDetails['MERCHANT_ID']; + $headersArray['API_USERNAME'] = $pluginTrackerDetails['API_USERNAME']; + $headersArray['MAGENTO_EDITION'] = $pluginTrackerDetails['MAGENTO_EDITION']; + $headersArray['MAGENTO_VERSION'] = $pluginTrackerDetails['MAGENTO_VERSION']; + $headersArray['PHP_VERSION'] = $pluginTrackerDetails['PHP_VERSION']; + $headersArray['CURRENT_WORLDPAY_PLUGIN_VERSION'] = isset($pluginTrackerDetails['CURRENT_WORLDPAY_PLUGIN_VERSION'])? + $pluginTrackerDetails['CURRENT_WORLDPAY_PLUGIN_VERSION']:""; + $headersArray['WORLDPAY_PLUGIN_VERSION_USED_TILL_DATE'] = isset($pluginTrackerDetails['WORLDPAY_PLUGIN_VERSION_USED_TILL_DATE'])? + $pluginTrackerDetails['WORLDPAY_PLUGIN_VERSION_USED_TILL_DATE']:""; + + $headersArray['UPGRADE_DATES'] = isset($pluginTrackerDetails['UPGRADE_DATES'])? + $pluginTrackerDetails['UPGRADE_DATES']:""; + + $logger->info('Sending additional headers as: ' . json_encode([ "MERCHANT_ID" => $pluginTrackerDetails['MERCHANT_ID'], "API_USERNAME" => $pluginTrackerDetails['API_USERNAME'], "MAGENTO_EDITION"=>$pluginTrackerDetails['MAGENTO_EDITION'], @@ -118,6 +125,9 @@ public function sendRequest($quote, $username, $password) "UPGRADE_DATES" => isset($pluginTrackerDetails['UPGRADE_DATES'])? $pluginTrackerDetails['UPGRADE_DATES']:"" ])); + } + $request->setHeaders($headersArray); + $request->setOption(CURLINFO_HEADER_OUT, 1); $request->post($url, $quote->saveXML()); @@ -133,17 +143,22 @@ public function sendRequest($quote, $username, $password) } if (!$result || ($request->getStatus() != self::SUCCESS)) { $logger->info('Request could not be sent.'); + $errorMessage = $this->findErrorMessage($result); $logger->info($result); - $logger->info('########### END OF REQUEST - FAILURE WHILST TRYING TO SEND REQUEST ###########'); + $logger->info('########### END OF REQUEST - FAILURE WHILE TRYING TO SEND REQUEST ###########'); + if (!empty($errorMessage)) { + $errorMessage = $errorMessage."."; + } + $errorMessage .= 'Worldpay api service not available'; throw new \Magento\Framework\Exception\LocalizedException( - __('Worldpay api service not available') + __($errorMessage) ); } $logger->info('Request successfully sent'); $logger->info($result); // extract headers - // extract headers + // extract headers $bits = explode("\r\n\r\n", $result); $body = array_pop($bits); $headers = implode("\r\n\r\n", $bits); @@ -164,7 +179,7 @@ public function sendRequest($quote, $username, $password) */ protected function _getObfuscatedXmlLog($quote) { - $elems = ['cardNumber', 'cvc']; + $elems = ['cardNumber', 'cvc', 'iban', 'telephoneNumber']; $_xml = clone($quote); foreach ($elems as $_e) { @@ -200,4 +215,25 @@ private function _getRequest() return $this->_request; } + /** + * Find Error message from header response + * + * @param string $response + */ + private function findErrorMessage($response) + { + $headerbits = explode("\r\n\r\n", $response); + $remainingBody = array_pop($headerbits); + $errorMsg = ""; + if (!empty($remainingBody)) { + $responseXml = new \SimpleXmlElement($remainingBody); + try { + $errorMsg = $responseXml->head->title; + } catch (\Exception $e) { + $this->_wplogger->info(__('Could not parse error body xml')); + } + + } + return $errorMsg; + } } diff --git a/Model/Request/AuthenticationService.php b/Model/Request/AuthenticationService.php index fdaab586..d0a26914 100644 --- a/Model/Request/AuthenticationService.php +++ b/Model/Request/AuthenticationService.php @@ -9,6 +9,16 @@ class AuthenticationService extends \Magento\Framework\DataObject { + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $_wplogger; + + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $worldpayhelper; + /** * Constructor * diff --git a/Model/Request/PaymentServiceRequest.php b/Model/Request/PaymentServiceRequest.php index 21e03821..3b5f8d49 100644 --- a/Model/Request/PaymentServiceRequest.php +++ b/Model/Request/PaymentServiceRequest.php @@ -16,7 +16,46 @@ class PaymentServiceRequest extends \Magento\Framework\DataObject * @var \Sapient\Worldpay\Model\Request $request */ protected $_request; + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $_wplogger; + + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $worldpayhelper; + + /** + * @var \Sapient\Worldpay\Helper\GeneralException + */ + protected $exceptionHelper; + + /** + * @var \Magento\Sales\Model\Service\InvoiceService + */ + protected $_invoiceService; + /** + * @var \Sapient\Worldpay\Helper\SendErrorReport + */ + protected $emailErrorReportHelper; + + /** + * @var \Magento\Customer\Model\Session + */ + protected $customerSession; + + /** + * @var \Magento\Framework\App\Config\ScopeConfigInterface + */ + protected $scopeConfig; + + /** + * @var \Magento\Store\Model\StoreManagerInterface + */ + protected $storeManager; + public const SEND_ADDITIONAL_HEADER = true; /** * Constructor * @@ -26,6 +65,9 @@ class PaymentServiceRequest extends \Magento\Framework\DataObject * @param \Sapient\Worldpay\Helper\GeneralException $exceptionHelper * @param \Magento\Sales\Model\Service\InvoiceService $invoiceService * @param \Sapient\Worldpay\Helper\SendErrorReport $emailErrorReportHelper + * @param \Magento\Customer\Model\Session $customerSession + * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig + * @param \Magento\Store\Model\StoreManagerInterface $storeManager */ public function __construct( \Sapient\Worldpay\Logger\WorldpayLogger $wplogger, @@ -33,7 +75,10 @@ public function __construct( \Sapient\Worldpay\Helper\Data $worldpayhelper, \Sapient\Worldpay\Helper\GeneralException $exceptionHelper, \Magento\Sales\Model\Service\InvoiceService $invoiceService, - \Sapient\Worldpay\Helper\SendErrorReport $emailErrorReportHelper + \Sapient\Worldpay\Helper\SendErrorReport $emailErrorReportHelper, + \Magento\Customer\Model\Session $customerSession, + \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, + \Magento\Store\Model\StoreManagerInterface $storeManager ) { $this->_wplogger = $wplogger; $this->_request = $request; @@ -41,6 +86,9 @@ public function __construct( $this->exceptionHelper = $exceptionHelper; $this->_invoiceService = $invoiceService; $this->emailErrorReportHelper = $emailErrorReportHelper; + $this->customerSession = $customerSession; + $this->scopeConfig = $scopeConfig; + $this->storeManager = $storeManager; } /** @@ -53,18 +101,25 @@ public function order3DSecure($directOrderParams) { $loggerMsg = '########## Submitting direct 3DSecure order request. OrderCode: '; $this->_wplogger->info($loggerMsg . $directOrderParams['orderCode'] . ' ##########'); - + $merchantCode = $directOrderParams['merchantCode']; + if (!empty($directOrderParams['isMultishippingOrder'])) { + $msMerchantCode = $this->worldpayhelper->getMultishippingMerchantCode(); + $merchantCode = !empty($msMerchantCode) ? $msMerchantCode : $merchantCode ; + } if (isset($directOrderParams['tokenRequestConfig'])) { $requestConfiguration = [ 'threeDSecureConfig' => $directOrderParams['threeDSecureConfig'], 'tokenRequestConfig' => $directOrderParams['tokenRequestConfig'] ]; - $this->xmldirectorder = new \Sapient\Worldpay\Model\XmlBuilder\DirectOrder($requestConfiguration); + $this->xmldirectorder = new \Sapient\Worldpay\Model\XmlBuilder\DirectOrder( + $this->customerSession, + $requestConfiguration + ); $paymentType = isset($directOrderParams['paymentDetails']['brand']) ? $directOrderParams['paymentDetails']['brand']: $directOrderParams['paymentDetails']['paymentType']; $orderSimpleXml = $this->xmldirectorder->build3DSecure( - $directOrderParams['merchantCode'], + $merchantCode, $directOrderParams['orderCode'], $directOrderParams['paymentDetails'], $directOrderParams['paResponse'], @@ -77,7 +132,7 @@ public function order3DSecure($directOrderParams) $this->xmldirectorder = new \Sapient\Worldpay\Model\XmlBuilder\WalletOrder($requestConfiguration); $paymentType = $directOrderParams['paymentType']; $orderSimpleXml = $this->xmldirectorder->build3DSecure( - $directOrderParams['merchantCode'], + $merchantCode, $directOrderParams['orderCode'], $directOrderParams['paymentDetails'], $directOrderParams['paResponse'], @@ -85,10 +140,20 @@ public function order3DSecure($directOrderParams) ); } + $xmlUsername = $this->worldpayhelper->getXmlUsername($paymentType); + $xmlPassword = $this->worldpayhelper->getXmlPassword($paymentType); + + if (!empty($directOrderParams['isMultishippingOrder'])) { + $msMerchantUn = $this->worldpayhelper->getMultishippingMerchantUsername(); + $msMerchantPw = $this->worldpayhelper->getMultishippingMerchantPassword(); + + $xmlUsername = !empty($msMerchantUn) ? $msMerchantUn : $xmlUsername ; + $xmlPassword = !empty($msMerchantPw) ? $msMerchantPw : $xmlPassword ; + } return $this->_sendRequest( dom_import_simplexml($orderSimpleXml)->ownerDocument, - $this->worldpayhelper->getXmlUsername($paymentType), - $this->worldpayhelper->getXmlPassword($paymentType) + $xmlUsername, + $xmlPassword ); } @@ -146,8 +211,20 @@ public function order($directOrderParams) $xmlPassword = !empty($wpMotoPassword) ? $wpMotoPassword : $xmlPassword; $merchantCode = !empty($wpMotoCode) ? $wpMotoCode : $merchantCode; } + if (!empty($directOrderParams['isMultishippingOrder'])) { + $msMerchantCode = $this->worldpayhelper->getMultishippingMerchantCode(); + $msMerchantUn = $this->worldpayhelper->getMultishippingMerchantUsername(); + $msMerchantPw = $this->worldpayhelper->getMultishippingMerchantPassword(); - $this->xmldirectorder = new \Sapient\Worldpay\Model\XmlBuilder\DirectOrder($requestConfiguration); + $xmlUsername = !empty($msMerchantUn) ? $msMerchantUn : $xmlUsername ; + $xmlPassword = !empty($msMerchantPw) ? $msMerchantPw : $xmlPassword ; + $merchantCode = !empty($msMerchantCode) ? $msMerchantCode : $merchantCode ; + } + $captureDelay = $this->worldpayhelper->getCaptureDelayValues(); + $this->xmldirectorder = new \Sapient\Worldpay\Model\XmlBuilder\DirectOrder( + $this->customerSession, + $requestConfiguration + ); if (empty($directOrderParams['thirdPartyData']) && empty($directOrderParams['shippingfee'])) { $directOrderParams['thirdPartyData']=''; @@ -201,12 +278,14 @@ public function order($directOrderParams) $directOrderParams['shippingfee'], $directOrderParams['exponent'], $directOrderParams['primeRoutingData'], - $directOrderParams['orderLineItems'] + $directOrderParams['orderLineItems'], + $captureDelay ); return $this->_sendRequest( dom_import_simplexml($orderSimpleXml)->ownerDocument, $xmlUsername, - $xmlPassword + $xmlPassword, + self::SEND_ADDITIONAL_HEADER ); } @@ -220,9 +299,23 @@ public function achOrder($directOrderParams) { $this->_wplogger->info('########## Submitting ACH order request. OrderCode: ' . $directOrderParams['orderCode'] . ' ##########'); + + $xmlUsername = $this->worldpayhelper->getXmlUsername($directOrderParams['paymentDetails']['paymentType']); + $xmlPassword = $this->worldpayhelper->getXmlPassword($directOrderParams['paymentDetails']['paymentType']); + $merchantCode = $directOrderParams['merchantCode']; + if (!empty($directOrderParams['isMultishippingOrder'])) { + $msMerchantCode = $this->worldpayhelper->getMultishippingMerchantCode(); + $msMerchantUn = $this->worldpayhelper->getMultishippingMerchantUsername(); + $msMerchantPw = $this->worldpayhelper->getMultishippingMerchantPassword(); + + $xmlUsername = !empty($msMerchantUn) ? $msMerchantUn : $xmlUsername ; + $xmlPassword = !empty($msMerchantPw) ? $msMerchantPw : $xmlPassword ; + $merchantCode = !empty($msMerchantCode) ? $msMerchantCode : $merchantCode ; + } + $captureDelay = $this->worldpayhelper->getCaptureDelayValues(); $this->xmldirectorder = new \Sapient\Worldpay\Model\XmlBuilder\ACHOrder(); $orderSimpleXml = $this->xmldirectorder->build( - $directOrderParams['merchantCode'], + $merchantCode, $directOrderParams['orderCode'], $directOrderParams['orderDescription'], $directOrderParams['currencyCode'], @@ -235,13 +328,65 @@ public function achOrder($directOrderParams) $directOrderParams['billingAddress'], $directOrderParams['shopperId'], $directOrderParams['statementNarrative'], - $directOrderParams['exponent'] + $directOrderParams['exponent'], + $captureDelay ); return $this->_sendRequest( dom_import_simplexml($orderSimpleXml)->ownerDocument, - $this->worldpayhelper->getXmlUsername($directOrderParams['paymentDetails']['paymentType']), - $this->worldpayhelper->getXmlPassword($directOrderParams['paymentDetails']['paymentType']) + $xmlUsername, + $xmlPassword, + self::SEND_ADDITIONAL_HEADER + ); + } + + /** + * Send SEPA order XML to Worldpay server + * + * @param array $directOrderParams + * @return mixed + */ + public function sepaOrder($directOrderParams) + { + $this->_wplogger->info('########## Submitting SEPA order request. OrderCode: ' . + $directOrderParams['orderCode'] . ' ##########'); + + $xmlUsername = $this->worldpayhelper->getXmlUsername($directOrderParams['paymentDetails']['paymentType']); + $xmlPassword = $this->worldpayhelper->getXmlPassword($directOrderParams['paymentDetails']['paymentType']); + $merchantCode = $directOrderParams['merchantCode']; + if (!empty($directOrderParams['isMultishippingOrder'])) { + $msMerchantCode = $this->worldpayhelper->getMultishippingMerchantCode(); + $msMerchantUn = $this->worldpayhelper->getMultishippingMerchantUsername(); + $msMerchantPw = $this->worldpayhelper->getMultishippingMerchantPassword(); + + $xmlUsername = !empty($msMerchantUn) ? $msMerchantUn : $xmlUsername ; + $xmlPassword = !empty($msMerchantPw) ? $msMerchantPw : $xmlPassword ; + $merchantCode = !empty($msMerchantCode) ? $msMerchantCode : $merchantCode ; + } + $captureDelay = $this->worldpayhelper->getCaptureDelayValues(); + $this->xmldirectorder = new \Sapient\Worldpay\Model\XmlBuilder\SEPAOrder(); + $orderSimpleXml = $this->xmldirectorder->build( + $merchantCode, + $directOrderParams['orderCode'], + $directOrderParams['orderDescription'], + $directOrderParams['currencyCode'], + $directOrderParams['amount'], + $directOrderParams['paymentDetails'], + $directOrderParams['shopperEmail'], + $directOrderParams['acceptHeader'], + $directOrderParams['userAgentHeader'], + $directOrderParams['shippingAddress'], + $directOrderParams['billingAddress'], + $directOrderParams['shopperId'], + $directOrderParams['statementNarrative'], + $directOrderParams['exponent'], + $captureDelay + ); + + return $this->_sendRequest( + dom_import_simplexml($orderSimpleXml)->ownerDocument, + $xmlUsername, + $xmlPassword ); } @@ -291,7 +436,23 @@ public function orderToken($tokenOrderParams) ? $this->worldpayhelper->getMotoMerchantCode() : $merchantCode; } - $this->xmltokenorder = new \Sapient\Worldpay\Model\XmlBuilder\DirectOrder($requestConfiguration); + // Different Merchant code for Recurring Orders + if (!empty($tokenOrderParams['paymentDetails']['isRecurringOrder'])) { + if ($tokenOrderParams['paymentDetails']['isRecurringOrder'] == 1) { + $recurringUserName = $this->worldpayhelper->getRecurringUsername(); + $recurringPassword = $this->worldpayhelper->getRecurringPassword(); + $recurringCode = $this->worldpayhelper->getRecurringMerchantCode(); + + $xmlUsername = !empty($recurringUserName) ? $recurringUserName : $xmlUsername; + $xmlPassword = !empty($recurringPassword) ? $recurringPassword : $xmlPassword; + $merchantCode = !empty($recurringCode) ? $recurringCode : $merchantCode; + } + } + + $this->xmltokenorder = new \Sapient\Worldpay\Model\XmlBuilder\DirectOrder( + $this->customerSession, + $requestConfiguration + ); if (empty($tokenOrderParams['thirdPartyData']) && empty($tokenOrderParams['shippingfee'])) { $tokenOrderParams['thirdPartyData']=''; $tokenOrderParams['shippingfee']=''; @@ -302,6 +463,17 @@ public function orderToken($tokenOrderParams) if (empty($tokenOrderParams['orderLineItems'])) { $tokenOrderParams['orderLineItems'] = ''; } + + if (!empty($tokenOrderParams['isMultishippingOrder'])) { + $msMerchantCode = $this->worldpayhelper->getMultishippingMerchantCode(); + $msMerchantUn = $this->worldpayhelper->getMultishippingMerchantUsername(); + $msMerchantPw = $this->worldpayhelper->getMultishippingMerchantPassword(); + + $xmlUsername = !empty($msMerchantUn) ? $msMerchantUn : $xmlUsername ; + $xmlPassword = !empty($msMerchantPw) ? $msMerchantPw : $xmlPassword ; + $merchantCode = !empty($msMerchantCode) ? $msMerchantCode : $merchantCode ; + } + $captureDelay = $this->worldpayhelper->getCaptureDelayValues(); $orderSimpleXml = $this->xmltokenorder->build( $merchantCode, $tokenOrderParams['orderCode'], @@ -325,7 +497,8 @@ public function orderToken($tokenOrderParams) $tokenOrderParams['shippingfee'], $tokenOrderParams['exponent'], $tokenOrderParams['primeRoutingData'], - $tokenOrderParams['orderLineItems'] + $tokenOrderParams['orderLineItems'], + $captureDelay ); return $this->_sendRequest( dom_import_simplexml($orderSimpleXml)->ownerDocument, @@ -367,6 +540,7 @@ public function redirectOrder($redirectOrderParams) $xmlUsername = $this->worldpayhelper->getXmlUsername($redirectOrderParams['paymentDetails']['cardType']); $xmlPassword = $this->worldpayhelper->getXmlPassword($redirectOrderParams['paymentDetails']['cardType']); $merchantCode = $redirectOrderParams['merchantCode']; + $installationId = $redirectOrderParams['installationId']; if ($redirectOrderParams['method'] == 'worldpay_moto') { $redirectOrderParams['paymentDetails']['PaymentMethod'] = $redirectOrderParams['method']; @@ -377,8 +551,35 @@ public function redirectOrder($redirectOrderParams) $merchantCode = !empty($this->worldpayhelper->getMotoMerchantCode()) ? $this->worldpayhelper->getMotoMerchantCode() : $merchantCode; } - + + if (!empty($redirectOrderParams['isMultishippingOrder'])) { + $msMerchantCode = $this->worldpayhelper->getMultishippingMerchantCode(); + $msMerchantUn = $this->worldpayhelper->getMultishippingMerchantUsername(); + $msMerchantPw = $this->worldpayhelper->getMultishippingMerchantPassword(); + $msInstallationId = $this->worldpayhelper->getMultishippingInstallationId(); + $xmlUsername = !empty($msMerchantUn) ? $msMerchantUn : $xmlUsername ; + $xmlPassword = !empty($msMerchantPw) ? $msMerchantPw : $xmlPassword ; + $merchantCode = !empty($msMerchantCode) ? $msMerchantCode : $merchantCode ; + $installationId = !empty($msInstallationId) ? $msInstallationId : $installationId ; + } + if (!empty($redirectOrderParams['is_paybylink_order'])) { + $pblMerchantUn = $this->worldpayhelper->getPayByLinkMerchantUsername(); + $pblMerchantPw = $this->worldpayhelper->getPayByLinkMerchantPassword(); + $pblMerchantCode = $this->worldpayhelper->getPayByLinkMerchantCode(); + $pblInstallationId = $this->worldpayhelper->getPayByLinkInstallationId(); + $xmlUsername = !empty($pblMerchantUn) ? $pblMerchantUn : $xmlUsername ; + $xmlPassword = !empty($pblMerchantPw) ? $pblMerchantPw : $xmlPassword ; + $merchantCode = !empty($pblMerchantCode) ? $pblMerchantCode : $merchantCode ; + $installationId = !empty($pblInstallationId) ? $pblInstallationId : $installationId ; + } $this->xmlredirectorder = new \Sapient\Worldpay\Model\XmlBuilder\RedirectOrder($requestConfiguration); + + if (!empty($redirectOrderParams['is_paybylink_order'])) { + $this->xmlredirectorder = new \Sapient\Worldpay\Model\XmlBuilder\RedirectPayByLinkOrder( + $requestConfiguration + ); + } + if (empty($redirectOrderParams['thirdPartyData']) && empty($redirectOrderParams['shippingfee'])) { $redirectOrderParams['thirdPartyData']=''; $redirectOrderParams['shippingfee']=''; @@ -396,7 +597,7 @@ public function redirectOrder($redirectOrderParams) if (empty($redirectOrderParams['storedCredentialsEnabled'])) { $redirectOrderParams['storedCredentialsEnabled']=''; } - + $captureDelay = $this->worldpayhelper->getCaptureDelayValues(); $redirectSimpleXml = $this->xmlredirectorder->build( $merchantCode, $redirectOrderParams['orderCode'], @@ -411,7 +612,7 @@ public function redirectOrder($redirectOrderParams) $redirectOrderParams['shippingAddress'], $redirectOrderParams['billingAddress'], $redirectOrderParams['paymentPagesEnabled'], - $redirectOrderParams['installationId'], + $installationId, $redirectOrderParams['hideAddress'], $redirectOrderParams['paymentDetails'], $redirectOrderParams['thirdPartyData'], @@ -419,13 +620,15 @@ public function redirectOrder($redirectOrderParams) $redirectOrderParams['exponent'], $redirectOrderParams['cusDetails'], $redirectOrderParams['orderLineItems'], + $captureDelay, $redirectOrderParams['saveCardEnabled'], - $redirectOrderParams['storedCredentialsEnabled'], + $redirectOrderParams['storedCredentialsEnabled'] ); return $this->_sendRequest( dom_import_simplexml($redirectSimpleXml)->ownerDocument, $xmlUsername, - $xmlPassword + $xmlPassword, + self::SEND_ADDITIONAL_HEADER ); } @@ -443,9 +646,25 @@ public function redirectKlarnaOrder($redirectOrderParams) if (empty($redirectOrderParams['statementNarrative'])) { $redirectOrderParams['statementNarrative']=''; } + $xmlUsername = $this->worldpayhelper->getXmlUsername($redirectOrderParams['paymentType']); + $xmlPassword = $this->worldpayhelper->getXmlPassword($redirectOrderParams['paymentType']); + $merchantCode = $redirectOrderParams['merchantCode']; + $installationId = $redirectOrderParams['installationId']; + if (!empty($redirectOrderParams['isMultishippingOrder'])) { + $msMerchantCode = $this->worldpayhelper->getMultishippingMerchantCode(); + $msMerchantUn = $this->worldpayhelper->getMultishippingMerchantUsername(); + $msMerchantPw = $this->worldpayhelper->getMultishippingMerchantPassword(); + $msinstallationId = $this->worldpayhelper->getMultishippingInstallationId(); + + $xmlUsername = !empty($msMerchantUn) ? $msMerchantUn : $xmlUsername ; + $xmlPassword = !empty($msMerchantPw) ? $msMerchantPw : $xmlPassword ; + $merchantCode = !empty($msMerchantCode) ? $msMerchantCode : $merchantCode ; + $installationId = !empty($msinstallationId) ? $msinstallationId : $installationId ; + } + $captureDelay = $this->worldpayhelper->getCaptureDelayValues(); $this->xmlredirectorder = new \Sapient\Worldpay\Model\XmlBuilder\RedirectKlarnaOrder(); $redirectSimpleXml = $this->xmlredirectorder->build( - $redirectOrderParams['merchantCode'], + $merchantCode, $redirectOrderParams['orderCode'], $redirectOrderParams['orderDescription'], $redirectOrderParams['currencyCode'], @@ -458,18 +677,20 @@ public function redirectKlarnaOrder($redirectOrderParams) $redirectOrderParams['shippingAddress'], $redirectOrderParams['billingAddress'], $redirectOrderParams['paymentPagesEnabled'], - $redirectOrderParams['installationId'], + $installationId, $redirectOrderParams['hideAddress'], $redirectOrderParams['orderLineItems'], $redirectOrderParams['exponent'], $redirectOrderParams['sessionData'], - $redirectOrderParams['orderContent'] + $redirectOrderParams['orderContent'], + $captureDelay ); return $this->_sendRequest( dom_import_simplexml($redirectSimpleXml)->ownerDocument, - $this->worldpayhelper->getXmlUsername($redirectOrderParams['paymentType']), - $this->worldpayhelper->getXmlPassword($redirectOrderParams['paymentType']) + $xmlUsername, + $xmlPassword, + self::SEND_ADDITIONAL_HEADER ); } catch (Exception $ex) { $this->_wplogger->error($ex->getMessage()); @@ -505,9 +726,26 @@ public function directIdealOrder($redirectOrderParams) if (empty($redirectOrderParams['statementNarrative'])) { $redirectOrderParams['statementNarrative']=''; } + + $xmlUsername = $this->worldpayhelper->getXmlUsername($redirectOrderParams['paymentType']); + $xmlPassword = $this->worldpayhelper->getXmlPassword($redirectOrderParams['paymentType']); + $merchantCode = $redirectOrderParams['merchantCode']; + $installationId = $redirectOrderParams['installationId']; + if (!empty($redirectOrderParams['isMultishippingOrder'])) { + $msMerchantCode = $this->worldpayhelper->getMultishippingMerchantCode(); + $msMerchantUn = $this->worldpayhelper->getMultishippingMerchantUsername(); + $msMerchantPw = $this->worldpayhelper->getMultishippingMerchantPassword(); + $msMerchantInstallationId = $this->worldpayhelper->getMultishippingInstallationId(); + + $xmlUsername = !empty($msMerchantUn) ? $msMerchantUn : $xmlUsername ; + $xmlPassword = !empty($msMerchantPw) ? $msMerchantPw : $xmlPassword ; + $merchantCode = !empty($msMerchantCode) ? $msMerchantCode : $merchantCode ; + $installationId = !empty($msMerchantInstallationId) ? $msMerchantInstallationId : $installationId ; + } + $captureDelay = $this->worldpayhelper->getCaptureDelayValues(); $this->xmldirectidealorder = new \Sapient\Worldpay\Model\XmlBuilder\DirectIdealOrder($requestConfiguration); $redirectSimpleXml = $this->xmldirectidealorder->build( - $redirectOrderParams['merchantCode'], + $merchantCode, $redirectOrderParams['orderCode'], $redirectOrderParams['orderDescription'], $redirectOrderParams['currencyCode'], @@ -520,17 +758,18 @@ public function directIdealOrder($redirectOrderParams) $redirectOrderParams['shippingAddress'], $redirectOrderParams['billingAddress'], $redirectOrderParams['paymentPagesEnabled'], - $redirectOrderParams['installationId'], + $installationId, $redirectOrderParams['hideAddress'], $redirectOrderParams['callbackurl'], $redirectOrderParams['cc_bank'], - $redirectOrderParams['exponent'] + $redirectOrderParams['exponent'], + $captureDelay ); return $this->_sendRequest( dom_import_simplexml($redirectSimpleXml)->ownerDocument, - $this->worldpayhelper->getXmlUsername($redirectOrderParams['paymentType']), - $this->worldpayhelper->getXmlPassword($redirectOrderParams['paymentType']) + $xmlUsername, + $xmlPassword ); } @@ -549,7 +788,10 @@ public function capture(\Magento\Sales\Model\Order $order, $wp, $paymentMethodCo $orderCode = $wp->getWorldpayOrderId(); $loggerMsg = '########## Submitting capture request. Order: '; $this->_wplogger->info($loggerMsg . $orderCode . ' Amount:' . $order->getGrandTotal() . ' ##########'); - $this->xmlcapture = new \Sapient\Worldpay\Model\XmlBuilder\Capture(); + $this->xmlcapture = new \Sapient\Worldpay\Model\XmlBuilder\Capture( + $this->scopeConfig, + $this->storeManager + ); $currencyCode = $order->getOrderCurrencyCode(); $exponent = $this->worldpayhelper->getCurrencyExponent($currencyCode); @@ -573,6 +815,25 @@ public function capture(\Magento\Sales\Model\Order $order, $wp, $paymentMethodCo ? $this->worldpayhelper->getMotoMerchantCode() : $merchantCode; } + if ($wp->getIsMultishippingOrder()) { + $msMerchantCode = $this->worldpayhelper->getMultishippingMerchantCode(); + $msMerchantUn = $this->worldpayhelper->getMultishippingMerchantUsername(); + $msMerchantPw = $this->worldpayhelper->getMultishippingMerchantPassword(); + + $xmlUsername = !empty($msMerchantUn) ? $msMerchantUn : $xmlUsername ; + $xmlPassword = !empty($msMerchantPw) ? $msMerchantPw : $xmlPassword ; + $merchantCode = !empty($msMerchantCode) ? $msMerchantCode : $merchantCode ; + } + if ($paymentMethodCode == 'worldpay_paybylink') { + + $pblMerchantCode = $this->worldpayhelper->getPayByLinkMerchantCode(); + $pblMerchantUn = $this->worldpayhelper->getPayByLinkMerchantUsername(); + $pblMerchantPw = $this->worldpayhelper->getPayByLinkMerchantPassword(); + $merchantCode = !empty($pblMerchantCode) ? $pblMerchantCode : $merchantCode; + $xmlUsername = !empty($pblMerchantUn) ? $pblMerchantUn : $xmlUsername; + $xmlPassword = !empty($pblMerchantPw) ? $pblMerchantPw : $xmlPassword; + } + $captureSimpleXml = $this->xmlcapture->build( $merchantCode, $orderCode, @@ -589,7 +850,8 @@ public function capture(\Magento\Sales\Model\Order $order, $wp, $paymentMethodCo return $this->_sendRequest( dom_import_simplexml($captureSimpleXml)->ownerDocument, $xmlUsername, - $xmlPassword + $xmlPassword, + self::SEND_ADDITIONAL_HEADER ); } catch (Exception $e) { $this->_wplogger->error($e->getMessage()); @@ -606,15 +868,19 @@ public function capture(\Magento\Sales\Model\Order $order, $wp, $paymentMethodCo * @param \Magento\Framework\DataObject $wp * @param float $grandTotal * @param array|null $capturedItems + * @param string|null $paymentMethodCode * @return mixed */ - public function partialCapture(\Magento\Sales\Model\Order $order, $wp, $grandTotal, $capturedItems = null) + public function partialCapture(\Magento\Sales\Model\Order $order, $wp, $grandTotal, $capturedItems = null, $paymentMethodCode = null) { try { $orderCode = $wp->getWorldpayOrderId(); $loggerMsg = '########## Submitting Partial capture request. Order: '; $this->_wplogger->info($loggerMsg . $orderCode . ' Amount:' . $grandTotal . ' ##########'); - $this->xmlcapture = new \Sapient\Worldpay\Model\XmlBuilder\Capture(); + $this->xmlcapture = new \Sapient\Worldpay\Model\XmlBuilder\Capture( + $this->scopeConfig, + $this->storeManager + ); $currencyCode = $order->getOrderCurrencyCode(); $exponent = $this->worldpayhelper->getCurrencyExponent($currencyCode); @@ -638,7 +904,23 @@ public function partialCapture(\Magento\Sales\Model\Order $order, $wp, $grandTot $merchantCode = !empty($this->worldpayhelper->getMotoMerchantCode()) ? $this->worldpayhelper->getMotoMerchantCode() : $merchantCode; } - + if ($wp->getIsMultishippingOrder()) { + $msMerchantCode = $this->worldpayhelper->getMultishippingMerchantCode(); + $msMerchantUn = $this->worldpayhelper->getMultishippingMerchantUsername(); + $msMerchantPw = $this->worldpayhelper->getMultishippingMerchantPassword(); + + $xmlUsername = !empty($msMerchantUn) ? $msMerchantUn : $xmlUsername ; + $xmlPassword = !empty($msMerchantPw) ? $msMerchantPw : $xmlPassword ; + $merchantCode = !empty($msMerchantCode) ? $msMerchantCode : $merchantCode ; + } + if ($paymentMethodCode == 'worldpay_paybylink') { + $pblMerchantCode = $this->worldpayhelper->getPayByLinkMerchantCode(); + $pblMerchantUn = $this->worldpayhelper->getPayByLinkMerchantUsername(); + $pblMerchantPw = $this->worldpayhelper->getPayByLinkMerchantPassword(); + $merchantCode = !empty($pblMerchantCode) ? $pblMerchantCode : $merchantCode; + $xmlUsername = !empty($pblMerchantUn) ? $pblMerchantUn : $xmlUsername; + $xmlPassword = !empty($pblMerchantPw) ? $pblMerchantPw : $xmlPassword; + } $captureSimpleXml = $this->xmlcapture->build( $merchantCode, $orderCode, @@ -655,7 +937,8 @@ public function partialCapture(\Magento\Sales\Model\Order $order, $wp, $grandTot return $this->_sendRequest( dom_import_simplexml($captureSimpleXml)->ownerDocument, $xmlUsername, - $xmlPassword + $xmlPassword, + self::SEND_ADDITIONAL_HEADER ); } catch (Exception $e) { $this->_wplogger->error($e->getMessage()); @@ -671,11 +954,12 @@ public function partialCapture(\Magento\Sales\Model\Order $order, $wp, $grandTot * @param SimpleXmlElement $xml * @param string $username * @param string $password + * @param bool $additionalHeader * @return SimpleXmlElement $response */ - protected function _sendRequest($xml, $username, $password) + protected function _sendRequest($xml, $username, $password, $additionalHeader = false) { - $response = $this->_request->sendRequest($xml, $username, $password); + $response = $this->_request->sendRequest($xml, $username, $password, $additionalHeader); $this->_checkForError($response, $xml); return $response; } @@ -735,7 +1019,9 @@ public function refund( $orderCode = $wp->getWorldpayOrderId(); $loggerMsg = '########## Submitting refund request. OrderCode: '; $this->_wplogger->info($loggerMsg . $orderCode . ' ##########'); - $this->xmlrefund = new \Sapient\Worldpay\Model\XmlBuilder\Refund(); + $this->xmlrefund = new \Sapient\Worldpay\Model\XmlBuilder\Refund( + $this->scopeConfig + ); $currencyCode = $order->getOrderCurrencyCode(); $exponent = $this->worldpayhelper->getCurrencyExponent($currencyCode); @@ -750,6 +1036,23 @@ public function refund( $merchantCode = !empty($this->worldpayhelper->getMotoMerchantCode()) ? $this->worldpayhelper->getMotoMerchantCode() : $merchantCode; } + if ($wp->getIsMultishippingOrder()) { + $msMerchantCode = $this->worldpayhelper->getMultishippingMerchantCode(); + $msMerchantUn = $this->worldpayhelper->getMultishippingMerchantUsername(); + $msMerchantPw = $this->worldpayhelper->getMultishippingMerchantPassword(); + + $xmlUsername = !empty($msMerchantUn) ? $msMerchantUn : $xmlUsername ; + $xmlPassword = !empty($msMerchantPw) ? $msMerchantPw : $xmlPassword ; + $merchantCode = !empty($msMerchantCode) ? $msMerchantCode : $merchantCode ; + } + if ($paymentMethodCode == 'worldpay_paybylink') { + $pblMerchantCode = $this->worldpayhelper->getPayByLinkMerchantCode(); + $pblMerchantUn = $this->worldpayhelper->getPayByLinkMerchantUsername(); + $pblMerchantPw = $this->worldpayhelper->getPayByLinkMerchantPassword(); + $merchantCode = !empty($pblMerchantCode) ? $pblMerchantCode : $merchantCode; + $xmlUsername = !empty($pblMerchantUn) ? $pblMerchantUn : $xmlUsername; + $xmlPassword = !empty($pblMerchantPw) ? $pblMerchantPw : $xmlPassword; + } $refundSimpleXml = $this->xmlrefund->build( $merchantCode, @@ -765,7 +1068,8 @@ public function refund( return $this->_sendRequest( dom_import_simplexml($refundSimpleXml)->ownerDocument, $xmlUsername, - $xmlPassword + $xmlPassword, + self::SEND_ADDITIONAL_HEADER ); } @@ -783,7 +1087,7 @@ public function refund( public function inquiry($merchantCode, $orderCode, $storeId, $paymentMethodCode, $paymenttype, $interactionType) { $this->_wplogger->info('########## Submitting order inquiry. OrderCode: (' . $orderCode . ') ##########'); - + $this->_wplogger->info('## Interaction Type'.$interactionType); $xmlUsername = $this->worldpayhelper->getXmlUsername($paymenttype); $xmlPassword = $this->worldpayhelper->getXmlPassword($paymenttype); $merchantcode = $merchantCode; @@ -797,12 +1101,29 @@ public function inquiry($merchantCode, $orderCode, $storeId, $paymentMethodCode, ? $this->worldpayhelper->getMotoMerchantCode() : $merchantcode; } + if ($interactionType == \Sapient\Worldpay\Model\Payment\Service::INTERACTION_TYPE_MS) { + $msMerchantCode = $this->worldpayhelper->getMultishippingMerchantCode(); + $msMerchantUn = $this->worldpayhelper->getMultishippingMerchantUsername(); + $msMerchantPw = $this->worldpayhelper->getMultishippingMerchantPassword(); + + $xmlUsername = !empty($msMerchantUn) ? $msMerchantUn : $xmlUsername ; + $xmlPassword = !empty($msMerchantPw) ? $msMerchantPw : $xmlPassword ; + $merchantcode = !empty($msMerchantCode) ? $msMerchantCode : $merchantcode ; + } + + if ($paymentMethodCode == 'worldpay_paybylink') { + $pblMerchantCode = $this->worldpayhelper->getPayByLinkMerchantCode(); + $pblMerchantUn = $this->worldpayhelper->getPayByLinkMerchantUsername(); + $pblMerchantPw = $this->worldpayhelper->getPayByLinkMerchantPassword(); + $merchantCode = !empty($pblMerchantCode) ? $pblMerchantCode : $merchantCode; + $xmlUsername = !empty($pblMerchantUn) ? $pblMerchantUn : $xmlUsername; + $xmlPassword = !empty($pblMerchantPw) ? $pblMerchantPw : $xmlPassword; + } $this->xmlinquiry = new \Sapient\Worldpay\Model\XmlBuilder\Inquiry(); $inquirySimpleXml = $this->xmlinquiry->build( $merchantcode, $orderCode ); - return $this->_sendRequest( dom_import_simplexml($inquirySimpleXml)->ownerDocument, $xmlUsername, @@ -875,9 +1196,10 @@ public function tokenDelete( * Get Payment options based on country * * @param array $paymentOptionsParams + * @param boolean $isMultishipping * @return mixed */ - public function paymentOptionsByCountry($paymentOptionsParams) + public function paymentOptionsByCountry($paymentOptionsParams, $isMultishipping = false) { $spoofCountryId = ''; $countryCodeSpoofs = $this->worldpayhelper->getCountryCodeSpoofs(); @@ -891,11 +1213,18 @@ public function paymentOptionsByCountry($paymentOptionsParams) $paymentOptionsParams['merchantCode'], $countryId ); - + $merchantUn = $this->worldpayhelper->getXmlUsername($paymentOptionsParams['paymentType']); + $merchantPw = $this->worldpayhelper->getXmlPassword($paymentOptionsParams['paymentType']); + if ($isMultishipping) { + $msMerchantUn = $this->worldpayhelper->getMultishippingMerchantUsername(); + $mcMerchantPw = $this->worldpayhelper->getMultishippingMerchantPassword(); + $merchantUn = !empty($msMerchantUn) ? $msMerchantUn : $merchantUn; + $merchantPw = !empty($mcMerchantPw) ? $mcMerchantPw : $merchantPw; + } return $this->_sendRequest( dom_import_simplexml($paymentOptionsXml)->ownerDocument, - $this->worldpayhelper->getXmlUsername($paymentOptionsParams['paymentType']), - $this->worldpayhelper->getXmlPassword($paymentOptionsParams['paymentType']) + $merchantUn, + $merchantPw ); } @@ -913,9 +1242,23 @@ public function walletsOrder($walletOrderParams) $requestConfiguration = [ 'threeDSecureConfig' => $walletOrderParams['threeDSecureConfig'], ]; + $xmlUsername = $this->worldpayhelper->getXmlUsername($walletOrderParams['paymentType']); + $xmlPassword = $this->worldpayhelper->getXmlPassword($walletOrderParams['paymentType']); + $merchantCode = $walletOrderParams['merchantCode']; + + if (!empty($walletOrderParams['isMultishippingOrder'])) { + $msMerchantCode = $this->worldpayhelper->getMultishippingMerchantCode(); + $msMerchantUn = $this->worldpayhelper->getMultishippingMerchantUsername(); + $msMerchantPw = $this->worldpayhelper->getMultishippingMerchantPassword(); + + $xmlUsername = !empty($msMerchantUn) ? $msMerchantUn : $xmlUsername ; + $xmlPassword = !empty($msMerchantPw) ? $msMerchantPw : $xmlPassword ; + $merchantCode = !empty($msMerchantCode) ? $msMerchantCode : $merchantCode ; + } + $captureDelay = $this->worldpayhelper->getCaptureDelayValues(); $this->xmlredirectorder = new \Sapient\Worldpay\Model\XmlBuilder\WalletOrder($requestConfiguration); $walletSimpleXml = $this->xmlredirectorder->build( - $walletOrderParams['merchantCode'], + $merchantCode, $walletOrderParams['orderCode'], $walletOrderParams['orderDescription'], $walletOrderParams['currencyCode'], @@ -932,13 +1275,15 @@ public function walletsOrder($walletOrderParams) $walletOrderParams['cusDetails'], $walletOrderParams['shopperIpAddress'], $walletOrderParams['paymentDetails'], - $walletOrderParams['exponent'] + $walletOrderParams['exponent'], + $captureDelay ); return $this->_sendRequest( dom_import_simplexml($walletSimpleXml)->ownerDocument, - $this->worldpayhelper->getXmlUsername($walletOrderParams['paymentType']), - $this->worldpayhelper->getXmlPassword($walletOrderParams['paymentType']) + $xmlUsername, + $xmlPassword, + self::SEND_ADDITIONAL_HEADER ); } @@ -955,8 +1300,22 @@ public function applePayOrder($applePayOrderParams) $this->xmlredirectorder = new \Sapient\Worldpay\Model\XmlBuilder\ApplePayOrder(); + $xmlUsername = $this->worldpayhelper->getXmlUsername($applePayOrderParams['paymentType']); + $xmlPassword = $this->worldpayhelper->getXmlPassword($applePayOrderParams['paymentType']); + $merchantCode = $applePayOrderParams['merchantCode']; + + if (!empty($applePayOrderParams['isMultishippingOrder'])) { + $msMerchantCode = $this->worldpayhelper->getMultishippingMerchantCode(); + $msMerchantUn = $this->worldpayhelper->getMultishippingMerchantUsername(); + $msMerchantPw = $this->worldpayhelper->getMultishippingMerchantPassword(); + + $xmlUsername = !empty($msMerchantUn) ? $msMerchantUn : $xmlUsername ; + $xmlPassword = !empty($msMerchantPw) ? $msMerchantPw : $xmlPassword ; + $merchantCode = !empty($msMerchantCode) ? $msMerchantCode : $merchantCode ; + } + $captureDelay = $this->worldpayhelper->getCaptureDelayValues(); $appleSimpleXml = $this->xmlredirectorder->build( - $applePayOrderParams['merchantCode'], + $merchantCode, $applePayOrderParams['orderCode'], $applePayOrderParams['orderDescription'], $applePayOrderParams['currencyCode'], @@ -969,13 +1328,15 @@ public function applePayOrder($applePayOrderParams) $applePayOrderParams['ephemeralPublicKey'], $applePayOrderParams['publicKeyHash'], $applePayOrderParams['transactionId'], - $applePayOrderParams['exponent'] + $applePayOrderParams['exponent'], + $captureDelay ); return $this->_sendRequest( dom_import_simplexml($appleSimpleXml)->ownerDocument, - $this->worldpayhelper->getXmlUsername($applePayOrderParams['paymentType']), - $this->worldpayhelper->getXmlPassword($applePayOrderParams['paymentType']) + $xmlUsername, + $xmlPassword, + self::SEND_ADDITIONAL_HEADER ); } @@ -990,10 +1351,24 @@ public function samsungPayOrder($samsungPayOrderParams) $loggerMsg = '########## Submitting samsung pay order request. OrderCode: '; $this->_wplogger->info($loggerMsg . $samsungPayOrderParams['orderCode'] . ' ##########'); + $xmlUsername = $this->worldpayhelper->getXmlUsername($samsungPayOrderParams['paymentType']); + $xmlPassword = $this->worldpayhelper->getXmlPassword($samsungPayOrderParams['paymentType']); + $merchantCode = $samsungPayOrderParams['merchantCode']; + $captureDelay = $this->worldpayhelper->getCaptureDelayValues(); + if (!empty($samsungPayOrderParams['isMultishippingOrder'])) { + $msMerchantCode = $this->worldpayhelper->getMultishippingMerchantCode(); + $msMerchantUn = $this->worldpayhelper->getMultishippingMerchantUsername(); + $msMerchantPw = $this->worldpayhelper->getMultishippingMerchantPassword(); + + $xmlUsername = !empty($msMerchantUn) ? $msMerchantUn : $xmlUsername ; + $xmlPassword = !empty($msMerchantPw) ? $msMerchantPw : $xmlPassword ; + $merchantCode = !empty($msMerchantCode) ? $msMerchantCode : $merchantCode ; + } + $this->xmlredirectorder = new \Sapient\Worldpay\Model\XmlBuilder\SamsungPayOrder(); $appleSimpleXml = $this->xmlredirectorder->build( - $samsungPayOrderParams['merchantCode'], + $merchantCode, $samsungPayOrderParams['orderCode'], $samsungPayOrderParams['orderDescription'], $samsungPayOrderParams['currencyCode'], @@ -1001,13 +1376,15 @@ public function samsungPayOrder($samsungPayOrderParams) $samsungPayOrderParams['paymentType'], $samsungPayOrderParams['shopperEmail'], $samsungPayOrderParams['data'], - $samsungPayOrderParams['exponent'] + $samsungPayOrderParams['exponent'], + $captureDelay ); return $response = $this->_sendRequest( dom_import_simplexml($appleSimpleXml)->ownerDocument, - $this->worldpayhelper->getXmlUsername($samsungPayOrderParams['paymentType']), - $this->worldpayhelper->getXmlPassword($samsungPayOrderParams['paymentType']) + $xmlUsername, + $xmlPassword, + self::SEND_ADDITIONAL_HEADER, ); } @@ -1022,6 +1399,7 @@ public function chromepayOrder($chromeOrderParams) $loggerMsg = '########## Submitting chromepay order request. OrderCode: '; $this->_wplogger->info($loggerMsg . $chromeOrderParams['orderCode'] . ' ##########'); $paymentType = 'worldpay_cc'; + $captureDelay = $this->worldpayhelper->getCaptureDelayValues(); $this->xmlredirectorder = new \Sapient\Worldpay\Model\XmlBuilder\ChromePayOrder(); $chromepaySimpleXml = $this->xmlredirectorder->build( $chromeOrderParams['merchantCode'], @@ -1034,13 +1412,15 @@ public function chromepayOrder($chromeOrderParams) $chromeOrderParams['shippingAddress'], $chromeOrderParams['billingAddress'], $chromeOrderParams['shopperEmail'], - $chromeOrderParams['exponent'] + $chromeOrderParams['exponent'], + $captureDelay ); //echo $this->worldpayhelper->getXmlUsername($paymentType);exit; return $this->_sendRequest( dom_import_simplexml($chromepaySimpleXml)->ownerDocument, $this->worldpayhelper->getXmlUsername($paymentType), - $this->worldpayhelper->getXmlPassword($paymentType) + $this->worldpayhelper->getXmlPassword($paymentType), + self::SEND_ADDITIONAL_HEADER ); } @@ -1054,16 +1434,26 @@ public function order3Ds2Secure($directOrderParams) { $loggerMsg = '########## Submitting direct 3Ds2Secure order request. OrderCode: '; $this->_wplogger->info($loggerMsg . ' ##########'); + $merchantCode = $directOrderParams['merchantCode']; + + if (!empty($directOrderParams['isMultishippingOrder'])) { + $msMerchantCode = $this->worldpayhelper->getMultishippingMerchantCode(); + $merchantCode = !empty($msMerchantCode) ? $msMerchantCode : $merchantCode ; + } + if (isset($directOrderParams['tokenRequestConfig'])) { $requestConfiguration = [ 'threeDSecureConfig' => $directOrderParams['threeDSecureConfig'], 'tokenRequestConfig' => $directOrderParams['tokenRequestConfig'] ]; - $this->xmldirectorder = new \Sapient\Worldpay\Model\XmlBuilder\DirectOrder($requestConfiguration); + $this->xmldirectorder = new \Sapient\Worldpay\Model\XmlBuilder\DirectOrder( + $this->customerSession, + $requestConfiguration + ); $paymentType = isset($directOrderParams['paymentDetails']['brand']) ? $directOrderParams['paymentDetails']['brand']: $directOrderParams['paymentDetails']['paymentType']; $orderSimpleXml = $this->xmldirectorder->build3Ds2Secure( - $directOrderParams['merchantCode'], + $merchantCode, $directOrderParams['orderCode'], $directOrderParams['paymentDetails'], $directOrderParams['paymentDetails']['dfReferenceId'] @@ -1075,16 +1465,26 @@ public function order3Ds2Secure($directOrderParams) $this->xmldirectorder = new \Sapient\Worldpay\Model\XmlBuilder\WalletOrder($requestConfiguration); $paymentType = $directOrderParams['paymentType']; $orderSimpleXml = $this->xmldirectorder->build3Ds2Secure( - $directOrderParams['merchantCode'], + $merchantCode, $directOrderParams['orderCode'], $directOrderParams['paymentDetails'], $directOrderParams['paymentDetails']['dfReferenceId'] ); } + $xmlUsername = $this->worldpayhelper->getXmlUsername($paymentType); + $xmlPassword = $this->worldpayhelper->getXmlPassword($paymentType); + if (!empty($directOrderParams['isMultishippingOrder'])) { + $msMerchantUn = $this->worldpayhelper->getMultishippingMerchantUsername(); + $msMerchantPw = $this->worldpayhelper->getMultishippingMerchantPassword(); + + $xmlUsername = !empty($msMerchantUn) ? $msMerchantUn : $xmlUsername ; + $xmlPassword = !empty($msMerchantPw) ? $msMerchantPw : $xmlPassword ; + } + return $this->_sendRequest( dom_import_simplexml($orderSimpleXml)->ownerDocument, - $this->worldpayhelper->getXmlUsername($paymentType), - $this->worldpayhelper->getXmlPassword($paymentType) + $xmlUsername, + $xmlPassword ); } @@ -1177,6 +1577,23 @@ public function voidSale(\Magento\Sales\Model\Order $order, $wp, $paymentMethodC $merchantCode = !empty($this->worldpayhelper->getMotoMerchantCode()) ? $this->worldpayhelper->getMotoMerchantCode() : $merchantCode; } + if ($wp->getIsMultishippingOrder()) { + $msMerchantCode = $this->worldpayhelper->getMultishippingMerchantCode(); + $msMerchantUn = $this->worldpayhelper->getMultishippingMerchantUsername(); + $msMerchantPw = $this->worldpayhelper->getMultishippingMerchantPassword(); + + $xmlUsername = !empty($msMerchantUn) ? $msMerchantUn : $xmlUsername ; + $xmlPassword = !empty($msMerchantPw) ? $msMerchantPw : $xmlPassword ; + $merchantCode = !empty($msMerchantCode) ? $msMerchantCode : $merchantCode ; + } + if ($paymentMethodCode == 'worldpay_paybylink') { + $pblMerchantCode = $this->worldpayhelper->getPayByLinkMerchantCode(); + $pblMerchantUn = $this->worldpayhelper->getPayByLinkMerchantUsername(); + $pblMerchantPw = $this->worldpayhelper->getPayByLinkMerchantPassword(); + $merchantCode = !empty($pblMerchantCode) ? $pblMerchantCode : $merchantCode; + $xmlUsername = !empty($pblMerchantUn) ? $pblMerchantUn : $xmlUsername; + $xmlPassword = !empty($pblMerchantPw) ? $pblMerchantPw : $xmlPassword; + } $voidSaleSimpleXml = $this->xmlvoidsale->build( $merchantCode, @@ -1222,7 +1639,23 @@ public function cancelOrder(\Magento\Sales\Model\Order $order, $wp, $paymentMeth $merchantCode = !empty($this->worldpayhelper->getMotoMerchantCode()) ? $this->worldpayhelper->getMotoMerchantCode() : $merchantCode; } - + if ($wp->getIsMultishippingOrder()) { + $msMerchantCode = $this->worldpayhelper->getMultishippingMerchantCode(); + $msMerchantUn = $this->worldpayhelper->getMultishippingMerchantUsername(); + $msMerchantPw = $this->worldpayhelper->getMultishippingMerchantPassword(); + + $xmlUsername = !empty($msMerchantUn) ? $msMerchantUn : $xmlUsername ; + $xmlPassword = !empty($msMerchantPw) ? $msMerchantPw : $xmlPassword ; + $merchantCode = !empty($msMerchantCode) ? $msMerchantCode : $merchantCode ; + } + if ($paymentMethodCode == 'worldpay_paybylink') { + $pblMerchantCode = $this->worldpayhelper->getPayByLinkMerchantCode(); + $pblMerchantUn = $this->worldpayhelper->getPayByLinkMerchantUsername(); + $pblMerchantPw = $this->worldpayhelper->getPayByLinkMerchantPassword(); + $merchantCode = !empty($pblMerchantCode) ? $pblMerchantCode : $merchantCode; + $xmlUsername = !empty($pblMerchantUn) ? $pblMerchantUn : $xmlUsername; + $xmlPassword = !empty($pblMerchantPw) ? $pblMerchantPw : $xmlPassword; + } $cancelSimpleXml = $this->xmlcancel->build( $merchantCode, $orderCode, @@ -1236,7 +1669,8 @@ public function cancelOrder(\Magento\Sales\Model\Order $order, $wp, $paymentMeth return $this->_sendRequest( dom_import_simplexml($cancelSimpleXml)->ownerDocument, $xmlUsername, - $xmlPassword + $xmlPassword, + self::SEND_ADDITIONAL_HEADER ); } diff --git a/Model/ResourceModel/Multishipping/Order/Collection.php b/Model/ResourceModel/Multishipping/Order/Collection.php index 552ec631..3c91197f 100644 --- a/Model/ResourceModel/Multishipping/Order/Collection.php +++ b/Model/ResourceModel/Multishipping/Order/Collection.php @@ -86,4 +86,23 @@ public function getOriginalOrderId($order_id) ->addFieldToFilter('order_id', ['eq' => $order_id]); return $collection->getFirstItem(); } + + /** + * Fetch Multishipping Order ids + * + * @param int $quoteId + * @return array + */ + public function getMultishippingOrderIds($quoteId) + { + $connection = $this->getConnection(); + $select = $connection->select()->from( + ['wms' => $this->getTable('worldpay_multishipping')], + ['order_id'] + )->where( + 'wms.quote_id = :quote_id' + ); + + return $connection->fetchAll($select, [':quote_id' => $quoteId]); + } } diff --git a/Model/Response/RedirectResponse.php b/Model/Response/RedirectResponse.php index 77e304be..ace32d53 100644 --- a/Model/Response/RedirectResponse.php +++ b/Model/Response/RedirectResponse.php @@ -9,6 +9,11 @@ */ class RedirectResponse extends \Sapient\Worldpay\Model\Response\ResponseAbstract { + + /** + * @var \Magento\Framework\UrlInterface + */ + public $_urlBuilder; /** * Constructor * diff --git a/Model/Response/ResponseAbstract.php b/Model/Response/ResponseAbstract.php index 14e86a1c..b41ad4f6 100644 --- a/Model/Response/ResponseAbstract.php +++ b/Model/Response/ResponseAbstract.php @@ -19,7 +19,7 @@ abstract class ResponseAbstract public const PAYMENT_DETAILS_ERROR = 7; /** - * @var SimpleXmlElement + * @var \SimpleXmlElement */ protected $_responseXml; /** diff --git a/Model/SavedToken.php b/Model/SavedToken.php index 0562c681..bc53aa70 100644 --- a/Model/SavedToken.php +++ b/Model/SavedToken.php @@ -25,7 +25,7 @@ protected function _construct() * Load worldpay token Details * * @param string $order_id - * @return Sapient\Worldpay\Model\SavedToken + * @return \Sapient\Worldpay\Model\SavedToken */ public function loadByTokenCode($order_id) { diff --git a/Model/System/Config/Backend/AdminLabels.php b/Model/System/Config/Backend/AdminLabels.php index 1955cef4..d0eabe5a 100644 --- a/Model/System/Config/Backend/AdminLabels.php +++ b/Model/System/Config/Backend/AdminLabels.php @@ -27,6 +27,12 @@ class AdminLabels extends \Magento\Framework\App\Config\Value */ private $storeManager; + /** + * + * @var \Sapient\Worldpay\Helper\AdminLabels + */ + private $adminLabels; + /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry diff --git a/Model/System/Config/Backend/CheckoutLabels.php b/Model/System/Config/Backend/CheckoutLabels.php index 7e242908..1f97fea7 100644 --- a/Model/System/Config/Backend/CheckoutLabels.php +++ b/Model/System/Config/Backend/CheckoutLabels.php @@ -26,6 +26,11 @@ class CheckoutLabels extends \Magento\Framework\App\Config\Value * @var \Magento\Store\Model\StoreManagerInterface */ private $storeManager; + /** + * + * @var \Sapient\Worldpay\Helper\CheckoutLabels + */ + private $checkoutLabels; /** * @param \Magento\Framework\Model\Context $context diff --git a/Model/System/Config/Backend/CreditCardException.php b/Model/System/Config/Backend/CreditCardException.php index 3022f904..a1a478bb 100644 --- a/Model/System/Config/Backend/CreditCardException.php +++ b/Model/System/Config/Backend/CreditCardException.php @@ -24,6 +24,12 @@ class CreditCardException extends \Magento\Framework\App\Config\Value * @var \Magento\Store\Model\StoreManagerInterface */ private $storeManager; + /** + * Store manager interface + * + * @var \Sapient\Worldpay\Helper\CreditCardException + */ + private $creditcardexception; /** * @param \Magento\Framework\Model\Context $context diff --git a/Model/System/Config/Backend/CurrencyExponents.php b/Model/System/Config/Backend/CurrencyExponents.php index b58834fa..269de406 100644 --- a/Model/System/Config/Backend/CurrencyExponents.php +++ b/Model/System/Config/Backend/CurrencyExponents.php @@ -25,6 +25,12 @@ class CurrencyExponents extends \Magento\Framework\App\Config\Value */ private $storeManager; + /** + * + * @var \Sapient\Worldpay\Helper\Currencyexponents + */ + private $currencyexponent; + /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry diff --git a/Model/System/Config/Backend/CurrentPluginVersion.php b/Model/System/Config/Backend/CurrentPluginVersion.php index 3c9053d3..36f3ae7a 100644 --- a/Model/System/Config/Backend/CurrentPluginVersion.php +++ b/Model/System/Config/Backend/CurrentPluginVersion.php @@ -11,6 +11,24 @@ class CurrentPluginVersion extends \Magento\Framework\App\Config\Value /* Module Name */ public const MODULE_NAME = 'Sapient_Worldpay'; + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + /** + * @var \Magento\Framework\Component\ComponentRegistrarInterface + */ + protected $componentRegistrar; + + /** + * @var \Magento\Framework\Filesystem\Directory\ReadFactory + */ + protected $readFactory; + /** + * @var \Magento\Framework\App\Config\Storage\WriterInterface + */ + protected $configWriter; + /** * Constructor * diff --git a/Model/System/Config/Backend/ExtendedResponseCodes.php b/Model/System/Config/Backend/ExtendedResponseCodes.php index 782e51e3..743ee10c 100644 --- a/Model/System/Config/Backend/ExtendedResponseCodes.php +++ b/Model/System/Config/Backend/ExtendedResponseCodes.php @@ -11,7 +11,10 @@ */ class ExtendedResponseCodes extends \Magento\Framework\App\Config\Value { - + /** + * @var \Sapient\Worldpay\Helper\ExtendedResponseCodes + */ + protected $extendedResponseCodes; /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry diff --git a/Model/System/Config/Backend/GeneralException.php b/Model/System/Config/Backend/GeneralException.php index 75b78ee5..01e305fb 100644 --- a/Model/System/Config/Backend/GeneralException.php +++ b/Model/System/Config/Backend/GeneralException.php @@ -18,6 +18,12 @@ class GeneralException extends \Magento\Framework\App\Config\Value * @var \Magento\Store\Model\StoreManagerInterface */ private $storeManager; + + /** + * + * @var \Sapient\Worldpay\Helper\GeneralException + */ + private $generalexception; /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry diff --git a/Model/System/Config/Backend/Instalmentconfig.php b/Model/System/Config/Backend/Instalmentconfig.php index 42463178..6d11eefb 100644 --- a/Model/System/Config/Backend/Instalmentconfig.php +++ b/Model/System/Config/Backend/Instalmentconfig.php @@ -10,6 +10,12 @@ class Instalmentconfig extends \Magento\Framework\App\Config\Value { + /** + * + * @var \Sapient\Worldpay\Helper\Instalmentconfig + */ + private $instalmentconfig; + /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry diff --git a/Model/System/Config/Backend/KlarnaCountries.php b/Model/System/Config/Backend/KlarnaCountries.php index c213349b..d28c8276 100644 --- a/Model/System/Config/Backend/KlarnaCountries.php +++ b/Model/System/Config/Backend/KlarnaCountries.php @@ -9,7 +9,13 @@ */ class KlarnaCountries extends \Magento\Framework\App\Config\Value { - + + /** + * + * @var \Sapient\Worldpay\Helper\KlarnaCountries + */ + private $klarnaCountries; + /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry diff --git a/Model/System/Config/Backend/Merchantprofile.php b/Model/System/Config/Backend/Merchantprofile.php index a505d8cf..8cd3b310 100644 --- a/Model/System/Config/Backend/Merchantprofile.php +++ b/Model/System/Config/Backend/Merchantprofile.php @@ -9,6 +9,11 @@ */ class Merchantprofile extends \Magento\Framework\App\Config\Value { + /** + * + * @var \Sapient\Worldpay\Helper\Merchantprofile + */ + private $merchantprofile; /** * @param \Magento\Framework\Model\Context $context diff --git a/Model/System/Config/Backend/MyAccountException.php b/Model/System/Config/Backend/MyAccountException.php index 5f963f80..feb71d8d 100644 --- a/Model/System/Config/Backend/MyAccountException.php +++ b/Model/System/Config/Backend/MyAccountException.php @@ -24,6 +24,13 @@ class MyAccountException extends \Magento\Framework\App\Config\Value * @var \Magento\Store\Model\StoreManagerInterface */ private $storeManager; + + /** + * + * @var \Sapient\Worldpay\Helper\MyAccountException + */ + private $myaccountexception; + /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry diff --git a/Model/System/Config/Backend/MyAccountLabels.php b/Model/System/Config/Backend/MyAccountLabels.php index f3c08f03..7eec3fa0 100644 --- a/Model/System/Config/Backend/MyAccountLabels.php +++ b/Model/System/Config/Backend/MyAccountLabels.php @@ -27,6 +27,11 @@ class MyAccountLabels extends \Magento\Framework\App\Config\Value */ private $storeManager; + /** + * + * @var \Sapient\Worldpay\Helper\MyAccountLabels + */ + private $myAccountLabels; /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry diff --git a/Model/System/Config/Backend/PluginUpgradeDates.php b/Model/System/Config/Backend/PluginUpgradeDates.php index 681efb2f..7711158f 100644 --- a/Model/System/Config/Backend/PluginUpgradeDates.php +++ b/Model/System/Config/Backend/PluginUpgradeDates.php @@ -9,6 +9,39 @@ */ class PluginUpgradeDates extends \Magento\Framework\App\Config\Value { + + /** + * + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + private $wplogger; + + /** + * Store manager interface + * + * @var \Magento\Store\Model\StoreManagerInterface + */ + private $storeManager; + + /** + * @var \Magento\Framework\App\Config\ScopeConfigInterface + */ + private $scopeConfig; + + /** + * @var \Magento\Framework\App\Config\Storage\WriterInterface + */ + private $configWriter; + + /** + * @var \Magento\Framework\App\Cache\Manager + */ + private $cacheManager; + + /** + * @var \Sapient\Worldpay\Model\System\Config\Backend\PluginVersionHistory + */ + private $versionhistory; /** * Constructor * diff --git a/Model/System/Config/Backend/PluginVersionHistory.php b/Model/System/Config/Backend/PluginVersionHistory.php index b67d4c52..c4f662bf 100644 --- a/Model/System/Config/Backend/PluginVersionHistory.php +++ b/Model/System/Config/Backend/PluginVersionHistory.php @@ -10,6 +10,30 @@ class PluginVersionHistory extends \Magento\Framework\App\Config\Value { /* Module Name */ public const MODULE_NAME = 'Sapient_Worldpay'; + /** + * + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + private $wplogger; + /** + * @var \Magento\Framework\App\Config\ScopeConfigInterface + */ + private $scopeConfig; + + /** + * @var \Magento\Framework\App\Config\Storage\WriterInterface + */ + private $configWriter; + + /** + * @var \Magento\Framework\App\Cache\Manager + */ + private $cacheManager; + + /** + * @var \Sapient\Worldpay\Model\System\Config\Backend\CurrentPluginVersion + */ + private $currentversionconfig; /** * Constructor diff --git a/Model/Token.php b/Model/Token.php index d6f54da4..5afaa93d 100644 --- a/Model/Token.php +++ b/Model/Token.php @@ -19,6 +19,16 @@ class Token */ protected $_request; + /** + * @var \Sapient\Worldpay\Helper\Data + */ + protected $worldpayhelper; + + /** + * @var \Magento\Framework\Session\SessionManager + */ + protected $_session; + /** * Constructor * diff --git a/Model/Token/Service.php b/Model/Token/Service.php index f720cebe..5c67ef20 100644 --- a/Model/Token/Service.php +++ b/Model/Token/Service.php @@ -13,10 +13,25 @@ class Service { /** - * @var Sapient\WorldPay\Model\Request\PaymentServiceRequest + * @var \Sapient\WorldPay\Model\Request\PaymentServiceRequest */ protected $_paymentServiceRequest; + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $_wplogger; + + /** + * @var \Sapient\Worldpay\Model\Payment\Update\Factory + */ + protected $paymentupdatefactory; + + /** + * @var \Sapient\Worldpay\Model\Worldpayment + */ + protected $worldpayPayment; + /** * Constructor * @@ -40,10 +55,10 @@ public function __construct( /** * Send token update request to WP server and gives back the answer * - * @param Sapient\Worldpay\Model\Token $tokenModel + * @param \Sapient\Worldpay\Model\Token $tokenModel * @param \Magento\Customer\Model\Customer $customer * @param int $storeId - * @return Sapient\Worldpay\Model\Token\UpdateXml + * @return \Sapient\Worldpay\Model\Token\UpdateXml */ public function getTokenUpdate( SavedToken $tokenModel, diff --git a/Model/Token/StateXml.php b/Model/Token/StateXml.php index 9505e909..50b529bb 100644 --- a/Model/Token/StateXml.php +++ b/Model/Token/StateXml.php @@ -10,7 +10,7 @@ class StateXml implements \Sapient\Worldpay\Model\Token\StateInterface { /** - * @var SimpleXMLElement + * @var \SimpleXMLElement */ private $_xml; /** @@ -35,7 +35,7 @@ class StateXml implements \Sapient\Worldpay\Model\Token\StateInterface private $_orderStatusNode; /** - * @param SimpleXMLElement $xml + * @param \SimpleXMLElement $xml */ public function __construct(\SimpleXMLElement $xml) { diff --git a/Model/Token/UpdateXml.php b/Model/Token/UpdateXml.php index 02aaee8c..2924ca09 100644 --- a/Model/Token/UpdateXml.php +++ b/Model/Token/UpdateXml.php @@ -12,12 +12,12 @@ class UpdateXml implements UpdateInterface { /** - * @var SimpleXMLElement + * @var \SimpleXMLElement */ private $_xml; /** - * @param SimpleXMLElement $xml + * @param \SimpleXMLElement $xml */ public function __construct(\SimpleXMLElement $xml) { diff --git a/Model/Token/WorldpayToken.php b/Model/Token/WorldpayToken.php index b90a9312..7213948d 100644 --- a/Model/Token/WorldpayToken.php +++ b/Model/Token/WorldpayToken.php @@ -37,15 +37,39 @@ class WorldpayToken */ private $paymentTokenRepository; /** - * @var Magento\Framework\Serialize\Serializer\Json + * @var \Magento\Framework\Serialize\Serializer\Json */ protected $serializer; + /** + * @var SavedToken + */ + protected $savedtoken; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + + /** + * @var CreditCardTokenFactory + */ + protected $paymentTokenFactory; + /** + * @var OrderPaymentExtensionInterfaceFactory + */ + protected $paymentExtensionFactory; + + /** + * @var \Sapient\Worldpay\Model\Recurring\Subscription\TransactionsFactory + */ + protected $transactionFactory; + /** * Constructor * * @param SavedToken $savedtoken - * @param Sapient\Worldpay\Logger\WorldpayLogger $wplogger + * @param \Sapient\Worldpay\Logger\WorldpayLogger $wplogger * @param \Sapient\Worldpay\Model\Recurring\Subscription\TransactionsFactory $transactionsFactory * @param OrderPaymentExtensionInterfaceFactory $paymentExtensionFactory * @param CreditCardTokenFactory $paymentTokenFactory @@ -79,9 +103,9 @@ public function __construct( /** * Update token of the given customer * - * @param Sapient\WorldPay\Model\Token $token + * @param \Sapient\WorldPay\Model\Token $token * @param \Magento\Customer\Model\Customer $customer - * @throws Sapient\Worldpay\Model\Token\AccessDeniedException + * @throws \Sapient\Worldpay\Model\Token\AccessDeniedException */ public function updateTokenByCustomer(SavedToken $token, \Magento\Customer\Model\Customer $customer) { diff --git a/Model/Utilities/PaymentMethods.php b/Model/Utilities/PaymentMethods.php index 47b56ae1..dd7b8ff8 100644 --- a/Model/Utilities/PaymentMethods.php +++ b/Model/Utilities/PaymentMethods.php @@ -10,7 +10,7 @@ class PaymentMethods { /** - * @var SimpleXMLElement + * @var \SimpleXMLElement */ protected static $_xml; @@ -19,6 +19,35 @@ class PaymentMethods */ protected $_xmlLocation; + /** + * @var \Magento\Store\Model\StoreManagerInterface + */ + protected $_storeManager; + + /** + * @var \Magento\Framework\App\Config\ScopeConfigInterface + */ + protected $scopeConfig; + + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ + protected $wplogger; + + /** + * @var \Magento\Checkout\Model\Session + */ + protected $checkoutsession; + + /** + * @var \Magento\Backend\Model\Session\Quote + */ + protected $adminsessionquote; + + /** + * @var \Magento\Backend\Model\Auth\Session + */ + protected $authSession; public const PAYMENT_METHOD_PATH = '/paymentMethods/'; public const TYPE_PATH = '/types/'; diff --git a/Model/WorldpayConfigProvider.php b/Model/WorldpayConfigProvider.php index be858ea0..ed0cee3d 100644 --- a/Model/WorldpayConfigProvider.php +++ b/Model/WorldpayConfigProvider.php @@ -61,13 +61,6 @@ class WorldpayConfigProvider implements ConfigProviderInterface */ public $session; - /** - * Locale model - * - * @var \Magento\Framework\Locale\ResolverInterface - */ - protected $localeResolver; - /** * @var SerializerInterface */ @@ -77,6 +70,51 @@ class WorldpayConfigProvider implements ConfigProviderInterface * @var fileDriver */ protected $fileDriver; + + /** + * @var \Magento\Customer\Model\Session + */ + protected $customerSession; + + /** + * @var \Magento\Backend\Model\Session\Quote + */ + protected $adminquotesession; + + /** + * @var SavedTokenFactory + */ + protected $savedTokenFactory; + + /** + * @var \Sapient\Worldpay\Model\Utilities\PaymentMethods + */ + protected $paymentmethodutils; + + /** + * @var \Magento\Backend\Model\Auth\Session + */ + protected $backendAuthSession; + + /** + * @var Repository + */ + protected $assetRepo; + + /** + * @var RequestInterface + */ + protected $request; + + /** + * @var Source + */ + protected $assetSource; + + /** + * @var \Magento\Framework\Locale\ResolverInterface + */ + protected $localeResolver; /** * @param \Sapient\Worldpay\Logger\WorldpayLogger $wplogger @@ -252,6 +290,9 @@ public function getConfig() $config['payment']['ccform']['latAmCountries'] = $this->worldpayHelper->getConfigCountries(); //ACH Pay $config['payment']['ccform']['achdetails'] = $this->worldpayHelper->getACHDetails(); + //Sepa Pay + $config['payment']['ccform']['sepadetails'] = $this->worldpayHelper->getSEPADetails(); + $config['payment']['ccform']['sepa_e_mandate'] = $this->worldpayHelper->getSepaEmandate(); //Prime Routing $config['payment']['ccform']['isPrimeRoutingEnabled'] = $this->worldpayHelper->isPrimeRoutingEnabled(); diff --git a/Model/XmlBuilder/ACHOrder.php b/Model/XmlBuilder/ACHOrder.php index f62070e6..cf6b09d3 100644 --- a/Model/XmlBuilder/ACHOrder.php +++ b/Model/XmlBuilder/ACHOrder.php @@ -86,6 +86,10 @@ class ACHOrder * @var array|string */ private $exponent; + /** + * @var string $captureDelay + */ + private $captureDelay; /** * Build xml for processing Request @@ -104,6 +108,7 @@ class ACHOrder * @param string $shopperId * @param string $statementNarrative * @param string $exponent + * @param string $captureDelay */ public function build( $merchantCode, @@ -119,7 +124,8 @@ public function build( $billingAddress, $shopperId, $statementNarrative, - $exponent + $exponent, + $captureDelay ) { $this->merchantCode = $merchantCode; @@ -136,6 +142,7 @@ public function build( $this->shopperId = $shopperId; $this->statementNarrative = $statementNarrative; $this->exponent = $exponent; + $this->captureDelay = $captureDelay; $xml = new \SimpleXMLElement(self::ROOT_ELEMENT); $xml['merchantCode'] = $this->merchantCode; @@ -168,6 +175,9 @@ private function _addOrderElement($submit) { $order = $submit->addChild('order'); $order['orderCode'] = $this->orderCode; + if ($this->captureDelay!="") { + $order['captureDelay'] = $this->captureDelay; + } $this->_addDescriptionElement($order); $this->_addAmountElement($order); $this->_addPaymentDetailsElement($order); diff --git a/Model/XmlBuilder/ApplePayOrder.php b/Model/XmlBuilder/ApplePayOrder.php index fffb09a7..e3208a4c 100644 --- a/Model/XmlBuilder/ApplePayOrder.php +++ b/Model/XmlBuilder/ApplePayOrder.php @@ -45,6 +45,41 @@ class ApplePayOrder */ private $exponent; + /** + * @var string $captureDelay + */ + private $captureDelay; + + /** + * @var string + */ + private $shopperEmail; + /** + * @var string + */ + private $protocolVersion; + + /** + * @var string + */ + private $signature; + /** + * @var array | string + */ + private $data; + /** + * @var string + */ + private $ephemeralPublicKey; + /** + * @var string + */ + private $publicKeyHash; + /** + * @var string + */ + private $transactionId; + /** * Build xml for processing Request * @@ -62,6 +97,7 @@ class ApplePayOrder * @param string $publicKeyHash * @param string $transactionId * @param string|array|float $exponent + * @param string $captureDelay * @return SimpleXMLElement $xml */ public function build( @@ -78,7 +114,8 @@ public function build( $ephemeralPublicKey, $publicKeyHash, $transactionId, - $exponent + $exponent, + $captureDelay ) { $this->merchantCode = $merchantCode; $this->orderCode = $orderCode; @@ -94,6 +131,7 @@ public function build( $this->publicKeyHash = $publicKeyHash; $this->transactionId = $transactionId; $this->exponent = $exponent; + $this->captureDelay = $captureDelay; $xml = new \SimpleXMLElement(self::ROOT_ELEMENT); $xml['merchantCode'] = $this->merchantCode; $xml['version'] = '1.4'; @@ -126,7 +164,9 @@ private function _addOrderElement($submit) $order = $submit->addChild('order'); $order['orderCode'] = $this->orderCode; $order['shopperLanguageCode'] = "en"; - + if ($this->captureDelay!="") { + $order['captureDelay'] = $this->captureDelay; + } $this->_addDescriptionElement($order); $this->_addAmountElement($order); $this->_addPaymentDetailsElement($order); diff --git a/Model/XmlBuilder/Capture.php b/Model/XmlBuilder/Capture.php index 7bba8e1e..00225958 100644 --- a/Model/XmlBuilder/Capture.php +++ b/Model/XmlBuilder/Capture.php @@ -36,6 +36,54 @@ class Capture */ private $exponent; + /** + * @var \Magento\Framework\App\Config\ScopeConfigInterface + */ + protected $scopeConfig; + /** + * @var \Magento\Store\Model\StoreManagerInterface + */ + protected $storeManager; + + /** + * @var Order $order + */ + protected $order; + + /** + * @var mixed + */ + protected $captureType; + + /** + * @var bool + */ + protected $isMultishippingOrder; + + /** + * @var string|null + */ + protected $paymentType; + + /** + * @var array|null + */ + protected $invoicedItems; + + /** + * Capture constructor + * + * @param Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig + * @param Magento\Store\Model\StoreManagerInterface $storeManager + */ + + public function __construct( + \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, + \Magento\Store\Model\StoreManagerInterface $storeManager + ) { + $this->scopeConfig = $scopeConfig; + $this->storeManager = $storeManager; + } /** * Build xml for processing Request * @@ -81,12 +129,8 @@ public function build( $orderModification = $this->_addOrderModificationElement($modify); $capture = $this->_addCapture($orderModification); $this->_addCaptureElement($capture); - - $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORES; - - $level23DataEnabled = $objectManager->get(\Magento\Framework\App\Config\ScopeConfigInterface::class) - ->getValue('worldpay/level23_config/level23', $storeScope); + $level23DataEnabled = $this->scopeConfig->getValue('worldpay/level23_config/level23', $storeScope); //Level23 data changes $countryCode = $order->getBillingAddress()->getCountryId(); @@ -140,13 +184,11 @@ private function _addOrderModificationElement($modify) private function _addCapture($orderModification) { $capture = $orderModification->addChild('capture'); - - $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORES; - $autoInvoice = $objectManager->get(\Magento\Framework\App\Config\ScopeConfigInterface::class) + $autoInvoice = $this->scopeConfig ->getValue('worldpay/general_config/capture_automatically', $storeScope); - $partialCapture = $objectManager->get(\Magento\Framework\App\Config\ScopeConfigInterface::class) + $partialCapture = $this->scopeConfig ->getValue('worldpay/partial_capture_config/partial_capture', $storeScope); //check the partial capture if ($this->captureType == 'partial' && $partialCapture) { @@ -182,12 +224,11 @@ private function _addCaptureElement($capture) $amountElement['exponent'] = $this->exponent; $amountElement['value'] = $this->_amountAsInt($this->amount); - $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORES; - $autoInvoice = $objectManager->get(\Magento\Framework\App\Config\ScopeConfigInterface::class) + $autoInvoice = $this->scopeConfig ->getValue('worldpay/general_config/capture_automatically', $storeScope); - $partialCapture = $objectManager->get(\Magento\Framework\App\Config\ScopeConfigInterface::class) + $partialCapture = $this->scopeConfig ->getValue('worldpay/partial_capture_config/partial_capture', $storeScope); //check the partial capture @@ -244,13 +285,12 @@ private function _addBranchSpecificExtension($order, $capture) $purchase->addChild('customerReference', $order->getCustomerId()); } - $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORES; - $cardAcceptorTaxId = $objectManager->get(\Magento\Framework\App\Config\ScopeConfigInterface::class) + $cardAcceptorTaxId = $this->scopeConfig ->getValue('worldpay/level23_config/CardAcceptorTaxId', $storeScope); - $dutyAmount = $objectManager->get(\Magento\Framework\App\Config\ScopeConfigInterface::class) + $dutyAmount = $this->scopeConfig ->getValue('worldpay/level23_config/duty_amount', $storeScope); $taxAmount = $order->getTaxAmount(); @@ -444,8 +484,7 @@ private function _addKlarnaOrderLineItemElement($order, $capture, $invoicedItems $this->_addCDATA($orderTaxAmountElement, $this->_amountAsInt($order->getTaxAmount())); //terms url - $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); - $store = $objectManager->get(\Magento\Store\Model\StoreManagerInterface::class)->getStore(); + $store = $this->storeManager->getStore(); $termsURLElement = $orderLinesElement->addChild('termsURL'); $this->_addCDATA($termsURLElement, $store->getBaseUrl()); diff --git a/Model/XmlBuilder/ChromePayOrder.php b/Model/XmlBuilder/ChromePayOrder.php index 8e8dae8e..ebd22c18 100644 --- a/Model/XmlBuilder/ChromePayOrder.php +++ b/Model/XmlBuilder/ChromePayOrder.php @@ -74,12 +74,21 @@ class ChromePayOrder * @var array|string */ private $exponent; + /** + * @var string + */ + private $paymentType; /** - * @var Sapient\Worldpay\Model\XmlBuilder\Config\TokenConfiguration + * @var \Sapient\Worldpay\Model\XmlBuilder\Config\TokenConfiguration */ protected $tokenRequestConfig; + /** + * @var string $captureDelay + */ + protected $captureDelay; + /** * Build xml for processing Request * @@ -94,6 +103,7 @@ class ChromePayOrder * @param float $billingAddress * @param string $shopperEmail * @param array|string $exponent + * @param string $captureDelay * @return SimpleXMLElement $xml */ public function build( @@ -111,7 +121,8 @@ public function build( $billingAddress, //$shopperId, $shopperEmail, - $exponent + $exponent, + $captureDelay ) { $this->merchantCode = $merchantCode; $this->orderCode = $orderCode; @@ -125,6 +136,7 @@ public function build( $this->billingAddress = $billingAddress; $this->shopperEmail = $shopperEmail; $this->exponent = $exponent; + $this->captureDelay = $captureDelay; //$this->acceptHeader = $acceptHeader; //$this->userAgentHeader = $userAgentHeader; @@ -159,6 +171,9 @@ private function _addOrderElement($submit) { $order = $submit->addChild('order'); $order['orderCode'] = $this->orderCode; + if ($this->captureDelay!="") { + $order['captureDelay'] = $this->captureDelay; + } $this->_addDescriptionElement($order); $this->_addAmountElement($order); $this->_addPaymentDetailsElement($order); diff --git a/Model/XmlBuilder/DirectIdealOrder.php b/Model/XmlBuilder/DirectIdealOrder.php index 59f3267a..f80e223b 100644 --- a/Model/XmlBuilder/DirectIdealOrder.php +++ b/Model/XmlBuilder/DirectIdealOrder.php @@ -92,7 +92,23 @@ class DirectIdealOrder * @var Sapient\Worldpay\Model\XmlBuilder\Config\TokenConfiguration */ private $tokenRequestConfig; + /** + * @var string $captureDelay + */ + private $captureDelay; + /** + * @var string + */ + private $callbackurl; + /** + * @var string + */ + private $bankcode; + /** + * @var string + */ + private $shopperId; /** * Constructor * @@ -129,6 +145,7 @@ public function __construct(array $args = []) * @param string $callbackurl * @param string $ccbank * @param array|string $exponent + * @param string $captureDelay * @return SimpleXMLElement $xml */ public function build( @@ -149,7 +166,8 @@ public function build( $hideAddress, $callbackurl, $ccbank, - $exponent + $exponent, + $captureDelay ) { $this->merchantCode = $merchantCode; $this->orderCode = $orderCode; @@ -169,6 +187,7 @@ public function build( $this->callbackurl = $callbackurl; $this->bankcode = $ccbank; $this->exponent = $exponent; + $this->captureDelay = $captureDelay; $xml = new \SimpleXMLElement(self::ROOT_ELEMENT); $xml['merchantCode'] = $this->merchantCode; @@ -213,7 +232,9 @@ private function _addOrderElement($submit) $order['hideContact'] = 'false'; } } - + if ($this->captureDelay!="") { + $order['captureDelay'] = $this->captureDelay; + } $this->_addDescriptionElement($order); $this->_addAmountElement($order); $this->_addOrderContentElement($order); diff --git a/Model/XmlBuilder/DirectOrder.php b/Model/XmlBuilder/DirectOrder.php index ff84d48e..64d7113c 100644 --- a/Model/XmlBuilder/DirectOrder.php +++ b/Model/XmlBuilder/DirectOrder.php @@ -137,13 +137,25 @@ class DirectOrder */ protected $tokenRequestConfig; + /** + * @var string $captureDelay + */ + protected $captureDelay; + + /** + * @var \Magento\Customer\Model\Session + */ + protected $customerSession; /** * Constructor - * + * @param \Magento\Customer\Model\Session $customerSession * @param array $args */ - public function __construct(array $args = []) - { + public function __construct( + \Magento\Customer\Model\Session $customerSession, + array $args = [] + ) { + $this->customerSession = $customerSession; $this->threeDSecureConfig = new \Sapient\Worldpay\Model\XmlBuilder\Config\ThreeDSecure( $args['threeDSecureConfig']['isDynamic3D'], $args['threeDSecureConfig']['is3DSecure'] @@ -179,6 +191,7 @@ public function __construct(array $args = []) * @param array|string $exponent * @param mixed $primeRoutingData * @param array $orderLineItems + * @param string $captureDelay * @return SimpleXMLElement $xml */ public function build( @@ -204,7 +217,8 @@ public function build( $shippingfee, $exponent, $primeRoutingData, - $orderLineItems + $orderLineItems, + $captureDelay ) { $this->merchantCode = $merchantCode; @@ -230,6 +244,7 @@ public function build( $this->exponent = $exponent; $this->primeRoutingData =$primeRoutingData; $this->orderLineItems = $orderLineItems; + $this->captureDelay = $captureDelay; $xml = new \SimpleXMLElement(self::ROOT_ELEMENT); $xml['merchantCode'] = $this->merchantCode; @@ -333,6 +348,10 @@ private function _addOrderElement($submit) $session['id'] = $this->paymentDetails['sessionId']; return $order; } + + if ($this->captureDelay!="") { + $order['captureDelay'] = $this->captureDelay; + } $this->_addDescriptionElement($order); $this->_addAmountElement($order); @@ -1016,10 +1035,8 @@ private function _addBranchSpecificExtension($order) $purchase = $branchSpecificExtension->addChild('purchase'); $customerId = ''; - $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); - $customerSession = $objectManager->get(\Magento\Customer\Model\Session::class); - if ($customerSession->isLoggedIn()) { - $customerId = $customerSession->getCustomer()->getId(); + if ($this->customerSession->isLoggedIn()) { + $customerId = $this->customerSession->getCustomer()->getId(); } if (!empty($customerId)) { diff --git a/Model/XmlBuilder/RedirectKlarnaOrder.php b/Model/XmlBuilder/RedirectKlarnaOrder.php index 07df4bfd..cf2c201b 100644 --- a/Model/XmlBuilder/RedirectKlarnaOrder.php +++ b/Model/XmlBuilder/RedirectKlarnaOrder.php @@ -95,6 +95,14 @@ class RedirectKlarnaOrder * @var array|string */ private $orderContent; + /** + * @var string $captureDelay + */ + private $captureDelay; + /** + * @var array + */ + private $orderlineitems; /** * RedirectKlarnaOrder constructor @@ -128,6 +136,7 @@ public function __construct() * @param array|string $exponent * @param string $sessionData * @param array|string $orderContent + * @param string $captureDelay * @return SimpleXMLElement $xml */ public function build( @@ -149,7 +158,8 @@ public function build( $orderlineitems, $exponent, $sessionData, - $orderContent + $orderContent, + $captureDelay ) { $this->merchantCode = $merchantCode; $this->orderCode = $orderCode; @@ -170,7 +180,7 @@ public function build( $this->exponent = $exponent; $this->sessionData = $sessionData; $this->orderContent = $orderContent; - + $this->captureDelay = $captureDelay; $xml = new \SimpleXMLElement(self::ROOT_ELEMENT); $xml['merchantCode'] = $this->merchantCode; $xml['version'] = '1.4'; @@ -214,6 +224,10 @@ private function _addOrderElement($submit) $order['hideContact'] = 'false'; } } + + if ($this->captureDelay!="") { + $order['captureDelay'] = $this->captureDelay; + } $this->_addDescriptionElement($order); $this->_addAmountElement($order); $this->_addOrderContentElement($order); diff --git a/Model/XmlBuilder/RedirectOrder.php b/Model/XmlBuilder/RedirectOrder.php index 0bcfa2e4..f0e9bbbe 100644 --- a/Model/XmlBuilder/RedirectOrder.php +++ b/Model/XmlBuilder/RedirectOrder.php @@ -119,6 +119,19 @@ class RedirectOrder * @var array */ private $storedCredentialsEnabled; + /** + * @var string + */ + private $captureDelay; + + /** + * @var string + */ + private $shopperId; + /** + * @var array + */ + public $paymentDetails; /** * Constructor @@ -158,6 +171,7 @@ public function __construct(array $args = []) * @param mixed $exponent * @param string $cusDetails * @param array $orderLineItems + * @param string $captureDelay * @param string $savemyCard * @param string $storedCredentialsEnabled = null * @return SimpleXMLElement $xml @@ -184,6 +198,7 @@ public function build( $exponent, $cusDetails, $orderLineItems, + $captureDelay, $savemyCard = null, $storedCredentialsEnabled = null ) { @@ -208,6 +223,7 @@ public function build( $this->exponent = $exponent; $this->cusDetails = $cusDetails; $this->orderLineItems = $orderLineItems; + $this->captureDelay = $captureDelay; $this->saveCardEnabled = $savemyCard; $this->storedCredentialsEnabled = $storedCredentialsEnabled; @@ -255,7 +271,9 @@ private function _addOrderElement($submit) $order['hideContact'] = 'false'; } } - + if ($this->captureDelay!="") { + $order['captureDelay'] = $this->captureDelay; + } $this->_addDescriptionElement($order); $amountElement = $order->addChild('amount'); $this->_addAmountElement($amountElement, $this->currencyCode, $this->exponent, $this->amount); diff --git a/Model/XmlBuilder/RedirectPayByLinkOrder.php b/Model/XmlBuilder/RedirectPayByLinkOrder.php new file mode 100644 index 00000000..c02531b6 --- /dev/null +++ b/Model/XmlBuilder/RedirectPayByLinkOrder.php @@ -0,0 +1,970 @@ + +EOD; + + /** + * @var string + */ + private $merchantCode; + /** + * @var string + */ + private $orderCode; + /** + * @var string + */ + private $orderDescription; + /** + * @var string + */ + private $currencyCode; + /** + * @var float + */ + private $amount; + /** + * @var string + */ + private $paymentType; + /** + * @var string + */ + private $shopperEmail; + /** + * @var string + */ + private $statementNarrative; + /** + * @var string + */ + private $acceptHeader; + /** + * @var string + */ + private $userAgentHeader; + /** + * @var array + */ + private $shippingAddress; + /** + * @var array + */ + private $billingAddress; + /** + * @var float + */ + private $paymentPagesEnabled; + /** + * @var string + */ + private $installationId; + /** + * @var string + */ + private $hideAddress; + /** + * @var string + */ + private $thirdparty; + /** + * @var mixed + */ + private $shippingfee; + /** + * @var mixed + */ + private $exponent; + /** + * @var string + */ + private $cusDetails; + /** + * @var array + */ + private $orderLineItems; + + /** + * @var Sapient\Worldpay\Model\XmlBuilder\Config\ThreeDSecure + */ + private $threeDSecureConfig; + + /** + * @var Sapient\Worldpay\Model\XmlBuilder\Config\TokenConfiguration + */ + private $tokenRequestConfig; + + /** + * @var array + */ + private $saveCardEnabled; + + /** + * @var array + */ + private $storedCredentialsEnabled; + /** + * @var string $captureDelay + */ + private $captureDelay; + + /** + * @var string + */ + private $shopperId; + + /** + * @var array + */ + private $paymentDetails; + + /** + * @var string + */ + private $savemyCard; + + /** + * Constructor + * + * @param array $args + */ + public function __construct(array $args = []) + { + $this->threeDSecureConfig = new \Sapient\Worldpay\Model\XmlBuilder\Config\ThreeDSecure(); + $this->tokenRequestConfig = new \Sapient\Worldpay\Model\XmlBuilder\Config\TokenConfiguration( + $args['tokenRequestConfig'] + ); + $this->shopperId = $args['shopperId']; + } + + /** + * Build xml for processing Request + * + * @param string $merchantCode + * @param string $orderCode + * @param string $orderDescription + * @param string $currencyCode + * @param float $amount + * @param string $paymentType + * @param string $shopperEmail + * @param string $statementNarrative + * @param string $acceptHeader + * @param string $userAgentHeader + * @param string $shippingAddress + * @param string $billingAddress + * @param float $paymentPagesEnabled + * @param string $installationId + * @param string $hideAddress + * @param array $paymentDetails + * @param string $thirdparty + * @param mixed $shippingfee + * @param mixed $exponent + * @param string $cusDetails + * @param array $orderLineItems + * @param string $captureDelay + * @param string $savemyCard + * @param string $storedCredentialsEnabled = null + * @return SimpleXMLElement $xml + */ + public function build( + $merchantCode, + $orderCode, + $orderDescription, + $currencyCode, + $amount, + $paymentType, + $shopperEmail, + $statementNarrative, + $acceptHeader, + $userAgentHeader, + $shippingAddress, + $billingAddress, + $paymentPagesEnabled, + $installationId, + $hideAddress, + $paymentDetails, + $thirdparty, + $shippingfee, + $exponent, + $cusDetails, + $orderLineItems, + $captureDelay, + $savemyCard = null, + $storedCredentialsEnabled = null + ) { + $this->merchantCode = $merchantCode; + $this->orderCode = $orderCode; + $this->orderDescription = $orderDescription; + $this->currencyCode = $currencyCode; + $this->amount = $amount; + $this->paymentType = $paymentType; + $this->shopperEmail = $shopperEmail; + $this->statementNarrative = $statementNarrative; + $this->acceptHeader = $acceptHeader; + $this->userAgentHeader = $userAgentHeader; + $this->shippingAddress = $shippingAddress; + $this->billingAddress = $billingAddress; + $this->paymentPagesEnabled = $paymentPagesEnabled; + $this->installationId = $installationId; + $this->hideAddress = $hideAddress; + $this->paymentDetails = $paymentDetails; + $this->thirdparty = $thirdparty; + $this->shippingfee = $shippingfee; + $this->exponent = $exponent; + $this->cusDetails = $cusDetails; + $this->orderLineItems = $orderLineItems; + $this->captureDelay = $captureDelay; + + $this->saveCardEnabled = $savemyCard; + $this->storedCredentialsEnabled = $storedCredentialsEnabled; + + $xml = new \SimpleXMLElement(self::ROOT_ELEMENT); + $xml['merchantCode'] = $this->merchantCode; + $xml['version'] = '1.4'; + + $submit = $this->_addSubmitElement($xml); + $this->_addOrderElement($submit); + + return $xml; + } + + /** + * Add submit tag to xml + * + * @param SimpleXMLElement $xml + * @return SimpleXMLElement + */ + private function _addSubmitElement($xml) + { + return $xml->addChild('submit'); + } + + /** + * Add order tag to xml + * + * @param SimpleXMLElement $submit + * @return SimpleXMLElement $order + */ + private function _addOrderElement($submit) + { + $order = $submit->addChild('order'); + $order['orderCode'] = $this->orderCode; + + if ($this->paymentPagesEnabled) { + $order['installationId'] = $this->installationId; + + $order['fixContact'] = 'true'; + $order['hideContact'] = 'true'; + + if ($this->hideAddress) { + $order['fixContact'] = 'false'; + $order['hideContact'] = 'false'; + } + } + if ($this->captureDelay!="") { + $order['captureDelay'] = $this->captureDelay; + } + $this->_addDescriptionElement($order); + $amountElement = $order->addChild('amount'); + $this->_addAmountElement($amountElement, $this->currencyCode, $this->exponent, $this->amount); + if (isset($this->paymentDetails['paymentType']) && $this->paymentDetails['paymentType'] == "TOKEN-SSL") { + $this->_addPaymentDetailsElement($order); + } else { + $this->_addPaymentMethodMaskElement($order); + } + $this->_addShopperElement($order); + $this->_addShippingElement($order); + $this->_addBillingElement($order); + + //Level 23 data request body + if (!empty($this->paymentDetails['isLevel23Enabled']) && $this->paymentDetails['isLevel23Enabled'] + && ($this->paymentDetails['cardType'] === 'ECMC-SSL' || $this->paymentDetails['cardType'] === 'VISA-SSL') + && ($this->paymentDetails['countryCode'] === 'US' || $this->paymentDetails['countryCode'] === 'CA')) { + $this->_addBranchSpecificExtension($order); + } else { + $this->addOrderLineItemsXML($order); + } + + if (!empty($this->thirdparty)) { + $this->_addThirdPartyData($order); + } + $this->_addDynamic3DSElement($order); + $this->_addCreateTokenElement($order); + if (!empty($this->statementNarrative)) { + $this->_addStatementNarrativeElement($order); + } + $this->_addFraudSightData($order); + return $order; + } + + /** + * Add description tag to xml + * + * @param SimpleXMLElement $order + */ + private function _addDescriptionElement($order) + { + $description = $order->addChild('description'); + if (!empty($this->thirdparty['statement'])) { + $this->_addCDATA($description, $this->thirdparty['statement']); + } else { + $this->_addCDATA($description, $this->orderDescription); + } + } + + /** + * Add amount tag to xml + * + * @param SimpleXMLElement $amountElement + * @param string $currencyCode + * @param mixed $exponent + * @param float $amount + */ + private function _addAmountElement($amountElement, $currencyCode, $exponent, $amount) + { + $amountElement['currencyCode'] = $currencyCode; + $amountElement['exponent'] = $exponent; + $amountElement['value'] = $this->_amountAsInt($amount); + } + + /** + * Add dynamicInteractionType and its attribute tag to xml + * + * @param SimpleXMLElement $order + */ + private function _addDynamic3DSElement($order) + { + if (isset($this->paymentDetails['PaymentMethod']) + && $this->paymentDetails['PaymentMethod'] == 'worldpay_moto') { + $threeDSElement = $order->addChild('dynamic3DS'); + $threeDSElement['overrideAdvice'] = self::DYNAMIC3DS_NO3DS; + } + + if ($this->threeDSecureConfig->isDynamic3DEnabled() === false) { + return; + } + + $threeDSElement = $order->addChild('dynamic3DS'); + if ($this->threeDSecureConfig->is3DSecureCheckEnabled() + && (isset($this->paymentDetails['PaymentMethod']) + && $this->paymentDetails['PaymentMethod'] !== 'worldpay_moto')) { + $threeDSElement['overrideAdvice'] = self::DYNAMIC3DS_DO3DS; + } else { + $threeDSElement['overrideAdvice'] = self::DYNAMIC3DS_NO3DS; + } + } + + /** + * Add createToken and its child tag to xml + * + * @param SimpleXMLElement $order + */ + private function _addCreateTokenElement($order) + { + if (! $this->tokenRequestConfig->istokenizationIsEnabled()) { + return; + } + + $createTokenElement = $order->addChild('createToken'); + $createTokenElement['tokenScope'] = self::TOKEN_SCOPE; + if ($this->paymentDetails['token_type']) { + $createTokenElement['tokenScope'] = 'merchant'; + $createTokenElement->addChild( + 'tokenEventReference', + time().'_'.random_int(0, 99999) + ); + } + if ($this->tokenRequestConfig->getTokenReason($this->orderCode)) { + $createTokenElement->addChild( + 'tokenReason', + $this->tokenRequestConfig->getTokenReason($this->orderCode) + ); + } + } + + /** + * Add paymentMethodMask and its child tag to xml + * + * @param SimpleXMLElement $order + */ + private function _addPaymentMethodMaskElement($order) + { + $paymentMethodMask = $order->addChild('paymentMethodMask'); + if ($this->saveCardEnabled && $this->storedCredentialsEnabled) { + $this->_addStoredCredentials($paymentMethodMask); + } + $include = $paymentMethodMask->addChild('include'); + $include['code'] = $this->paymentType; + } + + /** + * Add _addStatementNarrativeElement to xml + * + * @param SimpleXMLElement $order + */ + private function _addStatementNarrativeElement($order) + { + $order->addChild('statementNarrative', $this->statementNarrative); + } + /** + * Add shopper and its child tag to xml + * + * @param SimpleXMLElement $order + */ + private function _addShopperElement($order) + { + $shopper = $order->addChild('shopper'); + $shopper->addChild('shopperEmailAddress', $this->shopperEmail); + if (!$this->paymentDetails['token_type']) { + if ($this->tokenRequestConfig->istokenizationIsEnabled()) { + $shopper->addChild('authenticatedShopperID', $this->shopperId); + } elseif (isset($this->paymentDetails['tokenCode'])) { + $shopper->addChild('authenticatedShopperID', $this->paymentDetails['customerId']); + } + } + + $browser = $shopper->addChild('browser'); + + $acceptHeader = $browser->addChild('acceptHeader'); + $this->_addCDATA($acceptHeader, $this->acceptHeader); + + $userAgentHeader = $browser->addChild('userAgentHeader'); + $this->_addCDATA($userAgentHeader, $this->userAgentHeader); + } + + /** + * Add shippingAddress and its child tag to xml + * + * @param SimpleXMLElement $order + */ + private function _addShippingElement($order) + { + $shippingAddress = $order->addChild('shippingAddress'); + $this->_addAddressElement( + $shippingAddress, + $this->shippingAddress['firstName'], + $this->shippingAddress['lastName'], + $this->shippingAddress['street'], + $this->shippingAddress['postalCode'], + $this->shippingAddress['city'], + $this->shippingAddress['countryCode'] + ); + } + + /** + * Add billing and its child tag to xml + * + * @param SimpleXMLElement $order + */ + private function _addBillingElement($order) + { + $billingAddress = $order->addChild('billingAddress'); + $this->_addAddressElement( + $billingAddress, + $this->billingAddress['firstName'], + $this->billingAddress['lastName'], + $this->billingAddress['street'], + $this->billingAddress['postalCode'], + $this->billingAddress['city'], + $this->billingAddress['countryCode'] + ); + } + + /** + * Add address and its child tag to xml + * + * @param SimpleXMLElement $parentElement + * @param string $firstName + * @param string $lastName + * @param string $street + * @param string $postalCode + * @param string $city + * @param string $countryCode + */ + private function _addAddressElement( + $parentElement, + $firstName, + $lastName, + $street, + $postalCode, + $city, + $countryCode + ) { + $address = $parentElement->addChild('address'); + + $firstNameElement = $address->addChild('firstName'); + $this->_addCDATA($firstNameElement, $firstName); + + $lastNameElement = $address->addChild('lastName'); + $this->_addCDATA($lastNameElement, $lastName); + + $streetElement = $address->addChild('street'); + $this->_addCDATA($streetElement, $street); + + $postalCodeElement = $address->addChild('postalCode'); + //Zip code mandatory for worldpay, if not provided by customer we will pass manually + $zipCode = '00000'; + //If Zip code provided by customer + if ($postalCode) { + $zipCode = $postalCode; + } + $this->_addCDATA($postalCodeElement, $zipCode); + + $cityElement = $address->addChild('city'); + $this->_addCDATA($cityElement, $city); + + $countryCodeElement = $address->addChild('countryCode'); + $this->_addCDATA($countryCodeElement, $countryCode); + } + + /** + * Add cdata to xml + * + * @param SimpleXMLElement $element + * @param string $content + */ + private function _addCDATA($element, $content) + { + $node = dom_import_simplexml($element); + $no = $node->ownerDocument; + $node->appendChild($no->createCDATASection($content)); + } + + /** + * Returns the rounded value of num to specified precision + * + * @param float $amount + * @return int + */ + private function _amountAsInt($amount) + { + return round($amount, $this->exponent, PHP_ROUND_HALF_EVEN) * pow(10, $this->exponent); + } + + /** + * Add paymentDetails and its child tag to xml + * + * @param SimpleXMLElement $order + */ + protected function _addPaymentDetailsElement($order) + { + $paymentDetailsElement = $order->addChild('paymentDetails'); + $this->_addPaymentDetailsForTokenOrder($paymentDetailsElement); + $this->_addPaymentDetailsForStoredCredentialsOrder($paymentDetailsElement); + $session = $paymentDetailsElement->addChild('session'); + $session['id'] = $this->paymentDetails['sessionId']; + $session['shopperIPAddress'] = $this->paymentDetails['shopperIpAddress']; + } + /** + * Add stored credentials data and its child tag to xml + * + * @param element $paymentDetailsElement + * @return string + */ + protected function _addStoredCredentials($paymentDetailsElement) + { + $storedCredentials = $paymentDetailsElement->addChild('storedCredentials'); + $storedCredentials['usage'] = "FIRST"; + return $storedCredentials; + } + /** + * Add payment details for stored credentials data and its child tag to xml + * + * @param element $paymentDetailsElement + * @return string + */ + protected function _addPaymentDetailsForStoredCredentialsOrder($paymentDetailsElement) + { + $storedCredentials = $paymentDetailsElement->addChild('storedCredentials'); + $storedCredentials['usage'] = "USED"; + return $storedCredentials; + } + /** + * Add encryptedData and its child tag to xml + * + * @param SimpleXMLElement $paymentDetailsElement + */ + protected function _addPaymentDetailsForTokenOrder($paymentDetailsElement) + { + if (isset($this->paymentDetails['encryptedData'])) { + $cseElement = $this->_addCseElement($paymentDetailsElement); + } + $tokenNode = $paymentDetailsElement->addChild($this->paymentDetails['paymentType']); + $tokenNode['tokenScope'] = self::TOKEN_SCOPE; + if ($this->paymentDetails['token_type']) { + $tokenNode['tokenScope'] = 'merchant'; + } + if (isset($this->paymentDetails['ccIntegrationMode']) && + $this->paymentDetails['ccIntegrationMode'] == "redirect") { + $tokenNode['captureCvc'] = "true"; + } + + $tokenNode->addChild('paymentTokenID', $this->paymentDetails['tokenCode']); + } + + /** + * Add third party data and its child tag to xml + * + * @param element $order + * @return string + */ + protected function _addThirdPartyData($order) + { + $thirdparty = $order->addChild('thirdPartyData'); + if (!empty($this->thirdparty['instalment'])) { + $thirdparty->addChild('instalments', $this->thirdparty['instalment']); + } + if ($this->billingAddress['countryCode']=='BR' && !empty($this->shippingfee['shippingfee'])) { + $firstinstalment = $thirdparty->addChild('firstInstalment'); + $firstinstalment = $firstinstalment->addChild('amountNoCurrency'); + $firstinstalment['value'] =$this->_amountAsInt($this->shippingfee['shippingfee']); + } + if (!empty($this->thirdparty['cpf'])) { + $thirdparty->addChild('cpf', $this->thirdparty['cpf']); + } + return $thirdparty; + } + + /** + * Add fraud sight data and its child tag to xml + * + * @param element $order + * @return string + */ + private function _addFraudSightData($order) + { + $fraudsightData = $order->addChild('FraudSightData'); + $shopperFields = $fraudsightData->addChild('shopperFields'); + $shopperFields->addChild('shopperName', $this->cusDetails['shopperName']); + if (isset($this->cusDetails['shopperId'])) { + $shopperFields->addChild('shopperId', $this->cusDetails['shopperId']); + } + if (isset($this->cusDetails['birthDate'])) { + $shopperDOB = $shopperFields->addChild('birthDate'); + $dateElement= $shopperDOB->addChild('date'); + $dateElement['dayOfMonth'] = date("d", strtotime($this->cusDetails['birthDate'])); + $dateElement['month'] = date("m", strtotime($this->cusDetails['birthDate'])); + $dateElement['year'] = date("Y", strtotime($this->cusDetails['birthDate'])); + } + $shopperAddress = $shopperFields->addChild('shopperAddress'); + $this->_addAddressElement( + $shopperAddress, + $this->billingAddress['firstName'], + $this->billingAddress['lastName'], + $this->billingAddress['street'], + $this->billingAddress['postalCode'], + $this->billingAddress['city'], + $this->billingAddress['countryCode'] + ); + } + + /** + * Add branchSpecificExtension and its child tag to xml + * + * @param SimpleXMLElement $order + */ + private function _addBranchSpecificExtension($order) + { + $order_details = $this->cusDetails['order_details']; + $branchSpecificExtension = $order->addChild('branchSpecificExtension'); + $purchase = $branchSpecificExtension->addChild('purchase'); + if (!empty($order_details['customer_id'])) { + $purchase->addChild('customerReference', $order_details['customer_id']); + } else { + $purchase->addChild('customerReference', 'guest'); + } + $purchase->addChild('cardAcceptorTaxId', $this->paymentDetails['cardAcceptorTaxId']); + + $salesTax = $purchase->addChild('salesTax'); + $salesTaxElement = $salesTax->addChild('amount'); + $this->_addAmountElement( + $salesTaxElement, + $this->currencyCode, + $this->exponent, + $this->paymentDetails['salesTax'] + ); + + if (isset($this->cusDetails['discount_amount'])) { + $discountAmount = $purchase->addChild('discountAmount'); + $discountAmountElement = $discountAmount->addChild('amount'); + $this->_addAmountElement( + $discountAmountElement, + $this->currencyCode, + $this->exponent, + $this->cusDetails['discount_amount'] + ); + } + if (isset($this->cusDetails['shipping_amount'])) { + $shippingAmount = $purchase->addChild('shippingAmount'); + $shippingAmountElement = $shippingAmount->addChild('amount'); + $this->_addAmountElement( + $shippingAmountElement, + $this->currencyCode, + $this->exponent, + $this->cusDetails['shipping_amount'] + ); + } + + if (isset($this->paymentDetails['dutyAmount'])) { + $dutyAmount = $purchase->addChild('dutyAmount'); + $dutyAmountElement = $dutyAmount->addChild('amount'); + $this->_addAmountElement( + $dutyAmountElement, + $this->currencyCode, + $this->exponent, + $this->paymentDetails['dutyAmount'] + ); + } + + //$purchase->addChild('shipFromPostalCode', ''); + $purchase->addChild('destinationPostalCode', $this->shippingAddress['postalCode']); + $purchase->addChild('destinationCountryCode', $this->shippingAddress['countryCode']); + + $orderDate = $purchase->addChild('orderDate'); + $dateElement = $orderDate->addChild('date'); + $today = new \DateTime(); + $dateElement['dayOfMonth'] = $today->format('d'); + $dateElement['month'] = $today->format('m'); + $dateElement['year'] = $today->format('Y'); + + $purchase->addChild('taxExempt', $this->paymentDetails['salesTax'] > 0 ? 'false' : 'true'); + + $this->_addL23OrderLineItemElement($order, $purchase); + } + + /** + * Add all order line item element values to xml + * + * @param Order $order + * @param mixed $purchase + */ + private function _addL23OrderLineItemElement($order, $purchase) + { + + $orderLineItems = $this->orderLineItems; + + foreach ($orderLineItems['lineItem'] as $lineitem) { + $this->_addLineItemElement( + $purchase, + $lineitem['description'], + $lineitem['productCode'], + $lineitem['commodityCode'], + $lineitem['quantity'], + $lineitem['unitCost'], + $lineitem['unitOfMeasure'], + $lineitem['itemTotal'], + $lineitem['itemTotalWithTax'], + $lineitem['itemDiscountAmount'], + $lineitem['taxAmount'] + ); + } + } + + /** + * Add order line item element values to xml + * + * @param SimpleXMLElement $parentElement + * @param string $description + * @param string $productCode + * @param string $commodityCode + * @param string $quantity + * @param float $unitCost + * @param string $unitOfMeasure + * @param float $itemTotal + * @param float $itemTotalWithTax + * @param float $itemDiscountAmount + * @param float $taxAmount + */ + private function _addLineItemElement( + $parentElement, + $description, + $productCode, + $commodityCode, + $quantity, + $unitCost, + $unitOfMeasure, + $itemTotal, + $itemTotalWithTax, + $itemDiscountAmount, + $taxAmount + ) { + $item = $parentElement->addChild('item'); + + $descriptionElement = $item->addChild('description'); + $this->_addCDATA($descriptionElement, $description); + + $productCodeElement = $item->addChild('productCode'); + $this->_addCDATA($productCodeElement, $productCode); + + if ($commodityCode) { + $commodityCodeElement = $item->addChild('commodityCode'); + $this->_addCDATA($commodityCodeElement, $commodityCode); + } + $quantityElement = $item->addChild('quantity'); + $this->_addCDATA($quantityElement, $quantity); + + $unitCostElement = $item->addChild('unitCost'); + $unitCostAmount = $unitCostElement->addChild('amount'); + $this->_addAmountElement($unitCostAmount, $this->currencyCode, $this->exponent, $unitCost); + + if ($unitOfMeasure) { + $unitOfMeasureElement = $item->addChild('unitOfMeasure'); + $this->_addCDATA($unitOfMeasureElement, $unitOfMeasure); + } + + $itemTotalElement = $item->addChild('itemTotal'); + $itemTotalElementAmount = $itemTotalElement->addChild('amount'); + $this->_addAmountElement($itemTotalElementAmount, $this->currencyCode, $this->exponent, $itemTotal); + + $itemTotalWithTaxElement = $item->addChild('itemTotalWithTax'); + $itemTotalWithTaxElementAmount = $itemTotalWithTaxElement->addChild('amount'); + $this->_addAmountElement( + $itemTotalWithTaxElementAmount, + $this->currencyCode, + $this->exponent, + $itemTotalWithTax + ); + + $itemDiscountAmountElement = $item->addChild('itemDiscountAmount'); + $itemDiscountElementAmount = $itemDiscountAmountElement->addChild('amount'); + $this->_addAmountElement($itemDiscountElementAmount, $this->currencyCode, $this->exponent, $itemDiscountAmount); + + $taxAmountElement = $item->addChild('taxAmount'); + $taxAmountElementAmount = $taxAmountElement->addChild('amount'); + $this->_addAmountElement($taxAmountElementAmount, $this->currencyCode, $this->exponent, $taxAmount); + } + /** + * Add order line items to XML + * + * @param SimpleXMLElement $order + */ + private function addOrderLineItemsXML($order) + { + $diffAmt = 0; + $totalAmount = 0; + + $orderLinesElement = $order->addChild('orderLines'); + + $orderlineitems = $this->orderLineItems; + + $orderTaxAmountElement = $orderLinesElement->addChild('orderTaxAmount'); + $this->_addCDATA($orderTaxAmountElement, $this->_amountAsInt($orderlineitems['orderTaxAmount'])); + + $termsURLElement = $orderLinesElement->addChild('termsURL'); + $this->_addCDATA($termsURLElement, $orderlineitems['termsURL']); + + foreach ($orderlineitems['lineItem'] as $lineitem) { + + $totaldiscountamount = (isset($lineitem['totalDiscountAmount'])) ? $lineitem['totalDiscountAmount'] : 0; + if ($lineitem['productType'] === 'bundle' && $diffAmt > 0) { + $totaldiscountamount = $diffAmt; + $totalAmount = $lineitem['totalAmount'] - $diffAmt; + } else { + $totalAmount = 0; + } + + $this->_addOrderLineItemElement( + $orderLinesElement, + $lineitem['reference'], + $lineitem['name'], + $lineitem['productType'], + $lineitem['quantity'], + $lineitem['quantityUnit'], + $lineitem['unitPrice'], + $lineitem['taxRate'], + ($totalAmount > 0 ? $totalAmount : $lineitem['totalAmount']), + $lineitem['totalTaxAmount'], + $totaldiscountamount + ); + } + } + + /** + * Add order line item element values to xml + * + * @param SimpleXMLElement $parentElement + * @param string $reference + * @param string $name + * @param string $productType + * @param string $quantity + * @param string $quantityUnit + * @param string $unitPrice + * @param float $taxRate + * @param float $totalAmount + * @param float $totalTaxAmount + * @param float $totalDiscountAmount + */ + private function _addOrderLineItemElement( + $parentElement, + $reference, + $name, + $productType, + $quantity, + $quantityUnit, + $unitPrice, + $taxRate, + $totalAmount, + $totalTaxAmount, + $totalDiscountAmount = 0 + ) { + $unitPrice = sprintf('%0.2f', $unitPrice); + + $lineitem = $parentElement->addChild('lineItem'); + + if ($productType === 'shipping') { + $lineitem->addChild('shippingFee'); + } elseif ($productType === 'downloadable' || $productType === 'virtual' || $productType === 'giftcard') { + $lineitem->addChild('digital'); + } elseif ($productType === 'Store Credit') { + $lineitem->addChild('storeCredit'); + } elseif ($productType === 'Gift Card') { + $lineitem->addChild('giftCard'); + } else { + $lineitem->addChild('physical'); + } + $referenceElement = $lineitem->addChild('reference'); + $this->_addCDATA($referenceElement, $reference); + + $nameElement = $lineitem->addChild('name'); + $this->_addCDATA($nameElement, $name); + + $quantityElement = $lineitem->addChild('quantity'); + $this->_addCDATA($quantityElement, $quantity); + + $quantityUnitElement = $lineitem->addChild('quantityUnit'); + $this->_addCDATA($quantityUnitElement, $quantityUnit); + + $unitPriceElement = $lineitem->addChild('unitPrice'); + $this->_addCDATA($unitPriceElement, $this->_amountAsInt($unitPrice)); + + $taxRateElement = $lineitem->addChild('taxRate'); + $this->_addCDATA($taxRateElement, $this->_amountAsInt($taxRate)); + + $totalAmountElement = $lineitem->addChild('totalAmount'); + $this->_addCDATA($totalAmountElement, $this->_amountAsInt($totalAmount)); + + $totalTaxAmountElement = $lineitem->addChild('totalTaxAmount'); + $this->_addCDATA($totalTaxAmountElement, $this->_amountAsInt($totalTaxAmount)); + + if ($totalDiscountAmount > 0) { + $totalDiscountAmountElement = $lineitem->addChild('totalDiscountAmount'); + $this->_addCDATA($totalDiscountAmountElement, $this->_amountAsInt($totalDiscountAmount)); + } + } +} diff --git a/Model/XmlBuilder/Refund.php b/Model/XmlBuilder/Refund.php index d329e8ca..e7599b31 100644 --- a/Model/XmlBuilder/Refund.php +++ b/Model/XmlBuilder/Refund.php @@ -39,7 +39,22 @@ class Refund * @var mixed */ private $exponent; + /** + * @var \Magento\Framework\App\Config\ScopeConfigInterface + */ + protected $scopeConfig; + /** + * Refund constructor + * + * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig + */ + public function __construct( + \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig + ) { + $this->scopeConfig = $scopeConfig; + } + /** * Build xml for processing Request * @@ -122,11 +137,9 @@ private function _addRefundElement($orderModification, $order, $paymentType) $amountElement['value'] = $this->_amountAsInt($this->amount); $amountElement['currencyCode'] = $this->currencyCode; $amountElement['exponent'] = $this->exponent; - - $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORES; - $level23DataEnabled = $objectManager->get(\Magento\Framework\App\Config\ScopeConfigInterface::class) + $level23DataEnabled = $this->scopeConfig ->getValue('worldpay/level23_config/level23', $storeScope); //Level23 data changes @@ -167,13 +180,12 @@ private function _addBranchSpecificExtension($order, $refund) $purchase->addChild('customerReference', $order->getCustomerId()); } - $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORES; - $cardAcceptorTaxId = $objectManager->get(\Magento\Framework\App\Config\ScopeConfigInterface::class) + $cardAcceptorTaxId = $this->scopeConfig ->getValue('worldpay/level23_config/CardAcceptorTaxId', $storeScope); - $dutyAmount = $objectManager->get(\Magento\Framework\App\Config\ScopeConfigInterface::class) + $dutyAmount = $this->scopeConfig ->getValue('worldpay/level23_config/duty_amount', $storeScope); $purchase->addChild('cardAcceptorTaxId', $cardAcceptorTaxId); diff --git a/Model/XmlBuilder/SEPAOrder.php b/Model/XmlBuilder/SEPAOrder.php new file mode 100644 index 00000000..3e9eb679 --- /dev/null +++ b/Model/XmlBuilder/SEPAOrder.php @@ -0,0 +1,315 @@ + +EOD; + + /** + * @var string + */ + private $merchantCode; + /** + * @var string + */ + private $orderCode; + /** + * @var string + */ + private $orderDescription; + /** + * @var string + */ + private $currencyCode; + /** + * @var float + */ + private $amount; + /** + * @var array + */ + private $paymentDetails; + /** + * @var string + */ + private $shopperEmail; + /** + * @var string + */ + private $acceptHeader; + /** + * @var string + */ + private $userAgentHeader; + /** + * @var array + */ + private $shippingAddress; + /** + * @var array + */ + private $billingAddress; + /** + * @var string + */ + private $shopperId; + /** + * @var array|string + */ + private $statementNarrative; + /** + * @var array|string + */ + private $exponent; + /** + * @var string $captureDelay + */ + private $captureDelay; + + /** + * Build xml for processing Request + * + * @param string $merchantCode + * @param string $orderCode + * @param string $orderDescription + * @param string $currencyCode + * @param float $amount + * @param array $paymentDetails + * @param string $shopperEmail + * @param string $acceptHeader + * @param string $userAgentHeader + * @param string $shippingAddress + * @param float $billingAddress + * @param string $shopperId + * @param string $statementNarrative + * @param string $exponent + * @param string $captureDelay + */ + public function build( + $merchantCode, + $orderCode, + $orderDescription, + $currencyCode, + $amount, + $paymentDetails, + $shopperEmail, + $acceptHeader, + $userAgentHeader, + $shippingAddress, + $billingAddress, + $shopperId, + $statementNarrative, + $exponent, + $captureDelay + ) { + + $this->merchantCode = $merchantCode; + $this->orderCode = $orderCode; + $this->orderDescription = $orderDescription; + $this->currencyCode = $currencyCode; + $this->amount = $amount; + $this->paymentDetails = $paymentDetails; + $this->shopperEmail = $shopperEmail; + $this->acceptHeader = $acceptHeader; + $this->userAgentHeader = $userAgentHeader; + $this->shippingAddress = $shippingAddress; + $this->billingAddress = $billingAddress; + $this->shopperId = $shopperId; + $this->statementNarrative = $statementNarrative; + $this->exponent = $exponent; + $this->captureDelay = $captureDelay; + + $xml = new \SimpleXMLElement(self::ROOT_ELEMENT); + $xml['merchantCode'] = $this->merchantCode; + $xml['version'] = '1.4'; + + $submit = $this->_addSubmitElement($xml); + $this->_addOrderElement($submit); + + return $xml; + } + + /** + * Add submit tag to xml + * + * @param SimpleXMLElement $xml + * @return SimpleXMLElement + */ + private function _addSubmitElement($xml) + { + return $xml->addChild('submit'); + } + + /** + * Add order and its child tag to xml + * + * @param SimpleXMLElement $submit + * @return SimpleXMLElement $order + */ + private function _addOrderElement($submit) + { + $order = $submit->addChild('order'); + $order['orderCode'] = $this->orderCode; + if ($this->captureDelay!="") { + $order['captureDelay'] = $this->captureDelay; + } + $this->_addDescriptionElement($order); + $this->_addAmountElement($order); + $this->_addPaymentDetailsElement($order); + $this->_addShopperElement($order); + $this->_addBillingElement($order); + $this->_addMandateElement($order); + + return $order; + } + + /** + * Add description tag to xml + * + * @param SimpleXMLElement $order + */ + private function _addDescriptionElement($order) + { + $description = $order->addChild('description'); + $this->_addCDATA($description, $this->orderDescription); + } + + /** + * Add amount and its child tag to xml + * + * @param SimpleXMLElement $order + */ + private function _addAmountElement($order) + { + $amountElement = $order->addChild('amount'); + $amountElement['currencyCode'] = $this->currencyCode; + $amountElement['exponent'] = $this->exponent; + $amountElement['value'] = $this->_amountAsInt($this->amount); + } + + /** + * Add paymentDetails and its child tag to xml + * + * @param SimpleXMLElement $order + */ + protected function _addPaymentDetailsElement($order) + { + $paymentDetailsElement = $order->addChild('paymentDetails'); + $sepaElement = $paymentDetailsElement->addChild('SEPA_DIRECT_DEBIT-SSL'); + $sepaElement = $sepaElement->addChild('bankAccount-SEPA'); + $sepaElement->addChild('iban', $this->paymentDetails['sepaIban']); + $sepaElement->addChild('accountHolderName', $this->paymentDetails['sepaAccountHolderName']); + return $paymentDetailsElement; + } + + /** + * Add shopper and its child tag to xml + * + * @param SimpleXMLElement $order + */ + protected function _addShopperElement($order) + { + $shopper = $order->addChild(self::TOKEN_SCOPE); + $shopper->addChild('shopperEmailAddress', $this->shopperEmail); + return $shopper; + } + + /** + * Add billing and its child tag to xml + * + * @param SimpleXMLElement $order + */ + private function _addBillingElement($order) + { + + $billingAddress = $order->addChild('billingAddress'); + $address = $billingAddress->addChild('address'); + + $firstNameElement = $address->addChild('firstName'); + $this->_addCDATA($firstNameElement, $this->billingAddress['firstName']); + + $lastNameElement = $address->addChild('lastName'); + $this->_addCDATA($lastNameElement, $this->billingAddress['lastName']); + + $streetElement = $address->addChild('address1'); + $this->_addCDATA($streetElement, $this->billingAddress['street']); + + $postalCodeElement = $address->addChild('postalCode'); + $postalCode = $this->billingAddress['postalCode']; + //Zip code mandatory for worldpay, if not provided by customer we will pass manually + $zipCode = '00000'; + //If Zip code provided by customer + if ($postalCode) { + $zipCode = $postalCode; + } + $this->_addCDATA($postalCodeElement, $zipCode); + + $cityElement = $address->addChild('city'); + $this->_addCDATA($cityElement, $this->billingAddress['city']); + + if (isset($this->billingAddress['state'])) { + $stateElement = $address->addChild('state'); + $this->_addCDATA($stateElement, $this->billingAddress['state']); + } + + $countryCodeElement = $address->addChild('countryCode'); + $this->_addCDATA($countryCodeElement, $this->billingAddress['countryCode']); + + if (isset($this->billingAddress['telephone'])) { + $telephoneElement = $address->addChild('telephoneNumber'); + $this->_addCDATA($telephoneElement, $this->billingAddress['telephone']); + } + + return $address; + } + + /** + * Add mandate and its child tag to xml + * + * @param SimpleXMLElement $order + */ + protected function _addMandateElement($order) + { + $time = strtotime("now"); + $merchantNumber = $this->paymentDetails['sepaMerchantNumber']; + $mandateId = "M-".$merchantNumber."-".$time; + $mandateElement = $order->addChild('mandate'); + $mandateElement->addChild('mandateType', $this->paymentDetails['sepaMandateType']); + $mandateElement->addChild('mandateId', $mandateId); + return $mandateElement; + } + + /** + * Add cdata to xml + * + * @param SimpleXMLElement $element + * @param string $content + */ + protected function _addCDATA($element, $content) + { + $node = dom_import_simplexml($element); + $no = $node->ownerDocument; + $node->appendChild($no->createCDATASection($content)); + } + + /** + * Returns the rounded value of num to specified precision + * + * @param float $amount + * @return int + */ + private function _amountAsInt($amount) + { + return round($amount, $this->exponent, PHP_ROUND_HALF_EVEN) * pow(10, $this->exponent); + } +} diff --git a/Model/XmlBuilder/SamsungPayOrder.php b/Model/XmlBuilder/SamsungPayOrder.php index b442046e..9026e772 100644 --- a/Model/XmlBuilder/SamsungPayOrder.php +++ b/Model/XmlBuilder/SamsungPayOrder.php @@ -44,6 +44,19 @@ class SamsungPayOrder * @var mixed */ private $exponent; + /** + * @var string $captureDelay + */ + private $captureDelay; + + /** + * @var string + */ + private $shopperEmail; + /** + * @var array + */ + private $data; /** * Build xml for processing Request @@ -57,6 +70,7 @@ class SamsungPayOrder * @param string $shopperEmail * @param array $data * @param mixed $exponent + * @param string $captureDelay * @return SimpleXMLElement $xml */ public function build( @@ -68,7 +82,8 @@ public function build( $paymentType, $shopperEmail, $data, - $exponent + $exponent, + $captureDelay ) { $this->merchantCode = $merchantCode; $this->orderCode = $orderCode; @@ -79,6 +94,7 @@ public function build( $this->shopperEmail = $shopperEmail; $this->data = $data; $this->exponent = $exponent; + $this->captureDelay = $captureDelay; $xml = new \SimpleXMLElement(self::ROOT_ELEMENT); $xml['merchantCode'] = $this->merchantCode; $xml['version'] = '1.4'; @@ -110,6 +126,9 @@ private function _addOrderElement($submit) $order = $submit->addChild('order'); $order['orderCode'] = $this->orderCode; $order['shopperLanguageCode'] = "en"; + if ($this->captureDelay!="") { + $order['captureDelay'] = $this->captureDelay; + } $this->_addDescriptionElement($order); $this->_addAmountElement($order); diff --git a/Model/XmlBuilder/TokenDelete.php b/Model/XmlBuilder/TokenDelete.php index a031c327..5498fa3d 100644 --- a/Model/XmlBuilder/TokenDelete.php +++ b/Model/XmlBuilder/TokenDelete.php @@ -19,12 +19,12 @@ class TokenDelete EOD; /** - * @var Mage_Customer_Model_Customer + * @var \Magento\Customer\Model\Customer */ private $customer; /** - * @var Sapient_WorldPay_Model_Token + * @var \Sapient\WorldPay\Model\Token */ private $tokenModel; diff --git a/Model/XmlBuilder/TokenInquiry.php b/Model/XmlBuilder/TokenInquiry.php index d696451d..2865c4d8 100644 --- a/Model/XmlBuilder/TokenInquiry.php +++ b/Model/XmlBuilder/TokenInquiry.php @@ -19,12 +19,12 @@ class TokenInquiry EOD; /** - * @var Mage_Customer_Model_Customer + * @var \Magento\Customer\Model\Customer */ private $customer; /** - * @var Sapient_WorldPay_Model_Token + * @var \Sapient\WorldPay\Model\Token */ private $tokenModel; diff --git a/Model/XmlBuilder/TokenUpdate.php b/Model/XmlBuilder/TokenUpdate.php index 3e3ac5a8..3da7352a 100644 --- a/Model/XmlBuilder/TokenUpdate.php +++ b/Model/XmlBuilder/TokenUpdate.php @@ -19,12 +19,12 @@ class TokenUpdate EOD; /** - * @var Mage_Customer_Model_Customer + * @var \Magento\Customer\Model\Customer */ private $customer; /** - * @var Sapient_WorldPay_Model_Token + * @var \Sapient\WorldPay\Model\Token */ private $tokenModel; diff --git a/Model/XmlBuilder/VoidSale.php b/Model/XmlBuilder/VoidSale.php index 0a86df12..dd97dc31 100644 --- a/Model/XmlBuilder/VoidSale.php +++ b/Model/XmlBuilder/VoidSale.php @@ -44,7 +44,7 @@ class VoidSale * @param float $amount * @param float $exponent * @param string|null $paymentType - * @return SimpleXMLElement $xml + * @return \SimpleXMLElement $xml */ public function build($merchantCode, $orderCode, $currencyCode, $amount, $exponent, $paymentType = null) { diff --git a/Model/XmlBuilder/WalletOrder.php b/Model/XmlBuilder/WalletOrder.php index 8fbb1d50..82794008 100644 --- a/Model/XmlBuilder/WalletOrder.php +++ b/Model/XmlBuilder/WalletOrder.php @@ -57,13 +57,18 @@ class WalletOrder */ private $sessionId; /** - * @var Sapient\Worldpay\Model\XmlBuilder\Config\ThreeDSecure + * @var \Sapient\Worldpay\Model\XmlBuilder\Config\ThreeDSecure */ protected $threeDSecureConfig; /** * @var string */ private $cusDetails; + + /** + * @var string + */ + private $shopperEmail; /** * @var string */ @@ -84,7 +89,30 @@ class WalletOrder * @var string */ protected $userAgentHeader; - + /** + * @var string $captureDelay + */ + protected $captureDelay; + + /** + * @var string + */ + protected $protocolVersion; + + /** + * @var string + */ + protected $signature; + + /** + * @var string + */ + protected $signedMessage; + + /** + * @var array + */ + protected $billingAddress; /** * Constructor * @@ -119,7 +147,8 @@ public function __construct(array $args = []) * @param string $shopperIpAddress * @param array $paymentDetails * @param float $exponent - * @return SimpleXMLElement $xml + * @param string $captureDelay + * @return \SimpleXMLElement $xml */ public function build( $merchantCode, @@ -139,7 +168,8 @@ public function build( $cusDetails, $shopperIpAddress, $paymentDetails, - $exponent + $exponent, + $captureDelay ) { $this->merchantCode = $merchantCode; $this->orderCode = $orderCode; @@ -159,6 +189,7 @@ public function build( $this->shopperIpAddress = $shopperIpAddress; $this->paymentDetails = $paymentDetails; $this->exponent = $exponent; + $this->captureDelay = $captureDelay; $xml = new \SimpleXMLElement(self::ROOT_ELEMENT); $xml['merchantCode'] = $this->merchantCode; $xml['version'] = '1.4'; @@ -258,6 +289,9 @@ private function _addOrderElement($submit) $session['id'] = $this->paymentDetails['sessionId']; return $order; } + if ($this->captureDelay!="") { + $order['captureDelay'] = $this->captureDelay; + } $order['shopperLanguageCode'] = "en"; $this->_addDescriptionElement($order); $this->_addAmountElement($order); diff --git a/Observer/AddtoCartBefore.php b/Observer/AddtoCartBefore.php index 75eb18cd..9436e2a9 100644 --- a/Observer/AddtoCartBefore.php +++ b/Observer/AddtoCartBefore.php @@ -12,11 +12,49 @@ class AddtoCartBefore implements ObserverInterface { - /** - * @var \Sapient\Worldpay\Helper\Recurring - */ + /** + * @var \Sapient\Worldpay\Logger\WorldpayLogger + */ private $wplogger; + /** + * @var \Magento\Quote\Api\CartRepositoryInterface + */ + private $quoteRepository; + /** + * @var \Magento\Customer\Model\Session + */ + private $customerSession; + + /** + * @var \Magento\Checkout\Model\Cart + */ + private $customerCart; + + /** + * @var \Sapient\Worldpay\Helper\Data + */ + private $wpHelper; + + /** + * @var \Magento\Quote\Model\QuoteManagement + */ + private $quoteManagement; + + /** + * @var \Magento\Customer\Api\CustomerRepositoryInterface + */ + private $customerRepository; + + /** + * @var \Magento\Store\Model\StoreManagerInterface + */ + private $storeManager; + + /** + * @var \Magento\Checkout\Model\Session + */ + private $checkoutSession; /** * Constructor function * diff --git a/Observer/AfterPlaceOrder.php b/Observer/AfterPlaceOrder.php index 1e78b404..1f69fc48 100644 --- a/Observer/AfterPlaceOrder.php +++ b/Observer/AfterPlaceOrder.php @@ -11,11 +11,36 @@ class AfterPlaceOrder implements ObserverInterface { - /** - * @var \Sapient\Worldpay\Helper\Recurring - */ + /** + * @var \Sapient\Worldpay\Helper\Recurring + */ private $wplogger; + /** + * @var \Magento\Quote\Api\CartRepositoryInterface + */ + private $quoteRepository; + + /** + * @var \Magento\Checkout\Model\Session + */ + private $checkoutSession; + + /** + * @var \Magento\Customer\Model\Session + */ + private $customerSession; + + /** + * @var \Magento\Framework\Controller\ResultFactory + */ + private $responseFactory; + + /** + * @var \Magento\Customer\CustomerData\SectionPoolInterface + */ + private $sectionPoolInterface; + /** * Constructor function * diff --git a/Observer/CheckoutCartUpdateItemsAfterObserver.php b/Observer/CheckoutCartUpdateItemsAfterObserver.php index aff468d0..8a968c83 100644 --- a/Observer/CheckoutCartUpdateItemsAfterObserver.php +++ b/Observer/CheckoutCartUpdateItemsAfterObserver.php @@ -36,10 +36,13 @@ public function execute(\Magento\Framework\Event\Observer $observer) $info = $observer->getEvent()->getInfo(); foreach ($info->getData() as $itemId => $itemInfo) { - $item = $quote->getItemById($itemId); - if ($this->recurringHelper->getSelectedPlan($item->getProduct())) { - $item->setQty(1); + if (!empty($itemInfo)) { + $item = $quote->getItemById($itemId); + if ($this->recurringHelper->getSelectedPlan($item->getProduct())) { + $item->setQty(1); + } } + } } } diff --git a/Observer/MultishippingLayoutLoadBefore.php b/Observer/MultishippingLayoutLoadBefore.php new file mode 100644 index 00000000..3f22eec4 --- /dev/null +++ b/Observer/MultishippingLayoutLoadBefore.php @@ -0,0 +1,53 @@ +helper = $helper; + $this->wplogger = $wplogger; + } + + /** + * Change multishipping checkout layout based on configuration + * + * @param \Magento\Framework\Event\Observer $observer + */ + public function execute(Observer $observer) + { + $layout = $observer->getEvent()->getLayout(); + $controllerAction = $observer->getEvent()->getFullActionName(); + if ($controllerAction == 'multishipping_checkout_billing') { + if ($this->helper->isWorldPayEnable() && $this->helper->isMultishippingEnabled()) { + $layout->getUpdate()->addHandle("wp_multishipping_checkout_billing"); + } else { + $layout->getUpdate()->addHandle("multishipping_checkout_billing"); + } + } + } +} diff --git a/Observer/SalesServiceQuoteSubmitBeforeObserver.php b/Observer/SalesServiceQuoteSubmitBeforeObserver.php index 5b72261a..e5234719 100644 --- a/Observer/SalesServiceQuoteSubmitBeforeObserver.php +++ b/Observer/SalesServiceQuoteSubmitBeforeObserver.php @@ -24,7 +24,10 @@ class SalesServiceQuoteSubmitBeforeObserver implements ObserverInterface * @var \Sapient\Worldpay\Model\Recurring\Order\Address\ToSubscriptionAddress */ private $orderAddressToSubscriptionAddress; - + /** + * @var \Magento\Framework\DataObject\Copy + */ + private $objectCopyService; /** * @param \Sapient\Worldpay\Helper\Recurring $recurringHelper * @param \Sapient\Worldpay\Model\Recurring\Order\Item\ToSubscription $orderItemToSubscription diff --git a/Plugin/Checkout/Block/Onepage.php b/Plugin/Checkout/Block/Onepage.php index 274ca2c0..0c4aa674 100644 --- a/Plugin/Checkout/Block/Onepage.php +++ b/Plugin/Checkout/Block/Onepage.php @@ -20,7 +20,7 @@ class Onepage */ private $checkoutSession; /** - * @var Magento\Framework\Serialize\Serializer\Json + * @var \Magento\Framework\Serialize\Serializer\Json */ protected $serializer; diff --git a/Plugin/Checkout/CustomerData/Cart.php b/Plugin/Checkout/CustomerData/Cart.php index 872c7b63..e9e4ebdd 100644 --- a/Plugin/Checkout/CustomerData/Cart.php +++ b/Plugin/Checkout/CustomerData/Cart.php @@ -35,7 +35,12 @@ class Cart protected $wplogger; /** - * @var quoteIdToMaskedQuoteId + * @var \Sapient\Worldpay\Helper\Data + */ + protected $wpHelper; + + /** + * @var QuoteIdToMaskedQuoteIdInterface */ protected $quoteIdToMaskedQuoteId; diff --git a/Plugin/Checkout/CustomerData/Customer.php b/Plugin/Checkout/CustomerData/Customer.php index c25be98d..57eb6bbb 100644 --- a/Plugin/Checkout/CustomerData/Customer.php +++ b/Plugin/Checkout/CustomerData/Customer.php @@ -17,15 +17,30 @@ class Customer { /** - * @var wplogger + * @var \Sapient\Worldpay\Logger\WorldpayLogger */ protected $wplogger; /** - * @var currentCustomer + * @var \Sapient\Worldpay\Helper\Data */ + protected $wpHelper; + + /** + * @var CurrentCustomer + */ protected $currentCustomer; + /** + * @var CustomerAddressDataProvider + */ + protected $customerAddressData; + + /** + * @var CustomerRepository + */ + protected $customerRepository; + /** * Constructor Function * diff --git a/Plugin/GuestPaymentInformationManagement.php b/Plugin/GuestPaymentInformationManagement.php index b187130c..00848353 100644 --- a/Plugin/GuestPaymentInformationManagement.php +++ b/Plugin/GuestPaymentInformationManagement.php @@ -24,7 +24,7 @@ class GuestPaymentInformationManagement */ private $cartManagement; /** - * @var LoggerInterface + * @var WorldpayLogger */ private $logger; /** @@ -39,7 +39,7 @@ class GuestPaymentInformationManagement /** * GuestPaymentInformationManagement constructor. * @param GuestCartManagementInterface $cartManagement - * @param LoggerInterface $logger + * @param WorldpayLogger $logger * @param MethodList $methodList * @param bool $checkMethods */ diff --git a/Plugin/PaymentInformationManagement.php b/Plugin/PaymentInformationManagement.php index ff70d0ae..6d33127a 100644 --- a/Plugin/PaymentInformationManagement.php +++ b/Plugin/PaymentInformationManagement.php @@ -22,7 +22,7 @@ class PaymentInformationManagement */ private $cartManagement; /** - * @var LoggerInterface + * @var WorldpayLogger */ private $logger; /** @@ -37,7 +37,7 @@ class PaymentInformationManagement /** * PaymentInformationManagement constructor. * @param CartManagementInterface $cartManagement - * @param LoggerInterface $logger + * @param WorldpayLogger $logger * @param MethodList $methodList * @param bool $checkMethods */ diff --git a/Plugin/PluginBefore.php b/Plugin/PluginBefore.php index c7f7b164..b77dfe0b 100644 --- a/Plugin/PluginBefore.php +++ b/Plugin/PluginBefore.php @@ -15,6 +15,43 @@ */ class PluginBefore { + /** + * @var \Magento\Framework\UrlInterface + */ + public $_urlBuilder; + /** + * @var \Magento\Sales\Model\Order + */ + public $order; + /** + * @var \Magento\Framework\App\RequestInterface + */ + public $request; + /** + * @var \Sapient\Worldpay\Model\Worldpayment + */ + public $worldpaypaymentmodel; + /** + * @var \Magento\Framework\Stdlib\DateTime\DateTime + */ + public $objDate; + /** + * @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface + */ + public $timeobj; + /** + * @var \Sapient\Worldpay\Model\Worldpayment + */ + public $worldpaymodel; + /** + * @var \Sapient\Worldpay\Helper\Data + */ + public $worldpayHelper; + + /** + * @var object + */ + public $_request; /** * PluginBefore constructor @@ -22,17 +59,29 @@ class PluginBefore * @param \Magento\Framework\UrlInterface $urlBuilder * @param \Magento\Sales\Model\Order $order * @param RequestInterface $request + * @param \Sapient\Worldpay\Model\Worldpayment $worldpaypaymentmodel + * @param \Magento\Framework\Stdlib\DateTime\DateTime $objDate + * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $timeobj + * @param \Sapient\Worldpay\Model\Worldpayment $worldpaymodel * @param Data $worldpayHelper */ public function __construct( \Magento\Framework\UrlInterface $urlBuilder, \Magento\Sales\Model\Order $order, RequestInterface $request, + \Sapient\Worldpay\Model\Worldpayment $worldpaypaymentmodel, + \Magento\Framework\Stdlib\DateTime\DateTime $objDate, + \Magento\Framework\Stdlib\DateTime\TimezoneInterface $timeobj, + \Sapient\Worldpay\Model\Worldpayment $worldpaymodel, Data $worldpayHelper ) { $this->_urlBuilder = $urlBuilder; $this->order = $order; $this->request = $request; + $this->worldpaypaymentmodel = $worldpaypaymentmodel; + $this->objDate = $objDate; + $this->timeobj = $timeobj; + $this->worldpaymodel = $worldpaymodel; $this->worldpayHelper = $worldpayHelper; } @@ -66,37 +115,40 @@ public function beforePushButtons( ['label' => __('Sync Status'), 'onclick' => 'setLocation("'.$syncurl.'")', 'class' => 'reset'], -1 ); - } + //Cancel button function to send order-modification request to Cancel Order. - $cancelurl = $this->_urlBuilder->getUrl( - "worldpay/cancel/index", - ['order_id' => $orderId] - ); - $buttonList->remove('order_cancel'); - $buttonList->add('cancel', ['label' => __('Cancel'), + $cancelurl = $this->_urlBuilder->getUrl( + "worldpay/cancel/index", + ['order_id' => $orderId] + ); + $buttonList->remove('order_cancel'); + $buttonList->add('cancel', ['label' => __('Cancel'), 'onclick' => 'setLocation("' . $cancelurl . '")', 'class' => 'cancel'], -1); //Void Sale changes - $data = $order->getData(); - $paymenttype = $this->getPaymentType($data['increment_id']); - if ($this->checkEligibilityForVoidSale($order)) { + $data = $order->getData(); + $paymenttype = $this->getPaymentType($data['increment_id']); + if ($this->checkEligibilityForVoidSale($order)) { $buttonList->remove('void_payment'); $voidsaleurl = $this->_urlBuilder->getUrl( "worldpay/voidsale/index", ['order_id' => $orderId] ); - $buttonList->add( - 'void_sale', - ['label' => __('Void Sale'), - 'onclick' => 'setLocation("' . $voidsaleurl . '")', - 'class' => 'void'], - -1 - ); - } - if ($paymenttype === 'ACH_DIRECT_DEBIT-SSL' || $this->isPrimeRoutingRequest($data['increment_id'])) { - $buttonList->remove('void_payment'); - $this->removeShipmentButton($order, $buttonList); + $buttonList->add( + 'void_sale', + ['label' => __('Void Sale'), + 'onclick' => 'setLocation("' . $voidsaleurl . '")', + 'class' => 'void'], + -1 + ); + } + if ($paymenttype === 'ACH_DIRECT_DEBIT-SSL' || + $paymenttype === 'SEPA_DIRECT_DEBIT-SSL' || + $this->isPrimeRoutingRequest($data['increment_id'])) { + $buttonList->remove('void_payment'); + $this->removeShipmentButton($order, $buttonList); + } } } @@ -111,13 +163,10 @@ public function beforePushButtons( */ public function getOrderDateDetails($order) { - $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $orderdate=$order->getCreatedAt(); - $objDate = $objectManager->create(\Magento\Framework\Stdlib\DateTime\DateTime::class); - $currentdate = $objDate->Date(); - $timeobj= $objectManager->create(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class); - $formattedCurrentDate=$timeobj->formatDate($currentdate, \IntlDateFormatter::SHORT); - $formattedOrderDate=$timeobj->formatDate($orderdate, \IntlDateFormatter::SHORT); + $currentdate = $this->objDate->Date(); + $formattedCurrentDate=$this->timeobj->formatDate($currentdate, \IntlDateFormatter::SHORT); + $formattedOrderDate=$this->timeobj->formatDate($orderdate, \IntlDateFormatter::SHORT); if ($formattedCurrentDate===$formattedOrderDate) { return true; @@ -134,9 +183,7 @@ public function getOrderDateDetails($order) */ public function getPaymentType($orderid) { - $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); - $worldpaymodel = $objectManager->create(\Sapient\Worldpay\Model\Worldpayment::class); - $worldpaydata=$worldpaymodel->loadByPaymentId($orderid); + $worldpaydata=$this->worldpaymodel->loadByPaymentId($orderid); return $worldpaydata->getPaymentType(); } @@ -170,9 +217,7 @@ public function checkEligibilityForVoidSale($order) */ public function isPrimeRoutingRequest($orderid) { - $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); - $worldpaymodel = $objectManager->create(\Sapient\Worldpay\Model\Worldpayment::class); - $worldpaydata=$worldpaymodel->loadByPaymentId($orderid); + $worldpaydata=$this->worldpaymodel->loadByPaymentId($orderid); if ($worldpaydata->getIsPrimeroutingEnabled()) { return true; diff --git a/Plugin/SalesOrderGridPlugin.php b/Plugin/SalesOrderGridPlugin.php new file mode 100644 index 00000000..6f17869c --- /dev/null +++ b/Plugin/SalesOrderGridPlugin.php @@ -0,0 +1,33 @@ +isLoaded()) { + $orderIncrementColumnName = 'increment_id'; + $tableName = $subject->getResource()->getTable('worldpay_payment'); + + $subject->getSelect()->joinLeft( + $tableName, + $tableName . '.order_id = main_table.' . $orderIncrementColumnName, + $tableName . '.merchant_id' + ); + } + return [$printQuery, $logQuery]; + } +} diff --git a/README.txt b/README.txt index 0d190db8..ee2abc1e 100644 --- a/README.txt +++ b/README.txt @@ -2,6 +2,10 @@ Latest releases for all supported version: For Magento 2.4.5 +Worldpay Plugin version: 2.4.5-p20823 +1. Magento 2.4.5-p2 compatible +2. SEPA Direct Debit + Worldpay Plugin version: 2.4.5-p10123 1. Magento 2.4.5-p1 compatible 2. Pay by link feature diff --git a/Setup/Patch/Data/DefaultConfigurations.php b/Setup/Patch/Data/DefaultConfigurations.php index 083ab489..acf3b78d 100644 --- a/Setup/Patch/Data/DefaultConfigurations.php +++ b/Setup/Patch/Data/DefaultConfigurations.php @@ -1742,6 +1742,21 @@ public function addExtraCheckoutLabels() 'wpay_label_code' => 'CO28', 'wpay_label_desc'=> $iframeCheckOutMsg, 'wpay_custom_label'=> "" + ], + [ + 'wpay_label_code' => 'CO29', + 'wpay_label_desc'=> 'Mandate Type', + 'wpay_custom_label'=> '' + ], + [ + 'wpay_label_code' => 'CO30', + 'wpay_label_desc'=> 'IBAN', + 'wpay_custom_label'=> '' + ], + [ + 'wpay_label_code' => 'CO31', + 'wpay_label_desc'=> "Account Holder Name", + 'wpay_custom_label'=> '' ] ]; foreach ($newLabels as $label) { diff --git a/Test/Unit/Helper/DataTest.php b/Test/Unit/Helper/DataTest.php index b1be6f76..49d94951 100644 --- a/Test/Unit/Helper/DataTest.php +++ b/Test/Unit/Helper/DataTest.php @@ -91,13 +91,17 @@ class DataTest extends TestCase /** * @var string */ - protected $APM_TYPES = 'CHINAUNIONPAY-SSL,IDEAL-SSL,QIWI-SSL,PAYPAL-EXPRESS,' + protected $APM_TYPES = 'CHINAUNIONPAY-SSL,IDEAL-SSL,PAYPAL-EXPRESS,' . 'SOFORT-SSL,GIROPAY-SSL,ALIPAY-SSL,SEPA_DIRECT_DEBIT-SSL,' . 'KLARNA-SSL,PRZELEWY-SSL,MISTERCASH-SSL,ACH_DIRECT_DEBIT-SSL'; /** * @var string */ protected $ACH_BANK_ACC_TYPES = 'Checking,Savings,Corporate,Corp Savings'; + /** + * @var string + */ + protected $SEPA_MANDATE_TYPES = 'ONE-OFF, RECURRING'; /** * @var string */ @@ -110,7 +114,6 @@ class DataTest extends TestCase protected $ALL_APM_METHODS = [ 'CHINAUNIONPAY-SSL' => 'Union Pay', 'IDEAL-SSL' => 'IDEAL', - 'QIWI-SSL' => 'Qiwi', //'YANDEXMONEY-SSL' => 'Yandex.Money', 'PAYPAL-EXPRESS' => 'PayPal', 'SOFORT-SSL' => 'SoFort EU', @@ -394,7 +397,6 @@ public function testGetApmTypes() ->withConsecutive( ['worldpay_apm','CHINAUNIONPAY-SSL'], ['worldpay_apm','IDEAL-SSL'], - ['worldpay_apm','QIWI-SSL'], ['worldpay_apm','PAYPAL-EXPRESS'], ['worldpay_apm','SOFORT-SSL'], ['worldpay_apm','GIROPAY-SSL'], @@ -425,7 +427,6 @@ public function testGetACHDetails() ->withConsecutive( ['worldpay_apm','CHINAUNIONPAY-SSL'], ['worldpay_apm','IDEAL-SSL'], - ['worldpay_apm','QIWI-SSL'], ['worldpay_apm','PAYPAL-EXPRESS'], ['worldpay_apm','SOFORT-SSL'], ['worldpay_apm','GIROPAY-SSL'], @@ -439,7 +440,7 @@ public function testGetACHDetails() ->willReturn(true); $this->assertEquals(explode(",", $this->ACH_BANK_ACC_TYPES), $this->dataObj->getACHDetails()); } - + public function testGetACHBankAccountTypes() { $this->scopeConfigMock->expects($this->any()) @@ -448,7 +449,46 @@ public function testGetACHBankAccountTypes() ->willReturn($this->ACH_BANK_ACC_TYPES); $this->assertEquals($this->ACH_BANK_ACC_TYPES, $this->dataObj->getACHBankAccountTypes()); } - + + public function testGetSEPADetails() + { + $this->scopeConfigMock->expects($this->any()) + ->method('getValue') + ->withConsecutive( + ['worldpay/cc_config/integration_mode',\Magento\Store\Model\ScopeInterface::SCOPE_STORE], + ['worldpay/apm_config/paymentmethods',\Magento\Store\Model\ScopeInterface::SCOPE_STORE], + ['worldpay/apm_config/sepa_mandate_types',\Magento\Store\Model\ScopeInterface::SCOPE_STORE] + ) + ->will($this->onConsecutiveCalls('Direct', $this->APM_TYPES, $this->SEPA_MANDATE_TYPES)); + + $this->paymentlist->expects($this->any()) + ->method('checkCurrency') + ->withConsecutive( + ['worldpay_apm','CHINAUNIONPAY-SSL'], + ['worldpay_apm','IDEAL-SSL'], + ['worldpay_apm','PAYPAL-EXPRESS'], + ['worldpay_apm','SOFORT-SSL'], + ['worldpay_apm','GIROPAY-SSL'], + ['worldpay_apm','ALIPAY-SSL'], + ['worldpay_apm','SEPA_DIRECT_DEBIT-SSL'], + ['worldpay_apm','KLARNA-SSL'], + ['worldpay_apm','PRZELEWY-SSL'], + ['worldpay_apm','MISTERCASH-SSL'], + ['worldpay_apm','ACH_DIRECT_DEBIT-SSL'] + ) + ->willReturn(true); + $this->assertEquals(explode(",", $this->SEPA_MANDATE_TYPES), $this->dataObj->getSEPADetails()); + } + + public function testGetSEPAMandateTypes() + { + $this->scopeConfigMock->expects($this->any()) + ->method('getValue') + ->with('worldpay/apm_config/sepa_mandate_types', \Magento\Store\Model\ScopeInterface::SCOPE_STORE) + ->willReturn($this->SEPA_MANDATE_TYPES); + $this->assertEquals($this->SEPA_MANDATE_TYPES, $this->dataObj->getSEPAMandateTypes()); + } + public function testIsIframeIntegration() { $this->scopeConfigMock->expects($this->any()) diff --git a/Test/Unit/Model/Config/Source/PaymentMethodsApmTest.php b/Test/Unit/Model/Config/Source/PaymentMethodsApmTest.php index 33db484e..e1971ebb 100644 --- a/Test/Unit/Model/Config/Source/PaymentMethodsApmTest.php +++ b/Test/Unit/Model/Config/Source/PaymentMethodsApmTest.php @@ -37,7 +37,6 @@ public function testToOptionArray() $expectedResult = [ ['value' => 'CHINAUNIONPAY-SSL', 'label' => __('Union Pay')], ['value' => 'IDEAL-SSL', 'label' => __('IDEAL')], - ['value' => 'QIWI-SSL', 'label' => __('Qiwi')], // ['value' => 'YANDEXMONEY-SSL', 'label' => __('Yandex.Money')], ['value' => 'PAYPAL-EXPRESS', 'label' => __('PayPal')], ['value' => 'SOFORT-SSL', 'label' => __('SoFort EU')], diff --git a/Test/Unit/Model/Config/Source/SEPAMandateTypesTest.php b/Test/Unit/Model/Config/Source/SEPAMandateTypesTest.php new file mode 100644 index 00000000..e53df84f --- /dev/null +++ b/Test/Unit/Model/Config/Source/SEPAMandateTypesTest.php @@ -0,0 +1,43 @@ +getMockBuilder(Context::class) + ->disableOriginalConstructor()->getMock(); + $registryMock = $this->getMockBuilder(Registry::class) + ->disableOriginalConstructor()->getMock(); + $configMock = $this->getMockBuilder(ScopeConfigInterface::class) + ->disableOriginalConstructor()->getMock(); + $cacheTypeListMock = $this->getMockBuilder(TypeListInterface::class) + ->disableOriginalConstructor()->getMock(); + $this->model = new SEPAMandateTypes($contextMock, $registryMock, $configMock, $cacheTypeListMock); + } + + public function testToOptionArray() + { + $expectedResult = [ + ['value' => 'ONE-OFF', 'label' => __('ONE-OFF')], + ['value' => 'RECURRING', 'label' => __('RECURRING')] + ]; + $this->assertEquals($expectedResult, $this->model->toOptionArray()); + } +} diff --git a/Test/Unit/Model/WorldpayConfigProviderTest.php b/Test/Unit/Model/WorldpayConfigProviderTest.php index 260e794d..1da4f8d3 100644 --- a/Test/Unit/Model/WorldpayConfigProviderTest.php +++ b/Test/Unit/Model/WorldpayConfigProviderTest.php @@ -44,7 +44,6 @@ class WorldpayConfigProviderTest extends TestCase protected $ALL_APM_METHODS = [ 'CHINAUNIONPAY-SSL' => 'Union Pay', 'IDEAL-SSL' => 'IDEAL', - 'QIWI-SSL' => 'Qiwi', //'YANDEXMONEY-SSL' => 'Yandex.Money', 'PAYPAL-EXPRESS' => 'PayPal', 'SOFORT-SSL' => 'SoFort EU', diff --git a/Ui/Component/Listing/Column/FraudisightMessage.php b/Ui/Component/Listing/Column/FraudisightMessage.php index 5192e476..a348ffd1 100644 --- a/Ui/Component/Listing/Column/FraudisightMessage.php +++ b/Ui/Component/Listing/Column/FraudisightMessage.php @@ -41,6 +41,12 @@ class FraudisightMessage extends Column * @var OrderRepositoryInterface */ protected $_orderRepository; + + /** + * + * @var Data + */ + protected $helper; /** * FraudisightMessage constructor @@ -81,6 +87,9 @@ public function prepareDataSource(array $dataSource) { if (isset($dataSource['data']['items'])) { foreach ($dataSource['data']['items'] as & $item) { + if(!in_array($item['payment_method'],$this->helper->getWpPaymentMethods())){ + continue; + } $worldpaypayment=$this->_worldpaypayment->loadByPaymentId($item["increment_id"]); $fraudsightMessage = $worldpaypayment->getFraudsightMessage(); diff --git a/Ui/Component/Listing/Column/InvoiceStatus.php b/Ui/Component/Listing/Column/InvoiceStatus.php index d2845f18..1268544d 100644 --- a/Ui/Component/Listing/Column/InvoiceStatus.php +++ b/Ui/Component/Listing/Column/InvoiceStatus.php @@ -39,6 +39,12 @@ class InvoiceStatus extends Column * @var OrderRepositoryInterface */ protected $_orderRepository; + + /** + * + * @var Data + */ + protected $helper; /** * Invoice Status constructor @@ -76,6 +82,9 @@ public function prepareDataSource(array $dataSource) { if (isset($dataSource['data']['items'])) { foreach ($dataSource['data']['items'] as & $item) { + if(!in_array($item['payment_method'],$this->helper->getWpPaymentMethods())){ + continue; + } $order = $this->_orderRepository->get($item['entity_id']); if ($order->hasInvoices()) { if ($order->getBaseTotalDue() == 0) { diff --git a/Ui/Component/Listing/Column/MerchantId.php b/Ui/Component/Listing/Column/MerchantId.php new file mode 100644 index 00000000..5907d329 --- /dev/null +++ b/Ui/Component/Listing/Column/MerchantId.php @@ -0,0 +1,117 @@ +_worldpaypayment = $_worldpaypayment; + $this->_orderRepository = $orderRepository; + $this->_searchCriteria = $criteria; + $this->helper = $helper; + parent::__construct($context, $uiComponentFactory, $components, $data); + } + + /** + * Prepare Data Source + * + * @param array $dataSource + * @return array + */ + public function prepareDataSource(array $dataSource) + { + if (isset($dataSource['data']['items'])) { + foreach ($dataSource['data']['items'] as & $item) { + if(!in_array($item['payment_method'],$this->helper->getWpPaymentMethods())){ + continue; + } + $worldpaypayment =$this->_worldpaypayment->loadByPaymentId($item["increment_id"]); + $merchantId = $worldpaypayment->getMerchantId(); + if (empty($merchantId)) { + $merchantId = 'N/A'; + } + $item[$this->getData('name')] = strtoupper($merchantId); + } + } + + return $dataSource; + } + + /** + * Prepare component configuration + * + * @return void + */ + public function prepare() + { + parent::prepare(); + if ($this->helper->isWorldPayEnable()) { + $this->_data['config']['componentDisabled'] = false; + } else { + $this->_data['config']['componentDisabled'] = true; + } + } +} diff --git a/Ui/Component/Listing/Column/MultishippingId.php b/Ui/Component/Listing/Column/MultishippingId.php index 6a8aeec7..67ca4535 100644 --- a/Ui/Component/Listing/Column/MultishippingId.php +++ b/Ui/Component/Listing/Column/MultishippingId.php @@ -39,6 +39,12 @@ class MultishippingId extends Column * @var OrderRepositoryInterface */ protected $_orderRepository; + + /** + * + * @var Data + */ + protected $helper; /** * Mulishipping Id constructor @@ -79,6 +85,9 @@ public function prepareDataSource(array $dataSource) { if (isset($dataSource['data']['items'])) { foreach ($dataSource['data']['items'] as & $item) { + if(!in_array($item['payment_method'],$this->helper->getWpPaymentMethods())){ + continue; + } $worldpaypayment=$this->_worldpaypayment->loadByPaymentId($item["increment_id"]); $isMultishipping = $worldpaypayment->getIsMultishippingOrder(); if ($isMultishipping) { diff --git a/Ui/Component/Listing/Column/WorldpayPaymentStatus.php b/Ui/Component/Listing/Column/WorldpayPaymentStatus.php index 6c51fd1c..aaa57471 100644 --- a/Ui/Component/Listing/Column/WorldpayPaymentStatus.php +++ b/Ui/Component/Listing/Column/WorldpayPaymentStatus.php @@ -39,6 +39,12 @@ class WorldpayPaymentStatus extends Column * @var OrderRepositoryInterface */ protected $_orderRepository; + + /** + * + * @var Data + */ + protected $helper; /** * Worldpay Payment Status constructor @@ -79,6 +85,9 @@ public function prepareDataSource(array $dataSource) { if (isset($dataSource['data']['items'])) { foreach ($dataSource['data']['items'] as & $item) { + if(!in_array($item['payment_method'],$this->helper->getWpPaymentMethods())){ + continue; + } $worldpaypayment=$this->_worldpaypayment->loadByPaymentId($item["increment_id"]); $paymentStatus = $worldpaypayment->getPaymentStatus(); if (empty($paymentStatus)) { diff --git a/composer.json b/composer.json index d49026c2..42b6b4c8 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ "magento/module-quote": ">=100.0.0", "magento/module-vault": ">=100.0.0" }, - "version": "2.4.5-p10123", + "version": "2.4.5-p20823", "license":"proprietary", "autoload":{ "files":[ diff --git a/etc/adminhtml/di.xml b/etc/adminhtml/di.xml index b680b500..97012318 100644 --- a/etc/adminhtml/di.xml +++ b/etc/adminhtml/di.xml @@ -12,4 +12,9 @@ - \ No newline at end of file + + + + + + diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 9e4207a5..a6d73fed 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -347,11 +347,11 @@ - Location of the ApplePay.key.pem. eg. /var/www/html/cert/. Files should be have read access by the webserver + Location of the ApplePay.key.pem. eg. /var/www/html/cert/ApplePay.key.pem. Files should be have read access by the webserver - Location of the ApplePay.crt.pem. eg. /var/www/html/cert/. Files should be have read access by the webserver + Location of the ApplePay.crt.pem. eg. /var/www/html/cert/ApplePay.crt.pem. Files should be have read access by the webserver @@ -477,17 +477,31 @@ Magento\Config\Model\Config\Source\Yesno - + + + + Sapient\Worldpay\Model\Config\Source\PaymentMethodsApm - + Sapient\Worldpay\Model\Config\Source\ACHAccountTypes - - + + + Sapient\Worldpay\Model\Config\Source\SEPAMandateTypes + + + + For this detail, You must connect with your Worldpay contact. + + + + You must ensure you display the official wording to your shoppers so they can agree to be debited. This is official wording which is to be used to constitute a SEPA-compliant mandate. Without this official wording, shoppers can easily reverse the direct debit with their bank.. + + @@ -1095,25 +1109,6 @@ 1 - - - - - Magento\Config\Model\Config\Source\Yesno - - - - Sapient\Worldpay\Model\Config\Backend\Image - sapient_worldpay/images - sapient_worldpay/images - -
    -
  • Recommended size: Logo size should be (50*30)px and Max upto 50KB.
  • -
- ]]>
- 1 -
-
@@ -1266,11 +1261,31 @@ - + Magento\Config\Model\Config\Source\Yesno Set to yes if you want to enable the Worldpay Payment methods on multishipping orders. + + + 1 + Enter the merchant code for Multishipping orders. If it is blank, global merchant code entered under General configuration will be applicable. + + + + 1 + Enter the merchant username for Multishipping orders. If it is blank, global merchant username entered under General configuration will be applicable. + + + + 1 + Enter the merchant password for Multishipping orders. If it is blank, global merchant password entered under General configuration will be applicable. + + + + 1 + Enter the merchant Installation Id for Multishipping orders. If it is blank, global merchant Installation Id entered under HPP configuration will be applicable. + @@ -1284,7 +1299,76 @@ 1 + + + Enter the merchant code for Paybylink orders. If it is blank, global merchant code entered under General configuration will be applicable. + 1 + + + + Enter the merchant username for Paybylink orders. If it is blank, global merchant username entered under General configuration will be applicable. + 1 + + + + Enter the merchant password for Paybylink orders. If it is blank, global merchant password entered under General configuration will be applicable. + 1 + + + + 1 + Enter the merchant Installation Id for Pay By Link orders. If it is blank, global merchant Installation Id entered under HPP configuration will be applicable. + + + + 1 + validate-no-empty validate-digits validate-digits-range digits-range-1-48 + Pay By Link will be expired based on the above entered value. The value must be entered in the range between 1 to 48 hours. + + + + 1 + Magento\Config\Model\Config\Source\Yesno + If set "Yes", expiry lifetime will be doubled once. + + + + + + + + 1 + Enter the merchant code for Recurring orders. If it is blank, global merchnat code entered under General configuration will be applicable. + + + + 1 + Enter the username for this Recurring specific Merchant code. If it is blank, global XML username entered under General configuration will be applicable. + + + + 1 + Enter the password for this Recurring specific Merchant code. If it is blank, global XML password entered under General configuration will be applicable. + + + + + + + + + + Sapient\Worldpay\Model\Config\Source\CaptureDelay + 0 - Automatically captures immediately
1-14 - Sets the number of days to delay capture by
OFF - Disables capture completely (you have to capture with an order modification)
DEFAULT - Uses the default preconfigured value set on the merchantCode]]>
+
+ + + required-entry validate-digits validate-not-negative-number validate-digits-range digits-range-1-14 + custom + Sets the number of days to delay capture by +
+
diff --git a/etc/config.xml b/etc/config.xml index 942d35ce..c9e13b95 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -80,6 +80,8 @@ 0 Alternative Payment Methods PAYPAL-EXPRESS + ONE-OFF + By signing this mandate form, you authorise (A) Worldpay to send instructions to your bank to debit your account and (B) your bank to debit your account in accordance with the instructions from Worldpay. As part of your rights, you are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited. Your rights are explained in a statement that you can obtain from your bank. JE-GB,IM-GB @@ -108,8 +110,13 @@ adobe@fisglobal.com - Share Order + Pay By Link + 24 + + default + 1 + diff --git a/etc/cron_groups.xml b/etc/cron_groups.xml index 306ff5aa..7e052907 100644 --- a/etc/cron_groups.xml +++ b/etc/cron_groups.xml @@ -18,4 +18,13 @@ 600 1 + + 1 + 4 + 2 + 10 + 60 + 600 + 1 + \ No newline at end of file diff --git a/etc/crontab.xml b/etc/crontab.xml index fa323153..a3239640 100644 --- a/etc/crontab.xml +++ b/etc/crontab.xml @@ -10,4 +10,9 @@ * * * * * + + + * * * * * + + \ No newline at end of file diff --git a/etc/email_templates.xml b/etc/email_templates.xml index 68e22d3d..394c8475 100644 --- a/etc/email_templates.xml +++ b/etc/email_templates.xml @@ -13,9 +13,6 @@