Search
 
SCRIPT & CODE EXAMPLE
 

PHP

How to validate Envato Purchase Code in PHP

function curl_request($code = '')
    {
        $product_code = $code;

        $personal_token = "oFGW4ECN7iquvQkiAhbLECAClwQpZ7Tr";
        $url = "https://api.envato.com/v3/market/author/sale?code=" . $product_code;
        $curl = curl_init($url);

        //setting the header for the rest of the api
        $bearer   = 'bearer ' . $personal_token;
        $header   = array();
        $header[] = 'Content-length: 0';
        $header[] = 'Content-type: application/json; charset=utf-8';
        $header[] = 'Authorization: ' . $bearer;

        $verify_url = 'https://api.envato.com/v1/market/private/user/verify-purchase:' . $product_code . '.json';
        $ch_verify = curl_init($verify_url . '?code=' . $product_code);

        curl_setopt($ch_verify, CURLOPT_HTTPHEADER, $header);
        curl_setopt($ch_verify, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch_verify, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch_verify, CURLOPT_CONNECTTIMEOUT, 5);
        curl_setopt($ch_verify, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');

        $cinit_verify_data = curl_exec($ch_verify);
        curl_close($ch_verify);

        $response = json_decode($cinit_verify_data, true);

        if (isset($response['verify-purchase']) && count($response['verify-purchase']) > 0) {
            return true;
        } else {
            // I WILL MAKE IT FALSE AFTER HAVING A VALID PURCHASE CODE TO TEST
            return true;
        }
    }
Comment

how to verify envato purchase code in php


function verify_purchase_code($code) {
    $code = urlencode($code);
    $url = "https://envato.eduardofiorini.com/index.php?item=35215272&code=" . $code . "&domain=" . $_SERVER['HTTP_HOST'];

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
    curl_setopt($ch, CURLOPT_HTTPHEADER, Array('Content-type: application/json'));

    $ret = curl_exec($ch);
    curl_close($ch);

    if (!$ret) {
        $ret = file_get_contents($url);
    }

    $data = json_decode($ret??"{}",true);

    if($data["error"]){
        echo json_encode(array("success" => false, "message" => $data["msg"]));
        exit();
    }else{
        return true;
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: wp php get total product order quantity 
Php :: php+js,code 
Php :: random record get with pagination in karavel 8 
Php :: how to get the top_area in orders laravel 
Php :: php code to display a div with background fade 
Php :: do php 
Php :: Issue with Generating Random Numbers using Laravel contains vs foreach loop 
Php :: get my account orders page url woocommerce 
Php :: $name = $name; "Robert" echo; 
Php :: laravel how to fetch user from user model based on id from post 
Php :: google api for language translation in php 
Php :: php executor 
Php :: validate unique or equal 
Php :: how to change css during holidays with php or Javascript in wordpress 
Php :: laravel handle image validation 
Php :: if gd is image 
Php :: contact us page mail prestashop 
Php :: laravel validation error messages are not showing on register oage 
Php :: php random array name 
Php :: file_get_contents vs readfile speed 
Php :: codeigniter 4 get method deprecated 
Php :: laravel rename file ftp 
Php :: model coomad laravel 
Php :: laravel One to Many relationship using custom primary keys 
Php :: php firebase sdk cloud messaging initialization 
Php :: laravel notion require 
Php :: php oops 
Php :: laravel model query time 
Php :: how to reduce time taken by php script on server 
Php :: ajax call php bootstrap validation 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =