Guest User

ITem_stopped

a guest
Jun 9th, 2016
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.02 KB | None | 0 0
  1. <?php
  2.   2         define("WP_USE_THEMES",true);
  3.   3         require(__DIR__."/../../../../wp-load.php");
  4.   4
  5.   5         $conf = parse_ini_file("../../../../config.ini");
  6.   6         $servername = $conf['host'];
  7.   7         $username = $conf['user'];
  8.   8         $password = $conf['password'];
  9.   9         $database = $conf['database'];
  10.  10
  11.  11         $conn = mysqli_connect($servername, $username, $password,$database);
  12.  12         $check = 0;
  13.  13
  14.  14         // Check connection
  15.  15         if ($conn->connect_error) {
  16.  16             die("Database Connection failed: " . $conn->connect_error);
  17.  17                 $check = 1;
  18.  18         }
  19.  19
  20.  20         require_once(__DIR__. '/Requests/library/Requests.php');
  21.  21         Requests::register_autoloader();
  22.  22
  23.  23         // START CODE FROM HERE
  24.  24         ///////////////////////////////////////////////////////////////////////
  25.  25
  26.  26         $oid = $_GET['order_idx'];
  27.  27         $oiid = $_GET['order_item_idx'];
  28.  28
  29.  29         //MAP ORDERID AND USERID        
  30.  30         $result = mysqli_query($conn,"SELECT * FROM orderid_hashkey_map WHERE orderid='$oid'");
  31.  31         $hash = mysqli_fetch_array($result)['hash'];
  32.  32         $userid = mysqli_fetch_array($result)['userid'];
  33.  33         $invoiceid = mysqli_fetch_array($result)['invoiceid'];
  34.  34
  35.  35         //MAP CONNECTION DETAILS
  36.  36         $result1 = mysqli_query($conn,"SELECT * FROM hiveage_connection WHERE userid='$userid'");
  37.  37         $userhash = mysqli_fetch_array($result1)['userhash'];
  38.  38         $firstname = mysqli_fetch_array($result1)['firstname'];
  39.             $url = 'https://healthonrent.hiveage.com/api/rinv/'.$hash.'/';
  40.  44
  41.  45
  42.  46
  43.  47
  44.  48         $customer = new WC_Order($oid);
  45.  49         //$customer = new WC_Order('239');
  46.  50         $email = $customer->billing_email;
  47.  51         $firstname = $customer->billing_first_name;
  48.  52         $lastname =  $customer->billing_last_name;
  49.  53         $address = $customer->billing_address_1 . " " .$customer->billing_address_2;
  50.  54         $city = $customer->billing_city;
  51.  55         $statename = $customer->billing_state;
  52.  56         $zipcode = $customer->billing_postcode;
  53.  57         $country = $customer->shipping_country;
  54.  58         $phone = $customer->billing_phone;
  55.  59
  56.  60         //echo $email. " ". $firstname . " " .$lastname;                
  57.  61
  58.  62         //GET ORDER DETAILS
  59.  63         $date_today = date("Y-m-d");
  60.  64         $get_url = "http://128.199.112.153/wp-content/plugins/orders/rent.php?order_id=".$oid."&date=".$date_today;
  61.  65         $get_rent_array = file_get_contents($get_url);
  62.  66         $items = get_object_vars(json_decode($get_rent_array));
  63.  
  64.             //Create the items array
  65.  69         $hiveage_item_format = array();
  66.  70         $i = 0;
  67.  71         $alop = 0;
  68.  72         foreach($items as $item_id => $rent_object){
  69.  73                 $rent_det = get_object_vars($rent_object);
  70.  74                 if($item_id != $oiid && $rent_det["rent"]){
  71.  75                         echo $item_id." ".$oiid." INSIDE <br>";
  72.  76                         $alop = 1;
  73.  77                         $hiveage_item_format[$i] = array(
  74.  78                                                 'date' => $date_today,
  75.  79                                                 'description' => $rent_det["name"],
  76.  80                                                 'price' => $rent_det["rent"],
  77.  81                                                 'quantity' => '1',
  78.  82                                                 'unit' => 'monthly',
  79.  83                                                 'sort_order' => $i + 1
  80.  84                                                 );
  81.  85                         $i++;
  82.  86                 }
  83.  87         }
  84.             echo "<br><br><br>";
  85.  91         var_dump($hiveage_item_format);
  86.  92         echo "<br><br><br>";
  87.  93         if($alop){
  88.  94                 $data = array(
  89.  95                         'recurring_invoice' => array(
  90.  96                                 'id' => $invoiceid,
  91.  97                                 'connection' => array(
  92.  98                                                 'id' => $userid,
  93.  99                                                 'hash_key' => $userhash,
  94. 100                                                 'name' => $fname
  95. 101                                 ),
  96. 102                                 'recurring_method' => 'auto_send',
  97. 103                                 'next_billing_date' => $date_today,
  98. 104                                 'profile_name' => 'Recurring-Invoice',
  99. 105                                 'profile_no' => substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $    length),
  100. 106                                 'occurrences' => '0',
  101. 107                                 'interval' => '1',
  102. 108                                 'interval_unit' => 'months',
  103. 109                                 'due_date_options' => '5',
  104. 110                                 'hash_key' => $hash,
  105. 111                                 'summary' => $oid,
  106. 112                                 'note' => $oid,
  107. 113                                 'allow_partial_payments' => 'false',
  108. 114                                 'send_receipts_automatically' => 'true',
  109. 115                                 'currency_iso_code' => 'INR',
  110. 116                                 'items' => $hiveage_item_format
  111. 117                         )
  112. 118                 );
  113. 119                 $data = json_encode($data);
  114. 120                 echo $url;
  115.                
  116.                     $headers = array('content-type' => 'application/json');
  117. 123                 $options = array('auth' => array('xxxx', 'xxxx'));
  118. 124
  119. 125                 if($alop){
  120. 126                         $request = Requests::put($url,$headers,$data,$options);
  121. 127                         //var_dump($request);
  122. 128                 }
  123. 129                 else{
  124. 130                         $request = Requests::delete($url ,$headers,$options );
  125. 131                 }
  126. 132                 var_dump($request);
  127. 133         }
  128. 134
  129. 135 ?>
Add Comment
Please, Sign In to add comment