As described here https://developers.payrexx.com/docs/mobile-apps-javascript
I would like to interact with the javascript events of an iframe I want to create in the webview_flutter plugin.
The following example code is given in the official documentation
window.addEventListener('message', handleMessage(this), false);
and
function handleMessage(e) {
if (typeof e.data === 'string') {
try {
var data = JSON.parse(e.data);
} catch (e) {}
if (data && data.payrexx) {
jQuery.each(data.payrexx, function(name, value) {
switch (name) {
case 'transaction':
if (typeof value === 'object') {
if (value.status === 'confirmed') {
//handling success
} else {
//handling failure
}
}
break;
}
});
}
}
}
Do you know a way to do this? I have implemented an iframe in which there is the address of my gateway, but it is impossible to check if the payment has taken place.
Sounds good. The Payrexx iFrame sends a post message with the transaction details (including transaction status) to the parent window (e.g. your Flutter webview) after the payment (on the Payrexx result page). So you only need to add an event listener for type "message" in your webview as in the example:
window.addEventListener('message', handleMessage(this), false);
Please make sure you also send a post message into the Payrexx iFrame as soon as the iFrame is loaded (onload event):
let iFrame = document.getElementById('IFRAME-ID');
if (iFrame) {
iFrame.contentWindow.postMessage(
JSON.stringify({
origin: window.location.origin,
}),
iFrame.src,
);
}
Now you are ready to receive and handle the messages from the Payrexx iFrame:
private handleMessage(e): void {
try {
let message = JSON.parse(e.data);
if (typeof message !== 'object' ||
!message.payrexx ||
!message.payrexx.transaction) {
return;
}
let transaction = message.payrexx.transaction;
console.log(transaction);
} catch (e) {
}
};
Last but not least:
Make sure you also check the transaction status via transaction webhook (server-to-server notification):
https://docs.payrexx.com/developer/guides/webhook
if ($("#Switch").is(":checked") == true)
{
alert("checked");
}
else
{
alert(" Not checked");
}
This code is giving me the alert "checked" first time after changing the switch state from OFF to ON. And after i am changing the state to OFF again but it is showing only alert "checked".
Please help me, I am using this code in button click event. Every time I am getting only checked.
function getChecked(elementId)
{
if ($("#elementId").is(":checked") == true)
{
alert("checked");
}
else
{
alert(" Not checked");
}
}
onchange="getChecked('#id')"
put this code inside your js onchange event
var checked = $(this).prop('checked');
if(checked) {
alert('checked');
} else {
alert('not checked');
}
I wrote a wrapper function for the FB.getLoginStatus that is defined as follows:
this.isLoggedInFB = function() {
FB.getLoginStatus(function(response) {
if(response.status == 'connected')
{
return true;
}
else if(response.status =='not_authorized'){
return true;
else{
return false;
}
});
}
Whenever I make the following alert
alert(myClass.isLoggedInFB());
I get undefined.
When I add an alert within the body of isLoggedInFB to see if FB is defined I get:
[Object object]
which tells me that it FB.init has been called, which is confusing because
that is the only thing that I thought could have gone wrong.
Finally, I made an alert to see if I mistyped the name or that my name-spacing was wrong by doing
alert(myClass.isLoggedInFB);
and I got the correct function definition.
because the function isLoggedInFB does not return any value. if you need to get the response data back you need to return a value like this:
var connected = 0;
this.isLoggedInFB = function() {
FB.getLoginStatus(function(response) {
if(response.status == 'connected')
{
connected = 1;
return true;
}
else if(response.status =='not_authorized'){
{
connected = 1;
return true;
}
else{
connected = 0;
return false;
}
});
return connected;
}
I have an issue with a some of the jQuery notifications I have created to trigger based on information echo'd from a PHP file after a user submits a sign up HTML form via AJAX. The notifications for errors work, but not for a successful post to the database. I know that the success notification should show because the data is validated and written to the database and AJAX post is successful. However the success notification does not want to work. What could be the reason for this technicality?
I have the following set up:
signup.html (contains the following ajax within the page*):
function registerUser(formKey) {
$.ajax({
type:"POST",
url:"engine/new_user.php",
data: $("#"+formKey).serialize(),
cache:false,
success: function(data) {
if(data == -3){
$("html, body").animate({ scrollTop: 0 }, 600);
$("#user-exists-notification").fadeIn(1000);
}
if(data == -4){
$("#account-created").fadeIn(1000);
}
if(data == -1){
$("html, body").animate({ scrollTop: 0 }, 600);
$("#fields-complete-notification").delay(1000).fadeIn(1000);
}
if(data == -2){
$("html, body").animate({ scrollTop: 0 }, 600);
$("#pw-confirm-notification").delay(1000).fadeIn(1000);
}
},
error: function(data) {
}
});
}
new_user.php
require("register-classes.php");
$register=new Register($_POST['fname'], $_POST['lname'], $_POST['email'], $_POST['sex'], $_POST['birthdate'], $_POST['phone'], $_POST['country'], $_POST['alias'], $_POST['handle'], $_POST["password"], $_POST["cpassword"], $_POST['network']);
if($register->checkFields()== false){
echo -1;
} else if($register->confirmPasswords()== false){
echo -2;
}else if($register->registerUser()!=false){
echo -4;
} else if($register->registerUser()==false){
echo -3;
}
and register-classes.php (which contains classes for processing sign up form)
class Register {
public function __construct($fname, $lname, $mail, $sex,
$birthday, $phonenumber, $regCountry, $alias, $username,
$password, $conf_password, $network_site) {
//Copy Constructor
$this->site=$network_site;
$this->firstname=$fname;
$this->lastname=$lname;
$this->email=$mail;
$this->sex=$sex;
$this->birthdate=$birthday;
$this->phone=$phonenumber;
$this->country=$regCountry;
$this->displayname=$alias;
$this->handle=$username;
$this->salt="a2cflux9e8g7ds6ggty589498j8jko007876j89j8j7";
$this->password=crypt($this->salt.$password);
$this->joindate=date("Y-m-d H:i:s");
$this->confirm_password1=$password;
$this->confirm_password2=$conf_password;
}
public function registerUser(){
$database=new Database();
$database->getConnection();
$database->startConnection();
//Check database to insure user and email address is not already in the system.
$checkUsers= mysql_query("SELECT network_users.network_id
FROM network_users, network_profile
WHERE network_users.handle = '$this->handle'
OR network_profile.email = '$this->email'");
$numRecords= mysql_num_rows($checkUsers);
if($numRecords == 0){
$addUser= mysql_query("INSERT INTO network_users(handle, password, date_created, parent_network, site_created, active, account_type, del)
values('$this->handle', '$this->password', '$this->joindate',' fenetwork', 'network', 'active', 'standard', 'F')") or die(mysql_error());
$networkId=mysql_insert_id();
$addProfile= mysql_query("INSERT INTO network_profile(network_id, first_name, last_name, email, sex, birthdate, phone, country, display_name, del)
values('$networkId', '$this->firstname', '$this->lastname', '$this->email','$this->sex', '$this->birthdate', '$this->phone', '$this->country', '$this->displayname', 'F')") or die(mysql_error());
$this->addUser;
$this->addProfile;
return true;
}
else{
return false;
}
}
public function checkFields(){
if(($this->firstname)!="" && ($this->lastname)!="" && ($this->email)!="" && ($this->sex)!="" &&
($this->birthdate)!="" &&($this->country)!="" && ($this->handle)!="" && ($this->password)!=""){
return true;
} else {
return false;
}
}
public function confirmPasswords(){
if($this->confirm_password1==$this->confirm_password2){
return true;
} else {
return false;
}
}
private $site, $firstname, $lastname, $email,
$sex, $birthdate, $phone, $country, $displayname,
$handle, $password, $salt, $joindate, $confirm_password1, $confirm_password2;
protected $addUser, $addProfile;
}
I found the issue. The issue was due to printf() functions that were apart of a few class members in the database class. They were causing an interruption with the function completing and returning the boolean value true or false in registerUser();
Thank you all for your help and assistance. I would give up a vote up, but I don't have enough reputation points. haha.
I have 2 jQuery snippets 1st is toggle readonly and the 2nd is a submit form.
Toggle readonly:
$('#lock').toggle( function () {
$('#handle').attr('readonly', true).addClass('disabled');
return false;
} , function() {
$('#handle').attr('readonly', false).removeClass('disabled');
return false;
});
Submit form:
$('button').click(function() {
var handle = $('#handle').val();
var msg = $('#msg').val();
var dataString = 'handle='+ handle + '&msg=' + msg;
if(handle=='' || msg=='') {
$('.error').fadeOut(200).show();
} else {
$.ajax({
type : 'POST',
url : 'form.php',
data : dataString,
success : function(){
$('#foo').load('page.php');
}}
});
}
return false;
});
What I am trying to achieve is
if readonly = true do not reset "handle" value
otherwise reset both, so I need to get the status of the 1st snippet (toggle readonly) and allow the 2nd (form) to distinguish whether its true or false.
I tried this in success: but it didn't work.
if($('#handle').attr('readonly', true)){
$('#msg').val('');
}else{
$('#handle, #msg').val('');
Try this code instead:
if ($('#handle').is('[readonly]')) {
$('#msg').val('');
}
else {
$('#handle, #msg').val('');
}
Also for use
$('#handle').prop('readonly', true)
instead of
$('#handle').attr('readonly', true)