From 043a074616d0fff2d9d2a23f03dd6a31fcd0b30a Mon Sep 17 00:00:00 2001 From: Shane Logsdon Date: Thu, 17 Sep 2020 15:22:19 -0400 Subject: [PATCH] get basic transactions working --- README.md | 6 +- app/code/community/Hps/Transit/Block/Form.php | 41 - .../community/Hps/Transit/Model/Payment.php | 757 +++++------ app/code/community/Hps/Transit/etc/config.xml | 24 +- app/code/community/Hps/Transit/etc/system.xml | 57 +- .../sql/hps_transit_setup/install-1.0.0.php | 6 +- .../default/default/layout/transit.xml | 16 +- .../frontend/base/default/layout/transit.xml | 68 +- .../base/default/template/transit/form.phtml | 8 +- composer.json | 4 +- js/transit/checkout-form.js | 1104 ++++++----------- js/transit/secure.submit-1.0.1.js | 115 -- .../base/default/transit/css/hps-styles.css | 6 +- 13 files changed, 789 insertions(+), 1423 deletions(-) delete mode 100644 js/transit/secure.submit-1.0.1.js diff --git a/README.md b/README.md index ee6037c..e43f734 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ## TransIT Magento Payment Gateway -This extension allows Magento to use the Heartland Payment Systems Gateway. All card data is tokenized using Heartland's TransIT product. +This extension allows Magento to use the Heartland Payment Systems Gateway. All card data is tokenized using Heartland's single-use tokenization solution. ## Installation @@ -22,10 +22,6 @@ Example OpenMage LTS `composer.json`: } ``` -## Usage - -Download the contents and extract to the root of your Magento install folder. - ## Contributing 1. Fork it diff --git a/app/code/community/Hps/Transit/Block/Form.php b/app/code/community/Hps/Transit/Block/Form.php index 6747b64..2a6e1ba 100644 --- a/app/code/community/Hps/Transit/Block/Form.php +++ b/app/code/community/Hps/Transit/Block/Form.php @@ -16,47 +16,6 @@ protected function _construct() $this->setTemplate('transit/form.phtml'); } - public function getCca() - { - if (!$this->getConfig('enable_threedsecure')) { - return false; - } - - if (null !== $this->cca) { - return $this->cca; - } - - $helper = Mage::helper('hps_transit/jwt'); - $orderNumber = str_shuffle('abcdefghijklmnopqrstuvwxyz'); - $data = array( - 'jti' => str_shuffle('abcdefghijklmnopqrstuvwxyz'), - 'iat' => time(), - 'iss' => $this->getConfig('threedsecure_api_identifier'), - 'OrgUnitId' => $this->getConfig('threedsecure_org_unit_id'), - 'Payload' => array( - 'OrderDetails' => array( - 'OrderNumber' => $orderNumber, - // Centinel requires amounts in pennies - 'Amount' => 100 * Mage::getSingleton('checkout/cart') - ->getQuote() - ->getGrandTotal(), - 'CurrencyCode' => '840', - ), - ), - ); - error_log(print_r($data, true)); - $jwt = $helper::encode( - $this->getConfig('threedsecure_api_key'), - $data - ); - $this->cca = array( - 'jwt' => $jwt, - 'orderNumber' => $orderNumber, - ); - - return $this->cca; - } - protected function getConfig($key) { return Mage::getStoreConfig(sprintf('payment/hps_transit/%s', $key)); diff --git a/app/code/community/Hps/Transit/Model/Payment.php b/app/code/community/Hps/Transit/Model/Payment.php index 84c84bc..8a51ce1 100644 --- a/app/code/community/Hps/Transit/Model/Payment.php +++ b/app/code/community/Hps/Transit/Model/Payment.php @@ -1,16 +1,26 @@ getInfoInstance(); @@ -94,157 +97,61 @@ private function _authorize(Varien_Object $payment, $amount, $capture) { $this->getFraudSettings(); - $order = $payment->getOrder(); /* @var $order Mage_Sales_Model_Order */ + /* @var $order Mage_Sales_Model_Order */ + $order = $payment->getOrder(); $multiToken = false; $cardData = null; $additionalData = new Varien_Object($payment->getAdditionalData() ? unserialize($payment->getAdditionalData()) : null); $secureToken = $additionalData->getTransitToken() ? $additionalData->getTransitToken() : null; - $saveCreditCard = !! (bool)$additionalData->getCcSaveFuture(); + $saveCreditCard = (bool) $additionalData->getCcSaveFuture(); $customerId = $additionalData->getCustomerId(); - $giftService = $this->_getGiftService(); - $giftCardNumber = $additionalData->getGiftcardNumber(); - $giftCardPin = filter_var($additionalData->getGiftcardPin(),FILTER_VALIDATE_INT, ARRAY('default' => FILTER_NULL_ON_FAILURE)); - $ccaData = $additionalData->getCcaData(); - - if ($giftCardNumber) { - // 1. check balance - $giftcard = new HpsGiftCard(); - $giftcard->number = $giftCardNumber; - $giftcard->pin = $giftCardPin; - $giftResponse = $giftService->balance($giftcard); - - // 2. is balance > amount? - if ($giftResponse->balanceAmount > $amount) { - // 2.yes. process full to gift - try { - $this->checkVelocity(); - - if (strpos($this->getConfigData('secretapikey'), '_cert_') !== false) { - $giftresp = $giftService->sale($giftcard, 10.00); - } else { - $giftresp = $giftService->sale($giftcard, $amount); - } - - $order->addStatusHistoryComment('Used Heartland Gift Card ' . $giftCardNumber . ' for amount $' . $amount . '. [full payment]'); - $payment->setTransactionAdditionalInfo(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, - array( - 'gift_card_number' => $giftCardNumber, - 'gift_card_transaction' => $giftresp->transactionId, - 'gift_card_amount_charged' => $amount)); - - // just adds a trackable type for the DB - $giftresp->cardType = 'Gift'; - // \Hps_Transit_Model_Payment::closeTransaction - $this->closeTransaction($payment,$amount,$giftresp); - return $this; - } catch (Exception $e) { - $this->updateVelocity($e); - - Mage::logException($e); - $payment->setStatus(self::STATUS_ERROR); - $this->throwUserError($e->getMessage(), null, true); - } - } else { - // 2.no. process full gift card amt and card process remainder - try { - $this->checkVelocity(); - - $giftresp = $giftService->sale($giftcard, $giftResponse->balanceAmount); - $order->addStatusHistoryComment('Used Heartland Gift Card ' . $giftCardNumber . ' for amount $' . $giftResponse->balanceAmount . '. [partial payment]')->save(); - $payment->setTransactionAdditionalInfo(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, - array( - 'gift_card_number' => $giftCardNumber, - 'gift_card_transaction' => $giftresp->transactionId, - 'gift_card_amount_charged' => $giftResponse->balanceAmount)); - $payment->setAmount($giftResponse->balanceAmount)->save(); - $amount = $amount - $giftResponse->balanceAmount; // remainder - } catch (Exception $e) { - $this->updateVelocity($e); - - Mage::logException($e); - $payment->setStatus(self::STATUS_ERROR); - $this->throwUserError($e->getMessage(), null, true); - } - // 3. TODO: if the card payment fails later, refund the gift transaction - } - } $cardType = $payment->getCcType(); if ($saveCreditCard) { $multiToken = true; - $cardData = new HpsCreditCard(); + $cardData = new CreditCardData(); $cardData->number = $payment->getCcLast4(); $cardData->expYear = $payment->getCcExpYear(); $cardData->expMonth = $payment->getCcExpMonth(); } - $chargeService = $this->_getChargeService(); - $cardHolder = $this->_getCardHolderData($order); - $details = $this->_getTxnDetailsData($order); - $cardOrToken = new HpsTokenData(); - $cardOrToken->tokenValue = $secureToken; - $secureEcommerce = $this->getSecureEcommerce($ccaData, $cardType); + $this->_configureSDK(); + $address = $this->_getCardHolderAddress($order); + $memo = $this->_getTxnMemo($order); + $invoiceNumber = $this->_getTxnInvoiceNumber($order); + $customerId = $this->_getTxnCustomerId($order); + + $cardOrToken = new CreditCardData(); + $cardOrToken->token = $secureToken; + $cardOrToken->cardHolderName = $this->_getCardHolderName($order); try { $this->checkVelocity(); - $captureBuilder = false; $builder = null; - if ($capture) { - if ($payment->getCcTransId()) { - $builder = $chargeService->capture() - ->withTransactionId($payment->getCcTransId()) - ->withAmount(); - $captureBuilder = true; - } else { - $builder = $chargeService->charge() - ->withAmount($amount) - ->withCurrency(strtolower($order->getBaseCurrencyCode())) - ->withToken($cardOrToken) - ->withCardHolder($cardHolder) - ->withRequestMultiUseToken($multiToken) - ->withDetails($details); - } + if ($capture && $payment->getCcTransId()) { + $builder = Transaction::fromId($payment->getCcTransId())->capture(); } else { - $builder = $chargeService->authorize() - ->withAmount($amount) + $requestType = $capture ? 'charge' : 'authorize'; + $builder = $cardOrToken->{$requestType}($amount) ->withCurrency(strtolower($order->getBaseCurrencyCode())) - ->withToken($cardOrToken) - ->withCardHolder($cardHolder) + ->withAddress($address) ->withRequestMultiUseToken($multiToken) - ->withDetails($details); - } - - if (false === $captureBuilder && null !== $secureEcommerce) { - $builder = $builder->withSecureEcommerce($secureEcommerce); + ->withDescription($memo) + ->withInvoiceNumber($invoiceNumber) + ->withCustomerId($customerId); } $response = $builder->execute(); + + if ($response->responseCode !== '00') { + // TODO: move this + // $this->updateVelocity($e); - $this->_debugChargeService($chargeService); - // \Hps_Transit_Model_Payment::closeTransaction - $this->closeTransaction($payment, $amount, $response); - - if ($giftCardNumber) { - $order->addStatusHistoryComment('Remaining amount to be charged to credit card ' .$this->_formatAmount((string)$amount) . '. [partial payment]')->save(); - } - - if ($multiToken) { - $this->saveMultiUseToken($response, $cardData, $customerId, $cardType); - } - } catch (HpsCreditException $e) { - $this->updateVelocity($e); - - Mage::logException($e); - $this->_debugChargeService($chargeService, $e); - - // refund gift (if used) - if ($giftCardNumber) { - $order->addStatusHistoryComment('Reversed Heartland Gift Card ' . $giftCardNumber . ' for amount $' . $giftResponse->balanceAmount . '. [full reversal]')->save(); - $giftResponse = $giftService->reverse($giftcard, $giftResponse->balanceAmount); - } + if (!$this->_allow_fraud || $response->responseCode !== 'FR') { + throw new ApiException($this->mapResponseCodeToFriendlyMessage($response->responseCode)); + } - if ($this->_allow_fraud && $e->getCode() == HpsExceptionCodes::POSSIBLE_FRAUD_DETECTED) { // we can skip the card saving if it fails for possible fraud there will be no token. if ($this->_email_fraud && $this->_fraud_address != '') { // EMAIL THE PEOPLE @@ -257,21 +164,23 @@ private function _authorize(Varien_Object $payment, $amount, $capture) } $this->closeTransaction($payment,$amount,$e); - } else { - $payment->setStatus(self::STATUS_ERROR); - if ($e->getCode() == HpsExceptionCodes::POSSIBLE_FRAUD_DETECTED) { - $this->throwUserError($this->_fraud_text, null, true); - } else { - $this->throwUserError($e->getMessage(), null, true); - } + return; } - } catch (HpsException $e) { - $this->_debugChargeService($chargeService, $e); + + $this->_debugChargeService(); + // \Hps_Transit_Model_Payment::closeTransaction + $this->closeTransaction($payment, $amount, $response); + + if ($multiToken) { + $this->saveMultiUseToken($response, $cardData, $customerId, $cardType); + } + } catch (ApiException $e) { + $this->_debugChargeService($e); $payment->setStatus(self::STATUS_ERROR); $this->throwUserError($e->getMessage(), null, true); } catch (Exception $e) { - $this->_debugChargeService($chargeService, $e); + $this->_debugChargeService($e); Mage::logException($e); $payment->setStatus(self::STATUS_ERROR); $this->throwUserError($e->getMessage()); @@ -280,6 +189,154 @@ private function _authorize(Varien_Object $payment, $amount, $capture) return $this; } + + /** + * @param Varien_Object|Mage_Sales_Model_Order_Payment $payment + * @param float $amount + * @return Hps_Transit_Model_Payment + */ + public function refund(Varien_Object $payment, $amount) + { + $transactionDetails = $this->getTransactionDetails($payment); + if ($this->canVoid($payment) && $this->transactionActiveOnGateway($transactionDetails)) { + if ($this->getCurrentAuthorizationAmount($transactionDetails) > $amount) { + $this->_reversal($payment, $transactionDetails, $amount); + } else { + $this->void($payment); + } + } else { + $this->_refund($payment, $amount); + } + + return $this; + } + + + /** + * Void payment abstract method + * + * @param Varien_Object $payment + * + * @return Hps_Transit_Model_Payment + */ + public function void(Varien_Object $payment) + { + $transactionId = null; + + if (false !== ($parentId = $this->getParentTransactionId($payment))) { + $transactionId = $parentId; + } else { + $transactionId = $payment->getCcTransId(); + } + + try { + $voidResponse = Transaction::fromId($transactionId)->void()->execute(); + $payment + ->setTransactionId($voidResponse->transactionId) + ->setParentTransactionId($transactionId) + ->setIsTransactionClosed(1) + ->setShouldCloseParentTransaction(1); + } catch (ApiException $e) { + $this->_debugChargeService($e); + $this->throwUserError($e->getMessage()); + } catch (Exception $e) { + $this->_debugChargeService($e); + Mage::logException($e); + $this->throwUserError(Mage::helper('hps_transit')->__('An unexpected error occurred. Please try again or contact a system administrator.')); + } + + return $this; + } + + /** + * @param Varien_Object|Mage_Sales_Model_Order_Payment $payment + * @param $amount + * @return Hps_Transit_Model_Payment + */ + public function _refund(Varien_Object $payment, $amount) + { + $transactionId = $payment->getCcTransId(); + /* @var $order Mage_Sales_Model_Order */ + $order = $payment->getOrder(); + $address = $this->_getCardHolderAddress($order); + $memo = $this->_getTxnMemo($order); + $invoiceNumber = $this->_getTxnInvoiceNumber($order); + $customerId = $this->_getTxnCustomerId($order); + + try { + $refundResponse = Transaction::fromId($transactionId)->refund($amount) + ->withCurrency(strtolower($order->getBaseCurrencyCode())) + ->withAddress($address) + ->withDescription($memo) + ->withInvoiceNumber($invoiceNumber) + ->withCustomerId($customerId) + ->execute(); + $payment + ->setTransactionId($refundResponse->transactionId) + ->setParentTransactionId($transactionId) + ->setIsTransactionClosed(1) + ->setShouldCloseParentTransaction(1); + } catch (ApiException $e) { + $this->_debugChargeService($e); + $this->throwUserError($e->getMessage()); + } catch (Exception $e) { + $this->_debugChargeService($e); + Mage::logException($e); + $this->throwUserError($e->getMessage()); + } + + return $this; + } + + + /** + * @param Varien_Object|Mage_Sales_Model_Order_Payment $payment + * @param HpsReportTransactionDetails $transactionDetails + * @param float $newAuthAmount + * @return Hps_Transit_Model_Payment + */ + public function _reversal(Varien_Object $payment, HpsReportTransactionDetails $transactionDetails, $newAuthAmount) + { + + $transactionId = null; + + if (false !== ($parentId = $this->getParentTransactionId($payment))) { + $transactionId = $parentId; + } else { + $transactionId = $payment->getCcTransId(); + } + $newAuthAmount = $this->getCurrentAuthorizationAmount($transactionDetails) - $newAuthAmount; + /* @var $order Mage_Sales_Model_Order */ + $order = $payment->getOrder(); + $memo = $this->_getTxnMemo($order); + $invoiceNumber = $this->_getTxnInvoiceNumber($order); + $customerId = $this->_getTxnCustomerId($order); + + try { + $reverseResponse = Transaction::fromId($transactionId)->reverse($transactionDetails->authorizedAmount) + ->withCurrency(strtolower($order->getBaseCurrencyCode())) + ->withDescription($memo) + ->withInvoiceNumber($invoiceNumber) + ->withCustomerId($customerId) + ->withAuthAmount($newAuthAmount) + ->execute(); + $payment + ->setTransactionId($reverseResponse->transactionId) + ->setParentTransactionId($transactionId) + ->setIsTransactionClosed(1) + ->setShouldCloseParentTransaction(1); + } catch (ApiException $e) { + $this->_debugChargeService($e); + $this->throwUserError($e->getMessage()); + } catch (Exception $e) { + $this->_debugChargeService($e); + Mage::logException($e); + $this->throwUserError($e->getMessage()); + } + + return $this; + } + /** * @param Varien_Object|Mage_Sales_Model_Order_Payment $payment * @param float $amount @@ -339,47 +396,6 @@ protected function saveMultiUseToken($response, $cardData, $customerId, $cardTyp } } - protected function getSecureEcommerce($ccaData, $cardType) - { - if ($this->getConfigData('enable_threedsecure') - && !empty($ccaData) && !empty($ccaData['actionCode']) - && in_array($ccaData['actionCode'], array('SUCCESS', 'NOACTION')) - ) { - $dataSource = ''; - switch ($cardType) { - case 'visa': - $dataSource = 'Visa 3DSecure'; - break; - case 'mastercard': - $dataSource = 'MasterCard 3DSecure'; - break; - case 'discover': - $dataSource = 'Discover 3DSecure'; - break; - case 'amex': - $dataSource = 'AMEX 3DSecure'; - break; - } - $cavv = !empty($ccaData['cavv']) - ? $ccaData['cavv'] - : ''; - $eciFlag = !empty($ccaData['eci']) - ? substr($ccaData['eci'], 1) - : ''; - $xid = !empty($ccaData['xid']) - ? $ccaData['xid'] - : ''; - $secureEcommerce = new HpsSecureEcommerce(); - $secureEcommerce->type = '3DSecure'; - $secureEcommerce->dataSource = $dataSource; - $secureEcommerce->data = $cavv; - $secureEcommerce->eciFlag = $eciFlag; - $secureEcommerce->xid = $xid; - return $secureEcommerce; - } - - return false; - } protected function _formatAmount($amount) { return Mage::helper('core')->currency($amount, true, false); @@ -416,7 +432,6 @@ protected function getFraudSettings() protected function maybeResetVelocityTimeout() { - $timeoutSeconds = $this->_fraud_velocity_timeout * 60; $timeoutExpiration = (int)$this->getVelocityVar('TimeoutExpiration'); if (time() < $timeoutExpiration) { @@ -443,7 +458,7 @@ protected function checkVelocity() if ($count >= $this->_fraud_velocity_attempts && time() < $timeoutExpiration) { sleep(5); - throw new HpsException(sprintf($this->_fraud_text, $issuerResponse)); + throw new ApiException(sprintf($this->_fraud_text, $issuerResponse)); } } @@ -470,19 +485,19 @@ protected function updateVelocity($e) protected function getVelocityVar($var) { - return Mage::getSingleton('checkout/session') + return Mage::getSingleton(self::CHECKOUT_SESSION_MODEL_PATH) ->getData($this->getVelocityVarPrefix() . $var); } protected function setVelocityVar($var, $data = null) { - return Mage::getSingleton('checkout/session') + return Mage::getSingleton(self::CHECKOUT_SESSION_MODEL_PATH) ->setData($this->getVelocityVarPrefix() . $var, $data); } protected function unsVelocityVar($var) { - return Mage::getSingleton('checkout/session') + return Mage::getSingleton(self::CHECKOUT_SESSION_MODEL_PATH) ->unsetData($this->getVelocityVarPrefix() . $var); } @@ -511,28 +526,6 @@ protected function getRemoteIP() return $remoteIP; } - - /** - * @param Varien_Object|Mage_Sales_Model_Order_Payment $payment - * @param float $amount - * @return Hps_Transit_Model_Payment - */ - public function refund(Varien_Object $payment, $amount) - { - $transactionDetails = $this->getTransactionDetails($payment); - if ($this->canVoid($payment) && $this->transactionActiveOnGateway($transactionDetails)) { - if ($this->getCurrentAuthorizationAmount($transactionDetails) > $amount) { - $this->_reversal($payment, $transactionDetails, $amount); - } else { - $this->void($payment); - } - } else { - $this->_refund($payment, $amount); - } - - return $this; - } - public function getCurrentAuthorizationAmount($transactionDetails) { if (floatval($transactionDetails->settlementAmount) > 0) { @@ -558,6 +551,7 @@ public function getTransactionDetails(Varien_Object $payment) public function transactionActiveOnGateway($transactionDetail) { + // TODO: CHECK THIS return $transactionDetail->transactionStatus == 'A'; } @@ -575,131 +569,6 @@ public function getParentTransactionId(Varien_Object $payment) } } - - /** - * Void payment abstract method - * - * @param Varien_Object $payment - * - * @return Hps_Transit_Model_Payment - */ - public function void(Varien_Object $payment) - { - $transactionId = null; - - if (false !== ($parentId = $this->getParentTransactionId($payment))) { - $transactionId = $parentId; - } else { - $transactionId = $payment->getCcTransId(); - } - - $chargeService = $this->_getChargeService(); - - try { - $voidResponse = $chargeService->void() - ->withTransactionId($transactionId) - ->execute(); - $payment - ->setTransactionId($voidResponse->transactionId) - ->setParentTransactionId($transactionId) - ->setIsTransactionClosed(1) - ->setShouldCloseParentTransaction(1); - } catch (HpsException $e) { - $this->_debugChargeService($chargeService, $e); - $this->throwUserError($e->getMessage()); - } catch (Exception $e) { - $this->_debugChargeService($chargeService, $e); - Mage::logException($e); - $this->throwUserError(Mage::helper('hps_transit')->__('An unexpected error occurred. Please try again or contact a system administrator.')); - } - - return $this; - } - - /** - * @param Varien_Object|Mage_Sales_Model_Order_Payment $payment - * @param $amount - * @return Hps_Transit_Model_Payment - */ - public function _refund(Varien_Object $payment, $amount) - { - $transactionId = $payment->getCcTransId(); - $order = $payment->getOrder(); /* @var $order Mage_Sales_Model_Order */ - $chargeService = $this->_getChargeService(); - $cardHolder = $this->_getCardHolderData($order); - $details = $this->_getTxnDetailsData($order); - - try { - $refundResponse = $chargeService->refund() - ->withAmount($amount) - ->withCurrency(strtolower($order->getBaseCurrencyCode())) - ->withTransactionId($transactionId) - ->withCardHolder($cardHolder) - ->withDetails($details) - ->execute(); - $payment - ->setTransactionId($refundResponse->transactionId) - ->setParentTransactionId($transactionId) - ->setIsTransactionClosed(1) - ->setShouldCloseParentTransaction(1); - } catch (HpsException $e) { - $this->_debugChargeService($chargeService, $e); - $this->throwUserError($e->getMessage()); - } catch (Exception $e) { - $this->_debugChargeService($chargeService, $e); - Mage::logException($e); - $this->throwUserError($e->getMessage()); - } - - return $this; - } - - - /** - * @param Varien_Object|Mage_Sales_Model_Order_Payment $payment - * @param HpsReportTransactionDetails $transactionDetails - * @param float $newAuthAmount - * @return Hps_Transit_Model_Payment - */ - public function _reversal(Varien_Object $payment, HpsReportTransactionDetails $transactionDetails, $newAuthAmount) - { - - $transactionId = null; - - if (false !== ($parentId = $this->getParentTransactionId($payment))) { - $transactionId = $parentId; - } else { - $transactionId = $payment->getCcTransId(); - } - $newAuthAmount = $this->getCurrentAuthorizationAmount($transactionDetails) - $newAuthAmount; - $order = $payment->getOrder(); - /* @var $order Mage_Sales_Model_Order */ - $chargeService = $this->_getChargeService(); - $details = $this->_getTxnDetailsData($order); - try { - $reverseResponse = $chargeService->reverse() - ->withTransactionId($transactionId) - ->withAmount($transactionDetails->authorizedAmount) - ->withCurrency(strtolower($order->getBaseCurrencyCode())) - ->withDetails($details) - ->withAuthAmount($newAuthAmount) - ->execute(); - $payment - ->setTransactionId($reverseResponse->transactionId) - ->setParentTransactionId($transactionId) - ->setIsTransactionClosed(1) - ->setShouldCloseParentTransaction(1); - } catch (HpsException $e) { - $this->_debugChargeService($chargeService, $e); - $this->throwUserError($e->getMessage()); - } catch (Exception $e) { - $this->_debugChargeService($chargeService, $e); - Mage::logException($e); - $this->throwUserError($e->getMessage()); - } - - return $this; - } /** * @param null|Mage_Sales_Model_Quote $quote * @return bool @@ -710,7 +579,7 @@ public function isAvailable($quote = null) return false; } - return $this->getConfigData('secretapikey', ($quote ? $quote->getStoreId() : null)) + return $this->getConfigData('transaction_key', ($quote ? $quote->getStoreId() : null)) && parent::isAvailable($quote); } @@ -746,18 +615,6 @@ public function assignData($data) $details['transit_token'] = $data->getData('transit_token'); } - if ($data->getData('giftcard_number')) { - $details['giftcard_number'] = $data->getData('giftcard_number'); - } - - if ($data->getData('giftcard_pin')) { - $details['giftcard_pin'] = $data->getData('giftcard_pin'); - } - - if ($data->getData('giftcard_skip_cc')) { - $details['giftcard_skip_cc'] = $data->getData('giftcard_skip_cc') === 'true'; - } - if ($data->getData('use_credit_card')) { $details['use_credit_card'] = 1; } @@ -766,32 +623,6 @@ public function assignData($data) $details['customer_id'] = $data->getData('customer_id'); } - $ccaData = array(); - - if ($data->getData('cca_data_action_code')) { - $ccaData['actionCode'] = $data->getData('cca_data_action_code'); - } - - if ($data->getData('cca_data_cavv')) { - $ccaData['cavv'] = $data->getData('cca_data_cavv'); - } - - if ($data->getData('cca_data_eci')) { - $ccaData['eci'] = $data->getData('cca_data_eci'); - } - - if ($data->getData('cca_data_xid')) { - $ccaData['xid'] = $data->getData('cca_data_xid'); - } - - if ($data->getData('cca_data_token')) { - $ccaData['token'] = $data->getData('cca_data_token'); - } - - if (array() !== $ccaData) { - $details['cca_data'] = $ccaData; - } - if (!empty($details)) { $this->getInfoInstance()->setAdditionalData(serialize($details)); } @@ -828,12 +659,9 @@ public function throwUserError($error, $detailedError = null, $goToPaymentSectio } } - /** - * @return HpsCreditService - */ - protected function _getChargeService() + protected function _configureSDK() { - $config = new HpsServicesConfig(); + $config = new ServicesConfig(); // Support HTTP proxy if (Mage::getStoreConfig('payment/hps_transit/use_http_proxy')) { @@ -844,77 +672,59 @@ protected function _getChargeService() ); } - $config->secretApiKey = $this->getConfigData('secretapikey'); + $config->secretApiKey = 'skapi_cert_MTyMAQBiHVEAewvIzXVFcmUd2UcyBge_eCpaASUp0A'; $config->versionNumber = '1573'; $config->developerId = '002914'; + $config->gatewayProvider = GatewayProvider::PORTICO; + $config->environment = Environment::TEST; - return new HpsFluentCreditService($config); + ServicesContainer::configure($config); } - protected function _getGiftService() + /** + * @param Mage_Sales_Model_Order $order + * @return Address + */ + protected function _getCardHolderAddress($order) { - $config = new HpsServicesConfig(); - - // 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'), - ); - } + $billing = $order->getBillingAddress(); - $config->secretApiKey = $this->getConfigData('secretapikey'); - $config->versionNumber = '1573'; - $config->developerId = '002914'; + $address = new Address(); + $address->streetAddress1 = substr($billing->getStreet(1), 0, 40); // Actual limit unknown.. + $address->city = substr($billing->getCity(), 0, 20); + $address->province = substr($billing->getRegion(), 0, 20); + $address->postalCode = substr(preg_replace('/[^A-Z0-9]/', '', strtoupper($billing->getPostcode())), 0, 9); + $address->country = $billing->getCountry(); - return new HpsGiftCardService($config); + return $address; } /** * @param Mage_Sales_Model_Order $order - * @return HpsCardHolder + * @return string */ - protected function _getCardHolderData($order) + protected function _getCardHolderName($order) { $billing = $order->getBillingAddress(); - $address = new HpsAddress(); - $address->address = substr($billing->getStreet(1), 0, 40); // Actual limit unknown.. - $address->city = substr($billing->getCity(), 0, 20); - $address->state = substr($billing->getRegion(), 0, 20); - $address->zip = substr(preg_replace('/[^A-Z0-9]/', '', strtoupper($billing->getPostcode())), 0, 9); - $address->country = $billing->getCountry(); - - $cardHolder = new HpsCardHolder(); - $cardHolder->firstName = substr($billing->getData('firstname'), 0, 26); - $cardHolder->lastName = substr($billing->getData('lastname'), 0, 26); - $cardHolder->phone = substr(preg_replace('/[^0-9]/', '', $billing->getTelephone()), 0, 10); - $cardHolder->emailAddress = substr($billing->getData('email'), 0, 40); - $cardHolder->address = $address; + $firstName = substr($billing->getData('firstname'), 0, 26); + $lastName = substr($billing->getData('lastname'), 0, 26); - return $cardHolder; + return sprintf('%s %s', $firstName, $lastName); } + /** * @param Mage_Sales_Model_Order $order - * @return HpsTransactionDetails + * @return string */ - protected function _getTxnDetailsData($order) + protected function _getTxnMemo($order) { $memo = array(); - $ip = ''; - - if (isset($_SERVER['REMOTE_ADDR'])) { - $ip = $_SERVER['REMOTE_ADDR']; - } - - if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { - $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; - } + $ip = $this->getRemoteIP(); if ($ip) { - $memo[] = 'Customer IP Address: '.$ip; + $memo[] = 'Customer IP Address: ' . $ip; } if (isset($_SERVER['HTTP_USER_AGENT'])) { @@ -922,26 +732,36 @@ protected function _getTxnDetailsData($order) } $memo = implode(', ', $memo); - $details = new HpsTransactionDetails(); - $details->memo = substr($memo, 0, 200); // Actual limit unknown.. - $details->invoiceNumber = $order->getIncrementId(); - $details->customerId = substr($order->getCustomerEmail(), 0, 25); // Actual limit unknown.. + return substr($memo, 0, 200); + } - return $details; + /** + * @param Mage_Sales_Model_Order $order + * @return string + */ + protected function _getTxnInvoiceNumber($order) + { + return $order->getIncrementId(); + } + + /** + * @param Mage_Sales_Model_Order $order + * @return string + */ + protected function _getTxnCustomerId($order) + { + return substr($order->getCustomerEmail(), 0, 25); } /** - * @param HpsCreditService $chargeService * @param Exception|null $exception */ - protected function _debugChargeService(HpsFluentCreditService $chargeService, $exception = null) + protected function _debugChargeService($exception = null) { if ($this->getDebugFlag()) { $debugData = array( 'store' => Mage::app()->getStore($this->getStore())->getFrontendName(), 'exception_message' => $exception ? get_class($exception).': '.$exception->getMessage() : '', - // 'last_request' => $chargeService->lastRequest, - // 'last_response' => $chargeService->lastResponse, ); $this->_debug($debugData); } @@ -972,4 +792,75 @@ public function getFormBlockType() { return Mage::app()->getStore()->isAdmin() ? $this->_formBlockTypeAdmin : $this->_formBlockType; } + + protected function mapResponseCodeToFriendlyMessage($responseCode) { + $result = ''; + + switch ($responseCode) { + case '02': + case '03': + case '04': + case '05': + case '41': + case '43': + case '44': + case '51': + case '56': + case '61': + case '62': + case '63': + case '65': + case '78': + $result = "The card was declined."; + break; + case '06': + case '07': + case '12': + case '15': + case '19': + case '52': + case '53': + case '57': + case '58': + case '76': + case '77': + case '96': + case 'EC': + $result = "An error occurred while processing the card."; + break; + case '13': + $result = "Must be greater than or equal 0."; + break; + case '54': + $result = "The card has expired."; + break; + case '55': + $result = "The pin is invalid."; + break; + case '75': + $result = "Maximum number of pin retries exceeded."; + break; + case '80': + $result = "Card expiration date is invalid."; + break; + case '86': + $result = "Can't verify card pin number."; + break; + case 'EB': + case 'N7': + $result = "The card's security code is incorrect."; + break; + case '91': + $result = "The card issuer timed-out."; + break; + case 'FR': + $result = "Possible fraud detected"; + break; + default: + $result = "An unknown issuer error has occurred."; + break; + } + + return $result; + } } diff --git a/app/code/community/Hps/Transit/etc/config.xml b/app/code/community/Hps/Transit/etc/config.xml index ee96200..286c563 100644 --- a/app/code/community/Hps/Transit/etc/config.xml +++ b/app/code/community/Hps/Transit/etc/config.xml @@ -33,11 +33,8 @@ Hps_Transit_Model_Resource - storedcard
+ hps_transit_storedcard
- - report_settlement
-
@@ -68,8 +65,12 @@ AE,VI,MC,DI,JCB 1 - - + + + + + + no 3 10 0 @@ -129,5 +130,16 @@ + + + + + singleton + hps_transit/observer + requestTransactionKey + + + + diff --git a/app/code/community/Hps/Transit/etc/system.xml b/app/code/community/Hps/Transit/etc/system.xml index 42b3c9c..4dacd4f 100644 --- a/app/code/community/Hps/Transit/etc/system.xml +++ b/app/code/community/Hps/Transit/etc/system.xml @@ -40,23 +40,58 @@ 1 - - + + adminhtml/system_config_backend_encrypted 10 1 1 1 - - - + + + obscure adminhtml/system_config_backend_encrypted 11 1 1 1 - + + + + obscure + adminhtml/system_config_backend_encrypted + 12 + 1 + 1 + 1 + + + + adminhtml/system_config_backend_encrypted + 13 + 1 + 1 + 1 + + + + obscure + adminhtml/system_config_backend_encrypted + 14 + 1 + 1 + 1 + + + + select + adminhtml/system_config_source_yesno + 15 + 1 + 1 + 1 + @@ -89,16 +124,6 @@ Heartland Account must be configured for multi-use tokenization.]]> - - - select - adminhtml/system_config_source_yesno - 31 - 1 - 1 - 1 - - diff --git a/app/code/community/Hps/Transit/sql/hps_transit_setup/install-1.0.0.php b/app/code/community/Hps/Transit/sql/hps_transit_setup/install-1.0.0.php index 11cd88b..baf3d71 100644 --- a/app/code/community/Hps/Transit/sql/hps_transit_setup/install-1.0.0.php +++ b/app/code/community/Hps/Transit/sql/hps_transit_setup/install-1.0.0.php @@ -63,10 +63,12 @@ 'hps_transit/storedcard', 'customer_id', 'customer/entity', - 'entity_id'), + 'entity_id' + ), 'customer_id', $installer->getTable( - 'customer/entity'), + 'customer/entity' + ), 'entity_id', Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE diff --git a/app/design/adminhtml/default/default/layout/transit.xml b/app/design/adminhtml/default/default/layout/transit.xml index dd1b9a3..6a6f74e 100644 --- a/app/design/adminhtml/default/default/layout/transit.xml +++ b/app/design/adminhtml/default/default/layout/transit.xml @@ -2,12 +2,16 @@ - - transit/secure.submit-1.0.1.js - - - transit/admin-checkout.js - + + + + + ]]> + + + + transit/admin-checkout.js diff --git a/app/design/frontend/base/default/layout/transit.xml b/app/design/frontend/base/default/layout/transit.xml index 139e489..7e7035d 100644 --- a/app/design/frontend/base/default/layout/transit.xml +++ b/app/design/frontend/base/default/layout/transit.xml @@ -3,7 +3,7 @@ - + skin_css transit/css/hps-styles.css @@ -11,21 +11,16 @@ - - + + ]]> - transit/checkout-form.js - transit/masterpass/lightbox.js - - - + transit/checkout-form.js @@ -63,16 +58,11 @@ - + save_token transit/storedcard/index - - masterpass_connect - transit/masterpass/connect - - @@ -83,52 +73,4 @@ - - - - - - - - transit/masterpass/lightbox.js - - - - - - - - - - - - - - - - - - - defaultcheckout/cart_item_renderer - groupedcheckout/cart_item_renderer_grouped - configurablecheckout/cart_item_renderer_configurable - - - - - - - skin_jsjs/checkout/review.js - - - - - - - defaultcheckout/cart_item_renderer - groupedcheckout/cart_item_renderer_grouped - configurablecheckout/cart_item_renderer_configurable - - - diff --git a/app/design/frontend/base/default/template/transit/form.phtml b/app/design/frontend/base/default/template/transit/form.phtml index 59ef502..dd21094 100755 --- a/app/design/frontend/base/default/template/transit/form.phtml +++ b/app/design/frontend/base/default/template/transit/form.phtml @@ -5,7 +5,7 @@ $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 = !!Mage::getModel('hps_transit/payment')->getConfigData('use_iframes'); +$use_iframes = true; $cca = $this->getCca(); if ($_loggedIn && $allow_card_saving) { @@ -96,9 +96,9 @@ TransITMagento.init({ allowGift: false, useIframes: true, iframeTargets: { - cardNumber: '_cc_number_iframe', - cardExpiration: '_cc_exp_iframe', - cardCvv: '_cc_cvv_iframe' + cardNumber: '#_cc_number_iframe', + cardExpiration: '#_cc_exp_iframe', + cardCvv: '#_cc_cvv_iframe' } }); diff --git a/composer.json b/composer.json index 62c84ac..656f100 100644 --- a/composer.json +++ b/composer.json @@ -6,13 +6,13 @@ "authors": [ { "name": "Heartland Payment Systems", - "email": "EntApp_DevPortal@e-hps.com" + "email": "developers@heartland.us" } ], "keywords": [ "openmage-module" ], "require": { - "globalpayments/php-sdk": "*" + "globalpayments/php-sdk": "dev-TransIT_Certification" } } diff --git a/js/transit/checkout-form.js b/js/transit/checkout-form.js index fe821bc..ecfff69 100644 --- a/js/transit/checkout-form.js +++ b/js/transit/checkout-form.js @@ -4,7 +4,7 @@ if (!String.prototype.trim) { }; } -(function(window, document, undefined) { +(function(window, document, _undefined) { var opcTokenSubmits = {}; var THIS = { __data: {}, @@ -12,41 +12,40 @@ if (!String.prototype.trim) { init: function(options) { THIS.options = options; THIS.observeSavedCards(); - THIS.observeGift(); if (typeof Payment !== 'undefined') { window.payment = window.payment || {}; - payment.secureSubmitPublicKey = THIS.options.publicKey; - payment.secureSubmitGetTokenDataUrl = THIS.options.tokenDataUrl; + payment.transitPublicKey = THIS.options.publicKey; + payment.transitGetTokenDataUrl = THIS.options.tokenDataUrl; } else if (document.getElementById('multishipping-billing-form')) { - THIS.secureSubmitMS = transitMultishipping( + THIS.transitMS = transitMultishipping( document.getElementById('multishipping-billing-form') ); - THIS.secureSubmitMS.secureSubmitPublicKey = THIS.options.publicKey; - THIS.secureSubmitMS.secureSubmitGetTokenDataUrl = + THIS.transitMS.transitPublicKey = THIS.options.publicKey; + THIS.transitMS.transitGetTokenDataUrl = THIS.options.tokenDataUrl; document.observe('dom:loaded', function() { Event.observe('payment-continue', 'click', function(e) { Event.stop(e); - THIS.secureSubmitMS.save(); + THIS.transitMS.save(); }); }); } if (typeof OPC !== 'undefined') { - OPC.prototype.secureSubmitPublicKey = THIS.options.publicKey; - OPC.prototype.secureSubmitGetTokenDataUrl = THIS.options.tokenDataUrl; + OPC.prototype.transitPublicKey = THIS.options.publicKey; + OPC.prototype.transitGetTokenDataUrl = THIS.options.tokenDataUrl; } // MageStore OSC window.payment = window.payment || {}; - window.payment.secureSubmitPublicKeyOSC = THIS.options.publicKey; - window.payment.secureSubmitGetTokenDataUrlOSC = THIS.options.tokenDataUrl; + window.payment.transitPublicKeyOSC = THIS.options.publicKey; + window.payment.transitGetTokenDataUrlOSC = THIS.options.tokenDataUrl; // IWD OPC if (typeof IWD !== 'undefined' && typeof IWD.OPC !== 'undefined') { - IWD.OPC.secureSubmitPublicKey = THIS.options.publicKey; - IWD.OPC.secureSubmitGetTokenDataUrl = THIS.options.tokenDataUrl; + IWD.OPC.transitPublicKey = THIS.options.publicKey; + IWD.OPC.transitGetTokenDataUrl = THIS.options.tokenDataUrl; } // Latest Version of IWD One page Checkout @@ -55,16 +54,16 @@ if (!String.prototype.trim) { typeof OnePage !== 'undefined' && typeof PaymentMethod !== 'undefined' ) { - PaymentMethod.prototype.secureSubmitPublicKey = THIS.options.publicKey; - PaymentMethod.prototype.secureSubmitGetTokenDataUrl = + PaymentMethod.prototype.transitPublicKey = THIS.options.publicKey; + PaymentMethod.prototype.transitGetTokenDataUrl = THIS.options.tokenDataUrl; } // AheadWorks OneStepCheckout if (typeof AWOnestepcheckoutForm !== 'undefined') { - AWOnestepcheckoutForm.prototype.secureSubmitPublicKey = + AWOnestepcheckoutForm.prototype.transitPublicKey = THIS.options.publicKey; - AWOnestepcheckoutForm.prototype.secureSubmitGetTokenDataUrl = + AWOnestepcheckoutForm.prototype.transitGetTokenDataUrl = THIS.options.tokenDataUrl; } @@ -103,312 +102,259 @@ if (!String.prototype.trim) { ); } }, - observeGift: function() { - if (THIS.options.allowGift) { - Event.observe('apply-gift-card', 'click', function(event) { - $j.ajax({ - url: THIS.options.giftBalanceUrl, - type: 'GET', - data: - 'giftcard_number=' + - $j('#' + THIS.options.code + '_giftcard_number').val() + - '&giftcard_pin=' + - $j('#' + THIS.options.code + '_giftcard_pin').val(), - success: function(data) { - if (data.error) { - alert('Error adding gift card: ' + data.message); - } else { - //successful gift, show things - $j('#apply-gift-card').hide(); - $j('#' + THIS.options.code + '_giftcard_number').hide(); - $j('#' + THIS.options.code + '_giftcard_pin').hide(); - $j('#gift-card-number-label').text( - $j('#' + THIS.options.code + '_giftcard_number').val() + - ' - $' + - data.balance - ); - $j('#gift-card-number-label').show(); - $j('#remove-gift-card').show(); - - if (!data.less_than_total) { - // skip cc capture enable - $$('#payment_form_hps_transit .new-card')[0].hide(); - $('hps_transit_gift_card').style.borderTopWidth = '0px'; - $(THIS.options.code + '_token').value = 'dummy'; - THIS.skipCreditCard = true; - $(THIS.options.code + '_giftcard_skip_cc').value = 'true'; - } - } - }, - }); - }); - Event.observe('remove-gift-card', 'click', function(event) { - $j('#apply-gift-card').show(); - $j('#' + THIS.options.code + '_giftcard_number').val(''); - $j('#' + THIS.options.code + '_giftcard_number').show(); - $j('#' + THIS.options.code + '_giftcard_pin').val(''); - $j('#' + THIS.options.code + '_giftcard_pin').show(); - $j('#gift-card-number-label').text(''); - $j('#gift-card-number-label').hide(); - $j('#remove-gift-card').hide(); - - // skip cc capture disable - $$('#payment_form_hps_transit .new-card')[0].show(); - $('hps_transit_gift_card').style.borderTopWidth = '1px'; - $(THIS.options.code + '_token').value = ''; - THIS.skipCreditCard = false; - $(THIS.options.code + '_giftcard_skip_cc').value = 'false'; - }); - } - }, setupFields: function() { - if (THIS.options.useIframes) { - var options = { - publicKey: THIS.options.publicKey, - type: 'iframe', - fields: { - cardNumber: { - target: THIS.options.iframeTargets.cardNumber, - placeholder: '•••• •••• •••• ••••', - }, - cardExpiration: { - target: THIS.options.iframeTargets.cardExpiration, - placeholder: 'MM / YYYY', - }, - cardCvv: { - target: THIS.options.iframeTargets.cardCvv, - placeholder: 'CVV', - }, + GlobalPayments.configure({ + publicApiKey: 'pkapi_cert_jKc1FtuyAydZhZfbB3', + }); + + THIS.cardForm = GlobalPayments.ui.form({ + fields: { + "card-number": { + target: THIS.options.iframeTargets.cardNumber, + placeholder: '•••• •••• •••• ••••', }, - style: { - '#heartland-field': { - height: '40px', - border: '1px solid silver', - 'letter-spacing': '2.5px', - width: '97.5%', - 'padding-left': '9px', - }, - '.iwd-opc-index-index #heartland-field': { - 'max-width': '365px', - }, - '#heartland-field:hover': { - border: '1px solid #3989e3', - }, - '#heartland-field:focus': { - border: '1px solid #3989e3', - 'box-shadow': 'none', - outline: 'none', - }, - '#heartland-field[name="cardNumber"]': { - background: - 'transparent url(' + - THIS.options.baseUrl.replace('/index.php', '') + - 'skin/frontend/base/default/transit/images/ss-inputcard-blank@2x.png) no-repeat right', - 'background-size': '50px 30px', - }, - '#heartland-field.valid.card-type-visa': { - background: - 'transparent url(' + - THIS.options.baseUrl.replace('/index.php', '') + - 'skin/frontend/base/default/transit/images/ss-saved-visa@2x.png) no-repeat top right', - 'background-size': '75px 84px', - }, - '#heartland-field.invalid.card-type-visa': { - background: - 'transparent url(' + - THIS.options.baseUrl.replace('/index.php', '') + - 'skin/frontend/base/default/transit/images/ss-saved-visa@2x.png) no-repeat bottom right', - 'background-size': '75px 84px', - }, - '#heartland-field[name="cardNumber"].invalid.card-type-discover': { - background: - 'transparent url(' + - THIS.options.baseUrl.replace('/index.php', '') + - 'skin/frontend/base/default/transit/images/ss-saved-discover@2x.png) no-repeat right', - 'background-size': '70px 74px', - 'background-position-y': '-35px', - }, - '#heartland-field[name="cardNumber"].valid.card-type-discover': { - background: - 'transparent url(' + - THIS.options.baseUrl.replace('/index.php', '') + - 'skin/frontend/base/default/transit/images/ss-saved-discover@2x.png) no-repeat right', - 'background-size': '70px 74px', - 'background-position-y': '2px', - }, - '#heartland-field[name="cardNumber"].invalid.card-type-amex': { - background: - 'transparent url(' + - THIS.options.baseUrl.replace('/index.php', '') + - 'skin/frontend/base/default/transit/images/ss-input-amex@2x.png) no-repeat center right', - 'background-size': '50px 55px', - }, - '#heartland-field[name="cardNumber"].valid.card-type-amex': { - background: - 'transparent url(' + - THIS.options.baseUrl.replace('/index.php', '') + - 'skin/frontend/base/default/transit/images/ss-inputcard-amex@2x.png) no-repeat center right', - 'background-size': '50px 55px', - }, - '#heartland-field[name="cardNumber"].invalid.card-type-jcb': { - background: - 'transparent url(' + - THIS.options.baseUrl.replace('/index.php', '') + - 'skin/frontend/base/default/transit/images/ss-saved-jcb@2x.png) no-repeat right', - 'background-size': '75px 75px', - 'background-position-y': '10px -35px', - }, - '#heartland-field[name="cardNumber"].valid.card-type-jcb': { - background: - 'transparent url(' + - THIS.options.baseUrl.replace('/index.php', '') + - 'skin/frontend/base/default/transit/images/ss-saved-jcb@2x.png) no-repeat right', - 'background-size': '75px 76px', - 'background-position-y': '10px 2px', - }, - '#heartland-field[name="cardNumber"].invalid.card-type-mastercard': { - background: - 'transparent url(' + - THIS.options.baseUrl.replace('/index.php', '') + - 'skin/frontend/base/default/transit/images/ss-saved-mastercard@2x.png) no-repeat bottom right', - 'background-size': '71px', - 'background-position-y': '-35px', - }, - '#heartland-field[name="cardNumber"].valid.card-type-mastercard': { - background: - 'transparent url(' + - THIS.options.baseUrl.replace('/index.php', '') + - 'skin/frontend/base/default/transit/images/ss-saved-mastercard@2x.png) no-repeat top right', - 'background-size': '71px', - 'background-position-y': '3px', - }, - '#heartland-field[name="cardCvv"]': { - background: - 'transparent url(' + - THIS.options.baseUrl.replace('/index.php', '') + - 'skin/frontend/base/default/transit/images/cvv1.png) no-repeat right', - 'background-size': '50px 30px', - }, - '@media only screen and (max-width: 479px)': { - '#heartland-field': { - width: '95%', - }, + "card-expiration": { + target: THIS.options.iframeTargets.cardExpiration, + placeholder: 'MM / YYYY', + }, + "card-cvv": { + target: THIS.options.iframeTargets.cardCvv, + placeholder: 'CVV', + }, + }, + styles: { + '#secure-payment-field': { + height: '40px', + border: '1px solid silver', + 'letter-spacing': '2.5px', + width: '97.5%', + 'padding-left': '9px', + }, + '#secure-payment-field:hover': { + border: '1px solid #3989e3', + }, + '#secure-payment-field:focus': { + border: '1px solid #3989e3', + 'box-shadow': 'none', + outline: 'none', + }, + '#secure-payment-field[name="cardNumber"]': { + background: + 'transparent url(' + + THIS.options.baseUrl.replace('/index.php', '') + + 'skin/frontend/base/default/transit/images/ss-inputcard-blank@2x.png) no-repeat right', + 'background-size': '50px 30px', + }, + '#secure-payment-field[name="cardNumber"].valid.card-type-visa': { + background: + 'transparent url(' + + THIS.options.baseUrl.replace('/index.php', '') + + 'skin/frontend/base/default/transit/images/ss-saved-visa@2x.png) no-repeat top right', + 'background-size': '75px 84px', + }, + '#secure-payment-field[name="cardNumber"].invalid.card-type-visa': { + background: + 'transparent url(' + + THIS.options.baseUrl.replace('/index.php', '') + + 'skin/frontend/base/default/transit/images/ss-saved-visa@2x.png) no-repeat bottom right', + 'background-size': '75px 84px', + }, + '#secure-payment-field[name="cardNumber"].invalid.card-type-discover': { + background: + 'transparent url(' + + THIS.options.baseUrl.replace('/index.php', '') + + 'skin/frontend/base/default/transit/images/ss-saved-discover@2x.png) no-repeat right', + 'background-size': '70px 74px', + 'background-position-y': '-35px', + }, + '#secure-payment-field[name="cardNumber"].valid.card-type-discover': { + background: + 'transparent url(' + + THIS.options.baseUrl.replace('/index.php', '') + + 'skin/frontend/base/default/transit/images/ss-saved-discover@2x.png) no-repeat right', + 'background-size': '70px 74px', + 'background-position-y': '2px', + }, + '#secure-payment-field[name="cardNumber"].invalid.card-type-amex': { + background: + 'transparent url(' + + THIS.options.baseUrl.replace('/index.php', '') + + 'skin/frontend/base/default/transit/images/ss-input-amex@2x.png) no-repeat center right', + 'background-size': '50px 55px', + }, + '#secure-payment-field[name="cardNumber"].valid.card-type-amex': { + background: + 'transparent url(' + + THIS.options.baseUrl.replace('/index.php', '') + + 'skin/frontend/base/default/transit/images/ss-inputcard-amex@2x.png) no-repeat center right', + 'background-size': '50px 55px', + }, + '#secure-payment-field[name="cardNumber"].invalid.card-type-jcb': { + background: + 'transparent url(' + + THIS.options.baseUrl.replace('/index.php', '') + + 'skin/frontend/base/default/transit/images/ss-saved-jcb@2x.png) no-repeat right', + 'background-size': '75px 75px', + 'background-position-y': '10px -35px', + }, + '#secure-payment-field[name="cardNumber"].valid.card-type-jcb': { + background: + 'transparent url(' + + THIS.options.baseUrl.replace('/index.php', '') + + 'skin/frontend/base/default/transit/images/ss-saved-jcb@2x.png) no-repeat right', + 'background-size': '75px 76px', + 'background-position-y': '10px 2px', + }, + '#secure-payment-field[name="cardNumber"].invalid.card-type-mastercard': { + background: + 'transparent url(' + + THIS.options.baseUrl.replace('/index.php', '') + + 'skin/frontend/base/default/transit/images/ss-saved-mastercard@2x.png) no-repeat bottom right', + 'background-size': '71px', + 'background-position-y': '-35px', + }, + '#secure-payment-field[name="cardNumber"].valid.card-type-mastercard': { + background: + 'transparent url(' + + THIS.options.baseUrl.replace('/index.php', '') + + 'skin/frontend/base/default/transit/images/ss-saved-mastercard@2x.png) no-repeat top right', + 'background-size': '71px', + 'background-position-y': '3px', + }, + '#secure-payment-field.card-cvv': { + background: + 'transparent url(' + + THIS.options.baseUrl.replace('/index.php', '') + + 'skin/frontend/base/default/transit/images/cvv1.png) no-repeat right', + 'background-size': '50px 30px', + }, + '@media only screen and (max-width: 479px)': { + '#secure-payment-field': { + width: '95%', }, }, - onTokenSuccess: function(resp) { - var heartland = resp.heartland || resp; + } + }) + + THIS.cardForm.on('token-success', function(resp) { + // BEGIN: AheadWorks OneStepCheckout fix + // This is required in order to work around a limitation with AW OSC and our + // iframes' `message` event handler. Because of how AW OSC refreshes the payment + // multiple times, mutiple event handlers for `message` are added, so the + // `onTokenSuccess` event that we receive is firing multiple times which also + // submits the form multiple times, attempting to create multiple orders. + if ( + THIS.isOnePageCheckout() && + typeof opcTokenSubmits[resp.paymentReference] !== 'undefined' + ) { + return; + } - // TODO: Need to investigate why this is necessary - if (heartland.error) { - options.onTokenError(heartland); - return; - } + opcTokenSubmits[resp.paymentReference] = true; + // END: AheadWorks OneStepCheckout fix + + $(THIS.options.code + '_token').value = resp.paymentReference; + + if (resp.details) { + $( + THIS.options.code + '_cc_last_four' + ).value = resp.details.cardLast4; + $(THIS.options.code + '_cc_type').value = resp.details.cardType; + $( + THIS.options.code + '_cc_exp_month' + ).value = resp.details.expiryMonth.trim(); + $( + THIS.options.code + '_cc_exp_year' + ).value = resp.details.expiryYear.trim(); + } - // BEGIN: AheadWorks OneStepCheckout fix - // This is required in order to work around a limitation with AW OSC and our - // iframes' `message` event handler. Because of how AW OSC refreshes the payment - // multiple times, mutiple event handlers for `message` are added, so the - // `onTokenSuccess` event that we receive is firing multiple times which also - // submits the form multiple times, attempting to create multiple orders. - if ( - THIS.isOnePageCheckout() && - typeof opcTokenSubmits[heartland.token_value] !== 'undefined' - ) { - return; - } + THIS.completeCheckout(); + }); - opcTokenSubmits[heartland.token_value] = true; - // END: AheadWorks OneStepCheckout fix - - $(THIS.options.code + '_token').value = heartland.token_value; - $( - THIS.options.code + '_cc_last_four' - ).value = heartland.card.number.substr(-4); - $(THIS.options.code + '_cc_type').value = heartland.card_type; - $( - THIS.options.code + '_cc_exp_month' - ).value = heartland.exp_month.trim(); - $( - THIS.options.code + '_cc_exp_year' - ).value = heartland.exp_year.trim(); - - if (resp.cardinal) { - var el = document.createElement('input'); - el.value = resp.cardinal.token_value; - el.type = 'hidden'; - el.name = 'payment[cardinal_token]'; - el.id = THIS.options.code + '_cardinal_token'; - $('payment_form_' + THIS.options.code).appendChild(el); - } + var onError = function(response) { + if (THIS.skipCreditCard) { + THIS.completeCheckout(); + return; + } - THIS.initializeCCA(THIS.completeCheckout); - }, - onTokenError: function(response) { - if (THIS.skipCreditCard) { - THIS.completeCheckout(); - return; - } + if (response.error.message) { + alert(response.error.message); + } else { + alert('Unexpected error.'); + } - if (response.error.message) { - alert(response.error.message); - } else { - alert('Unexpected error.'); - } + if (typeof Payment !== 'undefined' && window.checkout) { + checkout.setLoadWaiting(false); + } else if (typeof OPC !== 'undefined' && window.checkout) { + checkout.setLoadWaiting(false); + } else if ( + typeof iwdOpcConfig !== 'undefined' && + typeof OnePage !== 'undefined' && + typeof PaymentMethod !== 'undefined' + ) { + $ji('.iwd_opc_loader_wrapper.active').hide(); + } - if (typeof Payment !== 'undefined' && window.checkout) { - checkout.setLoadWaiting(false); - } else if (typeof OPC !== 'undefined' && window.checkout) { - checkout.setLoadWaiting(false); - } else if ( - typeof iwdOpcConfig !== 'undefined' && - typeof OnePage !== 'undefined' && - typeof PaymentMethod !== 'undefined' - ) { - $ji('.iwd_opc_loader_wrapper.active').hide(); - } + if (window.awOSCForm) { + form.enablePlaceOrderButton(); + form.hidePleaseWaitNotice(); + form.hideOverlay(); + } + }; - if (window.awOSCForm) { - form.enablePlaceOrderButton(); - form.hidePleaseWaitNotice(); - form.hideOverlay(); - } - }, - }; + THIS.cardForm.on('token-error', onError); + GlobalPayments.on('error', onError); + + if (document.getElementById('amscheckout-onepage')) { + var ssbanner = document.getElementById('ss-banner'); + var ccnumber = document.getElementById('cc-number'); + var expirationdate = document.getElementById('expiration-dat'); + var ccv = document.getElementById('payment-buttons-container'); - if (THIS.options.cca) { - options.cca = THIS.options.cca; + if (ssbanner) { + ssbanner.style.backgroundSize = '325px 40px'; + } + if (ccnumber) { + ccnumber.className = 'transit_amasty_one_page_checkout'; + } + if (expirationdate) { + expirationdate.className = 'transit_amasty_one_page_checkout'; + } + if (ccv) { + ccv.className = 'transit_amasty_one_page_checkout'; } + } + }, + triggerSubmit: function () { + // manually include submit button + const fields = ['submit']; + const target = THIS.cardForm.frames['card-number']; + + for (const type in THIS.cardForm.frames) { + if (THIS.cardForm.frames.hasOwnProperty(type)) { + fields.push(type); + } + } - THIS.tokenizeOptions = options; - THIS.hps = new Heartland.HPS(options); + for (const type in THIS.cardForm.frames) { + if (!THIS.cardForm.frames.hasOwnProperty(type)) { + continue; + } - if (document.getElementById('amscheckout-onepage')) { - var ssbanner = document.getElementById('ss-banner'); - var ccnumber = document.getElementById('cc-number'); - var expirationdate = document.getElementById('expiration-dat'); - var ccv = document.getElementById('payment-buttons-container'); + const frame = THIS.cardForm.frames[type]; - if (ssbanner) { - ssbanner.style.backgroundSize = '325px 40px'; - } - if (ccnumber) { - ccnumber.className = 'transit_amasty_one_page_checkout'; - } - if (expirationdate) { - expirationdate.className = 'transit_amasty_one_page_checkout'; - } - if (ccv) { - ccv.className = 'transit_amasty_one_page_checkout'; - } + if (!frame) { + continue; } - } else { - Heartland.Card.attachNumberEvents( - '#' + THIS.options.code + '_cc_number' - ); - Heartland.Card.attachExpirationEvents( - '#' + THIS.options.code + '_exp_date' - ); - Heartland.Card.attachCvvEvents('#' + THIS.options.code + '_cvv_number'); + + GlobalPayments.internal.postMessage.post({ + data: { + fields: fields, + target: target.id + }, + id: frame.id, + type: 'ui:iframe-field:request-data' + }, frame.id); } }, isOnePageCheckout: function() { @@ -418,7 +364,7 @@ if (!String.prototype.trim) { (typeof iwdOpcConfig !== 'undefined' && typeof OnePage !== 'undefined' && typeof PaymentMethod !== 'undefined') || - window.secureSubmitAmastyCompleteCheckoutOriginal || + window.transitAmastyCompleteCheckoutOriginal || window.oscPlaceOrderOriginal || window.awOSCForm ); @@ -446,8 +392,8 @@ if (!String.prototype.trim) { ) { $ji('.iwd_opc_loader_wrapper.active').show(); Singleton.get(OnePage).saveOrder(); - } else if (window.secureSubmitAmastyCompleteCheckoutOriginal) { - secureSubmitAmastyCompleteCheckoutOriginal(); + } else if (window.transitAmastyCompleteCheckoutOriginal) { + transitAmastyCompleteCheckoutOriginal(); } else if (window.oscPlaceOrderOriginal) { $('onestepcheckout-place-order-loading').show(); $('onestepcheckout-button-place-order').removeClassName( @@ -469,106 +415,8 @@ if (!String.prototype.trim) { document.getElementById('payment-continue').enable(); document.getElementById('multishipping-billing-form').submit(); } else if (window.awOSCForm) { - awOSCForm._secureSubmitOldPlaceOrder(); - } - }, - initializeCCA: function(callback) { - if (!THIS.options.cca) { - callback(); - return; - } - - Cardinal.__secureSubmitInitFrame = - Cardinal.__secureSubmitInitFrame || false; - if (!Cardinal.__secureSubmitInitFrame) { - Cardinal.setup('init', { - jwt: THIS.options.cca.jwt, - }); - Cardinal.on('payments.validated', function(data, jwt) { - var makeField = function(name, value) { - var el = document.createElement('input'); - el.value = value; - el.type = 'hidden'; - el.name = 'payment[cca_data_' + name + ']'; - $('payment_form_' + THIS.options.code).appendChild(el); - }; - makeField('action_code', data.ActionCode); - makeField( - 'cavv', - data.Payment && - data.Payment.ExtendedData && - data.Payment.ExtendedData.CAVV - ? data.Payment.ExtendedData.CAVV - : '' - ); - makeField( - 'eci', - data.Payment && - data.Payment.ExtendedData && - data.Payment.ExtendedData.ECIFlag - ? data.Payment.ExtendedData.ECIFlag - : '' - ); - makeField( - 'xid', - data.Payment && - data.Payment.ExtendedData && - data.Payment.ExtendedData.XID - ? data.Payment.ExtendedData.XID - : '' - ); - makeField( - 'token', - data.Token && data.Token.Token ? data.Token.Token : '' - ); - if (callback) { - callback(); - } - }); - Cardinal.__secureSubmitInitFrame = true; + awOSCForm._transitOldPlaceOrder(); } - - Cardinal.trigger('jwt.update', THIS.options.cca.jwt); - - var payload = { - OrderDetails: { - OrderNumber: THIS.options.cca.orderNumber + 'cca', - }, - }; - - if (THIS.options.useIframes) { - payload.Token = { - Token: $(THIS.options.code + '_cardinal_token').value, - ExpirationMonth: $('hps_transit_cc_exp_month').value.replace( - /\D/g, - '' - ), - ExpirationYear: $('hps_transit_cc_exp_year').value.replace( - /\D/g, - '' - ), - }; - } else { - payload.Consumer = { - Account: { - AccountNumber: $('hps_transit_cc_number').value.replace( - /\D/g, - '' - ), - CardCode: $('hps_transit_cvv_number').value.replace(/\D/g, ''), - ExpirationMonth: $('hps_transit_cc_exp_month').value.replace( - /\D/g, - '' - ), - ExpirationYear: $('hps_transit_cc_exp_year').value.replace( - /\D/g, - '' - ), - }, - }; - } - - Cardinal.start('cca', payload); }, useStoredCard: function() { var newRadio = $('hps_transit_stored_card_select_new'); @@ -611,7 +459,7 @@ if (!String.prototype.trim) { })(window, window.document); function transitMultishipping(multiForm) { - var secureSubmit = { + var transit = { save: function() { if (payment && payment.currentMethod != 'hps_transit') { multiForm.submit(); @@ -621,14 +469,14 @@ function transitMultishipping(multiForm) { document.getElementById('payment-continue').disable(); // Use stored card checked, get existing token data - if (this.secureSubmitUseStoredCard()) { + if (this.transitUseStoredCard()) { var radio = $$( '[name="hps_transit_stored_card_select"]:checked' )[0]; var storedcardId = radio.value; var storedcardType = $(radio.id + '_card_type').value; - new Ajax.Request(this.secureSubmitGetTokenDataUrl, { + new Ajax.Request(this.transitGetTokenDataUrl, { method: 'post', parameters: {storedcard_id: storedcardId}, onSuccess: function(response) { @@ -639,7 +487,7 @@ function transitMultishipping(multiForm) { ); $('hps_transit_cc_exp_year').value = data.token.cc_exp_year; } - this.secureSubmitResponseHandler.call(this, { + this.transitResponseHandler.call(this, { card_type: storedcardType, token_value: data.token.token_value, token_type: null, // 'supt'? @@ -655,42 +503,14 @@ function transitMultishipping(multiForm) { }); } else { // Use stored card not checked, get new token - if (TransITMagento.options.useIframes) { - TransITMagento.hps.Messages.post( - { - accumulateData: true, - action: 'tokenize', - data: TransITMagento.tokenizeOptions, - }, - 'cardNumber' - ); - } else { - var validator = new Validation(multiForm); - if (validator.validate()) { - if ($('hps_transit_exp_date').value) { - var date = $('hps_transit_exp_date').value.split('/'); - $('hps_transit_cc_exp_month').value = date[0].trim(); - $('hps_transit_cc_exp_year').value = date[1].trim(); - } - - new Heartland.HPS({ - publicKey: this.secureSubmitPublicKey, - cardNumber: $('hps_transit_cc_number').value, - cardCvv: $('hps_transit_cvv_number').value, - cardExpMonth: $('hps_transit_cc_exp_month').value, - cardExpYear: $('hps_transit_cc_exp_year').value, - success: this.secureSubmitResponseHandler.bind(this), - error: this.secureSubmitResponseHandler.bind(this), - }).tokenize(); - } - } + TransITMagento.triggerSubmit(); } }, - secureSubmitUseStoredCard: function() { + transitUseStoredCard: function() { var newRadio = $('hps_transit_stored_card_select_new'); return !newRadio.checked; }, - secureSubmitResponseHandler: function(response) { + transitResponseHandler: function(response) { var tokenField = $('hps_transit_token'), typeField = $('hps_transit_cc_type'), lastFourField = $('hps_transit_cc_last_four'); @@ -727,15 +547,15 @@ function transitMultishipping(multiForm) { } }, }; - return secureSubmit; + return transit; } -var secureSubmitAmastyCompleteCheckoutOriginal; +var transitAmastyCompleteCheckoutOriginal; // AheadWorks OneStepCheckout Event.observe(document, 'aw_osc:onestepcheckout_form_init_before', function(e) { var form = e.memo.form; var oldAwOsc = Object.clone(form); - form._secureSubmitOldPlaceOrder = oldAwOsc.placeOrder; + form._transitOldPlaceOrder = oldAwOsc.placeOrder; form.placeOrder = function() { var checkedPaymentMethod = $$( @@ -745,7 +565,7 @@ Event.observe(document, 'aw_osc:onestepcheckout_form_init_before', function(e) { checkedPaymentMethod.length !== 1 || checkedPaymentMethod[0].value !== 'hps_transit' ) { - this._secureSubmitOldPlaceOrder(); + this._transitOldPlaceOrder(); return; } @@ -754,7 +574,7 @@ Event.observe(document, 'aw_osc:onestepcheckout_form_init_before', function(e) { var radio = $$('[name="hps_transit_stored_card_select"]:checked')[0]; var storedcardId = radio.value; var storedcardType = $(radio.id + '_card_type').value; - new Ajax.Request(form.secureSubmitGetTokenDataUrl, { + new Ajax.Request(form.transitGetTokenDataUrl, { method: 'post', parameters: {storedcard_id: storedcardId}, onSuccess: function(response) { @@ -765,7 +585,7 @@ Event.observe(document, 'aw_osc:onestepcheckout_form_init_before', function(e) { ); $('hps_transit_cc_exp_year').value = data.token.cc_exp_year; } - this.secureSubmitResponseHandler.call(this, { + this.transitResponseHandler.call(this, { card_type: storedcardType, token_value: data.token.token_value, token_type: null, // 'supt'? @@ -785,14 +605,7 @@ Event.observe(document, 'aw_osc:onestepcheckout_form_init_before', function(e) { } else { // Use stored card not checked, get new token if (window.TransITMagento.options.useIframes) { - window.TransITMagento.hps.Messages.post( - { - accumulateData: true, - action: 'tokenize', - data: window.TransITMagento.tokenizeOptions, - }, - 'cardNumber' - ); + window.TransITMagento.triggerSubmit(); } else { if ( $('hps_transit_exp_date') && @@ -804,19 +617,19 @@ Event.observe(document, 'aw_osc:onestepcheckout_form_init_before', function(e) { } new Heartland.HPS({ - publicKey: form.secureSubmitPublicKey, + publicKey: form.transitPublicKey, cardNumber: $('hps_transit_cc_number').value, cardCvv: $('hps_transit_cvv_number').value, cardExpMonth: $('hps_transit_cc_exp_month').value, cardExpYear: $('hps_transit_cc_exp_year').value, - success: form.secureSubmitResponseHandler.bind(form), - error: form.secureSubmitResponseHandler.bind(form), + success: form.transitResponseHandler.bind(form), + error: form.transitResponseHandler.bind(form), }).tokenize(); } } }; - form.secureSubmitResponseHandler = function(response) { + form.transitResponseHandler = function(response) { var tokenField = $('hps_transit_token'), typeField = $('hps_transit_cc_type'), lastFourField = $('hps_transit_cc_last_four'); @@ -848,12 +661,8 @@ Event.observe(document, 'aw_osc:onestepcheckout_form_init_before', function(e) { lastFourField.value = response.card.number.substr(-4); typeField.value = response.card_type; - window.TransITMagento.initializeCCA( - function() { - // Continue Magento checkout steps - form._secureSubmitOldPlaceOrder(); - }.bind(this) - ); + // Continue Magento checkout steps + form._transitOldPlaceOrder(); } else { alert('Unexpected error.'); } @@ -863,28 +672,28 @@ Event.observe(document, 'aw_osc:onestepcheckout_form_init_before', function(e) { document.observe('dom:loaded', function() { // Override default Payment save handler if (typeof Payment !== 'undefined') { - if (typeof Payment.prototype._secureSubmitOldSave === 'undefined') { + if (typeof Payment.prototype._transitOldSave === 'undefined') { var oldPayment = Object.clone(Payment.prototype); - Payment.prototype._secureSubmitOldSave = oldPayment.save; + Payment.prototype._transitOldSave = oldPayment.save; } Object.extend(Payment.prototype, { save: function() { if (this.currentMethod != 'hps_transit') { - this._secureSubmitOldSave(); + this._transitOldSave(); return; } if (checkout.loadWaiting !== false) return; // Use stored card checked, get existing token data - if (this.secureSubmitUseStoredCard()) { + if (this.transitUseStoredCard()) { var radio = $$( '[name="hps_transit_stored_card_select"]:checked' )[0]; var storedcardId = radio.value; var storedcardType = $(radio.id + '_card_type').value; checkout.setLoadWaiting('payment'); - new Ajax.Request(this.secureSubmitGetTokenDataUrl, { + new Ajax.Request(this.transitGetTokenDataUrl, { method: 'post', parameters: {storedcard_id: storedcardId}, onSuccess: function(response) { @@ -896,7 +705,7 @@ document.observe('dom:loaded', function() { $('hps_transit_cc_exp_year').value = data.token.cc_exp_year; } - this.secureSubmitResponseHandler.call(this, { + this.transitResponseHandler.call(this, { card_type: storedcardType, token_value: data.token.token_value, token_type: null, // 'supt'? @@ -915,14 +724,7 @@ document.observe('dom:loaded', function() { // Use stored card not checked, get new token if (TransITMagento.options.useIframes) { checkout.setLoadWaiting('payment'); - TransITMagento.hps.Messages.post( - { - accumulateData: true, - action: 'tokenize', - data: TransITMagento.tokenizeOptions, - }, - 'cardNumber' - ); + TransITMagento.triggerSubmit(); } else { var validator = new Validation(this.form); if (this.validate() && validator.validate()) { @@ -938,23 +740,23 @@ document.observe('dom:loaded', function() { } new Heartland.HPS({ - publicKey: this.secureSubmitPublicKey, + publicKey: this.transitPublicKey, cardNumber: $('hps_transit_cc_number').value, cardCvv: $('hps_transit_cvv_number').value, cardExpMonth: $('hps_transit_cc_exp_month').value, cardExpYear: $('hps_transit_cc_exp_year').value, - success: this.secureSubmitResponseHandler.bind(this), - error: this.secureSubmitResponseHandler.bind(this), + success: this.transitResponseHandler.bind(this), + error: this.transitResponseHandler.bind(this), }).tokenize(); } } } }, - secureSubmitUseStoredCard: function() { + transitUseStoredCard: function() { var newRadio = $('hps_transit_stored_card_select_new'); return !newRadio.checked; }, - secureSubmitResponseHandler: function(response) { + transitResponseHandler: function(response) { var tokenField = $('hps_transit_token'), typeField = $('hps_transit_cc_type'), lastFourField = $('hps_transit_cc_last_four'); @@ -984,18 +786,14 @@ document.observe('dom:loaded', function() { lastFourField.value = response.card.number.substr(-4); typeField.value = response.card_type; - TransITMagento.initializeCCA( - function() { - // Continue Magento checkout steps - new Ajax.Request(this.saveUrl, { - method: 'post', - onComplete: this.onComplete, - onSuccess: this.onSave, - onFailure: checkout.ajaxFailure.bind(checkout), - parameters: Form.serialize(this.form), - }); - }.bind(this) - ); + // Continue Magento checkout steps + new Ajax.Request(this.saveUrl, { + method: 'post', + onComplete: this.onComplete, + onSuccess: this.onSave, + onFailure: checkout.ajaxFailure.bind(checkout), + parameters: Form.serialize(this.form), + }); } else { alert('Unexpected error.'); } @@ -1004,47 +802,20 @@ document.observe('dom:loaded', function() { } if (typeof OPC !== 'undefined') { - if (typeof OPC.prototype._secureSubmitOldSubmit === 'undefined') { + if (typeof OPC.prototype._transitOldSubmit === 'undefined') { var oldOPC = Object.clone(OPC.prototype); - OPC.prototype._secureSubmitOldSubmit = oldOPC.submit; + OPC.prototype._transitOldSubmit = oldOPC.submit; } Object.extend(OPC.prototype, { save: function() { if (this.sectionsToValidate[0].currentMethod != 'hps_transit') { - this._secureSubmitOldSubmit(); + this._transitOldSubmit(); return; } - if (TransITMagento.options.useIframes) { - TransITMagento.hps.Messages.post( - { - accumulateData: true, - action: 'tokenize', - data: TransITMagento.tokenizeOptions, - }, - 'cardNumber' - ); - } else { - if ( - $('hps_transit_exp_date') && - $('hps_transit_exp_date').value - ) { - var date = $('hps_transit_exp_date').value.split('/'); - $('hps_transit_cc_exp_month').value = date[0].trim(); - $('hps_transit_cc_exp_year').value = date[1].trim(); - } - new Heartland.HPS({ - publicKey: this.secureSubmitPublicKey, - cardNumber: $('hps_transit_cc_number').value, - cardCvv: $('hps_transit_cvv_number').value, - cardExpMonth: $('hps_transit_cc_exp_month').value, - cardExpYear: $('hps_transit_cc_exp_year').value, - success: this.secureSubmitResponseHandler.bind(this), - error: this.secureSubmitResponseHandler.bind(this), - }).tokenize(); - } + TransITMagento.triggerSubmit(); }, - secureSubmitResponseHandler: function(response) { + transitResponseHandler: function(response) { var tokenField = $('hps_transit_token'), typeField = $('hps_transit_cc_type'), lastFourField = $('hps_transit_cc_last_four'); @@ -1077,7 +848,7 @@ document.observe('dom:loaded', function() { this.setLoadWaiting(true); var params = Form.serialize(this.form); - var request = new Ajax.Request(this.saveUrl, { + new Ajax.Request(this.saveUrl, { method: 'post', parameters: params, onSuccess: this.setResponse.bind(this), @@ -1104,10 +875,10 @@ document.observe('dom:loaded', function() { // Amasty completeCheckout(); if ( - typeof completeCheckout === 'function' && + typeof window.completeCheckout === 'function' && document.getElementById('amscheckout-onepage') ) { - secureSubmitAmastyCompleteCheckoutOriginal = cloneFunction( + transitAmastyCompleteCheckoutOriginal = cloneFunction( completeCheckout ); @@ -1126,14 +897,13 @@ document.observe('dom:loaded', function() { container.parentNode.removeChild(container); } - completeCheckout = function(btn) { + window.completeCheckout = function(btn) { var validator = new Validation('amscheckout-onepage'); - var form = $('amscheckout-onepage'); if (validator.validate()) { var currentPayment = payment.currentMethod; if (currentPayment != 'hps_transit') { - secureSubmitAmastyCompleteCheckoutOriginal(btn); + transitAmastyCompleteCheckoutOriginal(btn); return; } @@ -1146,18 +916,18 @@ document.observe('dom:loaded', function() { $('hps_transit_cc_exp_year').value = date[1].trim(); } - if (secureSubmitUseStoredCardAOSC()) { + if (transitUseStoredCardAOSC()) { var radio = $$( '[name="hps_transit_stored_card_select"]:checked' )[0]; var storedcardId = radio.value; var storedcardType = $(radio.id + '_card_type').value; - new Ajax.Request(window.payment.secureSubmitGetTokenDataUrlOSC, { + new Ajax.Request(window.payment.transitGetTokenDataUrlOSC, { method: 'post', parameters: {storedcard_id: storedcardId}, onSuccess: function(response) { var data = response.responseJSON; - secureSubmitResponseHandlerAOSC( + transitResponseHandlerAOSC( { card_type: storedcardType, token_value: data.token.token_value, @@ -1175,40 +945,17 @@ document.observe('dom:loaded', function() { }, }); } else { - if (TransITMagento.options.useIframes) { - TransITMagento.hps.Messages.post( - { - accumulateData: true, - action: 'tokenize', - data: TransITMagento.tokenizeOptions, - }, - 'cardNumber' - ); - } else { - new Heartland.HPS({ - publicKey: window.payment.secureSubmitPublicKeyOSC, - cardNumber: $('hps_transit_cc_number').value, - cardCvv: $('hps_transit_cvv_number').value, - cardExpMonth: $('hps_transit_cc_exp_month').value, - cardExpYear: $('hps_transit_cc_exp_year').value, - success: function(response) { - secureSubmitResponseHandlerAOSC(response, btn); - }, - error: function(response) { - secureSubmitResponseHandlerAOSC(response, btn); - }, - }).tokenize(); - } + TransITMagento.triggerSubmit(); } } }; - secureSubmitUseStoredCardAOSC = function() { + window.transitUseStoredCardAOSC = function() { var newRadio = $('hps_transit_stored_card_select_new'); return !newRadio.checked; }; - secureSubmitResponseHandlerAOSC = function(response, btn) { + window.transitResponseHandlerAOSC = function(response, btn) { var tokenField = $('hps_transit_token'), typeField = $('hps_transit_cc_type'), lastFourField = $('hps_transit_cc_last_four'); @@ -1237,7 +984,7 @@ document.observe('dom:loaded', function() { lastFourField.value = response.card.number.substr(-4); typeField.value = response.card_type; - secureSubmitAmastyCompleteCheckoutOriginal(btn); + transitAmastyCompleteCheckoutOriginal(btn); } else { alert('Unexpected error.'); } @@ -1245,9 +992,9 @@ document.observe('dom:loaded', function() { } // MageStore One Step Checkout - if (typeof oscPlaceOrder === 'function') { + if (typeof window.oscPlaceOrder === 'function') { window.oscPlaceOrderOriginal = cloneFunction(oscPlaceOrder); - oscPlaceOrder = function(btn) { + window.oscPlaceOrder = function(btn) { var validator = new Validation('one-step-checkout-form'); var form = $('one-step-checkout-form'); TransITMagento.__data.btn = btn; @@ -1264,13 +1011,13 @@ document.observe('dom:loaded', function() { $('onestepcheckout-button-place-order').addClassName( 'onestepcheckout-btn-checkout' ); - if (secureSubmitUseStoredCardOSC()) { + if (transitUseStoredCardOSC()) { var radio = $$( '[name="hps_transit_stored_card_select"]:checked' )[0]; var storedcardId = radio.value; var storedcardType = $(radio.id + '_card_type').value; - new Ajax.Request(window.payment.secureSubmitGetTokenDataUrlOSC, { + new Ajax.Request(window.payment.transitGetTokenDataUrlOSC, { method: 'post', parameters: {storedcard_id: storedcardId}, onSuccess: function(response) { @@ -1282,7 +1029,7 @@ document.observe('dom:loaded', function() { $('hps_transit_cc_exp_year').value = data.token.cc_exp_year; } - secureSubmitResponseHandlerOSC( + transitResponseHandlerOSC( { card_type: storedcardType, token_value: data.token.token_value, @@ -1307,49 +1054,17 @@ document.observe('dom:loaded', function() { }, }); } else { - if (TransITMagento.options.useIframes) { - TransITMagento.hps.Messages.post( - { - accumulateData: true, - action: 'tokenize', - data: TransITMagento.tokenizeOptions, - }, - 'cardNumber' - ); - } else { - if ( - $('hps_transit_exp_date') && - $('hps_transit_exp_date').value - ) { - var date = $('hps_transit_exp_date').value.split('/'); - $('hps_transit_cc_exp_month').value = date[0].trim(); - $('hps_transit_cc_exp_year').value = date[1].trim(); - } - - new Heartland.HPS({ - publicKey: window.payment.secureSubmitPublicKeyOSC, - cardNumber: $('hps_transit_cc_number').value, - cardCvv: $('hps_transit_cvv_number').value, - cardExpMonth: $('hps_transit_cc_exp_month').value, - cardExpYear: $('hps_transit_cc_exp_year').value, - success: function(response) { - secureSubmitResponseHandlerOSC(response, btn); - }, - error: function(response) { - secureSubmitResponseHandlerOSC(response, btn); - }, - }).tokenize(); - } + TransITMagento.triggerSubmit(); } } }; - secureSubmitUseStoredCardOSC = function() { + window.transitUseStoredCardOSC = function() { var newRadio = $('hps_transit_stored_card_select_new'); return !newRadio.checked; }; - secureSubmitResponseHandlerOSC = function(response, btn) { + window.transitResponseHandlerOSC = function(response, btn) { var tokenField = $('hps_transit_token'), typeField = $('hps_transit_cc_type'), lastFourField = $('hps_transit_cc_last_four'); @@ -1393,12 +1108,9 @@ document.observe('dom:loaded', function() { $('onestepcheckout-button-place-order').addClassName( 'place-order-loader' ); - window.TransITMagento.initializeCCA( - function() { - // Continue Magento checkout steps - oscPlaceOrderOriginal(btn); - }.bind(this) - ); + + // Continue Magento checkout steps + oscPlaceOrderOriginal(btn); } else { alert('Unexpected error.'); $('onestepcheckout-place-order-loading').show(); @@ -1414,14 +1126,14 @@ document.observe('dom:loaded', function() { // IWD OPC if (typeof IWD !== 'undefined' && typeof IWD.OPC !== 'undefined') { - if (typeof IWD.OPC._secureSubmitOldSavePayment === 'undefined') { + if (typeof IWD.OPC._transitOldSavePayment === 'undefined') { var oldIWDOPC = Object.clone(IWD.OPC); - IWD.OPC._secureSubmitOldSavePayment = oldIWDOPC.savePayment; + IWD.OPC._transitOldSavePayment = oldIWDOPC.savePayment; } Object.extend(IWD.OPC, { savePayment: function() { if (payment.currentMethod != 'hps_transit') { - this._secureSubmitOldSavePayment(); + this._transitOldSavePayment(); return; } @@ -1429,37 +1141,9 @@ document.observe('dom:loaded', function() { return; } - if (TransITMagento.options.useIframes) { - TransITMagento.hps.Messages.post( - { - accumulateData: true, - action: 'tokenize', - data: TransITMagento.tokenizeOptions, - }, - 'cardNumber' - ); - } else { - if ( - $('hps_transit_exp_date') && - $('hps_transit_exp_date').value - ) { - var date = $('hps_transit_exp_date').value.split('/'); - $('hps_transit_cc_exp_month').value = date[0].trim(); - $('hps_transit_cc_exp_year').value = date[1].trim(); - } - - new Heartland.HPS({ - publicKey: this.secureSubmitPublicKey, - cardNumber: $('hps_transit_cc_number').value, - cardCvv: $('hps_transit_cvv_number').value, - cardExpMonth: $('hps_transit_cc_exp_month').value, - cardExpYear: $('hps_transit_cc_exp_year').value, - success: this.secureSubmitResponseHandler.bind(this), - error: this.secureSubmitResponseHandler.bind(this), - }).tokenize(); - } + TransITMagento.triggerSubmit(); }, - secureSubmitResponseHandler: function(response) { + transitResponseHandler: function(response) { var tokenField = $('hps_transit_token'), typeField = $('hps_transit_cc_type'), lastFourField = $('hps_transit_cc_last_four'); @@ -1506,7 +1190,7 @@ document.observe('dom:loaded', function() { }); } - // Latest Version of IWD One page Checkou + // Latest Version of IWD One page Checkout if ( typeof iwdOpcConfig !== 'undefined' && typeof OnePage !== 'undefined' && @@ -1520,15 +1204,15 @@ document.observe('dom:loaded', function() { var _this = this; var _thisArguments = arguments; _this.showLoader(Singleton.get(OnePage).sectionContainer); - switch (_this.getPaymentMethodCode()) { - case Singleton.get(PaymentMethodIWD).code: - Singleton.get(PaymentMethodIWD).originalThis = _this; - Singleton.get(PaymentMethodIWD).originalArguments = _thisArguments; - Singleton.get(PaymentMethodIWD).savePayment(); - break; - default: - OnePage.prototype.saveSection.apply(_this, _thisArguments); + + if (_this.getPaymentMethodCode() !== Singleton.get(PaymentMethodIWD).code) { + OnePage.prototype.saveSection.apply(_this, _thisArguments); + return; } + + Singleton.get(PaymentMethodIWD).originalThis = _this; + Singleton.get(PaymentMethodIWD).originalArguments = _thisArguments; + Singleton.get(PaymentMethodIWD).savePayment(); }; function PaymentMethodIWD() { @@ -1594,13 +1278,13 @@ document.observe('dom:loaded', function() { } // Use stored card checked, get existing token data - if (this.secureSubmitUseStoredCard()) { + if (this.transitUseStoredCard()) { var radio = $$( '[name="hps_transit_stored_card_select"]:checked' )[0]; var storedcardId = radio.value; var storedcardType = $(radio.id + '_card_type').value; - new Ajax.Request(PaymentMethod.prototype.secureSubmitGetTokenDataUrl, { + new Ajax.Request(PaymentMethod.prototype.transitGetTokenDataUrl, { method: 'post', parameters: {storedcard_id: storedcardId}, onSuccess: function(response) { @@ -1611,7 +1295,7 @@ document.observe('dom:loaded', function() { ); $('hps_transit_cc_exp_year').value = data.token.cc_exp_year; } - this.secureSubmitResponseHandler.call(this, { + this.transitResponseHandler.call(this, { card_type: storedcardType, token_value: data.token.token_value, token_type: null, // 'supt'? @@ -1627,49 +1311,16 @@ document.observe('dom:loaded', function() { }); } else { // Use stored card not checked, get new token - if (TransITMagento.options.useIframes) { - TransITMagento.hps.Messages.post( - { - accumulateData: true, - action: 'tokenize', - data: TransITMagento.tokenizeOptions, - }, - 'cardNumber' - ); - } else { - var validator = new Validation('hps_transit_cc_form'); - if (validator.validate()) { - if ( - $('hps_transit_exp_date') && - $('hps_transit_exp_date').value - ) { - var date = $('hps_transit_exp_date').value.split('/'); - $('hps_transit_cc_exp_month').value = date[0].trim(); - $('hps_transit_cc_exp_year').value = date[1].trim(); - } - - new Heartland.HPS({ - publicKey: PaymentMethod.prototype.secureSubmitPublicKey, - cardNumber: $('hps_transit_cc_number').value, - cardCvv: $('hps_transit_cvv_number').value, - cardExpMonth: $('hps_transit_cc_exp_month').value, - cardExpYear: $('hps_transit_cc_exp_year').value, - success: this.secureSubmitResponseHandler.bind(this), - error: this.secureSubmitResponseHandler.bind(this), - }).tokenize(); - } else { - $ji('.iwd_opc_loader_wrapper.active').hide(); - } - } + TransITMagento.triggerSubmit(); } }; - PaymentMethodIWD.prototype.secureSubmitUseStoredCard = function() { + PaymentMethodIWD.prototype.transitUseStoredCard = function() { var newRadio = $('hps_transit_stored_card_select_new'); return !newRadio.checked; }; - PaymentMethodIWD.prototype.secureSubmitResponseHandler = function( + PaymentMethodIWD.prototype.transitResponseHandler = function( response ) { var tokenField = $('hps_transit_token'), @@ -1709,40 +1360,41 @@ document.observe('dom:loaded', function() { } }; } - // FireCheckout - if (typeof FireCheckout !== 'undefined') { - Object.extend(FireCheckout.prototype, { - save: function (urlSuffix, forceSave) { - if (this.loadWaiting != false) { - return; - } - if (!this.validate()) { - return; - } + // FireCheckout + if (typeof window.FireCheckout !== 'undefined') { + Object.extend(FireCheckout.prototype, { + save: function (urlSuffix, forceSave) { + if (this.loadWaiting != false) { + return; + } - if (payment.currentMethod) { - // HPS heartland - if (!forceSave && payment.currentMethod.indexOf("hps_transit") === 0) { - payment.save(); - return; - } - // HPS heartland - } + if (!this.validate()) { + return; + } - checkout.setLoadWaiting(true); - var params = Form.serialize(this.form, true); - $('review-please-wait').show(); - - urlSuffix = urlSuffix || ''; - var request = new Ajax.Request(this.urls.save + urlSuffix, { - method: 'post', - parameters: params, - onSuccess: this.setResponse.bind(this), - onFailure: this.ajaxFailure.bind(this) - }); - }, + if (payment.currentMethod) { + // HPS heartland + if (!forceSave && payment.currentMethod.indexOf("hps_transit") === 0) { + payment.save(); + return; + } + // HPS heartland + } + + checkout.setLoadWaiting(true); + var params = Form.serialize(this.form, true); + $('review-please-wait').show(); + + urlSuffix = urlSuffix || ''; + new Ajax.Request(this.urls.save + urlSuffix, { + method: 'post', + parameters: params, + onSuccess: this.setResponse.bind(this), + onFailure: this.ajaxFailure.bind(this) }); - } - // FireCheckout + }, + }); + } + // FireCheckout }); diff --git a/js/transit/secure.submit-1.0.1.js b/js/transit/secure.submit-1.0.1.js deleted file mode 100644 index 65fcad8..0000000 --- a/js/transit/secure.submit-1.0.1.js +++ /dev/null @@ -1,115 +0,0 @@ -/*global $ */ -var hps = (function () { - "use strict"; - - var HPS = { - - Tag: "TransIT", - - Urls: { - CERT: "https://cert.api2.heartlandportico.com/Hps.Exchange.PosGateway.Hpf.v1/api/token", - PROD: "https://api2.heartlandportico.com/TransIT.v1/api/token" - }, - - tokenize: function (options) { - var gateway_url, params, env, getter_impl; - - // add additional service parameters - params = $H({ - "api_key": options.data.public_key, - "object": "token", - "token_type": "supt", - "_method": "post", - "card[number]": HPS.trim(options.data.number), - "card[cvc]": HPS.trim(options.data.cvc), - "card[exp_month]": HPS.trim(options.data.exp_month), - "card[exp_year]": HPS.trim(options.data.exp_year) - }); - - env = options.data.public_key.split("_")[1]; - - if (env === "uat") { - gateway_url = HPS.Urls.UAT; - } else if (env === "cert") { - gateway_url = HPS.Urls.CERT; - } else { - gateway_url = HPS.Urls.PROD; - } - - new Ajax.JSONP(gateway_url, { - parameters: params, - onComplete: function(json) { - - // Request failed, handle error - if (typeof json.error === 'object') { - // call error handler if provided and valid - if (typeof options.error === 'function') { - options.error(json.error); - } else { - // handle exception - HPS.error(json.error.message); - } - } else if (typeof options.success === 'function') { - options.success(json); - } - } - }); - - }, - - trim: function (string) { - if (string !== undefined && typeof string === "string" ) { - string = string.toString().replace(/^\s\s*/, '').replace(/\s\s*$/, ''); - } - return string; - }, - - empty: function (val) { - return val === undefined || val.length === 0; - }, - - error: function (message) { - if (console && console.log) { - console.log([HPS.Tag, ": ", message].join("")); - } - } - }; - - return HPS; -}()); - -Ajax.JSONP = Class.create(Ajax.Base, (function() { - var id = 0, - head = document.getElementsByTagName('head')[0]; - - return { - initialize: function($super, url, options) { - $super(options); - this.request(url); - }, - - request: function(url) { - var callbackName = '_prototypeJSONPCallback_' + (id++), - self = this, - script; - - this.options.parameters["callback"] = callbackName; - - url += (url.include('?') ? '&' : '?') + Object.toQueryString(this.options.parameters); - - window[callbackName] = function(json) { - script.remove(); - script = null; - window[callbackName] = undefined; - if (self.options.onComplete) { - self.options.onComplete.call(self, json); - } - } - script = new Element('script', { - type: 'text/javascript', - src: url - }); - head.appendChild(script); - } - }; -})()); diff --git a/skin/frontend/base/default/transit/css/hps-styles.css b/skin/frontend/base/default/transit/css/hps-styles.css index 20fc27f..82d957c 100755 --- a/skin/frontend/base/default/transit/css/hps-styles.css +++ b/skin/frontend/base/default/transit/css/hps-styles.css @@ -132,10 +132,8 @@ li>label.hps_transit_stored_card_label, font-weight: 600; } -#heartland-frame-cardExpiration, -#heartland-frame-cardNumber, -#heartland-frame-cardCvv { - height:50px !important; +#hps_transit_cc_form iframe { + min-height:50px !important; width:100%; }