Fortumo reciept verificaton - fortumo

Can anyone help to configure this its doing my nut in now.
This will be useful: https://developers.fortumo.com/cross-platform-mobile-payments/
I have the secret key and the widget set up i just need it add the stuff to my database e.g coins + 1 in a query but the code inserted into the successful payment bit wont run. So time to start again fresh.
Any help will be appreciated.
<?php
// check that the request comes from Fortumo server
if(!in_array($_SERVER['REMOTE_ADDR'],
array('1.2.3.4', '2.3.4.5'))) {
header("HTTP/1.0 403 Forbidden");
die("Error: Unknown IP");
}
// check the signature
$secret = ''; // insert your secret between ''
if(empty($secret) || !check_signature($_GET, $secret)) {
header("HTTP/1.0 404 Not Found");
die("Error: Invalid signature");
}
$sender = $_GET['sender'];//phone num.
$amount = $_GET['amount'];//credit
$cuid = $_GET['cuid'];//resource i.e. user
$payment_id = $_GET['payment_id'];//unique id
$test = $_GET['test']; // this parameter is present only when the payment is a test payment, it's value is either 'ok' or 'fail'
//hint: find or create payment by payment_id
//additional parameters: operator, price, user_share, country
if(preg_match("/completed/i", $_GET['status'])) {
// mark payment as successful
}
// print out the reply
if($test){
echo('TEST OK');
}
else {
echo('OK');
}
function check_signature($params_array, $secret) {
ksort($params_array);
$str = '';
foreach ($params_array as $k=>$v) {
if($k != 'sig') {
$str .= "$k=$v";
}
}
$str .= $secret;
$signature = md5($str);
return ($params_array['sig'] == $signature);
}
?>

The first lines of the code example validates that the request comes from Fortumo IP address, if not then it the script dies.
// check that the request comes from Fortumo server
if(!in_array($_SERVER['REMOTE_ADDR'],
array('1.2.3.4', '2.3.4.5'))) {
header("HTTP/1.0 403 Forbidden");
die("Error: Unknown IP");
}
Write to support#fortumo.com to get the latest IP addresses to validate (and replace the example values 1.2.3.4 with them).
Meanwhile you can comment out the ip check and continue building your script.

Related

Error 400: invalid_request Invalid parameter value for prompt: Invalid prompt: cons

I am creating a plugin in WordPress where I am trying to make the Google sheet script work but I can't find a way.
I tried all the code available on here and different sources but I can't find anything to make it work. This is the error I get:
Open the following link in your browser:
https://accounts.google.com/o/oauth2/auth?response_type=code&access_type=offline&client_id=390081316396-0es6irrbq1ccj01uvhlqvrbc0eo9eopq.apps.googleusercontent.com&redirect_uri=https%3A%2F%2Fwww.suma.pro%2Fapp%2F&state&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fspreadsheets.readonly&prompt=consent
Enter verification code: Fatal error: Uncaught
InvalidArgumentException: Invalid code in
/home/suma/public_html/app/wp-content/plugins/suma-app/inc/vendor/google/apiclient/src/Google/Client.php:176
Stack trace: #0
/home/suma/public_html/app/wp-content/plugins/suma-app/suma-app.php(125):
Google_Client->fetchAccessTokenWithAuthCode('') #1
/home/suma/public_html/app/wp-includes/class-wp-hook.php(292):
SumaApp->getClient('') #2
/home/suma/public_html/app/wp-includes/class-wp-hook.php(316):
WP_Hook->apply_filters(NULL, Array) #3
/home/suma/public_html/app/wp-includes/plugin.php(484):
WP_Hook->do_action(Array) #4
/home/suma/public_html/app/wp-settings.php(560): do_action('init') #5
/home/suma/public_html/app/wp-config.php(90):
require_once('/home/suma/publ...') #6
/home/suma/public_html/app/wp-load.php(37):
require_once('/home/suma/publ...') #7
/home/suma/public_html/app/wp-blog-header.php(13):
require_once('/home/suma/publ...') #8
/home/suma/public_html/app/index.php(17):
require('/home/suma/publ...') #9 {main} thrown in
/home/suma/public_html/app/wp-content/plugins/suma-app/inc/vendor/google/apiclient/src/Google/Client.php
on line 176
function getClient()
{
define('STDIN',fopen("php://stdin","r"));
$client = new Google_Client();
$client->setApplicationName('Sumaapptest');
$client->setScopes(Google_Service_Sheets::SPREADSHEETS_READONLY);
$client->setAuthConfig(plugin_dir_path(__FILE__) .'inc/vendor/credentials.json');
$client->setAccessType('offline');
$client->setRedirectUri( 'https://www.suma.pro/app/');
$client->setPrompt('consent');
// Load previously authorized token from a file, if it exists.
// The file token.json stores the user's access and refresh tokens, and is
// created automatically when the authorization flow completes for the first
// time.
$tokenPath = 'token.json';
if (file_exists($tokenPath)) {
$accessToken = json_decode(file_get_contents($tokenPath), true);
$client->setAccessToken($accessToken);
}
// If there is no previous token or it's expired.
if ($client->isAccessTokenExpired()) {
// Refresh the token if possible, else fetch a new one.
if ($client->getRefreshToken()) {
$client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
} else {
// Request authorization from the user.
$authUrl = $client->createAuthUrl();
printf("Open the following link in your browser:\n%s\n", $authUrl);
print 'Enter verification code: ';
$authCode = trim(fgets(STDIN));
// Exchange authorization code for an access token.
$accessToken = $client->fetchAccessTokenWithAuthCode($authCode);
$client->setAccessToken($accessToken);
// Check to see if there was an error.
if (array_key_exists('error', $accessToken)) {
throw new Exception(join(', ', $accessToken));
}
}
// Save the token to a file.
if (!file_exists(dirname($tokenPath))) {
mkdir(dirname($tokenPath), 0700, true);
}
file_put_contents($tokenPath, json_encode($client->getAccessToken()));
}
return $client;
}
function suma_order_status_change_custom($this_get_id){
// Get the API client and construct the service object.
$client = getClient();
$service = new Google_Service_Sheets($client);
// Prints the names and majors of students in a sample spreadsheet:
// https://docs.google.com/spreadsheets/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms/edit
$spreadsheetId = '1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms';
$range = 'Class Data!A2:E';
$response = $service->spreadsheets_values->get($spreadsheetId, $range);
$values = $response->getValues();
if (empty($values)) {
print "No data found.\n";
} else {
print "Name, Major:\n";
foreach ($values as $row) {
// Print columns A and E, which correspond to indices 0 and 4.
printf("%s, %s\n", $row[0], $row[4]);
}
}
// echo $this_get_id;
// die();
}
Check your OAuth Client IDs
Go to https://console.developers.google.com/
Navigate to APIs & Services and take a look at this screen.
You should see that the type of client IDs is Web Application. The message that you are getting looks like you have made it a "Desktop" type.
Ensure that you have followed the steps in the quickstart exactly and then make it work together with wordpress after the quickstart works without issue.

