Skip to content

Commit

Permalink
Merge pull request #183 from hps/saved-cards
Browse files Browse the repository at this point in the history
corrects functionality when saved cards are used
  • Loading branch information
securesubmit-buildmaster authored Aug 18, 2022
2 parents 6c175d0 + 8e29a6f commit fd9d2af
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 6 deletions.
92 changes: 87 additions & 5 deletions assets/js/securesubmit.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
(function (window, document, GlobalPayments, wc_securesubmit_params) {
var addHandler = window.GlobalPayments
? GlobalPayments.events.addHandler
: function () { };

function addClass(element, klass) {
if (element.className.indexOf(klass) === -1) {
element.className = element.className + ' ' + klass;
}
}

function removeClass(element, klass) {
if (element.className.indexOf(klass) === -1) return;
element.className = element.className.replace(klass, '');
}

function toAll(elements, fun) {
var i = 0;
var length = elements.length;
Expand Down Expand Up @@ -51,6 +60,21 @@
document.querySelector('.securesubmit_new_card_info')
);
} else {
if (document.getElementById("last_four"))
document.getElementById("last_four").remove();

if (document.getElementById("card_type"))
document.getElementById("card_type").remove();

if (document.getElementById("exp_month"))
document.getElementById("exp_month").remove();

if (document.getElementById("exp_year"))
document.getElementById("exp_year").remove();

if (document.getElementById("bin"))
document.getElementById("bin").remove();

var token = document.getElementById('securesubmit_token');
var last4 = document.createElement('input');
var cType = document.createElement('input');
Expand Down Expand Up @@ -82,10 +106,10 @@
expYr.name = 'exp_year';
expYr.value = response.details.expiryYear;

expYr.type = 'hidden';
expYr.id = 'bin';
expYr.name = 'bin';
expYr.value = response.details.cardBin;
bin.type = 'hidden';
bin.id = 'bin';
bin.name = 'bin';
bin.value = response.details.cardBin;

form.appendChild(last4);
form.appendChild(cType);
Expand All @@ -101,6 +125,40 @@
}, 500);
}

// Load function to attach event handlers when WC refreshes payment fields
window.securesubmitLoadEvents = function () {
if (!GlobalPayments) {
return;
}

toAll(
document.querySelectorAll('.card-number, .card-cvc, .expiry-date'),
function (element) {
addHandler(element, 'change', clearFields);
}
);

toAll(document.querySelectorAll('.saved-selector'), function (element) {
addHandler(element, 'click', function (e) {
var display = 'none';
if (document.getElementById('secure_submit_card_new').checked) {
display = 'block';
}
toAll(document.querySelectorAll('.new-card-content'), function (el) {
el.style.display = display;
});

// Set active flag
toAll(document.querySelectorAll('.saved-card'), function (el) {
removeClass(el, 'active');
});
addClass(element.parentNode.parentNode, 'active');
});
});
};

window.securesubmitLoadEvents();

// Load function to build iframes when WC refreshes payment fields
window.securesubmitLoadIframes = function () {
if (!wc_securesubmit_params) {
Expand Down Expand Up @@ -273,10 +331,34 @@
wc_securesubmit_params.hps.ready(
function () {
if (buttonTarget.firstChild)
buttonTarget.firstChild.style = "width: 100%"
buttonTarget.firstChild.style = "width: 100%";
if (
document.getElementById("securesubmit_card_number")
&& document.getElementById("securesubmit_card_number").firstChild
)
document.getElementById("securesubmit_card_number").firstChild.style.minHeight = "50px";

if (
document.getElementById("securesubmit_card_expiration")
&& document.getElementById("securesubmit_card_expiration").firstChild
)
document.getElementById("securesubmit_card_expiration").firstChild.style.minHeight = "50px";

if (
document.getElementById("securesubmit_card_cvv")
&& document.getElementById("securesubmit_card_cvv").firstChild
)
document.getElementById("securesubmit_card_cvv").firstChild.style.minHeight = "50px";
}
);

// use WooCommerce order button when Single-Use Token isn't needed
wc_securesubmit_params.hps.on("submit", "click", function () {
if (!document.getElementById("secure_submit_card_new")) return;
if (!document.getElementById("secure_submit_card_new").checked)
document.getElementById("place_order").click();
});

wc_securesubmit_params.hps.on("token-success", function(resp) {
responseHandler(resp);
});
Expand Down
2 changes: 1 addition & 1 deletion gateway-securesubmit.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: WooCommerce SecureSubmit Gateway
Plugin URI: https://developer.heartlandpaymentsystems.com/SecureSubmit/
Description: Heartland Payment Systems gateway for WooCommerce.
Version: 2.0.1
Version: 2.0.2
WC tested up to: 6.7.0
Author: SecureSubmit
Author URI: https://developer.heartlandpaymentsystems.com/SecureSubmit/
Expand Down
14 changes: 14 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ Get your Certification (Dev/Sandbox) Api Keys by creating an account on https://
3. A view of the Manage Cards section

== Changelog ==
= 2.0.2 =
* Fix saved-card functionality

= 2.0.1 =
* Fix incompatability with some themes/plugins

= 2.0.0 =
* Remove support for non-iframe payment fields
* Add support for transaction optimization
* Utilize latest Heartland tokenization library

= 1.13.1 =
* Security patch

= 1.13.0 =
* Add filters for third-party fraud solutions

Expand Down

0 comments on commit fd9d2af

Please sign in to comment.