I'm testing out the Pusher library for handling websockets with a rather simple app using PHP and Javscript (jQuery) you can find it here: http://jsfiddle.net/JyVvr/1/
Tha backend ajax.php file contains this:
require 'lib/Pusher.php';
$message = $_POST['msg'];
$pusher = PusherInstance::get_pusher(); // My API key, secret, etc is directly set in the Pusher.php file
$pusher->trigger(
'test_channel',
'new_comment',
array('message' => $message)
);
echo json_encode(array('message' => $message));
Basically the app just takes a message and appends it to the ul element on form submit, the appending part works just fine but the new_comment event isn't triggering so the app isn't working as intended, I used an alert just to test if it showed but it just does nothing plus it doesn't throw any errors or anything. Can anyone tell me what am I doing wrong?
Thanks in advance!
If the events aren't reaching Pusher, make sure the Pusher server time and your server time match or are within 599s of each other. I've been trying to figure this out recently and this article was the first one to appear, so just mentioning this for others to save them some time and headache.
Take a look at the Pusher Debug Console for your app. If you don't see your event triggered in there then it's either not reaching or is not being accepted by the Pusher REST API.
There aren't any issued raised about this Pusher PHP library.
Related
My code, which I tested yesterday and worked correctly, is not working now. I've had some results by trying to read the error messages.
First of all, I want to say that this is a login process. Using Axios, I receive the data in the form and send it to the back-end, and if everything is correct, I log in and redirect it to the dashboard. A classic login process.
Today, when I wanted to log in to develop new things, I saw the error code 422 returned, and when I printed the incoming data on the server-side, I saw something like this:
// $request->all(); result
Array
(
[------WebKitFormBoundary0OBe87BBjSLuzX6z
Content-Disposition:_form-data;_name] => "email"
example#example.com
------WebKitFormBoundary0OBe87BBjSLuzX6z
Content-Disposition: form-data; name="password"
example.123!
------WebKitFormBoundary0OBe87BBjSLuzX6z--
)
// Laravel Error
{"message":"The given data was invalid.","errors":{"email":["The email field is required."],"password":["The password field is required."]}}
I haven't made any changes or updated anything in this part of the system for about three months. So I don't understand why it's not working. However, the form element comes incorrectly on the javascript side, and the Axios request is sent successfully. Here is where I prepared the form:
let data = new FormData(form);
axios.post(url, data).then(function (response){
...
}
When I examined the Axios versions (I'm using it via CDN), I saw that it was due to an error in the v0.27.1 version. However, when I looked at Unpkg from the official CDN links, I saw that it was upgraded to the latest version, and when I included the Unpkg cd for testing, the problem was solved.
This version fixes the problem: https://github.com/axios/axios/releases/tag/v0.27.2.
I am trying to make a test transaction using my Laravel 7 app and Authorize.net.
After submitting the sample data, I'm getting:
The element 'createTransactionRequest' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd' has invalid child element 'clientId' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'. List of possible elements expected: 'merchantAuthentication' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'.
Anyone know what's causing this error or how to fix it?
Well, I'll answer my own question since it might help others. The problem is the error message in the Authorize.net response is really vague.
Kurt Friars' comment was helpful, since it pointed me in the right direction. As for Mansour Hamcherif's suggestion, the merchantAuthentication object was set in my app, it just didn't have the right values, so it wasn't that.
The solution for me was setting the proper values to setName() and setTransactionKey(). The previous developer who had worked on this project had left values and the credentials had expired. I did a Linux text search for "setTransactionKey", which lead me to the correct PHP file where I need to set:
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName('EnterYourLoginNameHere');
$merchantAuthentication->setTransactionKey('EnterYourTransactionKey');
After that, I cleared all of my Laravel app's caches as well as my browser's caches, did a hard reload, tried a transaction again and it worked! I got:
This transaction has been approved., Transaction ID: **********.
You may want to check the log for the raw request, it's likely the merchantAuthentication object has not been set, if you are using the PHP SDK I recommend checking the SimpleCodeConstants.php file and make sure your merchant credentials constants are set.
For example, if I set my merchant credentials to NULL, I get the same E00003 error as a result of sending the following raw request:
{"createTransactionRequest":{"merchantAuthentication":[],"clientId":"sdk-php-2.0.0-ALPHA", ...}
Background: I have implemented the GCM enable android app which is use to received announcement and the announcement are send by a web site developed in php where we have created a html for m to enter the annoncement and button to submit.We submit this to php file which call the which get the all the registered user and run the code to send the message to all the user.
<?php
include_once 'db_functions.php';
include_once 'gcm.php';
$gcm = new GCM();
$db_functions = new DB_Functions();
$alluser = $db_functions->getAllUsers();
$message = array("price" => $message);
ob_start();
while ($row = mysqli_fetch_assoc($alluser)) {
echo "\n" . $row["name"] . "--";
$result = $gcm->send_notification(
array($row["gcm_regid"]),
$message);
echo $result;
}//End of while statement
?>
Issue: When I submit the form to send message to android app by using GCM call the same php webpage run for multiple time which is causing duplicate messages in client android app.
Could any one help me understand or provide me link which discuss this issue.
Possible Issue may be as the number of users have increase and it take a long time run this code for each use.
Any help in optimizing will be greatly appreciated.
I don't know what GCM library you use, but note that you can also call GCM with a list of ID's (up to 1000) to send the same message. So in that way you don't need to make 1000 calls if you have 1000 users. Unless of course your message is different for each user, but it doesn't look like it.
Besides that I don't think there is something wrong with your code. It can be that it takes a long time and people submit the form twice. Or you have some javascript on the button to submit the form which makes it to submit twice?
Thanks for your comment.
Basically i have found that this issue was due to the browser refresh in on the send message php page when network was week(lollipop network issue) so it cause the same message to be send for multiple no of time.
To solve the issue I have redesign the PHP page i.e. form to accept the message and send message by using the concept of request redirect get concept.
The link for the your reference.
https://en.wikipedia.org/wiki/Post/Redirect/Get
So that this issue does not happen due to refreshing.
Also thanks Jorgen for pointing out the concept of sending request to gcm server for all the gcm registration id it has improve the performance.
I am creating Android app that allows user to add product into his shopping cart and places order.
I am using XMLRPC for this purpose.
Following steps I have done
1.cart.create
2.cart_customer.set
3.cart_customer.addresses
4.cart_shipping.list
5.cart_shipping.method
6.cart_product.add
7.cart_payment.list
8.cart_payment.method
All code works fine till cart_payment.method , but when I call cart_coupon.add api I get exception
org.xmlpull.v1.XmlPullParserException: expected: START_TAG {null}methodResponse
(position:START_TAG (empty) <br>#1:7 in java.io.InputStreamReader#4151b450)
at org.kxml2.io.KXmlParser.require(KXmlParser.java:2046)
My code is:
client = new XMLRPCClient(url);
object = client.callEx("call", new Object[]{sessionId,
"cart_coupon.add",new Object[]{shoppingCardId,couponcode}});
where url is valid magento host url,shoppingCardId is CardId that I get from server.
Exception is at class XMLRPCClient, at line
pullParser.require(XmlPullParser.START_TAG, null, Tag.METHOD_RESPONSE);
I think server replies with blank string and parser doesn't find start tag.
If I call same api through php script, cart_coupon.add and cart.order work fine and I get order id in response and
at server side in sales->orders , I can see order has been placed successfully.
But when I follow same procedure from Android I get Exception described above.
What should I do?
I also got same problem. I bypassed XMLRPC for last call and written php script to place order.
I have a simple php Paypal ipn listener which inserts the raw POST data into an SQLite (v2) database. It was working. Then...it stopped working. (I don't recall making any changes to it.) It uses a basic php sample that Paypal provides using CURL to communicate with Paypal (followed by the db insert). It just gives a 503 Service Unavailable error now.
It works (minus actually doing anything :)) if I comment out the final line, that simple contains "sqlite_exec(...)".
Alternatively, a MySQL insert works fine.Mailing results works as well.
The SQLite database appears normal. Another script reads & updates as normal.
Web host sees no issues on the server side.
Can anyone make sense of this?
Or maybe there is a way to send the POST data to another script so that it gets processed separately, on its own, instead of altogether as one page?
Update: What I'm trying to insert is the "raw post data" string...
$raw_post_data = file_get_contents('php://input');
...as seen on the top line here under php sample code: https://www.x.com/developers/PayPal/documentation-tools/code-sample/216623 . My script is the same except with an insert at the bottom, which basically looks like this:
$dbloc = "/db/ipn.sqlite";
if($db = sqlite_open("$dbloc", 0666, $sqlite_error)){}else{die ($sqlite_error);}
$datetime = date("Y-m-d H:i:s");
$data = $raw_post_data;
$sql="INSERT INTO Paypal (entrydate,verified,data) values ('$datetime',$verified,'$data')";
sqlite_exec($sql,$db);
From when are you getting this error ?
Paypal has done some IPN changes recently.
please check this links:
https://www.x.com/content/bulletin-ipn-and-pdt-scripts-and-http-1-1
http://www.tipsandtricks-hq.com/forum/topic/paypal-ipn-and-pdt-changes-effective-from-1st-february-2013
please let us know what you are trying to insert into the db.