How to prevent my bot from entering into a loop?

I created a functionality in my bot that allows to ping other computers, when the user pings more than 60 times the bot takes a long time to do it, and I think it does not respond to Telegram with an http 200 code, so Telegram sends it again the ping request and the loop never stops. I used this library to build my bot: https://github.com/Eleirbag89/TelegramBotPHP
The code to do it is very simple:
<?php
$telegram = new Telegram('token');
date_default_timezone_set('America/Bogota');
$chat_id = $telegram->ChatID();
$text = $telegram->Text();
$palabras = explode(" ", $text);
foreach ($palabras as $key) {
if (filter_var($key, FILTER_VALIDATE_IP)) {
$ip = $key;
$key = "";
}
if (is_numeric($key)){
$cant_paq=$key;
};
};
if (stristr($text, 'ping') && !empty($ip)) {
$numero = !empty($cant_paq) ? $cant_paq : 4;
exec("ping -c $numero $ip", $output, $status);
foreach ($output as $key) {
$resultPing .= $key . "\r\n";
}
$content = array('chat_id' => $chat_id, 'text' => $resultPing);
$telegram->sendMessage($content);
}
In the end, I managed to solve it myself, I searched all over the internet and found a clue from someone who had the same problem, adding http_response_code (200) was not enough. Now every time the something goes inside (stristr ($ text, 'ping') &&! empty ($ ip)) I clear the pending messages via drop_pending_updates parameter in the setWebhook method https://core.telegram.org/bots/api#setwebhook

Symfony3 add locale in deeplink

