Jump to content

Domains prices sync php cron job


sskafandri

Recommended Posts

Hello,

I am trying to develop a PHP script to fetch data from json and update domains prices by using cron job but I didn't succeed can you please help me.

this is the json data that i want to use:

{
   "transactid":"fe6s8f486ew84re68t4jg6bc8",
   "status":"SUCCESS",
   "product":[
      {
         "name":".com registration",
         "price":"10.99",
         "currency":"USD"
      },
      {
         "name":".com renewal",
         "price":"9.99",
         "currency":"USD"
      },
      {
         "name":".com transfer",
         "price":"8.99",
         "currency":"USD"
      },
      {
         "name":".com restore",
         "price":"70.00",
         "currency":"USD"
      },
      {
         "name":".net registration",
         "price":"9.99",
         "currency":"USD"
      },
      {
         "name":".net renewal",
         "price":"9.99",
         "currency":"USD"
      },
      {
         "name":".net transfer",
         "price":"9.99",
         "currency":"USD"
      },
      {
         "name":".net restore",
         "price":"70.00",
         "currency":"USD"
      },
      {
         "name":".org registration",
         "price":"12.30",
         "currency":"USD"
      },
      {
         "name":".org renewal",
         "price":"10.30",
         "currency":"USD"
      },
      {
         "name":".org transfer",
         "price":"10.30",
         "currency":"USD"
      },
      {
         "name":".org restore",
         "price":"70.00",
         "currency":"USD"
      },
      {
         "name":".fr registration",
         "price":"6.89",
         "currency":"USD"
      },
      {
         "name":".com.fr registration",
         "price":"6.89",
         "currency":"USD"
      },
      {
         "name":".fr renewal",
         "price":"4.89",
         "currency":"USD"
      },
      {
         "name":".com.fr renewal",
         "price":"6.89",
         "currency":"USD"
      },
      {
         "name":".fr trade",
         "price":"6.89",
         "currency":"USD"
      }
   ]
}

 

and this is my php script its only get the registration prices but not the renewal and the transfer prices :

 

<?php

$servername = "";
$dbname     = "";
$username   = "";
$password   = "";

$conn = mysqli_connect($servername, $username, $password, $dbname);

if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
} else {
    
    $commandUrl = "https://api.example.com/data.json";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL, $commandUrl);
    $result = curl_exec($ch);
    curl_close($ch);
    
    $products_json = json_decode($result, true);
    
    mysqli_query($conn, "TRUNCATE TABLE `tbldomainpricing`");
    echo "EMPTIED tbldomainpricing \n";
    mysqli_query($conn, "DELETE FROM `tblpricing` WHERE type='domainregister'");
    echo "REMOVED domainregister \n";
    mysqli_query($conn, "DELETE FROM `tblpricing` WHERE type='domaintransfer'");
    echo "REMOVED domaintransfer \n";
    mysqli_query($conn, "DELETE FROM `tblpricing` WHERE type='domainrenew'");
    echo "REMOVED domainrenew \n";
    
    $i = 1;
    foreach ($products_json['product'] as $product) {
        $extensions = $product['name'];
      
      if (substr($extensions, 0, 1) === '.') {
        if (strpos($extensions, "registration") !== FALSE) {
            $price     = $product['price'];
            $exts      = $product['name'];
            $extension = str_replace(' registration', '', $exts);
        
            $query = "INSERT INTO `tbldomainpricing` (`id` ,`extension` ,`dnsmanagement` ,`emailforwarding` ,`idprotection` ,`eppcode` ,`autoreg` ,`order`)
        VALUES (NULL , '" . $extension . "', '', '', '', '1', '', '$i');";
            mysqli_query($conn, $query);
            
            $relid = mysqli_insert_id($conn);
            
            $query = "INSERT INTO `tblpricing` (`id` ,`type` ,`currency` ,`relid` ,`msetupfee` ,`qsetupfee` ,`ssetupfee` ,`asetupfee` ,`bsetupfee` ,`tsetupfee` ,`monthly` ,`quarterly` ,`semiannually` ,`annually` ,`biennially` ,`triennially` )
        VALUES (NULL , 'domainregister', '1', '$relid', '" . $price . "', '-1.00', '-1.00', '-1.00', '-1.00', '0.00', '-1.00', '-1.00', '-1.00', '-1.00', '-1.00', '0.00')";
            mysqli_query($conn, $query);
            
            $i++;
        }
		
		if (strpos($extensions, "transfer") !== FALSE) {
            $price     = $product['price'];
            $exts      = $product['name'];
            $extension = str_replace(' transfer', '', $exts);
        
            $relid = mysqli_insert_id($conn);
            
            $query = "INSERT INTO `tblpricing` (`id` ,`type` ,`currency` ,`relid` ,`msetupfee` ,`qsetupfee` ,`ssetupfee` ,`asetupfee` ,`bsetupfee` ,`tsetupfee` ,`monthly` ,`quarterly` ,`semiannually` ,`annually` ,`biennially` ,`triennially` )
        VALUES (NULL , 'domaintransfer', '1', '$relid', '" . $price . "', '-1.00', '-1.00', '-1.00', '-1.00', '0.00', '-1.00', '-1.00', '-1.00', '-1.00', '-1.00', '0.00')";
            mysqli_query($conn, $query);
            
            
            $i++;
        }
		
		if (strpos($extensions, "renewal") !== FALSE) {
            $price     = $product['price'];
            $exts      = $product['name'];
            $extension = str_replace(' renewal', '', $exts);
        
		 $relid = mysqli_insert_id($conn);
		 
            $query = "INSERT INTO `tblpricing` (`id` ,`type` ,`currency` ,`relid` ,`msetupfee` ,`qsetupfee` ,`ssetupfee` ,`asetupfee` ,`bsetupfee` ,`tsetupfee` ,`monthly` ,`quarterly` ,`semiannually` ,`annually` ,`biennially` ,`triennially` )
        VALUES (NULL , 'domainrenew', '1', '$relid', '" . $price . "', '-1.00', '-1.00', '-1.00', '-1.00', '0.00', '-1.00', '-1.00', '-1.00', '-1.00', '-1.00', '0.00')";
            mysqli_query($conn, $query);
            
            $i++;
        }
      }
    }
    exit;
    
}

?>

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated