From e2a485c30ba46e1879e22c84e6fb7d8abe3db8df Mon Sep 17 00:00:00 2001 From: Shane Logsdon Date: Mon, 21 Sep 2020 17:57:58 -0400 Subject: [PATCH] support transit during customer checkout --- app/code/community/Hps/Transit/Block/Form.php | 17 +++- .../community/Hps/Transit/Helper/Data.php | 44 ++++++++- .../community/Hps/Transit/Model/Observer.php | 23 +++++ .../community/Hps/Transit/Model/Payment.php | 48 +++------- app/code/community/Hps/Transit/etc/config.xml | 23 ++--- .../base/default/template/transit/form.phtml | 8 +- .../template/transit/storedcards.phtml | 4 +- js/transit/checkout-form.js | 11 ++- .../base/default/transit/css/hps-styles.css | 91 +------------------ 9 files changed, 120 insertions(+), 149 deletions(-) create mode 100644 app/code/community/Hps/Transit/Model/Observer.php diff --git a/app/code/community/Hps/Transit/Block/Form.php b/app/code/community/Hps/Transit/Block/Form.php index 2a6e1ba..a251012 100644 --- a/app/code/community/Hps/Transit/Block/Form.php +++ b/app/code/community/Hps/Transit/Block/Form.php @@ -1,11 +1,13 @@ setTemplate('transit/form.phtml'); } + public function getCredentials() + { + Mage::helper('hps_transit/data')->configureSDK(); + + $manifest = ServicesContainer::instance()->getClient()->createManifest(); + + return json_encode([ + 'deviceId' => $this->getConfig('device_id'), + 'manifest' => $manifest, + 'env' => $this->getConfig('is_production') ? 'production' : 'sandbox', + ]); + } + protected function getConfig($key) { return Mage::getStoreConfig(sprintf('payment/hps_transit/%s', $key)); diff --git a/app/code/community/Hps/Transit/Helper/Data.php b/app/code/community/Hps/Transit/Helper/Data.php index b1ea823..69a0f39 100644 --- a/app/code/community/Hps/Transit/Helper/Data.php +++ b/app/code/community/Hps/Transit/Helper/Data.php @@ -1,16 +1,58 @@ 'merchant_id', + 'username' => 'user_id', + 'password' => 'password', + 'deviceId' => 'device_id', + 'developerId' => 'developer_id', + 'transactionKey' => 'transaction_key', + ]; + + foreach ($pairs as $sdk => $mage) { + $value = $this->getConfig($mage); + + if (empty($value)) { + continue; + } + + $config->{$sdk} = $value; + } + + $config->environment = $this->getConfig('is_production') ? Environment::PRODUCTION : Environment::TEST; + $config->gatewayProvider = GatewayProvider::TRANSIT; + $config->acceptorConfig = new AcceptorConfig(); + + ServicesContainer::configure($config); + } + + public function getConfig($key) + { + return Mage::getStoreConfig(sprintf(self::CONFIG_FORMAT, $key)); + } /** * @param $customerId diff --git a/app/code/community/Hps/Transit/Model/Observer.php b/app/code/community/Hps/Transit/Model/Observer.php new file mode 100644 index 0000000..0630c55 --- /dev/null +++ b/app/code/community/Hps/Transit/Model/Observer.php @@ -0,0 +1,23 @@ +getConfig('transaction_key'))) { + return; + } + + Mage::helper('hps_transit/data')->configureSDK(); + + $response = ServicesContainer::instance()->getClient()->getTransactionKey(); + + Mage::getConfig()->saveConfig(sprintf(self::CONFIG_FORMAT, 'transaction_key'), $response->transactionKey); + Mage::getConfig()->saveConfig(sprintf(self::CONFIG_FORMAT, 'user_id'), null); + Mage::getConfig()->saveConfig(sprintf(self::CONFIG_FORMAT, 'password'), null); + } +} diff --git a/app/code/community/Hps/Transit/Model/Payment.php b/app/code/community/Hps/Transit/Model/Payment.php index 8a51ce1..5a39b70 100644 --- a/app/code/community/Hps/Transit/Model/Payment.php +++ b/app/code/community/Hps/Transit/Model/Payment.php @@ -115,7 +115,7 @@ private function _authorize(Varien_Object $payment, $amount, $capture) $cardData->expMonth = $payment->getCcExpMonth(); } - $this->_configureSDK(); + Mage::helper('hps_transit/data')->configureSDK(); $address = $this->_getCardHolderAddress($order); $memo = $this->_getTxnMemo($order); $invoiceNumber = $this->_getTxnInvoiceNumber($order); @@ -123,6 +123,9 @@ private function _authorize(Varien_Object $payment, $amount, $capture) $cardOrToken = new CreditCardData(); $cardOrToken->token = $secureToken; + $cardOrToken->expYear = $payment->getCcExpYear(); + $cardOrToken->expMonth = $payment->getCcExpMonth(); + $cardOrToken->cvn = $payment->getCcCid(); $cardOrToken->cardHolderName = $this->_getCardHolderName($order); try { @@ -377,22 +380,17 @@ protected function closeTransaction($payment, $amount, $response, $status = self protected function saveMultiUseToken($response, $cardData, $customerId, $cardType) { - $tokenData = $response->tokenData; /* @var $tokenData HpsTokenData */ + $token = $response->token; - if ($tokenData->responseCode == '0') { - try { - $this->_getChargeService()->updateTokenExpiration($tokenData->tokenValue, $cardData->expMonth, $cardData->expYear); - } catch (Exception $e) { - Mage::logException($e); - } + if (empty($token)) { + Mage::log('Requested multi token has not been generated for the transaction # ' . $response->transactionId, Zend_Log::WARN); + return; + } - if ($customerId > 0) { - Mage::helper('hps_transit')->saveMultiToken($tokenData->tokenValue, $cardData, $cardType, $customerId); - } else { - Mage::helper('hps_transit')->saveMultiToken($tokenData->tokenValue, $cardData, $cardType); - } + if ($customerId > 0) { + Mage::helper('hps_transit')->saveMultiToken($token, $cardData, $cardType, $customerId); } else { - Mage::log('Requested multi token has not been generated for the transaction # ' . $response->transactionId, Zend_Log::WARN); + Mage::helper('hps_transit')->saveMultiToken($token, $cardData, $cardType); } } @@ -659,28 +657,6 @@ public function throwUserError($error, $detailedError = null, $goToPaymentSectio } } - protected function _configureSDK() - { - $config = new ServicesConfig(); - - // Support HTTP proxy - if (Mage::getStoreConfig('payment/hps_transit/use_http_proxy')) { - $config->useProxy = true; - $config->proxyOptions = array( - 'proxy_host' => Mage::getStoreConfig('payment/hps_transit/http_proxy_host'), - 'proxy_port' => Mage::getStoreConfig('payment/hps_transit/http_proxy_port'), - ); - } - - $config->secretApiKey = 'skapi_cert_MTyMAQBiHVEAewvIzXVFcmUd2UcyBge_eCpaASUp0A'; - $config->versionNumber = '1573'; - $config->developerId = '002914'; - $config->gatewayProvider = GatewayProvider::PORTICO; - $config->environment = Environment::TEST; - - ServicesContainer::configure($config); - } - /** * @param Mage_Sales_Model_Order $order * @return Address diff --git a/app/code/community/Hps/Transit/etc/config.xml b/app/code/community/Hps/Transit/etc/config.xml index 286c563..a2e2e55 100644 --- a/app/code/community/Hps/Transit/etc/config.xml +++ b/app/code/community/Hps/Transit/etc/config.xml @@ -70,6 +70,7 @@ + 003226G001 no 3 10 @@ -119,17 +120,6 @@ - - - - - - - Hps_Transit_Adminhtml - - - - @@ -141,5 +131,16 @@ + + + + + + + Hps_Transit_Adminhtml + + + + diff --git a/app/design/frontend/base/default/template/transit/form.phtml b/app/design/frontend/base/default/template/transit/form.phtml index dd21094..5e712c7 100755 --- a/app/design/frontend/base/default/template/transit/form.phtml +++ b/app/design/frontend/base/default/template/transit/form.phtml @@ -1,12 +1,9 @@ getMethodCode(); $_loggedIn = Mage::getSingleton('customer/session')->isLoggedIn(); -$public_key = Mage::getModel('hps_transit/payment')->getConfigData('publicapikey'); $token_data_url = Mage::getUrl('transit/storedcard/getTokenData', array('_secure' => TRUE)); $allow_card_saving = Mage::getModel('hps_transit/payment')->getConfigData('allow_card_saving'); -$allow_heartland_gift = Mage::getModel('hps_transit/payment')->getConfigData('allow_heartland_gift'); $use_iframes = true; -$cca = $this->getCca(); if ($_loggedIn && $allow_card_saving) { $customerStoredCards = Mage::helper('hps_transit')->getStoredCards( Mage::getSingleton('customer/session')->getCustomerId()); @@ -59,6 +56,7 @@ if ($_loggedIn && $allow_card_saving) { + @@ -74,7 +72,7 @@ if ($_loggedIn && $allow_card_saving) {
- +
@@ -90,7 +88,7 @@ TransITMagento.init({ code: '', baseUrl: '', loggedIn: , - publicKey: '', + credentials: getCredentials() ?>, allowCardSaving: , tokenDataUrl: '', allowGift: false, diff --git a/app/design/frontend/base/default/template/transit/storedcards.phtml b/app/design/frontend/base/default/template/transit/storedcards.phtml index 2ca4c45..57b7cc6 100755 --- a/app/design/frontend/base/default/template/transit/storedcards.phtml +++ b/app/design/frontend/base/default/template/transit/storedcards.phtml @@ -6,13 +6,13 @@ $_storedCards = Mage::helper('hps_transit')->getStoredCards(Mage::getSingleton('