PHP code example of gatioo / yotpo

1. Go to this page and download the library: Download gatioo/yotpo library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gatioo / yotpo example snippets



$ak = "APP_KEY";
$st = "SECRET";
$yotpo = new \Yotpo\Yotpo($ak, $st);

$yotpo->create_review(array(
      'app_key' => $ak, 
      'product_id' => "BLABLA", 
      'shop_domain' => "omri.co", 
      'product_title' => "pt", 
      'product_description' => "pd", 
      'product_url' => "http://google.com/?q=myproducturl", 
      'product_image_url' => "https://www.google.com/images/srpr/logo4w.png", 
      'user_display_name' => "MOSHE5656", 
      'user_email' => '[email protected]', 
      'review_body' => "this is my review body", 
      'review_title' => "my review title" , 
      'review_score' => 5  
      ));


$response = $yotpo->get_product_reviews(array('app_key' => $ak, 'product_id' => "BLABLA"));

echo $response->response->reviews[0]->title;
echo $response->response->reviews[0]->score;

$response = $yotpo->get_product_bottom_line(array('app_key' => $ak, 'product_id' => "BLABLA"));

echo $response->response->bottomline->average_score;
echo $response->response->bottomline->total_reviews;


// retrieving the utoken - will be valid for 24 hours
$credentials = $yotpo->get_oauth_token();
$utoken = $credentials->access_token;

// first creating the products that are in the order, notice that the key of the product hash is the product_sku
$products = array(
        "BLABLA1" => array(
                'url' => "http://shop.yotpo.com/products/amazing-yotpo-poster", 
                'name' => "Yotpo Amazing Poster", 
                'image_url' => "http://cdn.shopify.com/s/files/1/0098/1912/products/qa2_medium.png?41", 
                'description' => "this is the most awesome poster in the world!", 
                'price' => "100"
            )
        );


//now we will create a purchase using this the token we have received in the previous step
$response = $yotpo->create_purchase(array(	'app_key' => $ak, 
                                        		'utoken' => $utoken, 
                                        		'email' => "[email protected]", 
                                        		'customer_name' => "bob", 
                                        		'order_id' => "13444", 
                                        		'platform' => "Shopify", 
                                        		'order_date' => "2013-05-28", 
                                        		'products' => $products, 
                                        		'currency_iso' => "USD"
                                        		));

                                        

$response = $yotpo->get_purchases(array('app_key' => $ak, 'utoken' => $utoken, 'since_date' => "2013-05-26"));
echo $response->response->total_purchases;