How to run Javascript / Jquery when Woocommerce / Stripe checkout fails? - javascript

Seems like when I use Stripe plugin for payments, the checkout_error event does not happen when a card error occurs. (https://wordpress.stackexchange.com/questions/342148/list-of-js-events-in-the-woocommerce-frontend)
Looking through Stripe documentation, it seems like when a credit card gets rejected by Stripe, there is a 402 error. I would like to run a Javascript / Jquery code when this happens.
What I have tried
According to this post (Fire function when Stripe has error in WooCommerce) this is the code I could try:
add_action( 'wc_gateway_stripe_process_payment_error', 'test_this', 10, 2 );
function test_this($error, $order) {
$variable = "card error";
echo "<script>console.log('$variable');</script>";
}
Problem
However, nothing shows up in my console log when there is a card error.
Thank you!

Related

Attempted to handle event `becameInvalid` while in state 'root.loaded.saved'

I've implemented DS.Errors for my RestAdapter, thanks to Alex Spellers tutorial on server side validation.
However, in this part of my app I want to do a simple client side check to see if the form is complete. (Why not have DS.Errors handle all the errors?)
process: function(upload) {
var form = upload.get('form');
if (!isComplete(form)) {
upload.get('errors').add('field', 'field isempty');
return;
}
// else "Processing..."
The logic here is somewhat simplified, but errors.add() should invalidate, and add an error to the model. However I'm getting the following error:
Uncaught Error: Attempted to handle event `becameInvalid` on <#model:upload:54a1f298ef912a2ace760b0f> while in state root.loaded.saved.
I have read about the state manager, but am unsure as to how, and what state I should transition to before adding an error to my model.
Thanks in advance!
Ember : 1.8.1
Ember Data : 1.0.0-beta.11
Handlebars : 1.3.0
jQuery : 1.11.2
After revisiting this I came across the following post. What solved my problem was not sending willCommit, but sending upload.send('becomeDirty'); before executing the following:
upload.get('errors').add('field', 'field isempty');
Now errors can be added as the upload model is not in the saved state.

Facebook Event Cover URL

For days i was creating events by JS API and everything was ok. Two days from now Im getting a...
code: 2
message: "An unexpected error has occurred. Please retry your request later."
type: "OAuthException"
... everytime I try to update the cover_url of the created event. My code is just:
FB.api(
eventId,'post',
{ cover_url:'<url>'}, function...
I have already tryed everything that I found in documentation.
Look at the new documentation and didn't find anything.
Solve the problem:
Just change 'event_privacy' to 'OPEN' when creating. After this, event cover_url update works fine.
Hope it helps.

Forcing the Twitter Epi Library to post a status update even if it's a duplicate of the last tweet

I'm using the epi libs from: https://github.com/jmathai/twitter-async/
When trying to post a twitter update I am met with an issue where if the tweet has already previously been made it errors out, I want it post it again and ignore the fact that it's a duplicate.
I thought that the code $twitter->post_statusesUpdate(array('status' => $tweet)); would forcefully make the tweet every time but it doesn't for me :/
Anyone know why or can give me an example of some working code / can fix this for me?
Here's a copy of my code snippit:
try {
$twitter->post_statusesUpdate(array('status' => $tweet));
} catch (EpiTwitterForbiddenException $e) {
$msg = json_decode($e->getMessage());
if ($msg->error != 'Status is a duplicate.') {
//throw $e;
}
}
Thanks in advance
- Hyflex
I want it post it again and ignore the fact that it's a duplicate.
It's not possible yet, You can not post the same tweet twice, that's twitter feature, look: https://dev.twitter.com/discussions/3714

Form data not passing to PHP file

The Program I'm writing and the functionality I'm trying to achieve
Okay. So what I'm writing at the moment is a very simple forum, in Javascript using AJAX. Part of my task is to add a new post, using an API that my lecturer wrote for us in PHP. Just to note, the API and the SQL database are completely local.
The function I am using to add this post is:
function addPosts()
{
// Add the new thread to the SQLlite database.
var treq = new Request({
url:'guestbook/control.php?action=insertPost',
'method':'post',
onSuccess: function() {
alert('win');
},
onFailure: function() {
alert('fail');
}
}).send(Object.toQueryString({
// Had to convert it to a query string because it wouldn't work as a normal object.
// These are the required values to send, to store a "post" in the database.
'name':'This is a name',
'comment':'This is a comment!'
}));
}
I am aware this will add the same data every single time. I'm just trying to get the damn thing working!
The problem
What is happening is, when this function is called, I am getting an SQL syntax error. I was confused, because that would imply that my lecturer's code is wrong. After speaking with my lecturer, he explained that this happens when the post data isn't sent correctly to the PHP code. So I went about using Google Chrome's developer tools to see what was going on, and this is what I discovered:
Now to me, this means that the data is successfully being loaded into the request, and is being passed to the PHP files fine. Obviously I'm wrong. I've been racking my brains trying to make this work.
I know that the API works fine, because everyone else in my class isn't having any problem with it, and the code I am using is practically a rip off of the code in the notes, so I'm about 90% sure that's correct to.
One thing to note is that the code in the onSuccess key runs, so I know it's not a problem on the AJAX side.
Another thing is that this code worked in University on those computers, and it's since I've got it home that it's decided not to work.
Stack Trace
Fatal error: Uncaught exception 'PDOException' with message
'SQLSTATE[HY000]: General error: 1 near ")": syntax error' in G:\Ajax
Coursework\guestbook\php\database.php:134Stack trace:#0 G:\Ajax
Coursework\guestbook\php\database.php(134): PDO->prepare('INSERT INTO
pos...')#1 G:\Ajax Coursework\guestbook\php\class.GuestBook.php(44):
DatabaseHandler->insert(Array)#2 G:\Ajax
Coursework\guestbook\control.php(8): GuestBook->insert(Array)#3
G:\Ajax Coursework\guestbook\control.php(56): insertPost()#4 {main}
thrown in G:\Ajax Coursework\guestbook\php\database.php on line 134
Object.toQueryString is used in convert an object to a query string. So if the server is requiring both $_POST['name'] and $_POST['comment'] to be set, it wont be.
Frankly because you are posting it, I dont think $_GET['name'] or $_GET['comment'] would be set either.
Request.send expects an opject. You are sending it a string. So it should be
Request.send({prop: 'value'}), not Request.send(value).
Do yourself a favor and make a PHP with the following php code, and see what it returns. It may clear this up for you right away. I have a feeling nothing is being sent except for $_GET['action']
<?php
echo '<pre>';
print_r($_GET);
print_r($_POST);
echo '</pre>';
?>
Just in-case anyone stumbles upon this thread looking for an answer:
function addPosts()
{
// Add the new thread to the SQLlite database.
var treq = new Request({
url:'guestbook/control.php?action=insertPost',
onSuccess: function() {
alert('win');
},
onFailure: function() {
alert('fail');
}
}).post('name=This is a name&comment=This is a comment!');
}
Here I'm using the .post method to POST data.

Using javascript setInterval in zend framework

I have a user notification data I fetch from the database and i want a div that contains this data to refresh every 2 mins. I am using zend frame. I have a layout that displays this data by using javascript setInterval function but it throws a database exception error everytime the div reloads.
This is my piece of code
// layout.phtml
<script type="text/javascript">
setInterval(function()
{
$('.friendrequestcount').load('notification.phtml');
},
2000 * 30 * 60
);
</script>
Can you point how I can reload a div in zend framework?
Any help will be appreciated.
Thanks
edit:
I echo out a number in my notification.phtml
eg echo 8;
and the error message is
Fatal error: Uncaught exception PDOException with message SQLSTATE[HY093]: Invalid parameter number: no parameter were bound in ............. link to PDO.php in Zend
I have a feeling (and could be wrong) that you should be using a route path and not the name of your view script in your load() URI, eg
$('.friendrequestcount').load('controller/notification');
You should never directly try to include or otherwise invoke a view script

Categories