Flex and Amazon Payments - apache-flex

I am trying to get amazon payments working w/ my flex app, as shown here:
http://miti.pricope.com/2009/07/11/using-amazon-flexible-payment-system-with-flex/
I've done exactly as he says, I've downloaded the files & changed the access key & secret key. When I run it on localhost or my production server I get "Signature did not match"
What else do I need to get this to work? Is there something else I need that he forgot to include.?

Lets try next:
goto return.and find function validateQueryString() and change to this:
function validateQueryString()
{
echo "validing the query string now\n";
$querystring = $_SERVER['QUERY_STRING'];
echo $querystring."\n";
echo $_GET['signature'];
$obj = new Amazon_FPS_CBUIUtils(AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY);
//Original signature received in response from Amazon FPS should be specified.
$signatureMatched = $obj->validateQueryString($querystring,$_GET['signature']);
if ($signatureMatched) {
echo "signature matched \n";
$request = new Amazon_FPS_Model_PayRequest();
//set the proper senderToken here.
$request->setSenderTokenId($_GET['tokenID']);
$amount = new Amazon_FPS_Model_Amount();
$amount->setCurrencyCode("USD");
//set the transaction amount here;
$amount->setValue($_SESSION['transaction_amount']);
$request->setTransactionAmount($amount);
//set the unique caller reference here.
$request->setCallerReference($_GET['callerReference']);
$service = new Amazon_FPS_Client(AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY);
invokePay($service, $request);
}
else
echo "Signature did not match \n";
}
and post output here please, including your Signature did not match
Thanks.

Related

wordpress wpdb->update strange error by converting single quote to html entity

Update Julu 2018:
I find out problem is something else. The print error method will always print out a encoded html message like the one below. If the message is not showing any extra piece of information means the SQL query is fine.
Original Question:
I tried to update the invite_code by using the $wpdb->update method, but it return strange error, it seems like WordPress convert the single quote to html entity - &#39
Please help me if anyone knows why it will convert the single quote to HTML entity automatically.
I am not able to do use any WordPress built-in method to update the query because the problem seems to happen at the prepared statement which will use in every built-in method.
WordPress database error: UPDATE exhibitor_invite SET invite_code =
&#039 ;8j8mxfkkubd0kppi082p&#039 ; WHERE id = 10
function createCode() {
$length = 20;
$inviteCode = "";
$characters = "0123456789abcdefghijklmnopqrstuvwxyz";
for ($p = 0; $p < $length; $p++) {
$inviteCode .= $characters[mt_rand(0, strlen($characters))];
}
return $inviteCode;
}
function updateCode($id) {
global $wpdb;
$wpdb->show_errors();
$prefix = $wpdb->prefix;
$invite_code = createCode() ;
// I tried to esc the string, but it doesn't work
// $invite_code = $wpdb->esc_like($invite_code);
// I also tried to use normal query, but it return the same error
// $affected_rows = $wpdb->query( $wpdb->prepare(
// " UPDATE {$wpdb->prefix}exhibitor_invite SET invite_code = %s WHERE id = %d", $invite_code, $id ));
$affected_rows = $wpdb->update( $prefix.'exhibitor_invite',
array('invite_code' => $invite_code),
array('id' => $id),
'%s',
'%d' );
$wpdb->print_error();
if(!is_bool($affected_rows)) {
return $affected_rows > 0;
}
return $affected_rows;
}
Perhaps way too late, but in case not I had the exact same problem and spent hours looking for a solution.
It seems that the WordPress property 'update' of wpdb object is where the problem occurs.
One solution that I found to work is to store the entire SQL string in a variable and then before using it, pass the variable through a PHP function of mysqli_real_escape_string().
PHP manual states:
This function is used to create a legal SQL string that you can use in an SQL statement. The given string is encoded to an escaped SQL string, taking into account the current character set of the connection.
Your solution may look something like this (untested).
$sql_string =
"
UPDATE ${prefix}exhibitor_invite
SET invite_code = %s
WHERE id = %d
";
//procedural style
mysqli_real_escape_string( $your_conn_to_server, $sql_string );
//update
$wpdb->update( $wpdb->prepare(
$sql_string,
array(
$invite_code,
$id
)
), OBJECT );

