Answer the question
In order to leave comments, you need to log in
How to generate a cryptogram before placing a woocommerce order?
I'm trying to implement my payment gateway through a third-party api.
There is a checkout script that collects data from the form and generates a cryptogram, which later needs to be uploaded to api.
Now the implementation of the story is as follows:
add_action( 'woocommerce_after_checkout_form', 'add_jscript_checkout');
function add_jscript_checkout() {
?>
<script>
var checkout_form = jQuery('form.checkout');
checkout_form.on('checkout_place_order', function () {
// Это нужно, что бы затормозить отправку перед платежем. Создается поля с валуем 1 для условия, что бы потом изменить и продолжить с готовой криптограммой.
if (jQuery('#confirm-order-flag').length == 0) {
checkout_form.append('<input type="hidden" id="confirm-order-flag" name="confirm-order-flag" value="1">');
checkout_form.append('<input type="hidden" id="crypto" autocomplete="off">');
alert('Js сработал, дальше...');
}
this.createCryptogram = function () {
var result = checkout.createCryptogramPacket();
if (result.success) {
document.getElementById("crypto").value == result.packet;
alert(result.packet)
}
else {
for (var msgName in result.messages) {
alert(result.messages[msgName]);
}
}
};
jQuery(function () {
checkout = new cp.Checkout(
"123123123123123",
document.getElementById("PaymentForm"));
});
return true;
});
jQuery(document.body).on('checkout_error', function () {
var error_count = jQuery('.woocommerce-error li').length;
if (error_count == 1) {
}else{
jQuery('.woocommerce-error li').each(function(){
var error_text = jQuery(this).text();
if (error_text == 'custom_notice'){
jQuery(this).css('display', 'none');
}
});
}
});
</script>
<?php
}
Uncaught TypeError: Cannot read properties of null (reading 'getElementsByTagName')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question