Skip to content

Commit

Permalink
get certification tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
slogsdon committed Nov 25, 2020
1 parent 3e2e1a7 commit 3a12b39
Show file tree
Hide file tree
Showing 16 changed files with 564 additions and 17 deletions.
4 changes: 2 additions & 2 deletions app/code/community/Hps/Transit/Block/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ protected function _construct()

public function getCredentials()
{
Mage::helper('hps_transit/data')->configureSDK();
Mage::helper('hps_transit/data')->configureSDK(true);

$manifest = ServicesContainer::instance()->getClient()->createManifest();

return json_encode([
'deviceId' => $this->getConfig('device_id'),
'deviceId' => $this->getConfig('device_id_tsep'),
'manifest' => $manifest,
'env' => $this->getConfig('is_production') ? 'production' : 'sandbox',
]);
Expand Down
25 changes: 21 additions & 4 deletions app/code/community/Hps/Transit/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use GlobalPayments\Api\AcceptorConfig;
use GlobalPayments\Api\ServicesConfig;
use GlobalPayments\Api\ServicesContainer;
use GlobalPayments\Api\Entities\Enums\CardDataSource;
use GlobalPayments\Api\Entities\Enums\Environment;
use GlobalPayments\Api\Entities\Enums\GatewayProvider;

Expand All @@ -18,16 +19,16 @@ class Hps_Transit_Helper_Data extends Mage_Core_Helper_Abstract
const XML_PATH_PAYMENT_HPS_SECURESUBMIT_HTTP_PROXY_HOST = 'payment/hps_transit/http_proxy_host';
const XML_PATH_PAYMENT_HPS_SECURESUBMIT_HTTP_PROXY_PORT = 'payment/hps_transit/http_proxy_port';
const CONFIG_FORMAT = 'payment/hps_transit/%s';
public function configureSDK()

public function configureSDK($isTsep = false)
{
$config = new ServicesConfig();

$pairs = [
'merchantId' => 'merchant_id',
'username' => 'user_id',
'password' => 'password',
'deviceId' => 'device_id',
'deviceId' => $isTsep ? 'device_id_tsep' : 'device_id',
'developerId' => 'developer_id',
'transactionKey' => 'transaction_key',
];
Expand All @@ -46,6 +47,10 @@ public function configureSDK()
$config->gatewayProvider = GatewayProvider::TRANSIT;
$config->acceptorConfig = new AcceptorConfig();

if ($this->isAdmin()) {
$config->acceptorConfig->cardDataSource = CardDataSource::MAIL;
}

ServicesContainer::configure($config);
}

Expand Down Expand Up @@ -96,11 +101,23 @@ public function saveMultiToken($token,$cardData,$cardType, $customerId = null)
$storedCard->save();
return $storedCard;
}catch (Exception $e){
if($e->getCode() == '23000'){
if ($e->getCode() == '23000'){
Mage::throwException($this->__('Customer Not Found : Card could not be saved.'));
}
Mage::throwException($e->getMessage());
}
}
}

protected function isAdmin() {
if (Mage::app()->getStore()->isAdmin()) {
return true;
}

if (Mage::getDesign()->getArea() == 'adminhtml') {
return true;
}

return false;
}
}
1 change: 1 addition & 0 deletions app/code/community/Hps/Transit/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function requestTransactionKey()

$response = ServicesContainer::instance()->getClient()->getTransactionKey();

error_log(print_r($response->transactionKey, true));
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);
Expand Down
39 changes: 34 additions & 5 deletions app/code/community/Hps/Transit/Model/Payment.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?php

use GlobalPayments\Api\ServicesConfig;
use GlobalPayments\Api\ServicesContainer;
use GlobalPayments\Api\Entities\Address;
use GlobalPayments\Api\Entities\StoredCredential;
use GlobalPayments\Api\Entities\Transaction;
use GlobalPayments\Api\Entities\Enums\Environment;
use GlobalPayments\Api\Entities\Enums\GatewayProvider;
use GlobalPayments\Api\Entities\Enums\StoredCredentialInitiator;
use GlobalPayments\Api\Entities\Exceptions\ApiException;
use GlobalPayments\Api\PaymentMethods\CreditCardData;