How Can I track sender's country after a cllient submits form via contact form 7?

Is there any mail-tags to use?
for instance; for tracking client's ip we can use; [_remote_ip]
First step is to create an API key. To get an API key we have to register in the site IPInfoDB.
Once API key is ready we have to download the file ip2locationlite.class.php from the site IPInfoDB.
Next step is to create our custom plugin.I named it as "country_custom_plugin.php". Its always good to create a custom plugin inside a folder, so that all the required files for the corresponding plugin stays in the folder. Named the folder as "country_custom_plugin"
Move the file "ip2locationlite.class.php" to the folder "country_custom_plugin".
/*Calling the function from contact-form-7 module and passing the result of the function stylus_ip_location_get_cc */
add_filter( 'wpcf7_special_mail_tags', 'country_custom_ip_location', 10, 2 );
/*Function to get location of an user from the ip address*/
function country_custom_ip_location( $output, $name ){
/*including the third party integration to get IP Location*/
include_once('ip2locationlite.class.php');
/*Special tag values are passed in format wpcf7.$name which we convert to _$name*/
$name = preg_replace( '/^wpcf7\./', '_', $name );
/*If location is requested in contact form enter the loop*/
if ( '_custom_ip_location' == $name ) {
$ipLite = new ip2location_lite;
/*Entering the API key value generated*/
$ipLite->setKey('"Enter your API Key Here"');
/*Getting the IP address*/
$ipaddress = preg_replace( '/[^0-9a-f.:, ]/', '', $_SERVER['REMOTE_ADDR'] );
/*Getting the Location*/
$visitorGeolocation = $ipLite->getCity($ipaddress);
if (!empty($visitorGeolocation) && is_array($visitorGeolocation)) {
$output = $visitorGeolocation['regionName'] . ', ' . $visitorGeolocation['countryName'] . ', ' . $visitorGeolocation['countryCode'];
}
}
return $output;
}
Reference.Hope this will help. Please let me know if any issue.

Unit Testing with Fat-Free-Framework

