Skip to content

Commit

Permalink
Copied Rocketsites changes
Browse files Browse the repository at this point in the history
  • Loading branch information
brittainmark committed Feb 16, 2022
1 parent bec4004 commit 5002437
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 20 deletions.
58 changes: 38 additions & 20 deletions includes/modules/pages/checkout_payment/jscript_square.php
Expand Up @@ -24,8 +24,19 @@

<script type="text/javascript" title="square">
var cardNonce;
var verificationDetails = {
intent: 'CHARGE',
amount: '<?php echo zen_round ( $order->info['total'], 2 ); ?>',
currencyCode: '<?php echo $_SESSION['currency']; ?>',
billingContact: {
givenName: '<?php echo (string)$order->billing['firstname']; ?>',
familyName: '<?php echo (string)$order->billing['lastname']; ?>'
}
};
var paymentForm = new SqPaymentForm({
applicationId: '<?php echo MODULE_PAYMENT_SQUARE_APPLICATION_ID; ?>',
<?php preg_match_all("/\[([^\]]*)\]/", MODULE_PAYMENT_SQUARE_LOCATION, $location); ?>
locationId: '<?php echo $location[1][0]; ?>',
inputClass: 'paymentInput',
inputStyles: [
{
Expand All @@ -52,26 +63,33 @@
},
callbacks: {
cardNonceResponseReceived: function (errors, nonce, cardData) {
if (errors) {
console.error("Encountered errors:");
var error_html = ""
errors.forEach(function (error) {
console.error(' ' + error.message);
error_html += "<li> " + error.message + " </li>";
});
document.getElementById('card-errors').innerHTML = '<ul>' + error_html + '</ul>';
$('#paymentSubmitButton').disabled = false;
} else {
// success
$('#paymentSubmitButton').disabled = true;
$("#card-errors").empty()
document.getElementById('card-nonce').value = nonce;
document.getElementById('card-type').value = cardData.card_brand;
document.getElementById('card-four').value = cardData.last_4;
document.getElementById('card-exp').value = ('0'+cardData.exp_month.toString()).substr(-2) + cardData.exp_year.toString().substr(-2);
document.getElementsByName('checkout_payment')[0].submit();
}

paymentForm.verifyBuyer(
nonce,
verificationDetails,
function(err, verificationResult) {
if (err == null) {
if (errors) {
console.error("Encountered errors:");
var error_html = ""
errors.forEach(function (error) {
console.error(' ' + error.message);
error_html += "<li> " + error.message + " </li>";
});
document.getElementById('card-errors').innerHTML = '<ul>' + error_html + '</ul>';
$('#paymentSubmitButton').disabled = false;
} else {
// success
$('#paymentSubmitButton').disabled = true;
$("#card-errors").empty()
document.getElementById('card-nonce').value = nonce;
document.getElementById('card-type').value = cardData.card_brand;
document.getElementById('card-four').value = cardData.last_4;
document.getElementById('card-exp').value = ('0'+cardData.exp_month.toString()).substr(-2) + cardData.exp_year.toString().substr(-2);
document.getElementById('token').value = verificationResult.token;
document.getElementsByName('checkout_payment')[0].submit();
}
}
});
},
unsupportedBrowserDetected: function () {
document.getElementById('card-errors').innerHTML = '<p class="error alert">This browser is not supported for Square Payments. Please contact us to let us know! Meanwhile, please pay using an alternate method; or shop using a different browser such as FireFox or Chrome.</p>';
Expand Down
3 changes: 3 additions & 0 deletions includes/modules/payment/square.php
Expand Up @@ -215,6 +215,7 @@ public function selection()
'<input type="hidden" id="card-type" name="' . $this->code . '_cc_type">' .
'<input type="hidden" id="card-four" name="' . $this->code . '_cc_four">' .
'<input type="hidden" id="card-exp" name="' . $this->code . '_cc_exp">',
'<input type="hidden" id="token" name="' . $this->code . '_token">',
),
),
);
Expand Down Expand Up @@ -259,6 +260,7 @@ public function process_button()
$process_button_string .= zen_draw_hidden_field('cc_type', zen_output_string_protected($_POST[$this->code . '_cc_type']));
$process_button_string .= zen_draw_hidden_field('cc_four', zen_output_string_protected($_POST[$this->code . '_cc_four']));
$process_button_string .= zen_draw_hidden_field('cc_expires', zen_output_string_protected($_POST[$this->code . '_cc_exp']));
$process_button_string .= zen_draw_hidden_field('token', zen_output_string_protected($_POST[$this->code . '_token']));

return $process_button_string;
}
Expand Down Expand Up @@ -331,6 +333,7 @@ public function before_process()
$payment_request->setSourceId((string)$_POST[$this->code . '_nonce']);
$payment_request->setReferenceId((string)(substr(zen_session_id(), 0, 40)));
$payment_request->setLocationId($location->getId());
$payment_request->setVerificationToken(zen_output_string_protected($_POST['token']));

// brief additional information transmitted as a "note", to max of 500 characters:
$extraNotes = defined('MODULES_PAYMENT_SQUARE_TEXT_ITEMS_ORDERED') ? MODULES_PAYMENT_SQUARE_TEXT_ITEMS_ORDERED : 'Ordered:';
Expand Down

0 comments on commit 5002437

Please sign in to comment.