Expand Down Expand Up @@ -104,6 +102,7 @@ private function _authorize(Varien_Object $payment, $amount, $capture)
$additionalData = new Varien_Object($payment->getAdditionalData() ? unserialize($payment->getAdditionalData()) : null);
$secureToken = $additionalData->getTransitToken() ? $additionalData->getTransitToken() : null;
$saveCreditCard = (bool) $additionalData->getCcSaveFuture();
$useStoredCard = (bool) $additionalData->getCcUseMulti();
$customerId = $additionalData->getCustomerId();

$cardType = $payment->getCcType();
Expand Down Expand Up @@ -138,19 +137,33 @@ private function _authorize(Varien_Object $payment, $amount, $capture)
$requestType = $capture ? 'charge' : 'authorize';
$builder = $cardOrToken->{$requestType}($amount)
->withCurrency(strtolower($order->getBaseCurrencyCode()))
->withClientTransactionId(time())
->withAddress($address)
->withRequestMultiUseToken($multiToken)
->withDescription($memo)
->withInvoiceNumber($invoiceNumber)
->withCustomerId($customerId);
}

if ($useStoredCard === true) {
$storedCreds = new StoredCredential;
$storedCreds->initiator = $this->isAdmin()
? StoredCredentialInitiator::MERCHANT
: StoredCredentialInitiator::CARDHOLDER;

$builder = $builder->withStoredCredential($storedCreds);
}

$response = $builder->execute();

