yii query buid error in adyen callback class - php

So I have the following scenario:
A user recharges his account via Adyen API and when the payment is processed I have a ProcessOrder method that receives the callback and does the following:
public function ProcessOrder($order)
{
//some order processing
$order_total = Yii::app()->db->createCommand()
->select('sum(`amount`) as total')
->from('`order_table`')
->where('`uid` = ' . $order->user->id)
->queryRow();
//send email with data
}
And I know the $order_total is failing but I don't know why...
I want to check logs but I don't know where they are (I'm new to this project) and I am trying to send me a email with the result. I cannot var_dump() the result and then die() because the class method is called via Adyen callback...
So basically my question is:
Where are the logs in a yii app OR
Why is the query failing? :-?
More Info
This class is the Order Module file under protected.
The var $order->user->id has the correct value, I checked this with email :D
I also tried foreach($order_total as $row) { //send result } and nothing... It's like the system does not have access to perform query s in that part
Please ask in comments if more information is needed

:)) This is stupid...
So I figured out why this does NOT work and the problem is this:
order_table and uid MUST NOT HAVE apostrophes ``! Without them, the query executes and everything works fine.
And yii app logs are in runtime folder :)
(And for those of you new to Yii and what to know how to call something from a query like this, the value is is $order_total['total'])*

Related

How to get the ID of the current Contact with PHP Mautic API?