Is there a way to use PHPUnit where I have a test folder with indexTest.php inside that tests routes in my index.php file?
The fat-free guide gives snippets of code for mocking route requests and POSTS. I have only managed to get such a test to work if I generate the route directly in my test file with whatever functionality in it.
What I would like is to mock a route with tokens, allow it to run from a route in index.php and through the controller and test f3 variables that should be set by running the route.
<?php
class indexTest extends \PHPUnit_Framework_TestCase
{
public function test()
{
$f3 = Base::instance();
// Don't write to STDOUT
$f3->set('QUIET', true);
$f3->route('GET /path', function(){ echo 'TEXT'; });
$this->assertNull($f3->mock('GET /path'));
$this->assertSame('TEXT', $f3->get('RESPONSE'));
$f3->route('GET /verify/#answer/#value',
function($f3, $params){
$errors = array();
$answer = $params['answer'];
$value = $params['value'];
$prefix = substr($answer, 0, 3); //pre, ans, pos
$id = (int)substr($answer, 3); //question id number (1, 2, 3, 4)
//$value is the input value from user
$result = check_id($prefix, $id, $value);
if($result !== true){
$errors[] = $result;
}
$f3->set('errors', $errors);
return $errors;
});
function check_id($prefix, $id, $value)
{
if($prefix == 'pre' || $prefix == 'pos'){
if($value <= 0 || $value > 180 || $value === NULL){
echo 'The input value of ' . $prefix . $id . ' question was out of bounds';
return 'The input value of ' . $prefix . $id . ' question was out of bounds';
}else{
return true;
}
}else if($prefix == 'ans'){
if($value < 0 || $value > 10 || $value === NULL){
echo 'The value of quiz ans' + $id + ' was out of bounds';
return 'The value of quiz ans' + $id + ' was out of bounds';
}else{
return true;
}
}else {
return 'The prefix does not match';
}
}
$this->assertNotNull($f3->mock('GET /verify/ans1/8'));
$this->assertEmpty($f3->get('RESPONSE')[0]);
$this->assertNotNull($f3->mock('GET /verify/dsk4/6'));
$this->assertSame('6', $f3->get('PARAMS.value'));
$this->assertSame('dsk4', $f3->get('PARAMS.answer'));
$this->assertEmpty($f3->get('RESPONSE')[0]);
$this->assertNotNull($f3->mock('GET /verify/pre4/250'));
$this->assertSame('The input value of pre4 question was out of bounds', $f3->get('errors')[0]);
$this->assertNotSame('pre4', $f3->get('PARAMS.answer'));
$f3->set('QUIET',FALSE); // allow test results to be shown later
$f3->clear('ERROR'); // clear any errors
}
}
I'd prefer not to declare the entire route like this, maybe I am entirely wrong and this is not possible? The above code works running vendor/bin/phpunit. Relative examples and tutorials are difficult to find on this.
Short answer
Separate your controller code from bootstrapping and routing code
Reuse the routing configuration in your environments, e.g. website, CLI and testing environment
Use Base->mock() in your tests to mock the previously defined routes
Don't execute Base->run() in the testing environment
Long answer
I'm planning for a long time to write an article about testing F3 routes but due the lack of time I will just give some points here instead:
Create a reusable file which defines the routes (e.g. a routes.php file or a INI file with route defintions)
Load the routes before running test code. This could be easily done with a custom bootstrap file for PHPUnit (--bootstrap <FILE> or use the according directive in PHPUnit's configuration).
Write the PHPUnit tests
Example
The following example is an adaption of my GitHub Gist:
bootstrap-website.php
<?php
$f3 = Base::instance();
require 'bootstrap-shared.php';
// [Custom rules only for the website here]
require 'routes.php';
$f3->run();
bootstrap-test.php
<?php
$f3 = Base::instance();
require 'bootstrap-shared.php';
// [Custom rules only for testing environment here]
$f3->set('QUIET', true);
$f3->set('APP.TEST', true);
require 'routes.php';
routes.php
<?php
/**
* #var $f3 Base
*/
$f3->route('GET /path', function(){ echo 'TEXT'; });
ExampleTest.php
class ExampleTest extends PHPUnit_Framework_TestCase {
public function test() {
// Could also be provided by a custom base TestCase.
$f3 = Base::instance();
$this->assertNull($f3->mock('GET /path'));
$this->assertSame('TEXT', $f3->get('RESPONSE'));
}
}
Some notes:
bootstrap-test.php is the custom bootstrapping file for PHPUnit
bootstrap-website.php is the bootstrapping file for the website
bootstrap-shared.php contains information shared by all environments. The file could include routing information. I separated the routing information in the example: routes.php
ExampleTest.php is a regular PHPUnit test
The $f3->set('QUIET', true); snippet should be added to the custom bootstrap file. It's also a good idea to introduce a variable showing that the application is running in a test mode, for instance $f3->set('APP.TEST', true)
F3 doesn't clean up your variables between tests/mocks. You could store the original state before running tests and then restore the state in PHPUnit's setUp() method
Instead of rendering pages it could also be sufficient to collect only the data which should be available for rendering. In this case use the introduced APP.TEST variable in your view to skip rendering
Notes for later answer updates
ini_set('error_log','./phpunit/error.log')
$f3->set('ONERROR',function(){});

Problems while getting custom dimensions via API from Google Analytics

Goog day. When I try to get custom dimensions via API, I got error
Exception 'Google_Service_Exception' with message 'Error calling GET
https://www.googleapis.com/analytics/v3/management/accounts/~all/webproperties/~all/customDimensions:
(400) Cannot query by ~all for id webPropertyId'
My code
$service_account_name = '<Service Email>#developer.gserviceaccount.com';
$key_file_location = '<keyName>.p12';
$key = file_get_contents($key_file_location);
$cred = new Google_Auth_AssertionCredentials(
$service_account_name,
array(Google_Service_Analytics::ANALYTICS),
$key,
'notasecret',
'http://oauth.net/grant_type/jwt/1.0/bearer',
'<My email>'
);
$client->getAuth()->setAssertionCredentials($cred);
$service = new Google_Service_Analytics($client);
$result = $service->management_customDimensions->listManagementCustomDimensions('~all', '~all');
print_r($result);
Similar code for getting goals works correctly
$service_account_name = '<Service Email>#developer.gserviceaccount.com';
$key_file_location = '<keyName>.p12';
$key = file_get_contents($key_file_location);
$cred = new Google_Auth_AssertionCredentials(
$service_account_name,
array(Google_Service_Analytics::ANALYTICS),
$key,
'notasecret',
'http://oauth.net/grant_type/jwt/1.0/bearer',
'<My email>'
);
$client->getAuth()->setAssertionCredentials($cred);
$service = new Google_Service_Analytics($client);
$result = $service->management_profiles->listManagementProfiles('~all', '~all');
print_r($result);
Both methods listManagementProfiles and listManagementProfiles get parametrs $accountId and $webPropertyId .
Could someone help, why I get error, while getting custom dimensions via API?
Looking at the documentation "~all" is specifically mentioned as valid parameter value for listManagementProfiles:
Account ID for the view (profiles) to retrieve. Can either be a
specific account ID or '~all', which refers to all the accounts to
which the user has access.
but not for listManagementCustomDimensions, here is says simply
Account ID for the custom dimensions to retrieve.
(same for property id). So your problem is quite literally what the error message says, you cannot use "~all" when querying custom dimensions.
So it seems that to list all custom dimensions you'd have to iterate through a list of property ids (as returned by the properties/list method) instead of using "~all".

prestashop user login integration

I have to integrate PrestaShop 1.5 with pre-existing symfony application.
Through webservices, I can keep the databases in sync so a user can perform login with the same data on both PrestaShop and application software.
Now I want to to ensure that logging in application, the user is automatically logged in the PrestaShop platform.
Can you help me?
I don't know if you're still searching for a solution but there is a way actually.
DO MAKE SURE IT IS A SECURE LOGIN.
Since you're giving access to all prestashop data do make sure the login is very secure. I've been able to recreate it with PHP I think that with some additions you're able to recreate it the way you want it. See it as a guideline.
To create a login system by using the prestashop webservice you'll need three things
Access through webservice to the customers table
The COOKIE_KEY, defined in app/config -> parameters.php:: 'cookie_key' => '12321test';
Some expierence with PHP
The first thing is to get the customers table from the webservice.
// code placeholder
require_once('./../PSWebServiceLibrary.php');
/**
* get information from PrestaShop
*/
$webService = new PrestaShopWebservice($url, $key, $debug);
$COOKIE_KEY = 'CookieKey';
$email = $_REQUEST['email'];
$password = $_REQUEST['password'];
$optUser = array(
'resource' => 'customers',
'filter[email]' => '[' . $email . ']',
'display' => '[id,email,lastname,firstname,passwd]'
);
$resultUser = ($webService->get($optUser));
$json = json_encode($resultUser);
The second and most important thing is to Check the user input
// code placeholder
foreach ($resultUser->customers->customer as $info) {
// Prestashop uses the cookie_key in combination with a salt key. To check the password use the php function: password_verify();
$salt = substr($info->passwd, strrpos($info->passwd, ':') + 1, 2);
$ZCpassword = md5($COOKIE_KEY . $password) . ':' . $salt;
// Check if password comparison is true or false
if (password_verify($password, $info->passwd) == true) {
session_start();
$response = array();
$response['status'] = 'succes';
$response['message'] = "You did it!";
setcookie("userId", $info->id);
header('Content-type: application/json');
echo json_encode($response);
} else {
$response = array();
$response['status'] = 'error';
$response['message'] = 'Wrong password';
header('Content-type: application/json');
echo json_encode($response);
}
}
This is how to reproduce the issue to a working example.
What i've used is setting a cookie and check if it exists!
Hope this helps!

Resources