if ($response->responseCode !== '00') {
if ($response->responseCode !== '00' || $response->responseMessage === 'Partially Approved') {
// TODO: move this
// $this->updateVelocity($e);

if ($response->responseCode === '10' || $response->responseMessage === 'Partially Approved') {
try { $response->void()->execute(); } catch (\Exception $e) {}
}

if (!$this->_allow_fraud || $response->responseCode !== 'FR') {
throw new ApiException($this->mapResponseCodeToFriendlyMessage($response->responseCode));
}
Expand Down Expand Up @@ -542,6 +555,10 @@ public function assignData($data)
$details['cc_save_future'] = 1;
}

if ($data->getData('cc_use_multi')) {
$details['cc_use_multi'] = 1;
}

if ($data->getData('transit_token')) {
$details['transit_token'] = $data->getData('transit_token');
}
Expand Down Expand Up @@ -772,4 +789,16 @@ protected function mapResponseCodeToFriendlyMessage($responseCode) {

return $result;
}

protected function isAdmin() {
if (Mage::app()->getStore()->isAdmin()) {
return true;
}

if (Mage::getDesign()->getArea() == 'adminhtml') {
return true;
}

return false;
}
}
1 change: 1 addition & 0 deletions app/code/community/Hps/Transit/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<user_id backend_model="adminhtml/system_config_backend_encrypted" />
<password backend_model="adminhtml/system_config_backend_encrypted" />
<device_id backend_model="adminhtml/system_config_backend_encrypted" />
<device_id_tsep backend_model="adminhtml/system_config_backend_encrypted" />
<transaction_key backend_model="adminhtml/system_config_backend_encrypted" />
<developer_id>003226G003</developer_id>
<is_production>no</is_production>
Expand Down
12 changes: 10 additions & 2 deletions app/code/community/Hps/Transit/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,19 @@
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</device_id>
<device_id_tsep translate="label">
<label>Device ID (TSEP)</label>
<backend_model>adminhtml/system_config_backend_encrypted</backend_model>
<sort_order>14</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</device_id_tsep>
<transaction_key translate="label">
<label>Transaction Key</label>
<frontend_type>obscure</frontend_type>
<backend_model>adminhtml/system_config_backend_encrypted</backend_model>
<sort_order>14</sort_order>
<sort_order>15</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
Expand All @@ -87,7 +95,7 @@
<label>Live Mode</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>15</sort_order>
<sort_order>16</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
Expand Down
4 changes: 4 additions & 0 deletions app/design/frontend/base/default/template/transit/form.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ if ($_loggedIn && $allow_card_saving) {
</label>
</li>
<?php endforeach ?>

<li style="display:none">
<input type="hidden" id="<?= $_code ?>_use_stored_card" name="payment[cc_use_multi]">
</li>
<?php endif ?>

<!-- START NEW CARD -->
Expand Down
3 changes: 2 additions & 1 deletion cypress.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"defaultCommandTimeout": 15000,
"pageLoadTimeout": 60000,
"defaultCommandTimeout": 30000,
"fixturesFolder": "test/fixtures",
"integrationFolder": "test/integration",
"pluginsFile": "test/plugins",
Expand Down
4 changes: 4 additions & 0 deletions js/transit/admin-checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
}
};
window.TransITMagentoAdmin.setupFields = function () {
if (!window.TransITMagentoAdmin.options) {
return;
}

GlobalPayments.configure(window.TransITMagentoAdmin.options.credentials);

window.TransITMagentoAdmin.cardForm = GlobalPayments.ui.form({
Expand Down
4 changes: 4 additions & 0 deletions js/transit/checkout-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,7 @@ document.observe('dom:loaded', function() {
$('hps_transit_cc_exp_year').value =
data.token.cc_exp_year;
}
$('hps_transit_use_stored_card').value = "1";
this.transitResponseHandler.call(this, {
card_type: storedcardType,
token_value: data.token.token_value,
Expand Down Expand Up @@ -923,6 +924,7 @@ document.observe('dom:loaded', function() {
var radio = $$(
'[name="hps_transit_stored_card_select"]:checked'
)[0];
$('hps_transit_use_stored_card').value = "1";
var storedcardId = radio.value;
var storedcardType = $(radio.id + '_card_type').value;
new Ajax.Request(window.payment.transitGetTokenDataUrlOSC, {
Expand Down Expand Up @@ -1018,6 +1020,7 @@ document.observe('dom:loaded', function() {
var radio = $$(
'[name="hps_transit_stored_card_select"]:checked'
)[0];
$('hps_transit_use_stored_card').value = "1";
var storedcardId = radio.value;
var storedcardType = $(radio.id + '_card_type').value;
new Ajax.Request(window.payment.transitGetTokenDataUrlOSC, {
Expand Down Expand Up @@ -1285,6 +1288,7 @@ document.observe('dom:loaded', function() {
var radio = $$(
'[name="hps_transit_stored_card_select"]:checked'
)[0];
$('hps_transit_use_stored_card').value = "1";
var storedcardId = radio.value;
var storedcardType = $(radio.id + '_card_type').value;
new Ajax.Request(PaymentMethod.prototype.transitGetTokenDataUrl, {
Expand Down
62 changes: 62 additions & 0 deletions test/integration/admin/checkout.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/// <reference types="cypress" />

import {
getStorefrontUrl,
adminLogin,
enterInIframe
} from '../../support/helpers';

context('Admin - Checkout', () => {
beforeEach(() => {
cy.visit(getStorefrontUrl().trim('/') + '/admin');
});

it('can create a customer order', () => {
adminLogin();

// goto orders
cy.get('#nav > li:nth-of-type(2) > ul li.level1:nth-of-type(1) a').click({ force: true });

// new order
cy.get('button[title="Create New Order"]:first').click();

// select a customer
cy.get('#sales_order_create_customer_grid_table tbody tr:first').click();

// add a product
// cy.get('#order-items button.add').click();
// cy.get('#sales_order_create_search_grid_table tbody tr:first').click();

// cy.wait(500);

// cy.get('button[title="Add Selected Product(s) to Order"]').click();
cy.get('#sidebar_data_reorder input[type="checkbox"]:first').click();
// cy.window().then((win) => win.order.sidebarApplyChanges());
cy.wait(2000);
cy.get('.create-order-sidebar-container button[title="Update Changes"]:first').click();

cy.wait(2000);

// select shipping method
cy.window().then((win) => win.order.loadShippingRates());
cy.get('#s_method_flatrate_flatrate').check();

// enter payment details
cy.window().then((win) => win.payment.switchMethod('hps_transit'));
cy.get('#p_method_hps_transit').click({force: true});

cy.wait(2000);

cy.get("#hps_transit_cc_number_iframe > iframe").then(enterInIframe('4242424242424242'));
cy.get("#hps_transit_cc_exp_iframe > iframe").then(enterInIframe('12 / 2025'));
cy.get("#hps_transit_cc_cvv_iframe > iframe").then(enterInIframe('999'));

cy.wait(1000);

// submit order
cy.window().then((win) => win.order.submit());

// confirm success
cy.get('#messages .success-msg').should('have.text', 'The order has been created.');
});
});
11 changes: 11 additions & 0 deletions test/integration/certification/direct-marketing.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// moto order - internet - sale visa
// 32.49 (25.49 + 7*1.00)
// moto order - internet - sale visa
// 11.12

// close batch

// return with reference - visa
// 11.12 (from order #2 above)
// return with reference - visa
// 7.00 (from order #1 above)
Loading

0 comments on commit 3a12b39

Please sign in to comment.