As I couldn't find anything in the documentation I might have a general understanding issue. But what I want to achieve is getting the ID of the current Contact browsing the Site. To get user details I always have to know the ID, like documented here: https://developer.mautic.org/#contacts
$api = new MauticApi();
$contactApi = $api->newApi("contacts", $auth, $settings['baseUrl']);
$contact = $contactApi->get(3);
Is there a way to the ID of the current Contact? I want to play highly customized content on the website and an entry point to get user details.
It's a REST API, so you should get a response in any case. What's the content of the response (eg. what contains $contact)? What's the HTTP code of the response? Error messages?
However... I'm not familiar with this particular API, but the principles are always the same
https://developer.mautic.org/?php#list-contacts
Without any query parameters it should give the full list of contacts. Each of the contact records should come with an ID for the details:
https://developer.mautic.org/?php#get-contact
As said, I'm not familiar with the API, so it could be that you get a contact list only from a higher entity, like a Company or so.
I can recommend Postman (https://www.postman.com/), a neat tool to make REST API requests while having full control over all the details.
Assuming that you're trying to get the details of the current logged in user.
You can use themautic.helper.user helper to do that as shown below:
<?php
$user = $this->get('mautic.helper.user')->getUser();
$firstName = $user->getFirstname();
$lastName = $user->getLastname();
$email = $user->getEmail();
$profile = $user->getProfile();
$role = $user->getRole()->getName();
if ($role->isAdmin()) {
// do something
}
Ref: https://developer.mautic.org/#services44
In order to do what you want here I do not think you actually need the API to get the user id. Mautic has dynamic content and as long as the user has a cookie dropped on his browser you can use Dynamic Content to say "Hi {contactfield=firstname}, welcome back.
You can actually call any custom field into the dynamic content slot.
Check out dynamic content which is found under the Components section in the left menu

Clickatell parseReplyCallback returning null?

I am trying to get a reply text message from Clickatell using their Rest API, when I call the parseReplyCallback function when their system posts to my page - it seems to be null or I am not sure how to get the variables it is returning. What I would like to do is have all of the variables returned insert into a SQL database so I can use it elsewhere.
I have tried quite a few things, using various styles of getting the variables such as $_POST, $results['text'], $results->text, and so forth each time I can't seem to get any information out of it. I can't just var_dump or anything because I can't see any backend or console so I am pretty much in the blind, hoping someone else is using this system and has it working fine.
require __DIR__.'/clickatell/src/Rest.php';
use clickatell\ClickatellException;
use clickatell\Rest;
$Rest = new Rest("j8VKw3sJTZuVfQGVC7jdhA");
// Incoming traffic callbacks (MO/Two Way callbacks)
$Rest->parseReplyCallback(function ($result) {
//mysqli_query($con,"INSERT INTO `SMSCHAT` (`text`) VALUES ('$result')");
$mesageId = mysqli_real_escape_string($con,$result['messageId']);
$text = mysqli_real_escape_string($con,$result['text']);
$replyMessageId = mysqli_real_escape_string($con,$result['replyMessageId']);
$to = mysqli_real_escape_string($con,$result['toNumber']);
$from = mysqli_real_escape_string($con,$result['fromNumber']);
$charset = mysqli_real_escape_string($con,$result['charset']);
$udh = mysqli_real_escape_string($con,$result['udh']);
$network = mysqli_real_escape_string($con,$result['network']);
$keyword = mysqli_real_escape_string($con,$result['keyword']);
$timestamp = mysqli_real_escape_string($con,$result['timestamp']);
//do mysqli_query
});
I'd like for it to break the result into individual variables (because I plan on doing other things such as an auto-reply, etc) and upload it to the SQL database scrubbed.
Either doesn't create the table entry or gives me a blank one altogether in that first test where I put the result in the text field.
From a Clickatell point of view, although we understand what you're asking - it's unfortunately outside the scope of support that we offer on our products.
If you would like more information on our REST API functionality, please feel free to find it here: https://www.clickatell.com/developers/api-documentation/rest-api-reply-callback/
If you don't succeed in setting up the callbacks, please feel free to log a support ticket here: https://www.clickatell.com/contact/contact-support/ and one of our team members will reach out and try to assist where possible.

PHP Live Chat Message insert ( Live streaming Chat, not VideoID Comment )

I'm actually building a PHP bot that reads the youtube live streaming chat, and store in a Database the message that contains a specific keyword wrote by the users during the livestream. All the logic is in place, what is missing is the feedback on chat when the bot is "triggered".
I looked everywhere but seams the PHP documentation is missing, if you look inside the PHP Classes there is the public function insert, but there is no example at all on how to use it?
Someone know how to use it?
Should be something "simple" like: $result = $youtube->liveChatMessages->Insert($args); but I can't figure out on what args looks like.
HERE the only reference about the Insert method
Thanks to all for any suggestion on how to use it!
17/06/2018 edit Working Example
$liveChatMessage = new Google_Service_YouTube_LiveChatMessage();
$liveChatSnippet = new Google_Service_YouTube_LiveChatMessageSnippet();
$liveChatSnippet->setLiveChatId($liveChatID);
$liveChatSnippet->setType("textMessageEvent");
$messageDetails = new Google_Service_YouTube_LiveChatTextMessageDetails();
$messageDetails->setMessageText("Message to type in chat");
$liveChatSnippet->setTextMessageDetails($messageDetails);
$liveChatMessage->setSnippet($liveChatSnippet);
$videoCommentInsertResponse = $youtube->liveChatMessages->insert('snippet', $liveChatMessage);

Authorize.Net CIM: How to send createProfile=true into the transaction with PHP API

The API docs say to set createProfile to true. I can't find an example of this so after searching around I found the setCreateProfile method. I'm using it like this. I get no errors.
$this->custpaymentprofile = new AnetAPI\CustomerProfilePaymentType();
$this->custpaymentprofile->setCreateProfile(true);
What I can't figure out is how to send this setting through the transaction so that a customer profile gets created.
All the other data is sent through AnetAPI\TransactionRequestType()
IE: $this->transactionRequestType->setOrder($this->order);
Everything else works, I can run a successful transaction, just need to get it to create a profile.
Found it:
$profile = new AnetAPI\CustomerProfilePaymentType();
$profile->setCreateProfile(true);
$transactionRequestType->setProfile($profile);

Make links clickable in PHP with twitterlibphp?

Hey guys, I'm using Twitter's PHP API, called twitterlibphp, and it works well, but there's one thing that I need to be able to initiate, which is the linking of URLs and #username replies. I already have the function for this written up correctly (it is called clickable_link($text);) and have tested it successfully. I am not too familiar with parts of twitterlibphp (link goes to source code), and I am not sure where to put the function clickable_link() in order to make URLs and #username's clickable. I hope that is enough information, thanks a lot.
EDIT:
In addition, I would like only one status to come up in the function GetFriendsTimeline(), right now 20 come up, is there any easy way to limit it to one?
I would extend the Twitter class and put the functionality in my own getUserTimeline method.
class MyTwitter extends Twitter
{
public function getUserTimeline()
{
$result = parent::getUserTimeline();
// Your functionality ...
return $result;
}
}
You don't need to put clickable_link() in twitterlibphp. Instead, call it right before you output a status message. Example:
$twitter = new Twitter('username', 'password');
$result = $twitter->getUserTimeline();
... parse the $result XML here ...
echo 'Status : '.clickable_link($status);

Categories