I create a new site in symfony3 following the getting started section in the official symfony documentation in https://symfony.com/doc/current/setup.html
Everything is working ok.. if I put mydomain.com as the URL, the framework add /en or the correct local.
My question is if there is a way that if the user do a deeplink to mydomain.com/blog the framework found that the local is not present so it can add and transform the url to mydomain.com/en/blog
I'm not adding the code as it is the default one. Let me know if you need it.
There are multiple ways to do this. Probably the easiest is to have an EventSubscriber or -Listener that catches request without a locale and then handles adding that information. Since you based your project on the demo application you might want to look at their solution: https://github.com/symfony/demo/blob/master/src/EventSubscriber/RedirectToPreferredLocaleSubscriber.php
The steps to perform in your event handler are roughly these:
Listen to kernel.request event
Return early based on some criteria, e.g. homepage, a cookie with the language is set, or something else
Detect the language either by getting the default locale or determining from your available locales and the browser header which language fits best (see: https://github.com/willdurand/Negotiation#language-negotiation)
Redirect, add the locale as attribute to request, write the currently set language to a cookie, or whatever else you need to do to change the route
Thanks to #dbrumann I get to this solution... For sure it can be improve to use less code but it just did the trick.
I updated the onKernelRequest method in RedirectToPreferredLocaleSubscriber class
public function onKernelRequest(GetResponseEvent $event): void
{
$request = $event->getRequest();
$path = explode('/',$request->getPathInfo());
$hasLocale = false;
foreach ($this->locales as $key => $l) {
if($l == $path[1]){
$hasLocale = true;
}
}
if(!$hasLocale){
// Ignore sub-requests and all URLs but the homepage
if (!$event->isMasterRequest() || '/' !== $request->getPathInfo()) {
$preferredLanguage = $request->getPreferredLanguage($this->locales);
if ($preferredLanguage !== $this->defaultLocale) {
$url = "";
foreach ($path as $key => $p) {
if($key > 0){
$url .= "/" . $p;
}
}
//print_r('/' . $preferredLanguage . $url);exit;
$response = new RedirectResponse('/' . $preferredLanguage . $url);
$event->setResponse($response);
}
}
else{
// Ignore requests from referrers with the same HTTP host in order to prevent
// changing language for users who possibly already selected it for this application.
if (0 === mb_stripos($request->headers->get('referer'), $request->getSchemeAndHttpHost())) {
return;
}
$preferredLanguage = $request->getPreferredLanguage($this->locales);
if ($preferredLanguage !== $this->defaultLocale) {
$response = new RedirectResponse($this->urlGenerator->generate('homepage', ['_locale' => $preferredLanguage]));
$event->setResponse($response);
}
}
}
}

Wordpress sending “Delivery status notification Failure” to my inbox every 7 minutes

We are getting spammed from wordpress#domain.com going to jaqqscigs#gmail.com. Ive tried the MU plug (Wordpress and wamp sending "Delivery status notification Failure" to my inbox every 7 minutes) but I got a parse error. Is there any way to just disable mail being sent from wordpress all together? We have changed passwords, disabled password ect..
Thanks!
Travis
Try this (not tested). Depending on your use, you may NOT want to throw the phpmailerException....
class fakemailer {
public function Send() {
throw new phpmailerException( 'Cancelling mail' );
}
}
if ( ! class_exists( 'phpmailerException' ) ) :
class phpmailerException extends Exception {
public function errorMessage() {
$errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n";
return $errorMsg;
}
}
add_action( 'phpmailer_init', 'wpse_53612_fakemailer' );
function wpse_53612_fakemailer( $phpmailer ) {
if ( ! /* condition */ )
$phpmailer = new fakemailer();
}
https://wordpress.stackexchange.com/questions/53612/how-to-stop-the-wp-mail-function

Adding a wordpress user to Salesforce Contact

I'm trying to do a relatively simple task by hooking into the Wordpress registration and adding the user that's being registered to a Salesforce db. When I run the Salesforce db code outside of Wordpress it works flawlessly, but when I test this by registering on my wordpress website, I get an error stating: INVALID_LOGIN: Invalid username, password, security token; or user locked out.
Additionally, I receive this error from Wordpress "Cannot modify header information - headers already sent" which doesn't allow me to view the entire object data that's being sent to Salesforce.
This is my code:
$SF_USERNAME = 'test';
$SF_PASSWORD = 'test';
define( 'CD_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
require_once (CD_PLUGIN_PATH . 'Toolkit/soapclient/SforceEnterpriseClient.php');
require_once (CD_PLUGIN_PATH . 'Toolkit/soapclient/SforceHeaderOptions.php');
function add_user_to_SF($user_id) {
$user = get_userdata($user_id);
try {
$mySforceConnection = new SforceEnterpriseClient();
$mySoapClient = $mySforceConnection->createConnection(CD_PLUGIN_PATH . 'Toolkit/soapclient/enterprise.wsdl.xml');
$mylogin = $mySforceConnection->login($SF_USERNAME, $SF_PASSWORD);
print '<pre>';
print_r($mylogin);
print '</pre>';
print '<br/><br/>';
$sObject = new stdclass();
$sObject->FirstName = $user->first_name;
$sObject->LastName = $user->last_name;
$sObject->Email = $user->user_email;
//echo "**** Creating the following:\r\n";
$createResponse = $mySforceConnection->create(array($sObject), 'Contact');
$ids = array();
foreach ($createResponse as $createResult) {
print_r($createResult);
array_push($ids, $createResult->id);
}
} catch (Exception $e) {
$errors->add( 'demo_error', __(print_r($_POST),'mydomain') );
$errors->add( 'demo_error', __($mySforceConnection->getLastRequest(),'mydomain') );
$errors->add( 'demo_error', __($e->faultstring,'mydomain') );
return $errors;
}
}
add_filter( 'registration_errors', 'add_user_to_SF', 10, 3 );
This is a php scope issue.
Adding:
global $SF_USERNAME;
global $SF_PASSWORD;
inside the function fixed the problem.
It looks like you might be missing the security token. It's appended to the end of the password.
This link explains how to generate the token
https://login.salesforce.com/help/doc/en/user_security_token.htm
You need to add your salesforce account security token with password
eg. Password - "testing"
Security Token - "2321njjn32j32"
You need to pass as - "testing2321njjn32j32"
This will work properly.

Resources